如何让SymPy使用tanh加法公式化简含artanh的表达式?
用SymPy化简
tanh(∑artanh x)类表达式的正确方法 问题场景
需要计算形如 q = tanh(∑_{x ∈ S} artanh x) 的表达式,其中所有x ∈ S都是有理数。根据双曲正切加法公式:
tanh(x + y) = (tanh x + tanh y)/(1 + tanh x tanh y)
理论上可以推导出q的精确有理值,但SymPy默认的化简工具无法直接处理这类式子。
遇到的问题
以简单两项为例:
from sympy import tanh, artanh, simplify expr = tanh(artanh(1/3) + artanh(2/3)) print(simplify(expr)) # 输出原表达式,未化简
尝试过以下操作均无法得到预期结果:
- 调用表达式的
.expand()方法 - 使用
.expand(power_exp=True)参数 - 传入
"deep"或"basic"参数的扩展操作 - 错误认为
tanh没有对应的双曲函数扩展方法
解决方案
使用SymPy的expand_trig()函数,它支持双曲函数的展开化简:
from sympy import tanh, artanh, expand_trig expr = tanh(artanh(1/3) + artanh(2/3)) result = expand_trig(expr) print(result) # 输出 3/4
该函数会自动应用双曲正切的加法公式,结合反双曲正切的性质,最终得到精确的有理结果。
内容的提问来源于stack exchange,提问作者Max
相关产品推荐
相关产品推荐

