Talk:Addition-chain exponentiation: Difference between revisions

 
(24 intermediate revisions by 5 users not shown)
Line 130:
==Associativity==
Exponentiation is the obvious application for addition chains, but shouldn't they work for any associative binary operation? I expect exponentiation will make the best application for a task requirement, but we might mention associativity in the description. —[[User:Sonia|Sonia]] 23:08, 13 February 2012 (UTC)
:Actually, except for low exponent, I doubt any software would use optimal solution, since it's really a pain to find the solutions. Also, there is a more general solution allowing inverse operations. It is interesting for multiplication (if addition and subtraction have roughly the same cost), but probably not for exponentiation, where multiplication/division are usually not expected to have the same cost. Hence for really optimal use, one would have to analyze carefully the costs of each variant. However, the task is still theoreyicallytheoretically interesting, and fidningfinding a good algorithm for large exponents is not so easy. A backtracking program I wrote some time ago in Fortran 77 took almost 24 hours to compute optimal solutions for all exponents up to 2048, I don't think it's fast enough, by far. And usually heuristics only give suboptimal solutions. [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 09:30, 30 April 2015 (UTC)
 
==Optimal solution, A003313, and κῦδος==
Any technique that guarantees optimal solutions produces A003313 so if the task allows only optimal solutions, then 1) the task requires an expensive computation, and 2) κῦδος are cheap for any valid solution. I would like to see the task allow solutions that are not guaranteed to be optimal but which generally improve on binary solutions. This is arguing for the practical result of accelerating a computation as opposed to the mathematical result of finding a limit. The rich literature out there seems mostly focused on the practical application of finding near-optimal solutions (for the purpose of accelerating RSA encryption.) κῦδος could still go to the mathematical result of A003313, but it could be made more challenging by requiring later terms of the sequence. Terms 8190-8195, for example, which are verifiable from a link from the OEIS page. Actually I'd like to see κῦδος awarded for reproducing those terms using a near-optimal technique. —[[User:Sonia|Sonia]] 23:08, 13 February 2012 (UTC)
:It's another task then. I don't think it's a problem to ask for optimal solutions. Actually, it's even very interesting: among the 5 solutions so far, 4 are wrong. A good task to separate those who can read a question from those who can't. I didn't check the C one carefully though: it's certainly wrong in the sense that it does not compute matrix exponentiation, but this is really irrelevant, the interesting part is the computation of ''optimal'' addition chains. [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 17:19, 19 July 2015 (UTC)
 
== Montgomery reduction ==
 
I just tried a fun experiment of combining this task with the [[Montgomery reduction]] task and it worked just fine. It's not that much of a stretch since Montgomery reduction is just another way to do multiplication, but still it was fun to see addition chain exponentiation work with this alternative operation and also see it work on some bigger numbers. The 100 bit exponents of my example there take about 150 multiplies using binary exponentiation but about 130 multiplies with the addition chains. —[[User:Sonia|Sonia]] 01:59, 2 March 2012 (UTC)
 
== Go is wrong, among others ==
 
The Go solution starts with the sentence "'''A non-optimal solution'''". The tasks states: "Note: Binary exponentiation does not usually produce the best solution. '''Provide only optimal solutions.'''".
 
Actually, the program states in the comments "the techniques here work only with 'star' chains". But star chains are known '''not''' to be optimal.
 
The answer is thus wrong.
 
