Previous Up Next

2.15.3  Top and leaves of an expression : sommet feuille op

An operator is an infixed function : for exemple ’+’ is an operator and ’sin’ is a function.
An expression can be represented by a tree. The top of the tree is either an operator, or a function and the leaves of the tree are the arguments of the operator or of the function (see also 2.37.11).
The instruction sommet (resp feuille (or op)) returns the top (resp. the list of the leaves) of an expression.
Input :

sommet(sin(x+2))

Output :

’sin’

Input :

sommet(x+2*y)

Output :

’+’

Input :

feuille(sin(x+2))

Or :

op(sin(x+2))

Output :

x+2

Input :

feuille(x+2*y)

Or :

op(x+2*y)

Output :

(x,2*y)

Remark
Suppose that a function is defined by a program, for example let us define the pgcd function :

pgcd(a,b):={local r; while (b!=0) {r:=irem(a,b);a:=b;b:=r;} return a;}

Then input :

sommet(pgcd)

Output :

’program’

Then input :

feuille(pgcd)[0]

Output :

(a,b)

Then input :

feuille(pgcd)[1]

Output :

(0,0) or (15,25) if the last input was pgcd(15,25)

Then input :

feuille(pgcd)[2]

Output :

The body of the program : {local r;....return(a);}

Previous Up Next