X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=an_faculteit.tex;h=59fd9214cb5cbdf928d1e196b7c3f06e8e834726;hb=d5eb78db13b8b04fdf0a3edf3e636dd9006948af;hp=9f11a5376b18938bad4fa9032dea9f7c785b9478;hpb=ace36a84d561e370c5f8f7f6542daa555440531b;p=sec1415.git diff --git a/an_faculteit.tex b/an_faculteit.tex index 9f11a53..59fd921 100644 --- a/an_faculteit.tex +++ b/an_faculteit.tex @@ -14,7 +14,7 @@ do ( In \textit{Piet} ziet dit er als volgt uit... \begin{lstlisting}[title=Faculteit in \textit{Piet'}] -push 5 // x:=5 +push 10 // x:=5 push 1 // y:=1 MARKERING A: @@ -86,3 +86,46 @@ push 1 roll // nu gaat het programma weer via een wit pad naar markering A \end{lstlisting} + +Wat in piet er uit zit als in \ref{fig:img3} +\begin{figure}[H] + \caption{Factulteit vanuit \textit{While} naar \textit{Piet}} + \label{fig:img3} + \centering + \fbox{\includegraphics[natheight=320px, natwidth=256px, height=320px, + width=256px]{img3.png}} +\end{figure} + +\begin{landscape} +De afleidingsrij voor 1! ziet er als volgt uit:\\ +$ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup;roll;push \: 1;push \: 2;push \: 1;push \: 1, [\:], [\:], [\:]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup;roll;push \: 1;push \: 2;push \: 1, [\:], [\:], [1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup;roll;push \: 1;push \: 2, [\:], [\:], [1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup;roll;push \: 1, [\:], [\:], [2,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup;roll, [\:], [\:], [1,2,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3;dup, [\:], [\:], [1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1;push \: 3, [\:], [\:], [1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll;push \: 1, [\:], [\:], [3,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1;roll, [\:], [\:], [1,3,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;push \: 1, [\:], [\:], [1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not;subtract;, [\:], [\:], [1,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1;not, [\:], [\:], [1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1;push \: 1, [\:], [\:], [1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract;push\:1, [\:], [\:], [1,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater;subtract, [\:], [\:], [1,1,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not;greater, [\:], [\:], [0,1,1,1]\rangle \Rightarrow\\ +\langle pointer; not, [\:], [\:], [1,1,1]\rangle \Rightarrow\\ +\langle pointer [\:], [\:], [0,1,1]\rangle \Rightarrow\\ +\langle [\:], [\:], [1,1]\rangle\\ +\\ +$ +Eerst worden x en y op de stack gestopt zodat de stack [y,x] = [1,1]. +Deze stack is gelijk aan de stack in de termineerende configuratie: 1 = 1! dus y = x!. +Als bewijs dat de wiskundige operaties op de stack goed zijn uitgevoerd staat in +de appendix onder het kopje voorbeelden een stukje code. In het programma +eenfaculteit worden alle wiskundige operaties die bij de commando's horen +achter elkaar uitgevoerd op de stack, waarbij het resultaat [1,1] is.\\ +Bij de voorbeelden staan ook nog de programma's tweefaculteit en +vijffaculteit die respectievelijk 2! en 5! uitrekenen. +\end{landscape} \ No newline at end of file