[FMFP] Restructure summary

This commit is contained in:
2026-07-06 09:49:27 +02:00
parent 67500a14cb
commit 294363f3c8
66 changed files with 127 additions and 101 deletions
@@ -0,0 +1,41 @@
\subsection{Formal proofs}
Given a language like $\cL = \{ \oplus, \otimes, +, \times \}$, and derivation rules
\begin{multicols}{2}
\begin{itemize}
\item $\alpha$: If $+$, then $\otimes$
\item $\beta$: If $+$, then $\times$
\item $\gamma$: If $\otimes$ and $\times$, then $\oplus$
\item $\delta$: $+$ holds
\end{itemize}
or displayed using graphical notation:
\begin{align*}
\frac{+}{\otimes} \; \alpha
\qquad \frac{+}{\times} \; \beta \\
\frac{\otimes \quad \times}{\oplus} \; \gamma
\qquad \frac{}{+} \; \delta
\end{align*}
\end{multicols}
Rules like $\delta$ above are also commonly referred to as an \textit{axiom}.
To prove $\oplus$ in this language, we can either write the following or draw a derivation tree:
\begin{multicols}{2}
\begin{itemize}
\item $+$ holds by $\delta$
\item $\otimes$ holds by $\alpha$ with 1.
\item $\times$ holds by $\beta$ with 1.
\item $\oplus$ holds by $\gamma$ with 2 and 3
\end{itemize}
Or as derivation tree
\[
\begin{prooftree}
% Left branch
\infer0[$\delta$]{+}
\infer1[$\alpha$]{\otimes}
% Right branch
\infer0[$\delta$]{+}
\infer1[$\beta$]{\times}
\infer2[$\gamma$]{ \oplus }
\end{prooftree}
\]
\end{multicols}
@@ -0,0 +1,8 @@
\subsection{Natural deduction}
The rules from above here are used to construct derivations under assumptions, e.g.
$A_1, \ldots, A_n \vdash A$, which is read as ``$A$ follows from $A_1, \ldots, A_n$''.
The derivations are always represented as derivation trees and a \bi{proof} is a derivation whose root has no assumptions.
Since we have to prove a statement, we have to draw the derivation trees from the bottom up, with the goal of reaching an axiom or a rule that is an assumption
using the other rules of the rule set.
@@ -0,0 +1,12 @@
\subsection{Propositional logic}
\subsubsection{Syntax}
\inlinedefinition For a set of variables $\cV$, the \bi{language of propositional logic} $\cL_P$ is the smallest set where
\begin{multicols}{2}
\begin{itemize}
\item $X \in \cL_P$ if $X \in \cV$
\item $\bot \in \cL_P$
\item $A \land B \in \cL_P$ if $A \in \cL_P$ and $B \in \cL_P$
\item $A \lor B \in \cL_P$ if $A \in \cL_P$ and $B \in \cL_P$
\item $A \rightarrow B \in \cL_P$ if $A \in \cL_P$ and $B \in \cL_P$
\end{itemize}
\end{multicols}
@@ -0,0 +1,19 @@
\subsubsection{Semantics}
\inlinedefinition[Valuation] $\sigma : \cV \rightarrow \{ \texttt{True}, \texttt{False} \}$ maps variables to truth values.
They are the simple models (i.e. \textit{interpretations}). \bi{Valuations} is the set of valuations.
\inlinedefinition[Satisfiability] smallest relation $\models \; \subseteq$ \textit{Valuations} $\times \cL_P$ such that
\begin{multicols}{2}
\begin{itemize}
\item $\sigma \models X$ if $\sigma(X) = \texttt{True}$
\item $\sigma \models A \land B$ if $\sigma \models A$ and $\sigma \models B$
\item $\sigma \models A \lor B$ if $\sigma \models A$ or $\sigma \models B$
\item $\sigma \models A \rightarrow B$ if whenever $\sigma \models A$ then $\sigma \models B$
\end{itemize}
\end{multicols}
\inlinedefinition[satisfiable formula] A formula $A \in \cL_P$ is \bi{satisfiable} if $\sigma \models A$ for \textbf{some} valuation $\sigma$
\inlinedefinition[tautology, valid formula] A formula $A \in \cL_P$ is \bi{valid} (a \bi{tautology}) if $\sigma \models A$ for \textbf{all} valuations $\sigma$
\inlinedefinition[Semantic entailment] $A_1, \ldots , A_n \models A$ if $\forall \sigma$ we have $\sigma \models A_1, \ldots, \sigma \models A_n$, then $\sigma \models A$
@@ -0,0 +1,10 @@
\newpage
\subsubsection{Requirements for a deductive system}
The derivation rules (syntactic entailment) and truth tables (semantic entailment) should agree.
For that we have two requirements, for $\Gamma = A_1, \ldots, A_n$ a collection of formulas:
\begin{itemize}
\item \bi{Soundness:} If $\Gamma \vdash A$ can be derived, then $\Gamma \models A$
\item \bi{Completeness:} If $\Gamma \models A$, then $\Gamma \vdash A$ can be derived
\end{itemize}
\bi{Decidability} is also desirable, i.e. having checks of the attributes be of low complexity.
@@ -0,0 +1,19 @@
\subsubsection{Natural deduction for propositional formulas}
\inlinedefinition[Sequent] Is an assertion of form $A_1, \ldots, A_n \vdash A$, with $A, A_1, \ldots, A_n$ being propositional formulas.
\inlineintuition $A$ follows from the $A_i$ and if the system is sound, the $A_i$ semantically entail $A$.
\inlinedefinition[Axiom] is the starting point (usually the leaves) of the derivation trees and are usually of the form
\[
\begin{prooftree}
\infer0[axiom]{\ldots, A, \ldots \vdash A}
\end{prooftree}
\]
i.e. when coming up with a derivation tree for a \bi{proof}, we want to reach a leaf where $A$ is contained in $\Gamma$.
\inlinedefinition[Proof] of $A$ is a derivation tree with \texttt{root} $\vdash A$. If a deductive system is \textit{sound}, then $A$ is a tautology.
There are two kinds of rules, \bi{introduce} and \bi{eliminate} connectives. If you are confused about the order when applying them when coming up with a deduction tree,
they are oriented top-down, so e.g. the introduction rule is inverted when coming up with the deduction tree.
If all rules are sound (i.e. they preserve semantic entailment), then the logic is sound.
@@ -0,0 +1,77 @@
\subsubsection{Derivation rules for propositional logic}
Remember that $E$ means \textit{elimination} and $I$ means \textit{introduction}, with $L$ and $R$ being the side (so $ER$ means elimination on the right)
\paragraph{Conjunction}
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash A}
\hypo{\Gamma \vdash B}
\infer2[$\land$-I]{\Gamma \vdash A \land B}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash A \land B}
\infer1[$\land$-EL]{\Gamma \vdash A}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash A \land B}
\infer1[$\land$-ER]{\Gamma \vdash B}
\end{prooftree}
\end{align*}
\paragraph{Disjunction}
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash A}
\infer1[$\lor$-IL]{\Gamma \vdash A \lor B}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash B}
\infer1[$\lor$-IR]{\Gamma \vdash A \lor B}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash A \lor B}
\hypo{\Gamma, A \vdash C}
\hypo{\Gamma, B \vdash C}
\infer3[$\lor$-E]{\Gamma \vdash C}
\end{prooftree}
\end{align*}
\paragraph{Implication}
\begin{align*}
\begin{prooftree}
\hypo{\Gamma, A \vdash B}
\infer1[$\rightarrow$-I]{\Gamma \vdash A \rightarrow B}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash A \rightarrow B}
\hypo{\Gamma \vdash A}
\infer2[$\rightarrow$-E]{\Gamma \vdash B}
\end{prooftree}
\end{align*}
\paragraph{Others}
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash \bot}
\infer1[$\bot$-E]{\Gamma \vdash A}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash \neg A}
\hypo{\Gamma \vdash A}
\infer2[$\neg$-E]{\Gamma \vdash B}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma, \neg A \vdash \bot}
\infer1[RAA]{\Gamma \vdash A}
\end{prooftree}
\qquad
\begin{prooftree}
\infer0[axiom]{\ldots, A, \ldots \vdash A}
\end{prooftree}
\end{align*}
@@ -0,0 +1,38 @@
\newsection
\subsection{First-Order Logic}
\subsubsection{Syntax}
\inlinedefinition[Signature] consists of a set of function symbols $\cF$ and a set of predicate symbols $\cP$, as well as their arities.
We write $f^k$ (or $p^k$, for predicates) to indicate that it has \textit{arity} $k \in \N$.
Constant functions have arity $0$, linear functions have arity $1$, thus, the arity of a given function (or predicate) is given by
the number of parameters to uniquely describe it, minus one.
\inlinedefinition[Term] is the terms of first-order logic and is the smallest set, where (with $\cV$ again a set of variables)
\begin{enumerate}
\item $x \in \textit{Term}$ if $x \in \cV$
\item $f^n(t_1, \ldots, t_n) \in \textit{Term}$ if $f^n \in \cF$ and $t_i \in \textit{Term}$, $\forall 1 \leq i \leq n$ (description of form of formulas)
\end{enumerate}
\inlinedefinition[Form] is the formulas of first-order logic, is the smallest set where
\begin{enumerate}
\item $\bot \in \textit{Form}$
\item $p^n(t_1, \ldots, t_n) \in \textit{Form}$ if $p^n \in \cP$ and $t_j \in \textit{Term}$, $\forall 1\leq j \leq n$ (description of form of predicates)
\item $A \circ B \in \textit{Form}$ if $A \in \textit{Form}$, $B \in \textit{Form}$ and $\circ \in \{ \land, \lor, \rightarrow \}$ (i.e. formulas with logic symbols)
\item $Qx.A \in \textit{Form}$ if $A \in \textit{Form}$, $x \in \cV$ and $Q \in \{ \forall, \exists \}$ (i.e. formulas with quantifiers)
\end{enumerate}
\paragraph{Binding}
\inlinedefinition[Bound variable] A variable that occurs in a quantifier in scope ({\color{blue} blue in example below})
\inlinedefinition[Free variable] A variable that is not bound by a quantifier in scope ({\color{red} red in example below})
\inlineexample $(q({\color{red} x}) \lor \exists {\color{blue} x}.\forall {\color{blue} y}. p(f({\color{blue} x}), {\color{red} z}) \land q({\color{red} a}))
\lor \forall {\color{blue} x}.r({\color{blue} x}, {\color{red} z}, g({\color{blue} x}))$
\inlinedefinition[$\alpha$-conversion] A \bi{bound} variable can be renamed at any time, but must preserve binding structure.
\paragraph{Precedences}
$\neg > \land > \lor > \rightarrow$, with $>$ a total order of precedences.
Quantifiers extend as far right as possible, bounded by the end of line or a going out of scope by closing parenthesis.
@@ -0,0 +1,40 @@
\subsubsection{Semantics}
\inlinedefinition[Structure] is a pair $\cS = \langle U_\cS, I_\cS \rangle$, where $U_\cS$ is the universe (non-empty set) and $I_\cS$ is a mapping:
\begin{enumerate}
\item $I_\cS(p^n)$ is an $n$-ary relation on $U_\cS$ for $p^n \in \cP$ (short $p^\cS$)
\item $I_\cS(f^n)$ is an $n$-ary (total) function on $U_\cS$ for $f^n \in \cF$ short ($f^\cS$)
\end{enumerate}
\inlineintuition The $I_\cS$ is essentially assigning to each predicate and formula its definition in the universe of the structure, noted as a relation.
\inlinedefinition[Interpretation] is a pair $\cI = \langle \cS, v \rangle$, with $v : \cV \rightarrow U_\cS$ a valuation\\
\inlineintuition it assigns definitions to the formulas and predicates (through the structure), as well as values to the variables (through the valuation).
\inlinedefinition[Value] of a term $t$ under $\cI$ is written as $\cI(t)$ and defined by $\cI(x) = v(x)$ for $x \in \cV$ and\\
$\cI(f(t_1, \ldots, t_n)) = f^\cS(\cI(t_1), \ldots, \cI(t_n))$
\inlinedefinition[Satisfiability] $\models \subseteq$ Interpretations $\times$ \textit{Form} is the smallest relation satisfying
\begin{align*}
& \langle \cS, v \rangle \models p(t_1, \ldots, t_n) & & \text{ if } (\cI(t_1), \ldots, \cI(t_n)) \in p^\cS \text{ where } \cI = \langle \cS, v \rangle \\
& \langle \cS, v \rangle \models \forall x. A & & \text{ if } \langle \cS, v[x \mapsto a] \rangle \models A, \text{ for all } a \in \U_\cS \\
& \langle \cS, v \rangle \models \exists x. A & & \text{ if } \langle \cS, v[x \mapsto a] \rangle \models A, \text{ for some } a \in \U_\cS \\
\end{align*}
\inlinedefinition[Model] When $\langle \cS, v \rangle \models A$, then $\langle \cS, v \rangle$ is a \bi{model} for $A$.
If $A$ does not have free variables, the satisfaction does not depend on the valuation $v$ and we write $\cS \models A$
\inlinedefinition[Validity] When every interpretation is a model, we write $\models A$, and we say that $A$ is \bi{valid}
\inlinedefinition[Satisfiability] $A$ is \bi{satisfiable}, if there exists at least one model for $A$.
\inlineexample Given $\forall x.p(x, s(x))$, we a model would be
\begin{align*}
U_\cS & = \N \\
p^\cS & = \{ (m, n) \divider m, n \in U_\cS \text{ and } m < n \} \\
s^\cS & = \text{ successor function on } U_\cS, \text{ i.e. } s^\cS(x) = x + 1
\end{align*}
\paragraph{Substitution}
\inlinedefinition[Substitution] Replace all occurrences of a free variable $x$ with some term $t$ in $A$.
To denote a substitution, we write $A[x \mapsto t]$. \hl{Important} All free variables in $t$ must still be free in $A[x \mapsto t]$.
If that would not be true anymore, do a $\alpha$-conversion first.
@@ -0,0 +1,31 @@
\subsubsection{Quantifiers}
\paragraph{Universal quantification}
Additional rules are needed for the universal quantifier. * side condition is that $x$ is not free in any assumption of $\Gamma$
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash A}
\infer1[$\forall$-I*]{\Gamma \vdash \forall x.A}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash \forall x.A}
\infer1[$\forall$-E]{\Gamma \vdash A[x \rightarrow t]}
\end{prooftree}
\end{align*}
Again here be mindful not to capture free variables.
\paragraph{Existential quantification}
Additional rules are needed for the existential quantifier. ** side condition is that $x$ is neither free in B nor free in $\Gamma$
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash A[x \mapsto t]}
\infer1[$\exists$-I]{\Gamma \vdash \exists x.A}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash \exists x.A}
\hypo{\Gamma, A \vdash B}
\infer2[$\exists$-E**]{\Gamma \vdash A[x \rightarrow t]}
\end{prooftree}
\end{align*}
Again here be mindful not to capture free variables.
@@ -0,0 +1,43 @@
\subsection{Equality}
Since equality is such an important concept, it isn't just a predicate, but a separate First-Order Logic (FOL),
called \bi{FOL with equality}.
The language is extended by $t_1 = t_2 \in \textit{Form}$ if $t_1, t_2 \in \textit{Term}$,
the semantic entailment $\models$ is also extended by ``$\cI \models t_1 = t_2$ if $\cI(t_1) = \cI(t_2)$''.
This definition is the exact intuition of equality of two terms, in that they are equal if their value under the interpretation is equal.
Equality is an equivalence relation, so the following rules apply (ref = reflexivity, sym = symmetry, trans = transitivity):
\begin{align*}
\begin{prooftree}
\infer0[ref]{\Gamma \vdash t = t}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash t = s}
\infer1[sym]{\Gamma \vdash s = t}
\end{prooftree}
\qquad
\begin{prooftree}
\hypo{\Gamma \vdash t = s}
\hypo{\Gamma \vdash s = r}
\infer2[sym]{\Gamma \vdash s = r}
\end{prooftree}
\end{align*}
Equality is also a congruence on terms and (definable) relations
\begin{align*}
\begin{prooftree}
\hypo{\Gamma \vdash t_1 = s_1}
\hypo{\dots}
\hypo{\Gamma \vdash t_n = s_n}
\infer3[$cong_1$]{\Gamma f(t_1, \ldots, t_n) = f(s_1, \ldots, s_n)}
\end{prooftree}
\\
\begin{prooftree}
\hypo{\Gamma \vdash t_1 = s_1}
\hypo{\dots}
\hypo{\Gamma \vdash t_n = s_n}
\hypo{\Gamma \vdash p(t_1, \ldots, t_n)}
\infer4[$cong_2$]{\Gamma p(s_1, \ldots, s_n)}
\end{prooftree}
\end{align*}
@@ -0,0 +1,4 @@
\newsection
\subsection{Correctness}
For many programs, termination is an important aspect when talking about correctness,
as is, of course, that the return value is ``correct''.
@@ -0,0 +1,15 @@
\subsubsection{Termination}
\inlinetheorem For a function $f$ is defined in terms of other functions $g_1, \ldots, g_k$, for all of which we have $g_i \neq f$ and each $g_i$ terminates, then so does $f$.
\inlinelemma Sufficient condition for termination: The arguments are smaller along a \bi{well-founded} order on the function's domain
\inlinedefinition[Well-Founded Order] An order $>$ on a set $S$ is \bi{well-founded} if and only if there is no infinite decreasing chain $x_1 > x_2 > \ldots$ for $x_i \in S$
An example of such an order is $>$ on $\N$, denoted $>_\N$. Counter example: $>_\Z$ (not bounded from below)
\inlinelemma Let $R \subseteq S \times S$ be a relation on $S$. Let $s_0, s_i \in S$ and $i \geq 1$.
Then $s_0 \; R^i \; s_i$ if and only if $s_1, \ldots s_{i - 1} \in S$ such that $s_0 \; R \; s_1 \R \ldots R \; s_{i - 1} \; R \; s_i$
\inlinedefinition $R^+ \equiv \bigcup_{n \geq 1} R^n$, where $R^n \equiv R \circ R^{n - 1}$ for $n \geq 2$ and $R^1 \equiv R$
\inlinetheorem If $>$ is a well-founded order on $S$, then $>^+$ is also well-founded on $S$
@@ -0,0 +1,44 @@
\subsubsection{Correctness - Behaviour}
We denote that two functions \texttt{fac} and \texttt{fac2} compute the same function usually as
\[
\forall n \in \N. \texttt{fac } n = \texttt{fac2 } (n, 1)
\]
The two functions are given as follows:
\begin{multicols}{2}
\begin{code}{haskell}
fac :: Int -> Int
fac 0 = 1
fac n = n * fac (n - 1)
\end{code}
\begin{code}{haskell}
fac2 :: (Int, Int) -> Int
fac2 (0, a) = a
fac2 (n, a) = fac2 (n - 1, n * a)
\end{code}
\end{multicols}
An important fact to consider is that testing, while useful to find errors can't replace a formal proof to show that a function is correct!
These proofs are based on a simple idea: \bi{functions are equations} and thus, we can reason about them through equational reasoning, or more generally,
proofs in first-order logic with equality.
Often, especially in Haskell programs, we have cases depending on values. Logically, to prove such a function, we also use case distinction, also referred to as reasoning by cases.
\inlineexample Consider the Haskell function below \rmvspace
\begin{code}{haskell}
maxi :: Int -> Int -> Int
maxi n m
| n >= m = n
| otherwise = m
\end{code}
To prove that it is correct, we can use reasoning by cases:
We have $n \geq m \lor \neg(n \geq m)$.
We then show that the function is correct for both cases (i.e. LHS and RHS of OR):
\begin{enumerate}[label=C\arabic*]
\item $n \geq m$: Then $\texttt{maxi } n \ m = n$ and $n \geq n$
\item $\neg(n \geq m)$: Then $\texttt{maxi } n \ m = m$. But $m > n$, so we have $\texttt{maxi } n\ m \geq n$
\end{enumerate}
In this proof we used the \textbf{TND} and \textbf{$\lor$-E} (here also called \bi{Case Split}) rules.
What we have to show, given $Q \lor R$ for any proposition $P$ with case split, is that \bi{(1)} $P$ follows from $Q$ and \bi{(2)} $P$ follows from $R$