Skip to content

Commit b8a75b6

Browse files
author
Release Manager
committed
Trac #12696: rename .rational_reconstruct() to .rational_reconstruction() for consistency
For integers modulo n there is a {{{rational_reconstruction}}} method: {{{ sage: R = IntegerModRing(97) sage: a = R(2) / R(3) sage: a.rational_reconstruction() 2/3 }}} However for polynomials the corresponding method is named {{{rational_reconstruct}}}: {{{ sage: K.<x> = R[] sage: x.rational_reconstruct(x,4,4) (0, 1) }}} The naming is incoherent. URL: https://trac.sagemath.org/12696 Reported by: zimmerma Ticket author(s): Lorenz Panny Reviewer(s): Kwankyu Lee
2 parents 144d521 + 47c91ea commit b8a75b6

File tree

7 files changed

+58
-28
lines changed

7 files changed

+58
-28
lines changed

src/sage/rings/polynomial/polynomial_element.pyx

+21-19
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ from sage.misc.cachefunc import cached_function
126126
from sage.categories.map cimport Map
127127
from sage.categories.morphism cimport Morphism
128128

129-
from sage.misc.superseded import deprecation_cython as deprecation
129+
from sage.misc.superseded import deprecation_cython as deprecation, deprecated_function_alias
130130
from sage.misc.cachefunc import cached_method
131131

132132
from sage.rings.number_field.order import is_NumberFieldOrder
@@ -8925,7 +8925,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
89258925
else:
89268926
raise NotImplementedError("%s does not provide an xgcd implementation for univariate polynomials"%self.base_ring())
89278927

