Fix a lot of things following from Jan's comments.
[matthijs/master-project/report.git] / Chapters / Normalization.tex
index db743fc9a049d716c931747ca7cb09180723980a..f11788f4348fff5082a7a79bc5290057489b50d1 100644 (file)
   The first step in the core to \small{VHDL} translation process, is normalization. We
   aim to bring the core description into a simpler form, which we can
   subsequently translate into \small{VHDL} easily. This normal form is needed because
-  the full core language is more expressive than \small{VHDL} in some areas and because
-  core can describe expressions that do not have a direct hardware
-  interpretation.
-
-  \todo{Describe core properties not supported in \VHDL, and describe how the
-  \VHDL we want to generate should look like.}
+  the full core language is more expressive than \small{VHDL} in some
+  areas (higher order expressions, limited polymorphism using type
+  classes, etc.) and because core can describe expressions that do not
+  have a direct hardware interpretation.
 
   \section{Normal form}
-    \todo{Refresh or refer to distinct hardware per application principle}
     The transformations described here have a well-defined goal: To bring the
-    program in a well-defined form that is directly translatable to hardware,
-    while fully preserving the semantics of the program. We refer to this form as
-    the \emph{normal form} of the program. The formal definition of this normal
-    form is quite simple:
+    program in a well-defined form that is directly translatable to
+    \VHDL, while fully preserving the semantics of the program. We refer
+    to this form as the \emph{normal form} of the program. The formal
+    definition of this normal form is quite simple:
 
-    \placedefinition{}{A program is in \emph{normal form} if none of the
-    transformations from this chapter apply.}
+    \placedefinition{}{\startboxed A program is in \emph{normal form} if none of the
+    transformations from this chapter apply.\stopboxed}
 
     Of course, this is an \quote{easy} definition of the normal form, since our
     program will end up in normal form automatically. The more interesting part is
       can't generate any signals that can have multiple types. All types must be
       completely known to generate hardware.
       
-      \item Any \emph{higher order} constructions must be removed. We can't
+      \item All \emph{higher order} constructions must be removed. We can't
       generate a hardware signal that contains a function, so all values,
-      arguments and returns values used must be first order.
+      arguments and return values used must be first order.
 
-      \item Any complex \emph{nested scopes} must be removed. In the \small{VHDL}
+      \item All complex \emph{nested scopes} must be removed. In the \small{VHDL}
       description, every signal is in a single scope. Also, full expressions are
       not supported everywhere (in particular port maps can only map signal
       names and constants, not complete expressions). To make the \small{VHDL}
 
     A very simple example of a program in normal form is given in
     \in{example}[ex:MulSum]. As you can see, all arguments to the function (which
-    will become input ports in the final hardware) are at the outer level.
+    will become input ports in the generated \VHDL) are at the outer level.
     This means that the body of the inner lambda abstraction is never a
     function, but always a plain value.
 
     As the body of the inner lambda abstraction, we see a single (recursive)
     let expression, that binds two variables (\lam{mul} and \lam{sum}). These
-    variables will be signals in the final hardware, bound to the output port
+    variables will be signals in the generated \VHDL, bound to the output port
     of the \lam{*} and \lam{+} components.
 
     The final line (the \quote{return value} of the function) selects the
       newCircle.a(btex $a$ etex) "framed(false)";
       newCircle.b(btex $b$ etex) "framed(false)";
       newCircle.c(btex $c$ etex) "framed(false)";
-      newCircle.sum(btex $res$ etex) "framed(false)";
+      newCircle.sum(btex $sum$ etex) "framed(false)";
 
       % Components
       newCircle.mul(btex * etex);
         {\boxedgraphic{MulSum}}{The architecture described by the normal form.}
       \stopcombination
 
-    The previous example described composing an architecture by calling other
-    functions (operators), resulting in a simple architecture with components and
-    connections. There is of course also some mechanism for choice in the normal
-    form. In a normal Core program, the \emph{case} expression can be used in a
-    few different ways to describe choice. In normal form, this is limited to a
-    very specific form.
+    \in{Example}[ex:MulSum] showed a function that just applied two
+    other functions (multiplication and addition), resulting in a simple
+    architecture with two components and some connections.  There is of
+    course also some mechanism for choice in the normal form. In a
+    normal Core program, the \emph{case} expression can be used in a few
+    different ways to describe choice. In normal form, this is limited
+    to a very specific form.
 
     \in{Example}[ex:AddSubAlu] shows an example describing a
     simple \small{ALU}, which chooses between two operations based on an opcode
     expression scrutinizes the variable \lam{opcode} (and scrutinizing more
     complex expressions is not supported). The case expression can select a
     different variable based on the constructor of \lam{opcode}.
+    \refdef{case expression}
 
     \startbuffer[AddSubAlu]
     alu :: Bit -> Word -> Word -> Word
         {\boxedgraphic{AddSubAlu}}{The architecture described by the normal form.}
       \stopcombination
 
-    As a more complete example, consider \in{example}[ex:NormalComplete]. This
-    example contains everything that is supported in normal form, with the
-    exception of builtin higher order functions. The graphical version of the
-    architecture contains a slightly simplified version, since the state tuple
-    packing and unpacking have been left out. Instead, two seperate registers are
-    drawn. Also note that most synthesis tools will further optimize this
-    architecture by removing the multiplexers at the register input and
-    instead put some gates in front of the register's clock input, but we want
-    to show the architecture as close to the description as possible.
+    As a more complete example, consider
+    \in{example}[ex:NormalComplete]. This example shows everything that
+    is allowed in normal form, except for builtin higher order functions
+    (like \lam{map}). The graphical version of the architecture contains
+    a slightly simplified version, since the state tuple packing and
+    unpacking have been left out. Instead, two separate registers are
+    drawn. Also note that most synthesis tools will further optimize
+    this architecture by removing the multiplexers at the register input
+    and instead put some gates in front of the register's clock input,
+    but we want to show the architecture as close to the description as
+    possible.
 
     As you can see from the previous examples, the generation of the final
     architecture from the normal form is straightforward. In each of the
     \subsection[sec:normalization:intendednormalform]{Intended normal form definition}
       Now we have some intuition for the normal form, we can describe how we want
       the normal form to look like in a slightly more formal manner. The following
