Impressum/Kontaktparent nodes: implemented functions

⊥ Decode

testAplDecode

"http://www.microapl.co.uk/apl_help/ch_020_020_660.htm"

"Decode"
"Finds the value in units of a number represented in a particular number system, for example, how many inches are in one yard. In general, the result is a scalar value generated from a vector representation of a value.
The left argument contains the base (or bases) of the number system being used. The right argument is a value represented in the given number system. A scalar left argument is treated as if it is a vector which matches the length of the right argument. Similarly, a scalar right argument is extended to match the length of the left argument."

| table |

"To reduce the vector 3 2 6 9 representing, say, the readings of the separate dials on a meter, to a single number:"

"10 is the base for the conversion"
self assert: 3269 asApl = (#(3 2 6 9) asApl aplDecode:10).

"To convert a number represented in octal (base 8) to decimal:"

"Note that as before, the left argument is a vector"
self assert: 25 asApl = (#(3 1) asApl aplDecode:8).


"To reduce 1 yard 2 feet 8 inches to inches:"

"12 is the base for converting feet to inches, 3 is the base for converting yards to feet. For 1760 see the note below"
self assert: 68 asApl = (#(1 2 8) asApl aplDecode:#(1760 3 12)).

"If both arguments to aplDecode are vectors, they must contain the same number of elements. To make the left-hand argument up to the same length as the right, an extra number was included: 1760 (the conversion factor for miles to yards) is irrelevant to the conversion of yards feet and inches to inches, and any other sufficiently large value could have been used instead."

"The 1 is extended to match the length of the right argument"
self assert: 7 asApl = (1 asApl aplDecode:#(2 2 2)).


"To reduce 2 pounds 15 shillings 6 pence and 3 farthings to farthings (4 farthings to one penny, 12 pence one shilling, 20 shillings one pound):"
self assert: 2667 asApl = (#(2 15 6 3) asApl aplDecode:#(0 20 12 4)).

"Again note the first number in the left-hand argument. Its only purpose is to make the arguments the same length."

"The more general form of decode allows both left and right arguments to be numeric arrays. When the left argument is an array of rank 2 or more, it contains a set of vectors which describe different bases to be used independently. Each base lies along the last axis of the left argument, and is applied to each of the vectors on the first axis of the right argument. aplDecode follows the same rules as inner product, the length of the last axis of the left argument must match the length of the first axis of the right argument, and the shape of the result is given by deleting the two inner axes and joining the others in order."

"To convert a matrix of yards, feet and inches to inches:"

"The numbers to be decoded lie along the first axis, so the first value is 1 yard 2 feet 0 inches and so on"
table := #(1 1 1 2 0 3 0 1 8) aplReshape:#(3 3).

"The left argument is applied to each column of the right"
self assert: #(60 37 80) asApl = (table aplDecode:#(1760 3 12)).