1 | initial version |
This comes from working with numerical approximations.
In the computer, a
and b
are represented in binary.
They are very close but not equal.
sage: a.sign_mantissa_exponent()
(1, 11133510565745312, -54)
sage: b.sign_mantissa_exponent()
(1, 11133510565745310, -54)
But the difference is very small and their decimal expansions to 15 digits coincide.
Sage lets you work with exact algebraic numbers, either by creating a number field:
sage: K.<a> = NumberField(x^2 + x - 1, embedding=0.6)
sage: a.numerical_approx()
0.618033988749895
sage: 1 - a^2
a
or by using the field of algebraic number (QQbar
in Sage):
sage: a = QQbar(1/2*sqrt(5) - 1/2)
sage: a
0.618033988749895?
sage: 1 - a^2 == a
True
sage: a.minpoly()
x^2 + x - 1
sage: a.numerical_approx()
0.618033988749895
sage: a.radical_expression()
1/2*sqrt(5) - 1/2