]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
Revert "mjo/polynomial.py: improve multidiv performance a bit."
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 18 Feb 2019 18:56:28 +0000 (13:56 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 21 Feb 2019 01:18:22 +0000 (20:18 -0500)
This reverts commit 4e4efc9eff5c77a2ca19002b1dfa45598e974c54. Example
4 in the text doesn't work with this implementation, but it does with
my original one. Let's stick with slow and correct, for now.

mjo/polynomial.py

index 8b493711924d705e17eb612efd56e390ea98e88e..2b8dc2aa4cb825c06c6e0e09dc8582da0533817b 100644 (file)
@@ -171,9 +171,8 @@ def multidiv(f, gs):
     qs = [R.zero()]*s
 
     while p != R.zero():
-        i = 0
-        division_occurred = false
-        while i < s:
+        for i in range(0,s):
+            division_occurred = false
             # If gs[i].lt() divides p.lt(), then this remainder will
             # be zero and the quotient will be in R (and not the
             # fraction ring, which is important).
@@ -182,13 +181,7 @@ def multidiv(f, gs):
                 qs[i] += factor
                 p -= factor*gs[i]
                 division_occurred = true
-                # Don't increment "i" here because we want to try
-                # again with this "denominator" g[i]. We might
-                # get another factor out of it, but we know that
-                # we can't get another factor out of an *earlier*
-                # denominator g[i-k] for some k.
-            else:
-                i += 1
+                break
 
         if not division_occurred:
             r += p.lt()