![]() |
![]() |
#1 |
Jul 2009
111112 Posts |
![]()
What's the current standard algorithm for optimizing addition chains?
This is of course to minimize the number of multiplications needed to compute powers. I'd love to find a decent heuristic that doesn't have to be completely optimal, but is better than the double-and-add-if-odd standard binary method. Ie, for 15, I'd like to get a 6-long chain like 1 2 3 6 12 15 which is better than the binary method which computes the 7-long 1 2 3 4 7 8 15 Knuth's 4.6.3 survey is fun but not too practical. Currently I'm computing short chains by a pretty simple heuristic.. kind of a poor man's broken dynamic program. If N is prime, I return the shorter of the binary chain, 1+chain(N-1), or 1+chain(N-2). if N is factorable into pq, I return the shortest of the binary chain, or chain(p)+chain(q) for all possible pq. That heuristic certainly isn't optimal but it seems OK for medium sized n up to 2^32 or so. But surely there's some better methods. There's explicit tables here. But I'm hoping for a nice little function I can call to get "pretty likely optimal" results. Huge bonus points if someone did some template metaprogramming in C++ to do this right at runtime! |
![]() |
![]() |
![]() |
#2 |
Oct 2007
2·53 Posts |
![]()
If your objective is not to find the absolute best chain, there are a lot of improvements that can be done to the binary method. Bernstein has a survey with focus on exponentiation applications at:
http://cr.yp.to/papers/pippenger.pdf |
![]() |
![]() |
![]() |
#3 |
Tribal Bullet
Oct 2004
2·3·19·31 Posts |
![]()
GMP-ECM uses Montgomery's PRAC algorithm. His experiments show that the worst case result of the algorithm is within just a few percent of the performance of an optimal addition chain.
|
![]() |
![]() |
![]() |
#4 | |
Jul 2009
1F16 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#5 | |
Jul 2009
378 Posts |
![]() Quote:
Is this the idea of precomputing a table of 1 x^2 x^3 x^4 x^5 x^6 x^7 (or up to some 2^m -1) and then taking big steps of m bits at once and just doing one table lookup and then m doubling steps? |
|
![]() |
![]() |
![]() |
#6 |
"Nancy"
Aug 2002
Alexandria
2,467 Posts |
![]()
PRAC looks for what Montgomery dubbed "Lucas chains," which are addition chains with the extra condition that whenever a+b is formed from earlier chain elements a and b, then a-b must also be in the chain, or must be 0. For example, 1,2,3,6,7 isn't a Lucas chain because you need 6-1=5 to make 6+1=7. However, 1,2,3,5,7 is a Lucas chain. Such chains are needed for arithmetic on elliptic curves in Montgomery form, and for P+1 factoring/primality testing. The relevant manuscript (it was never formally published) is "Evaluating recurrences of form X_{m+n} = f (X_m, X_n, X_{m-n}) via Lucas chains", see ftp://ftp.cwi.nl/pub/pmontgom/Lucas.ps.gz.
Alex |
![]() |
![]() |
![]() |
#7 | |
Jul 2009
111112 Posts |
![]() Quote:
Knuth was so correct when he wrote that there was a rich and mysterious theory behind efficient addition chains. 30 years later it seems just as true. |
|
![]() |
![]() |
![]() |
#8 | |
"Richard B. Woods"
Aug 2002
Wisconsin USA
22×3×641 Posts |
![]() Quote:
Just be sure to use "snail mail" (as Knuth writes: "So if you want to write to me about any topic, please use good ol' snail mail and send a letter to the following address: ") and send it to the address given on this page: http://www-cs-faculty.stanford.edu/~knuth/email.html |
|
![]() |
![]() |
![]() |
#9 | |
Nov 2003
22·5·373 Posts |
![]() Quote:
addition chain is in P or whether it is NPC. I suspect the latter. It may be reducible to the subset-sum problem in some way. |
|
![]() |
![]() |
![]() |
#10 | |
Nov 2003
22·5·373 Posts |
![]() Quote:
http://scitation.aip.org/getabs/serv...cvips&gifs=yes |
|
![]() |
![]() |
![]() |
#11 |
Oct 2007
2×53 Posts |
![]()
It might still be possible, albeit unlikely, that the special (and more often used) case where m=1 is solvable in P.
|
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Generalised Cunningham Chains | robert44444uk | Open Projects | 12 | 2013-08-24 07:42 |
Primecoin - Cunningham Chains | Redarm | Lounge | 2 | 2013-07-18 01:04 |
Torture test best practices | Darin | Information & Answers | 7 | 2012-08-02 11:02 |
Cockney rhyming slang chains. | davieddy | Puzzles | 12 | 2011-08-09 02:36 |
On prime chains | Dougy | Math | 10 | 2009-09-11 21:05 |