Opened 15 years ago

Closed 14 years ago

## #2551 closed defect (fixed)

# [fixed by #5508] `__getitem__` for relative number field elements is ... now fixed

Reported by: | Craig Citro | Owned by: | William Stein |
---|---|---|---|

Priority: | minor | Milestone: | sage-3.4.1 |

Component: | number theory | Keywords: | |

Cc: | Merged in: | ||

Authors: | Reviewers: | ||

Report Upstream: | N/A | Work issues: | |

Branch: | Commit: | ||

Dependencies: | Stopgaps: |

### Description

Indexing into a relative number field element does unexpected things:

sage: K Number Field in b with defining polynomial x^3 - 5 over its base field sage: K([1,2,3]) 3*b^2 + (-6*a + 2)*b - 2*a + 7 sage: K([1,2,3])[0] 1 sage: K([1,2,3])[1] 2 sage: K([1,2,3]).list() [-2*a + 7, -6*a + 2, 3] sage: K([1,2,3]).list()[0] -2*a + 7 sage: K([1,2,3]).polynomial() 3*x^2 + 2*x + 1

The issue is that it's giving you the entries in the representation of the element as an *absolute* number field element. It should be fixed.

### Change History (5)

### comment:1 Changed 14 years ago by

Summary: | `__getitem__` for relative number field elements is ... surprising → [fixed subject to review of #5508] `__getitem__` for relative number field elements is ... now fixed |
---|

### comment:2 follow-up: 4 Changed 14 years ago by

Summary: | [fixed subject to review of #5508] `__getitem__` for relative number field elements is ... now fixed → [fixed by #5508] `__getitem__` for relative number field elements is ... now fixed |
---|

To close this we would need a doctest.

Cheers,

Michael

### comment:3 Changed 14 years ago by

Milestone: | sage-3.4.2 → sage-3.4.1 |
---|

### comment:4 Changed 14 years ago by

Replying to mabshoff:

To close this we would need a doctest.

See lines 2421 to 2445 of sage/rings/number_field/number_field_element.pyx as patched by #5508:

EXAMPLES:: sage: K.<a, b> = NumberField([x^3 - 5, x^2 + 3]) sage: c = (a + b)^3; c 3*b*a^2 - 9*a - 3*b + 5 sage: c[0] -3*b + 5 We illustrate bounds checking:: sage: c[-1] Traceback (most recent call last): ... IndexError: index must be between 0 and the relative degree minus 1. sage: c[4] Traceback (most recent call last): ... IndexError: index must be between 0 and the relative degree minus 1. The list method implicitly calls ``__getitem__``:: sage: list(c) [-3*b + 5, -9, 3*b] sage: K(list(c)) == c True

### comment:5 Changed 14 years ago by

Resolution: | → fixed |
---|---|

Status: | new → closed |

**Note:**See TracTickets for help on using tickets.

This is sorted out by the patch in #5508, in particular the changes there to

`__getitem__`

for the class`NumberFieldElement_relative`

in`sage/rings/number_field/number_field_element.pyx`

.