pystencils.sympyextensions.math.complete_the_square#
- pystencils.sympyextensions.math.complete_the_square(expr, symbol_to_complete, new_variable)#
Transforms second order polynomial into only squared part.
Examples
>>> a, b, c, s, n = sp.symbols("a b c s n") >>> expr = a * s**2 + b * s + c >>> completed_expr, substitution = complete_the_square(expr, symbol_to_complete=s, new_variable=n) >>> completed_expr a*n**2 + c - b**2/(4*a) >>> substitution (n, s + b/(2*a))