Skip to content

Commit fc1166b

Browse files
author
Release Manager
committed
gh-39553: make algdep always an alias for algebraic_dependency for the sake of uniformity, make sure that `algdep` only ever appears as an alias of `algebraic_dependency` both as method and as function in `arith.misc`. We keep both `algdep` and `algebraic_dependency` in the global namespace. also fixes #17302 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #39553 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents c2d418a + 70126c2 commit fc1166b

File tree

13 files changed

+81
-103
lines changed

13 files changed

+81
-103
lines changed

src/sage/arith/all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sage.misc.lazy_import import lazy_import
22

3-
from sage.arith.misc import (algdep, bernoulli, is_prime, is_prime_power,
3+
from sage.arith.misc import (algdep, algebraic_dependency,
4+
bernoulli, is_prime, is_prime_power,
45
is_pseudoprime, is_pseudoprime_power,
56
prime_powers, primes_first_n, eratosthenes, primes,
67
next_prime_power, next_probable_prime, next_prime,

src/sage/arith/misc.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
##################################################################
4141

4242

43-
def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None,
44-
use_digits=None, height_bound=None, proof=False):
43+
def algebraic_dependency(z, degree, known_bits=None,
44+
use_bits=None, known_digits=None,
45+
use_digits=None, height_bound=None, proof=False):
4546
"""
4647
Return an irreducible polynomial of degree at most `degree` which
4748
is approximately satisfied by the number `z`.
@@ -62,9 +63,9 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None,
6263
indicating that higher precision is required.
6364
6465
ALGORITHM: Uses LLL for real/complex inputs, PARI C-library
65-
``algdep`` command otherwise.
66+
:pari:`algdep` command otherwise.
6667
67-
Note that ``algebraic_dependency`` is a synonym for ``algdep``.
68+
Note that ``algdep`` is a synonym for ``algebraic_dependency``.
6869
6970
INPUT:
7071
@@ -79,7 +80,7 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None,
7980
8081
EXAMPLES::
8182
82-
sage: algdep(1.888888888888888, 1) # needs sage.libs.pari
83+
sage: algebraic_dependency(1.888888888888888, 1) # needs sage.libs.pari
8384
9*x - 17
8485
sage: algdep(0.12121212121212, 1) # needs sage.libs.pari
8586
33*x - 4
@@ -266,15 +267,14 @@ def norm(v):
266267

267268
else:
268269
from sage.libs.pari import pari
269-
y = pari(z)
270-
f = y.algdep(degree)
270+
f = pari(z).algdep(degree)
271271

272272
# f might be reducible. Find the best fitting irreducible factor
273-
factors = [p for p, e in R(f).factor()]
273+
factors = (p for p, _ in R(f).factor())
274274
return min(factors, key=lambda f: abs(f(z)))
275275

276276

277-
algebraic_dependency = algdep
277+
algdep = algebraic_dependency
278278

279279

280280
def bernoulli(n, algorithm='default', num_threads=1):

src/sage/calculus/calculus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@
419419
"""
420420

421421
import re
422-
from sage.arith.misc import algdep
422+
from sage.arith.misc import algebraic_dependency
423423
from sage.rings.integer import Integer
424424
from sage.rings.rational_field import QQ
425425
from sage.rings.real_double import RealDoubleElement
@@ -1117,7 +1117,7 @@ def minpoly(ex, var='x', algorithm=None, bits=None, degree=None, epsilon=0):
11171117

11181118
for degree in degree_list:
11191119

1120-
f = QQ[var](algdep(a, degree)) # TODO: use the known_bits parameter?
1120+
f = QQ[var](algebraic_dependency(a, degree)) # TODO: use the known_bits parameter?
11211121
# If indeed we have found a minimal polynomial,
11221122
# it should be accurate to a much higher precision.
11231123
error = abs(f(aa))

src/sage/rings/complex_double.pyx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,34 +2439,38 @@ cdef class ComplexDoubleElement(FieldElement):
24392439
from sage.libs.pari.convert_sage_complex_double import complex_double_element_zeta
24402440
return complex_double_element_zeta(self)
24412441

2442-
def algdep(self, long n):
2442+
def algebraic_dependency(self, long n):
24432443
"""
24442444
Return a polynomial of degree at most `n` which is
2445-
approximately satisfied by this complex number. Note that the
2446-
returned polynomial need not be irreducible, and indeed usually
2447-
won't be if `z` is a good approximation to an algebraic
2448-
number of degree less than `n`.
2445+
approximately satisfied by this complex number.
24492446
2450-
ALGORITHM: Uses the PARI C-library algdep command.
2447+
Note that the returned polynomial need not be irreducible, and
2448+
indeed usually will not be if `z` is a good approximation to an
2449+
algebraic number of degree less than `n`.
2450+
2451+
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
24512452
24522453
EXAMPLES::
24532454
24542455
sage: z = (1/2)*(1 + RDF(sqrt(3)) * CDF.0); z # abs tol 1e-16 # needs sage.symbolic
24552456
0.5 + 0.8660254037844387*I
2456-
sage: p = z.algdep(5); p # needs sage.libs.pari sage.symbolic
2457+
sage: p = z.algebraic_dependency(5); p # needs sage.libs.pari sage.symbolic
24572458
x^2 - x + 1
24582459
sage: abs(z^2 - z + 1) < 1e-14 # needs sage.symbolic
24592460
True
24602461
24612462
::
24622463
2463-
sage: CDF(0,2).algdep(10) # needs sage.libs.pari
2464+
sage: CDF(0,2).algebraic_dependency(10) # needs sage.libs.pari
24642465
x^2 + 4
2465-
sage: CDF(1,5).algdep(2) # needs sage.libs.pari
2466+
sage: CDF(1,5).algebraic_dependency(2) # needs sage.libs.pari
24662467
x^2 - 2*x + 26
24672468
"""
2468-
from sage.arith.misc import algdep
2469-
return algdep(self, n)
2469+
from sage.arith.misc import algebraic_dependency
2470+
return algebraic_dependency(self, n)
2471+
2472+
algdep = algebraic_dependency
2473+
24702474

24712475
cdef class FloatToCDF(Morphism):
24722476
"""

src/sage/rings/complex_mpc.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,10 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
13651365
13661366
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
13671367
1368-
INPUT: Type ``algdep?`` at the top level prompt. All additional
1369-
parameters are passed onto the top-level algdep command.
1368+
INPUT: Type ``algebraic_dependency?`` at the top level prompt.
1369+
1370+
All additional parameters are passed onto the top-level
1371+
``algebraic_dependency`` command.
13701372
13711373
EXAMPLES::
13721374
@@ -1379,8 +1381,10 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
13791381
sage: p(z)
13801382
1.11022302462516e-16
13811383
"""
1382-
from sage.arith.misc import algdep
1383-
return algdep(self, n, **kwds)
1384+
from sage.arith.misc import algebraic_dependency
1385+
return algebraic_dependency(self, n, **kwds)
1386+
1387+
algdep = algebraic_dependency
13841388

13851389
################################
13861390
# Basic Arithmetic

src/sage/rings/complex_mpfr.pyx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,21 +3257,23 @@ cdef class ComplexNumber(sage.structure.element.FieldElement):
32573257
32583258
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
32593259
3260-
INPUT: Type ``algdep?`` at the top level prompt. All additional
3261-
parameters are passed onto the top-level :func:`algdep` command.
3260+
INPUT: Type ``algebraic_dependency?`` at the top level prompt.
3261+
3262+
All additional parameters are passed onto the top-level
3263+
:func:`algebraic_dependency` command.
32623264
32633265
EXAMPLES::
32643266
32653267
sage: C = ComplexField()
32663268
sage: z = (1/2)*(1 + sqrt(3.0) *C.0); z
32673269
0.500000000000000 + 0.866025403784439*I
3268-
sage: p = z.algdep(5); p
3270+
sage: p = z.algebraic_dependency(5); p
32693271
x^2 - x + 1
32703272
sage: p(z)
32713273
1.11022302462516e-16
32723274
"""
3273-
from sage.arith.misc import algdep
3274-
return algdep(self, n, **kwds)
3275+
from sage.arith.misc import algebraic_dependency
3276+
return algebraic_dependency(self, n, **kwds)
32753277

32763278
# Alias
32773279
algdep = algebraic_dependency

src/sage/rings/padics/padic_ZZ_pX_element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ cdef class pAdicZZpXElement(pAdicExtElement):
513513
Return a rational approximation of ``self``.
514514
515515
This does not try to optimize which rational is picked: see
516-
``algdep`` for another option.
516+
``algebraic_dependency`` for another option.
517517
518518
EXAMPLES::
519519

src/sage/rings/padics/padic_generic_element.pyx

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,57 +1117,13 @@ cdef class pAdicGenericElement(LocalGenericElement):
11171117
extdeg = parent.absolute_degree() // (base.absolute_degree() * polydeg)
11181118
return -extdeg * poly[polydeg-1]
11191119
1120-
def algdep(self, n):
1121-
"""
1122-
Return a polynomial of degree at most `n` which is approximately
1123-
satisfied by this number. Note that the returned polynomial need not be
1124-
irreducible, and indeed usually won't be if this number is a good
1125-
approximation to an algebraic number of degree less than `n`.
1126-
1127-
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
1128-
1129-
INPUT:
1130-
1131-
- ``self`` -- a `p`-adic element
1132-
- ``n`` -- integer
1133-
1134-
OUTPUT: polynomial; degree `n` polynomial approximately satisfied by ``self``
1135-
1136-
EXAMPLES::
1137-
1138-
sage: K = Qp(3,20,'capped-rel','series'); R = Zp(3,20,'capped-rel','series')
1139-
sage: a = K(7/19); a
1140-
1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12
1141-
+ 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20)
1142-
sage: a.algdep(1)
1143-
19*x - 7
1144-
sage: K2 = Qp(7,20,'capped-rel')
1145-
sage: b = K2.zeta(); b.algdep(2)
1146-
x^2 - x + 1
1147-
sage: K2 = Qp(11,20,'capped-rel')
1148-
sage: b = K2.zeta(); b.algdep(4)
1149-
x^4 - x^3 + x^2 - x + 1
1150-
sage: a = R(7/19); a
1151-
1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12
1152-
+ 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20)
1153-
sage: a.algdep(1)
1154-
19*x - 7
1155-
sage: R2 = Zp(7,20,'capped-rel')
1156-
sage: b = R2.zeta(); b.algdep(2)
1157-
x^2 - x + 1
1158-
sage: R2 = Zp(11,20,'capped-rel')
1159-
sage: b = R2.zeta(); b.algdep(4)
1160-
x^4 - x^3 + x^2 - x + 1
1161-
"""
1162-
# TODO: figure out if this works for extension rings. If not, move this to padic_base_generic_element.
1163-
from sage.arith.misc import algdep
1164-
return algdep(self, n)
1165-
11661120
def algebraic_dependency(self, n):
11671121
"""
11681122
Return a polynomial of degree at most `n` which is approximately
1169-
satisfied by this number. Note that the returned polynomial need not
1170-
be irreducible, and indeed usually won't be if this number is a good
1123+
satisfied by this number.
1124+
1125+
Note that the returned polynomial need not be irreducible, and
1126+
indeed usually will not be if this number is a good
11711127
approximation to an algebraic number of degree less than `n`.
11721128
11731129
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
@@ -1177,7 +1133,9 @@ cdef class pAdicGenericElement(LocalGenericElement):
11771133
- ``self`` -- a `p`-adic element
11781134
- ``n`` -- integer
11791135
1180-
OUTPUT: polynomial; degree `n` polynomial approximately satisfied by ``self``
1136+
OUTPUT:
1137+
1138+
polynomial; degree `n` polynomial approximately satisfied by ``self``
11811139
11821140
EXAMPLES::
11831141
@@ -1205,7 +1163,12 @@ cdef class pAdicGenericElement(LocalGenericElement):
12051163
sage: b = R2.zeta(); b.algebraic_dependency(4)
12061164
x^4 - x^3 + x^2 - x + 1
12071165
"""
1208-
return self.algdep(n)
1166+
# TODO: figure out if this works for extension rings.
1167+
# If not, move this to padic_base_generic_element.
1168+
from sage.arith.misc import algebraic_dependency
1169+
return algebraic_dependency(self, n)
1170+
1171+
algdep = algebraic_dependency
12091172
12101173
#def exp_artin_hasse(self):
12111174
# """

