Section 4.7

Pairing Functions and Gödel Numberings

[18/33%]
Show
LaTeX
Example 4.32

Show that the function π:N2→N\pi : \mathbf{N}^{2} \rightarrow \mathbf{N}, defined by

π(i,j)=(i+j)(i+j+1)2+j, \pi (i, j)=\frac{(i+j)(i+j+1)}{2}+j,

is a pairing function.

?
Example 4.33

Show that the Fibonacci function is primitive recursive.

?
Example 4.34

Show that the function

τ(n1,…,nk−1,nk)=⟨k−1,⟨n1,⟨⋯⟨nk−1,nk⟩⋯ ⟩⟩⟩ \tau \left(n_{1}, \ldots , n_{k-1}, n_{k}\right)=\left\langle k-1,\left\langle n_{1},\left\langle \cdots \left\langle n_{k-1}, n_{k}\right\rangle \cdots \right\rangle \right\rangle \right\rangle

is a Gödel numbering.

?
Example 4.35

Show that the following functions are primitive recursive:

?
(a)

list⁡(m,0)=0\operatorname {list}(m, 0)=0 and list⁡(m,k)=[m,m,…,m⏟k]\operatorname {list}(m, k)=[\underbrace{m, m, \ldots , m}_{k}], if k≥1k \geq 1.

(b)

