prog1
2001-06-01
experimental
2001-02-16
0
0
arith1
quant1
relation1
A CD for basic algorithmic concepts. We define the minimal machinery to write
small programs in OpenMath encoding.
assignment
This symbol is used to assign values to variables. The syntax is
assignment(variable, value), where variable is the encoding of an
OpenMath variable (OMV) and value is an OpenMath object.
The assignment a := 125 is encoded as
125
block
This symbol is meant to represent an arbitray block of code. A block of code
can be empty. The syntax is block(obj1, obj2,...,objN), where obji is the
OpenMath encoding of the ith sentence (or action) inside the body.
The following block of code
{
a := 153;
a := a+1;
}
is encoded as
153
local_var
This symbol can be used to declare local variables.
global_var
This symbol can be used to declare global variables as know to function.
return
This symbol can be used to return values from fuctions.
for
This symbol can be used to encode the for loop. The syntax is
for(block1,conditional_block,block3,block4), where block1 is the
inicialization block, conditional_block is the conditional block that
determines the end of the loop, block3 is the incremental block and block4
is the body of the for loop. Each of this blocks should be present (althougth
they can be empty).
while
The symbol the while loop. The syntax is while(conditional_block, block1), where
conditional_block is the block that determines when to stop the while loop and
block1 is the body of the while loop.
if
The symbol can be used to encode the if, then, else construct. The syntax is
if(conditional_block,block1,block2), where the conditional_block is the block
that determines wich of the block of codes block1 and block2 is going to be
executed, block1 is the then block and block2 if the else block. The
conditional_block and block1 are required but block2 is optional.
call_arguments
This symbol can be used to encode the arguments that will be pased to a function
or procedure.
def_arguments
This symbol can be used to encode the arguments that a function or procedure
can receive.
function_block
The block of code defining the body of the function. The syntax is
function_block(local_var,block1), where local_var encodes the local
variables (private to the function body) and block1 is the body of
the function. Both locar_var and block1 should be present (and of
course both can be also empty).
function_definition
The symbol function_definition can be is used to define a function. The syntax is
function_definition(name, def_arguments, function_block), where name is the
encoding of an OpenMath variable (OMV) representing the name of the funtion,
def_arguments is the enconding of the arguments that the function receives and
function_block is the body of the function (local variables declarations +
body of the function). Functions are completely unaware of the rest of the
"world" except for the information they received from the arguments. Functions
are only allowed to return values by means of the return construct.
The function (in Maple notation),
MyFunction:=proc(N) local i, Result; Result := 1; for i from 2 to N do
Result := Result + i^10; od; Result; end;, is encoded as
1
2
1
10
1
The encoding of a function N --> 1+2^3+...+N^3 (uses the while loop)
is
1
0
3
1
The encoding of a function the compute the Nth term of the Fibonacci
sequence is
1
2
1
1
2
function_call
Symbol function_call can be used to "call" already defined functions.
The syntax is function_call(name, call_arguments), where name is the
encoding of an OpenMath variable (OMV) representing the name of the
function and call_arguments are the arguments to pass to the function.
Both, name and call_arguments, should be present but call_arguments can be
empty.
The function call "MyFunction(100)" is encoded as
100
procedure_definition
This symbol can be used to define a procedure. The sintax is
procedure_definition(name, def_arguments, procedure_block), where name is the
encoding of an OpenMath variable representing the name of the procedure,
def_arguments encodes the argument the procedure can receive and
procedure_block encodes the body of the procedure. Contrary to function
procedures can have knowledge about global objects by means of the
global_var construct (see procedure block).
procedure_call
Symbol procedure_call can be used to "call" already defined procedures.
The syntax is procedure_call(name, call_arguments), where name is the
encoding of an OpenMath variable (OMV) representing the name of the
function and call_arguments are the arguments to pass to the function.
Both, name and call_arguments, should be present but call_arguments can be
empty.
procedure_block
The block of code defining the body of the procedure. The syntax is
procedure_block(local_var, global_var, block1), where local_var encodes the local
variables (private to the procedure body), gloval_var are global variables that
are know to the procedure and block1 is the body of the procedure. All these
elements, locar_var, global_var and block1, should be present
(but they can also be empty).