[FMFP] Notes

This commit is contained in:
2026-07-27 17:11:14 +02:00
parent be2e079959
commit 3fe6b41d8b
3 changed files with 10 additions and 2 deletions
@@ -15,6 +15,8 @@ For all functions with recursion, don't forget the base cases. In addition, for
there is no equal sign before the pipe characters. there is no equal sign before the pipe characters.
For the cases notation, there are equal signs. We can use underscores as a ``don't care'' character. For the cases notation, there are equal signs. We can use underscores as a ``don't care'' character.
Always consider making use of functions defined in previous subtasks. This can save a lot of time.
\subparagraph{Lists} \subparagraph{Lists}
In list comprehensions, to draw from a list, \texttt{<-} is used, to delimit the description of the list contents from the generator part, we use a pipe character In list comprehensions, to draw from a list, \texttt{<-} is used, to delimit the description of the list contents from the generator part, we use a pipe character
and to separate each statement in the generator part, we use a comma. and to separate each statement in the generator part, we use a comma.
@@ -49,6 +51,8 @@ Ideally, we first write the function, then infer its type.
Remember that in the definition of these two functions, the \texttt{-> b ->} (and \texttt{-> a ->}, respectively) denote the type of the base case. Remember that in the definition of these two functions, the \texttt{-> b ->} (and \texttt{-> a ->}, respectively) denote the type of the base case.
For more elaborate data structures, the functions for each subtype should be in the same order as in the data type definition, for canonical definition of the fold function. For more elaborate data structures, the functions for each subtype should be in the same order as in the data type definition, for canonical definition of the fold function.
Note that these functions' type doesn't contain the data structure typically, but simply, e.g. for \texttt{Mlist a = Bot | Node [a] (Mlist a)},
the type of the canonical fold function is simply \texttt{b -> ([a] -> a -> b) -> Mlist a -> b} and not \texttt{(Mlist b) -> ([a] -> Mlist a -> Mlist b) -> (Mlist a) -> (Mlist b)}.
\subparagraph{zipWith} \subparagraph{zipWith}
@@ -69,4 +73,6 @@ Remember:
\item in the end state that since it holds for all $n$, it, in particular, holds for $n = 0$ (or equivalent) \item in the end state that since it holds for all $n$, it, in particular, holds for $n = 0$ (or equivalent)
\end{itemize} \end{itemize}
For generalizing, a very helpful tactic is to think about the statement some, come up with the generalization you think is correct, then doing the base case in the proof For generalizing, a very helpful tactic is to think about the statement some, come up with the generalization you think is correct, then doing the base case in the proof
after only a very short amount of time, as the correct generalized statement will become apparent there very quickly after only a very short amount of time, as the correct generalized statement will become apparent there very quickly.
Remember to always check that parenthesis are set correctly and to only apply one rule exactly once.
@@ -7,7 +7,9 @@ Contrary to those however, we have pre- and postconditions, which we typically n
This typically involves finding a loop invariant that holds before and after each iteration of the loop. This typically involves finding a loop invariant that holds before and after each iteration of the loop.
This invariant should mention every variable used in the loop. This invariant should mention every variable used in the loop.
Any other variable should also be mentioned in it. The loop \textit{variant} may also be added for proving termination. Any other variable should also be mentioned in it. The loop \textit{variant} may also be added for proving termination.
A typical for-loop loop variant would be \texttt{n - x = Z}, as the next value of the loop variant has to be lower than the previous one. A typical for-loop loop variant would be \texttt{n - x = Z}, or the same for a while loop like \texttt{while i < n do s end},
as the next value of the loop variant has to be lower than the previous one.
The preconditions and postconditions in the loops then reflect that the update to the loop variant variable(s) leads to them being smaller than $Z$, The preconditions and postconditions in the loops then reflect that the update to the loop variant variable(s) leads to them being smaller than $Z$,
which allows proving that the loop variant is decreasing, signifying that the loop terminates \textit{eventually}. which allows proving that the loop variant is decreasing, signifying that the loop terminates \textit{eventually}.
Of course, if \texttt{x} is decreasing, it itself can become the variant, as it fulfils the condition. Of course, if \texttt{x} is decreasing, it itself can become the variant, as it fulfils the condition.