Opened 7 years ago

Last modified 7 years ago

#17741 needs_work enhancement

Polynomial __div__ override redundant with coercion.

Reported by: robertwb Owned by:
Priority: major Milestone: sage-6.9
Component: coercion Keywords:
Cc: Merged in:
Authors: Robert Bradshaw Reviewers:
Report Upstream: N/A Work issues:
Branch: public/17741 (Commits, GitHub, GitLab) Commit: f5a59a3400508531d6d19803dc277c01e896f8d8
Dependencies: #17740 Stopgaps:

Status badges

Description

We no longer need to special case this now that #17740 is fixed.

Change History (10)

comment:1 Changed 7 years ago by robertwb

  • Branch set to u/robertwb/poly-div

comment:2 Changed 7 years ago by robertwb

  • Commit set to 69962b6b5428e1c7935c2c6becfa639d57246dc7
  • Status changed from new to needs_review

comment:3 Changed 7 years ago by mmezzarobba

  • Status changed from needs_review to needs_work

(I didn't try #17740 separately.)

File "src/sage/rings/polynomial/padics/polynomial_padic.py", line 84, in sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic.factor
Failed example:
    for p,e in pol.factor(): print e, p
Exception raised:
    Traceback (most recent call last):
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 488, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 850, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic.factor[2]>", line 1, in <module>
        for p,e in pol.factor(): print e, p
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/padics/polynomial_padic.py", line 158, in factor
        absprec = min([x.precision_absolute() for x in self_normal])
    TypeError: 'FractionFieldElement_1poly_field' object is not iterable
File "src/sage/rings/padics/padic_generic.py", line 465, in sage.rings.padics.padic_generic.pAdicGeneric.extension
Failed example:
    F = list(Qp(19)['x'](cyclotomic_polynomial(5)).factor())[0][0]
Exception raised:
    Traceback (most recent call last):
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 488, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 850, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.padics.padic_generic.pAdicGeneric.extension[3]>", line 1, in <module>
        F = list(Qp(Integer(19))['x'](cyclotomic_polynomial(Integer(5))).factor())[Integer(0)][Integer(0)]
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/padics/polynomial_padic.py", line 158, in factor
        absprec = min([x.precision_absolute() for x in self_normal])
    TypeError: 'FractionFieldElement_1poly_field' object is not iterable
File "src/sage/rings/multi_power_series_ring_element.py", line 2024, in sage.rings.multi_power_series_ring_element.MPowerSeries.log
Failed example:
    log(1+a)
Exception raised:
    Traceback (most recent call last):
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 488, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 850, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.multi_power_series_ring_element.MPowerSeries.log[10]>", line 1, in <module>
        log(Integer(1)+a)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/functions/log.py", line 313, in __call__
        return GinacFunction.__call__(self, *args, **kwds)
      File "sage/symbolic/function.pyx", line 843, in sage.symbolic.function.GinacFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:9047)
        res = super(GinacFunction, self).__call__(*args, **kwds)
      File "sage/symbolic/function.pyx", line 983, in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:10379)
        res = method()
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/multi_power_series_ring_element.py", line 2059, in log
        return R(result_bg, prec=prec)
      File "sage/structure/parent.pyx", line 1096, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9486)
        return mor._call_with_args(x, args, kwds)
      File "sage/structure/coerce_maps.pyx", line 129, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (build/cythonized/sage/structure/coerce_maps.c:4817)
        raise
      File "sage/structure/coerce_maps.pyx", line 119, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_with_args (build/cythonized/sage/structure/coerce_maps.c:4641)
        return C._element_constructor(x, **kwds)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/multi_power_series_ring.py", line 791, in _element_constructor_
        return self.element_class(parent=self, x=f, prec=prec)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/multi_power_series_ring_element.py", line 378, in __init__
        self._bg_value = parent._send_to_bg(x).add_bigoh(prec)
      File "/home/marc/co/sage/local/lib/python2.7/site-packages/sage/rings/multi_power_series_ring.py", line 1025, in _send_to_bg
        raise TypeError("Cannot coerce input to polynomial ring.")
    TypeError: Cannot coerce input to polynomial ring.
File "src/sage/rings/polynomial/multi_polynomial_libsingular.pyx", line 2350, in sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular._div_
Failed example:
    x/3
Expected:
    Traceback (most recent call last):
    ...
    TypeError: self must be an integral domain.
Got:
    -341*x

