examples of primitive recursive encoding

examples of primitive recursive encoding

In this entry, we present three

examples of primitive recursive encodings

. In all the examples, the following notations are used:

ℕ

is the set of all

natural numbers

(including

0

),

ℕ

*

is the set of all

finite sequences

over

ℕ

, and

E

:

ℕ

*

→

ℕ

is the

encoding

in question. For any

sequence

a

1

,

…

,

a

k

, its image under

E

is denoted by

⟨

a

1

,

…

,

a

k

⟩

, and is called the

sequence number

corresponding to

a

1

,

…

,

a

k

. Furthermore,

(

)

denotes the empty sequence, and its sequence number is denoted by

⟨

⟩

. The fact that the

E

in each of the examples below is in fact encoding is proved in this entry (

http://planetmath.org/EncodingWords

).

Example 1

. (

Multiplicative encoding

)

E

is defined as follows:

⟨

⟩

:=

1

,

⟨

a

1

,

…

,

a

k

⟩

:=

p

1

s

⁢

(

a

1

)

⁢

⋯

⁢

p

k

s

⁢

(

a

k

)

,

where

s

is the successor function, and

p

1

,

…

,

p

k

are the first

k

prime numbers

.

To see that

E

is

primitive recursive

, we verify the following:

•

the

predicate

“

x

is a sequence number” is primitive recursive: a number

x

∈

ℕ

is a sequence number iff

x

=

1

or, if

p

|

x

for some prime

p

, then

q

|

x

for any prime

q

≤

p

. The predicates

Φ

1

:=

`

`

p

|

x

for some prime

p

”

≡

`

`

∃

p

≤

x

(

P

(

p

)

∧

(

p

|

x

)

)

”

,

Φ

2

:=

`

`

p

is prime and

q

|

x

for all primes

q

≤

p

”

≡

`

`

∀

q

≤

p

(

P

(

p

)

∧

P

(

q

)

∧

(

q

|

x

)

)

”

where

P

⁢

(

r

)

:=

“

r

is prime”, are primitive recursive by bounded quantification. Thus “

x

is a sequence number” iff “

x

=

1

or

Φ

1

→

Φ

2

” iff “

(

x

=

1

)

∨

(

¬

Φ

1

∨

Φ

2

)

”, is primitive recursive as a result.

•

E

k

⁢

(

a

1

,

…

,

a

k

)

:=

p

1

s

⁢

(

a

1

)

⁢

⋯

⁢

p

k

s

⁢

(

a

k

)

is clearly primitive recursive.

•

lh

⁡

(

x

)

can be defined as the number of primes dividing

x

, which is primitive recursive.

•

(

x

)

y

can be defined as the

exponent

of the

y

-th prime in

x

(the largest power of

p

y

dividing

x

), which is again primitive recursive.

Example 2

. (Encoding via a

pairing function

) First, let

J

:

ℕ

2

→

ℕ

be a (primitive recursive) pairing function. For any

n

≥

2

, define

J

2

⁢

(

x

1

,

x

2

)

:=

J

⁢

(

x

1

,

x

2

)

J

n

+

1

⁢

(

x

1

,

…

,

x

n

,

x

n

+

1

)

:=

J

⁢

(

x

1

,

J

n

⁢

(

x

2

,

…

,

x

n

+

1

)

)

.

Then define

E

by

⟨

⟩

:=

0

,

⟨

a

1

,

…

,

a

k

⟩

:=

J

⁢

(

k

,

J

k

⁢

(

a

1

,

…

,

a

k

)

)

.

E

is primitive recursive because

•

E

is a

bijection

, so the predicate “

x

is a sequence number” is the same as “

x

∈

ℕ

”, which is clearly primitive recursive,

•

E

k

⁢

(

a

1

,

…

,

a

k

)

:=

J

⁢

(

k

,

J

k

⁢

(

a

1

,

…

,

a

k

)

)

is primitive recursive since both

J

and

J

k

are, the latter of which can be shown to be primitive recursive by

induction

,

•

The two

functions

R

,

L

:

ℕ

→

ℕ

such that

J

⁢

(

L

⁢

(

m

)

,

R

⁢

(

m

)

)

=

m

are primitive recursive. So

lh

⁡

(

x

)

=

L

⁢

(

x

)

in particular is primitive recursive.

•

If

J

k

⁢

(

a

1

,

…

,

a

k

)

=

b

, then

a

1

=

L

⁢

(

b

)

,

a

2

=

L

⁢

R

⁢

L

⁢

(

b

)

,

…

,

a

k

-

1

=

(

L

⁢

R

)

k

-

2

⁢

L

⁢

(

b

)

, and

a

k

=

R

⁢

(

L

⁢

R

)

