You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 09:37:10