src/sage/rings/real_double.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ cdef class RealDoubleElement(FieldElement):
19551955
sage: r.algebraic_dependency(5) # needs sage.libs.pari
19561956
x^2 - 2
19571957
"""
1958-
return sage.arith.misc.algdep(self, n)
1958+
return sage.arith.misc.algebraic_dependency(self, n)
19591959

19601960
algdep = algebraic_dependency
19611961

src/sage/rings/real_mpfi.pyx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4996,7 +4996,7 @@ cdef class RealIntervalFieldElement(RingElement):
49964996
"""
49974997
return (~self).arctanh()
49984998

4999-
def algdep(self, n):
4999+
def algebraic_dependency(self, n):
50005000
r"""
50015001
Return a polynomial of degree at most `n` which is
50025002
approximately satisfied by ``self``.
@@ -5012,35 +5012,35 @@ cdef class RealIntervalFieldElement(RingElement):
50125012
50135013
ALGORITHM:
50145014
5015-
Uses the PARI C-library ``algdep`` command.
5015+
This uses the PARI C-library :pari:`algdep` command.
50165016
50175017
EXAMPLES::
50185018
50195019
sage: r = sqrt(RIF(2)); r
50205020
1.414213562373095?
5021-
sage: r.algdep(5)
5021+
sage: r.algebraic_dependency(5)
50225022
x^2 - 2
50235023
50245024
If we compute a wrong, but precise, interval, we get a wrong
50255025
answer::
50265026
50275027
sage: r = sqrt(RealIntervalField(200)(2)) + (1/2)^40; r
50285028
1.414213562374004543503461652447613117632171875376948073176680?
5029-
sage: r.algdep(5)
5029+
sage: r.algebraic_dependency(5)
50305030
7266488*x^5 + 22441629*x^4 - 90470501*x^3 + 23297703*x^2 + 45778664*x + 13681026
50315031
50325032
But if we compute an interval that includes the number we mean,
50335033
we're much more likely to get the right answer, even if the
50345034
interval is very imprecise::
50355035
50365036
sage: r = r.union(sqrt(2.0))
5037-
sage: r.algdep(5)
5037+
sage: r.algebraic_dependency(5)
50385038
x^2 - 2
50395039
50405040
Even on this extremely imprecise interval we get an answer which is
50415041
technically correct::
50425042
5043-
sage: RIF(-1, 1).algdep(5)
5043+
sage: RIF(-1, 1).algebraic_dependency(5)
50445044
x
50455045
"""
50465046
# If 0 is in the interval, then we have no known bits! But
@@ -5053,7 +5053,10 @@ cdef class RealIntervalFieldElement(RingElement):
50535053

50545054
known_bits = -self.relative_diameter().log2()
50555055

5056-
return sage.arith.misc.algdep(self.center(), n, known_bits=known_bits)
5056+
return sage.arith.misc.algebraic_dependency(self.center(),
5057+
n, known_bits=known_bits)
5058+
5059+
algdep = algebraic_dependency
50575060

50585061
def factorial(self):
50595062
"""

0 commit comments

Comments
 (0)