Ask Your Question
2

Comparing numbers in an algebraic field

asked 2014-11-12 20:25:40 +0200

updated 2015-07-31 18:15:50 +0200

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?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2014-11-12 22:44:28 +0200

tmonteil gravatar image

updated 2014-11-12 22:49:23 +0200

What bothers me is that, though Qb is defined with an embedding in $\mathbb{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
edit flag offensive delete link more

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 ( 2014-11-13 14:14:22 +0200 )edit
1

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

tmonteil gravatar imagetmonteil ( 2014-11-13 18:55:45 +0200 )edit
0

answered 2014-11-18 12:25:20 +0200

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).

edit flag offensive delete link more

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: 2014-11-12 20:25:40 +0200

Seen: 421 times

Last updated: Nov 18 '14