-      EBNF-like description completely captures the intended structure (and
-      generates a subset of GHC's core format).
-
-      Some clauses have an expression listed in parentheses. These are conditions
-      that need to apply to the clause.
+      EBNF-like description captures most of the intended structure (and
+      generates a subset of GHC's core format). 
+      
+      There are two things missing: Cast expressions are sometimes
+      allowed by the prototype, but not specified here and the below
+      definition allows uses of state that cannot be translated to \VHDL
+      properly. These two problems are discussed in
+      \in{section}[sec:normalization:castproblems] and
+      \in{section}[sec:normalization:stateproblems] respectively.
+
+      Some clauses have an expression listed behind them in parentheses.
+      These are conditions that need to apply to the clause. The
+      predicates used there (\lam{lvar()}, \lam{representable()},
+      \lam{gvar()}) will be defined in
+      \in{section}[sec:normalization:predicates].
+
+      An expression is in normal form if it matches the first
+      definition, \emph{normal}.
 
-      \defref{intended normal form definition}
       \todo{Fix indentation}
-      \startlambda
-      \italic{normal} = \italic{lambda}
-      \italic{lambda} = λvar.\italic{lambda} (representable(var))
+      \startbuffer[IntendedNormal]
+      \italic{normal} := \italic{lambda}
+      \italic{lambda} := λvar.\italic{lambda}                        (representable(var))
                       | \italic{toplet} 
-      \italic{toplet} = letrec [\italic{binding}...] in var (representable(var))
-      \italic{binding} = var = \italic{rhs} (representable(rhs))
+      \italic{toplet} := letrec [\italic{binding}...] in var         (representable(var))
+      \italic{binding} := var = \italic{rhs}                         (representable(rhs))
                        -- State packing and unpacking by coercion
-                       | var0 = var1 ▶ State ty (lvar(var1))
-                       | var0 = var1 ▶ ty (var1 :: State ty) (lvar(var1))
-      \italic{rhs} = userapp
-                   | builtinapp
+                       | var0 = var1 ▶ State ty                      (lvar(var1))
+                       | var0 = var1 ▶ ty                            (var1 :: State ty ∧ lvar(var1))
+      \italic{rhs} := \italic{userapp}
+                   | \italic{builtinapp}
                    -- Extractor case
-                   | case var of C a0 ... an -> ai (lvar(var))
+                   | case var of C a0 ... an -> ai                   (lvar(var))
                    -- Selector case
-                   | case var of (lvar(var))
-                      DEFAULT -> var0 (lvar(var0))
-                      C w0 ... wn -> resvar (\forall{}i, wi \neq resvar, lvar(resvar))
-      \italic{userapp} = \italic{userfunc}
+                   | case var of                                     (lvar(var))
+                      [ DEFAULT -> var ]                             (lvar(var))
+                      C0 w0,0 ... w0,n -> var0
+                      \vdots
+                      Cm wm,0 ... wm,n -> varm                       (\forall{}i \forall{}j, wi,j \neq vari, lvar(vari))
+      \italic{userapp} := \italic{userfunc}
                        | \italic{userapp} {userarg}
-      \italic{userfunc} = var (gvar(var))
-      \italic{userarg} = var (lvar(var))
-      \italic{builtinapp} = \italic{builtinfunc}
+      \italic{userfunc} := var                                       (gvar(var))
+      \italic{userarg} := var                                        (lvar(var))
+      \italic{builtinapp} := \italic{builtinfunc}
                           | \italic{builtinapp} \italic{builtinarg}
-      \italic{builtinfunc} = var (bvar(var))
-      \italic{builtinarg} = \italic{coreexpr}
-      \stoplambda
-
-      \todo{Limit builtinarg further}
-
-      \todo{There can still be other casts around (which the code can handle,
-      e.g., ignore), which still need to be documented here}
-
-      \todo{Note about the selector case. It just supports Bit and Bool
-      currently, perhaps it should be generalized in the normal form? This is
-      no longer true, btw}
-
-      When looking at such a program from a hardware perspective, the top level
-      lambda's define the input ports. The variable reference in the body of
-      the recursive let expression is the output port. Most function
-      applications bound by the let expression define a component
-      instantiation, where the input and output ports are mapped to local
-      signals or arguments. Some of the others use a builtin construction (\eg
-      the \lam{case} expression) or call a builtin function (\eg \lam{+} or
-      \lam{map}). For these, a hardcoded \small{VHDL} translation is
-      available.
+      \italic{builtinfunc} := var                                    (bvar(var))
+      \italic{builtinarg} := var                                     (representable(var) ∧ lvar(var))
+                          | \italic{partapp}                         (partapp :: a -> b)
+                          | \italic{coreexpr}                        (¬representable(coreexpr) ∧ ¬(coreexpr :: a -> b))
+      \italic{partapp} := \italic{userapp} 
+                       | \italic{builtinapp}
+      \stopbuffer
+
+      \placedefinition[][def:IntendedNormal]{Definition of the intended nnormal form using an \small{EBNF}-like syntax.}
+          {\defref{intended normal form definition}
+           \typebufferlam{IntendedNormal}}
+
+      When looking at such a program from a hardware perspective, the
+      top level lambda abstractions define the input ports. Lambda
+      abstractions cannot appear anywhere else. The variable reference
+      in the body of the recursive let expression is the output port.
+      Most function applications bound by the let expression define a
+      component instantiation, where the input and output ports are
+      mapped to local signals or arguments. Some of the others use a
+      builtin construction (\eg the \lam{case} expression) or call a
+      builtin function (\eg \lam{+} or \lam{map}). For these, a
+      hardcoded \small{VHDL} translation is available.
 
   \section[sec:normalization:transformation]{Transformation notation}
     To be able to concisely present transformations, we use a specific format
 
     This format desribes a transformation that applies to \lam{<original
     expresssion>} and transforms it into \lam{<transformed expression>}, assuming
-    that all conditions apply. In this format, there are a number of placeholders
+    that all conditions are satisfied. In this format, there are a number of placeholders
     in pointy brackets, most of which should be rather obvious in their meaning.
     Nevertheless, we will more precisely specify their meaning below:
 
       transformation applies, commonly to prevent a transformation from
       causing a loop with itself or another transformation.
 
-      Only if these conditions are \emph{all} true, the transformation
+      Only if these conditions are \emph{all} satisfied, the transformation
       applies.
       \stopdesc
 
       \startdesc{<transformed expression>}
       This is the expression template that is the result of the transformation. If, looking
       at the above three items, the transformation applies, the \lam{<original
-      expression>} is completely replaced with the \lam{<transformed expression>}.
+      expression>} is completely replaced by the \lam{<transformed expression>}.
       We call this a template, because it can contain placeholders, referring to
       any placeholder bound by the \lam{<original expression>} or the
       \lam{<context conditions>}. The resulting expression will have those
       \stopdesc
 
       \startdesc{<context additions>}
-      These are templates for new functions to add to the context. This is a way
-      to have a transformation create new top level functions.
+      These are templates for new functions to be added to the context.
+      This is a way to let a transformation create new top level
+      functions.
 
       Each addition has the form \lam{binder = template}. As above, any
       placeholder in the addition is replaced with the value bound to it, and any
       replaced with) a fresh binder.
       \stopdesc
 
