examples of primitive recursive functions

examples of primitive recursive functions

Starting from the simplest

primitive recursive functions

, we can build more complicated primitive recursive functions by

functional

composition

and

primitive recursion

. In this entry, we have listed some basic examples using functional composition alone. In this entry, we list more basic examples, allowing the use of primitive recursion:

1.

add

⁡

(

x

,

y

)

=

x

+

y

:

add

⁡

(

x

,

0

)

=

id

⁡

(

x

)

, and

add

⁡

(

x

,

n

+

1

)

=

s

⁢

(

add

⁡

(

x

,

n

)

)

2.

mult

⁡

(

x

,

y

)

=

x

⁢

y

:

mult

⁡

(

x

,

0

)

=

z

⁢

(

x

)

, and

mult

⁡

(

x

,

n

+

1

)

=

add

⁡

(

x

,

mult

⁡

(

x

,

n

)

)

.

3.

p

2

⁢

(

x

)

=

x

2

, which is just

mult

⁡

(

x

,

x

)

; more generally,

p

m

+

1

⁢

(

x

)

=

mult

⁡

(

x

,

p

m

⁢

(

x

)

)

, which is primitive recursive by

induction

on

m

4.

exp

m

⁡

(

x

)

=

m

x

:

exp

m

⁡

(

0

)

=

s

⁢

(

0

)

, and

exp

m

⁡

(

n

+

1

)

=

mult

⁡

(

const

m

⁡

(

n

)

,

exp

m

⁡

(

n

)

)

5.

exp

⁡

(

x

,

y

)

=

x

y

:

exp

⁡

(

x

,

0

)

=

const

1

⁡

(

x

)

, and

exp

⁡

(

x

,

n

+

1

)

=

mult

⁡

(

x

,

exp

⁡

(

x

,

n

)

)

6.

fact

⁡

(

x

)

=

x

!

:

fact

⁡

(

0

)

=

s

⁢

(

0

)

, and

fact

⁡

(

n

+

1

)

=

mult

⁡

(

s

⁢

(

n

)

,

fact

⁡

(

n

)

)

7.

sub

1

⁡

(

x

)

=

x

⁢

-

˙

⁢

1

:=

