Talk:Babbage problem: Difference between revisions

Line 46:
 
Hopefully Mister Babbage you guessed wrong! The solution of your problem is 25264 and not 99736. Hopefully because half of the languages examples would have been wrong. Because the square of 25264 (638,269,696) needs only the 32-bit integer type but the square of 99736 (9,947,269,696) needs the 64-bit integer type! And a lot of languages have problems with it. --[[User: PatGarrett|PatGarrett]] ([[User talk: PatGarrett|talk]]) 19:47, 11 February 2017 (UTC)
 
== Thoughts on Babbage's point of view ==
 
To wish that example programs might be easily understood by Babbage himself
is a good idea. As he was a trained and capable mathematician, who tend to
write as terse as possible, verbosity is not necessary at all.
 
Furthermore, as he has planned his whole life to build a programmable
computer, the Analytical Engine (AE), its concepts should be the
starting point.
 
The AE could only combine two variables by addition, subtraction,
multiplication and division (including delivery of the remainder),
and send the result to a third variable, not necessarily different from one
of the inputs, i.e. allow statements of the form
 
V1 + V2 -> V3
 
If the contents of a variable had to be copied, zero had to be added,
and the result sent to the new variable.
 
A large number of variables was planned to be available,
and variables were seldomly overwritten, except in loops.
Although variables were numbered, this was just a name, not an index;
so using single-letter variable names like in mathematics should be fine.
But identifieres, i.e. words of letters, were not a concept obvious to
him; remember that mathematicians often do not use a multiplication symbol.
 
As a variable could only be overwritten if it was zero before -- a complication
we should leave out here --, all not-initialised variables
can be assumed to be reset to zero at start time.
 
Loops were mentioned in his talk in Milan and the report extended
by Ada Lovelace, but never detailled. Nevertheless, simple loops
are fine.
Note however, that Jaquard cards never used loops, and repeating
pattern were created by repeating cards, so loops should only be used
where indispensible, not when elegant.
 
In contrast to Alan Turing, subroutines or functions were not present in the AE,
so the examples should refrain from using functions.
 
As in all early machines, multiplication, although provided by hardware
in the AE, was time consuming, even if simple multiplications with 2, 3,
4 or 10 etc were rather quick.
Thus, Babbage would never had enumerated square numbers by multiplication,
but by using a binominal formula as in my example below.
 
No text output was availble; only tabular output of rows and columns
of numbers. So an example should just print numbers.
And of course, to check the lower digits, a division by a power of 10
would be used, no tricky string manipulations.
 
This leads to my proposal in AWK (without header comments):
 
# Use x² = (x-1)² + 2x - 1 to enumerate the squares
# The variable x contains 2x in the loop
# Because of 500² = 250000, start at 500
BEGIN {
x = 500
y = x * x
x = 2 * x
do {
x = x + 2
y = y + x
y = y - 1
z = y % 1000000
z = z - 269696
} while (z != 0)
x = x / 2
print x, y
}
 
More in-depth information on the AE can be found on my website [http://rclab.de/rclab/analyticalengine/]. Other examples are in the document on the AE Game [https://rclab.de/rclab/analyticalengine/visualae], but I currently do not think it would be useful to add the AE as a programming language.
Anonymous user