如何将 5*3**n/6 重写为 5/2*3**(n-1) :我想要字符串 ok

how to rewrite 5*3**n/6 as 5/2*3**(n-1) :I want string ok

我想使用序列

我想要字符串 ok

5*3**n/6 ---> 5/2*3**(n-1)

我试试

from sympy import *
var('n')
f=5  *3**n/6
g=5/2*3**(n-1)
print("#",f,simplify(f))
print("#",g,simplify(g))
# 5*3**n/6       5*3**n/6
# 2.5*3**(n - 1) 0.833333333333333*3**n

(2022-02-11)

https://docs.sympy.org/latest/tutorial/simplification.html#powsimp

>>> from sympy import powsimp
>>> powsimp(5*3**n/6)
5*3**(n - 1)/2