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.
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="a"/>
<OMI> 125 </OMI>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">assignment</csymbol><ci>a</ci><cn type="integer">125</cn></apply>
</math>
Prefix
Popcorn
prog1.assignment($a, 125)
Rendered Presentation MathML
Signatures:
sts
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="a"/>
<OMI> 153 </OMI>
</OMA>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="a"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMV name="a"/>
</OMA>
</OMA>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol><ci>a</ci><cn type="integer">153</cn></apply>
<apply><csymbol cd="prog1">assignment</csymbol>
<ci>a</ci>
<apply><csymbol cd="arith1">plus</csymbol><ci>a</ci></apply>
</apply>
</apply>
</math>
Prefix
Popcorn
prog1.assignment($a, 153) ; prog1.assignment($a, $a)
Rendered Presentation MathML
block
(
assignment
(
a
,
153
)
,
assignment
(
a
,
a
)
)
Signatures:
sts
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
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
Role:
application
Description:
This symbol, which can have an aribtrary positive number of arguments, can be used to return values from functions.
Signatures:
sts
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
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
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
Role:
application
Description:
This symbol can be used to encode the arguments that will be passed to a function
or procedure.
Signatures:
sts
Role:
application
Description:
This symbol can be used to encode the arguments that a function or procedure
can receive.
Signatures:
sts
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
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="function_definition"/>
<OMV name="MyFunct"/>
<OMA>
<OMS cd="prog1" name="def_arguments"/>
<OMV name="N"/>
</OMA>
<OMA>
<OMS cd="prog1" name="function_block"/>
<OMA>
<OMS cd="prog1" name="local_var"/>
<OMV name="i"/>
<OMV name="Result"/>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="Result"/>
<OMI>1</OMI>
</OMA>
<OMA>
<OMS cd="prog1" name="for"/>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="i"/>
<OMI>2</OMI>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="relation1" name="leq"/>
<OMV name="i"/>
<OMV name="N"/>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="i"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMV name="i"/>
<OMI>1</OMI>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="Result"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMA>
<OMS cd="arith1" name="power"/>
<OMV name="i"/>
<OMI> 10 </OMI>
</OMA>
<OMI>1</OMI>
</OMA>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="return"/>
<OMV name="Result"/>
</OMA>
</OMA>
</OMA>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">function_definition</csymbol>
<ci>MyFunct</ci>
<apply><csymbol cd="prog1">def_arguments</csymbol><ci>N</ci></apply>
<apply><csymbol cd="prog1">function_block</csymbol>
<apply><csymbol cd="prog1">local_var</csymbol><ci>i</ci><ci>Result</ci></apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol><ci>Result</ci><cn type="integer">1</cn></apply>
<apply><csymbol cd="prog1">for</csymbol>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol><ci>i</ci><cn type="integer">2</cn></apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="relation1">leq</csymbol><ci>i</ci><ci>N</ci></apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol>
<ci>i</ci>
<apply><csymbol cd="arith1">plus</csymbol><ci>i</ci><cn type="integer">1</cn></apply>
</apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol>
<ci>Result</ci>
<apply><csymbol cd="arith1">plus</csymbol>
<apply><csymbol cd="arith1">power</csymbol><ci>i</ci><cn type="integer">10</cn></apply>
<cn type="integer">1</cn>
</apply>
</apply>
</apply>
</apply>
<apply><csymbol cd="prog1">return</csymbol><ci>Result</ci></apply>
</apply>
</apply>
</apply>
</math>
Prefix
function_definition
(
MyFunct ,
def_arguments
(
N )
,
function_block
(
local_var
(
i ,
Result )
,
block
(
assignment
(
Result , 1)
,
for
(
block
(
assignment
(
i , 2)
)
,
block
(
leq
(
i ,
N )
)
,
block
(
assignment
(
i ,
plus
(
i , 1)
)
)
,
block
(
assignment
(
Result ,
plus
(
power
(
i , 10 )
, 1)
)
)
)
,
return
(
Result )
)
)
)
Popcorn
prog1.function_definition($MyFunct, prog1.def_arguments($N), prog1.function_block(prog1.local_var($i, $Result), prog1.assignment($Result, 1) ; prog1.for(prog1.assignment($i, 2), $i <= $N, prog1.assignment($i, $i + 1), prog1.assignment($Result, $i ^ 10 + 1)) ; prog1.return($Result)))
Rendered Presentation MathML
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="function_definition"/>
<OMV name="Prog1AddCubes"/>
<OMA>
<OMS cd="prog1" name="def_arguments"/>
<OMV name="n"/>
</OMA>
<OMA>
<OMS cd="prog1" name="function_block"/>
<OMA>
<OMS cd="prog1" name="local_var"/>
<OMV name="Total"/>
<OMV name="i"/>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="i"/>
<OMI>1</OMI>
</OMA>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="Total"/>
<OMI>0</OMI>
</OMA>
<OMA>
<OMS cd="prog1" name="while"/>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="relation1" name="leq"/>
<OMV name="i"/>
<OMV name="n"/>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="Total"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMV name="Total"/>
<OMA>
<OMS cd="arith1" name="power"/>
<OMV name="i"/>
<OMI>3</OMI>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="assignment"/>
<OMV name="i"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMV name="i"/>
<OMI>1</OMI>
</OMA>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="return"/>
<OMV name="Total"/>
</OMA>
</OMA>
</OMA>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">function_definition</csymbol>
<ci>Prog1AddCubes</ci>
<apply><csymbol cd="prog1">def_arguments</csymbol><ci>n</ci></apply>
<apply><csymbol cd="prog1">function_block</csymbol>
<apply><csymbol cd="prog1">local_var</csymbol><ci>Total</ci><ci>i</ci></apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol><ci>i</ci><cn type="integer">1</cn></apply>
<apply><csymbol cd="prog1">assignment</csymbol><ci>Total</ci><cn type="integer">0</cn></apply>
<apply><csymbol cd="prog1">while</csymbol>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="relation1">leq</csymbol><ci>i</ci><ci>n</ci></apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">assignment</csymbol>
<ci>Total</ci>
<apply><csymbol cd="arith1">plus</csymbol>
<ci>Total</ci>
<apply><csymbol cd="arith1">power</csymbol><ci>i</ci><cn type="integer">3</cn></apply>
</apply>
</apply>
<apply><csymbol cd="prog1">assignment</csymbol>
<ci>i</ci>
<apply><csymbol cd="arith1">plus</csymbol><ci>i</ci><cn type="integer">1</cn></apply>
</apply>
</apply>
</apply>
<apply><csymbol cd="prog1">return</csymbol><ci>Total</ci></apply>
</apply>
</apply>
</apply>
</math>
Prefix
function_definition
(
Prog1AddCubes ,
def_arguments
(
n )
,
function_block
(
local_var
(
Total ,
i )
,
block
(
assignment
(
i , 1)
,
assignment
(
Total , 0)
,
while
(
block
(
leq
(
i ,
n )
)
,
block
(
assignment
(
Total ,
plus
(
Total ,
power
(
i , 3)
)
)
,
assignment
(
i ,
plus
(
i , 1)
)
)
)
,
return
(
Total )
)
)
)
Popcorn
prog1.function_definition($Prog1AddCubes, prog1.def_arguments($n), prog1.function_block(prog1.local_var($Total, $i), prog1.assignment($i, 1) ; prog1.assignment($Total, 0) ; while $i <= $n do prog1.assignment($Total, $Total + $i ^ 3) ; prog1.assignment($i, $i + 1) endwhile ; prog1.return($Total)))
Rendered Presentation MathML
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="function_definition"/>
<OMV name="Prog1Fibonacci"/>
<OMA>
<OMS cd="prog1" name="def_arguments"/>
<OMV name="n"/>
</OMA>
<OMA>
<OMS cd="prog1" name="function_block"/>
<OMA>
<OMS cd="prog1" name="local_var"/>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="if"/>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="logic1" name="or"/>
<OMA>
<OMS cd="relation1" name="eq"/>
<OMV name="n"/>
<OMI>1</OMI>
</OMA>
<OMA>
<OMS cd="relation1" name="eq"/>
<OMV name="n"/>
<OMI>2</OMI>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="return"/>
<OMI>1</OMI>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="block"/>
<OMA>
<OMS cd="prog1" name="return"/>
<OMA>
<OMS cd="arith1" name="plus"/>
<OMA>
<OMS cd="prog1" name="function_call"/>
<OMV name="Prog1Fibonacci"/>
<OMA>
<OMS cd="prog1" name="call_arguments"/>
<OMA>
<OMS cd="arith1" name="minus"/>
<OMV name="n"/>
<OMI>1</OMI>
</OMA>
</OMA>
</OMA>
<OMA>
<OMS cd="prog1" name="function_call"/>
<OMV name="Prog1Fibonacci"/>
<OMA>
<OMS cd="prog1" name="call_arguments"/>
<OMA>
<OMS cd="arith1" name="minus"/>
<OMV name="n"/>
<OMI>2</OMI>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">function_definition</csymbol>
<ci>Prog1Fibonacci</ci>
<apply><csymbol cd="prog1">def_arguments</csymbol><ci>n</ci></apply>
<apply><csymbol cd="prog1">function_block</csymbol>
<apply><csymbol cd="prog1">local_var</csymbol></apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">if</csymbol>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="logic1">or</csymbol>
<apply><csymbol cd="relation1">eq</csymbol><ci>n</ci><cn type="integer">1</cn></apply>
<apply><csymbol cd="relation1">eq</csymbol><ci>n</ci><cn type="integer">2</cn></apply>
</apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">return</csymbol><cn type="integer">1</cn></apply>
</apply>
<apply><csymbol cd="prog1">block</csymbol>
<apply><csymbol cd="prog1">return</csymbol>
<apply><csymbol cd="arith1">plus</csymbol>
<apply><csymbol cd="prog1">function_call</csymbol>
<ci>Prog1Fibonacci</ci>
<apply><csymbol cd="prog1">call_arguments</csymbol>
<apply><csymbol cd="arith1">minus</csymbol><ci>n</ci><cn type="integer">1</cn></apply>
</apply>
</apply>
<apply><csymbol cd="prog1">function_call</csymbol>
<ci>Prog1Fibonacci</ci>
<apply><csymbol cd="prog1">call_arguments</csymbol>
<apply><csymbol cd="arith1">minus</csymbol><ci>n</ci><cn type="integer">2</cn></apply>
</apply>
</apply>
</apply>
</apply>
</apply>
</apply>
</apply>
</apply>
</apply>
</math>
Prefix
function_definition
(
Prog1Fibonacci ,
def_arguments
(
n )
,
function_block
(
local_var
()
,
block
(
if
(
block
(
or
(
eq
(
n , 1)
,
eq
(
n , 2)
)
)
,
block
(
return
(1)
)
,
block
(
return
(
plus
(
function_call
(
Prog1Fibonacci ,
call_arguments
(
minus
(
n , 1)
)
)
,
function_call
(
Prog1Fibonacci ,
call_arguments
(
minus
(
n , 2)
)
)
)
)
)
)
)
)
)
Popcorn
prog1.function_definition($Prog1Fibonacci, prog1.def_arguments($n), prog1.function_block(prog1.local_var(), if $n = 1 > $n = 2 then prog1.return(1) else prog1.return(prog1.function_call($Prog1Fibonacci, prog1.call_arguments($n - 1)) + prog1.function_call($Prog1Fibonacci, prog1.call_arguments($n - 2))) endif ))
Rendered Presentation MathML
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
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
OpenMath XML (source)
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
<OMA>
<OMS cd="prog1" name="function_call"/>
<OMV name="MyFunct"/>
<OMA>
<OMS cd="prog1" name="call_arguments"/>
<OMI>100</OMI>
</OMA>
</OMA>
</OMOBJ>
Strict Content MathML
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><csymbol cd="prog1">function_call</csymbol>
<ci>MyFunct</ci>
<apply><csymbol cd="prog1">call_arguments</csymbol><cn type="integer">100</cn></apply>
</apply>
</math>
Prefix
Popcorn
prog1.function_call($MyFunct, prog1.call_arguments(100))
Rendered Presentation MathML
function_call
(
MyFunct
,
call_arguments
(
100
)
)
Signatures:
sts
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
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
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