About high-level
and not-very-high-level programming languages
(APL
vs.
classical languages )
par Andrei Buzin
Twenty five years ago I was a
student in applied mathematics fter a concise course of programming
by machine codes we began study the programming language ALGOL - one of a few
high-level language of that time. rogramming with ALGOL was
essentially more intellectual work than programming with machine codes.
Nevertheless, I was very surprised, when the teacher gave us the task to
calculate the result of 2×2
multiplication. Too much routine operations we must make to solve this
elementary problem: a)to write the program with head, «begin», «output»,
«end»; b)supply the program with operating system directives; c)debug,
translate, and start in special manner.
Computers have made the giant progress in last 25 years...Now anybody knows
that 2×2 is an example not for computers
but for calculators, and test example for modern programming languages is not
the printing of 4, but the printing of "Hello World". Let we see how
the modern JAVA carries out this task [1]:
class
HelloWorld {
public static void main (String args[]) {
System.out.println("Hello
World");}}
Are here not too many words for
describing such a work?
The high-level programming languages
differ from low-level languages firstly by their possibility to operate with
the named (not numerated) data, secondly by substitution of often used command
constructions by more accustomed lexems (FOR...NEXT, IF...THEN..., WRITE etc.).
The evolution of classical programming paradigm (procedural, structural,
object-oriented) concerns the structure of program code, in
little extent - the structure of data; practically nothing was to simplify the elementary language
constructions. Descriptions of input/output, using of external libraries,
processing of complex data structures remain very diffuse in classical
programming languages. These languages don't shoulder the work, which must be by intellectual assistant - the
automatic research of data used and relief in processing, input and output of
the data in the whole (not by their elements). In this sense C++ remains on
FORTRAN level.
The reason is that the modern
programming languages was developed by programmers for programmers, unlike
first programming languages, which
was developed for engineers and applied scientists. Not the universal languages
but corresponding software packages was proposed to use for applicators
(engineers and scientists). This makes the human-computer interaction more
effective in many cases, and this tendency will remain in future apparently.
The necessity to wield a universal programming language will be the portion of
system programmers only.
Nevertheless it is avowed that
engineers and applied mathematicians must study programming languages. There
are some reasons in this tradition. Really, it is not always possible to find
quickly inexpensive adequate software. Really, the study of programming
languages gives the practice of algorithmization and of information
structurization. Really, some software systems can be extended by the user, if
this user knows one of popular programming language.
But the question about the
efficiency of teaching classical universal programming language for applicators
is problematic. Why such a user must know how the processor registers works and
how the memory is allocated; why must he write such programs, the most part of
which has no direct relation to the problem? Is it interesting for you how is
organized the coffee-grinder, you are using to prepare your coffee?
To see the large difference between
mathematical and programming cultures we can compare the difference in their
terminology. The terms "variable", "function",
"operator" are used both in mathematics and in programming, but the
meanings of this words are essentially different in each scope.
The other confirmation of divergence of two cultures is their approach
to data arrays. The commonly used operations with data arrays such as
transposition MT, inverse M‑1, minimax, trace
, minor , where M is a matrix, or mean , norm, where x is a
vector, are accustomed in mathematics, but are programmed by unwieldy
cycles. The operations with functions
(in mathematical sense) is also diffuse; for example, if we want designate the
first derivation of a function, we must write few lines of code (and double
cycle for Jacobian); unlike the mathematical notation, which is very
concise.
Thoughthere are libraries' procedures for
operations with arrays and functions, these can not cover all desirable
operations. The elementary matrix by scalar multiplication demands in general
case the using of double cycle. We must use the double cycle by multiplication
of column-vector by row-vector too. Moreover, the programmer must explain to
computer, that the result will be two-dimensional array (matrix) and must
describe it especially.
Arrays and functions are not the
most complex objects considered in mathematics. Until the last time (when the
structure type appeared in C) the classical programming languages do not give
the convenient means for nested arrays representation. It is impossible to
describe the structure such as genealogical tree in PASCAL, and rather hard it
can be made in C.
Worth to say that the
object-oriented paradigm has partly solved the problem of definition of new
operations with arbitrary structures (so called overloading of operations), but
the detailed descriptions of structures and operations definitions take a bit
of doing.
Two problems are important for
programmer, but not interesting for mathematician: the memory allocation of
data and organization of cycles.
First problem arises because the
representation of data can influence on program processing. The programmer must
know how the variable with value 2, for example is represented in the memory: is it
integer or real, of ordinary or of double precision. The result of the division
4/2 is unambiguous for mathematician, but it is not true for programmer.
What about cycles, we can say, that
a programmer thinks in terms of cycles. To qualify the programmer means to
drill the students to speak in terms of cycles. Diong so is the most complex
task in teaching programming, because the cycle are not very often in natural
and in mathematical languages. Why the task «Say the maximal value in this
numerical set» is easy for scholar, but the task of writing the computer
program in programming language, which find the maximal value among the
numbers, claims special training? The reason is that by using classical
programming we must represent the problem as repetition of some unified
operations. But the cycle is not the essence of
problem involved (see, by the way, that there are many types of cycles,
which solves this problem). In English or in mathematical language (), the solution is more concise; I believe the human mind
does not work cyclically solving this task.
We can regret that if we discard the
cycles, then the students will not be able to solve the problems
algorithmicaly, but these doubt is of the same sort as the doubt about using
calculator in the school.
Let we see how the classical Pascal
solves the problem to find maximum among
the set of numbers. The following text is adopted from tutorial [2]; but the
solution is analogues in other classical languages.
Program
Max(input,output); (*1*)
const
M=10;N=20; (*2*)
var
i,j:M..N; (*3*)
X:array
[M..N] of real; (*4*)
begin (*5*)
for i:=M
to N do (*6*)
read
(X[I]); (*7*)
j:=M; (*8*)
for
i:=M+1 to N do (*9*)
if
X[i]>X[j] (*10*)
then j:=i; (*11*)
writeln(X[j]); (*12*)
end. (*13*)
This program inputs eleven numbers
from keyboard and outputs one maximal value among these numbers (lines are
enumerated for citation).
The first word «Program» is to show
the head program in software package (which consists of only one program in our
case). It is synonym of «
After this in parenthesis «(input,
output)» is the message that the program will interact with input/output
devices. Can the translator guess this fact from lines 7 and 12 or not? This
message looks in C as preprocessor directive such as #include <iostream.h>.
Semicolons are out discussing - it
is a matter of taste.
Line 2 can be used for the sake of
rapid modification of the program, in the case if the data involved will be
consisted of twelve, not eleven numbers. Can the translator count the numbers,
which will be inputted? Why not?
Line 3 works out two problems. At
first, - allocate two bytes for each of variables i and j and describe the
format of these bytes. Secondly, - tell to translator to watch the variables i and j can not pass the limits M and N. The last instruction is
reasonable: it enhances the reliability of the program. But what is
interesting: we make themselves the asperity by using the concrete (i-th) elements of array (X[i]), then we
solve the problem of consistency of variable i. More logically will be to say for translator: do it with all elements
of array.
Line 4. Reserve 11 four-bytes cells
for elements of vector X. Check X can not be the simple variable,
two-dimensional array or vulgarism. If
you do not confide to the user (there are, of course, some grounds for such
disbelief), is it not more simple to check his input in line 7?
Lines 2-4 are the impost for our
blunt translator. We are questioned for input some numbers and output one of
them in the screen. Note, in formulation of our problem there are no word that
input and output must have the names. What is the reason to invent five names?
I think, it is routine work and can be done by computer.
Lines 5 and 13. In classical
languages it is always necessary to separate something from function (program)
body. Writing «Begin» and «End» was bored for inventors of C and they changed
them for unique symbols «{» and «}» consistently. That’s more convenient, but
you can see, that this separation is the consequence of grammatical parting of
program. The classical program has usually three part: head, descriptions and
the body.
Lines 6 and 7. Input of X array. Of
course, we must order this work for translator. But why must we do the input 11
times for each element of X? In line 4 we have told to our translator, that X
has 11 elements, now we must ask about first, second and so on elements
separately. We converse with translator as with child of three years; the child
of four years can answer the less detailed question «Say some numbers» already.
If anything is known about X, then to realize the instruction «Read X» is not
more complex then the lines 6-7. Why must the programmer grind this fact to
translator?
Lines 8-12 are the essence of
solution. They are, in fact, the phraseFind
maximum element in numerical set given translated from English to Pascal.This phrase is, of course,
ineluctable and if the translator can understand it only in such form, then we
must write it in this form. It characterize only the possibilities of the
translator. Other translators (Excel, Mathematica, mathematician, Russian,
Englishmen, Japanese) can understand this phrase in other form (see Table).
Language |
Problem
formulation |
Russian | Íàéòè íàèáîëüøèé ýëåìåíò â çàäàííîì íàáîðå
÷èñåë. |
English |
Find
maximum element in numerical set given. |
Japanese | |
Pascal | j:=M;for i:=M+1 to N do if X[i]>X[j] then j:=i; writeln(X[j]); |
C++ | j=M;for (int i=M+1;i<N;i++) if(X[i]>X[j])then j=i;cout<<X[j]; |
Excel and other languages with
function Max |
Max(X) |
Mathematics | max {xM, xM+1,..., xN} |
Lines 8-12 reflect not only the
essence of the problem, but the style of thinking, bound up with the classical
programming languages. If you are proposed to find the maximum among eleven
numbers, will you operate in such a manner: memorize the first number, consider
the second, if it is more then memorized number, then change the later,
consider the third... and so on? I believe not.
Let we discuss the line 12
separately (This discussion is also true for line 7). This line gives to the
translator a directive to output j-th
element of X to the screen, then move the cursor to the next line. Firstly, the
parenthesis here are surplus: «writeln» is an special keyword and to separate
this word from argument one special symbol (which can not be used as the first
symbol of argument) can be used (blank, for example). Note, that in the case,
when the name of output procedure is constructed by the symbols, prohibited for
argument, the separation will be quite unnecessary. Secondly, let we see, what
will happen, if we will forget to write the name «writeln». It will remain the
expression «X[j]». Pascal treats this expression as an error. But it is very
natural to treat this expression as the request to output the value X[j]. In
this case the notation will be more concise and, what is important, more
usually: to compute 2×2 we
must write only «2×2»,
and to output «Hello World» - only
'Hello World'.
Summarize our analysis of program
involved. To claim the computer to give one maximum from the set of numbers, we
had writtten about 150 symbols. Much of that we had written, has no relation to the essence of
problem involved, but describes the structure of data and very detailed
instructions how to operate these data (in terms of described structure).
Really, Pascal is more convenient in comparison with assembler, but do you not
feeling that it concuss the programmer to do the routine work?
What orders we must deliver to the
computer to solve the «maximum» problem? Try to formulate this orders in such a
manner, that on the one hand, they will be represented as clear algorithm, on
the other hand, they will be not very complex to translate in classical
programming language (that is not very complex to translate in machine code):
[0]
Max
[1]
Check_whether_the_operations_correspond_to_the_objects_processed
[2]
Insert_the_elementary_maximum_function_between_the_elements_of_the_object_inputed_from_keyboard_and_compute_the_expression
Such a program will calculate the
maximum of input set of numbers and output the maximum to the screen, because
we believe that the explicit result of expression (calculated in line [2]) will
be printed in the screen by default.
Now we use some abbreviations
in our algorithm (numeration is only for
citation):
[0]
Max
[1]
R
TRAP‑0
'C'
'''Some error!'''
[2]
/R
[3]
If you mean, that this program is
the product of my dreams, you are mistaken! It is the real program in APL
(version DyalogAPL/W v.7.2.5).
Let we see now that the problem is
resolved in essence by this program. Are you asking for data input? Yes; the
program asked for the data by the aid of symbol «R» in line [2]. It may be this symbol makes afraid, because it is not present on
the keyboard and you must memorize the keyboard placement of such symbols. May
be it is easier for you to remember that input is designated by «read» or
«cin», or mouthful «istrstream»? Every man to his own taste. If you want, you
can redesignate «R» by
«read» or even by «read(X)». But the symbol «R» has a strong advantage in comparison with
other inputs in different languages: it is simultaneously the input order and
the variable, which has the value of input! We are asked to analyze the input,
not the unknown X, and in APL we must not invent some new name for this input.
Line [2] includes the instruction to proceed the input.
Left from the symbol «R» in line [2] you can see what
the translator must do with the input, that is the description of computing
algorithm. But be not afraid that you must memorize the exotic names such as «/». Though this is really the name
of function «maximum of the number set», it consists of two independent lexems,
which describe two separate actions: «» is the name of elementary function of maximum
between two numbers and «/» is the name of so called «reduction» - operation,
which inserts the name of any dyadic function between the elements of the set
(if possible). So, notation «/» designate the concise notation of algorithm
which looks for a maximum in the number set (if the number set is represented
as one-dimensional array, then the result is obvious; in other cases there are
some default conventions about grouping of elements).
Now then, in line [2] is the
following instruction: insert the maximum function between elements of input.
If, for example, we shell input the numbers 4,7,5 then the function
/ generates the expression 475, which will be treated by APL-translator as max{4,max{7,5}} and gives the number 7. Explicit result will be put on
the screen by default. Let we see the protocol of work of our APL-function:
Max
:
7 4 5 19 23.7 4 28 6 28 11 11
28
So, the algorithm of solving is in
all in line 2. What is the mission of lines [0] and [1]?
Line [1] executes the checking of
input data. In fact it simulates the implicit checking which is made by Pascal
due to descriptions of the data. This line reveals some types of errors in
input, for example, if the input is symbolic, not numerical. It seems strange,
that APL, which disembarrasses the user from routine operations, ask him for
checking the data manually. But the time to describe this checking is
comparable with the time spending for descriptions of data. On the other hand
the programmer is free in his choice by controlling the data.
Line [0] serves to block all
operations (check and maximum search) in one function. If you don’t need the
data checking, you can solve the problem interactively in one line:
/
:
7 4 8 3
8
What are the conclusions of our
comparative analysis of two programming styles? APL excuses us from practically
all operations, which has no relations with the problem. We must not invent the
names of memory cells, which will be used by computer solution. We must not
describe their structure. We was delivered from element by element input and
output of data. And finally, the algorithm was described only by two symbols.
The expression
/R is on one hand the correct APL-expression, on
the other hand, it can be used always, where the function Max must be used. The algorithm
expressed by this three symbols means: «Input the data, Find the maximum and
Output the result». Important is that it is not the mnemonic name, but real
algorithm, written by three separately lexems. Similarly, summation of one-dimensional array of numbers, which are
inputted from keyboard, can be written in such a way:
+/
:
7 4 8 3
22
The product of elements of arbitrary
numeric vector X can be coded as «×/X».
The result of expression is explicit result
and can be used in other expression:
1+/7 4 8 3
9
Note, that the reason of conciseness
of APL-notation is not the same as in languages, which have a giant number of
built-in functions (Mathematica, MathCad etc.). The notation of maximum
algorithm is very concise because of a)using of operation (/), defined on
function and
b)using the special symbols (,R).
The second reason is not principal,
because the notation «#max #reduction #input» is also essentially
more laconic than of classical languages one.
APL tries to deliver the programmer
from routine work. In this sense it is more intellectual and is the language of
higher level in comparison with Pascal, C and so on.
The famous Russian poet Majakovski
wrote, that he would choose the Russian language because Lenin was spoken it. I
believe that the reason to chose C++ is of this type: Bill Gates and his
company speak it. Choice of method of communication with computer is
determinated not only by effectiveness of this method, but also by its
accessibility and by its popularity in your environment. For example, OS/2 is
evaluated by many programmers as more effective than Windows, but the later is
essentially more popular.
Traditionally the education in
computer science means the study of classical programming language. The
selection one of this language depends to a great extent from taste of teacher,
not from advantages of language. Sometimes there are absurd situation, when the
students study Basic at first year, Pascal at second, C at third. The
difference between this languages is linguistic, not ideological.
The ideological innovations are that
what make the languages more effective. For example, the object-oriented idea
permits to make programming more effective with the mean of fast cloning of
large objects. Object-oriented Pascal 7.0 differ from Pascal 4.0 more then from
C++.
At the beginning of computer era the
communication with computer was in the level of baby talk. Now the computers
are in the age of maturity and we can communicate with them by more serious
languages. The language used depends, of course, on the theme of communication.
If you are using computer to create the booklets, the «3DSudio» is more useful
for you than Pascal. This languages is prior for educational institution, which
profess admen. Teaching «baby talk» is not serious work.
There is some by-effect in study of
classical procedural languages. They educate in the students some order in
problem solution. This means the partition of the problem in such parts, which
have obvious solution. But «obvious solution» is not common term! People say
that Landau (the Nobel laureate in physics) liked to stump his colleagues by
the phrase «It’s obvious!» related with very nontrivial mathematical
statements.
If the standard course of
mathematics includes the concept of maximum, scalar and vector product, matrix multiplication etc.,
then why their notations in programming language are in terms of arrays’
elements? May be more serious language can be chosen to code mathematical operations?
My shift to APL was stimulated in
great extent by some monographs in
computer investigation of mathematical models. Very large part of these
books was occupied by the text with programming code.
The situation changes striking with
APL. In one lab you can solve several standard problems. It is promoted by
APL-ideology and conciseness of this language.
Let we see some examples of problem
solution by APL. Note, that sometimes you can solve the problem not in form of
function (program), but in form of one interactive expression. At first, see
the simplicity of input/output operations with arrays.
1)Add 1 to each component of the vector:
1+2 3 4 5
‑Programmers
directive
3 4 5 6 ‑Answer
2)Add 1 to input:
1+
‑ Programmers
directive
:
‑Input demand
3¢1 2 3 ‑Input
4 7 10 ‑Answer
Note that input
can be an expression!
3)Summarize all components of a vector:
+/3 4 5
12
4) Assign to variable M the value of 3×2-matrix and output the matrix to the screen:
+M3
2½9 8 7 6 5 4
9 8
7 6
5 4
5) Calculate the minimum in each column of
matrix M:
M
5 4
6) Square each element of matrix M:
M*2
81 64
49 36
25 16
7)Define Sin as the name of function to
calculate sine:
Sin1°±
Sine
in APL is a special case so-called «trigonometric primitive»
±.
This
example shows, that APL submits the possibility of overdetermination of
functions names; practically you can achieve similarity of your programs
with text in Pascal or other classical language by such overdeterminations.
8)
Sine of squares of elements of matrix M:
Sin M*2
¯0.6298879943
0.9200260382
¯0.9537526528
¯0.9917788534
¯0.1323517501
¯0.2879033167
9) Calculate MMT (matrix
product M and transposed M)
M+.¢³M
145 111 77
111 85 59
77 59
41
10) Generate, assign to variable A and output
to the screen one random 3×3-matrix with elements in interval [0; 1]:
+A0.1¢?3 3½10
0.5 0.8 1
0.8 0.3 0.1
0.8 0.4 0.7
11) Generate, assign to variable A and output
to the screen one unit 3×3-matrix:
+E(¼3)°.=¼3
1 0 0
0 1 0
0 0 1
12)
Inverse
matrix (E-A)-1:
E-A
¯0.1617507136
¯0.608943863 ¯0.742150333
¯0.3044719315
0.6184586108 ¯0.808753568
¯0.8372978116
¯0.7992388202 0.2759276879
13)
Four first powers of matrix A:
+.¢\4½A
0.5 0.8 1 1.69 1.04 1.28 2.701 2.176 2.69 5.2433
3.8896 4.8016
0.8 0.3 0.1 0.72 0.77 0.9 1.696
1.167 1.427 2.9232 2.2777 2.8116
0.8 0.4 0.7 1.28 1.04 1.33 2.536 1.868 2.315 4.6144 3.5152 4.3433
14)
Number of negative elements in matrix (E-A)-1:
+/,0>E-A
7
APL works
successful with arrays, containing the data of different types and structure.
15)
Assign and output the variable Q as a
matrix with numbers and symbols:
+Q('' 'Èâaíoâ' 'Ïempoâ' 'Cèäopoâ')('Èþíü' 10 20
30)('Èþëü' 3 2 1)('Aâãycm' 4 5 60000)
‑Programmer
directive
Èâaíoâ Ïempoâ Cèäopoâ ‑|
Èþíü 10 20 30 ‑|
Èþëü 3 2 1 ‑|‑Answer
Aâãycm 4 5 60000
‑|
Note that output
was formatted automatically.
16)Add the
«Total» column to matrix Q:
(³Q),(' Total'),+1 1Q
Èþíü
Èþëü Aâãycm Òotal
Èâaíoâ 10
3 4 17
Ïempoâ 20
2 5 27
Cèäopoâ 30 1 60000
60031
17)APL works with data structures of arbitrary complexity;
its description is constructive! You can see below example of a matrix which
elements are scalars, nested matrix, vectors and function definition yet.
Different elements are enclosed in frames for visualization:
.
-------------------------------------------------------.
.
--. |
| 2 A |3 B| |
| - '+--' |
| .
----------. .
----------------------.
.------------. |
| | .
--. | .
--.
| | 0 1 ° +.¢ | |
| | 4 5 |ABC| | | 2 A |3 B|
| | ¯1 0 | |
| | '---' | | - '+--'
| '-----------' |
| '¹----------' | .
----------. | |
| | | .
--.
| 2 A | |
| | | 4 5 |ABC| | - | |
| | | '---' |
| |
| | '¹----------' | |
| '¹----------------------' |
'¹-------------------------------------------------------'
Now we will show some programs in
APL, its description and use (Programs in APL are of two types - functions and
operators).
18) The following text is the
definition of a function which calculates the polynomial in points x (it can be a vector) with coefficients
(the line numeration
is not necessary):
[0]
ra
Pol x
[1]
r(,[«]x)a
Using of this function is much more
flexible than in classical programming languages:
1 0 1 Pol 0.01¢¼10
‑Calculate
õ2+1 in points 0.01,0.02,...,0.1
1.0001 1.0004
1.0009 1.0016 1.0025 1.0036 1.0049 1.0064 1.0081 1.01
Pol
‑Calculate
polynomial with coefficients and points inputted from keyboard:
:
1 2 3
‑Input points
:
1 0 1
‑Input coefficients
2 5 10
19)User defined operator to find the
numerical (with increment
) derivative of function f
in points x:
[0]
r(
Diff f)x
[1]
r((f x+)-f x)£
[2]
Example of use:
0.001
Diff Sin 3.14 0 1.57
¯0.9999993614 0.9999998333 0.0002963267782
Note that in APL, analogous as in
mathematics, function of function is called operator. The similarity of
operators in APL and in mathematics is more stronger. Operator applied to the
function generates other function (we mean function as a mapping data into
data). For example, the expression 0.001 Diff Sin
is the name
of some function (numerical approximation of cosine), which can be used as any
other function name, say, we can differentiate it:
0.001 Diff (0.001 Diff Sin) 3.14 0 1.57
¯0.0005926535057
¯0.0009999997501 ¯0.9999998959
It
is possible to differentiate more complex functions. Here is an example of
numerical derivation (with increment 0.001) of polynomials
x2+1 in points
0.01,0.02..., 0.1:
0.001 Diff (1 0 1°Pol) 1 2 3
2.001 4.001
6.001
20)Here is the user
function which calculates the coefficients of trigonometric interpolation (up to m-th) of an arbitrary set of
points, given by their coordinates on a plane (spectral analysis).
[0]
r‑m Furmin xy;x;y
[1]
x y‑xy
[2]
r‑y}1,(2±x°.×¼m),1±x°.×¼m
21)
[0]
xNE(F
Newton DF)x0;n;N;E;w
[1]
©Newton
method for the system F(x)=0 with Jacobian DF
[2]
©
initial point x0;max number of iterations N; accuracy E
[3]
N ENE
©Halt parameters
[4]
n0
©Iterations
counter
[5]
xx0
[6]
lOOP:
x0x
[7]
xx0-(F x0)DF x0
©Iteration
[8]
((N<nn+1)(E<0.5*¥w+.¢wx-x0))/nOT
lOOP
[9]
0
[10]nOT:x«
©If
the method converges
As the F and DF
functions are formal operands, it is possible to use any name of permissible
function. Here, for example, is the calculation of a solution of equation x2-1=0, using
the
function Pol, described above:
20 0.001 (1 0 ¯1°Pol) Newton (2 0°Pol) 2
1.000000046
If
we use an APL-operator for calculating Jacobian:
[0]
J(
Jacobian F)x
[1]
J¢J°.=J¼½x
[2]
J(³(F¤(x)+J)-F x)£
,
then we can solve nonlinear algebraic system of arbitrary dimension. For
example:
50 .01 F42 Newton (.000001 Jacobian F42) 0.1 0
0 0
¯2.136559765
10.14085331 2.048642888 ¯0.05293643388
Here F42 is an APL
function which describes one nonlinear algebraic system with four variables
(see [3], p.112).
The above mentioned
operations (equation solution or
interpolation) are certainly presented in standard software. But in our case
they are completely open for modifications and are rather flexible, for
example, they can be used as operands for other operations.
22)
Here is an example of description
and research of a mathematical model of an stochastic process, known as «birth and death process»:
[0]
rNn
BirthDeath lambda;i;n;N
[1]
©Birth-Death
process with Poisson distribution
[2]
N nNn
[3]
r,n
[4]
:For i :In ¼N
[5]
rr,n+/n Poisson lambda 20
[6]
:EndFor
The function which
generates n random numbers distributed by Poisson law
with parameter lambda is described
as:
[0]
rn
Poisson par;P;k;w;q;lambda
[1]
©Generates
n random numbers distributed approximately by Poisson with parameter lambda
[2]
©q
is the maximal value of random value
[3]
lambda qpar
[4]
P+\(*-lambda)¢(lambda*k)£!k0,¼q
[5]
w0.000001¢?n/1000000 ©n equidistributed random values
[6]
r1+q-(+/w°.<P)
Our APL-model is not
only concise, but (and it is more important) it is very convenient for
experiments. Its result, which is a vector of N numbers, may be investigated in interactive mode:
Calculation of a trajectory of birth and death
process and of its average:
0.1¢+/10 100 BirthDeath 1.01
100 112 114 115
114 105 100 107 120 145 142
127.4
Calculation
of other trajectory and increments of this trajectory:
1T-¯1²T10
100 BirthDeath 1.01
100 99 85 89 93
93 93 69 76 72 79
¯1 ¯14 4 4 0 0
¯24 7 ¯4 7
Though APL is especially
attractive for applied mathematicians and modellers, it is universal language
permitting to create modern graphics applications, network or databases.
'We should not overestimate the value of classical programming languages
for courses of computer science. APL is good alternative.'
[1] Naughton, Patrick «The JAVA
Handbook», Osborn, McGraw-Hill,1996
[2]Perminov, O.N. «Programming in
Pascal»,
[3]Monastyrnyi,P.I.(ed.) «Collection
of Exercises in Calculation Methods»,