The way Sage compares number field elements has nothing to do with any
embeddings of the field into R.  It cannot, really, since not all
fields have real embeddings and many have more than one.  The
comparison being used by expressions such as "u > 1" is based on
something like a lexicographic ordering of the coordinates of the
element with respect to a basis for the field.

I would recommend that you make the embedding explicit, e.g. by

sage: emb = K.embeddings(RR)[0]

and then comparing emb(a) with emb(b), or test positivity with
emb(a)>0, and so on.  That is surely safest.  It's probably OK to use
RR(a) where coercion is used to map a into RR, but you do have to
think about which embedding the coercion system will use.  Fine if you
get that right, but why not be explicit.

John

On May 1, 1:55 pm, Samuel Lelievre <[email protected]> wrote:
> Hello,
>
> I use elements in a totally real quadratic extension K of QQ.
> I specify the embedding, so elements in K can be evaluated.
> I want to use this to compare elements, but it gets confusing.
> Apparently '>' always gives true, and '<' always gives False.
>
> sage: var('u z')
> sage: K.<u> = NumberField(x**2 - x - 1, embedding=1.6)
> sage: u, u.n(), u > 0
> (u, 1.61803398874989, True)
> sage: -u, -u.n(), -u > 0
> (-u, -1.61803398874989, True)
> sage: u > -u
> True
> sage: -u > u
> True
> sage: u > 1
> True
> sage: 1 > u
> True
> sage: 1 < u
> False
> sage: u < 1
> False
> sage: z = -2*u+3
> sage: z
> -2*u + 3
> sage: z.n()
> -0.236067977499790
> sage: RR(z)
> -0.236067977499790
> sage: z > 0
> True
> sage: z.n() > 0
> False
> sage: RR(z) > 0
> False
> sage: zz = 3*u - 5
> sage: zz.n()
> -0.145898033750315
> sage: zz > 0
> True
>
> How does Sage compare elements of K?
> Is 'RR(z) > 0' the recommended way to test whether z is positive?
>
> Samuel

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to