# Comparing even powers of $i$ with 1

Computing $i^4$ yields $1$, but it's not the same $1$ as when I type $1$. Compare these two evaluations:

sage: I^4 == 1
1 == 1
sage: I^2 == 1
-1 == 1


I would have expected the first to yield True and the second to yield False. Is Sage's answer a desirable default behavior?

I see that the first $1$ is a sage.symbolic.expression.Expression and the other $1$ is a sage.rings.integer.Integer (likewise for the $-1$). How can I make the comparison evaluate as one might reasonably expect mathematically?

edit retag close merge delete

Sort by ยป oldest newest most voted

Since I^4 is a symblic expression, I^4 == 1 is also a symbolic expression:

sage: expr = (I^4 == 1)
sage: expr.parent()
Symbolic Ring


You can evaluate it by typing:

sage: bool(I^4 == 1)
True


But warning: if the expression is complicated and maxima is not able to decide wether it is True or False, then bool(expr) will return False.

A good advice is to avoid the symbolic ring as much as possible. For example, you can work in the algebraic field:

sage: QQbar(I)^4 == 1
True

more