Commit 30c420c7 by Frederik Hennig

### Reverted previous change. Added test case for constants.

parent 87e9fa8e
Pipeline #38342 failed with stages
in 3 minutes and 2 seconds
 ... ... @@ -469,9 +469,12 @@ def simplify_by_equality(expr, a, b, c): if not isinstance(a, sp.Symbol) or not isinstance(b, sp.Symbol): raise ValueError("a and b must be symbols.") c = sp.sympify(c) if not (isinstance(c, sp.Symbol) or is_constant(c)): raise ValueError("c must be either a symbol or a constant!") expr = sp.sympify(expr) if not {a, b, c} <= expr.atoms(sp.Symbol): return expr expr_expanded = sp.expand(expr) a_coeff = expr_expanded.coeff(a, 1) ... ... @@ -481,11 +484,9 @@ def simplify_by_equality(expr, a, b, c): if isinstance(c, sp.Symbol): c_coeff = expr_expanded.coeff(c, 1) rest = expr_expanded - (c * c_coeff).expand() elif is_constant(c): else: c_coeff = expr_expanded / c rest = 0 else: raise ValueError("c must be either a symbol or a constant!") a_summands = summands(a_coeff) b_summands = summands(b_coeff) ... ...
 ... ... @@ -196,3 +196,8 @@ def test_simplify_by_equality(): expr = x * (y + z) - y * z expr = simplify_by_equality(expr, x, y, z) assert expr == x*y + z**2 # Let x = y + 2 expr = x * p - 2 * p expr = simplify_by_equality(expr, x, y, 2) assert expr == y * p
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!