-
-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compute list CRT via tree #34512
Comments
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:5
test, please ignore |
comment:6
I simplified(?) the code --- a/src/sage/arith/misc.py
+++ b/src/sage/arith/misc.py
@@ -3302,13 +3302,14 @@ def CRT_list(v, moduli):
if len(v) == 1:
return moduli[0].parent()(v[0])
from sage.arith.functions import lcm
- v = [CRT(v[i], v[i+1], moduli[i], moduli[i+1]) for i in range(0, len(v)-1, 2)] + v[len(v)//2*2:]
- moduli = [lcm(moduli[i], moduli[i+1]) for i in range(0, len(moduli)-1, 2)] + moduli[len(moduli)//2*2:]
while len(v) > 1:
- for i in range(0, len(v)-1, 2):
- v[i] = CRT(v[i], v[i+1], moduli[i], moduli[i+1])
- moduli[i] = lcm(moduli[i], moduli[i+1])
- v, moduli = v[::2], moduli[::2]
+ vs = [CRT(v[i], v[i + 1], moduli[i], moduli[i + 1]) for i in range(0, len(v) - 1, 2)]
+ ms = [lcm(moduli[i], moduli[i + 1]) for i in range(0, len(v) - 1, 2)]
+ if len(v) % 2:
+ vs.append(v[-1])
+ ms.append(moduli[-1])
+ v = vs
+ moduli = ms
return v[0] % moduli[0] This is slightly slower than your code but easier to read. What do you think? |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:8
Thanks! I continued tweaking it and ended up with this. It seems to be just as fast as my first version. |
comment:10
Thanks. Looks nice. I moved the implementation comment to the code block. Other than that, I am positive. |
Reviewer: Kwankyu Lee |
comment:11
and others |
comment:14
Passed BUILD&TEST. |
Changed branch from public/compute_list_CRT_via_tree to |
Currently,
CRT_list()
works by folding the input from one side. In typical cases of interest, it is much more efficient to use a binary-tree structure instead. (This is similar to howprod()
is implemented.)Example:
Sage 9.7.rc0:
This branch:
Similar speedups can be observed for polynomials; example (a length‑1024 inverse DFT):
Sage 9.7.rc0:
This branch:
Component: algebra
Author: Lorenz Panny
Branch/Commit:
5f3a23f
Reviewer: Kwankyu Lee
Issue created by migration from https://trac.sagemath.org/ticket/34512
The text was updated successfully, but these errors were encountered: