coverage.md

June 17, 2016 · View on GitHub

Coverage of the APLT Compiler

This page documents the functionality of the APLT compiler.

Datatypes

Supported datatypes include booleans, integers, doubles, and characters. Strings are represented as character arrays. Nested arrays are currently not supported, except in a limited fashion for resembling tuples (see below).

Monadic Functions

ExpressionNameMeaningNotes
⍴ AShapeReturns the shape of the array A as a vector of integers.
⍳ NIotaReturns a vector of length N with values [1,...,N].
, ARavelReturns the vector of values appearing in A in row-major order.
+ AIdentityReturns A.
- ANegationReturns the array A with all elements negated.
÷ AReciprocalReturns the array A with elements being the reciprocal values of the values in A.
× ASignReturns the array A with elements being -1 for negative values in A and 1 for positive values in A.
⌈ ACeilReturns A with elements ceiled.The function returns an integer array.
⌊ AFloorReturns A with elements floored.The function returns an integer array.
⍉ ATransposeReturns the transposed version of A.
~ ALogical negationReturns A with boolean elements negated.Assumes A to be of boolean type.
○ APi timesReturns A with all elements multiplied by pi.
⍟ ALogReturns A with the natural logarithm applied to all elements.
? ARandomReturns random values between 0 and 1 (if the argument is 0) and otherwise between 0 and the argument (whole number).
≢ ATallyReturns the size of the outer dimension of A.

Dyadic Functions

ExpressionNameMeaningNotes
B ⍴ AReshapeReturns an array with shape B and values taken from ,A (rotated if there are not sufficiently many values in A).The length of the vector B must be statically decided.
B ⍉ ADyadic transposeReturns the generalized transposed version of A, according to the dimension index vector B.B must be an integer vector of the same length as A.
B + AAdditionPair-wise addition of elements in B and A.Scalar expansion supported: Arrays A and B must be of the same shape unless one of the arrays is a scalar value in which case the array is extended to match the shape of the other array.
B - ASubtractionPair-wise subtraction of elements in B and A.Scalar expansion supported.
B ÷ ADivisionPair-wise division of elements in B and A.Scalar expansion supported.
B × AMultiplicationPair-wise multiplication of elements in B and A.Scalar expansion supported.
B ⌈ AMaximumPair-wise maximum of elements in B and A.Scalar expansion supported.
B ⌊ AMinimumPair-wise minimum of elements in B and A.Scalar expansion supported.
N ↑ ATakeReturns the vector resulting from taking N elements from A (row-major order).When N is negative, values are taken from the right.
N ↓ ADropReturns the vector resulting from dropping N elements from A (row-major order).When N is negative, values are dropped from the right.
N ⌽ ARotateReturns the vector resulting from rotating values in A to the left N steps (row-major order).When N is negative, values are right-rotated.
N ⊖ ARotate lastReturns the vector resulting from rotating values (in A) N steps along the last axis (column-major order).When N is negative, values are rotated in the opposite directions.
B , ACatenateReturns the vector resulting from catenating elements in B with elements in A (row-major order).
B ⍪ ACatenate lastReturns the vector resulting from catenating elements in B with elements in A (column-major order).
B ∨ ABoolean orReturns the logical disjunction of B and A.Scalar expansion supported.
B ∧ ABoolean andReturns the logical conjunction of B and A.Scalar expansion supported.
B ⍱ ABoolean norReturns the negation of the logical disjunction of B and A.Scalar expansion supported.
B ⍲ ABoolean nandReturns the negation of the logical conjunction of B and A.Scalar expansion supported.
B = AEqualityPair-wise equality of elements in B and A.Scalar expansion supported.
B ≠ ANot equalPair-wise inequality of elements in B and A.Scalar expansion supported.
B < ALess thanPair-wise less than comparison of elements in B and A.Scalar expansion supported.
B ≤ ALess than or equalPair-wise less than or equal comparison of elements in B and A.Scalar expansion supported.
B > AGreater thanPair-wise greater than comparison of elements in B and A.Scalar expansion supported.
B ≥ AGreater than or equalPair-wise greater that or equal comparison of elements in B and A.Scalar expansion supported.
B / ACompressReturns the elements in A (as a vector) for which the corresponding elements in the boolean vector B are true.Assumes A to be a vector of the same length as the boolean vector B.
B / AReplicateReturns repeated elements from A (as a vector) with the repetition controlled by the corresponding elements in the integer vector B.Assumes A to be a vector of the same length as the integer vector B.
B ○ ACircReturns the trigonometric function on A dependent on the integer value B; 1:sin, 2:cos, 3:tan.The value of B has to be statically determined.

Monadic Operators

ExpressionNameMeaningNotes
f /ReduceReturns a monadic function that reduces (using f) its argument array along the first axis. The argument to the operator must be a dyadic function.Certain limitations apply.
f ⌿Reduce last axisReturns a monadic function that reduces (using f) its argument array along the last axis. The argument to the operator must be a dyadic function.Certain limitations apply.
f ¨EachReturns a monadic function that maps (using f) over its argument array. The argument to the operator must be a monadic function.
∘. fOuter productReturns a dyadic function that applies f to all elements (pairs) from the cartesian product of the array arguments.

Dyadic Operators

ExpressionNameMeaningNotes
f . gInner productReturns a dyadic function that performs the inner product of its arguments (using f and g). The arguments to the operator must be a dyadic function.Certain limitations apply.
f ⍣ nPowerReturns a monadic function that iteratively applies f to its argument n times.Parentheses may be needed to separate n from the argument to the resulting function. The function f may take (and produce) a vector of arrays, which may be indexed in the body of f using array indexing.

Scalar extensions

Scalar extensions are supported.

Identity items

For certain built-in functions, identity items are supported:

FunctionLeft-identityRight-identity
+00
-0
×11
÷1
``0
=,,11
,>,<00
0
1
-inf-inf
infinf

Quad Assignment (output)

Intermediate arrays may be printed using assignment to the quad-character:

⎕ ← A

Arrays of rank 2 are printed as matrices. Other arrays are printed using a flat representation, specifying both the shape vector and the underlying values.

Trains (points-free notation)

APLT supports writing expressions in points-free (also called tacit) notation. For instance, the APL code

mean ← +/÷≢
⎕ ← mean 2 37 4 1

results in the output 11. APLT support both monadic and dyadic Agh trains and monadic and dyadic fgh trains.

Tuples of arrays

APLT supports having tuples of arrays of different ranks and types. For instance, a tuple c of a vector, a pair (of two vectors), and a scalar, may be constructed as

a ← 1 2 4 3
b ← 'hello'
c ← a (b a) 4

Tuples, such as c, may be passed to functions and deconstructed using index notation:

f ← {
  a1 ← +/⍵[1]
  a2 ← ⊃⍴(⍵[2])[1]
  a1 + a2 + ⍵[3]
}
⎕ ← f c   ⍝ --> [](19)

A particular use of this feature is in conjunction with the power operator. See the powtup.apl test example.

System Functions

ExpressionNameMeaningNotes
⎕ReadFile fileREAD FILETakes a filepath as parameter and returns a vector of charactersFails in case the file cannot be read.
⎕ReadIntVecFile fileREAD INT VECTOR FROM FILETakes a filepath as parameter and returns a vector of integersFails in case the input file cannot be read or does not contain a sequence of integers separated by space characters.

Using APLT

Here is the output from executing aplt on the command-line:

bash-3.2$ aplt 
Usage: ../apltail/aplt [OPTIONS]... file.apl...
 -o file        : write TAIL program to file
 -oc file       : write LAILA program to file
 -c             : compile only (no evaluation)
 -noopt         : disable optimizations
 -materialize   : disable materialization of arrays
 -p_tail        : print TAIL program
 -p_types       : print types in TAIL code
 -p_laila       : print LAILA code
 -s_parse       : stop after parsing
 -s_tail        : stop after TAIL generation
 -silent        : evaluation output only (unless there are errors)
 -v             : verbose
 -O n           : optimisation level (n>0 optimises double operations aggresively)
 -comments      : write comments in generated C code
 -unsafe        : don't include assert code in generated C code for array indexing
 -stat_laila    : print statistics for LAILA code generation
 -opt_hoist     : enable hoist optimization in LAILA code generation
 -opt_loopsplit : enable loop split optimization in LAILA code generation