ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 15 Oct 2013 16:49:17 +0200Comparing even powers of $i$ with 1https://ask.sagemath.org/question/10612/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?Tue, 15 Oct 2013 16:41:10 +0200https://ask.sagemath.org/question/10612/comparing-even-powers-of-i-with-1/Answer by tmonteil for <p>Computing $i^4$ yields $1$, but it's not the same $1$ as when I type $1$. Compare these two evaluations:</p>
<pre><code>sage: I^4 == 1
1 == 1
sage: I^2 == 1
-1 == 1
</code></pre>
<p>I would have expected the first to yield <code>True</code> and the second to yield <code>False</code>. Is Sage's answer a desirable default behavior? </p>
<p>I see that the first $1$ is a <code>sage.symbolic.expression.Expression</code> and the other $1$ is a <code>sage.rings.integer.Integer</code> (likewise for the $-1$). How can I make the comparison evaluate as one might reasonably expect mathematically?</p>
https://ask.sagemath.org/question/10612/comparing-even-powers-of-i-with-1/?answer=15541#post-id-15541Since `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
Tue, 15 Oct 2013 16:49:17 +0200https://ask.sagemath.org/question/10612/comparing-even-powers-of-i-with-1/?answer=15541#post-id-15541