Skip to content

Commit

Permalink
Merge branch 'sage_rings_optional_annotations' into sd117_more_option…
Browse files Browse the repository at this point in the history
…al_doctest_tags
  • Loading branch information
Matthias Koeppe committed Apr 8, 2023
2 parents 86d857a + 4d20f8a commit 49f068f
Show file tree
Hide file tree
Showing 64 changed files with 4,240 additions and 3,967 deletions.
1 change: 1 addition & 0 deletions src/sage/rings/algebraic_closure_finite_field.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: optional - sage.rings.finite_rings
r"""
Algebraic closures of finite fields
Expand Down
24 changes: 12 additions & 12 deletions src/sage/rings/complex_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField):
EXAMPLES::
sage: CDF._magma_init_(magma) # optional - magma
sage: CDF._magma_init_(magma) # optional - magma
'ComplexField(53 : Bits := true)'
sage: magma(CDF) # optional - magma
sage: magma(CDF) # optional - magma
Complex field of precision 15
sage: floor(RR(log(2**53, 10)))
15
sage: magma(CDF).sage() # optional - magma
sage: magma(CDF).sage() # optional - magma
Complex Field with 53 bits of precision
"""
return "ComplexField(%s : Bits := true)" % self.prec()
Expand Down Expand Up @@ -2570,11 +2570,11 @@ cdef class ComplexToCDF(Morphism):
EXAMPLES::
sage: import numpy
sage: f = CDF.coerce_map_from(numpy.complex_)
sage: f(numpy.complex_(I))
sage: import numpy # optional - numpy
sage: f = CDF.coerce_map_from(numpy.complex_) # optional - numpy
sage: f(numpy.complex_(I)) # optional - numpy
1.0*I
sage: f(numpy.complex_(I)).parent()
sage: f(numpy.complex_(I)).parent() # optional - numpy
Complex Double Field
"""
def __init__(self, R):
Expand All @@ -2590,8 +2590,8 @@ cdef class ComplexToCDF(Morphism):
EXAMPLES::
sage: import numpy
sage: CDF(numpy.complex_(I)) # indirect doctest
sage: import numpy # optional - numpy
sage: CDF(numpy.complex_(I)) # indirect doctest # optional - numpy
1.0*I
"""
cdef ComplexDoubleElement z = <ComplexDoubleElement>ComplexDoubleElement.__new__(ComplexDoubleElement)
Expand All @@ -2604,9 +2604,9 @@ cdef class ComplexToCDF(Morphism):
EXAMPLES::
sage: import numpy
sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_)
sage: f._repr_type()
sage: import numpy # optional - numpy
sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # optional - numpy
sage: f._repr_type() # optional - numpy
'Native'
"""
return "Native"
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/complex_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,10 @@ cdef class ComplexNumber(sage.structure.element.FieldElement):
EXAMPLES::
sage: import numpy
sage: numpy.array([1.0, 2.5j]).dtype
sage: import numpy # optional - numpy
sage: numpy.array([1.0, 2.5j]).dtype # optional - numpy
dtype('complex128')
sage: numpy.array([1.000000000000000000000000000000000000j]).dtype
sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # optional - numpy
dtype('O')
"""
if self._prec <= 53:
Expand Down
203 changes: 110 additions & 93 deletions src/sage/rings/derivation.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/sage/rings/fast_arith.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: optional - sage.libs.pari
"""
Basic arithmetic with C integers
"""
Expand Down
117 changes: 60 additions & 57 deletions src/sage/rings/finite_rings/integer_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,13 @@ cdef class IntegerMod_abstract(FiniteRingElement):
EXAMPLES::
sage: a = Mod(2,19)
sage: gap(a)
sage: gap(a) # optional - sage.libs.gap
Z(19)
sage: gap(Mod(3, next_prime(10000)))
sage: gap(Mod(3, next_prime(10000))) # optional - sage.libs.gap
Z(10007)^6190
sage: gap(Mod(3, next_prime(100000)))
sage: gap(Mod(3, next_prime(100000))) # optional - sage.libs.gap
ZmodpZObj( 3, 100003 )
sage: gap(Mod(4, 48))
sage: gap(Mod(4, 48)) # optional - sage.libs.gap
ZmodnZObj( 4, 48 )
"""
return '%s*One(ZmodnZ(%s))' % (self, self.__modulus.sageInteger)
Expand Down Expand Up @@ -716,7 +716,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
Examples like this took extremely long before :trac:`32375`::
sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5)
sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) # optional - sage.libs.pari
99999999999999999999999999999999999999999999999999
We check that non-existence of solutions is detected:
Expand Down Expand Up @@ -1028,27 +1028,27 @@ cdef class IntegerMod_abstract(FiniteRingElement):
r"""
EXAMPLES::
sage: Mod(3,17).is_square()
sage: Mod(3, 17).is_square()
False
sage: Mod(9,17).is_square()
sage: Mod(9, 17).is_square() # optional - sage.libs.pari
True
sage: Mod(9,17*19^2).is_square()
sage: Mod(9, 17*19^2).is_square() # optional - sage.libs.pari
True
sage: Mod(-1,17^30).is_square()
sage: Mod(-1, 17^30).is_square() # optional - sage.libs.pari
True
sage: Mod(1/9, next_prime(2^40)).is_square()
sage: Mod(1/9, next_prime(2^40)).is_square() # optional - sage.libs.pari
True
sage: Mod(1/25, next_prime(2^90)).is_square()
sage: Mod(1/25, next_prime(2^90)).is_square() # optional - sage.libs.pari
True
TESTS::
sage: Mod(1/25, 2^8).is_square()
sage: Mod(1/25, 2^8).is_square() # optional - sage.libs.pari
True
sage: Mod(1/25, 2^40).is_square()
sage: Mod(1/25, 2^40).is_square() # optional - sage.libs.pari
True
sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time
sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time # optional - sage.libs.pari
....: for ep,eq,er in cartesian_product_iterator([[0,1,2,3],[0,1,2,3],[0,1,2,3]]):
....: for e2 in [0, 1, 2, 3, 4]:
....: n = p^ep * q^eq * r^er * 2^e2
Expand Down Expand Up @@ -1126,21 +1126,21 @@ cdef class IntegerMod_abstract(FiniteRingElement):
86
sage: mod(7, 18).sqrt()
5
sage: a = mod(14, 5^60).sqrt()
sage: a*a
sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari
sage: a*a # optional - sage.libs.pari
14
sage: mod(15, 389).sqrt(extend=False)
sage: mod(15, 389).sqrt(extend=False) # optional - sage.libs.pari
Traceback (most recent call last):
...
ValueError: self must be a square
sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2)
sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari
9
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2)
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari
25
::
sage: a = Mod(3,5); a
sage: a = Mod(3, 5); a
3
sage: x = Mod(-1, 360)
sage: x.sqrt(extend=False)
Expand Down Expand Up @@ -1386,30 +1386,31 @@ cdef class IntegerMod_abstract(FiniteRingElement):
5
sage: K(23).nth_root(3) # optional - sage.libs.pari
29
sage: mod(225,2^5*3^2).nth_root(4, all=True)
[225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231]
sage: mod(275,2^5*7^4).nth_root(7, all=True)
sage: mod(225, 2^5*3^2).nth_root(4, all=True) # optional - sage.rings.padics
[225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81,
273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231]
sage: mod(275, 2^5*7^4).nth_root(7, all=True) # optional - sage.rings.padics
[58235, 25307, 69211, 36283, 3355, 47259, 14331]
sage: mod(1,8).nth_root(2,all=True)
sage: mod(1,8).nth_root(2, all=True) # optional - sage.rings.padics
[1, 7, 5, 3]
sage: mod(4,8).nth_root(2,all=True)
sage: mod(4,8).nth_root(2, all=True) # optional - sage.rings.padics
[2, 6]
sage: mod(1,16).nth_root(4,all=True)
sage: mod(1,16).nth_root(4, all=True) # optional - sage.rings.padics
[1, 15, 13, 3, 9, 7, 5, 11]
sage: (mod(22,31)^200).nth_root(200)
sage: (mod(22,31)^200).nth_root(200) # optional - sage.groups
5
sage: mod(3,6).nth_root(0,all=True)
sage: mod(3,6).nth_root(0, all=True) # optional - sage.rings.padics
[]
sage: mod(3,6).nth_root(0)
Traceback (most recent call last):
...
ValueError
sage: mod(1,6).nth_root(0,all=True)
sage: mod(1,6).nth_root(0, all=True) # optional - sage.rings.padics
[1, 2, 3, 4, 5]
TESTS::
sage: for p in [1009,2003,10007,100003]:
sage: for p in [1009,2003,10007,100003]: # optional - sage.libs.pari
....: K = GF(p)
....: for r in (p-1).divisors():
....: if r == 1: continue
Expand All @@ -1434,7 +1435,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
We check that :trac:`13172` is resolved::
sage: mod(-1, 4489).nth_root(2, all=True)
sage: mod(-1, 4489).nth_root(2, all=True) # optional - sage.rings.padics
[]
We check that :trac:`32084` is fixed::
Expand All @@ -1445,7 +1446,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
Check that the code path cunningham might be used::
sage: a = Mod(9,11)
sage: a.nth_root(2, False, True, 'Johnston', cunningham = True) # optional - cunningham_tables
sage: a.nth_root(2, False, True, 'Johnston', cunningham=True) # optional - cunningham_tables
[3, 8]
ALGORITHM:
Expand Down Expand Up @@ -1736,20 +1737,20 @@ cdef class IntegerMod_abstract(FiniteRingElement):
EXAMPLES::
sage: mod(1,2).is_primitive_root()
sage: mod(1, 2).is_primitive_root()
True
sage: mod(3,4).is_primitive_root()
sage: mod(3, 4).is_primitive_root()
True
sage: mod(2,7).is_primitive_root()
sage: mod(2, 7).is_primitive_root() # optional - sage.libs.pari
False
sage: mod(3,98).is_primitive_root()
sage: mod(3, 98).is_primitive_root() # optional - sage.libs.pari
True
sage: mod(11,1009^2).is_primitive_root()
sage: mod(11, 1009^2).is_primitive_root() # optional - sage.libs.pari
True
TESTS::
sage: for p in prime_range(3,12):
sage: for p in prime_range(3,12): # optional - sage.libs.pari
....: for k in range(1,4):
....: for even in [1,2]:
....: n = even*p^k
Expand All @@ -1762,14 +1763,14 @@ cdef class IntegerMod_abstract(FiniteRingElement):
`0` is not a primitive root mod `n` (:trac:`23624`) except for `n=0`::
sage: mod(0, 17).is_primitive_root()
sage: mod(0, 17).is_primitive_root() # optional - sage.libs.pari
False
sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20))
sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) # optional - sage.libs.pari
True
sage: mod(0, 1).is_primitive_root()
True
sage: all(not mod(p^j, p^k).is_primitive_root()
sage: all(not mod(p^j, p^k).is_primitive_root() # optional - sage.libs.pari
....: for p in prime_range(3, 12)
....: for k in srange(1, 4)
....: for j in srange(0, k))
Expand Down Expand Up @@ -1824,14 +1825,15 @@ cdef class IntegerMod_abstract(FiniteRingElement):
EXAMPLES::
sage: Mod(-1,5).multiplicative_order()
sage: Mod(-1, 5).multiplicative_order() # optional - sage.libs.pari
2
sage: Mod(1,5).multiplicative_order()
sage: Mod(1, 5).multiplicative_order() # optional - sage.libs.pari
1
sage: Mod(0,5).multiplicative_order()
sage: Mod(0, 5).multiplicative_order() # optional - sage.libs.pari
Traceback (most recent call last):
...
ArithmeticError: multiplicative order of 0 not defined since it is not a unit modulo 5
ArithmeticError: multiplicative order of 0 not defined
since it is not a unit modulo 5
"""
try:
return sage.rings.integer.Integer(self.__pari__().znorder())
Expand All @@ -1854,9 +1856,9 @@ cdef class IntegerMod_abstract(FiniteRingElement):
::
sage: R=ZZ.quo(9)
sage: a=R(3)
sage: b=R(6)
sage: R = ZZ.quo(9)
sage: a = R(3)
sage: b = R(6)
sage: a.valuation(3)
1
sage: a.valuation(3) + b.valuation(3)
Expand All @@ -1875,9 +1877,9 @@ cdef class IntegerMod_abstract(FiniteRingElement):
TESTS::
sage: R=ZZ.quo(12)
sage: a=R(2)
sage: b=R(4)
sage: R = ZZ.quo(12)
sage: a = R(2)
sage: b = R(4)
sage: a.valuation(2)
1
sage: b.valuation(2)
Expand Down Expand Up @@ -1977,8 +1979,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):
r"""
EXAMPLES::
sage: p = next_prime(2^32) # optional - sage.libs.pari
sage: GF(p)(int(p+1)) # optional - sage.libs.pari
sage: p = next_prime(2^32) # optional - sage.libs.pari
sage: GF(p)(int(p + 1)) # optional - sage.libs.pari
1
"""
mpz_set_si(self.value, value)
Expand Down Expand Up @@ -2915,9 +2917,9 @@ cdef class IntegerMod_int(IntegerMod_abstract):
Traceback (most recent call last):
...
ValueError: self must be a square
sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2)
sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari
9
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2)
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari
25
::
Expand All @@ -2932,7 +2934,8 @@ cdef class IntegerMod_int(IntegerMod_abstract):
sage: y = x.sqrt(); y
sqrt359
sage: y.parent()
Univariate Quotient Polynomial Ring in sqrt359 over Ring of integers modulo 360 with modulus x^2 + 1
Univariate Quotient Polynomial Ring in sqrt359
over Ring of integers modulo 360 with modulus x^2 + 1
sage: y^2
359
Expand Down Expand Up @@ -2961,7 +2964,7 @@ cdef class IntegerMod_int(IntegerMod_abstract):
[406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444]
sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari
(13, 13, 104)
sage: all(x^2 == 169 for x in v)
sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari
True
Modulo a power of 2::
Expand Down
Loading

0 comments on commit 49f068f

Please sign in to comment.