12.07.2015 Views

Funciones primitivas recursivas - Dpto. Ciencias de la Computación ...

Funciones primitivas recursivas - Dpto. Ciencias de la Computación ...

Funciones primitivas recursivas - Dpto. Ciencias de la Computación ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Ejemplos (II)Las siguientes funciones son <strong>primitivas</strong> <strong>recursivas</strong>:−◮ Signo inverso: sg : N −→ N◮ Suma: + : N 2 −→ N◮ Producto: · : N 2 −→ N−sg (x) = 1 • − sg(x)+(x, y) = x + y·(x, y) = x·y◮ Mínimo: min : N 2 −→ N{ x si x ≤ ymin(x, y) =y e.c.o.c.◮ Máximo: max : N 2 −→ N{ x si x ≥ ymax(x, y) =y e.c.o.c.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.5


Ejemplos (III)◮ Distancia: || : N 2 −→ N{ x − y si x ≥ y|x − y| =y − x e.c.o.c.◮ Exponencial: exp : N 2 −→ N{ 1 si x = 0 ∧ y = 0exp(x, y) =x y e.c.o.c.◮ Factorial: fact : N −→ N⎧1 si x = 0⎪⎨fact(x) = ∏⎪⎩j e.c.o.c.1≤j≤xComp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.6


GOTO y PR (I)◮ Las funciones básicas son G-computables:{◮ X ←− X + 1Siguiente, S :Y ←− X◮ Nu<strong>la</strong>, O : Programa vacío, p∅∏ (n)◮ Proyecciones,j: Y ←− X j◮ GCOMP es cerrado bajo composición:Sean g : N k −→ N, h 1 , ..., h k : N m −→ N G-computables.El siguiente programa calcu<strong>la</strong> f = C(g; h 1 , ..., h n ):Z 1 ←− h 1 (X 1 , ..., X m ).Z k ←− h n (X 1 , ..., X m )Y ←− g(Z 1 , ..., Z k )Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.7


GOTO y PR (II)◮ GCOMP es cerrado bajo recursión primitiva:Sean g : N m −→ N, h : N m+2 −→ N G-computables.El siguiente programa calcu<strong>la</strong> f = R(g; h):[A]Y ←− g(X 1 , ..., X m )IF X m+1 = 0 GOTO EY ←− h(X 1 , ..., X m , Z, Y )Z ←− Z + 1X m+1 ←− X m+1 − 1GOTO AComp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.8


GOTO y PR (III)Proposición. PR GCOMP.Observaciones:◮ Existen funciones no totales que son GOTO–computables.◮ Importante: Existen funciones totales y GOTO–computablesque no son PR; por ejemplo, <strong>la</strong> función <strong>de</strong> Ackermann.◮La función <strong>de</strong> Ackermann, A : N 2 −→ N, se <strong>de</strong>fine porA(n, x) = A n (x), siendo para cada n ∈ N{A0 (x) = x + 1 (∀x ∈ N)A n+1 (x) = (A n ◦ A n ◦ (x+1) . . . ◦A n )(1) (∀x ∈ N)Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.9


Predicados GOTO–computables y PR◮ Un predicado sobre N es PR (resp. GOTO–computable) si<strong>la</strong> función que lo <strong>de</strong>fine es PR (resp. G–computable).◮ Un conjunto A ⊆ N n es PR (resp. GOTO–computable) sisu función característica, C A , es PR (resp. G–computable)Ejemplos:◮ Los conjuntos ∅ y N k , para cada k ∈ N son PR.◮ Los predicados: θ 1 (x, y) ≡ x = y; θ 2 (x, y) ≡ x ≤ y;θ 3 (x, y) ≡ x < y son PR.◮ Si f : N k −→ N; es PR (resp. GOTO–computable),entonces los predicados (k + 1)-arios siguientes son PR (resp.GOTO–computables):θ(⃗x, y) ≡ f (⃗x) = y; θ ′ (⃗x, y) ≡ f (⃗x) ≤ y; θ ′′ (⃗x, y) ≡ f (⃗x) < y.◮ El grafo <strong>de</strong> una función f ∈ PR (n) :G(f ) = {(⃗x, y) ∈ N n+1 : f (⃗x) = y}es un conjunto PR.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.10


Operaciones con conjuntos y predicadosProposición. Sean θ, θ ′ predicados sobre N, n–arios y PR (resp.G–COMP) entonces ¬θ, θ ∧ θ ′ , θ ∨ θ ′ , θ ⇒ θ ′ y θ ⇔ θ ′son predicados PR (resp. G-COMP).◮ ¬θ(⃗x) = sg(θ(⃗x)).◮ (θ ∧ θ ′ )(⃗x) = θ(⃗x)·θ ′ (⃗x)◮ (θ ∨ θ ′ )(⃗x) = sg(θ(⃗x) + θ ′ (⃗x))◮ θ ⇒ θ ′ ≡ ¬θ ∨ θ ′ .◮ θ ⇔ θ ′ ≡ θ ⇒ θ ′ ∧ θ ′ ⇒ θCoro<strong>la</strong>rio. Si A, B ⊆ N n son conjuntos PR (resp. G-COMP),entonces: N n − A; A ∩ B; A ∪ B son PR (resp. G-COMP).◮ C N n −A = ¬C A ;◮ C A∩B = C A ∧ C B ;◮ C A∪B = C A ∨ C BComp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.11


Definiciones por casosProposición. Sean k ≥ 2 y f 1 , . . . , f k : N m −→ N funciones PR.Sea {A 1 , . . . , A k } una partición <strong>de</strong> N m en conjuntos PR, es <strong>de</strong>cir,N m = ⋃ ki=1 A i y ∀i, j = 1, . . . , k, i ≠ j ⇒ A i ∩ A j = ∅Entonces, <strong>la</strong> función g : N m −→ N <strong>de</strong>finida por⎧⎪⎨ f 1 (⃗x) si ⃗x ∈ A 1g(⃗x) = . . .⎪⎩f k (⃗x) si ⃗x ∈ A kes PR.◮ Basta observar que g = f 1·C A1 + . . . + f k·C Akque es PR.◮ Nota: La proposición anterior pue<strong>de</strong> expresarse con predicadosPR, θ 1 , . . . , θ k , que sean exhaustivos y excluyentes (es <strong>de</strong>cir,tales que, para todo ⃗x ∈ N m : θ 1 (⃗x) + . . . + θ k (⃗x) = 1)Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.12


Suma y producto acotadosSea f : N n+1 −→ N total. Definimos:◮ Suma acotada: ∑ f (⃗x, y) = ∑ z≤yf (⃗x, z)◮ Producto acotado: ∏ f (⃗x, y) = ∏ z≤yf (⃗x, z)Proposición. Si f ∈ PR (n+1) entonces ∑ f , ∏ f∈ PR (n+1) .Observaciones:1. En vez <strong>de</strong> <strong>la</strong> última variable, podría utilizarse cualquier otracomo cota <strong>de</strong> <strong>la</strong> suma o <strong>de</strong>l producto.2. Para n = 0: ∑ f (y) = ∑ z≤y f (z) y ∏f (y) = ∏ z≤y f (z).Coro<strong>la</strong>rio. Si f : N n+1 −→ N; g : N n+k −→ N son PR, entoncestambién son PR <strong>la</strong>s funciones F 1 , F 2 : N n+k −→ N <strong>de</strong>finidas por:F 1 (⃗x,⃗y) =∑f (⃗x, z); F 2 (⃗x,⃗y) = ∏f (⃗x, z)z≤g(⃗x,⃗y)z≤g(⃗x,⃗y)Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.13


Cuantificación acotadaProposición. Sea θ ∈ PR un predicado n+1-ario. Los siguientespredicados son PR:θ 1 (⃗x, y) ≡ ∀z ≤ y θ(⃗x, z); θ 2 (⃗x, y) ≡ ∃z ≤ y θ(⃗x, z)◮ En efecto:θ 1 (⃗x, y) = ∏ z≤yθ(⃗x, z); θ 2 (⃗x, y) = sg( ∑ z≤yθ(⃗x, z))Ejemplos. Los siguientes predicados son PR:◮ Predicado <strong>de</strong> divisibilidad, x|y:◮ Predicado <strong>de</strong> primalidad:θ(x, y) ≡ ∃z ≤ y(y = z · x)primo(x) ≡ (x > 1) ∧ ∀t ≤ x((t|x) → (t = 1 ∨ t = x))Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.14


Minimización acotada (I)Definición. Sea θ(⃗x, y) un predicado (n + 1)–ario. Definimos <strong>la</strong>función θ ∗ µ : N n+1 → N, así:{θµ(⃗x, ∗ min{z ≤ y : θ(⃗x, z)} si existe tal mínimoy) =y + 1e.c.o.c.◮ Usualmente escribiremos: µz ≤ y θ(⃗x, z)y diremos que θ ∗ µ se obtiene <strong>de</strong> θ por minimización acotada.Proposición. Si θ ∈ PR (n+1) entonces θ ∗ µ ∈ PR (n+1) .◮ Basta observar que <strong>la</strong> función θ ∗ µ pue<strong>de</strong> expresarse como:θ ∗ µ(⃗x, y) = ∑ t≤y( ∏ z≤t¬θ(⃗x, z))Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.15


Minimización acotada (II)Definición. Sea f (⃗x, y) una función (n + 1)–aria. Definimos <strong>la</strong>función <strong>de</strong> aridad n + 1, f ∗ µ , así:f ∗ µ (⃗x, y) = µz ≤ y (f (⃗x, z) = 0)◮ Decimos que f ∗ µ se obtiene <strong>de</strong> f por minimización acotada.Proposición. Si f ∈ PR (n+1) entonces f ∗ µ ∈ PR (n+1) .Ejemplos.◮ La función cociente:◮ La función resto.rm(x, y) ={qt(x, y) = µt ≤ x (x < (t + 1) · y).x • − (y · qt(x, y)) si y ≠ 00 si y = 0Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.16


Minimización acotada (III)Otro ejemplo:◮ La sucesión <strong>de</strong> números primos.Sea p : N → N <strong>la</strong> función tal que p(0) = 0 y para todo n ≥ 1,p(n) = p n es el n–ésimo primo.◮ Lema. ∀n (p n+1 ≤ 1 + p n !).Por tanto, 1 + p(x)! es una cota para p(x + 1) y tenemos:{ p(0) = 0p(x + 1) = µy ≤ (1 + p(x)!) (primo(y) ∧ y > p(x))Luego p ∈ PR.Observación. Los resultados presentados sobre sumas y productosacotados, cuantificación acotada y minimización acotada sontambién válidos para predicados GOTO–computables y funcionesGOTO–computables totales.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.17


Codificación <strong>de</strong> sucesionesDefinición (Sucesiones finitas). Una codificación <strong>de</strong> N ma partir <strong>de</strong> N, es una función total f : N m −→ N que verifica:1. f es PR e inyectiva.2. Para cada i, 1 ≤ i ≤ m, <strong>la</strong> función total, g i : N −→ N:{ai si x ∈ rang(f ) ∧ x = f (ag i (x) =1 , ..., a m )0 e.c.o.c.es PR.Definición (Sucesiones <strong>de</strong> longitud arbitraria).Sea N ′ = {ε} ∪ N ∪ N 2 ∪ ... ∪ N k ∪ ... (don<strong>de</strong> ε es <strong>la</strong> sucesiónvacía -<strong>de</strong> longitud 0-).Una función f : N ′ −→ N, codifica N ′ a partir <strong>de</strong> N, si:◮ f es total.◮ ∀j ≥ 1, f ↾ N j es una codificación <strong>de</strong> N j , a partir <strong>de</strong> N.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.18


La función parLa función par es <strong>la</strong> función total 〈· , ·〉 : N 2 −→ N <strong>de</strong>finida por〈x, y〉 = 2 x · (2y + 1) • − 1◮ La función par es PR y biyectiva.◮ Para todo x, y ∈ N se verifica:x ≤ 〈x, y〉, y ≤ 〈x, y〉◮ Existen l, r : N −→ N tales que si z = 〈x, y〉 ,l(z) = x; r(z) = y z = 〈l(z), r(z)〉l y r son funciones <strong>de</strong>codificadoras <strong>de</strong> 〈 ·, ·〉.◮ Las funciones l, r son PR (1)Nota. Usando <strong>la</strong> función par po<strong>de</strong>mos codificar N 3 a partir <strong>de</strong> N:Y, en general, N k a partir <strong>de</strong> N.(x, y, z) −→ 〈x, 〈y, z〉〉Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.19


Números <strong>de</strong> Gö<strong>de</strong>lSea {p n : n ≥ 1} <strong>la</strong> sucesión <strong>de</strong> números primos y [ · · · ] : N ′ −→ N<strong>la</strong> función <strong>de</strong>finida así:{ [ε] = 1[a 1 , ..., a n ] = p a 11 ...pan nDiremos que [a 1 , ..., a n ] es el número <strong>de</strong> Gö<strong>de</strong>l <strong>de</strong> <strong>la</strong> sucesiónfinita a 1 , ..., a n .Propieda<strong>de</strong>s:◮ La función [ · · · ] codifica N ′ a partir <strong>de</strong> N.◮ Para todo i, 1 ≤ i ≤ n se verifica: a i ≤ [a 1 , ..., a n ].◮ Sin embargo:- La función [ · · · ] no es inyectiva.- rang( [ · · · ])= N − {0}.- Cada número natural codifica infinitas sucesiones.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.20


Las funciones componente y longitudLema. Si x ∈ N − {0, 1} existen unos únicos a 1 , ..., a n ∈ N, a n ≠ 0,tales que x = [a 1 , ..., a n ].◮ Escribiremos (x) i = a i si i ∈ {1, ..., n} y diremos que a i es<strong>la</strong> componente i–ésima <strong>de</strong> x.◮ Si i /∈ {1, ..., n} entonces escribiremos: (x) i = 0.Definición. Denominaremos función componente a <strong>la</strong> función:( · )· : N 2 −→ N , <strong>de</strong>finida así:(x) i = µt ≤ x (¬(p t+1i|x))◮ La función componente es PR.Definición. Definimos <strong>la</strong> función longitud, long : N −→ N, así:long(x) = µi ≤ x ((x) i ≠ 0 ∧ ∀j ≤ x (j > i → (x) j = 0))◮ La función longitud es PR.Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.21


La función historia◮ Sea f : N n+1 −→ N (con n ≥ 0). La función historia <strong>de</strong> f es<strong>la</strong> función ˆf : N n+1 −→ N <strong>de</strong>finida así:ˆf (⃗x, y) = [f (⃗x, 0), ..., f (⃗x, y)]Proposición. f ∈ PR (n+1) ⇐⇒ ˆf ∈ PR (n+1) .(⇒) ˆf se <strong>de</strong>fine por recursión a partir <strong>de</strong> funciones PR:{ ˆf (⃗x, 0) = 2 f (⃗x,0)ˆf (⃗x, y + 1) = ˆf (⃗x, y)·p f (⃗x,y+1)y+2(⇐) En efecto: f (⃗x, y) = (ˆf (⃗x, y)) y+1Nota: Obsérvese que para n = 0 <strong>la</strong> función historia <strong>de</strong> f está<strong>de</strong>finida así:ˆf (x) = [f (0), f (1), ..., f (x)]Comp., 2006–07 <strong>Funciones</strong> Primitivas Recursivas 3.22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!