Sage math: how to check if two expressions are equivalent?

How can I determine in a sage whether two expressions are equivalent? For instance:

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 
+5
source share
1 answer

The usual way to do this is to derive an equation from them and check if 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 that it is True , which is not the same as a lie. The equivalence test of two arbitrary expressions can be arbitrarily long, and a crazy sequence of extensions / 'simplifications' may be required that the computer cannot predict.

This is the answer to another question:

 sage: e1 is e2 False 

This is Python, and it is a very strong condition that two things are the same "object", which in this case is not.

 sage: a = 1 sage: b = 1 sage: a is b False sage: a = 1 sage: b = a sage: a is b True 
+5
source

Source: https://habr.com/ru/post/1211213/


All Articles