Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

math

sage

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
like image 517
Oleg Avatar asked Jan 16 '15 01:01

Oleg


People also ask

How can you prove that two expressions are equivalent?

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.

Can Sage solve a system of equations?

Sage can perform various computations related to basic algebra and calculus: for example, finding solutions to equations, differentiation, integration, and Laplace transforms.

How do you write an equation in Sagemath?

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].

How do you write square root on Sage?

The Sage command for square root is sqrt.

What is the difference between two equivalent expressions in this class?

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.

How to use coerce to an algebraic number?

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.

What is the purpose of the expression converter in Sage?

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

How do you calculate the value of K in Sage?

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)¶


1 Answers

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
like image 150
kcrisman Avatar answered Oct 11 '22 17:10

kcrisman