Search code examples
symbolic-mathsagesimplify

Sagemath simplification


I am interested in expressions like

w=2*cos(3/7*pi) - 2*cos(2/7*pi) + 2*cos(1/7*pi) - 1

w is exactly 0, as is easily verified by expressing each cosine as sum of powers of a 7'th root of -1; Sage can verify this approximately by evaluating w as real.

I have tried to apply all simplify methods to w, to no avail. All return the same expression. Have I reached a Sage limitation, or is there some way of making it handle such expression?

I am using version 8.2.


Solution

  • One way to know if the expression is zero is to ask.

    Typing w == 0 will return a symbolic equation, but using bool can evaluate it to a boolean.

    sage: w = 2*cos(3/7*pi) - 2*cos(2/7*pi) + 2*cos(1/7*pi) - 1
    sage: w == 0
    2*cos(3/7*pi) - 2*cos(2/7*pi) + 2*cos(1/7*pi) - 1 == 0
    sage: bool(w == 0)
    True
    

    Another way is to convert w to the field of algebraic numbers, QQbar.

    sage: ww = QQbar(w)
    sage: ww
    0
    

    Note: a similar question was asked and answered as