TPK algorithm: Difference between revisions

Content deleted Content added
move up the ALGOL 60 implementation, as it is from the paper itself (and not OR). It does seem redundant to have so many descriptions of the algorithm, but whatever. Remove comment about overflow.
modifications needed, to give a small sense of the early languages
Line 25:
The algorithm reads eleven numbers from an input device, stores them in an array, and then processes them in reverse order, applying a user-defined function to each value and reporting either the value of the function or a message to the effect that the value has exceeded some threshold.
 
In the original paper, they gave the following example implementation "in a dialect of [[ALGOL 60]]", noting that ALGOL 60 was a later development than the languages actually discussed in the paper:<ref name="edpl"/>
 
<syntaxhighlight lang="Pascal" line>
Line 39:
end TPK.
</syntaxhighlight>
 
As many of the early high-level languages could not handle the TPK algorithm exactly, they allow the following modifications:<ref name="edpl"/>
 
* If the language supports only integer variables, then assume that all inputs and outputs are integer-valued, and that <code>sqrt(x)</code> means the largest ''integer'' not exceeding <math>\sqrt{x}</math>.
 
* If the language does not support alphabetic output, then instead of the string <code>'TOO LARGE'</code>, output the number 999.
 
* If the language does not allow ''any'' input and output, then assume that the 11 input values <math>a_0, a_1, \ldots, a_{10}</math> have been supplied by an external process somehow, and the task is to compute the 22 output values <math>10, f(10), 9, f(9), \ldots, 0, f(0)</math> (with 999 replacing too-large values of <math>f(i)</math>).
 
* If the language does not allow programmers to define their own functions, then replace <code>f(a[i])</code> with an expression equivalent to <math>\sqrt{|a_i|} + 5x^3</math>.
 
== Implementations ==