pystencils.sympyextensions.math.replace_second_order_products#
- pystencils.sympyextensions.math.replace_second_order_products(expr, search_symbols, positive=None, replace_mixed=None)#
Replaces second order mixed terms like 4*x*y by 2*( (x+y)**2 - x**2 - y**2 ).
This makes the term longer - simplify usually is undoing these - however this transformation can be done to find more common sub-expressions
- Parameters:
expr (
Expr
) – input expressionsearch_symbols (
Iterable
[Symbol
]) – symbols that are searched for for example, given [x,y,z] terms like x*y, x*z, z*y are replacedpositive (
Optional
[bool
]) – there are two ways to do this substitution, either with term (x+y)**2 or (x-y)**2 . if positive=True the first version is done, if positive=False the second version is done, if positive=None the sign is determined by the sign of the mixed term that is replacedreplace_mixed (
Optional
[List
[Assignment
]]) – if a list is passed here, the expr x+y or x-y is replaced by a special new symbol and the replacement equation is added to the list
- Return type: