Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 15dabc3

Browse files
committed
errata, improve random tests
1 parent f6cd17e commit 15dabc3

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/sage/rings/polynomial/polynomial_element.pyx

+2-24
Original file line numberDiff line numberDiff line change
@@ -2077,17 +2077,6 @@ cdef class Polynomial(CommutativeAlgebraElement):
20772077
0
20782078
sage: g._mul_generic(h) - K([h*c for c in g.list()])
20792079
0
2080-
2081-
Compare with external libraries::
2082-
2083-
sage: K = ZZ['x']
2084-
sage: L = []
2085-
sage: for i in range(10):
2086-
... f = K.random_element(randint(10,100),100)
2087-
... g = K.random_element(randint(10,100),100)
2088-
... L.append(f*g - f._mul_generic(g))
2089-
sage: L
2090-
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
20912080
"""
20922081
if self is right:
20932082
return self._square_generic()
@@ -2326,17 +2315,6 @@ cdef class Polynomial(CommutativeAlgebraElement):
23262315
sage: h2 = f._mul_karatsuba(g,randint(0,10))
23272316
sage: h1 == h2
23282317
True
2329-
2330-
Compare with external libraries::
2331-
2332-
sage: K = ZZ['x']
2333-
sage: L = []
2334-
sage: for i in range(10):
2335-
... f = K.random_element(randint(10,100),100)
2336-
... g = K.random_element(randint(10,100),100)
2337-
... L.append(f*g - f._mul_karatsuba(g, randint(0,32)))
2338-
sage: L
2339-
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
23402318
"""
23412319
if self.is_zero():
23422320
return self
@@ -6601,7 +6579,7 @@ cdef do_karatsuba_different_size(left, right, Py_ssize_t K_threshold):
66016579
Here, we use Fibonacci numbers that need deepest recursion in this method.
66026580
66036581
sage: K = ZZ[x]
6604-
sage: f = K.random_element(28)
6582+
sage: f = K.random_element(21)
66056583
sage: g = K.random_element(34)
66066584
sage: f*g - f._mul_karatsuba(g,0)
66076585
0
@@ -6676,7 +6654,7 @@ cdef do_karatsuba(left, right, Py_ssize_t K_threshold,Py_ssize_t start_l, Py_ssi
66766654
- num_elts: the length of the polynomials.
66776655
66786656
Thus, the actual polynomials we want to multiply are represented by the
6679-
slices: left[ start_l: start_l+num_elts ], left[ right_l: right_l+num_elts ].
6657+
slices: left[ start_l: start_l+num_elts ], right[ right_l: right_l+num_elts ].
66806658
We use this representation in order to avoid creating slices of lists and
66816659
create smaller lists.
66826660

src/sage/rings/tests.py

+18
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,21 @@ def test_random_arith(level=MAX_LEVEL, trials=1):
294294
if i >= trials:
295295
return
296296

297+
@random_testing
298+
def test_karatsuba_multiplication(degree1, degree2, verbose=False):
299+
"""
300+
Test univariate karatsuba multiplication against an external library (FLINT).
301+
302+
EXAMPLES::
303+
304+
sage: sage.rings.tests.test_karatsuba_multiplication(1000,1000)
305+
"""
306+
from sage.all import ZZ, randint
307+
threshold = randint(0,min(degree1,degree2))
308+
R = ZZ['x']
309+
for i in range(10):
310+
f = R.random_element(degree1,100)
311+
g = R.random_element(degree2,100)
312+
if g*f - f._mul_karatsuba(g,threshold) != 0:
313+
raise ValueError("Multiplication failed")
314+
return

0 commit comments

Comments
 (0)