📜  Python| sympy.rewrite() 方法

📅  最后修改于: 2022-05-13 01:55:34.578000             🧑  作者: Mango

Python| sympy.rewrite() 方法

sympy.rewrite()方法的帮助下,我们可以用另一个函数。

示例 #1:

# import sympy 
from sympy import * 
  
x = symbols('x')
expr = tan(x)
print("Expression = {}".format(expr))
   
# Use sympy.rewrite() method 
expr_in_terms_of_sin = expr.rewrite(sin)  
      
print("Expression in terms of sin() : {}".format(expr_in_terms_of_sin))  

输出:

Expression = tan(x)
Expression in terms of sin() : 2*sin(x)**2/sin(2*x)

示例 #2:

# import sympy 
from sympy import * 
  
x = symbols('x')
expr = factorial(x)
print("Expression = {}".format(expr))
   
# Use sympy.rewrite() method 
expr_in_terms_of_gamma = expr.rewrite(gamma)  
      
print("Expression in terms of gamma() : {}".format(expr_in_terms_of_gamma))  

输出:

Expression = factorial(x)
Expression in terms of gamma() : gamma(x + 1)