-    As an example, we'll look at η-abstraction:
+    To understand this notation better, the step by step application of
+    the η-abstraction transformation to a simple \small{ALU} will be
+    shown. Consider η-abstraction, described using above notation as
+    follows:
 
     \starttrans
     E                 \lam{E :: a -> b}
     transformation does not apply infinitely (which are not necessarily part
     of the conventional definition of η-abstraction).
 
-    Consider the following function, which is a fairly obvious way to specify a
-    simple ALU (Note that \in{example}[ex:AddSubAlu] shows the normal form of this
-    function). The parentheses around the \lam{+} and \lam{-} operators are
-    commonly used in Haskell to show that the operators are used as normal
-    functions, instead of \emph{infix} operators (\eg, the operators appear
-    before their arguments, instead of in between).
+    Consider the following function, in Core notation, which is a fairly obvious way to specify a
+    simple \small{ALU} (Note that it is not yet in normal form, but
+    \in{example}[ex:AddSubAlu] shows the normal form of this function).
+    The parentheses around the \lam{+} and \lam{-} operators are
+    commonly used in Haskell to show that the operators are used as
+    normal functions, instead of \emph{infix} operators (\eg, the
+    operators appear before their arguments, instead of in between).
 
     \startlambda 
     alu :: Bit -> Word -> Word -> Word
     \stoplambda
     
     Here, the transformation does apply, binding \lam{E} to the entire
-    expression and \lam{x} to the fresh binder \lam{b}, resulting in the
-    replacement:
+    expression (which has type \lam{Word -> Word}) and binding \lam{x}
+    to the fresh binder \lam{b}, resulting in the replacement:
 
     \startlambda
     λb.(case opcode of
       High -> (-)) a b
     \stoplambda
 
-    Again, the transformation does not apply to this lambda abstraction, so we
-    look at its body. For brevity, we'll put the case statement on one line from
+    The transformation does not apply to this lambda abstraction, so we
+    look at its body. For brevity, we'll put the case expression on one line from
     now on.
 
     \startlambda
 
       In particular, we define no particular order of transformations. Since
       transformation order should not influence the resulting normal form,
-      \todo{This is not really true, but would like it to be...} this leaves
-      the implementation free to choose any application order that results in
-      an efficient implementation.
+      this leaves the implementation free to choose any application order that
+      results in an efficient implementation. Unfortunately this is not
+      entirely true for the current set of transformations. See
+      \in{section}[sec:normalization:non-determinism] for a discussion of this
+      problem.
 
       When applying a single transformation, we try to apply it to every (sub)expression
       in a function, not just the top level function body. This allows us to
       keep the transformation descriptions concise and powerful.
 
     \subsection{Definitions}
-      In the following sections, we will be using a number of functions and
-      notations, which we will define here.
-
-      \todo{Define substitution (notation)}
-
-      \subsubsection{Concepts}
-        A \emph{global variable} is any variable (binder) that is bound at the
-        top level of a program, or an external module. A \emph{local variable} is any
-        other variable (\eg, variables local to a function, which can be bound by
-        lambda abstractions, let expressions and pattern matches of case
-        alternatives).  Note that this is a slightly different notion of global versus
-        local than what \small{GHC} uses internally.
-        \defref{global variable} \defref{local variable}
-
-        A \emph{hardware representable} (or just \emph{representable}) type or value
-        is (a value of) a type that we can generate a signal for in hardware. For
-        example, a bit, a vector of bits, a 32 bit unsigned word, etc. Values that are
-        not runtime representable notably include (but are not limited to): Types,
-        dictionaries, functions.
-        \defref{representable}
-
-        A \emph{builtin function} is a function supplied by the Cλash framework, whose
-        implementation is not valid Cλash. The implementation is of course valid
-        Haskell, for simulation, but it is not expressable in Cλash.
-        \defref{builtin function} \defref{user-defined function}
+      A \emph{global variable} is any variable (binder) that is bound at the
+      top level of a program, or an external module. A \emph{local variable} is any
+      other variable (\eg, variables local to a function, which can be bound by
+      lambda abstractions, let expressions and pattern matches of case
+      alternatives). This is a slightly different notion of global versus
+      local than what \small{GHC} uses internally, but for our purposes
+      the distinction \GHC makes is not useful.
+      \defref{global variable} \defref{local variable}
+
+      A \emph{hardware representable} (or just \emph{representable}) type or value
+      is (a value of) a type that we can generate a signal for in hardware. For
+      example, a bit, a vector of bits, a 32 bit unsigned word, etc. Values that are
+      not runtime representable notably include (but are not limited to): Types,
+      dictionaries, functions.
+      \defref{representable}
+
+      A \emph{builtin function} is a function supplied by the Cλash framework, whose
+      implementation is not valid Cλash. The implementation is of course valid
+      Haskell, for simulation, but it is not expressable in Cλash.
+      \defref{builtin function} \defref{user-defined function}
 
       For these functions, Cλash has a \emph{builtin hardware translation}, so calls
       to these functions can still be translated. These are functions like
       A \emph{user-defined} function is a function for which we do have a Cλash
       implementation available.
 
-      \subsubsection{Predicates}
+      \subsubsection[sec:normalization:predicates]{Predicates}
         Here, we define a number of predicates that can be used below to concisely
-        specify conditions.\refdef{global variable}
+        specify conditions.
 
         \emph{gvar(expr)} is true when \emph{expr} is a variable that references a
         global variable. It is false when it references a local variable.
 
-        \refdef{local variable}\emph{lvar(expr)} is the complement of \emph{gvar}; it is true when \emph{expr}
+        \emph{lvar(expr)} is the complement of \emph{gvar}; it is true when \emph{expr}
         references a local variable, false when it references a global variable.
 