k

-

2

⁢

L

⁢

(

b

)

. Thus,

(

x

)

y

=

{

(

L

⁢

R

)

y

⁢

(

x

)

if

⁢

y

<

L

⁢

(

x

)

,

R

⁢

(

L

⁢

R

)

y

⁢

(

x

)

if

⁢

y

=

L

⁢

(

x

)

,

0

otherwise

.

is primitive recursive, since each case is primitive recursive.

Example 3

. (Digital

Representation

) Pick a

positive integers

p

>

1

. Define

E

by

⟨

⟩

:=

1

⟨

a

⟩

:=

p

s

⁢

(

a

)

⟨

a

1

,

…

,

a

k

,

a

k

+

1

⟩

:=

⟨

a

1

⟩

⁢

(

⟨

a

2

,

…

,

a

k

+

1

⟩

+

1

)

.

In other words,

⟨

a

1

,

…

,

a

k

⟩

=

p

s

⁢

(

a

1

)

+

p

s

⁢

(

a

1

)

+

s

⁢

(

a

2

)

+

⋯

⁢

p

s

⁢

(

a

1

)

+

⋯

+

s

⁢

(

a

k

)

.

(1)

To see that

E

is primitive recursive, we first define three functions

f

:

ℕ

→

ℕ

given by

f

⁢

(

x

)

:=

lo

⁡

(

p

,

x

)

, the exponent of

p

in

x

,

g

:

ℕ

→

ℕ

given by

g

⁢

(

x

)

:=

quo

⁡

(

x

,

p

f

⁢

(

x

)

)

⁢

-

˙

⁢

1

, and

h

:

ℕ

2

→

ℕ

given by

h

⁢

(

x

,

0

)

:=

x

h

⁢

(

x

,

n

+

1

)

:=

g

⁢

(

h

⁢

(

x

,

n

)

)

.

Clearly,

f

,

g

,

h

are all primitive recursive. Furthermore,

h

has the property that if

h

⁢

(

x

,

n

)

>

0

, then

h

⁢

(

x

,

n

+

1

)

<

h

⁢

(

x

,

n

)

, and therefore

h

⁢

(

x

,

n

)

=

0

for large enough

n

. Using

h

, we may proceed to show that

E

is primitive recursive:

•

the predicate “

x

is a sequence number” is

equivalent

to the predicate

“

(

x

=

1

)

∨

(

(

x

>

0

)

∧

(

∀

n

p

|

h

(

x

,

n

)

)

)

”

which is equivalent to the predicate

“

(

x

=

1

)

∨

(

(

x

>

0

)

∧

(

∀

n

≤

x

p

|

h

(

x

,

n

)

)

)

”

since

p

>

1

. As the quantification is

bounded

, the predicate is primitive recursive.

•

E

k

⁢

(

a

1

,

…

,

a

k

)

=

⟨

a

1

,

…

,

a

k

⟩

is primitive recursive by

equation

(1) above.

•

lh

⁡

(

x

)

can be defined as the number of

n

such that

h

⁢

(

x

,

n

)

≠

0

, or

∑

i

=

0

x

sgn

⁡

(

h

⁢

(

x

,

i

)

)

,

which is primitive recursive, because it is a

bounded sum

.

•

If

⟨

a

1

,

…

,

a

k

⟩

=

x

, then

f

⁢

(

h

⁢

(

x

,

0

)

)

=

s

⁢

(

a

1

)

,

…

,

f

⁢

(

h

⁢

(

x

,

k

-

1

)

)

=

s

⁢

(

a

k

)

. Therefore,

(

x

)

y

is just

f

⁢

(

h

⁢

(

x

,

y

⁢

-

˙

⁢

1

)

)

⁢

-

˙

⁢

1

, which is primitive recursive.

Remark

. In the third example,

E

can be more generally defined so that

⟨

a

1

,

…

,

a

k

,

a

k

+

1

⟩

:=

⟨

a

1

⟩

⁢

(

r

⁢

⟨

a

2

,

…

,

a

k

+

1

⟩

+

q

)

,

provided that

p

,

q

are

coprime

. It is fairly straightforward to show that

E

is again primitive recursive.

Title

examples of primitive recursive encoding

Canonical name

ExamplesOfPrimitiveRecursiveEncoding

Date of creation

2013-03-22 19:06:23

Last modified on

2013-03-22 19:06:23

Owner

CWoo (3771)

Last modified by

CWoo (3771)

Numerical id

8

Author

CWoo (3771)

Entry type

Example

Classification

msc 94A60

Classification

msc 68Q45

Classification

msc 68Q05

Classification

msc 03D20

Generated on Sat Feb 10 13:42:48 2018 by

LaTeXML