English Page
Elementary Techniques | Techniques of Function | Techniques of Recursion | Techniques of Number

Replace in a recursive function

Sample Code 1

a(X):XXXXrXXXXla(srslX)
a(r)
(20B)

The code above can be compressed by replacing XXXX by another variable.

a(X,Y):YrYla(srslX,XXXX)
a(r,)
(19B)

Special first term

Sample Code 1

a(X,Y):YrYla(srslX,XXXX)
a(r,sss)

Even if you replace something by Y, the rule of Y isn't applied for "1st Y".
Thus, you can use "1st Y" freely.

Sample Code 2

a(X,Y):XYXa(XX,l)
a(srsl,r)

Sample Code 3

a(X,Y):XXXXYa(sX,YYl)
a(r,)

In this code, "1st Y" and "2nd Y" is special.

Controll the spped of growth

Sample Code 1

a(X,Y):XXXXra(sY,X) a(r,r)

X grows with a spped of 1/2.

Sample Code 2

a(X,Y,Z):Xra(ssY,sZ,X) a(,,)

This code gives a sequence [0,2,3][3,5,6][6,8,9][9,11,12]...

Sample Code 3

a(X,Y,Z):Xra(sYX,Z,Y)
a(,,s)

This code gives a sequence [0,1][3,4][6,7]...
"s" and "" appar at Y alternatively.

Change of variables

Sample Code

a(X):XrXrXrXra(XrXlX)
a(s)

Put Y = Xr, then this code can be transformed to the following code：

b(Y):YYYYb(newY = [newX]r = XrXlXr = YYllY)
b(sr)
b(Y):YYYYb(YYllY)
b(sr)

Multiple recursion

Sample Code 1

f(X):ssXlssf(sX)
f()
[12B]

This code can be compressed by recycling "ss"：

f(X):ssXlf(f(sX))
f()
[11B]

Sample Code 2

f(X):srslXf(f(ss))
f()

Recursion with many functions

f(X):
a(X):a(f(X))
a(f())

This code can be compressed by using two recursive functions.

f(X):a()
a(X):f(X)
f()

Last-modified: 2013-02-13 (水) 23:34:22 (2441d)