-        \refdef{representable}\emph{representable(expr)} or \emph{representable(var)} is true when
-        \emph{expr} or \emph{var} is \emph{representable}.
+        \emph{representable(expr)} is true when \emph{expr} is \emph{representable}.
 
     \subsection[sec:normalization:uniq]{Binder uniqueness}
       A common problem in transformation systems, is binder uniqueness. When not
       \stoplambda
 
       This is obviously not what was supposed to happen! The root of this problem is
-      the reuse of binders: Identical binders can be bound in different scopes, such
-      that only the inner one is \quote{visible} in the inner expression. In the example
-      above, the \lam{c} binder was bound outside of the expression and in the inner
-      lambda expression. Inside that lambda expression, only the inner \lam{c} is
-      visible.
+      the reuse of binders: Identical binders can be bound in different,
+      but overlapping scopes. Any variable reference in those
+      overlapping scopes then refers to the variable bound in the inner
+      (smallest) scope. There is not way to refer to the variable in the
+      outer scope. This effect is usually referred to as
+      \emph{shadowing}: When a binder is bound in a scope where the
+      binder already had a value, the inner binding is said to
+      \emph{shadow} the outer binding. In the example above, the \lam{c}
+      binder was bound outside of the expression and in the inner lambda
+      expression. Inside that lambda expression, only the inner \lam{c}
+      can be accessed.
 
       There are a number of ways to solve this. \small{GHC} has isolated this
       problem to their binder substitution code, which performs \emph{deshadowing}
        optimizations, but they are required to get our program into intended
        normal form.
 
+        \placeintermezzo{}{
+          \defref{substitution notation}
+          \startframedtext[width=8cm,background=box,frame=no]
+          \startalignment[center]
+            {\tfa Substitution notation}
+          \stopalignment
+          \blank[medium]
+
+          In some of the transformations in this chapter, we need to perform
+          substitution on an expression. Substitution means replacing every
+          occurence of some expression (usually a variable reference) with
+          another expression.
+
+          There have been a lot of different notations used in literature for
+          specifying substitution. The notation that will be used in this report
+          is the following:
+
+          \startlambda
+            E[A=>B]
+          \stoplambda
+
+          This means expression \lam{E} with all occurences of \lam{A} replaced
+          with \lam{B}.
+          \stopframedtext
+        }
+
       \subsubsection[sec:normalization:beta]{β-reduction}
-        \defref{beta-reduction}
         β-reduction is a well known transformation from lambda calculus, where it is
         the main reduction step. It reduces applications of lambda abstractions,
         removing both the lambda abstraction and the application.
         This transformation is not needed to get an expression into intended
         normal form (since these bindings are part of the intended normal
         form), but makes the resulting \small{VHDL} a lot shorter.
-        
+       
+        \refdef{substitution notation}
         \starttrans
         letrec
           a0 = E0
         This transformation removes let bindings that are never used.
         Occasionally, \GHC's desugarer introduces some unused let bindings.
 
