diff --git a/info4/kapitel-9/PrimitiveRekursion.ipynb b/info4/kapitel-9/PrimitiveRekursion.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..d79129902e9a8189397e26f9de5c171277251155
--- /dev/null
+++ b/info4/kapitel-9/PrimitiveRekursion.ipynb
@@ -0,0 +1,1676 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "76265463",
+   "metadata": {},
+   "source": [
+    "# Primitiv Rekursive Funktionen\n",
+    "\n",
+    "\n",
+    "Wir stellen jetzt die primitiv rekursiven Funktionen in der logischen Programmiersprache Prolog ab. Prolog arbeiten mit Relationen, d.h. alle Funktionen haben ein zusätzliches Argument: den Rückgabewert.\n",
+    "\n",
+    "\n",
+    "Alle konstanten Funktionen sind primitiv rekursiv und die Nachfolgerfunktion ist primitiv rekursiv."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "1be13bd0",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "% wir brauchen hier nur die konstante Funktion die 0 zurückgibt:\n",
+    "zero(0).\n",
+    "\n",
+    "% die Nachfolgerfunktion (Successor):\n",
+    "s(X,X1) :- X1 is X+1."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "2a60777c",
+   "metadata": {},
+   "source": [
+    "Alle Identitäten (Projektionen) sind primitiv rekursiv:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "7aa01fb7",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "% hier ein paar Projektionsfunktionen die wir benötigen:\n",
+    "id_1_1(X,X).\n",
+    "id_2_1(X,_,X).\n",
+    "id_2_2(_,Y,Y).\n",
+    "id_3_1(X,_,_,X).\n",
+    "id_3_2(_,Y,_,Y).\n",
+    "id_3_3(_,_,Z,Z)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "08bb0d22",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mR = 11"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- s(10,R)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "5e09a6e0",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 0,\n",
+       "Res = 1"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- zero(X), s(X,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "8e91be0c",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 22"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- id_3_2(11,22,33,Res)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "0fae8b28",
+   "metadata": {},
+   "source": [
+    "### Substitution\n",
+    "- h(n1, n2, ... nm) = f(g1(n1, n2, ... nm); g2(n1, n2, ... nm),..., gk(n1, n2, ... nm))\n",
+    "\n",
+    "Die Komposition von primitiv rekursiven Funktionen (Substitution) ist auch primitiv rekursiv:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "id": "cdece1e6",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "s_id_3_2(N,Y,Z,R) :- id_3_2(N,Y,Z,R1), s(R1,R)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "11da5fea",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 23"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- s_id_3_2(11,22,33,Res)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "6af212c6",
+   "metadata": {},
+   "source": [
+    "### Primitive Rekursion\n",
+    "- f(0, x1, x2, ... xm) = g(x1, x2, ... , xm)\n",
+    "- f(n + 1, x1, x2, ... xm) = h(n, f(n, x1, x2, ... , xm), x1, x2, ..., xm)\n",
+    "\n",
+    "Die primitive Rekursion selber kann in Prolog durch zwei Klauseln dargestellt werden: eine für die Basis (0) und eine für die Rekursion (n+1):"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "id": "4e52bde2",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "add_pr(0,X,Res) :- id_1_1(X,Res).\n",
+    "add_pr(N1,X,R1) :- N1>0, N is N1-1,\n",
+    "   add_pr(N,X,R), % rekursiver Aufruf\n",
+    "   s_id_3_2(N,R,X,R1). % Funktion h"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
+   "id": "e44bf4b9",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 3"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- add_pr(1,2,Res)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "474a8d10",
+   "metadata": {},
+   "source": [
+    "Hier ein weiteres Beispiel:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "id": "e0a5e76e",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "mul_pr(0,_X,Res) :- zero(Res).\n",
+    "mul_pr(N1,X,Res) :- N1>0, N is N1-1,\n",
+    "   mul_pr(N,X,RecRes), % rekursiver Aufruf\n",
+    "   h_mul(N,RecRes,X,Res). % Funktion h\n",
+    "\n",
+    "h_mul(A,RecRes,C,Res) :- id_3_2(A,RecRes,C,RR), id_3_3(A,RecRes,C,RC),\n",
+    "                add_pr(RR,RC,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "id": "6d457c8f",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mR = 200"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- mul_pr(10,20,R)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "6c83afad",
+   "metadata": {},
+   "source": [
+    "## Gödelisierung\n",
+    "\n",
+    "Wie kann man eine primitiv rekursive Funktion als Zahl oder Wort darstellen?\n",
+    "\n",
+    "Wir suchen eine Funktion G die injektiv und berechnbar ist und einer Darstellung einer primitiv rekursiven Funktion eine Zahl oder ein Wort zuordnet.\n",
+    "\n",
+    "Unten werden wir anstatt Wörtern oder Zahlen Prolog Terme verwenden, wobei ein Prolog Term wie ```s(0)``` auch immer eine Darstellung als Wort hat.\n",
+    "\n",
+    "Wei kann man eine Funktion wie die Addition oder Multiplikation, definiert nach obigem Schema in eine Wortdarstellung umwandeln?\n",
+    "\n",
+    "- add(0, x) = id1(x)\n",
+    "- add(n + 1, x) = h(n, add(n, x), x)\n",
+    "\n",
+    "Wir brauchen eine Syntax / Darstellung für primitiv rekursive Funktionen die mit beliebiger Verschachtelung und beliebig vielen Argumenten umgehen kann.\n",
+    "\n",
+    "Im Skript ist dies ```G(add) = PR[id|∗|,SUB[s;id|||∗||](x|,x||,x|||)](x|,x||)```\n",
+    "\n",
+    "Unten im Prolog Programm machen wir es uns etwas einfacher und erlauben auch die Verwendung von Zahlen anstatt der Verwendung der Querstriche. Bei den Identitäten speichern wir auch nur den Index der Projektion, nicht die Arität der Eingabe (diese ist überflüssig).\n",
+    "Bei der Substitution und der Rekursion ist die Gödelisierung der Namen der Argumente (G(x1),...) auch überflüssig.\n",
+    "Unsere Gödelisierung der Addition ist deshalb: ```pr(id(1),sub(s,[id(2)])) ```\n",
+    "\n",
+    "- id(N) steht für eine Projektionsfunktion die auf das Argument N projiziert\n",
+    "- s steht (wie im Skript) für die Nachfolgerfunktion\n",
+    "- sub(F,Gs) steht für eine Funktion die durch das Substitutionsschema definiert wird; Gs ist eine Liste von Darstellungen von Funktionen\n",
+    "- pr(G,H) steht für eine Funktion die durch Rekursion mit Basisfunktion G und rekursivem Fall H definiert ist\n",
+    "\n",
+    "\n",
+    "Wir schreiben jetzt einen Interpreter der unsere Gödelisierung als Prolog Term verarbeitet und ausrechnet. Dies ist ein konstruktiver Beweis, dass unsere Gödelisierung injektiv ist und die Umkehrfunktion berechenbar ist:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 45,
+   "id": "c426862d",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "indent(0).\n",
+    "indent(s(X)) :- write('->'), indent(X).\n",
+    "\n",
+    "iformat(I,Msg,Args) :- indent(I), format(user_output,Msg,Args),fail.\n",
+    "iformat(_,_,_)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 46,
+   "id": "194ac4e1",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "->->Test Ausgabe1"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mtrue"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- iformat(s(s(0)),'Test Ausgabe~w~n',[1])."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 47,
+   "id": "cd0e84d5",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "compute_pr(PR,Args,R) :- compute_pr(PR,Args,R,0).\n",
+    "% rules to compute primitive recursive functions:\n",
+    "compute_pr(PR,Args,_Result,I) :- iformat(I,'Computing ~w with ~w~n',[PR,Args]),fail.\n",
+    "compute_pr(cst(X),_Args,X,_).\n",
+    "compute_pr(id(N),Args,X,_) :- nth1(N,Args,X).\n",
+    "compute_pr(s,[X],Res,_) :- Res is X+1.\n",
+    "compute_pr(sub(F,Gs),Args,Res,I) :-\n",
+    "   compute_pr_l(Gs,Args,GAs,s(I)), % apply the functions in Gs to the args\n",
+    "   compute_pr(F,GAs,Res,s(I)), % apply F to the result of applying Gs\n",
+    "   iformat(I,'Result = ~w~n',[Res]).\n",
+    "compute_pr(pr(G,_H),[N|Args],Res,I) :- N=0, % base case of primitive recursion\n",
+    "   compute_pr(G,Args,Res,s(I)),\n",
+    "   iformat(I,'pr base case = ~w~n',[Res]).\n",
+    "compute_pr(pr(G,H),[N1|Args],Res,I) :- N1>0, N is N1-1, % recursive case\n",
+    "   compute_pr(pr(G,H),[N|Args],RecResult,s(I)),\n",
+    "   compute_pr(H,[N,RecResult|Args],Res,s(I)).\n",
+    "\n",
+    "% compute result for a list of arguments:\n",
+    "compute_pr_l([],_,[],_).\n",
+    "compute_pr_l([Fun|TF],Args,[Res1|TA],I) :-\n",
+    "    compute_pr(Fun,Args,Res1,I), compute_pr_l(TF,Args,TA,I)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 49,
+   "id": "ba2d1d5b",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Computing pr(id(1),sub(s,[id(2)])) with [2,3]\n",
+       "->Computing pr(id(1),sub(s,[id(2)])) with [1,3]\n",
+       "->->Computing pr(id(1),sub(s,[id(2)])) with [0,3]\n",
+       "->->->Computing id(1) with [3]\n",
+       "->->pr base case = 3\n",
+       "->->Computing sub(s,[id(2)]) with [0,3,3]\n",
+       "->->->Computing id(2) with [0,3,3]\n",
+       "->->->Computing s with [3]\n",
+       "->->Result = 4\n",
+       "->Computing sub(s,[id(2)]) with [1,4,3]\n",
+       "->->Computing id(2) with [1,4,3]\n",
+       "->->Computing s with [4]\n",
+       "->Result = 5"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 5"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- compute_pr(pr(id(1),sub(s,[id(2)])), [2,3], Res)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "729fa283",
+   "metadata": {},
+   "source": [
+    "Können wir prüfen ob eine Gödelisierung valide ist? Ist G[Pr] entscheidbar. Ja, hier ist der Code für unser Beispiel:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 50,
+   "id": "9cc30401",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "% checking if something is a valid primitive recursive function\n",
+    "check_arity(cst(_X),_). % any arity is fine\n",
+    "check_arity(id(N),Arity) :- N>0, N =< Arity. % Note: we do not encode the total number of args\n",
+    "check_arity(s,1).\n",
+    "check_arity(sub(F,Gs),Arity) :- l_check_arity(Gs,Arity), length(Gs,Len), check_arity(F,Len).\n",
+    "check_arity(pr(G,H),Arity) :- A1 is Arity-1, check_arity(G,A1),\n",
+    "  Ap1 is Arity+1, check_arity(H,Ap1).\n",
+    "%check_arity(Fun,Arity) :- format('INVALID ARITY ~w for ~w !~n',[Arity,Fun]), fail.\n",
+    "\n",
+    "l_check_arity([],_).\n",
+    "l_check_arity([G1|TG],Arity) :- check_arity(G1,Arity), l_check_arity(TG,Arity).\n",
+    "\n",
+    "run_pr(Fun,Args,Res) :- length(Args,Len),\n",
+    "   check_arity(Fun,Len),\n",
+    "   compute_pr(Fun,Args,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 51,
+   "id": "b2dc1cb4",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Computing pr(id(1),sub(s,[id(2)])) with [2,3]\n",
+       "->Computing pr(id(1),sub(s,[id(2)])) with [1,3]\n",
+       "->->Computing pr(id(1),sub(s,[id(2)])) with [0,3]\n",
+       "->->->Computing id(1) with [3]\n",
+       "->->pr base case = 3\n",
+       "->->Computing sub(s,[id(2)]) with [0,3,3]\n",
+       "->->->Computing id(2) with [0,3,3]\n",
+       "->->->Computing s with [3]\n",
+       "->->Result = 4\n",
+       "->Computing sub(s,[id(2)]) with [1,4,3]\n",
+       "->->Computing id(2) with [1,4,3]\n",
+       "->->Computing s with [4]\n",
+       "->Result = 5"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 5"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- run_pr(pr(id(1),sub(s,[id(2)])), [2,3], Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "fccefd19",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1;31mfalse"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- run_pr(pr(id(1),sub(s,[id(2)])), [2], Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 53,
+   "id": "cb6e6ee5",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "add_fun(   pr(id(1),sub(s,[id(2)]))   ).\n",
+    "mul_fun(   pr(cst(0),sub( pr(id(1),sub(s,[id(2)])) ,[id(2),id(3)]))   ).\n",
+    "\n",
+    "add(X,Y,Res) :- add_fun(Fun), run_pr(Fun,[X,Y],Res).\n",
+    "mul(X,Y,Res) :- mul_fun(Fun), run_pr(Fun,[X,Y],Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 56,
+   "id": "23998b5d",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [5,2]\n",
+       "->Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [4,2]\n",
+       "->->Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [3,2]\n",
+       "->->->Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [2,2]\n",
+       "->->->->Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [1,2]\n",
+       "->->->->->Computing pr(cst(0),sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)])) with [0,2]\n",
+       "->->->->->->Computing cst(0) with [2]\n",
+       "->->->->->pr base case = 0\n",
+       "->->->->->Computing sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)]) with [0,0,2]\n",
+       "->->->->->->Computing id(2) with [0,0,2]\n",
+       "->->->->->->Computing id(3) with [0,0,2]\n",
+       "->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [0,2]\n",
+       "->->->->->->->Computing id(1) with [2]\n",
+       "->->->->->->pr base case = 2\n",
+       "->->->->->Result = 2\n",
+       "->->->->Computing sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)]) with [1,2,2]\n",
+       "->->->->->Computing id(2) with [1,2,2]\n",
+       "->->->->->Computing id(3) with [1,2,2]\n",
+       "->->->->->Computing pr(id(1),sub(s,[id(2)])) with [2,2]\n",
+       "->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [1,2]\n",
+       "->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [0,2]\n",
+       "->->->->->->->->Computing id(1) with [2]\n",
+       "->->->->->->->pr base case = 2\n",
+       "->->->->->->->Computing sub(s,[id(2)]) with [0,2,2]\n",
+       "->->->->->->->->Computing id(2) with [0,2,2]\n",
+       "->->->->->->->->Computing s with [2]\n",
+       "->->->->->->->Result = 3\n",
+       "->->->->->->Computing sub(s,[id(2)]) with [1,3,2]\n",
+       "->->->->->->->Computing id(2) with [1,3,2]\n",
+       "->->->->->->->Computing s with [3]\n",
+       "->->->->->->Result = 4\n",
+       "->->->->Result = 4\n",
+       "->->->Computing sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)]) with [2,4,2]\n",
+       "->->->->Computing id(2) with [2,4,2]\n",
+       "->->->->Computing id(3) with [2,4,2]\n",
+       "->->->->Computing pr(id(1),sub(s,[id(2)])) with [4,2]\n",
+       "->->->->->Computing pr(id(1),sub(s,[id(2)])) with [3,2]\n",
+       "->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [2,2]\n",
+       "->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [1,2]\n",
+       "->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [0,2]\n",
+       "->->->->->->->->->Computing id(1) with [2]\n",
+       "->->->->->->->->pr base case = 2\n",
+       "->->->->->->->->Computing sub(s,[id(2)]) with [0,2,2]\n",
+       "->->->->->->->->->Computing id(2) with [0,2,2]\n",
+       "->->->->->->->->->Computing s with [2]\n",
+       "->->->->->->->->Result = 3\n",
+       "->->->->->->->Computing sub(s,[id(2)]) with [1,3,2]\n",
+       "->->->->->->->->Computing id(2) with [1,3,2]\n",
+       "->->->->->->->->Computing s with [3]\n",
+       "->->->->->->->Result = 4\n",
+       "->->->->->->Computing sub(s,[id(2)]) with [2,4,2]\n",
+       "->->->->->->->Computing id(2) with [2,4,2]\n",
+       "->->->->->->->Computing s with [4]\n",
+       "->->->->->->Result = 5\n",
+       "->->->->->Computing sub(s,[id(2)]) with [3,5,2]\n",
+       "->->->->->->Computing id(2) with [3,5,2]\n",
+       "->->->->->->Computing s with [5]\n",
+       "->->->->->Result = 6\n",
+       "->->->Result = 6\n",
+       "->->Computing sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)]) with [3,6,2]\n",
+       "->->->Computing id(2) with [3,6,2]\n",
+       "->->->Computing id(3) with [3,6,2]\n",
+       "->->->Computing pr(id(1),sub(s,[id(2)])) with [6,2]\n",
+       "->->->->Computing pr(id(1),sub(s,[id(2)])) with [5,2]\n",
+       "->->->->->Computing pr(id(1),sub(s,[id(2)])) with [4,2]\n",
+       "->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [3,2]\n",
+       "->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [2,2]\n",
+       "->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [1,2]\n",
+       "->->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [0,2]\n",
+       "->->->->->->->->->->Computing id(1) with [2]\n",
+       "->->->->->->->->->pr base case = 2\n",
+       "->->->->->->->->->Computing sub(s,[id(2)]) with [0,2,2]\n",
+       "->->->->->->->->->->Computing id(2) with [0,2,2]\n",
+       "->->->->->->->->->->Computing s with [2]\n",
+       "->->->->->->->->->Result = 3\n",
+       "->->->->->->->->Computing sub(s,[id(2)]) with [1,3,2]\n",
+       "->->->->->->->->->Computing id(2) with [1,3,2]\n",
+       "->->->->->->->->->Computing s with [3]\n",
+       "->->->->->->->->Result = 4\n",
+       "->->->->->->->Computing sub(s,[id(2)]) with [2,4,2]\n",
+       "->->->->->->->->Computing id(2) with [2,4,2]\n",
+       "->->->->->->->->Computing s with [4]\n",
+       "->->->->->->->Result = 5\n",
+       "->->->->->->Computing sub(s,[id(2)]) with [3,5,2]\n",
+       "->->->->->->->Computing id(2) with [3,5,2]\n",
+       "->->->->->->->Computing s with [5]\n",
+       "->->->->->->Result = 6\n",
+       "->->->->->Computing sub(s,[id(2)]) with [4,6,2]\n",
+       "->->->->->->Computing id(2) with [4,6,2]\n",
+       "->->->->->->Computing s with [6]\n",
+       "->->->->->Result = 7\n",
+       "->->->->Computing sub(s,[id(2)]) with [5,7,2]\n",
+       "->->->->->Computing id(2) with [5,7,2]\n",
+       "->->->->->Computing s with [7]\n",
+       "->->->->Result = 8\n",
+       "->->Result = 8\n",
+       "->Computing sub(pr(id(1),sub(s,[id(2)])),[id(2),id(3)]) with [4,8,2]\n",
+       "->->Computing id(2) with [4,8,2]\n",
+       "->->Computing id(3) with [4,8,2]\n",
+       "->->Computing pr(id(1),sub(s,[id(2)])) with [8,2]\n",
+       "->->->Computing pr(id(1),sub(s,[id(2)])) with [7,2]\n",
+       "->->->->Computing pr(id(1),sub(s,[id(2)])) with [6,2]\n",
+       "->->->->->Computing pr(id(1),sub(s,[id(2)])) with [5,2]\n",
+       "->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [4,2]\n",
+       "->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [3,2]\n",
+       "->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [2,2]\n",
+       "->->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [1,2]\n",
+       "->->->->->->->->->->Computing pr(id(1),sub(s,[id(2)])) with [0,2]\n",
+       "->->->->->->->->->->->Computing id(1) with [2]\n",
+       "->->->->->->->->->->pr base case = 2\n",
+       "->->->->->->->->->->Computing sub(s,[id(2)]) with [0,2,2]\n",
+       "->->->->->->->->->->->Computing id(2) with [0,2,2]\n",
+       "->->->->->->->->->->->Computing s with [2]\n",
+       "->->->->->->->->->->Result = 3\n",
+       "->->->->->->->->->Computing sub(s,[id(2)]) with [1,3,2]\n",
+       "->->->->->->->->->->Computing id(2) with [1,3,2]\n",
+       "->->->->->->->->->->Computing s with [3]\n",
+       "->->->->->->->->->Result = 4\n",
+       "->->->->->->->->Computing sub(s,[id(2)]) with [2,4,2]\n",
+       "->->->->->->->->->Computing id(2) with [2,4,2]\n",
+       "->->->->->->->->->Computing s with [4]\n",
+       "->->->->->->->->Result = 5\n",
+       "->->->->->->->Computing sub(s,[id(2)]) with [3,5,2]\n",
+       "->->->->->->->->Computing id(2) with [3,5,2]\n",
+       "->->->->->->->->Computing s with [5]\n",
+       "->->->->->->->Result = 6\n",
+       "->->->->->->Computing sub(s,[id(2)]) with [4,6,2]\n",
+       "->->->->->->->Computing id(2) with [4,6,2]\n",
+       "->->->->->->->Computing s with [6]\n",
+       "->->->->->->Result = 7\n",
+       "->->->->->Computing sub(s,[id(2)]) with [5,7,2]\n",
+       "->->->->->->Computing id(2) with [5,7,2]\n",
+       "->->->->->->Computing s with [7]\n",
+       "->->->->->Result = 8\n",
+       "->->->->Computing sub(s,[id(2)]) with [6,8,2]\n",
+       "->->->->->Computing id(2) with [6,8,2]\n",
+       "->->->->->Computing s with [8]\n",
+       "->->->->Result = 9\n",
+       "->->->Computing sub(s,[id(2)]) with [7,9,2]\n",
+       "->->->->Computing id(2) with [7,9,2]\n",
+       "->->->->Computing s with [9]\n",
+       "->->->Result = 10\n",
+       "->Result = 10"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 10"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?-mul(5,2,Res)."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "b66ec641",
+   "metadata": {},
+   "source": [
+    "## Aufzählung der validen primitiv rekursiven Funktionen\n",
+    "\n",
+    "Wir schreiben erst zwei kleine Hilfsprädikate, um die natürlichen Zahlen aufzuzählen und um Zahlen bis zu einer Obergrenze aufzuzählen:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 62,
+   "id": "06533a42",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "gen_any_nr(N,N).\n",
+    "gen_any_nr(N,R) :- N1 is N+1, gen_any_nr(N1,R).\n",
+    "\n",
+    "gen_nr_up_to(Bound,Bound).\n",
+    "gen_nr_up_to(X,Bound) :- Bound>0, B1 is Bound-1, gen_nr_up_to(X,B1)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 63,
+   "id": "bdeb602e",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 0"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- gen_any_nr(0,X)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 64,
+   "id": "bcb27beb",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 1"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 65,
+   "id": "d0ee04c3",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 2"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 66,
+   "id": "e2832af2",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "% The new active goal is: mul(5,2,Res)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mtrue"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:cut."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 67,
+   "id": "65473e50",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 2"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- gen_nr_up_to(X,2)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 68,
+   "id": "05ca76fd",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 1"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 69,
+   "id": "878e5dae",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = 0"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "f5828d6d",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1;31mfalse"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 100,
+   "id": "6e9af2a9",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "gen_valid_pr_fun(X) :- gen_any_nr(0,Bound),gen_pr(X,Bound), \n",
+    "   check_arity(X,1). % prüfe, dass wir eine valide Funktion der Arität 1 haben\n",
+    "\n",
+    "% a way to enumerate possible primitive recursive functions:\n",
+    "% by enumerating the Prolog term encodings\n",
+    "gen_pr(cst(X),Bound) :- gen_nr_up_to(X,Bound).\n",
+    "gen_pr(id(N),Bound) :- gen_nr_up_to(N,Bound), N>0.\n",
+    "gen_pr(s,_).\n",
+    "gen_pr(sub(F,Gs),Bound) :- Bound>1, B1 is Bound - 1,\n",
+    "   gen_pr(F,B1), l_gen_pr(Gs,B1).\n",
+    "gen_pr(pr(G,H),Bound) :- Bound>1, B1 is Bound - 1, gen_pr(G,B1), gen_pr(H,B1).\n",
+    "\n",
+    "l_gen_pr([],_).\n",
+    "l_gen_pr([F1|TF],Bound) :- Bound>0, gen_pr(F1,Bound), B1 is Bound-1, l_gen_pr(TF,B1)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 85,
+   "id": "8413c05f",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(0)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- gen_valid_pr_fun(Function)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 86,
+   "id": "c6857661",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = s"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 87,
+   "id": "7fb572c6",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(1)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 88,
+   "id": "23d8ba01",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(0)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 89,
+   "id": "553312d9",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = id(1)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 90,
+   "id": "8b06c226",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = s"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 91,
+   "id": "f10e13a7",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(2)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 92,
+   "id": "4a62362f",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(1)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 93,
+   "id": "8d9c5277",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = cst(0)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 94,
+   "id": "4b19394e",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = id(1)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 95,
+   "id": "a53a4113",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = s"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 96,
+   "id": "2b461e04",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = sub(cst(1),[])"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:retry."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 97,
+   "id": "22cbb7d4",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "% The new active goal is: mul(5,2,Res)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mtrue"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- jupyter:cut."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 98,
+   "id": "bf5fd841",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mX = cst(3)"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- gen_pr(X,3), check_arity(X,1)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 103,
+   "id": "c9979069",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    ":- dynamic sol_count/0.\n",
+    "set_limit(X) :- retractall(sol_count(_,_)), assert(sol_count(1,X)).\n",
+    "print_sol(X) :- retract(sol_count(Nr,Lim)),\n",
+    "   format('Sol ~w: ~w~n',[Nr,X]),\n",
+    "   (Nr>=Lim -> true ; N1 is Nr+1, assert(sol_count(N1,Lim)),fail)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "b5d03b36",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Sol 1: cst(2)\n",
+       "Sol 2: cst(1)\n",
+       "Sol 3: cst(0)\n",
+       "Sol 4: id(1)\n",
+       "Sol 5: s\n",
+       "Sol 6: sub(cst(1),[])\n",
+       "Sol 7: sub(cst(1),[cst(1)])\n",
+       "Sol 8: sub(cst(1),[cst(0)])\n",
+       "Sol 9: sub(cst(1),[id(1)])\n",
+       "Sol 10: sub(cst(1),[s])\n",
+       "Sol 11: sub(cst(0),[])\n",
+       "Sol 12: sub(cst(0),[cst(1)])\n",
+       "Sol 13: sub(cst(0),[cst(0)])\n",
+       "Sol 14: sub(cst(0),[id(1)])\n",
+       "Sol 15: sub(cst(0),[s])\n",
+       "Sol 16: sub(id(1),[cst(1)])\n",
+       "Sol 17: sub(id(1),[cst(0)])\n",
+       "Sol 18: sub(id(1),[id(1)])\n",
+       "Sol 19: sub(id(1),[s])\n",
+       "Sol 20: sub(s,[cst(1)])\n",
+       "Sol 21: sub(s,[cst(0)])\n",
+       "Sol 22: sub(s,[id(1)])\n",
+       "Sol 23: sub(s,[s])\n",
+       "Sol 24: pr(cst(1),cst(1))\n",
+       "Sol 25: pr(cst(1),cst(0))\n",
+       "Sol 26: pr(cst(1),id(1))\n",
+       "Sol 27: pr(cst(0),cst(1))\n",
+       "Sol 28: pr(cst(0),cst(0))\n",
+       "Sol 29: pr(cst(0),id(1))"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1;31mfalse"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- set_limit(100),gen_pr(X,2), check_arity(X,1), print_sol(X)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 108,
+   "id": "af201e0b",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Sol 1: cst(0)\n",
+       "Sol 2: s\n",
+       "Sol 3: cst(1)\n",
+       "Sol 4: cst(0)\n",
+       "Sol 5: id(1)\n",
+       "Sol 6: s\n",
+       "Sol 7: cst(2)\n",
+       "Sol 8: cst(1)\n",
+       "Sol 9: cst(0)\n",
+       "Sol 10: id(1)\n",
+       "Sol 11: s\n",
+       "Sol 12: sub(cst(1),[])\n",
+       "Sol 13: sub(cst(1),[cst(1)])\n",
+       "Sol 14: sub(cst(1),[cst(0)])\n",
+       "Sol 15: sub(cst(1),[id(1)])\n",
+       "Sol 16: sub(cst(1),[s])\n",
+       "Sol 17: sub(cst(0),[])\n",
+       "Sol 18: sub(cst(0),[cst(1)])\n",
+       "Sol 19: sub(cst(0),[cst(0)])\n",
+       "Sol 20: sub(cst(0),[id(1)])\n",
+       "Sol 21: sub(cst(0),[s])\n",
+       "Sol 22: sub(id(1),[cst(1)])\n",
+       "Sol 23: sub(id(1),[cst(0)])\n",
+       "Sol 24: sub(id(1),[id(1)])\n",
+       "Sol 25: sub(id(1),[s])\n",
+       "Sol 26: sub(s,[cst(1)])\n",
+       "Sol 27: sub(s,[cst(0)])\n",
+       "Sol 28: sub(s,[id(1)])\n",
+       "Sol 29: sub(s,[s])\n",
+       "Sol 30: pr(cst(1),cst(1))\n",
+       "Sol 31: pr(cst(1),cst(0))\n",
+       "Sol 32: pr(cst(1),id(1))\n",
+       "Sol 33: pr(cst(0),cst(1))\n",
+       "Sol 34: pr(cst(0),cst(0))\n",
+       "Sol 35: pr(cst(0),id(1))\n",
+       "Sol 36: cst(3)\n",
+       "Sol 37: cst(2)\n",
+       "Sol 38: cst(1)\n",
+       "Sol 39: cst(0)\n",
+       "Sol 40: id(1)\n",
+       "Sol 41: s\n",
+       "Sol 42: sub(cst(2),[])\n",
+       "Sol 43: sub(cst(2),[cst(2)])\n",
+       "Sol 44: sub(cst(2),[cst(2),cst(1)])\n",
+       "Sol 45: sub(cst(2),[cst(2),cst(0)])\n",
+       "Sol 46: sub(cst(2),[cst(2),id(1)])\n",
+       "Sol 47: sub(cst(2),[cst(2),s])\n",
+       "Sol 48: sub(cst(2),[cst(1)])\n",
+       "Sol 49: sub(cst(2),[cst(1),cst(1)])\n",
+       "Sol 50: sub(cst(2),[cst(1),cst(0)])\n",
+       "Sol 51: sub(cst(2),[cst(1),id(1)])\n",
+       "Sol 52: sub(cst(2),[cst(1),s])\n",
+       "Sol 53: sub(cst(2),[cst(0)])\n",
+       "Sol 54: sub(cst(2),[cst(0),cst(1)])\n",
+       "Sol 55: sub(cst(2),[cst(0),cst(0)])\n",
+       "Sol 56: sub(cst(2),[cst(0),id(1)])\n",
+       "Sol 57: sub(cst(2),[cst(0),s])\n",
+       "Sol 58: sub(cst(2),[id(1)])\n",
+       "Sol 59: sub(cst(2),[id(1),cst(1)])\n",
+       "Sol 60: sub(cst(2),[id(1),cst(0)])\n",
+       "Sol 61: sub(cst(2),[id(1),id(1)])\n",
+       "Sol 62: sub(cst(2),[id(1),s])\n",
+       "Sol 63: sub(cst(2),[s])\n",
+       "Sol 64: sub(cst(2),[s,cst(1)])\n",
+       "Sol 65: sub(cst(2),[s,cst(0)])\n",
+       "Sol 66: sub(cst(2),[s,id(1)])\n",
+       "Sol 67: sub(cst(2),[s,s])\n",
+       "Sol 68: sub(cst(2),[sub(cst(1),[])])\n",
+       "Sol 69: sub(cst(2),[sub(cst(1),[]),cst(1)])\n",
+       "Sol 70: sub(cst(2),[sub(cst(1),[]),cst(0)])\n",
+       "Sol 71: sub(cst(2),[sub(cst(1),[]),id(1)])\n",
+       "Sol 72: sub(cst(2),[sub(cst(1),[]),s])\n",
+       "Sol 73: sub(cst(2),[sub(cst(1),[cst(1)])])\n",
+       "Sol 74: sub(cst(2),[sub(cst(1),[cst(1)]),cst(1)])\n",
+       "Sol 75: sub(cst(2),[sub(cst(1),[cst(1)]),cst(0)])\n",
+       "Sol 76: sub(cst(2),[sub(cst(1),[cst(1)]),id(1)])\n",
+       "Sol 77: sub(cst(2),[sub(cst(1),[cst(1)]),s])\n",
+       "Sol 78: sub(cst(2),[sub(cst(1),[cst(0)])])\n",
+       "Sol 79: sub(cst(2),[sub(cst(1),[cst(0)]),cst(1)])\n",
+       "Sol 80: sub(cst(2),[sub(cst(1),[cst(0)]),cst(0)])\n",
+       "Sol 81: sub(cst(2),[sub(cst(1),[cst(0)]),id(1)])\n",
+       "Sol 82: sub(cst(2),[sub(cst(1),[cst(0)]),s])\n",
+       "Sol 83: sub(cst(2),[sub(cst(1),[id(1)])])\n",
+       "Sol 84: sub(cst(2),[sub(cst(1),[id(1)]),cst(1)])\n",
+       "Sol 85: sub(cst(2),[sub(cst(1),[id(1)]),cst(0)])\n",
+       "Sol 86: sub(cst(2),[sub(cst(1),[id(1)]),id(1)])\n",
+       "Sol 87: sub(cst(2),[sub(cst(1),[id(1)]),s])\n",
+       "Sol 88: sub(cst(2),[sub(cst(1),[s])])\n",
+       "Sol 89: sub(cst(2),[sub(cst(1),[s]),cst(1)])\n",
+       "Sol 90: sub(cst(2),[sub(cst(1),[s]),cst(0)])\n",
+       "Sol 91: sub(cst(2),[sub(cst(1),[s]),id(1)])\n",
+       "Sol 92: sub(cst(2),[sub(cst(1),[s]),s])\n",
+       "Sol 93: sub(cst(2),[sub(cst(0),[])])\n",
+       "Sol 94: sub(cst(2),[sub(cst(0),[]),cst(1)])\n",
+       "Sol 95: sub(cst(2),[sub(cst(0),[]),cst(0)])\n",
+       "Sol 96: sub(cst(2),[sub(cst(0),[]),id(1)])\n",
+       "Sol 97: sub(cst(2),[sub(cst(0),[]),s])\n",
+       "Sol 98: sub(cst(2),[sub(cst(0),[cst(1)])])\n",
+       "Sol 99: sub(cst(2),[sub(cst(0),[cst(1)]),cst(1)])\n",
+       "Sol 100: sub(cst(2),[sub(cst(0),[cst(1)]),cst(0)])\n",
+       "Sol 101: sub(cst(2),[sub(cst(0),[cst(1)]),id(1)])\n",
+       "Sol 102: sub(cst(2),[sub(cst(0),[cst(1)]),s])\n",
+       "Sol 103: sub(cst(2),[sub(cst(0),[cst(0)])])\n",
+       "Sol 104: sub(cst(2),[sub(cst(0),[cst(0)]),cst(1)])\n",
+       "Sol 105: sub(cst(2),[sub(cst(0),[cst(0)]),cst(0)])\n",
+       "Sol 106: sub(cst(2),[sub(cst(0),[cst(0)]),id(1)])\n",
+       "Sol 107: sub(cst(2),[sub(cst(0),[cst(0)]),s])\n",
+       "Sol 108: sub(cst(2),[sub(cst(0),[id(1)])])\n",
+       "Sol 109: sub(cst(2),[sub(cst(0),[id(1)]),cst(1)])\n",
+       "Sol 110: sub(cst(2),[sub(cst(0),[id(1)]),cst(0)])\n",
+       "Sol 111: sub(cst(2),[sub(cst(0),[id(1)]),id(1)])\n",
+       "Sol 112: sub(cst(2),[sub(cst(0),[id(1)]),s])\n",
+       "Sol 113: sub(cst(2),[sub(cst(0),[s])])\n",
+       "Sol 114: sub(cst(2),[sub(cst(0),[s]),cst(1)])\n",
+       "Sol 115: sub(cst(2),[sub(cst(0),[s]),cst(0)])\n",
+       "Sol 116: sub(cst(2),[sub(cst(0),[s]),id(1)])\n",
+       "Sol 117: sub(cst(2),[sub(cst(0),[s]),s])\n",
+       "Sol 118: sub(cst(2),[sub(id(1),[cst(1)])])\n",
+       "Sol 119: sub(cst(2),[sub(id(1),[cst(1)]),cst(1)])\n",
+       "Sol 120: sub(cst(2),[sub(id(1),[cst(1)]),cst(0)])\n",
+       "Sol 121: sub(cst(2),[sub(id(1),[cst(1)]),id(1)])\n",
+       "Sol 122: sub(cst(2),[sub(id(1),[cst(1)]),s])\n",
+       "Sol 123: sub(cst(2),[sub(id(1),[cst(0)])])\n",
+       "Sol 124: sub(cst(2),[sub(id(1),[cst(0)]),cst(1)])\n",
+       "Sol 125: sub(cst(2),[sub(id(1),[cst(0)]),cst(0)])\n",
+       "Sol 126: sub(cst(2),[sub(id(1),[cst(0)]),id(1)])\n",
+       "Sol 127: sub(cst(2),[sub(id(1),[cst(0)]),s])\n",
+       "Sol 128: sub(cst(2),[sub(id(1),[id(1)])])\n",
+       "Sol 129: sub(cst(2),[sub(id(1),[id(1)]),cst(1)])\n",
+       "Sol 130: sub(cst(2),[sub(id(1),[id(1)]),cst(0)])\n",
+       "Sol 131: sub(cst(2),[sub(id(1),[id(1)]),id(1)])\n",
+       "Sol 132: sub(cst(2),[sub(id(1),[id(1)]),s])\n",
+       "Sol 133: sub(cst(2),[sub(id(1),[s])])\n",
+       "Sol 134: sub(cst(2),[sub(id(1),[s]),cst(1)])\n",
+       "Sol 135: sub(cst(2),[sub(id(1),[s]),cst(0)])\n",
+       "Sol 136: sub(cst(2),[sub(id(1),[s]),id(1)])\n",
+       "Sol 137: sub(cst(2),[sub(id(1),[s]),s])\n",
+       "Sol 138: sub(cst(2),[sub(s,[cst(1)])])\n",
+       "Sol 139: sub(cst(2),[sub(s,[cst(1)]),cst(1)])\n",
+       "Sol 140: sub(cst(2),[sub(s,[cst(1)]),cst(0)])\n",
+       "Sol 141: sub(cst(2),[sub(s,[cst(1)]),id(1)])\n",
+       "Sol 142: sub(cst(2),[sub(s,[cst(1)]),s])\n",
+       "Sol 143: sub(cst(2),[sub(s,[cst(0)])])\n",
+       "Sol 144: sub(cst(2),[sub(s,[cst(0)]),cst(1)])\n",
+       "Sol 145: sub(cst(2),[sub(s,[cst(0)]),cst(0)])\n",
+       "Sol 146: sub(cst(2),[sub(s,[cst(0)]),id(1)])\n",
+       "Sol 147: sub(cst(2),[sub(s,[cst(0)]),s])\n",
+       "Sol 148: sub(cst(2),[sub(s,[id(1)])])\n",
+       "Sol 149: sub(cst(2),[sub(s,[id(1)]),cst(1)])\n",
+       "Sol 150: sub(cst(2),[sub(s,[id(1)]),cst(0)])\n",
+       "Sol 151: sub(cst(2),[sub(s,[id(1)]),id(1)])\n",
+       "Sol 152: sub(cst(2),[sub(s,[id(1)]),s])\n",
+       "Sol 153: sub(cst(2),[sub(s,[s])])\n",
+       "Sol 154: sub(cst(2),[sub(s,[s]),cst(1)])\n",
+       "Sol 155: sub(cst(2),[sub(s,[s]),cst(0)])\n",
+       "Sol 156: sub(cst(2),[sub(s,[s]),id(1)])\n",
+       "Sol 157: sub(cst(2),[sub(s,[s]),s])\n",
+       "Sol 158: sub(cst(2),[pr(cst(1),cst(1))])\n",
+       "Sol 159: sub(cst(2),[pr(cst(1),cst(1)),cst(1)])\n",
+       "Sol 160: sub(cst(2),[pr(cst(1),cst(1)),cst(0)])\n",
+       "Sol 161: sub(cst(2),[pr(cst(1),cst(1)),id(1)])\n",
+       "Sol 162: sub(cst(2),[pr(cst(1),cst(1)),s])\n",
+       "Sol 163: sub(cst(2),[pr(cst(1),cst(0))])\n",
+       "Sol 164: sub(cst(2),[pr(cst(1),cst(0)),cst(1)])\n",
+       "Sol 165: sub(cst(2),[pr(cst(1),cst(0)),cst(0)])\n",
+       "Sol 166: sub(cst(2),[pr(cst(1),cst(0)),id(1)])\n",
+       "Sol 167: sub(cst(2),[pr(cst(1),cst(0)),s])\n",
+       "Sol 168: sub(cst(2),[pr(cst(1),id(1))])\n",
+       "Sol 169: sub(cst(2),[pr(cst(1),id(1)),cst(1)])\n",
+       "Sol 170: sub(cst(2),[pr(cst(1),id(1)),cst(0)])\n",
+       "Sol 171: sub(cst(2),[pr(cst(1),id(1)),id(1)])\n",
+       "Sol 172: sub(cst(2),[pr(cst(1),id(1)),s])\n",
+       "Sol 173: sub(cst(2),[pr(cst(0),cst(1))])\n",
+       "Sol 174: sub(cst(2),[pr(cst(0),cst(1)),cst(1)])\n",
+       "Sol 175: sub(cst(2),[pr(cst(0),cst(1)),cst(0)])\n",
+       "Sol 176: sub(cst(2),[pr(cst(0),cst(1)),id(1)])\n",
+       "Sol 177: sub(cst(2),[pr(cst(0),cst(1)),s])\n",
+       "Sol 178: sub(cst(2),[pr(cst(0),cst(0))])\n",
+       "Sol 179: sub(cst(2),[pr(cst(0),cst(0)),cst(1)])\n",
+       "Sol 180: sub(cst(2),[pr(cst(0),cst(0)),cst(0)])\n",
+       "Sol 181: sub(cst(2),[pr(cst(0),cst(0)),id(1)])\n",
+       "Sol 182: sub(cst(2),[pr(cst(0),cst(0)),s])\n",
+       "Sol 183: sub(cst(2),[pr(cst(0),id(1))])\n",
+       "Sol 184: sub(cst(2),[pr(cst(0),id(1)),cst(1)])\n",
+       "Sol 185: sub(cst(2),[pr(cst(0),id(1)),cst(0)])\n",
+       "Sol 186: sub(cst(2),[pr(cst(0),id(1)),id(1)])\n",
+       "Sol 187: sub(cst(2),[pr(cst(0),id(1)),s])\n",
+       "Sol 188: sub(cst(1),[])\n",
+       "Sol 189: sub(cst(1),[cst(2)])\n",
+       "Sol 190: sub(cst(1),[cst(2),cst(1)])\n",
+       "Sol 191: sub(cst(1),[cst(2),cst(0)])\n",
+       "Sol 192: sub(cst(1),[cst(2),id(1)])\n",
+       "Sol 193: sub(cst(1),[cst(2),s])\n",
+       "Sol 194: sub(cst(1),[cst(1)])\n",
+       "Sol 195: sub(cst(1),[cst(1),cst(1)])\n",
+       "Sol 196: sub(cst(1),[cst(1),cst(0)])\n",
+       "Sol 197: sub(cst(1),[cst(1),id(1)])\n",
+       "Sol 198: sub(cst(1),[cst(1),s])\n",
+       "Sol 199: sub(cst(1),[cst(0)])\n",
+       "Sol 200: sub(cst(1),[cst(0),cst(1)])"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mFunction = sub(cst(1),[cst(0),cst(1)])"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    " ?- set_limit(200),gen_valid_pr_fun(Function),print_sol(Function)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 109,
+   "id": "4d80d79e",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "\n",
+    ":- dynamic goedel_counter/1.\n",
+    "goedel_counter(0).\n",
+    "reset_gc :- retractall(goedel_counter(_)),\n",
+    "            assert(goedel_counter(0)).\n",
+    "get_next_gc(Nr) :- retract(goedel_counter(N)), N1 is N+1,\n",
+    "                   assert(goedel_counter(N1)),\n",
+    "                   Nr=N1."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 110,
+   "id": "dba239a4",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "\n",
+    "% Die universelle Funktion:\n",
+    "\n",
+    "upr(I,X,Res) :- number(I),\n",
+    "          reset_gc,\n",
+    "          gen_valid_pr_fun(Function),\n",
+    "          get_next_gc(I),\n",
+    "          format('Running program ~w on input ~w.~nProgram = ~w~n',[I,X,Function]),\n",
+    "          (run_pr(Function,[X],Res) -> format('Result: ~w~n',[Res])\n",
+    "           ; print('Program fails (undefined value)'),nl).\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 111,
+   "id": "d13019d5",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Running program 1 on input 2.\n",
+       "Program = cst(0)\n",
+       "Computing cst(0) with [2]\n",
+       "Result: 0"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 0"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- upr(1,2,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 112,
+   "id": "2406f7bc",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Running program 10 on input 2.\n",
+       "Program = id(1)\n",
+       "Computing id(1) with [2]\n",
+       "Result: 2"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 2"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- upr(10,2,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 113,
+   "id": "3ffd9e1e",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Running program 10 on input 10.\n",
+       "Program = id(1)\n",
+       "Computing id(1) with [10]\n",
+       "Result: 10"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mRes = 10"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- upr(10,10,Res)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 114,
+   "id": "3042f06f",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "% Die Funktion aus dem Skript:\n",
+    "f(I,Res) :- upr(I,I,R1), Res is R1+1."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 115,
+   "id": "e23973dc",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Running program 10 on input 10.\n",
+       "Program = id(1)\n",
+       "Computing id(1) with [10]\n",
+       "Result: 10"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "text/plain": [
+       "\u001b[1mR = 11"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "?- f(10,R)."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "0ed724d0",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Prolog",
+   "language": "prolog",
+   "name": "prolog_kernel"
+  },
+  "language_info": {
+   "codemirror_mode": "prolog",
+   "file_extension": ".pl",
+   "mimetype": "text/x-prolog",
+   "name": "Prolog"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}