{

0

if

⁢

x

=

0

,

x

-

1

otherwise,

built using

z

and

s

:

sub

1

⁡

(

0

)

=

z

⁢

(

0

)

, and

sub

1

⁡

(

n

+

1

)

=

s

⁢

(

sub

1

⁡

(

n

)

)

;

8.

more generally,

sub

m

⁡

(

x

)

=

x

⁢

-

˙

⁢

m

may be defined:

sub

m

=

sub

1

m

.

9.

sub

⁡

(

x

,

y

)

=

x

⁢

-

˙

⁢

y

:

sub

⁡

(

x

,

0

)

=

id

⁡

(

x

)

, and

sub

⁡

(

x

,

n

+

1

)

=

sub

1

⁡

(

sub

⁡

(

x

,

n

)

)

.

10.

diff

⁡

(

x

,

y

)

=

|

x

-

y

|

:=

sub

⁡

(

x

,

y

)

+

sub

⁡

(

y

,

x

)

11.

d

0

⁢

(

x

)

:=

{

1

if

⁢

x

=

0

,

0

otherwise.

built using

const

1

and

z

:

d

0

⁢

(

0

)

=

const

1

⁡

(

0

)

, and

d

0

⁢

(

n

+

1

)

=

z

⁢

(

d

0

⁢

(

n

)

)

.

12.

more generally,

d

m

⁢

(

x

)

:=

{

1

if

⁢

x

=

m

,

0

otherwise.

is primitive recursive, for it is

d

0

(

diff

(

x

,

const

m

(

x

)

)

.

13.

even more generally,

d

S

⁢

(

x

)

:=

{

1

if

⁢

x

∈

S

,

0

otherwise.

where

S

=

{

a

1

,

…

,

a

m

}

, is primitive recursive, for it is

d

a

1

+

⋯

+

d

a

m

.

14.

sgn

⁡

(

x

)

:=

{

0

if

⁢

x

=

0

,

1

otherwise.

which is just

sub

⁡

(

const

1

⁡

(

x

)

,

d

0

⁢

(

x

)

)

.

15.

rem

⁡

(

x

,

y

)

:=

{

0

if

⁢

y

=

0

,

x

mod

y

otherwise,

where

x

mod

y

is the

remainder

of

x

÷

y

. Suppose

y

≠

0

. Then

0

mod

y

=

0

. In

addition

,

(

n

+

1

)

mod

y

=

{

0

if

⁢

diff

⁡

(

s

⁢

(

n

mod

y

)

,

y

)

=

0

,

s

⁢

(

n

mod

y

)

otherwise,

Then

rem

⁡

(

0

,

y

)

=

z

⁢

(

y

)

, and

rem

⁡

(

n

+

1

,

y

)

=

sgn

⁡

(

y

)

⁢

(

rem

⁡

(

n

,

y

)

+

1

)

⁢

sgn

⁡

(

|

rem

⁡

(

n

,

y

)

+

1

-

y

|

)

=

mult

⁡

(

sgn

⁡

(

y

)

,

mult

⁡

(

s

⁢

(

rem

⁡

(

n

,

y

)

)

,

sgn

⁡

(

diff

⁡

(

s

⁢

(

rem

⁡

(

n

,

y

)

)

,

y

)

)

)

)

=

g

⁢

(

y

,

rem

⁡

(

n

,

y

)

)

where

g

⁢

(

y

,

x

)

:=

mult

⁡

(

sgn

⁡

(

y

)

,

mult

⁡

(

s

⁢

(

x

)

,

sgn

⁡

(

diff

⁡

(

s

⁢

(

x

)

,

y

)

)

)

)

. The reason for including

sgn

⁡

(

y

)

is to account for the case when

y

=

0

.

16.

q

⁢

(

x

,

y

)

=

{

quotient of

⁢

x

÷

y

if

⁢

y

≠

0

0

otherwise.

To see that

q

is primitive recursive, we use

equation

x

=

y

⁢

q

⁢

(

x

,

y

)

+

rem

⁡

(

x

,

y

)

obtained from the

division algorithm for integers

. Then

y

⁢

q

⁢

(

x

,

y

)

+

rem

⁡

(

x

,

y

)

+

1

=

x

+

1

=

y

⁢

q

⁢

(

x

+

1

,

y

)

+

rem

⁡

(

x

+

1

,

y

)

.

Simplify and we get

y

⁢

(

q

⁢

(

x

+

1

,

y

)

-

q

⁢

(

x

,

y

)

)

=

rem

⁡

(

x

,

y

)

+

1

-

rem

⁡

(

x

+

1

,

y

)

.

Thus, by the previous example, we get

q

⁢

(

n

+

1

,

y

)

=

{

q

⁢

(

n

,

y

)

+

1

if

⁢

rem

⁡

(

n

,

y

)

+

1

=

y

,

q

⁢

(

n

,

y

)

otherwise.

Therefore,

q

⁢

(

0

,

y

)

=

z

⁢

(

y

)

, and

q

⁢

(

n

+

1

,

y

)

=

sgn

⁡

(

y

)

⁢

(

q

⁢

(

n

,

y

)

+

sgn

⁡

(

diff

⁡

(

s

⁢

(

rem

⁡

(

n

,

y

)

)

,

y

)

)

)

where

sgn

⁡

(

y

)

takes the case

y

=

0

into account.

Remarks

.

•

All of the functions above are in fact examples of

elementary recursive functions

.

•

Example 3(m) above is a special case of a more general phenomenon. Recall that a subset

S

⊆

ℕ

n

is called

primitive recursive

if its

characteristic function

φ

S

is primitive recursive. If we take

S

=

{

m

}

, then

φ

S

=

d

m

. Furthermore, a

predicate

Φ

⁢

(

𝒙

)

over

ℕ

k

is

primitive recursive

if the corresponding set

S

⁢

(

Φ

)

:=

{

𝒙

∈

ℕ

k

∣

Φ

⁢

(

𝒙

)

}

is primitive recursive.

•

The technique of

bounded maximization

may be used to prove the

primitive

recursiveness of the

quotient

and the reminder functions in examples 3(o) and 3(p). See this entry (

http://planetmath.org/BoundedMaximization

) for more detail.

Title

examples of primitive recursive functions

Canonical

name

ExamplesOfPrimitiveRecursiveFunctions

Date of creation

2013-03-22 19:05:06

Last modified on

2013-03-22 19:05:06

Owner

CWoo (3771)

Last modified by

CWoo (3771)

Numerical id

17

Author

CWoo (3771)

Entry type

Example

Classification

msc 03D20

Related topic

ExamplesOfPrimitiveRecursivePredicates

Generated on Thu Feb 8 20:03:19 2018 by

LaTeXML