First time here? Check out the FAQ!

Ask Your Question
2

Comparing numbers in an algebraic field

asked 10 years ago

updated 9 years ago

FrédéricC gravatar image

I get a very strange results from comparison of number in an algebraic field, see the example:

version()
X = polygen(ZZ)
f = X^3 - 2*X^2 - 2*X - 2
Qb.<b> = QQ.extension(f, embedding=3)

b.N() # b is positive
0 < b # gives False; why?
0 < 1 # gives True; fine
Qb(0) < Qb(1) # gives False; WTF?

sage: version()
'Sage Version 6.1.1, Release Date: 2014-02-04'
sage: X = polygen(ZZ)
sage: f = X^3 - 2*X^2 - 2*X - 2
sage: Qb.<b> = QQ.extension(f, embedding=3)
sage: 
sage: b.N() # b is positive
2.91963956583942
sage: 0 < b # gives False; why?
False
sage: 0 < 1 # gives True; fine
True
sage: Qb(0) < Qb(1) # gives False; WTF?
False
sage:

Can I do something to obtain the correct results of comparison, or is using the flawed .N() the only option?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

What bothers me is that, though Qb is defined with an embedding in C, there is no canonical coercion from Qb to QQbar, as if the information of the embedding was lost (ideally, there should be a difference between "number field" and "embedded number field", even two different parents):

sage: cm = sage.structure.element.get_coercion_model()
sage: cm.common_parent(Qb,QQbar)
TypeError: no common canonical parent for objects with parents: 'Number Field in b with defining polynomial x^3 - 2*x^2 - 2*x - 2' and 'Algebraic Field'

Not even a conversion:

sage: QQbar(b)
TypeError: Illegal initializer for algebraic number
sage: AA(b)
TypeError: Illegal initializer for algebraic number

That said, the following workaround to consider b as a real algebraic number could do the job:

sage: Qb.embeddings(AA)
[
Ring morphism:
  From: Number Field in b with defining polynomial x^3 - 2*x^2 - 2*x - 2
  To:   Algebraic Real Field
  Defn: b |--> 2.919639565839419?
]
sage: bb = Qb.embeddings(AA)[0](b) ; bb
2.919639565839419?
sage: 0 < bb
True
Preview: (hide)
link

Comments

Thanks Thierry. Actually what is even stranger is that `floor(x-y)>=0` works well in place of `x>=y`. The problem with `AA` is that there seem to be some memory leaks :-/

tohecz gravatar imagetohecz ( 10 years ago )
1

Hi Tom, could you please provide more info on the memory leaks ? This will help in improving Sage source code.

tmonteil gravatar imagetmonteil ( 10 years ago )
0

answered 10 years ago

slelievre gravatar image

Comparison in number fields is not satisfactory in Sage.

The current implementation (except in some special cases) seems to be that

  • > always returns True,
  • < always returns False.

That is the case with b defined as in your example:

sage: b > 0
True
sage: 0 > b
True
sage: b < 0
False
sage: 0 < b
False

Comparison works well in quadratic number fields since ticket #13213.

The method is_real_positive() from ticket #8347 works in some number fields (but unfortunately not in the field Qb in your question).

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 559 times

Last updated: Nov 18 '14