Opened 7 years ago

Closed 7 years ago

#11952 closed defect (fixed)

Fix conversion Python -> PARI

Reported by: jdemeyer Owned by: was
Priority: major Milestone: sage-4.8
Component: interfaces Keywords:
Cc: Merged in: sage-4.8.alpha2
Authors: Jeroen Demeyer Reviewers: Robert Bradshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #11130, #11321, #11854, #11891, #11890, #11836 Stopgaps:

Description (last modified by jdemeyer)

Conversion of a Python complex to PARI fails:

sage: pari(complex(I))
  ***   Warning: unused characters: j.
1

Moreover, the conversion of other Python types to PARI can be improved by adding special code instead of using strings. This also makes the conversion more precise, see the example below:

Without patch:

sage: f = float(4651990089563211/4503599627370496)
sage: f
1.0329493015522242
sage: pari(f)
1.03294930155000

With patch:

sage: f = float(4651990089563211/4503599627370496)
sage: f
1.0329493015522242
sage: pari(f)
1.03294930155222

Attachments (1)

11952_python_to_pari.patch (10.5 KB) - added by jdemeyer 7 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130 to #11130, #11854
  • Status changed from new to needs_review

comment:2 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130, #11854 to #11130, #11854, #11904

comment:3 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130, #11854, #11904 to #11130, #11854, #11891, #11890, #11904

comment:4 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130, #11854, #11891, #11890, #11904 to #11130, #11321, #11854, #11891, #11890, #11904

comment:5 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130, #11321, #11854, #11891, #11890, #11904 to #11130, #11321, #11854, #11891, #11890, #11836, #11904

comment:6 Changed 7 years ago by jdemeyer

  • Status changed from needs_review to needs_work

Doctest failures in lseries_ell.py:

sage -t -long -force_lib "devel/sage/sage/schemes/elliptic_curves/lseries_ell.py"
  ***   Warning: new stack size = 1001728 (0.955 Mbytes).
  ***   Warning: new stack size = 1002624 (0.956 Mbytes).
  ***   Warning: new stack size = 1010736 (0.964 Mbytes).
  ***   Warning: new stack size = 1114144 (1.063 Mbytes).
  ***   Warning: new stack size = 1028720 (0.981 Mbytes).
  ***   Warning: new stack size = 1033680 (0.986 Mbytes).
**********************************************************************
File "/usr/local/src/sage-4.7.2.alpha2/devel/sage/sage/schemes/elliptic_curves/lseries_ell.py", line 459:
    sage: E.lseries().deriv_at1()
Expected:
    (0.305986660899342, 0.000800351433106958)
Got:
    (0.305986660898516, 0.000800351433106958)
**********************************************************************
File "/usr/local/src/sage-4.7.2.alpha2/devel/sage/sage/schemes/elliptic_curves/lseries_ell.py", line 461:
    sage: E.lseries().deriv_at1(100)
Expected:
    (0.305999773834879, 1.52437502288740e-45)
Got:
    (0.305999773834052, 1.52437502288740e-45)
**********************************************************************
File "/usr/local/src/sage-4.7.2.alpha2/devel/sage/sage/schemes/elliptic_curves/lseries_ell.py", line 463:
    sage: E.lseries().deriv_at1(1000)
Expected:
    (0.305999773834879, 0.000000000000000)
Got:
    (0.305999773834052, 0.000000000000000)
**********************************************************************

comment:7 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:8 Changed 7 years ago by jdemeyer

  • Status changed from needs_work to needs_review

comment:9 Changed 7 years ago by jdemeyer

  • Status changed from needs_review to needs_work

Conversion from int can be done without MPIR.

comment:10 Changed 7 years ago by jdemeyer

  • Status changed from needs_work to needs_review

comment:11 Changed 7 years ago by jdemeyer

  • Milestone sage-4.7.3 deleted

Milestone sage-4.7.3 deleted

comment:12 Changed 7 years ago by jdemeyer

  • Dependencies changed from #11130, #11321, #11854, #11891, #11890, #11836, #11904 to #11130, #11321, #11854, #11891, #11890, #11836
  • Milestone set to sage-4.8

comment:13 follow-up: Changed 7 years ago by robertwb

  • Status changed from needs_review to positive_review

Looks good to me (pending all doctests passing) and much cleaner. I checked the derivatives in lseries_ell.py to higher precision, the new values are correct.

Nit:

if PyBool_Check(s):
    return self.PARI_ONE if s else self.PARI_ZERO

Changed 7 years ago by jdemeyer

comment:14 in reply to: ↑ 13 Changed 7 years ago by jdemeyer

  • Reviewers set to Robert Bradshaw

Replying to robertwb:

if PyBool_Check(s):
    return self.PARI_ONE if s else self.PARI_ZERO

I made this small change.

comment:15 Changed 7 years ago by jdemeyer

  • Merged in set to sage-4.8.alpha2
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.