Talk:Long multiplication: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Wrong algorithms: new section)
(→‎Wrong algorithms: Append to my previous comment.)
Line 60: Line 60:


For these examples, I would like some assurance that the outside algorithm really is long multiplication, and not some other algorithm (such as Karatsuba or Toom multiplication). Examples that use the wrong algorithm are incorrect. Further, I would like to clarify the task, to prohibit the use of outside algorithms, unless those algorithms do long multiplication. I think that [[Arbitrary-precision integers (included)]] is a better place to call outside algorithms. --[[User:Kernigh|Kernigh]] 00:36, 20 March 2012 (UTC)
For these examples, I would like some assurance that the outside algorithm really is long multiplication, and not some other algorithm (such as Karatsuba or Toom multiplication). Examples that use the wrong algorithm are incorrect. Further, I would like to clarify the task, to prohibit the use of outside algorithms, unless those algorithms do long multiplication. I think that [[Arbitrary-precision integers (included)]] is a better place to call outside algorithms. --[[User:Kernigh|Kernigh]] 00:36, 20 March 2012 (UTC)

At the moment, I believe that <math>2^{64}</math> and <math>2^{128}</math> are so small that most outside algorithms would use long multiplication. (In [[MRI]] Ruby, the threshold for Karatsuba multiplication seems to be around <math>2^{2240}</math> or <math>2^{4480}</math>.) --[[User:Kernigh|Kernigh]] 03:03, 20 March 2012 (UTC)

Revision as of 03:03, 20 March 2012

BigNum

Wouldn't it be appropriate to replace this task with arbitrary-precision arithmetic implementation? I.e. long to long +, -, *, /, and long to short +, -, *, /. The divisions are to be implemented in a complete form (result + remainder).

Hi User_talk:Dmitry-kazakov. Yes that makes sense. For the moment I'll switch this task to be a member of Category:Arbitrary precision. IIRC the Newton Raphson Kontorovich method can be used to speed up the division. It looks interesting....

Re: long/short implementations... I spotted the Ada Rational Arithmetic sample code with "long + short" and considered replicating. But by the time if counted all the combinations I ran out of fingers and toes. E.g. one would have to combine the short..., short short, short, long, long long, long... for int, real, compl for the operators "+", "-", "/", "*", "%", "%*", "**", etc ... ALSO: ×, ÷, ... abs, over, mod up, bin etc ... together with "+:=", "-:=" etc ...

Result: No more toes... I think C++/Ada templates can manage this kind of complexity.

The ALGOL 68 standard had a shorthand/template ≮L≯ for this. e.g.

op ≮÷*, %*, ÷×, %×, mod≯  = (L int a, i) L int: ...

But this for the compiler writer, and not available to programmers.

NevilleDNZ 10:56, 26 February 2009 (UTC)

Hm, there's already good code out there, with good license (GPLv2 or later) too... e.g. Bc is an arbitrary precision calculator (Bc) ... does it make sense copy-pasting or this behaviour would just waste RC's aims and space? (I believe RC is not about originality, so it would be ok such a copypasted code, if licenses permit it?) Or should someone at least semplify the code or extract relevant parts in order to show more clearly the techinics of the calculation? --ShinTakezou 14:07, 26 February 2009 (UTC)
I created this task for two reasons. First, I wanted to see what a programmatic implementation of the algorithm behind long multiplication might look like. Second, there are better arbitrary-precision multiplication algorithms out there, but before one looks at those, it helps to understand the simpler, less-efficient ones first. Creating this task is a stepping stone for implementing those better algorithms. Libraries implementing general-purpose arbitrary-precision math tasks are great, but this one was specifically about the algorithm in question. I'll update the task description to be a little more clear on the "this isn't something you should do in production code" point. --Short Circuit 15:34, 26 February 2009 (UTC)
It is clear. But going further (implementing a whole algebra ...), I am not sure it would exemplify more. Anyway, does it make sense to show the GMP usage too, or the code should be eliminated? --ShinTakezou 14:32, 27 February 2009 (UTC)
In my opinion, the code ought to be kept, but it's in the wrong task. Perhaps we need more general arbitrary precision tasks, in addition to showing the individual algorithms. Or maybe the concept of a "task" needs to be further subdivided between "implement this algorithm" and "achieve this end." On the "implement this algorithm" pages, care should probably be taken to point out that there could be more idiomatic or best-practice methods of achieving the same goal, and include a link to corresponding "achieve this end" page.--Short Circuit 19:45, 27 February 2009 (UTC)

Wrong algorithms

Some of the examples seem to call an outside algorithm:

  • ALGOL 68 (1st example), calls operator * of LONG LONG INT
  • BBC BASIC (1st example), calls FNMAPM_Multiply
  • Bracmat, calls operator *
  • C++, calls operator * of cln::cl_I
  • C#, calls Multiply of System.Numerics.BigInteger
  • D (1st example), calls operator * of BigInt from std.bigint
  • F#, calls operator *
  • Groovy, calls operator *
  • Icon and Unicon, calls operator *
  • Java, calls multiply of java.math.BigInteger
  • Liberty BASIC, calls operator *
  • PHP, calls bcmul
  • PicoLisp, calls operator *
  • Prolog, calls operator *
  • PureBasic, calls TimesDecimal of decimal.pbi
  • Python (1st example), calls operator *
  • R (1st example), calls mul.bigz of gmp
  • REXX, calls operator *
  • Scheme, calls operator *
  • Seed7, calls operator *
  • Slate, calls operator *
  • Smalltalk, calls operator *

For these examples, I would like some assurance that the outside algorithm really is long multiplication, and not some other algorithm (such as Karatsuba or Toom multiplication). Examples that use the wrong algorithm are incorrect. Further, I would like to clarify the task, to prohibit the use of outside algorithms, unless those algorithms do long multiplication. I think that Arbitrary-precision integers (included) is a better place to call outside algorithms. --Kernigh 00:36, 20 March 2012 (UTC)

At the moment, I believe that and are so small that most outside algorithms would use long multiplication. (In MRI Ruby, the threshold for Karatsuba multiplication seems to be around or .) --Kernigh 03:03, 20 March 2012 (UTC)