Sylvester’s Algorithm
Vector 13:2, page 12
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 12
In [1] Norman Thomson resurrects Sylvester’s algorithm for converting a "vulgar fraction" (decimal between 0 and 1) into a list of "unit fractions" (or integer reciprocals). Here, Sylvester’s algorithm is recast again in J for perspicuity.
First, compute the largest unit fraction less than the input:
For example:
Use this to decompose the input into the largest unit fraction and the "error" term:
For example:
Use this to extend any such list by decomposing the last term:
For example:
And, finally, repeat it:
The integer reciprocals are obtained easily. For example:
Also, note the identity:
Further, this applies to a vulgar mixed fraction as well:
And to negative vulgar fractions (between _1 and 0):
And to real, non-empty arrays:
All this may be embodied in a program to return the leading integers (without the error term) whose unit fractions approximate the vulgar fraction input:
For example:
Also in [1] Norman Thomson codes a similar algorithm to represent a fraction (decimal) in a given number base. Here it is expressed simply:
For example:
Reference¶
[1] Thomson, N. J-ottings 9, Vector, Vol. 12, No. 4, April 1996 pp. 28-29