@@ -107,19 +107,19 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None,
107
107
compute a 200-bit approximation to `sqrt(2)` which is wrong in the
108
108
33'rd bit::
109
109
110
- sage: # needs sage.rings.real_mpfr
110
+ sage: # needs sage.libs.pari sage. rings.real_mpfr
111
111
sage: z = sqrt(RealField(200)(2)) + (1/2)^33
112
- sage: p = algdep(z, 4); p # needs sage.libs.pari
112
+ sage: p = algdep(z, 4); p
113
113
227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088
114
- sage: factor(p) # needs sage.libs.pari
114
+ sage: factor(p)
115
115
227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088
116
- sage: algdep(z, 4, known_bits=32) # needs sage.libs.pari
116
+ sage: algdep(z, 4, known_bits=32)
117
117
x^2 - 2
118
- sage: algdep(z, 4, known_digits=10) # needs sage.libs.pari
118
+ sage: algdep(z, 4, known_digits=10)
119
119
x^2 - 2
120
- sage: algdep(z, 4, use_bits=25) # needs sage.libs.pari
120
+ sage: algdep(z, 4, use_bits=25)
121
121
x^2 - 2
122
- sage: algdep(z, 4, use_digits=8) # needs sage.libs.pari
122
+ sage: algdep(z, 4, use_digits=8)
123
123
x^2 - 2
124
124
125
125
Using the ``height_bound`` and ``proof`` parameters, we can see that
@@ -131,18 +131,18 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None,
131
131
132
132
For stronger results, we need more precision::
133
133
134
- sage: algdep(pi.n(), 5, height_bound=100, proof=True) is None # needs sage.libs.pari sage.symbolic
134
+ sage: # needs sage.libs.pari sage.symbolic
135
+ sage: algdep(pi.n(), 5, height_bound=100, proof=True) is None
135
136
Traceback (most recent call last):
136
137
...
137
138
ValueError: insufficient precision for non-existence proof
138
- sage: algdep(pi.n(200), 5, height_bound=100, proof=True) is None # needs sage.libs.pari sage.symbolic
139
+ sage: algdep(pi.n(200), 5, height_bound=100, proof=True) is None
139
140
True
140
-
141
- sage: algdep(pi.n(), 10, height_bound=10, proof=True) is None # needs sage.libs.pari sage.symbolic
141
+ sage: algdep(pi.n(), 10, height_bound=10, proof=True) is None
142
142
Traceback (most recent call last):
143
143
...
144
144
ValueError: insufficient precision for non-existence proof
145
- sage: algdep(pi.n(200), 10, height_bound=10, proof=True) is None # needs sage.libs.pari sage.symbolic
145
+ sage: algdep(pi.n(200), 10, height_bound=10, proof=True) is None
146
146
True
147
147
148
148
We can also use ``proof=True`` to get positive results::
@@ -594,19 +594,20 @@ def is_pseudoprime(n):
594
594
595
595
EXAMPLES::
596
596
597
- sage: is_pseudoprime(389) # needs sage.libs.pari
597
+ sage: # needs sage.libs.pari
598
+ sage: is_pseudoprime(389)
598
599
True
599
- sage: is_pseudoprime(2000) # needs sage.libs.pari
600
+ sage: is_pseudoprime(2000)
600
601
False
601
- sage: is_pseudoprime(2) # needs sage.libs.pari
602
+ sage: is_pseudoprime(2)
602
603
True
603
- sage: is_pseudoprime(-1) # needs sage.libs.pari
604
+ sage: is_pseudoprime(-1)
604
605
False
605
606
sage: factor(-6)
606
607
-1 * 2 * 3
607
- sage: is_pseudoprime(1) # needs sage.libs.pari
608
+ sage: is_pseudoprime(1)
608
609
False
609
- sage: is_pseudoprime(-2) # needs sage.libs.pari
610
+ sage: is_pseudoprime(-2)
610
611
False
611
612
"""
612
613
return ZZ (n ).is_pseudoprime ()
@@ -1635,19 +1636,22 @@ class Sigma:
1635
1636
1636
1637
sage: sigma(100,4)
1637
1638
106811523
1638
- sage: sigma(factorial(100), 3).mod(144169) # needs sage.libs.pari
1639
+
1640
+ sage: # needs sage.libs.pari
1641
+ sage: sigma(factorial(100), 3).mod(144169)
1639
1642
3672
1640
- sage: sigma(factorial(150), 12).mod(691) # needs sage.libs.pari
1643
+ sage: sigma(factorial(150), 12).mod(691)
1641
1644
176
1642
- sage: RR(sigma(factorial(133),20)) # needs sage.libs.pari sage. rings.real_mpfr
1645
+ sage: RR(sigma(factorial(133),20)) # needs sage.rings.real_mpfr
1643
1646
2.80414775675747e4523
1644
- sage: sigma(factorial(100),0) # needs sage.libs.pari
1647
+ sage: sigma(factorial(100),0)
1645
1648
39001250856960000
1646
- sage: sigma(factorial(41),1) # needs sage.libs.pari
1649
+ sage: sigma(factorial(41),1)
1647
1650
229199532273029988767733858700732906511758707916800
1648
1651
sage: from numpy import int8 # needs numpy
1649
- sage: sigma(int8(100), int8(4)) # needs numpy sage.libs.pari
1652
+ sage: sigma(int8(100), int8(4)) # needs numpy
1650
1653
106811523
1654
+
1651
1655
sage: from gmpy2 import mpz
1652
1656
sage: sigma(mpz(100), mpz(4))
1653
1657
106811523
@@ -1797,13 +1801,13 @@ def gcd(a, b=None, **kwargs):
1797
1801
The following shows that indeed coercion takes place before computing
1798
1802
the gcd. This behaviour was introduced in :trac:`10771`::
1799
1803
1800
- sage: R.<x>= QQ[]
1801
- sage: S.<x>= ZZ[]
1804
+ sage: R.<x> = QQ[]
1805
+ sage: S.<x> = ZZ[]
1802
1806
sage: p = S.random_element(degree=(0,10))
1803
1807
sage: q = R.random_element(degree=(0,10))
1804
- sage: parent(gcd(1/p,q))
1808
+ sage: parent(gcd(1/p, q))
1805
1809
Fraction Field of Univariate Polynomial Ring in x over Rational Field
1806
- sage: parent(gcd([1/p,q]))
1810
+ sage: parent(gcd([1/p, q]))
1807
1811
Fraction Field of Univariate Polynomial Ring in x over Rational Field
1808
1812
1809
1813
Make sure we try QQ and not merely ZZ (:trac:`13014`)::
@@ -5068,26 +5072,28 @@ def falling_factorial(x, a):
5068
5072
5069
5073
sage: falling_factorial(10, 3)
5070
5074
720
5071
- sage: falling_factorial(10, RR('3.0')) # needs sage.symbolic
5072
- 720.000000000000
5073
- sage: falling_factorial(10, RR('3.3')) # needs sage.symbolic
5074
- 1310.11633396601
5075
5075
sage: falling_factorial(10, 10)
5076
5076
3628800
5077
5077
sage: factorial(10)
5078
5078
3628800
5079
- sage: a = falling_factorial(1 + I, I); a # needs sage.symbolic
5079
+
5080
+ sage: # needs sage.symbolic
5081
+ sage: falling_factorial(10, RR('3.0'))
5082
+ 720.000000000000
5083
+ sage: falling_factorial(10, RR('3.3'))
5084
+ 1310.11633396601
5085
+ sage: a = falling_factorial(1 + I, I); a
5080
5086
gamma(I + 2)
5081
- sage: CC(a) # needs sage.symbolic
5087
+ sage: CC(a)
5082
5088
0.652965496420167 + 0.343065839816545*I
5083
- sage: falling_factorial(1 + I, 4) # needs sage.symbolic
5089
+ sage: falling_factorial(1 + I, 4)
5084
5090
4*I + 2
5085
- sage: falling_factorial(I, 4) # needs sage.symbolic
5091
+ sage: falling_factorial(I, 4)
5086
5092
-10
5087
5093
5088
5094
sage: M = MatrixSpace(ZZ, 4, 4) # needs sage.modules
5089
5095
sage: A = M([1,0,1,0, 1,0,1,0, 1,0,10,10, 1,0,1,1]) # needs sage.modules
5090
- sage: falling_factorial(A, 2) # A(A - I) # needs sage.modules
5096
+ sage: falling_factorial(A, 2) # A(A - I) # needs sage.modules
5091
5097
[ 1 0 10 10]
5092
5098
[ 1 0 10 10]
5093
5099
[ 20 0 101 100]
@@ -5171,18 +5177,16 @@ def rising_factorial(x, a):
5171
5177
sage: rising_factorial(10,3)
5172
5178
1320
5173
5179
5174
- sage: rising_factorial(10, RR('3.0')) # needs sage.symbolic
5180
+ sage: # needs sage.symbolic
5181
+ sage: rising_factorial(10, RR('3.0'))
5175
5182
1320.00000000000
5176
-
5177
- sage: rising_factorial(10, RR('3.3')) # needs sage.symbolic
5183
+ sage: rising_factorial(10, RR('3.3'))
5178
5184
2826.38895824964
5179
-
5180
- sage: a = rising_factorial(1+I, I); a # needs sage.symbolic
5185
+ sage: a = rising_factorial(1+I, I); a
5181
5186
gamma(2*I + 1)/gamma(I + 1)
5182
- sage: CC(a) # needs sage.symbolic
5187
+ sage: CC(a)
5183
5188
0.266816390637832 + 0.122783354006372*I
5184
-
5185
- sage: a = rising_factorial(I, 4); a # needs sage.symbolic
5189
+ sage: a = rising_factorial(I, 4); a
5186
5190
-10
5187
5191
5188
5192
sage: x = polygen(ZZ)
@@ -5474,7 +5478,8 @@ def three_squares(n):
5474
5478
sage: three_squares(7^100)
5475
5479
(0, 0, 1798465042647412146620280340569649349251249)
5476
5480
sage: three_squares(11^111 - 1) # needs sage.libs.pari
5477
- (616274160655975340150706442680, 901582938385735143295060746161, 6270382387635744140394001363065311967964099981788593947233)
5481
+ (616274160655975340150706442680, 901582938385735143295060746161,
5482
+ 6270382387635744140394001363065311967964099981788593947233)
5478
5483
sage: three_squares(7 * 2^41) # needs sage.libs.pari
5479
5484
(1048576, 2097152, 3145728)
5480
5485
sage: three_squares(7 * 2^42)
@@ -5618,8 +5623,9 @@ def four_squares(n):
5618
5623
sage: four_squares(1101011011004)
5619
5624
(90, 102, 1220, 1049290)
5620
5625
sage: four_squares(10^100 - 1) # needs sage.libs.pari
5621
- (155024616290, 2612183768627, 14142135623730950488016887, 99999999999999999999999999999999999999999999999999)
5622
- sage: for i in range(2^129, 2^129+10000): # long time # needs sage.libs.pari
5626
+ (155024616290, 2612183768627, 14142135623730950488016887,
5627
+ 99999999999999999999999999999999999999999999999999)
5628
+ sage: for i in range(2^129, 2^129 + 10000): # long time # needs sage.libs.pari
5623
5629
....: S = four_squares(i)
5624
5630
....: assert sum(x^2 for x in S) == i
5625
5631
@@ -5695,7 +5701,11 @@ def sum_of_k_squares(k, n):
5695
5701
sage: sum_of_k_squares(5, 9634)
5696
5702
(0, 1, 2, 5, 98)
5697
5703
sage: sum_of_k_squares(6, 11^1111 - 1) # needs sage.libs.pari
5698
- (19215400822645944253860920437586326284, 37204645194585992174252915693267578306, 3473654819477394665857484221256136567800161086815834297092488779216863122, 5860191799617673633547572610351797996721850737768032876360978911074629287841061578270832330322236796556721252602860754789786937515870682024273948, 20457423294558182494001919812379023992538802203730791019728543439765347851316366537094696896669915675685581905102118246887673397020172285247862426612188418787649371716686651256443143210952163970564228423098202682066311189439731080552623884051737264415984619097656479060977602722566383385989, 311628095411678159849237738619458396497534696043580912225334269371611836910345930320700816649653412141574887113710604828156159177769285115652741014638785285820578943010943846225597311231847997461959204894255074229895666356909071243390280307709880906261008237873840245959883405303580405277298513108957483306488193844321589356441983980532251051786704380984788999660195252373574924026139168936921591652831237741973242604363696352878914129671292072201700073286987126265965322808664802662993006926302359371379531571194266134916767573373504566621665949840469229781956838744551367172353)
5704
+ (19215400822645944253860920437586326284, 37204645194585992174252915693267578306,
5705
+ 3473654819477394665857484221256136567800161086815834297092488779216863122,
5706
+ 5860191799617673633547572610351797996721850737768032876360978911074629287841061578270832330322236796556721252602860754789786937515870682024273948,
5707
+ 20457423294558182494001919812379023992538802203730791019728543439765347851316366537094696896669915675685581905102118246887673397020172285247862426612188418787649371716686651256443143210952163970564228423098202682066311189439731080552623884051737264415984619097656479060977602722566383385989,
5708
+ 311628095411678159849237738619458396497534696043580912225334269371611836910345930320700816649653412141574887113710604828156159177769285115652741014638785285820578943010943846225597311231847997461959204894255074229895666356909071243390280307709880906261008237873840245959883405303580405277298513108957483306488193844321589356441983980532251051786704380984788999660195252373574924026139168936921591652831237741973242604363696352878914129671292072201700073286987126265965322808664802662993006926302359371379531571194266134916767573373504566621665949840469229781956838744551367172353)
5699
5709
sage: sum_of_k_squares(7, 0)
5700
5710
(0, 0, 0, 0, 0, 0, 0)
5701
5711
sage: sum_of_k_squares(30,999999)
@@ -5954,32 +5964,32 @@ def sort_complex_numbers_for_display(nums):
5954
5964
5955
5965
EXAMPLES::
5956
5966
5967
+ sage: # needs sage.rings.complex_double
5957
5968
sage: import sage.arith.misc
5958
5969
sage: sort_c = sort_complex_numbers_for_display
5959
- sage: nums = [CDF(i) for i in range(3)] # needs sage.rings.complex_double
5960
- sage: for i in range(3): # needs sage.rings.complex_double
5970
+ sage: nums = [CDF(i) for i in range(3)]
5971
+ sage: for i in range(3):
5961
5972
....: nums.append(CDF(i + RDF.random_element(-3e-11, 3e-11),
5962
5973
....: RDF.random_element()))
5963
5974
....: nums.append(CDF(i + RDF.random_element(-3e-11, 3e-11),
5964
5975
....: RDF.random_element()))
5965
- sage: shuffle(nums) # needs sage.rings.complex_double
5966
- sage: nums = sort_c(nums) # needs sage.rings.complex_double
5967
- sage: for i in range(len(nums)): # needs sage.rings.complex_double
5976
+ sage: shuffle(nums)
5977
+ sage: nums = sort_c(nums)
5978
+ sage: for i in range(len(nums)):
5968
5979
....: if nums[i].imag():
5969
5980
....: first_non_real = i
5970
5981
....: break
5971
5982
....: else:
5972
5983
....: first_non_real = len(nums)
5973
- sage: assert first_non_real >= 3 # needs sage.rings.complex_double
5974
- sage: for i in range(first_non_real - 1): # needs sage.rings.complex_double
5984
+ sage: assert first_non_real >= 3
5985
+ sage: for i in range(first_non_real - 1):
5975
5986
....: assert nums[i].real() <= nums[i + 1].real()
5976
-
5977
5987
sage: def truncate(n):
5978
5988
....: if n.real() < 1e-10:
5979
5989
....: return 0
5980
5990
....: else:
5981
5991
....: return n.real().n(digits=9)
5982
- sage: for i in range(first_non_real, len(nums)-1): # needs sage.rings.complex_double
5992
+ sage: for i in range(first_non_real, len(nums)-1):
5983
5993
....: assert truncate(nums[i]) <= truncate(nums[i + 1])
5984
5994
....: if truncate(nums[i]) == truncate(nums[i + 1]):
5985
5995
....: assert nums[i].imag() <= nums[i+1].imag()
0 commit comments