comment:4 Changed 7 years ago by git

  • Commit changed from 69962b6b5428e1c7935c2c6becfa639d57246dc7 to 2372d53d149a02b6d421b5a469f573126eb52a11

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

7744207Better behavior for polynomial division.
1e88c72Another polynomial division action test.
7fd72c7Merge branch 'coerce-div' into poly-div
2372d53Fix a couple of tests.

comment:5 Changed 7 years ago by robertwb

  • Status changed from needs_work to needs_review

comment:6 Changed 7 years ago by git

  • Commit changed from 2372d53d149a02b6d421b5a469f573126eb52a11 to b63e8f8d841a6386a822f8531ae9eb633c5fe3b5

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

a60134ctrac #17740: review 1 (documentation)
728811dtrac #17740: review 2 (clean Errors)
96c1a03trac #17740: review 3 (less in try/except block)
2cb51c0Re-introduce action of fraction field as fallback for division action.
b63e8f8Merge branch 'coerce-div' into 17741-poly-div

comment:7 Changed 7 years ago by git

  • Commit changed from b63e8f8d841a6386a822f8531ae9eb633c5fe3b5 to 830460a4767e467087d0ed76d14232cdc7da635f

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

bff474bBetter _pseudo_fraction_field default implementation.
830460aMerge branch '17740-coerce-div' into 17741-poly-div

comment:8 Changed 7 years ago by vdelecroix

  • Status changed from needs_review to needs_work

Got one doctest failing

sage -t --long src/sage/rings/finite_rings/integer_mod_ring.py
**********************************************************************
File "src/sage/rings/finite_rings/integer_mod_ring.py", line 807, in sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic._pseudo_fraction_field
Failed example:
    (x+5)/2
Exception raised:
    Traceback (most recent call last)
    ...
sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic._pseudo_fraction_field[3]>", line 1, in <module>
        (x+Integer(5))/Integer(2)
      File "sage/structure/element.pyx", line 1973, in sage.structure.element.RingElement.__div__ (build/cythonized/sage/structure/element.c:18228)
        return coercion_model.bin_op(self, right, div)
      File "sage/structure/coerce.pyx", line 802, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:7201)
        raise
      File "sage/structure/coerce.pyx", line 798, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:7148)
        return PyObject_CallObject(op, xy)
      File "sage/structure/element.pyx", line 1971, in sage.structure.element.RingElement.__div__ (build/cythonized/sage/structure/element.c:18210)
        return (<RingElement>self)._div_(<RingElement>right)
      File "sage/structure/element.pyx", line 1981, in sage.structure.element.RingElement._div_ (build/cythonized/sage/structure/element.c:18365)
        return self._parent.fraction_field()(self, right)
      File "sage/rings/ring.pyx", line 1226, in sage.rings.ring.CommutativeRing.fraction_field (build/cythonized/sage/rings/ring.c:10158)
    TypeError: self must be an integral domain.

comment:9 Changed 7 years ago by vdelecroix

  • Branch changed from u/robertwb/poly-div to public/17741
  • Commit changed from 830460a4767e467087d0ed76d14232cdc7da635f to f5a59a3400508531d6d19803dc277c01e896f8d8
  • Milestone changed from sage-6.5 to sage-6.9
  • Status changed from needs_work to needs_review

rebased on sage-6.9.beta1


New commits:

f88dd38Remove redundant __div__ operator.
f5a59a3Fix a couple of tests for padics.

comment:10 Changed 7 years ago by vdelecroix

  • Status changed from needs_review to needs_work

I still get the error as in 8. Though the following works well

sage: R.<x> = Integers(15)[]
sage: (x+5) / R.base_ring()(2)
8*x + 10

and one can check

sage: cm = get_coercion_model()
sage: R.<x> = Integers(15)[]
sage: a = cm.get_action(R, R.base_ring(), operator.div)
sage: a(x+5,2)
8*x + 10

The problem is when we divide by an integer

sage: cm.get_action(R, ZZ, operator.div)
<NOTHING>

The above fails because the following does

sage: cm = get_coercion_model()
sage: R.<x> = Integers(15)[]
sage: right_mul = cm.get_action(R, ZZ, operator.mul)
sage: action = ~right_mul
Traceback (most recent call last):
...
CoercionException: x (=Ring of integers modulo 15) is not in Category of integral domains
Last edited 7 years ago by vdelecroix (previous) (diff)
Note: See TracTickets for help on using tickets.