Opened 6 years ago

Closed 6 years ago

#22319 closed defect (fixed)

Implement __index__ for PARI Gen

Reported by: Luca De Feo Owned by:
Priority: major Milestone: sage-7.6
Component: interfaces Keywords: PARI, coercion, rd3
Cc: Jeroen Demeyer, Vincent Delecroix Merged in:
Authors: Jeroen Demeyer Reviewers: Luca De Feo
Report Upstream: N/A Work issues:
Branch: 50593d6 (Commits, GitHub, GitLab) Commit: 50593d693c55e77ecf18459d8fd3baec047307e5
Dependencies: Stopgaps:

Status badges

Description (last modified by Luca De Feo)

Pari integers cannot be used to index lists:

sage: [1,2][pari(1)]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-f2823fec0752> in <module>()
----> 1 [Integer(1),Integer(2)][pari(Integer(1))]

TypeError: list indices must be integers, not sage.libs.cypari2.gen.Gen

With this ticket

sage: [1,2][pari(1)]
2

Incidentally, this also fixes pow

sage: 1^pari(1)
1

Change History (12)

comment:1 Changed 6 years ago by Jeroen Demeyer

Summary: Coercion broken in pow for PARI exponentsImplement __index__ for PARI Gen

comment:2 Changed 6 years ago by Jeroen Demeyer

Authors: Jeroen Demeyer

comment:3 Changed 6 years ago by Jeroen Demeyer

Branch: u/jdemeyer/implement___index___for_pari_gen

comment:4 Changed 6 years ago by Jeroen Demeyer

Commit: 0348e00f854a147baa36af3172a57c36878db4c9
Status: newneeds_review

New commits:

0348e00Implement __index__ for PARI Gen

comment:5 Changed 6 years ago by Luca De Feo

Status: needs_reviewneeds_work

This only solves part of the issue:

sage: 2^1.5
2.82842712474619
sage: 2^pari(1.5)
---------------------------------------------------------------------------
PariError                                 Traceback (most recent call last)
...
PariError: incorrect type in coercion to integer (t_REAL)

comment:6 in reply to:  5 Changed 6 years ago by Jeroen Demeyer

Status: needs_workneeds_review

Feel free to create a new ticket for other related issues.

comment:7 Changed 6 years ago by Jeroen Demeyer

Status: needs_reviewneeds_work

Although the exception type could be improved...

comment:8 Changed 6 years ago by git

Commit: 0348e00f854a147baa36af3172a57c36878db4c950593d693c55e77ecf18459d8fd3baec047307e5

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

50593d6Minor fixes to __index__

comment:9 Changed 6 years ago by Jeroen Demeyer

Status: needs_workneeds_review

comment:10 Changed 6 years ago by Luca De Feo

Description: modified (diff)
Reviewers: Luca De Feo
Status: needs_reviewpositive_review

I call this "ticket hijacking" :p

comment:11 Changed 6 years ago by Luca De Feo

Keywords: rd3 added

comment:12 Changed 6 years ago by Volker Braun

Branch: u/jdemeyer/implement___index___for_pari_gen50593d693c55e77ecf18459d8fd3baec047307e5
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.