import sympy as sp
sp.init_printing()
a,b,c = sp.symbols("a b c")
N=a*b*100 - (a**2) * (b**2)
D=2*(a-b)
V = N / D
print(V)
#Output: (-a**2*b**2 + 100*a*b)/(2*a - 2*b)
# HERE"s WHERE I GET THE RESULT:
g = V.diff(a)
print(g)
#Output: (-2*a*b**2 + 100*b)/(2*a - 2*b)
# -2*(-a**2*b**2 + 100*a*b)/(2*a - 2*b)**2
# The problem here is that it's the sum of two terms
# So I try simplifying it to get it as p/q
h = g.simplify()
print(h)
# Output: b*(a*(a*b - 100) + 2*(a - b)*(-a*b + 50)) / (2*(a - b)**2)
#
# It works to get the function as "p/q", except now
# it didn't expand the numerator and denominator into
# into a sum of polynomial terms. How to undo the factoring
# of numerator and denominator while still maintaining the whole
# function as a rational function of the form p/q?
Я пытаюсь заставить Sympy выдать результат, представляющий собой частное двух полиномов: p / q. [code]import sympy as sp sp.init_printing()
a,b,c = sp.symbols("a b c")
N=a*b*100 - (a**2) * (b**2) D=2*(a-b)
V = N / D print(V) #Output: (-a**2*b**2 + 100*a*b)/(2*a - 2*b)
# HERE"s WHERE I GET THE RESULT: g = V.diff(a) print(g) #Output: (-2*a*b**2 + 100*b)/(2*a - 2*b) # -2*(-a**2*b**2 + 100*a*b)/(2*a - 2*b)**2 # The problem here is that it's the sum of two terms
# So I try simplifying it to get it as p/q h = g.simplify() print(h) # Output: b*(a*(a*b - 100) + 2*(a - b)*(-a*b + 50)) / (2*(a - b)**2) # # It works to get the function as "p/q", except now # it didn't expand the numerator and denominator into # into a sum of polynomial terms. How to undo the factoring # of numerator and denominator while still maintaining the whole # function as a rational function of the form p/q? [/code] Я хочу, чтобы это выглядело так: [code](-2*a**2*b**2 - 4*a*b**3) / (4a + 4b**2)[/code]