Opened 7 years ago

Closed 7 years ago

#15888 closed enhancement (fixed)

CC -> PARI: return t_REAL for real numbers

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-6.2
Component: interfaces Keywords:
Cc: pbruin Merged in:
Authors: Jeroen Demeyer Reviewers: Peter Bruin
Report Upstream: N/A Work issues:
Branch: 7067299 (Commits) Commit: 70672995f7b2e1b87d4d365396370e62ba10ae0a
Dependencies: Stopgaps:

Description

When converting Sage complex numbers to PARI, we should return a PARI t_REAL if the original number was actually real. This fixes a problem with ellwp() in #15767. In PARI's floating point model, the number 1e-19 + 0.0*I has less precision than the real 1e-19.

It is also consistent with the PARI philosophy of returning simplified types (examples: (1.1*I)^2 and ellj(1.1*I) in PARI gives real numbers).

Change History (12)

comment:1 Changed 7 years ago by jdemeyer

  • Branch set to u/jdemeyer/ticket/15888
  • Created changed from 03/05/14 10:38:07 to 03/05/14 10:38:07
  • Modified changed from 03/05/14 10:38:07 to 03/05/14 10:38:07

comment:2 Changed 7 years ago by jdemeyer

  • Commit set to 988c1f8870435bac8fb097e4d6a8aad62f84d19e
  • Status changed from new to needs_review

New commits:

988c1f8Improve conversion of complex numbers to PARI

comment:3 Changed 7 years ago by pbruin

It would seem to make sense to treat purely imaginary numbers similarly, by setting the real component to the t_INT 0, as PARI does. With your patch,

sage: pari(CC(1))
1.00000000000000
sage: pari(CC(I))
0.E-19 + 1.00000000000000*I
sage: _.debug()
[&=0000000004a45468] COMPLEX(lg=3):0c00000000000003 0000000004a45458 0000000004a45440 
  real = [&=0000000004a45458] REAL(lg=2):0400000000000002 (0,expo=-64):1fffffffffffffc0 
  imag = [&=0000000004a45440] REAL(lg=3):0400000000000003 (+,expo=0):6000000000000000 8000000000000000 
sage: pari('1.0*I')
1.00000000000000*I
sage: _.debug()
[&=000000000332b280] COMPLEX(lg=3):0c00000000000003 000000000332b270 000000000332b250 
  real = [&=000000000332b270] INT(lg=2):0200000000000002 (0,lgefint=2):0000000000000002 
  imag = [&=000000000332b250] REAL(lg=4):0400000000000004 (+,expo=0):6000000000000000 8000000000000000 0000000000000000 

comment:4 Changed 7 years ago by jdemeyer

  • Reviewers set to Peter Bruin
  • Status changed from needs_review to needs_work

comment:5 Changed 7 years ago by git

  • Commit changed from 988c1f8870435bac8fb097e4d6a8aad62f84d19e to d6fdd0c38bb021e6002154023ac3e64e3b910cf4

Branch pushed to git repo; I updated commit sha1. New commits:

d6fdd0cCC->PARI: convert purely imaginary numbers to t_COMPLEX with real part exactly 0

comment:6 Changed 7 years ago by jdemeyer

  • Status changed from needs_work to needs_review

comment:7 Changed 7 years ago by pbruin

There are a few doctest failures:

File "src/sage/schemes/elliptic_curves/heegner.py", line 3154, in sage.schemes.elliptic_curves.heegner.HeegnerPointOnEllipticCurve.numerical_approx
Failed example:
    P.numerical_approx()
Expected:
    (-6.68...e-16 + 1.41421356237310*I : 1.00000000000000 - 1.41421356237309*I : 1.00000000000000)
Got:
    (-6.67918322963967e-16 + 1.41421356237310*I : 1.00000000000000 - 1.41421356237309*I : 1.00000000000000)
**********************************************************************
File "src/sage/libs/pari/gen.pyx", line 4835, in sage.libs.pari.gen.gen.tan
Failed example:
    pari(i).tan()
Expected:
    0.E-19 + 0.761594155955765*I
Got:
    0.761594155955765*I
**********************************************************************
File "src/sage/libs/pari/gen.pyx", line 4855, in sage.libs.pari.gen.gen.tanh
Failed example:
    z = pari(i); z
Expected:
    0.E-19 + 1.00000000000000*I
Got:
    1.00000000000000*I
**********************************************************************
File "src/sage/libs/pari/gen.pyx", line 4940, in sage.libs.pari.gen.gen.weber
Failed example:
    pari(i).weber(1)
Expected:
    1.09050773266526 + 0.E-19*I
Got:
    1.09050773266526
**********************************************************************

comment:8 Changed 7 years ago by pbruin

  • Status changed from needs_review to needs_work

comment:9 Changed 7 years ago by git

  • Commit changed from d6fdd0c38bb021e6002154023ac3e64e3b910cf4 to 70672995f7b2e1b87d4d365396370e62ba10ae0a

Branch pushed to git repo; I updated commit sha1. New commits:

7067299CC->PARI conversion: fix doctest failures

comment:10 Changed 7 years ago by jdemeyer

  • Status changed from needs_work to needs_review

comment:11 Changed 7 years ago by pbruin

  • Status changed from needs_review to positive_review

comment:12 Changed 7 years ago by vbraun

  • Branch changed from u/jdemeyer/ticket/15888 to 70672995f7b2e1b87d4d365396370e62ba10ae0a
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.