mutual recursion

mutual recursion

Mutual recursion

is a way of defining

functions

via

recursion

involving several functions simultaneously. In mutual recursion, the value of the next

argument

of

any

function involved depends on values of the current arguments of

all

functions involved. The following are two simple examples:

•

the pair of functions

f

,

g

such that

f

⁢

(

0

)

=

0

and

g

⁢

(

0

)

=

1

, with

f

⁢

(

n

+

1

)

=

f

⁢

(

n

)

⁢

g

⁢

(

n

)

and

g

⁢

(

n

+

1

)

=

f

⁢

(

n

)

+

g

⁢

(

n

)

is defined via mutual recursion. It is easy to see that

f

⁢

(

n

)

=

0

and

g

⁢

(

n

)

=

1

.

•

Fibonacci numbers

can be interpreted via mutual recursion:

F

⁢

(

0

)

=

1

and

G

⁢

(

0

)

=

1

, with

F

⁢

(

n

+

1

)

=

F

⁢

(

n

)

+

G

⁢

(

n

)

and

G

⁢

(

n

+

1

)

=

F

⁢

(

n

)

.

Formally,

Definition

. Functions

f

1

,

…

,

f

m

:

ℕ

k

+

1

→

ℕ

are said to be defined by

mutual recursion

via functions

g

1

,

…

⁢

g

m

:

ℕ

k

→

ℕ

and functions

h

1

,

…

,

h

m

:

ℕ

k

+

m

+

1

→

ℕ

, if

f

i

⁢

(

𝒙

,

0

)

=

g

i

⁢

(

𝒙

)

,

f

i

⁢

(

𝒙

,

n

+

1

)

=

h

i

⁢

(

𝒙

,

n

,

f

1

⁢

(

𝒙

,

n

)

,

…

,

f

m

⁢

(

𝒙

,

n

)

)

,

for any

𝒙

∈

ℕ

k

, and

i

=

1

,

…

,

m

.

Mutual recursion is an apparent

generalization

of

primitive recursion

, where the value of the next argument of a function depends on the value of the current argument of the same function, apparent because it is in fact

equivalent

to primitive recursion.

Proposition 1

.

As above, if all of

g

i

and

h

i

are

primitive recursive

, so are all of

f

i

.

Proof.

We use the

multiplicative encoding

technique. Define function

F

:

ℕ

k

+

1

→

ℕ

as follows:

F

⁢

(

𝒙

,

n

)

=

exp

⁡

(

p

1

,

f

1

⁢

(

𝒙

,

n

)

)

⁢

⋯

⁢

exp

⁡

(

p

m

,

f

m

⁢

(

𝒙

,

n

)

)

,

where

p

i

is the

i

-th

prime number

(

p

1

=

2

, etc…). Furthermore,

(

F

⁢

(

𝒙

,

n

)

)

i

=

f

i

⁢

(

𝒙

,

n

)

,

where

(

z

)

i

denotes the exponent of prime

p

i

in

z

. Then

F

⁢

(

𝒙

,

0

)

=

∏

i

=

1

m

exp

⁡

(

p

i

,

g

i

⁢

(

𝒙

)

)

=

G

⁢

(

𝒙

)

,

and

F

⁢

(

𝒙

,

n

+

1

)

=

∏

i

=

1

m

exp

⁡

(

p

1

,

f

1

⁢

(

𝒙

,

n

+

1

)

)

=

∏

i

=

1

m

exp

⁡

(

p

i

,

h

i

⁢

(

𝒙

,

n

,

f

1

⁢

(

𝒙

,

n

)

,

…

,

f

m

⁢

(

𝒙

,

n

)

)

)

=

∏

i

=

1

m

exp

(

p

i

,

h

i

(

𝒙

,

n

,

(

F

(

𝒙

,

n

)

)

1

,

…

,

(

F

(

𝒙

,

n

)

)

m

)

=

H

⁢

(

𝒙

,

n

,

F

⁢

(

𝒙

,

n

)

)

where

G

⁢

(

𝒙

)

=

∏

i

=

1

m

exp

⁡

(

p

i

,

g

i

⁢

(

𝒙

)

)

,

and

H

(

𝒙

,

y

,

z

)

=

∏

i

=

1

m

exp

(

p

i

,

h

i

(

𝒙

,

y

,

(

z

)

1

,

…

,

(

z

)

m

)

Since each of the

g

i

is primitive recursive,

G

is primitive recursive. Since each of the

h

i

is primitive recursive,

H

is primitive recursive. So

F

is primitive recursive, as it is defined via primitive recursion by

G

and

H

. Therefore, each

f

i

=

(

F

)

i

is primitive recursive.
∎

Remark

. The primitive recursiveness of mutual recursion can be derived from

course-of-values recursion

. The idea is the following: list the

f

i

’s in order, and construct a single function

F

so the its values correspond to the values of the

f

i

’s in the order given. For example, if two unary functions

f

1

and

f

2

defined by mutual recursion, then

f

1

⁢

(

0

)

f

2

⁢

(

0

)

f

1

⁢

(

1

)

f

2

⁢

(

1

)

f

1

⁢

(

2

)

⋯

f

1

⁢

(

k

)

f

2

⁢

(

k

)

f

1

⁢

(

k

+

1

)

f

2

⁢

(

k

+

1

)

⋯

F

⁢

(

0

)

F

⁢

(

1

)

F

⁢

(

2

)

F

⁢

(

3

)

F

⁢

(

4

)

⋯

F

⁢

(

2

⁢

k

)

F

⁢

(

2

⁢

k

+

1

)

F

⁢

(

2

⁢

k

+

2

)

F

⁢

(

2

⁢

k

+

3

)

⋯

T

⁢

h

⁢

e

⁢

n

⁢

i

⁢

t

⁢

i

⁢

s

⁢

n

⁢

o

⁢

t

⁢

h

⁢

a

⁢

r

⁢

d

⁢

t

⁢

o

⁢

s

⁢

e

⁢

e

⁢

t

⁢

h

⁢

a

⁢

t

F(k+1)

d

⁢

e

⁢

p

⁢

e

⁢

n

⁢

d

⁢

s

⁢

o

⁢

n

F(k),F(k-1)

,

a

n

d

F(k-2)

,

a

n

d

a

n

e

x

p

l

i

c

i

t

f

o

r

m

u

l

a

c

a

n

b

e

d

e

r

i

v

e

d

e

x

p

r

e

s

s

i

n

g

t

h

e

d

e

p

e

n

d

e

n

c

y

.

F

u

r

t

h

e

r

m

o

r

e

,

t

h

i

s

f

o

r

m

u

l

a

i

s

e

a

s

i

l

y

s

e

e

n

t

o

b

e

p

r

i

m

i

t

i

v

e

r

e

c

u

r

s

i

v

e

,

a

n

d

h

e

n

c

e

s

o

i

s

F(k)

.

Title

mutual recursion

Canonical name

MutualRecursion

Date of creation

2013-03-22 19:06:31

Last modified on

2013-03-22 19:06:31

Owner

CWoo (3771)

Last modified by

CWoo (3771)

Numerical id

9

Author

CWoo (3771)

Entry type

Definition

Classification

msc 03D20

Synonym

simultaneous recursion

Generated on Thu Feb 8 20:04:10 2018 by

LaTeXML