Ask Your Question

Revision history [back]

In short

If you are interested in elements of a number field, like in your example with sqrt(5), you could do this:

sage: K.<a> = NumberField(x^2-5,'a',embedding=2.236)
sage: b = (1 + a)^100 / 2
sage: RR(b)
5.02034537778533e50

You see that b is roughly 5 * 10^50 so you want to compute with more than 50 decimal digits precision. In particular, 50 hexadecimal digits, ie 200 binary digits, would work.

sage: R = RealField(prec=200)
sage: R(b)
5.0203453777853342471068924069687121743561926939248060361200e50
sage: R(b).frac()
0.60361199639737606048583984375000000000000000000000000000000

This gives you an idea of the value modulo one. Exercise: how many digits are correct?

More details

We create the embedded number field K for sqrt(5).

sage: K.<a> = NumberField(x^2-5,'a',embedding=2.236)

Check that the generator squares to 5.

sage: a^2
5

Check that the embedding is the one with the positive square root of 5.

sage: a.is_real_positive()
True

Or:

sage: RR(a)
2.23606797749979

Compute b in K.

sage: b = (1+a)^100/2
sage: b
112258335352548699824296575003536617685648198860800*a +
251017268889266712355344620348435608717810034802688

Check how big it is.

sage: RR(b)
5.02034537778533e50

Work with the appropriate precision.

sage: R = RealField(prec=200)
sage: R(b)
5.0203453777853342471068924069687121743561926939248060361200e50
sage: R(b).frac()
0.60361199639737606048583984375000000000000000000000000000000

Hint for the exercise:

sage: RR(2^200/10^50)
1.60693804425899e10