Ask Your Question

Revision history [back]

You have to keep in mind that in SageMath, symbolic variables have their own type:

sage: type(x)
<class 'sage.symbolic.expression.Expression'>

What you can do is to specify some domain for a symbolic variable; by default the domain is assumed to be the set of complex numbers, by you can restrict to real numbers by declaring

sage: x = var('x', domain='real')

This is taken into account in simplifications:

sage: sqrt(x^2).simplify()
abs(x)
sage: x = var('x', domain='complex')  # back to the default
sage: sqrt(x^2).simplify()
sqrt(x^2)

You have to keep in mind that in SageMath, symbolic variables have their own type:

sage: type(x)
<class 'sage.symbolic.expression.Expression'>

What you can do is to specify some domain for a symbolic variable; by default the domain is assumed to be the set of complex numbers, by you can restrict to real numbers by declaring

sage: x = var('x', domain='real')

This is taken into account in simplifications:

sage: sqrt(x^2).simplify()
sqrt(x^2)
abs(x)
sage: x = var('x', domain='complex')  # back to the default
sage: sqrt(x^2).simplify()
sqrt(x^2)
sqrt(x^2)

Another option is

sage: x = var('x', domain='positive')
sage: sqrt(x^2)
x

You have to keep in mind that in SageMath, symbolic variables have their own type:

sage: type(x)
<class 'sage.symbolic.expression.Expression'>

What you can do is to specify some domain for a symbolic variable; by default the domain is assumed to be the set of complex numbers, by you can restrict to real numbers by declaring

sage: x = var('x', domain='real')

This is taken into account in simplifications:

sage: sqrt(x^2)
abs(x)
sage: x = var('x', domain='complex')  # back to the default
sage: sqrt(x^2)
sqrt(x^2)

Another option is Other options are:

sage: x = var('x', domain='positive')
sage: sqrt(x^2)
x

sage: x = var('x', domain='integer')
sage: cos(x*pi).simplify_full()
(-1)^x

You have to keep in mind that in SageMath, symbolic variables have their own type:

sage: type(x)
<class 'sage.symbolic.expression.Expression'>

What you can do is to specify some domain for a symbolic variable; by default the domain is assumed to be the set of complex numbers, by but you can restrict to real numbers by declaring

sage: x = var('x', domain='real')

This is taken into account in simplifications:

sage: sqrt(x^2)
abs(x)
sage: x = var('x', domain='complex')  # back to the default
sage: sqrt(x^2)
sqrt(x^2)

Other options are:

sage: x = var('x', domain='positive')
sage: sqrt(x^2)
x

sage: x = var('x', domain='integer')
sage: cos(x*pi).simplify_full()
(-1)^x