-        This normalization pass should really be unneeded to get into intended normal form
-        (since unused bindings are not forbidden by the normal form), but in practice
-        the desugarer or simplifier emits some unused bindings that cannot be
-        normalized (e.g., calls to a \type{PatError}\todo{Check this name}). Also,
-        this transformation makes the resulting \small{VHDL} a lot shorter.
+        This normalization pass should really be not be necessary to get
+        into intended normal form (since the intended normal form
+        definition \refdef{intended normal form definition} does not
+        require that every binding is used), but in practice the
+        desugarer or simplifier emits some bindings that cannot be
+        normalized (e.g., calls to a
+        \hs{Control.Exception.Base.patError}) but are not used anywhere
+        either. To prevent the \VHDL generation from breaking on these
+        artifacts, this transformation removes them.
 
         \todo{Don't use old-style numerals in transformations}
         \starttrans
         \todo{Example}
 
       \subsubsection{Cast propagation / simplification}
-        This transform pushes casts down into the expression as far as possible.
-        Since its exact role and need is not clear yet, this transformation is
-        not yet specified.
+        This transform pushes casts down into the expression as far as
+        possible. This transformation has been added to make a few
+        specific corner cases work, but it is not clear yet if this
+        transformation handles cast expressions completely or in the
+        right way. See \in{section}[sec:normalization:castproblems].
 
-        \todo{Cast propagation}
+        \starttrans
+        (let binds in E) ▶ T
+        -------------------------
+        let binds in (E ▶ T)
+        \stoptrans
+
+        \starttrans
+        (case S of
+          p0 -> E0
+          \vdots
+          pn -> En
+        ) ▶ T
+        -------------------------
+        case S of
+          p0 -> E0 ▶ T
+          \vdots
+          pn -> En ▶ T
+        \stoptrans
 
       \subsubsection{Top level binding inlining}
+        \refdef{top level binding}
         This transform takes simple top level bindings generated by the
         \small{GHC} compiler. \small{GHC} sometimes generates very simple
         \quote{wrapper} bindings, which are bound to just a variable
-        reference, or a partial application to constants or other variable
-        references.
+        reference, or contain just a (partial) function appliation with
+        the type and dictionary arguments filled in (such as the
+        \lam{(+)} in the example below).
 
         Note that this transformation is completely optional. It is not
         required to get any function into intended normal form, but it does help making
         the resulting VHDL output easier to read (since it removes a bunch of
         components that are really boring).
 
-        This transform takes any top level binding generated by the compiler,
+        This transform takes any top level binding generated by \GHC,
         whose normalized form contains only a single let binding.
 
         \starttrans
 
         \starttrans
         E                 \lam{E :: a -> b}
-        --------------    \lam{E} is not the first argument of an application.
+        --------------    \lam{E} does not occur on a function position in an application
         λx.E x            \lam{E} is not a lambda abstraction.
-                          \lam{x} is a variable that does not occur free in \lam{E}.
         \stoptrans
 
         \startbuffer[from]
 
         \starttrans
         (case x of
-          p1 -> E1
+          p0 -> E0
           \vdots
           pn -> En) M
         -----------------
         case x of
-          p1 -> E1 M
+          p0 -> E0 M
           \vdots
           pn -> En M
         \stoptrans
 
         \transexample{apppropcase}{Application propagation for a case expression}{from}{to}
 
-      \subsubsection{Let recursification}
+      \subsubsection[sec:normalization:letrecurse]{Let recursification}
         This transformation makes all non-recursive lets recursive. In the
         end, we want a single recursive let in our normalized program, so all
         non-recursive lets can be converted. This also makes other
         This transformation ensures that the return value of a function is always a
         simple local variable reference.
 
-        Currently implemented using lambda simplification, let simplification, and
-        top simplification. Should change into something like the following, which
-        works only on the result of a function instead of any subexpression. This is
-        achieved by the contexts, like \lam{x = E}, though this is strictly not
-        correct (you could read this as "if there is any function \lam{x} that binds
-        \lam{E}, any \lam{E} can be transformed, while we only mean the \lam{E} that
-        is bound by \lam{x}. This might need some extra notes or something).
-
-        Note that the return value is not simplified if its not representable.
-        Otherwise, this would cause a direct loop with the inlining of
-        unrepresentable bindings. If the return value is not
-        representable because it has a function type, η-abstraction should
-        make sure that this transformation will eventually apply. If the value
-        is not representable for other reasons, the function result itself is
-        not representable, meaning this function is not translatable anyway.
+        This transformation only applies to the entire body of a
+        function instead of any subexpression in a function. This is
+        achieved by the contexts, like \lam{x = E}, though this is
+        strictly not correct (you could read this as "if there is any
+        function \lam{x} that binds \lam{E}, any \lam{E} can be
+        transformed, while we only mean the \lam{E} that is bound by
+        \lam{x}).
+
+        Note that the return value is not simplified if its not
+        representable.  Otherwise, this would cause a direct loop with
+        the inlining of unrepresentable bindings. If the return value is
+        not representable because it has a function type, η-abstraction
+        should make sure that this transformation will eventually apply.
+        If the value is not representable for other reasons, the
+        function result itself is not representable, meaning this
+        function is not translatable anyway.
 
         \starttrans
         x = E                            \lam{E} is representable
         
         \todo{More examples}
 
-    \subsection{Argument simplification}
-      The transforms in this section deal with simplifying application
-      arguments into normal form. The goal here is to:
-
-      \todo{This section should only talk about representable arguments. Non
-      representable arguments are treated by specialization.}
-
-      \startitemize
-       \item Make all arguments of user-defined functions (\eg, of which
-       we have a function body) simple variable references of a runtime
-       representable type. This is needed, since these applications will be turned
-       into component instantiations.
-       \item Make all arguments of builtin functions one of:
-         \startitemize
-          \item A type argument.
-          \item A dictionary argument.
-          \item A type level expression.
-          \item A variable reference of a runtime representable type.
-          \item A variable reference or partial application of a function type.
-         \stopitemize
-      \stopitemize
-
-      When looking at the arguments of a user-defined function, we can
-      divide them into two categories:
-      \startitemize
-        \item Arguments of a runtime representable type (\eg bits or vectors).
-
-              These arguments can be preserved in the program, since they can
-              be translated to input ports later on.  However, since we can
-              only connect signals to input ports, these arguments must be
-              reduced to simple variables (for which signals will be
-              produced). This is taken care of by the argument extraction
-              transform.
-        \item Non-runtime representable typed arguments. \todo{Move this
-        bullet to specialization}
-              
-              These arguments cannot be preserved in the program, since we
-              cannot represent them as input or output ports in the resulting
-              \small{VHDL}. To remove them, we create a specialized version of the
-              called function with these arguments filled in. This is done by
-              the argument propagation transform.
-
-              Typically, these arguments are type and dictionary arguments that are
-              used to make functions polymorphic. By propagating these arguments, we
-              are essentially doing the same which GHC does when it specializes
-              functions: Creating multiple variants of the same function, one for
-              each type for which it is used. Other common non-representable
-              arguments are functions, e.g. when calling a higher order function
-              with another function or a lambda abstraction as an argument.
-
-              The reason for doing this is similar to the reasoning provided for
-              the inlining of non-representable let bindings above. In fact, this
-              argument propagation could be viewed as a form of cross-function
-              inlining.
-      \stopitemize
-
-      \todo{Move this itemization into a new section about builtin functions}
-      When looking at the arguments of a builtin function, we can divide them
-      into categories: 
-
-      \startitemize
-        \item Arguments of a runtime representable type.
-              
-              As we have seen with user-defined functions, these arguments can
-              always be reduced to a simple variable reference, by the
-              argument extraction transform. Performing this transform for
-              builtin functions as well, means that the translation of builtin
-              functions can be limited to signal references, instead of
-              needing to support all possible expressions.
-
-        \item Arguments of a function type.
-              
-              These arguments are functions passed to higher order builtins,
-              like \lam{map} and \lam{foldl}. Since implementing these
-              functions for arbitrary function-typed expressions (\eg, lambda
-              expressions) is rather comlex, we reduce these arguments to
-              (partial applications of) global functions.
-              
-              We can still support arbitrary expressions from the user code,
-              by creating a new global function containing that expression.
-              This way, we can simply replace the argument with a reference to
-              that new function. However, since the expression can contain any
-              number of free variables we also have to include partial
-              applications in our normal form.
-
-              This category of arguments is handled by the function extraction
-              transform.
-        \item Other unrepresentable arguments.
-              
-              These arguments can take a few different forms:
-              \startdesc{Type arguments}
-                In the core language, type arguments can only take a single
-                form: A type wrapped in the Type constructor. Also, there is
-                nothing that can be done with type expressions, except for
-                applying functions to them, so we can simply leave type
-                arguments as they are.
-              \stopdesc
-              \startdesc{Dictionary arguments}
-                In the core language, dictionary arguments are used to find
-                operations operating on one of the type arguments (mostly for
-                finding class methods). Since we will not actually evaluatie
-                the function body for builtin functions and can generate
-                code for builtin functions by just looking at the type
-                arguments, these arguments can be ignored and left as they
-                are.
-              \stopdesc
-              \startdesc{Type level arguments}
-                Sometimes, we want to pass a value to a builtin function, but
-                we need to know the value at compile time. Additionally, the
-                value has an impact on the type of the function. This is
-                encoded using type-level values, where the actual value of the
-                argument is not important, but the type encodes some integer,
-                for example. Since the value is not important, the actual form
-                of the expression does not matter either and we can leave
-                these arguments as they are.
-              \stopdesc
-              \startdesc{Other arguments}
-                Technically, there is still a wide array of arguments that can
-                be passed, but does not fall into any of the above categories.
-                However, none of the supported builtin functions requires such
-                an argument. This leaves use with passing unsupported types to
-                a function, such as calling \lam{head} on a list of functions.
-
-                In these cases, it would be impossible to generate hardware
-                for such a function call anyway, so we can ignore these
-                arguments.
-
-                The only way to generate hardware for builtin functions with
-                arguments like these, is to expand the function call into an
-                equivalent core expression (\eg, expand map into a series of
-                function applications). But for now, we choose to simply not
-                support expressions like these.
-              \stopdesc
-
-              From the above, we can conclude that we can simply ignore these
-              other unrepresentable arguments and focus on the first two
-              categories instead.
+    \subsection[sec:normalization:argsimpl]{Representable arguments simplification}
+      This section contains just a single transformation that deals with
+      representable arguments in applications. Non-representable arguments are
+      handled by the transformations in
+      \in{section}[sec:normalization:nonrep]. 
+      
+      This transformation ensures that all representable arguments will become
+      references to local variables. This ensures they will become references
+      to local signals in the resulting \small{VHDL}, which is required due to
+      limitations in the component instantiation code in \VHDL (one can only
+      assign a signal or constant to an input port). By ensuring that all
+      arguments are always simple variable references, we always have a signal
+      available to map to the input ports.
+
+      To reduce a complex expression to a simple variable reference, we create
+      a new let expression around the application, which binds the complex
+      expression to a new variable. The original function is then applied to
+      this variable.
+
+      \refdef{global variable}
+      Note that references to \emph{global variables} (like a top level
+      function without arguments, but also an argumentless dataconstructors
+      like \lam{True}) are also simplified. Only local variables generate
+      signals in the resulting architecture. Even though argumentless
+      dataconstructors generate constants in generated \VHDL code and could be
+      mapped to an input port directly, they are still simplified to make the
+      normal form more regular.
+
+      \refdef{representable}
+      \starttrans
+      M N
+      --------------------    \lam{N} is representable
+      letrec x = N in M x     \lam{N} is not a local variable reference
+      \stoptrans
+      \refdef{local variable}
+
+      \startbuffer[from]
+      add (add a 1) 1
+      \stopbuffer
+
+      \startbuffer[to]
+      letrec x = add a 1 in add x 1
+      \stopbuffer
+
+      \transexample{argsimpl}{Argument simplification}{from}{to}
+
+    \subsection[sec:normalization:builtins]{Builtin functions}
+      This section deals with (arguments to) builtin functions.  In the
+      intended normal form definition\refdef{intended normal form definition}
+      we can see that there are three sorts of arguments a builtin function
+      can receive.
+      
+      \startitemize[KR]
+        \item A representable local variable reference. This is the most
+        common argument to any function. The argument simplification
+        transformation described in \in{section}[sec:normalization:argsimpl]
+        makes sure that \emph{any} representable argument to \emph{any}
+        function (including builtin functions) is turned into a local variable
+        reference.
+        \item (A partial application of) a top level function (either builtin on
+        user-defined). The function extraction transformation described in
+        this section takes care of turning every functiontyped argument into
+        (a partial application of) a top level function.
+        \item Any expression that is not representable and does not have a
+        function type. Since these can be any expression, there is no
+        transformation needed. Note that this category is exactly all
+        expressions that are not transformed by the transformations for the
+        previous two categories. This means that \emph{any} core expression
+        that is used as an argument to a builtin function will be either
+        transformed into one of the above categories, or end up in this
+        categorie. In any case, the result is in normal form.
       \stopitemize
 
-      \subsubsection[sec:normalization:argsimpl]{Argument simplification}
-        This transform deals with arguments to functions that
-        are of a runtime representable type. It ensures that they will all become
-        references to global variables, or local signals in the resulting
-        \small{VHDL}, which is required due to limitations in the component
-        instantiation code in \VHDL (one can only assign a signal or constant
-        to an input port). By ensuring that all arguments are always simple
-        variable references, we always have a signal available to assign to
-        input ports.
-
-        \todo{Say something about dataconstructors (without arguments, like True
-        or False), which are variable references of a runtime representable
-        type, but do not result in a signal.}
-
-        To reduce a complex expression to a simple variable reference, we create
-        a new let expression around the application, which binds the complex
-        expression to a new variable. The original function is then applied to
-        this variable.
-
-        Note that a reference to a \emph{global variable} (like a top level
-        function without arguments, but also an argumentless dataconstructors
-        like \lam{True}) is also simplified. Only local variables generate
-        signals in the resulting architecture. 
-
-        \refdef{representable}
-        \starttrans
-        M N
-        --------------------    \lam{N} is representable
-        letrec x = N in M x     \lam{N} is not a local variable reference
-        \stoptrans
-        \refdef{local variable}
-
-        \startbuffer[from]
-        add (add a 1) 1
-        \stopbuffer
+      As noted, the argument simplification will handle any representable
+      arguments to a builtin function. The following transformation is needed
+      to handle non-representable arguments with a function type, all other
+      non-representable arguments don't need any special handling.
 
-        \startbuffer[to]
-        letrec x = add a 1 in add x 1
-        \stopbuffer
-
-        \transexample{argextract}{Argument extraction}{from}{to}
-      
       \subsubsection[sec:normalization:funextract]{Function extraction}
-        \todo{Move to section about builtin functions}
         This transform deals with function-typed arguments to builtin
-        functions.  Since builtin functions cannot be specialized to remove
-        the arguments, we choose to extract these arguments into a new global
-        function instead. This greatly simplifies the translation rules needed
-        for builtin functions. \todo{Should we talk about these? Reference
-        Christiaan?}
+        functions. 
+        Since builtin functions cannot be specialized (see
+        \in{section}[sec:normalization:specialize]) to remove the arguments,
+        these arguments are extracted into a new global function instead. In
+        other words, we create a new top level function that has exactly the
+        extracted argument as its body. This greatly simplifies the
+        translation rules needed for builtin functions, since they only need
+        to handle (partial applications of) top level functions.
 
         Any free variables occuring in the extracted arguments will become
         parameters to the new global function. The original argument is replaced
         x = λf0 ... λfn.N
         \stoptrans
 
-        \todo{Split this example}
         \startbuffer[from]
-        map (λa . add a b) xs
-
-        map (add b) ys
+        addList = λb.λxs.map (λa . add a b) xs
         \stopbuffer
 
         \startbuffer[to]
-        map (x0 b) xs
-
-        map x1 ys
+        addList = λb.λxs.map (f b) xs
         ~
-        x0 = λb.λa.add a b
-        x1 = λb.add b
+        f = λb.λa.add a b
         \stopbuffer
 
         \transexample{funextract}{Function extraction}{from}{to}
 
-        Note that \lam{x0} and {x1} will still need normalization after this.
-
-      \todo{Fill the gap left by moving argument propagation away}
+        Note that the function \lam{f} will still need normalization after
+        this.
 
     \subsection{Case normalisation}
       \subsubsection{Scrutinee simplification}
           alts
         -----------------        \lam{E} is not a local variable reference
         letrec x = E in 
-          case E of
+          case x of
             alts
         \stoptrans
 
             False -> b
         \stopbuffer
 
-        \transexample{letflat}{Let flattening}{from}{to}
+        \transexample{letflat}{Case normalisation}{from}{to}
 
 
-      \subsubsection{Case simplification}
-        This transformation ensures that all case expressions become normal form. This
-        means they will become one of:
+      \subsubsection{Case normalization}
+        This transformation ensures that all case expressions get a form
+        that is allowed by the intended normal form. This means they
+        will become one of: \refdef{intended normal form definition}
         \startitemize
-        \item An extractor case with a single alternative that picks a single field
+        \item An extractor case with a single alternative that picks a field
         from a datatype, \eg \lam{case x of (a, b) -> a}.
         \item A selector case with multiple alternatives and only wild binders, that
         makes a choice between expressions based on the constructor of another
         expression, \eg \lam{case x of Low -> a; High -> b}.
         \stopitemize
+
+        For an arbitrary case, that has \lam{n} alternatives, with
+        \lam{m} binders in each alternatives, this will result in \lam{m
+        * n} extractor case expression to get at each variable, \lam{n}
+        let bindings for each of the alternatives' value and a single
+        selector case to select the right value out of these.
+
+        Technically, the defintion of this transformation would require
+        that the constructor for every alternative has exactly the same
+        amount (\lam{m}) of arguments, but of course this transformation
+        also applies when this is not the case.
         
-        \defref{wild binder}
         \starttrans
         case E of
           C0 v0,0 ... v0,m -> E0
           \vdots
           Cn vn,0 ... vn,m -> En
         --------------------------------------------------- \forall i \forall j, 0 ≤ i ≤ n, 0 ≤ i < m (\lam{wi,j} is a wild (unused) binder)
-        letrec
-          v0,0 = case E of C0 v0,0 .. v0,m -> v0,0
+        letrec                                              The case expression is not an extractor case
+          v0,0 = case E of C0 x0,0 .. x0,m -> x0,0          The case expression is not a selector case
           \vdots
-          v0,m = case E of C0 v0,0 .. v0,m -> v0,m
+          v0,m = case E of C0 x0,0 .. x0,m -> x0,m
           \vdots
-          vn,m = case E of Cn vn,0 .. vn,m -> vn,m
-          x0 = E0
+          vn,m = case E of Cn xn,0 .. xn,m -> xn,m
+          y0 = E0
           \vdots
-          xn = En
+          yn = En
         in
           case E of
-            C0 w0,0 ... w0,m -> x0
+            C0 w0,0 ... w0,m -> y0
             \vdots
-            Cn wn,0 ... wn,m -> xn
+            Cn wn,0 ... wn,m -> yn
         \stoptrans
-        \todo{Check the subscripts of this transformation}
-
-        Note that this transformation applies to case statements with any
-        scrutinee. If the scrutinee is a complex expression, this might result
-        in duplicate hardware. An extra condition to only apply this
-        transformation when the scrutinee is already simple (effectively
-        causing this transformation to be only applied after the scrutinee
-        simplification transformation) might be in order. 
 
-        \fxnote{This transformation specified like this is complicated and misses
-        conditions to prevent looping with itself. Perhaps it should be split here for
-        discussion?}
+        \refdef{wild binder}
+        Note that this transformation applies to case expressions with any
+        scrutinee. If the scrutinee is a complex expression, this might
+        result in duplication of work (hardware). An extra condition to
+        only apply this transformation when the scrutinee is already
+        simple (effectively causing this transformation to be only
+        applied after the scrutinee simplification transformation) might
+        be in order. 
 
         \startbuffer[from]
         case a of
         \stopbuffer
 
         \startbuffer[to]
-        letnonrec
+        letrec
           x0 = add b 1
           x1 = add b 2
         in
         \in{section}[sec:transformation:caseremoval].
 
       \subsubsection[sec:transformation:caseremoval]{Case removal}
-        This transform removes any case statements with a single alternative and
-        only wild binders.
+        This transform removes any case expression with a single alternative and
+        only wild binders.\refdef{wild binder}
 
-        These "useless" case statements are usually leftovers from case simplification
+        These "useless" case expressions are usually leftovers from case simplification
         on extractor case (see the previous example).
 
         \starttrans
 
         \transexample{caserem}{Case removal}{from}{to}
 
-    \subsection{Removing unrepresentable values}
+    \subsection[sec:normalization:nonrep]{Removing unrepresentable values}
       The transformations in this section are aimed at making all the
       values used in our expression representable. There are two main
       transformations that are applied to \emph{all} unrepresentable let
-      bindings and function arguments, but these are really meant to
-      address three different kinds of unrepresentable values:
-      Polymorphic values, higher order values and literals. Each of these
-      will be detailed below, followed by the actual transformations.
+      bindings and function arguments. These are meant to address three
+      different kinds of unrepresentable values: Polymorphic values, higher
+      order values and literals. The transformation are described generically:
+      They apply to all non-representable values. However, non-representable
+      values that don't fall into one of these three categories will be moved
+      around by these transformations but are unlikely to completely
+      disappear. They usually mean the program was not valid in the first
+      place, because unsupported types were used (for example, a program using
+      strings).
+     
+      Each of these three categories will be detailed below, followed by the
+      actual transformations.
 
       \subsubsection{Removing Polymorphism}
         As noted in \in{section}[sec:prototype:polymporphism],
         
         This propagation makes higher order values become applied (in
         particular both of the alternatives of the case now have a
-        representable type. Completely applied top level functions (like the
+        representable type). Completely applied top level functions (like the
         first alternative) are now no longer invalid (they fall under
         \in{item}[item:completeapp] above). (Completely) applied lambda
         abstractions can be removed by β-abstraction. For our example,
         solves (part of) the polymorphism, higher order values and
         unrepresentable literals in an expression.
 
+        \refdef{substitution notation}
         \starttrans
         letrec 
           a0 = E0
 
         \transexample{nonrepinline}{Nonrepresentable binding inlining}{from}{to}
 
-      \subsubsection{Function specialization}
+      \subsubsection[sec:normalization:specialize]{Function specialization}
         This transform removes arguments to user-defined functions that are
         not representable at runtime. This is done by creating a
         \emph{specialized} version of the function that only works for one
         ~
         x Y0 ... Yi ... Yn                               \lam{Yi} is not representable
         ---------------------------------------------    \lam{Yi} is not a local variable reference
-        x' y0 ... yi-1 f0 ...  fm Yi+1 ... Yn            \lam{f0 ... fm} are all free local vars of \lam{Yi}
+        x' Y0 ... Yi-1 f0 ...  fm Yi+1 ... Yn            \lam{f0 ... fm} are all free local vars of \lam{Yi}
         ~                                                \lam{T0 ... Tn} are the types of \lam{Y0 ... Yn}
-        x' = λ(y0 :: T0) ... λ(yi-1 :: Ty-1). λf0 ... λfm. λ(yi+1 :: Ty+1) ...  λ(yn :: Tn).       
-              E y0 ... yi-1 Yi yi+1 ... yn   
+        x' = λ(y0 :: T0) ... λ(yi-1 :: Ty-1). 
+             λf0 ... λfm.
+             λ(yi+1 :: Ty+1) ...  λ(yn :: Tn).       
+               E y0 ... yi-1 Yi yi+1 ... yn   
         \stoptrans
 
         This is a bit of a complex transformation. It transforms an
         from the types of the \emph{actual} arguments (\lam{T0 ... Tn}). This
         means that any polymorphism in the arguments is removed, even when the
         corresponding explicit type lambda is not removed
-        yet.\refdef{type lambda}
+        yet.
 
         \todo{Examples. Perhaps reference the previous sections}
 
-
   \section{Unsolved problems}
     The above system of transformations has been implemented in the prototype
     and seems to work well to compile simple and more complex examples of
         let y = (a * b) in y + y
         \stoplambda
 
-      \subsection{Non-determinism}
+      \subsection[sec:normalization:non-determinism]{Non-determinism}
         As an example, again consider the following expression:
 
         \startlambda
         transformation system as well. However, it is likely that there are
         other occurences of this problem.
 
-      \subsection{Casts}
+      \subsection[sec:normalization:castproblems]{Casts}
         We do not fully understand the use of cast expressions in Core, so
         there are probably expressions involving cast expressions that cannot
         be brought into intended normal form by this transformation system.
         transformations will probably need updating to handle them in all
         cases.
 
+      \subsection[sec:normalization:stateproblems]{Normalization of stateful descriptions}
+        Currently, the intended normal form definition\refdef{intended
+        normal form definition} offers enough freedom to describe all
+        valid stateful descriptions, but is not limiting enough. It is
+        possible to write descriptions which are in intended normal
+        form, but cannot be translated into \VHDL in a meaningful way
+        (\eg, a function that swaps two substates in its result, or a
+        function that changes a substate itself instead of passing it to
+        a subfunction).
+
+        It is now up to the programmer to not do anything funny with
+        these state values, whereas the normalization just tries not to
+        mess up the flow of state values. In practice, there are
+        situations where a Core program that \emph{could} be a valid
+        stateful description is not translateable by the prototype. This
+        most often happens when statefulness is mixed with pattern
+        matching, causing a state input to be unpacked multiple times or
+        be unpacked and repacked only in some of the code paths.
+
+        Without going into detail about the exact problems (of which
+        there are probably more than have shown up so far), it seems
+        unlikely that these problems can be solved entirely by just
+        improving the \VHDL state generation in the final stage. The
+        normalization stage seems the best place to apply the rewriting
+        needed to support more complex stateful descriptions. This does
+        of course mean that the intended normal form definition must be
+        extended as well to be more specific about how state handling
+        should look like in normal form.
+        \in{Section}[sec:prototype:statelimits] already contains a
+        tight description of the limitations on the use of state
+        variables, which could be adapted into the intended normal form.
+
   \section[sec:normalization:properties]{Provable properties}
     When looking at the system of transformations outlined above, there are a
     number of questions that we can ask ourselves. The main question is of course:
     possible proof strategies are shown below.
 
     \subsection{Graph representation}
-      Before looking into how to prove these properties, we'll look at our
-      transformation system from a graph perspective. The nodes of the graph are
-      all possible Core expressions. The (directed) edges of the graph are
-      transformations. When a transformation α applies to an expression \lam{A} to
-      produce an expression \lam{B}, we add an edge from the node for \lam{A} to the
-      node for \lam{B}, labeled α.
+      Before looking into how to prove these properties, we'll look at
+      transformation systems from a graph perspective. We will first define
+      the graph view and then illustrate it using a simple example from lambda
+      calculus (which is a different system than the Cλash normalization
+      system). The nodes of the graph are all possible Core expressions. The
+      (directed) edges of the graph are transformations. When a transformation
+      α applies to an expression \lam{A} to produce an expression \lam{B}, we
+      add an edge from the node for \lam{A} to the node for \lam{B}, labeled
+      α.
 
       \startuseMPgraphic{TransformGraph}
         save a, b, c, d;
       system with β and η reduction (solid lines) and expansion (dotted lines).}
           \boxedgraphic{TransformGraph}
 
-      Of course our graph is unbounded, since we can construct an infinite amount of
-      Core expressions. Also, there might potentially be multiple edges between two
-      given nodes (with different labels), though seems unlikely to actually happen
-      in our system.
+      Of course the graph for Cλash is unbounded, since we can construct an
+      infinite amount of Core expressions. Also, there might potentially be
+      multiple edges between two given nodes (with different labels), though
+      seems unlikely to actually happen in our system.
 
       See \in{example}[ex:TransformGraph] for the graph representation of a very
       simple lambda calculus that contains just the expressions \lam{(λx.λy. (+) x
       \todo{Define β-reduction and η-reduction?}
 
       Note that the normal form of such a system consists of the set of nodes
-      (expressions) without outgoing edges, since those are the expression to which
+      (expressions) without outgoing edges, since those are the expressions to which
       no transformation applies anymore. We call this set of nodes the \emph{normal
       set}. The set of nodes containing expressions in intended normal
       form \refdef{intended normal form} is called the \emph{intended
       Also, since there is only one node in the normal set, it must obviously be
       \emph{deterministic} as well.
 
-    \todo{Add content to these sections}
     \subsection{Termination}
       In general, proving termination of an arbitrary program is a very
       hard problem. \todo{Ref about arbitrary termination} Fortunately,