[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 21:14, 20 July 2015 (UTC)
 
: I do not think this is valid reasoning.
 
: The wikipedia mention of [[wp:Addition_chain#Brauer_chain|star chains]] does indeed mention that star chains can fail to produce invalid values. However, the example given is for an exponent of 1227873210934869755325459645562028180483410421970385642998266670782559244925047578059104483100233309036904622010710304861903062287481691063068371652744142574931000480320516175613904206157567455536712489864433925819285983619453998073177028402644441528674227. Here, the addition-chain has 6110 elements while the optimal chain has at most 6109 elements (but apparently no one has been able to prove that they have found an optimal chain for that exponent).
 
: So by your reasoning, any implementation which limits itself to 64 bit integers is also an invalid implementation because that implementation would not produce an optimal result for an exponent of 1227873210934869755325459645562028180483410421970385642998266670782559244925047578059104483100233309036904622010710304861903062287481691063068371652744142574931000480320516175613904206157567455536712489864433925819285983619453998073177028402644441528674227.
 
: That said, if you can modify the task in some reasonable way which brings out the flaws of star chains, I would accept your reasoning. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 21:43, 20 July 2015 (UTC)
::The article does not say it's the smallest counterexample. For you, if a statement is not (yet) proved, it's considered to be true? Wrong. Either you have a proof that star chains produce optimal solutions for 31415 and 27182, either a program based on star chain is useless. When the task asks for optimal solution, that means provably optimal solution, not ''maybe optimal, maybe not''. [[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 21:56, 20 July 2015 (UTC)
 
 
Quoting [http://strangelyconsistent.org/blog/t3-addition-chains this]: '''" A Brauer-based algorithm will fail the first time at N = 12509."''' (if this site is not enough for you, I'll try to give you the reference in Knuth's TAOCP then, as I'm sure to have read this in one of the volumes). It's far below the values of the task, which is a big problem for me. And the article linked in the Go program does not claim to give optimal solution, on the contrary: '''"Even though minimal-length cf-chains are not optimal, they have the nice property of being easy to compute [...]"'''.
This should close the question on the (in)correctness of the Go program.
 
[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 23:10, 20 July 2015 (UTC)
 
== One more value to find ==
 
I added 12509 to the values of the task, 31415 and 27182. Actually, 12509 is the [http://strangelyconsistent.org/blog/t3-addition-chains smallest] for which star chains fail to give an optimal answer, and since the optimality of star chains is questionnable for 31415 and 27182, it's better to clearly exclude this approach. The task insists in asking for an optimal solution, and not a suboptimal one, thus one has to comply with this: algorithms which are faster but suboptimal are perfectly acceptable from an engineering point of view, but do not qualify for an answer to this task. Here we need the guarantee that the answer is correct, that is, really optimal.
 
[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 23:30, 20 July 2015 (UTC)
 
== Should this task be deleted? ==
 
Is it reasonable for tasks to require running time in months or years?
 
I'm not sure how this task is going to satisfy any meaningful language comparison niche. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 01:53, 21 July 2015 (UTC)
 
 
I was just going to make this same point when I found this section :-)<br>
RC is about comparing languages not about original research in a proven difficult area. In the life of this task we have only a few examples and more comment on their correctness. I too think that the task is not written for an RC audience. It could be improved/saved if a particular algorithm or set of algorithms are approved in the task description and pseudo code given otherwise the task is too broad and contentious. <br>
--[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 06:58, 21 July 2015 (UTC)
:Many tasks are only suited to a few languages, it's the very purpose of having so many languages: if one could handle all tasks as well or better than any other, there would be no point in programming in any other language. We know it's not the case.
:Furthermore, this is an old problem, described in Knuth's TAOCP. I think it's still a good candidate for RC, but maybe it should be amended to use much lower exponents: in the 200-600 range, it should be reasonably fast.
:However, it should then still be clearly stated whether star chains are accepted or not: I don't think it's a good idea since the algorithm provides no guarantee that the result is optimal, it's only an observation made by comparing with the true optimal solution. This would encourage solving a problem with the wrong tool, just because it happens to give the right answer by chance (and it does not with 12509, as explained above). It's also possible to state explicitly that star chains are accepted because we know by other means that the answer is right in the asked cases (but then one has to choose exponents for which it is really known, of course, and give proper references).
:On the other hand, it would also be doable with the current exponents, but then the task should mention a reference to an efficient algorithm.
:For low exponents, I can give a backtracking algorithm relatively easy to adapt: in Frotran 77, thus only ''if'' and ''goto'' are really needed, and it can be translated to a recursive algorithm, hence most language families can do it.
:Another remark: I don't see much point in asking for matrix exponentiation since the core problem is in optimizing addition chains. That's adding a mostly trivial task, but which may require much code in some languages, for no benefit as there is already a task about this: [[Matrix-exponentiation operator]].
:[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 08:15, 21 July 2015 (UTC)
 
::Hi Arbautjc, if you see a way to tackle:
::# Giving an algorithm (in an accessible manner).
::# Excessive run times.
::# Matrices? (Possibly remove)?
 
::Then you could probably turn around the task and get more examples I think. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 09:22, 21 July 2015 (UTC)
:Should this task be deleted? As it is, I would say yes. It has many problems. It's current advocate, Arbautjc, feels optimal solutions should be required yet there no implementations of optimal chain algorithms (#include is not an implemenation) and people have cited reasons why optimal chain algorithms are not likely to be a good fit for RC. &mdash;[[User:Sonia|Sonia]] ([[User talk:Sonia|talk]]) 02:09, 10 August 2015 (UTC)
::The task as it is right now is too complex for RC. However, addition chains are IMO perfectly fit to RC. Choose lower bounds and it's easily feasible. However, if you choose lower bounds, it is known that star chains are optimal (but it is known by comparison to an optimal algorithm, not by an independant proof, AFAIK). The lowest N for which they fail to be optimal is greater than 10000, far above what is reasonably feasible with a simple backtracking algorithm. Therefore, if lower bounds are chosen, you may as well give the possibility to use star chains. So far, I have not had much time to write a new task for this (I have never written a task on RC yet, by the way).
::[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 15:20, 17 August 2015 (UTC)
 
As is, this page should be deleted. It is an exercise of the mind until shown that it has significance in daily computing.
 
In general, one should be able to find existing open source code as a working example that passes a test, such as from Perl's cpan for example. If this page is to be kept, the esoteric math symbols and terms should be translated.
[[User:tekbasse] ([[User talk:tekbasse|talk]]) 5:46, 1 March 2017 (UTC)
:Ridiculous. Is there a rule requiring that Rosetta Code tasks be useful in daily computing? Of course not. Esoteric math symbols? Maybe you think computer science has nothing to do with math. But this is also blatantly wrong. This problem has been the subject of several research articles, and good algorithms exist, period. That you may be unable to implement them is nobody's concern. There are other more or less difficult algorithms on RC, and I have no problem with that. RC is not limited to "Hello World" and "How do I write a for loop?", thankfully. [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 21:27, 16 December 2017 (UTC)
 
== Fast algorithm ==
There is indeed a fast algorithm, much faster than the straightforward backtracking algorithm I used. See the following article:
 
Neill Michael Clift,
''"Calculating optimal addition chains"'',
'''Computing''', March 2011, Volume 91, Issue 3, pp 265–284,
[https://doi.org/10.1007/s00607-010-0118-8 DOI:10.1007/s00607-010-0118-8]
 
[[User:Arbautjc|Arbautjc]] ([[User talk:Arbautjc|talk]]) 11:45, 29 August 2016 (UTC)
1,336

edits