previous contents index next
(..Operators) Contents Index (..Functions..)

2.8 Functions

 

2.8.1 Integer Functions (IntFunctionCall)

IntFunctionCall - Syntax:

Syntax: IntFunctionCall

 
abs( IntExpression )
calculates the absolute value of IntExpression.

 
sgn( IntExpression )
returns in principle the sign of its argument. Since the result should be an integer, it is 1 if IntExpression is positive, -1 if it is negative, and 0 if IntExpression is itself zero.

 
pow( IntExpression1 , IntExpression2 )
calculates the power of IntExpression1 with exponent IntExpression2. In order not to exceed ZZ, negative values for the exponent are not permitted. Remember furthermore that the result in absolute value must be less than 231-1.

Example 15:

pow(10,5)  leadsto  100 000
pow(34,0)  leadsto  1
pow(-2,3)  leadsto  -8

 
rand( i1 , i2 )
where i1 and i2 are elements of IntExpression, determines a random number of ZZ within the interval [ i1, i2 ] if i_1 <= i_2, and within [ i2, i1 ] if i2 < i1.

Example 16:


rand(1,49)         /* random number between 1 and 49 */

rand(49,1)                      /* -''- */

rand(9,9)          /* returns always 9 */ 


 
Example 17:

The random function allows the construction of probabilistic CA using the following method:

First, for each site a random number between 1 and n in IN is determined and stored in a variable number. Then for only one single event < Neighbour configuration> a special rule table can - just depending on number - provoke different actions <Consequence 1>, <Consequence 2>, and so on, with probabilities n_1/n, (n_2-n_1)/n$, ... , (n-n_m)/n, 0 < n_1 < ... < n_m < =n.

If the generic cell is itself a member of the neighbourhood as well, then nm < n is legal; in this case it will keep its old state with probability (n-n_m)/n. Like this, it is automatically guaranteed that the sum of all probabilities is 1.


 ...

TABLE

    number = rand(1,n);

    number>0; number<=n1;
    
             <Neighbour configuration> : <Consequence 1> : 

 
    number>n1; number<=n2;
 
             <Neighbour configuration> : <Consequence 2> : 

                          ...
For further information concerning the structure of SDL programs please refer to 'Table Part' of SDL.

 
stoi( StringExpression )
converts StringExpression as far as possible into an integer, starting at position 0 and obeying the rules below:

Example 18:

stoi(" -431332");     leadsto  -431332

stoi("120.982.566");  leadsto  120

stoi("state 42");     leadsto  0 

 
len( StringExpression )
determines how many characters StringExpression consists of.

Example 19:

Suppose thirteen to be a variable of type STRING with contents "13".
len("ten letters")  leadsto  11

len(thirteen)       leadsto  2  


 
instr( StringExpression1 , StringExpression2 )
passes through StringExpression1 from the left to the right in order to find out if StringExpression2 is a substring. Whether this is true, instr() returns the position of the first corresponding character, otherwise -1. (We start counting with 0.) If StringExpression2 is found more than once in StringExpression1, the first agreement will be taken.

 
coord( IntExpression )
may only be used in RDL within the structure CellAssignment in places where integer expressions are allowed. Suppose that d is the space dimension, then IntExpression must satisfy 1 <= IntExpression < d.
If CellDomain only consists of one site Cell, coord(i) returns the i-th component of the coordinate of Cell.
If CellDomain denotes a set of cells Loop, coord(i) will internally be applied to all single cells of the set. (This means, each cell will be assigned the i-th component of its own coordinate.)

 
Example 20:

In ZZ^2 we are going to look at sites with two integer registers x1 and x2. We choose a retina such that all cells of the square with diametral corners (0,0) and (10,10) are elements of it. By the following devices placed within the statement part of the belonging RDL program, we achieve that the registers x1 and x2 of those cells are initialized with their coordinates:

[0,0]..[10,10].x1 = coord(1);
[0,0]..[10,10].x2 = coord(2);


previous contents index next
(..Operators) Contents Index (..Functions..)