Home > front end >  How do I evaluate an expression with trignometric functions & also complex numbers in Sagemath?
How do I evaluate an expression with trignometric functions & also complex numbers in Sagemath?

Time:03-26

I wanted to verify if n-th roots of unity are actually the n-th roots of unity?

i.e. if (root)^n = 1

I was trying to use sagemath to do this.

For e.g. for regular expressions sage seems to evaluate stuff

For e.g.

sage: x = var('x')
sage: f(x) = (x 2)^3
sage: f(5)
343

But I am unable to do this

sage: a = var('a')
sage: b = var('b')
sage: f(a, b) = (a   i*b)^3
sage: f(cos((2*pi)/3) , sin((2*pi)/3))
(1/2*I*sqrt(3) - 1/2)^3

How do I make sage raise it to power 3 & evaluate?

CodePudding user response:

A sage expression has several methods to manipulate it, including expanding, factoring and simplifying:

e = f(cos((2*pi)/3) , sin((2*pi)/3))
e.expand()
e.simplify()
e.full_simplify()
e.factor()

You can see the list of all available methods by typing the name of the variable, followed by a dot, followed by a tabulation: e.<tab>.

In your case, it would appear e.full_simplify() should do the trick.

Relevant documentation:

  • Related