find⁡([n1,…,nk],m)={min⁡{i∣1≤i≤k,ni=m} if such an i exists ,0 otherwise \operatorname {find}\left(\left[n_{1}, \ldots , n_{k}\right], m\right)= \begin{cases} \min \left\{ i \mid 1 \leq i \leq k, n_{i}=m\right\} & \text{ if such an } i \text{ exists }, \\ 0 & \text{ otherwise } \end{cases}

(c)

replace⁡([n1,…,nk],m,i)={[n1,…,ni−1,m,ni+1,…,nk] if 1≤i≤k,[n1,…,nk] otherwise. \operatorname {replace}\left(\left[n_{1}, \ldots , n_{k}\right], m, i\right) = \begin{cases} \left[n_{1}, \ldots , n_{i-1}, m, n_{i+1}, \ldots , n_{k}\right] & \text{ if } 1 \leq i \leq k, \\ \left[n_{1}, \ldots , n_{k}\right] & \text{ otherwise. } \end{cases}

(d)

conseq⁡([n1,…,nk],[m1,…,mℓ])=[n1,…,nk,m1,…,mℓ]\operatorname {conseq}\left(\left[n_{1}, \ldots , n_{k}\right],\left[m_{1}, \ldots , m_{\ell }\right]\right)=\left[n_{1}, \ldots , n_{k}, m_{1}, \ldots , m_{\ell }\right].

(e)

subseq⁡([n1,…,nk],i,ℓ)\operatorname {subseq}\left(\left[n_{1}, \ldots , n_{k}\right], i, \ell \right)

={[ni,ni+1,…,ni+ℓ−1] if 1≤i≤k,1≤ℓ≤k−i+10 otherwise.  = \begin{cases} {\left[n_{i}, n_{i+1}, \ldots , n_{i+\ell -1}\right]} & \text{ if } 1 \leq i \leq k, 1 \leq \ell \leq k-i+1 \\ 0 & \text{ otherwise. }\end{cases}
Example 4.36

Show that the function f:N→Nf: \mathbf{N} \rightarrow \mathbf{N}, defined by f(0)=1f(0)=1, f(n+1)=f(0)n+1+f(1)n+…+f(n)1f(n+1)=f(0)^{n+1}+f(1)^{n}+\ldots +f(n)^{1}, is primitive recursive.

?
Example 4.38

The function sort : N→N\mathbf{N} \rightarrow \mathbf{N} maps a number [n1,n2,…,nk]\left[n_{1}, n_{2}, \ldots , n_{k}\right] to the number [np1,np2,…,npk]\left[n_{p_{1}}, n_{p_{2}}, \ldots , n_{p_{k}}\right], where (p1,p2,…,pk)\left(p_{1}, p_{2}, \ldots , p_{k}\right) is a permutation of (1,2,…,k)(1,2, \ldots , k) such that np1≤np2≤⋯≤npkn_{p_{1}} \leq n_{p_{2}} \leq \cdots \leq n_{p_{k}}. Show that sort is primitive recursive.

?
Problem 4.7.1

Show that the following functions are pairing functions.

?
(a)

f1(n,m)=2n(2m+1)−1f_{1}(n, m)=2^{n}(2 m+1)-1.

(b)

f2(n,m)=max⁡(n,m)2+m+g(m,n)f_{2}(n, m)=\max (n, m)^{2}+m+g(m, n), where g(m,n)=ng(m, n)=n if m≥nm \geq n, and g(m,n)=0g(m, n)=0 if n>mn>m.

Problem 4.7.2

Let τ1:⋃k=1∞Nk→N\tau_{1}: \bigcup_{k=1}^{\infty } \mathbf{N}^{k} \rightarrow \mathbf{N} be defined by f(n1,…,nk)=2n13n2⋯pknkf\left(n_{1}, \ldots , n_{k}\right)=2^{n_{1}} 3^{n_{2}} \cdots p_{k}^{n_{k}}, where pkp_{k} is the kk th prime.

?
(a)

Show that the τ1\tau_{1} is onto, primitive recursive and monotone. Also show that τ1\tau_{1} is almost one-to-one in the sense that if τ1(n1,…,nk)=τ1(m1,…,mℓ)\tau_{1}\left(n_{1}, \ldots , n_{k}\right)=\tau_{1}\left(m_{1}, \ldots , m_{\ell }\right), and if k≤ℓk \leq \ell, then ni=min_{i}=m_{i} for all i,1≤i≤ki, 1 \leq i \leq k, and mj=0m_{j}=0 for all j,k<j≤ℓj, k<j \leq \ell.

(b)

Verify that if we use τ1\tau_{1} as a Gödel numbering, then the functions size, item and the functions of Example 4.35 all remain primitive recursive. (Here, size⁡(n)\operatorname {size}(n) is the number of items in the sequence nn, excluding the trailing zeros.)

Problem 4.7.3

Let n1,n2,…,nkn_{1}, n_{2}, \ldots , n_{k} are kk nonnegative integers. Prove that if 1≤i1<i2<⋯<iℓ≤k1 \leq i_{1}< i_{2}<\cdots <i_{\ell } \leq k, then [ni1,ni2,…,niℓ]≤[n1,n2,…,nk]\left[n_{i_{1}}, n_{i_{2}}, \ldots , n_{i_{\ell }}\right] \leq \left[n_{1}, n_{2}, \ldots , n_{k}\right].

?
Problem 4.7.4

Assume that f(n,0)=g(n)f(n, 0)=g(n) and f(n,m+1)=h(n,f(n,k(m)))f(n, m+1)=h(n, f(n, k(m))) for some primitive recursive g,hg, h and kk. Also assume that k(m)≤mk(m) \leq m for all m>0m>0. Prove that ff is also primitive recursive. (Note that Solution 1 of Example 4.38 actually used this result.)

?
Problem 4.7.5

Show that the following functions are primitive recursive:

?
(a)

f(n,m)=f(n, m)= the number of occurrences of integer mm in the sequence n=[n1,…,nk]n=\left[n_{1}, \ldots , n_{k}\right].

(b)

g(n)=[dk,dk−1,…,d0]g(n)=\left[d_{k}, d_{k-1}, \ldots , d_{0}\right], where dkdk−1⋯d0d_{k} d_{k-1} \cdots d_{0} is the decimal representation of nn (e.g., g(2801)=[2,8,0,1]g(2801)=[2,8,0,1]).

Problem 4.7.6

We may extend the notion of primitive recursive functions to functions from Zk\mathbf{Z}^{k} to Z\mathbf{Z}, where Z\mathbf{Z} is the set of integers. All we need is to treat a pair ⟨n1,n2⟩\left\langle n_{1}, n_{2}\right\rangle as a represention of an integer in Z\mathbf{Z} : If n1>0n_{1}>0, then it represents n2n_{2}, otherwise it represents −n2-n_{2}. Show that the following functions on integers are primitive recursive:

?
(a)

inner⁡(n,m)=\operatorname {inner}(n, m)= the inner product of two kk-dimensional vectors nn and mm, if size⁡(n)=size⁡(m)=2k\operatorname {size}(n)=\operatorname {size}(m)=2 k (and it is 0, otherwise). (We treat a list [n1,n2,…,n2k]\left[n_{1}, n_{2}, \ldots , n_{2 k}\right] as a kk-dimensional integer vector whose ii th element is the integer represented by ⟨n2i−1,n2i⟩\left\langle n_{2 i-1}, n_{2 i}\right\rangle; that is, it is n2in_{2 i} if n2i−1>0n_{2 i-1}>0, and is −n2i-n_{2 i} if n2i−1=0n_{2 i-1}=0.)

(b)

det⁡(n)=\operatorname {det}(n)= the determinant of the matrix nn if size⁡(n)=2k2\operatorname {size}(n)=2 k^{2} for some k≥1k \geq 1 (and it is 0 otherwise). (We treat [n1,n2,…,n2k2]\left[n_{1}, n_{2}, \ldots , n_{2 k^{2}}\right] as a k×kk \times k integer matrix MM with MijM_{i j} equal to the integer represented by the pair ⟨n2(i−1)k+2j−1,n2(i−1)k+2j⟩\left\langle n_{2(i-1) k+2 j-1}, n_{2(i-1) k+2 j}\right\rangle.)

Problem 4.7.7

We say a sequence n=[n1,…,nk]n=\left[n_{1}, \ldots , n_{k}\right] is balanced if there exists a partition of {1,2,…,k}\left\{ 1,2, \ldots , k\right\} into two subsets BB and CC (i.e., B∪C={1,2,…,k}B \cup C=\left\{ 1,2, \ldots , k\right\} and B∩C=∅B \cap C=\emptyset) such that ∑i∈Bni=∑j∈Cnj\sum_{i \in B} n_{i}=\sum_{j \in C} n_{j}. Prove that the predicate [n[n is balanced] is primitive recursive.

?
Problem 4.7.8
?
(a)

Show that the function merge⁡(n,m)\operatorname {merge}(n, m) that merges two sorted sequences into a single sorted sequence (and output 0 if any of the two inputs is not sorted) is primitive recursive.

(b)

Prove that sort is primitive recursive using the algorithm of merge sort.

Problem 4.7.9

Assume that g:N→Ng: \mathbf{N} \rightarrow \mathbf{N} and h:N2→Nh: \mathbf{N}^{2} \rightarrow \mathbf{N} are two primitive recursive functions. Show that the following function ff is primitive recursive:

f(0,n)=g(n)f(m+1,n)=f(m,h(m,n)) \begin{aligned} f(0, n) & =g(n) \\ f(m+1, n) & =f(m, h(m, n)) \end{aligned}
?
Problem 4.7.10

Assume that g1,g2g_{1}, g_{2} and hh are all primitive recursive. Show that the following function ff is primitive recursive:

f(0,n)=g1(n)f(m+1,0)=g2(m)f(m+1,n+1)=h(m,n,f(m+1,n),f(m,n+1)) \begin{aligned} f(0, n) & =g_{1}(n) \\ f(m+1,0) & =g_{2}(m) \\ f(m+1, n+1) & =h(m, n, f(m+1, n), f(m, n+1)) \end{aligned}
?
Problem 4.7.11

Assume that g1,g2g_{1}, g_{2} and hh are all primitive recursive. Show that the following function ff is primitive recursive:

f(0,n)=g1(n)f(m+1,0)=g2(m)f(m+1,n+1)=h(m,n,f(m,n),f(n,m),f(m,m),f(n,n)) \begin{aligned} f(0, n) & =g_{1}(n) \\ f(m+1,0) & =g_{2}(m) \\ f(m+1, n+1) & =h(m, n, f(m, n), f(n, m), f(m, m), f(n, n)) \end{aligned}
?
Problem 4.7.12

Assume that g1,g2,h1g_{1}, g_{2}, h_{1} and h2h_{2} are all primitive recursive. Let f1f_{1} and f2f_{2} be functions defined by the following formulas:

f1(m,0)=g1(m)f2(m,0)=g2(m)f1(m,n+1)=h1(m,n,f1(m,n),f2(m,n))f2(m,n+1)=h2(m,n,f1(m,n),f2(m,n)) \begin{aligned} f_{1}(m, 0) & =g_{1}(m) \\ f_{2}(m, 0) & =g_{2}(m) \\ f_{1}(m, n+1) & =h_{1}\left(m, n, f_{1}(m, n), f_{2}(m, n)\right) \\ f_{2}(m, n+1) & =h_{2}\left(m, n, f_{1}(m, n), f_{2}(m, n)\right) \end{aligned}

Show that both f1f_{1} and f2f_{2} are primitive recursive:

?