Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberField embedding slightly off #7598

Closed
mwhansen opened this issue Dec 4, 2009 · 16 comments
Closed

NumberField embedding slightly off #7598

mwhansen opened this issue Dec 4, 2009 · 16 comments

Comments

@mwhansen
Copy link
Contributor

mwhansen commented Dec 4, 2009

sage: Q.<i> = NumberField(x^2+1)
sage: complex(i)
0.99999999999999967j

It should give 1j instead.

CC: @burcin

Component: number fields

Author: William Stein

Reviewer: Mike Hansen, John Cremona

Merged: sage-4.3.rc1

Issue created by migration from https://trac.sagemath.org/ticket/7598

@mwhansen
Copy link
Contributor Author

comment:3

This is probably caused by the roots method using NumPy which uses Fortran which is a little off. If you specify algorithm='pari' to the roots command when computing them, things should be fine.

sage: Q.<i> = NumberField(x^2+1)
sage: Q.defining_polynomial().change_ring(CC).roots()[1][0].imag().exact_rational()
9007199254740989/9007199254740992
sage: Q.defining_polynomial().change_ring(ComplexField(100)).roots()[1][0].imag().exact_rational()
1

Note that NumPy is not used for the second example.

@williamstein
Copy link
Contributor

comment:4

Attachment: trac_7598-more_serious_version.patch.gz

trac_7598-more_serious_version.patch -- this deals with the problems more at the root. Unfortunately, there are doctests in this file that fail:

	sage -t  devel/sage-main/sage/modular/dirichlet.py # 4 doctests failed

and I haven't had time to figure out what is wrong. It probably has to do with a complex embedding not being defined automatically, whereas before it was...

The design of embeddings was really bad before and relied on numerical errors to mess up the order of roots in case of 53 bit precision. This was potentially very buggy and was I think the result of some absolutely terrible design decisions. This absolutely must be fixed before releasing sage-4.3. This patch basically fixes it, modulo some small remaining issue.

Here is an example from sage-4.2.1 that illustrates just how horrendously bad the previous design was (with using CDF when prec=53 but ComplexField(prec) otherwise):

sage: K.<i> = QuadraticField(-1)
sage: i.complex_em
i.complex_embedding   i.complex_embeddings  
sage: i.complex_embedding()
1.0*I
sage: i.complex_embedding(100)
-1.0000000000000000000000000000*I

@mwhansen
Copy link
Contributor Author

comment:5

I think the errors in dirichlet.py comes from the following:

sage: a = mod(1,3)
sage: CDF.zeta(3)^a
-0.5 + 0.866025403784*I
sage: CC.zeta(3)^a
---------------------------------------------------------------------------
Traceback (most recent call last)
...
TypeError: unable to coerce <type 'sage.rings.complex_number.ComplexNumber'> to an integer

It'd be nice if the {{{pow}} methods were standardized.

@mwhansen
Copy link
Contributor Author

Attachment: trac_7598-dirichlet.patch.gz

@mwhansen
Copy link
Contributor Author

comment:6

I've added a patch which fixes the errors in dirichlet.py by just forcing the exponent to be an int.

William's changes look good to me so the only thing that needs review is trac_7598-dirichlet.patch.

We should open another ticket for the __pow__ discrepencies.

@mwhansen
Copy link
Contributor Author

Author: William Stein

@mwhansen
Copy link
Contributor Author

Reviewer: Mike Hansen

@JohnCremona
Copy link
Member

comment:7

Do we need to apply both patches? Or is it that Mike has given a positive review to the first and only needs a review of the second? I was hoping to test this (being someone who experienced the problems) but as it will take a long time to rebuild, I want to make sure that the time is not wasted.

@mwhansen
Copy link
Contributor Author

comment:8

You need to apply both patches. I've given a positive review to the first. The second is pretty easy since it makes the exponent an integer instead of an integermod.

@aghitza
Copy link

aghitza commented Dec 15, 2009

comment:9

Running long doctests on a 32-bit Arch Linux machine gives one doctest failure related to this ticket:

sage -t -long "devel/sage/doc/en/bordeaux_2008/nf_galois_groups.rst"
**********************************************************************
File "/opt/sage-4.3.rc0/devel/sage/doc/en/bordeaux_2008/nf_galois_groups.rst", line 109:
    sage: K.complex_embeddings()
Expected:
    [
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Double Field
      Defn: a |--> -0.629960524947 - 1.09112363597*I,
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Double Field
      Defn: a |--> -0.629960524947 + 1.09112363597*I,
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Double Field
      Defn: a |--> 1.25992104989
    ]
Got:
    [
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Field with 53 bits of precision
      Defn: a |--> -0.629960524947437 - 1.09112363597172*I,
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Field with 53 bits of precision
      Defn: a |--> -0.629960524947437 + 1.09112363597172*I,
    Ring morphism:
      From: Number Field in a with defining polynomial x^3 - 2
      To:   Complex Field with 53 bits of precision
      Defn: a |--> 1.25992104989487
    ]
**********************************************************************
1 items had failures:
   1 of   4 in __main__.example_3
***Test Failed*** 1 failures.
For whitespace errors, see the file /home/ghitza/.sage//tmp/.doctest_nf_galois_groups.py
	 [5.9 s]
exit code: 1024

Apart from this small issue, everything looks good.

@aghitza
Copy link

aghitza commented Dec 15, 2009

comment:10

OK, I've added a trivial patch that fixes the last doctest failure.

@aghitza
Copy link

aghitza commented Dec 15, 2009

Attachment: trac_7598-nf_galois_groups.patch.gz

apply after the previous two patches

@JohnCremona
Copy link
Member

comment:12

Applied all 3 patches to 4.3.rc0 on both 32-bit Suse (built using system gfortran) and 64-bit ubuntu (using Sage's gfortran). No problems. All tests in the files touched pass. I still get a failure in doc/en/bordeaux_2008/nf_introduction.rst but that has a different cause.

So, positive review.

@JohnCremona
Copy link
Member

Changed reviewer from Mike Hansen to Mike Hansen, John Cremona

@mwhansen
Copy link
Contributor Author

comment:13

Excellent. I'm glad we (you guys) tracked that down. I'm not sure why I didn't think that the number field was just using the alternate embedding.

@mwhansen
Copy link
Contributor Author

Merged: sage-4.3.rc1

@mwhansen mwhansen modified the milestones: sage-4.3.1, sage-4.3 Dec 15, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants