Recall that most algebraic symbols were invented when writing was done with pens, pencils, etc. A typerwriter keyboard has limited space and only the most heavily used symbols such as '+ - = % / ( ) .' have been represented. Many users of mathematics like to use other naming symbols than the conventional alphabets. Many are especially fond of Greek alphabetical symbols.
The Roman alphabet used by the English language has no supplimentary accents, etc and forms the basis for the systems in the English speaking and other parts of the world. Digital representation of symbols developed standard length digital words. Current systems use an eight bit word that has evolved from shorter versions. Eight bits allows 256 unique combinations. The current standard is called ASCII (American Standard Code for Information Interchange).
The development of electronic digital computer opened up the potential for doing a great deal more math at very high speeds. Communication with computers uses various techniques for encoding the input and output information. Existing equipment such as Teletype machines, punched tapes and cards, magnetic tape, etc were used with early machines. These have evolved to the current variety of devices. The problem of how to easily represent a large range of math symbols on conventional keyboards still exists. Various schemes are currently in place.
Ken Iverson was one of the people who recognized that there was needed for math more suited to digital computers. Notation was developed to incorporate his ideas and machines for its interpretation. APL first implimented on the IBM 360 series of computers is one such system. It uses a combination of conventional and special symbols most of which are based on Greek letters.
A more recent version by Iverson and Roger Hui is called J uses only conventional ASCII symbols.
These notes were originally developed using various APL systems. The current versions are tuned to use with browsers and some of the math functions have been recode using Java Script. An example is the formula interpreter which includes some of the symbols and their meanings.
APL and J use a set of primitve functions that reduce some of the ambiguities of conventional algebraic notation and extend it to recognize other operators that are useful for defining algorithms. The various implimentations are reasonably concistent in defining the primitives and their actions.
The following are some common mathematical models or functions. The models are simple algebraic expressions. They have general application and are used in most disciplines including business, science and technology.
These are shown ALGEBRAICALLY and in APL in LESSON'x8' in the APL files included in MYNET. To use LESSON'x8 go to the TAS ws , then View x8 using the Main Menu. Recall that in Windows XP use the [Enter] key to begin using the interpreter, and then the [F12] key to activate the Main Menu. Key v to activate view, followed by x8 to begin the LESSON. Paging within the kesson is described in the first panel.
The key actions to obtain the primitives shown use the Unified or TEXT keyboard used by MYSYS. The complete keyboard map will be displayed by keying [Enter] on the following line: ‘cc'q150' ¦ APL Unified or TEXT keyboard layout
The common arithmetic, algebraic and APL primitives are:
Primitive: required Keyboard Action
- negate, minus
+ plus
’ signum, times: [Alt -]
ö reciprical, divide: [Alt =]
You should be familiar with the following APL primitives:
= logical equal
* exponent
/ reduction
û shape: [Alt r]
• input or output: [Alt l]
assignment: [Alt []
â index,: [Alt i]
ô format: [Alt ']
Seperator: [Alt `]
Seperated Statemnts using are exectuted in left to right order.
Internally APL statements are interpreted from right to left.#
Functions and use are illustrated by the following examples:
MODEL 1. 'The SUM model
Y is equal to the SUM of the parts X1, X2 ... .
Y = X1 + X2 + X3 + ... + Xn. 'Xi' may be positive or negative.
'i' is a monotonic index beginning with 1, or 0.
The conservation laws that form the basis for accounting,
engineering, science and other aspecsts of life or nature are SUM
models. They assume that 'the whole' is equal to the SUM of the
parts. For some processes this may not be true and 'the whole'
may be greater or equal to the sum of the parts.
In APL this is written as Y +/ X
Where: X is a list of the various X's or parts.
Y+/X is verbalized as:
Y is assigned the SUM (plus reduction) of the X's.
To illustrate the SUM model discussed above, or for APL to
interpret any line on the display use the following:
Move the cursor to the line you want to interpret with the [][]
keys and then key [Enter].
The expressions below illustrate the SUM model:
'¦' is the comment symbol. The interpreter ignores characters
to the right of '¦'.
'ô' is the format primtive. It displays the value of the
variable when used as shown below. 'ô' converts numeric to
character.
'' is the statement seperator.
'‘r' is a MYSYS function to restore the panel.
ôX12 10 8 6 4 2 3 5 7 9 11 ‘r ¦ assignment of the values of X
ôY+/X ‘r ¦ assign the plus reduction of X to Y and Dislay Y'#
All of the above on one line; • is used to display results:
ôY+/•X12 10 8 6 4 2 3 5 7 9 11 ‘r ¦ includes assignment
+/12 10 8 6 4 2 3 5 7 9 11 ‘r ¦ no assignment.
MODEL 2. 'The RATE, or LINEAR model'
Y is Rate MULTIPLIED by quantity (general linear model).
Y = aQ ¦ in conventional algebraic notation. The line passes
through the origin.
Note: either or both a and Q may single quantities or lists. If
both are lists they must be the same length or there must be some
rule for matching one list with another. If 'a' and 'Q' are
singletons they define a line in two dimensions. If 'a' and 'Q'
are vectors of length two then they define a line in three
dimensions, and so on.
In APL if a and Q are the same length, then: (ûa) = ûQ. 'û' is
the shape primitive and is used to count the number of items in
'a' and 'Q'.
The multiplication primitive is '’' and the model is written as:
Y a ’ Q ¦ assumes a[n] is multipiled by Q[n]
Example:
ôa4.7 5.2 5.6 ôQ125 203 178 ôYa’Q ‘r
If a and Q are of different lengths or if all a's are to be
applied to all Q's indivdually then the model is written as:
Yaø.’Q ¦ 'ø.’' is the 'outer product notation and produces an
¦ array of possible combinations of the a and Q values.
¦ note: 'ø' is the 'jot' primitive, [Alt j]
¦ '.' is the 'dot' primitive, '.'on keyboard.#
Example:
ôa3.1 3.5 3.9 4 ôQ100 130 150 170 200 ôYaø.’Q
To sum any of the variables, or parts of the array use '+/'
+/a +/Q ‘r ¦ eg. of sums of each of the input variables
+/,Y ‘r ¦ sum all the elements of the array
+/Y ‘r ¦ sum of list or row sums of a matrix
+ëY ‘r ¦ sum of list or column sum of matrix
+/[1]Y ‘r ¦ sum across the first dimension (rows)
+/[2]Y ‘r ¦ sum across the second dimension (columns)
+ëaø.’Q ‘r ¦ example of a model that asks for the column
¦ sums of the outer product of a and Q.
In APL + - ’ ö * < ó = ò > † ú ^ ~ å ê all can be used in the
outer product definiton. There are therfore many variations of
the above model form.#
MODEL 3. 'FIXED plus VARIBLE amounts model'
Y is a fixed amount plus a rate multiplied by quantity. This is a
more general version of MODEL 2. because it allows the line to be
offset from the origin. The constant term defines the amount of
the offset.
Y = C + aQ or Y = aQ + C in Algebraic notation
(precedence rules multiply a by Q and add the result to C.
Where: a is rate,
Q is quantity, and
C is a constant amount.
When 'a, Q, C' ae singletons the model is a constant plus
directly varying amount (first degree polynomial), or general
straight line in two dimensions that is not necessarily through
the origin.
In APL this model can be written as:
Y C + a ’ Q ¦ C, a, Q may be singletons or equal length lists
If C, a and Q are equal length lists they define a straight line
in ûC = ûa = ûC dimensions. Note the number of dimensions is
limited only by APL system constraints. C may be a singleton or
vector = ûa. This is a multidimensional linear model.#
A variation of the above is practical in APL if the outer product
formulation is used. 'a' and 'Q' may be vectors of any practical
length. 'C' must be a singleton or an array with dimension of
(ûa), ûQ. The APL outer product formulation appears as follows:
Y C + aø.’Q ¦ Where: a, Q, may be unequal length lists, if C
¦ not a singleton it must be an array matching
¦ the shape of aø.’Q.
Example: (C is singleton ,i.e. one number)
ôC19 ôa4.7 5.2 5.6 ôQ125 203 178 ôYa’Q ‘r
ôC19 20 21 ûC a ûa ôYC+a’Q ¦ ûC=ûa=ûQ ‘r
If aø.’Q is used it produces a matrix and C must be a singleton
or matrix if it is to be added.
a ûa ‘r ¦ Review values assigned to 'a'
ôQ125 203 178 190 150 201 ûQ ‘r ¦ Incease length of Q
(ûa),ûQ ‘r ¦ Required Shape of 'C' array
ôC3 6û1 2 3 4 5 6 ûC ‘r ¦ Provide matching 'C`s'
ôY C + aø.’Q #
MODEL 4. 'The PRODUCT or Pi model of mathematics'
Y is equal the product of several factors.
Y = abc . ... . n or Y equals a times b times c . ... . times n.
In APL this model can be written as: Ya’b’c, or Y’/X
where X is a list of numeric quantities.
a3 b5 c7 ‘r ¦ assignment of values to a, b, and c
’/a,b,c ‘r ¦ simple example of product model
Note the above model can include recriprical or ratio terms. The
'•' below are inserted to reveal the elements of the product.
’/•a,(öb),c ’/•a, böc ‘r#
MODEL 5. 'The RATIO model'
The ratio model is a variant of the product model and is shown
because it exists as a unique variant of the use of the reduction
operator.
Y = abc/def ALGEBRAIC.
i.e (a times b times c)ö(d times e times f)
a b c
or Y = ÄÄÄ ’ ÄÄÄ ’ ÄÄÄ
d e f
In APL this model can be written simply as:
Yö/a,d,b,e,c,f ‘r
¦ divide reduction alternates between ö and ’#
MODEL 6. 'The EXPONENTIAL model'
Y equals a quantity raised to a power.
Y = X
In APL this expression is written as YX*n
e.g. Pythagoras' theorm on the properties of a right triangle
a3 b4 ‘r ¦ assignments for a 3, 4, 5 Triangle
ôc (+/(a*2),b*2)*ö2 ‘r ¦ note the parentheses are necessary
¦ APL has no other precedence rules.
x13 y23 zý16 ‘r ¦ assignments of x, y, z projections
ôr(+/(x*2),(y*2),z*2)*ö2 ‘r ¦ length of the vector in 3 space
¦ from its x, y, z components.
The LOGARITHMIC functions are written similarly to the exponental
functions above. The natural Log of 'a' is:
Y a
The log of a to base n is:
Y n a ¦ Therefore the log of a to base 10 is Y10 a#
MODEL 7. 'The CIRCLUAR (transcendental functions) models'
In APL there are 16 variations of the circular function ù to give
the triginometric & hyperbolic functions, and their inverses. The
monadic version is equivalent to pi times. e.g.
ù.5 ¦ is pi times 0.5 or a right angle in radians.
ùö180 ¦ is the number of radians per Degree.
ùö200 ¦ is the number of radians per Grad.
The common trig functions of the angle a in radians are:
Y 1 ù a ¦ Sine a þ Y ý1 ù a ¦ Inverse Sine a
Y 2 ù a ¦ Cosine a þ Y ý2 ù a ¦ Inverse Cosine a
Y 3 ù a ¦ Tamgent a þ Y ý3 ù a ¦ Inverse Tangent a
The meanings of the other circular fns are given by:
‘cc'8' ¦ Trig Idioms#
MODEL 8.
Y = (an ’ X*n ) + ..... (a2 ’ X*2 ) + (a1 ’ X) + a0
This is a polynomial of degree n and is often used as an
approximation when relationships are non linear.
A straight line is a first degree polynomial.
In APL a polynomial can be written as:
Y X æ A ¦ Where: A is a list of an, .... a2,a1,a0
¦ The a's are the polynomial coefficients.
X æ A is the general polynomial including a straight line.
A is list of coefficients and can be used to describe a line.
To evaluate A at several points X must be a column (vector) The
idiom for making column from a row is (X ø.+,0)
Y(X ø.+,0) æ A ¦ is one of the expressions that can be used.
¦ Example: Three degree polynommial: Y 0.1’X*2 + 2’X + 7
¦ below A coef. a, X values of x, and Y is list of y's
ôA .1 2 7 ô X1 1.5 2 2.5 3 ôY(X ø.+,0) æ A #
MODEL 9.
In general a model can consist of a number of primitives and can
be executed directly (immediate execution) or stated as as a
'defined function' and used as a program or subroutine.
Eg. the arithmetic mean of a list of numbers X can be written
for immediate execution in APL as:
(+/X)öûX ¦ common expressions are often called idioms in APL.
Or 'defined' as the function MEAN by:
ìrMEAN X
r(+/X)öûXì
û {shape} counts the number of items in X
ì {del} is used to open and close function definition
{left arrow} assigns the results to r {explicit definition}
Functions can be defined using the full screen editor:
)EDIT ìMEAN
Or using a direct definition function (FN in MYSYS), e.g.:
FN 'MEAN:r(+/)öû'
Defined functions have few naming restrictions, e.g. a difference
function ‘ could be defined using Iverson's direct definition as:
‘df '‘:(1)-ý1'
or with the fs editor using ')edit ì‘', then:
r‘ w
r(1w)-ý1w
Defined functions are similar to the lists of statments called
programs, routines, subroutines, etc. in many other computer
programming languages. In APL as in other languages it is
convienent to save copies of the routines.#
In MYSYS these are generally saved in the UTILS.SF or 'f' file.
‘get'f1' ¦ List directory of UTILS.SF. The ones that are most
frequently used are stored in utility packages saved in UVARS.SF
file, and as USER COMMANDS in UCMDS.SF.
]? ¦ List user commands.
Other short expressions and techniques used in writing defined
functions are stored as HELP object in IDIOM.SF.
‘cc'1' ¦ Access the idiom file directory
There are many other more specialized functions stored in various
tutorials, and in the workspaces. The function names in a
workspace are listed by:
)fns ¦ or •nl 3 can also be used.
The public comments, i.e. the primary documentation stored with a
function can be listed by: ‘e 'function name'. e.g.
‘e •nl 3 ¦ List all public comments of functions in workspace.
Use the following from APLie for further infomation:
LESSON 'x9' ¦ More on models and fitting functions to data.
‘hq 'models'¦ HELPS on MODELS
End to date, ams 990626