Opened 3 years ago

# Coercion of multivariate polynomials over padics

Reported by: Owned by: edgarcosta major sage-9.7 padics alexjbest N/A

```sage:PolynomialRing(Qp(2), 3, 'x')({(0,0,0):O(2)}).dict()
{}
```

instead of `{(0,0,0):O(2)}`

As a side effect substitution and addition is also broken:

```sage: R.<x,y,z> = Qp(2)[]
sage: f = x  + y + z - 1
sage: f.dict()
{(0, 0, 0): 1 + 2 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9 + 2^10 + 2^11 + 2^12 + 2^13 + 2^14 + 2^15 + 2^16 + 2^17 + 2^18 + 2^19 + O(2^20),
(0, 0, 1): 1 + O(2^20),
(0, 1, 0): 1 + O(2^20),
(1, 0, 0): 1 + O(2^20)}
{(0, 0, 1): 1 + O(2^20), (0, 1, 0): 1 + O(2^20)}
{(0, 0, 1): 1 + O(2^20), (0, 1, 0): 1 + O(2^20)}
```

While I would expect: `{(0, 0, 1): 1 + O(2^20), (0, 1, 0): 1 + O(2^20), (0,0,0): O(2)}` and

```sage: (f + (1 + O(2))).dict()
{(1, 0, 0): 1 + O(2^20), (0, 0, 1): 1 + O(2^20), (0, 1, 0): 1 + O(2^20)}
```

Alex Best, pointed out that most likely this has to do with a key removal being done with `if blah == 0:` instead of `if blah.is_zero()`

### comment:1 Changed 3 years ago by edgarcosta

• Description modified (diff)

### comment:2 Changed 3 years ago by alexjbest

The problem is in the PolyDict? add function calls the PolyDict? constructor with zero=K.zero() and remove_zeroes=True, this is quite awkward as it makes it hard to fix this while maintaining that variables with exact zero coefficient removed. Maybe this should be changed so that if PolyDict? constructor is called with remove_zeroes=True then the base ring `.is_zero()` method is called. Possibly this is a performance hit though?

the offending lines are

```if pdict[k] == zero:
del pdict[k]
```

in sage/rings/polynomial/polydict.pyx

As for the constructor issue, it is the same with line `x = polydict.PolyDict(x, parent.base_ring()(0), remove_zero=True)` in `sage/rings/polynomial/multi_polynomial_element.py` that does it.

Last edited 3 years ago by alexjbest (previous) (diff)

### comment:3 Changed 3 years ago by edgarcosta

Essentially the issue is that O(2) == 0 is true and a notion of exact zero should be used instead, I notice that there is a function _is_exact_zero but also x.is_zero(absprec=Infinity) for p-adic elements, are either of these suitable for a fix?

On side a note, univariate polynomials seem to do the right thing:

```sage: f = PolynomialRing(Qp(2),'a')([O(2),O(2^3)])
sage: f
O(2^3)*a + O(2)
```

### comment:4 Changed 2 years ago by embray

• Milestone changed from sage-9.0 to sage-9.1

Ticket retargeted after milestone closed

### comment:5 Changed 2 years ago by mkoeppe

• Milestone changed from sage-9.1 to sage-9.2

Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.

### comment:6 Changed 22 months ago by mkoeppe

• Milestone changed from sage-9.2 to sage-9.3

### comment:7 Changed 17 months ago by mkoeppe

• Milestone changed from sage-9.3 to sage-9.4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

### comment:8 Changed 12 months ago by mkoeppe

• Milestone changed from sage-9.4 to sage-9.5

### comment:9 Changed 7 months ago by mkoeppe

• Milestone changed from sage-9.5 to sage-9.6

### comment:10 Changed 2 months ago by mkoeppe

• Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.