Opened 20 months ago

Last modified 4 months ago

#28609 new defect

Coercion of multivariate polynomials over padics

Reported by: edgarcosta Owned by:
Priority: major Milestone: sage-9.4
Component: padics Keywords:
Cc: alexjbest Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by edgarcosta)

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)}
sage: f.substitute(x=Qp(2)(1).add_bigoh(1)).dict()
{(0, 0, 1): 1 + O(2^20), (0, 1, 0): 1 + O(2^20)}
sage: f((Qp(2)(1).add_bigoh(1),y,z)).dict()
{(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()

Change History (7)

comment:1 Changed 20 months ago by edgarcosta

  • Description modified (diff)

comment:2 Changed 20 months 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 20 months ago by alexjbest (previous) (diff)

comment:3 Changed 20 months ago by edgarcosta

Alex asked today about this ticket at the p-adics meeting on zulip.

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?

Julian mentioned there's at least one more ticket about this somewhere

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 18 months ago by embray

  • Milestone changed from sage-9.0 to sage-9.1

Ticket retargeted after milestone closed

comment:5 Changed 14 months 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 10 months ago by mkoeppe

  • Milestone changed from sage-9.2 to sage-9.3

comment:7 Changed 4 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.

Note: See TracTickets for help on using tickets.