How can I determine in sage whether two expressions are equivalent? For example:
sage: var('x')
x
sage: e1 = 1 + x
sage: e2 = x + 1
sage: e3 = x + 2
sage: is_equivalent(e1, e2)
True
sage: is_equivalent(e1, e3)
False
sage: var('y')
y
sage: e4 = x * (1 + y)
sage: e5 = x + (x * y)
sage: is_equivalent(e4, e5)
True
sage: is_equivalent(e4, e1)
False
sage: assume(x, 'real')
sage: e6 = sqrt(x**2) + 1
sage: is_equivalent(e6, e1)
True
What has already been suggested/ tried: (sage 6.4.1 on Ubuntu Linux)
sage: e1 == e2
x + 1 == x + 1
sage: e1 is e2
False
sage: e1.match(e2) is not None
True
sage: e4.match(e5) is not None
False
Combine any like terms on each side of the equation: x-terms with x-terms and constants with constants. Arrange the terms in the same order, usually x-term before constants. If all of the terms in the two expressions are identical, then the two expressions are equivalent.
Sage can perform various computations related to basic algebra and calculus: for example, finding solutions to equations, differentiation, integration, and Laplace transforms.
We can solve equations: sage: x = var('x') sage: S = solve(x^3 - 1 == 0, x) sage: S [x == 1/2*I*sqrt(3) - 1/2, x == -1/2*I*sqrt(3) - 1/2, x == 1] sage: S[0] x == 1/2*I*sqrt(3) - 1/2 sage: S[0].
The Sage command for square root is sqrt.
Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming.
Coerce to an algebraic number. If use_fake_div is set to True, then the converter will try to replace expressions whose operator is operator.mul with the corresponding expression whose operator is operator.truediv. The input to this method is a symbolic expression and the infix operator corresponding to that expression.
Primarily, it provides a class Converter which will walk the expression tree and make calls to methods overridden by subclasses. Bases: sage.symbolic.expression_conversions.Converter
sage: k=var('k')sage: assume(k,'integer')sage: f=e^(I*pi*k)sage: f.rectform()(-1)^k However, in general, the resulting expression may be more complicated than the original: sage: f=e^(I*x)sage: f.rectform()cos(x) + I*sin(x) reduce_trig(var=None)¶
The usual way to do this is to make an equation out of them and check whether it is True
or False
.
sage: e4 == e5
x*(y + 1) == x*y + x
sage: bool(_)
True
However, keep in mind that Sage will return False
if it cannot prove it is True
, which is not the same thing as being false. Checking equivalence of two arbitrary expressions might be arbitrarily long to do, and might require a crazy sequence of expansions/'simplifications' the computer cannot predict.
This is answering a different question:
sage: e1 is e2
False
This is Python, and is a very strong condition that two things are the same "object", which in this case they aren't.
sage: a = 1
sage: b = 1
sage: a is b
False
sage: a = 1
sage: b = a
sage: a is b
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With