\subsection{Faculteit} Als we de analyse op een compleet programma toepassen komt er een \textit{Piet} programma uit dat behoorlijk fors is maar netjes zijn werk doet. Dit programma berekent de faculteit van $x$ en stopt dat uiteindelijk in $y$. \begin{lstlisting}[title=Faculteit in \textit{While}] x:=5; y:=1; while $\neg$(x=1) do ( y:=y*x; x:=x-1 ) \end{lstlisting} In \textit{Piet} ziet dit er als volgt uit... \begin{lstlisting}[title=Faculteit in \textit{Piet'}] push 5 // x:=5 push 1 // y:=1 MARKERING A: // Un(2) // $\neg$(x=1) $\equiv$ \neg(x-1)>0) // x-1 // Un(2) push 2 // push 1 // roll // dup // push 3 // push 1 // roll // push 1 // sub // not // $\neg(x-1)$ push 1 // zet $0$ op de stack push 1 sub gre // $\neg(x-1)>0$ oftewel x=1 pointer // als x=0 dan draait de DP niet en gaat het programma naar pad B // als x$\neq$ dan draait de DP en gaat het programma naar pad A PAD A: skip // een oneindig aantal witte blokken, y is nu x! // evt een outchar om $y$ naar standardout te printen PAD B: // y:=y*x // Bin(1, 2) dup // Un(1) push 3 // Un(2+1) push 2 // roll // dup // push 4 // push 1 // roll // mul // x*y push 2 // Ass(1) push 1 roll pop // x:=x-1 push 2 // Un(2) push 1 roll dup push 3 push 1 roll push 1 // sub // x-1 push 3 // Ass(2) push 2 roll pop push 2 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}