LLM符号数学 (LLM Symbolic Math)
This notebook showcases using LLMs and Python to Solve Algebraic Equations. Under the hood is makes use of SymPy. 这个笔记本展示了如何使用LLMs和Python来解代数方程。在背后,它使用了SymPy。
from langchain.llms import OpenAI
from langchain.chains.llm_symbolic_math.base import LLMSymbolicMathChain
llm = OpenAI(temperature=0)
llm_symbolic_math = LLMSymbolicMathChain.from_llm(llm)
积分和导数 (Integrals and derivatives)
llm_symbolic_math.run("求sin(x)*exp(x)关于x的导数是多少?")
'答案:exp(x)*sin(x) + exp(x)*cos(x)'
llm_symbolic_math.run(
"求exp(x)*sin(x) + exp(x)*cos(x)关于x的积分是多少?"
)
'答案:exp(x)*sin(x)'
解线性和微分方程 (Solve linear and differential equations)
llm_symbolic_math.run('求解微分方程y" - y = e^t')
'答案:Eq(y(t), C2*exp(-t) + (C1 + t/2)*exp(t))'
llm_symbolic_math.run("这个方程y^3 + 1/3y的解是什么?")
'答案:{0, -sqrt(3)*I/3, sqrt(3)*I/3}'
llm_symbolic_math.run("x = y + 5, y = z - 3, z = x * y. 求解x, y, z的值")
'答案:(3 - sqrt(7), -sqrt(7) - 2, 1 - sqrt(7)), (sqrt(7) + 3, -2 + sqrt(7), 1 + sqrt(7))'