8928-
def rational_reconstruct(self, m, n_deg=None, d_deg=None):
8928+
def rational_reconstruction(self, m, n_deg=None, d_deg=None):
89298929
r"""
89308930
Return a tuple of two polynomials ``(n, d)``
89318931
where ``self * d`` is congruent to ``n`` modulo ``m`` and
@@ -8950,7 +8950,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
89508950
sage: z = PolynomialRing(QQ, 'z').gen()
89518951
sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1
89528952
sage: m = z**21
8953-
sage: n, d = p.rational_reconstruct(m)
8953+
sage: n, d = p.rational_reconstruction(m)
89548954
sage: print((n ,d))
89558955
(z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1)
89568956
sage: print(((p*d - n) % m ).is_zero())
@@ -8961,7 +8961,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
89618961
sage: z = PolynomialRing(ZZ, 'z').gen()
89628962
sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1
89638963
sage: m = z**21
8964-
sage: n, d = p.rational_reconstruct(m)
8964+
sage: n, d = p.rational_reconstruction(m)
89658965
sage: print((n ,d))
89668966
(z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1)
89678967
sage: print(((p*d - n) % m ).is_zero())
@@ -8973,12 +8973,12 @@ cdef class Polynomial(CommutativeAlgebraElement):
89738973
sage: x = P.gen()
89748974
sage: p = 7*x^5 - 10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256
89758975
sage: m = x^5
8976-
sage: n, d = p.rational_reconstruct(m, 3, 2)
8976+
sage: n, d = p.rational_reconstruction(m, 3, 2)
89778977
sage: print((n ,d))
89788978
(-32*x^3 + 384*x^2 + 2304*x + 2048, 5*x + 8)
89798979
sage: print(((p*d - n) % m ).is_zero())
89808980
True
8981-
sage: n, d = p.rational_reconstruct(m, 4, 0)
8981+
sage: n, d = p.rational_reconstruction(m, 4, 0)
89828982
sage: print((n ,d))
89838983
(-10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256, 1)
89848984
sage: print(((p*d - n) % m ).is_zero())
@@ -8993,7 +8993,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
89938993
sage: # p = (1 + t^2*z + z^4) / (1 - t*z)
89948994
sage: p = (1 + t^2*z + z^4)*(1 - t*z).inverse_mod(z^9)
89958995
sage: m = z^9
8996-
sage: n, d = p.rational_reconstruct(m)
8996+
sage: n, d = p.rational_reconstruction(m)
89978997
sage: print((n ,d))
89988998
(-1/t*z^4 - t*z - 1/t, z - 1/t)
89998999
sage: print(((p*d - n) % m ).is_zero())
@@ -9002,7 +9002,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
90029002
sage: n = -10*t^2*z^4 + (-t^2 + t - 1)*z^3 + (-t - 8)*z^2 + z + 2*t^2 - t
90039003
sage: d = z^4 + (2*t + 4)*z^3 + (-t + 5)*z^2 + (t^2 + 2)*z + t^2 + 2*t + 1
90049004
sage: prec = 9
9005-
sage: nc, dc = Pz((n.subs(z = w)/d.subs(z = w) + O(w^prec)).list()).rational_reconstruct(z^prec)
9005+
sage: nc, dc = Pz((n.subs(z = w)/d.subs(z = w) + O(w^prec)).list()).rational_reconstruction(z^prec)
90069006
sage: print( (nc, dc) == (n, d) )
90079007
True
90089008
@@ -9014,7 +9014,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
90149014
sage: # p = (1 + t^2*z + z^4) / (1 - t*z) mod z^9
90159015
sage: p = (1 + t^2*z + z^4) * sum((t*z)**i for i in range(9))
90169016
sage: m = z^9
9017-
sage: n, d = p.rational_reconstruct(m,)
9017+
sage: n, d = p.rational_reconstruction(m,)
90189018
sage: print((n ,d))
90199019
(-z^4 - t^2*z - 1, t*z - 1)
90209020
sage: print(((p*d - n) % m ).is_zero())
@@ -9025,7 +9025,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
90259025
sage: x = PolynomialRing(Qp(5),'x').gen()
90269026
sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2
90279027
sage: m = x^6
9028-
sage: n, d = p.rational_reconstruct(m, 3, 2)
9028+
sage: n, d = p.rational_reconstruction(m, 3, 2)
90299029
sage: print(((p*d - n) % m ).is_zero())
90309030
True
90319031
@@ -9036,34 +9036,34 @@ cdef class Polynomial(CommutativeAlgebraElement):
90369036
sage: x = P.gen()
90379037
sage: p = P(exp(z).list())
90389038
sage: m = x^5
9039-
sage: n, d = p.rational_reconstruct(m, 4, 0)
9039+
sage: n, d = p.rational_reconstruction(m, 4, 0)
90409040
sage: print((n ,d))
90419041
(1/24*x^4 + 1/6*x^3 + 1/2*x^2 + x + 1, 1)
90429042
sage: print(((p*d - n) % m ).is_zero())
90439043
True
90449044
sage: m = x^3
9045-
sage: n, d = p.rational_reconstruct(m, 1, 1)
9045+
sage: n, d = p.rational_reconstruction(m, 1, 1)
90469046
sage: print((n ,d))
90479047
(-x - 2, x - 2)
90489048
sage: print(((p*d - n) % m ).is_zero())
90499049
True
90509050
sage: p = P(log(1-z).list())
90519051
sage: m = x^9
9052-
sage: n, d = p.rational_reconstruct(m, 4, 4)
9052+
sage: n, d = p.rational_reconstruction(m, 4, 4)
90539053
sage: print((n ,d))
90549054
(25/6*x^4 - 130/3*x^3 + 105*x^2 - 70*x, x^4 - 20*x^3 + 90*x^2 - 140*x + 70)
90559055
sage: print(((p*d - n) % m ).is_zero())
90569056
True
90579057
sage: p = P(sqrt(1+z).list())
90589058
sage: m = x^6
9059-
sage: n, d = p.rational_reconstruct(m, 3, 2)
9059+
sage: n, d = p.rational_reconstruction(m, 3, 2)
90609060
sage: print((n ,d))
90619061
(1/6*x^3 + 3*x^2 + 8*x + 16/3, x^2 + 16/3*x + 16/3)
90629062
sage: print(((p*d - n) % m ).is_zero())
90639063
True
90649064
sage: p = P(exp(2*z).list())
90659065
sage: m = x^7
9066-
sage: n, d = p.rational_reconstruct(m, 3, 3)
9066+
sage: n, d = p.rational_reconstruction(m, 3, 3)
90679067
sage: print((n ,d))
90689068
(-x^3 - 6*x^2 - 15*x - 15, x^3 - 6*x^2 + 15*x - 15)
90699069
sage: print(((p*d - n) % m ).is_zero())
@@ -9076,26 +9076,26 @@ cdef class Polynomial(CommutativeAlgebraElement):
90769076
sage: x = P.gen()
90779077
sage: p = P(exp(2*z).list())
90789078
sage: m = x^7
9079-
sage: n, d = p.rational_reconstruct( m, 3, 3)
9079+
sage: n, d = p.rational_reconstruction(m, 3, 3)
90809080
sage: print((n ,d)) # absolute tolerance 1e-10
90819081
(-x^3 - 6.0*x^2 - 15.0*x - 15.0, x^3 - 6.0*x^2 + 15.0*x - 15.0)
90829082
90839083
.. SEEALSO::
90849084
90859085
* :mod:`sage.matrix.berlekamp_massey`,
9086-
* :meth:`sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint.rational_reconstruct`
9086+
* :meth:`sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint.rational_reconstruction`
90879087
"""
90889088
P = self.parent()
90899089
if not P.base_ring().is_field():
90909090
if not P.base_ring().is_integral_domain():
9091-
raise NotImplementedError("rational_reconstruct() "
9091+
raise NotImplementedError("rational_reconstruction() "
90929092
"is only implemented when the base ring is a field "
90939093
"or a integral domain, "
90949094
"a workaround is to do a multimodular approach")
90959095
Pf = P.base_extend(P.base_ring().fraction_field())
90969096
sF = Pf(self)
90979097
mF = Pf(m)
9098-
n, d = sF.rational_reconstruct( mF, n_deg, d_deg)
9098+
n, d = sF.rational_reconstruction(mF, n_deg, d_deg)
90999099
l = lcm([n.denominator(), d.denominator()])
91009100
n *= l
91019101
d *= l
@@ -9135,6 +9135,8 @@ cdef class Polynomial(CommutativeAlgebraElement):
91359135
t1 = t1 / c
91369136
return t1, t0
91379137

9138+
rational_reconstruct = deprecated_function_alias(12696, rational_reconstruction)
9139+
91389140
def variables(self):
91399141
"""
91409142
Return the tuple of variables occurring in this polynomial.

src/sage/rings/polynomial/polynomial_quotient_ring_element.py

+24
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,27 @@ def trace(self):
714714
389
715715
"""
716716
return self.matrix().trace()
717+
718+
def rational_reconstruction(self, *args, **kwargs):
719+
r"""
720+
Compute a rational reconstruction of this polynomial quotient
721+
ring element to its cover ring.
722+
723+
This method is a thin convenience wrapper around
724+
:meth:`Polynomial.rational_reconstruction`.
725+
726+
EXAMPLES::
727+
728+
sage: R.<x> = GF(65537)[]
729+
sage: m = x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + 54266*x + 47805
730+
sage: f = 20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447
731+
sage: f_mod_m = R.quotient(m)(f)
732+
sage: f_mod_m.rational_reconstruction()
733+
(51388*x^5 + 29141*x^4 + 59341*x^3 + 7034*x^2 + 14152*x + 23746,
734+
x^5 + 15208*x^4 + 19504*x^3 + 20457*x^2 + 11180*x + 28352)
735+
"""
736+
m = self.parent().modulus()
737+
R = m.parent()
738+
f = R(self._polynomial)
739+
return f.rational_reconstruction(m, *args, **kwargs)
740+

src/sage/rings/polynomial/polynomial_zmod_flint.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
1414
cdef int _set_list(self, x) except -1
1515
cdef int _set_fmpz_poly(self, fmpz_poly_t) except -1
1616
cpdef Polynomial _mul_trunc_opposite(self, Polynomial_zmod_flint other, length)
17-
cpdef rational_reconstruct(self, m, n_deg=?, d_deg=?)
17+
cpdef rational_reconstruction(self, m, n_deg=?, d_deg=?)

src/sage/rings/polynomial/polynomial_zmod_flint.pyx

+6-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ from sage.structure.element cimport parent
4545
from sage.structure.element import coerce_binop
4646
from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint
4747

48+
from sage.misc.superseded import deprecated_function_alias
49+
4850
# We need to define this stuff before including the templating stuff
4951
# to make sure the function get_cparent is found since it is used in
5052
# 'polynomial_template.pxi'.
@@ -585,7 +587,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
585587
nmod_poly_pow_trunc(&ans.x, &self.x, n, prec)
586588
return ans
587589

588-
cpdef rational_reconstruct(self, m, n_deg=0, d_deg=0):
590+
cpdef rational_reconstruction(self, m, n_deg=0, d_deg=0):
589591
"""
590592
Construct a rational function n/d such that `p*d` is equivalent to `n`
591593
modulo `m` where `p` is this polynomial.
@@ -594,7 +596,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
594596
595597
sage: P.<x> = GF(5)[]
596598
sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2
597-
sage: n, d = p.rational_reconstruct(x^9, 4, 4); n, d
599+
sage: n, d = p.rational_reconstruction(x^9, 4, 4); n, d
598600
(3*x^4 + 2*x^3 + x^2 + 2*x, x^4 + 3*x^3 + x^2 + x)
599601
sage: (p*d % x^9) == n
600602
True
@@ -638,6 +640,8 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
638640

639641
return t1, t0
640642

643+
rational_reconstruct = deprecated_function_alias(12696, rational_reconstruction)
644+
641645
@cached_method
642646
def is_irreducible(self):
643647
"""

src/sage/rings/power_series_poly.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ cdef class PowerSeries_poly(PowerSeries):
11191119
.. SEEALSO::
11201120
11211121
* :mod:`sage.matrix.berlekamp_massey`,
1122-
* :meth:`sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint.rational_reconstruct`
1122+
* :meth:`sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint.rational_reconstruction`
11231123
11241124
EXAMPLES::
11251125
@@ -1172,7 +1172,7 @@ cdef class PowerSeries_poly(PowerSeries):
11721172
polyring = self.parent()._poly_ring()
11731173
z = polyring.gen()
11741174
c = self.polynomial()
1175-
u, v = c.rational_reconstruct(z**(n + m + 1), m, n)
1175+
u, v = c.rational_reconstruction(z**(n + m + 1), m, n)
11761176
return u / v
11771177

11781178
def _symbolic_(self, ring):

src/sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
sage: A = Integers(101); R.<x> = A[]
268268
sage: f6 = sum( (i+1)^2 * x^i for i in (0..5) ); f6
269269
36*x^5 + 25*x^4 + 16*x^3 + 9*x^2 + 4*x + 1
270-
sage: num, den = f6.rational_reconstruct(x^6, 1, 3); num/den
270+
sage: num, den = f6.rational_reconstruction(x^6, 1, 3); num/den
271271
(100*x + 100)/(x^3 + 98*x^2 + 3*x + 100)
272272
273273
Sage example in ./polynomes.tex, line 1611::
@@ -283,7 +283,7 @@
283283
284284
Sage example in ./polynomes.tex, line 1677::
285285
286-
sage: num, den = ZpZx(s).rational_reconstruct(ZpZx(x)^10,4,5)
286+
sage: num, den = ZpZx(s).rational_reconstruction(ZpZx(x)^10,4,5)
287287
sage: num/den
288288
(1073741779*x^3 + 105*x)/(x^4 + 1073741744*x^2 + 105)
289289
@@ -304,7 +304,7 @@
304304
305305
sage: def mypade(pol, n, k):
306306
....: x = ZpZx.gen();
307-
....: n,d = ZpZx(pol).rational_reconstruct(x^n, k-1, n-k)
307+
....: n,d = ZpZx(pol).rational_reconstruction(x^n, k-1, n-k)
308308
....: return Qx(list(map(lift_sym, n)))/Qx(list(map(lift_sym, d)))
309309
310310
Sage example in ./polynomes.tex, line 1813::

src/sage/tests/books/computational-mathematics-with-sagemath/sol/polynomes_doctest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
9292
Sage example in ./sol/polynomes.tex, line 428::
9393
94-
sage: s.rational_reconstruct(mul(x-i for i in range(4)), 1, 2)
94+
sage: s.rational_reconstruction(mul(x-i for i in range(4)), 1, 2)
9595
(15*x + 2, x^2 + 11*x + 15)
9696
9797
Sage example in ./sol/polynomes.tex, line 454::

0 commit comments

Comments
 (0)