OpenMath Content Dictionary: prog1

Canonical URL:
http://www.openmath.org/cd/prog1.ocd
CD Base:
http://www.openmath.org/cd
CD File:
prog1.ocd
CD as XML Encoded OpenMath:
prog1.omcd
Defines:
assignment, block, call_arguments, def_arguments, for, function_block, function_call, function_definition, global_var, if, local_var, procedure_block, procedure_call, procedure_definition, return, while
Date:
2004-02-16
Version:
0 (Revision 1)
Review Date:
2001-06-01
Status:
experimental

A CD for basic algorithmic concepts. We define the minimal machinery to write small programs in OpenMath encoding.

Slightly edited by Arjeh Cohen on Decmeber 24, 2000.


assignment

Role:
application
Description:

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.

Example:
The assignment a := 125 is encoded as
assignment ( a , 125 )
Signatures:
sts


[Next: block] [Last: procedure_block] [Top]

block

Role:
application
Description:

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.

Example:
The following block of code { a := 153; a := a+1; } is encoded as
block ( assignment ( a , 153 ) , assignment ( a , a ) )
Signatures:
sts


[Next: local_var] [Previous: assignment] [Top]

local_var

Role:
application
Description:

This symbol, which can have an aribtrary positive number of arguments which must all be variables, can be used to declare local variables. represents

Signatures:
sts


[Next: global_var] [Previous: block] [Top]

global_var

Role:
application
Description:

This symbol, which can have an aribtrary positive number of arguments which must all be variables, can be used to declare global variables as known to functions.

Signatures:
sts


[Next: return] [Previous: local_var] [Top]

return

Role:
application
Description:

This symbol, which can have an aribtrary positive number of arguments, can be used to return values from functions.

Signatures:
sts


[Next: for] [Previous: global_var] [Top]

for

Role:
application
Description:

This symbol can be used to encode the for loop. The syntax is for(block1,conditional_block,block3,block4), where block1 is the initialization 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).

Signatures:
sts


[Next: while] [Previous: return] [Top]

while

Role:
application
Description:

This symbol represents 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.

Signatures:
sts


[Next: if] [Previous: for] [Top]

if

Role:
application
Description:

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.

Signatures:
sts


[Next: call_arguments] [Previous: while] [Top]

call_arguments

Role:
application
Description:

This symbol can be used to encode the arguments that will be passed to a function or procedure.

Signatures:
sts


[Next: def_arguments] [Previous: if] [Top]

def_arguments

Role:
application
Description:

This symbol can be used to encode the arguments that a function or procedure can receive.

Signatures:
sts


[Next: function_block] [Previous: call_arguments] [Top]

function_block

Role:
application
Description:

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).

Signatures:
sts


[Next: function_definition] [Previous: def_arguments] [Top]

function_definition

Role:
application
Description:

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.

Example:
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
function_definition ( MyFunct , def_arguments ( N ) , function_block ( local_var ( i , Result ) , block ( assignment ( Result , 1 ) , for ( block ( assignment ( i , 2 ) ) , block ( i N ) , block ( assignment ( i , i + 1 ) ) , block ( assignment ( Result , i 10 + 1 ) ) ) , return ( Result ) ) ) )
Example:
The encoding of a function N --> 1+2^3+...+N^3 (uses the while loop) is
function_definition ( Prog1AddCubes , def_arguments ( n ) , function_block ( local_var ( Total , i ) , block ( assignment ( i , 1 ) , assignment ( Total , 0 ) , while ( block ( i n ) , block ( assignment ( Total , Total + i 3 ) , assignment ( i , i + 1 ) ) ) , return ( Total ) ) ) )
Example:
The encoding of a function the compute the Nth term of the Fibonacci sequence is
function_definition ( Prog1Fibonacci , def_arguments ( n ) , function_block ( local_var ( ) , block ( if ( block ( ( n = 1 ) ( n = 2 ) ) , block ( return ( 1 ) ) , block ( return ( function_call ( Prog1Fibonacci , call_arguments ( n - 1 ) ) + function_call ( Prog1Fibonacci , call_arguments ( n - 2 ) ) ) ) ) ) ) )
Signatures:
sts


[Next: function_call] [Previous: function_block] [Top]

function_call

Role:
application
Description:

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.

Example:
The function call "MyFunction(100)" is encoded as
function_call ( MyFunct , call_arguments ( 100 ) )
Signatures:
sts


[Next: procedure_definition] [Previous: function_definition] [Top]

procedure_definition

Role:
application
Description:

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).

Signatures:
sts


[Next: procedure_call] [Previous: function_call] [Top]

procedure_call

Role:
application
Description:

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.

Signatures:
sts


[Next: procedure_block] [Previous: procedure_definition] [Top]

procedure_block

Role:
application
Description:

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).

Signatures:
sts


[First: assignment] [Previous: procedure_call] [Top]