<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><![CDATA[My Blog]]></title>
<description><![CDATA[My Blog]]></description>
<link>https://www.jure-smolar.com/</link>
<lastBuildDate>Tue, 10 Mar 2026 09:41:30 +0100</lastBuildDate>
<item>
  <title><![CDATA[Logika v računalništvu (Simpson)]]></title>
  <description><![CDATA[
<p>
Warning: The notes are not optimized for HTML (yet). Without warranty.
</p>
<div id="outline-container-orge2a9277" class="outline-2">
<details>
<summary>
<h2 id="orge2a9277">Lecture 1: Propositional logic</h2>
</summary>
<div class="outline-text-2" id="text-orge2a9277">
</div>
<div class="definition" id="org503064a">
<span class="block-title">Conjunction introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi\)}
\AxiomC{\(\psi\)}
\RightLabel{\(\land i\)}
\BinaryInfC{\(\phi \land \psi\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\phi \land \psi\)}
\RightLabel{\(\land e_{1}\)}
\UnaryInfC{\(\phi\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\phi \land \psi\)}
\RightLabel{\(\land e_{2}\)}
\UnaryInfC{\(\psi\)}
\end{bprooftree}
\end{gather*}
</div>

<div class="definition" id="org16aa7fb">
<span class="block-title">Disjunction introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi\)}
\RightLabel{\(\lor i_{1}\)}
\UnaryInfC{\(\phi \lor \psi\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\psi\)}
\RightLabel{\(\lor i_2\)}
\UnaryInfC{\(\phi \lor \psi\)}
\end{bprooftree}
\end{gather*}

<p>
Elimination is by case analysis: given \(\phi \lor \psi\), if both \(\phi \vdash \theta\) and \(\psi \vdash \theta\), conclude \(\theta\).
</p>

\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi \lor \psi\)}
\AxiomC{\(\phi\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(\theta\)}
\def\extraVskip{2pt}
\AxiomC{\(\psi\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(\theta\)}
\def\extraVskip{2pt}
\TrinaryInfC{\(\theta\)}
\end{bprooftree}
\end{gather*}
</div>

<div class="definition" id="org09e8920">
<span class="block-title">Implication introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi\)}
\noLine
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(\psi\)}
\RightLabel{\(\rightarrow i\)}
\UnaryInfC{\(\phi \rightarrow \psi\)}
\end{bprooftree}
\qquad\quad
\begin{bprooftree}
\AxiomC{\(\phi \rightarrow \psi\)}
\AxiomC{\(\phi\)}
\RightLabel{\(\rightarrow e\)}
\BinaryInfC{\(\psi\)}
\end{bprooftree}
\end{gather*}

<p>
\(\rightarrow i\) discharges the assumption \(\phi\). \(\rightarrow e\) is modus ponens.
</p>
</div>

<div class="definition" id="orgd0e4ac5">
<span class="block-title">Negation introduction and elimination, falsum elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(\bot\)}
\def\extraVskip{2pt}
\RightLabel{\(\neg i\)}
\UnaryInfC{\(\neg \phi\)}
\end{bprooftree}
\quad\qquad
\begin{bprooftree}
\AxiomC{\(\neg \phi\)}
\AxiomC{\(\phi\)}
\RightLabel{\(\neg e\)}
\BinaryInfC{\(\bot\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\bot\)}
\RightLabel{\(\bot e\)}
\UnaryInfC{\(\phi\)}
\end{bprooftree}
\end{gather*}

<p>
\(\neg i\) discharges \(\phi\). \(\bot e\) is <i>ex falso quodlibet</i>: from falsehood, anything follows.
</p>
</div>

<div class="remark" id="orgcef07c6">
<span class="block-title">Reductio ad absurdum</span>
<p>
The rule that distinguishes classical from intuitionistic logic:
</p>

\begin{prooftree}
\AxiomC{\(\neg \phi\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(\bot\)}
\def\extraVskip{2pt}
\RightLabel{raa}
\UnaryInfC{\(\phi\)}
\end{prooftree}

<p>
If assuming \(\neg \phi\) leads to \(\bot\), conclude \(\phi\). Compare with \(\neg i\): there, assuming \(\phi\) and deriving \(\bot\) gives \(\neg \phi\). RAA goes the other direction.
</p>
</div>

<div class="lexample" id="orgb251b10">
<span class="block-title">Distributivity of conjunction over disjunction</span>
<p>
\[
p \land (q \lor r) \rightarrow (p \land q) \lor (p \land r)
\]
</p>

\begin{logicproof}{3}
\begin{subproof}
  p \land (q \lor r) & \(\text{assumption} \) \\
  p & \(\land e(1) \) \\
  q \lor r & \(\land e(1) \) \\
  \begin{subproof}
    q & \(\text{assumption} \) \\
    p \land q & \(\land i(2)(4) \) \\
    (p \land q) \lor (p \land r) & \(\lor i(5)\)
  \end{subproof}
  \begin{subproof}
    r & \(\text{assumption} \) \\
    p \land r & \(\land i(2)(7) \) \\
    (p \land q) \lor (p \land r) & \(\lor i(8)\)
  \end{subproof}
  (p \land q) \lor (p \land r) & \(\lor e(3)(4{-}6)(7{-}9)\)
\end{subproof}
p \land (q \lor r) \rightarrow (p \land q) \lor (p \land r) & \(\rightarrow i (1{-}10)\)
\end{logicproof}
</div>

<div class="definition" id="org9f64959">
<span class="block-title">Proof and the turnstile notation</span>
<p>
A <i>proof</i> of a formula \(\phi\) from assumptions \(\Gamma\) is a sequence of formulas following the inference rules such that all assumptions used in the proof belong to \(\Gamma\). We write \(\Gamma \vdash \phi\).
</p>
</div>

<div class="theorem" id="org8904e01">
<span class="block-title">Soundness and completeness of propositional natural deduction</span>
<p>
\[
\Gamma \vdash \phi \iff \bigwedge \Gamma \rightarrow \phi \text{ is a tautology}
\]
</p>

<p>
<i>Soundness</i> (\(\Rightarrow\)): If \(\Gamma \vdash \phi\), then \(\phi\) is true under every truth assignment making all formulas in \(\Gamma\) true.
</p>

<p>
<i>Completeness</i> (\(\Leftarrow\)): If \(\phi\) is true under every truth assignment making all formulas in \(\Gamma\) true, then \(\Gamma \vdash \phi\).
</p>
</div>

<div class="remark" id="org644421c">
<span class="block-title">Curry-Howard correspondence: formulas as types</span>
<p>
Propositional formulas correspond to types, and proofs correspond to terms (judgements \(t : A\)):
</p>

<table>


<colgroup>
<col  class="org-left">

<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Formula</th>
<th scope="col" class="org-left">Type</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">\(p\) (atomic)</td>
<td class="org-left">\(\alpha\) (atomic type)</td>
</tr>

<tr>
<td class="org-left">\(\phi \land \psi\)</td>
<td class="org-left">\(A \times B\) (product)</td>
</tr>

<tr>
<td class="org-left">\(\phi \lor \psi\)</td>
<td class="org-left">\(A + B\) (coproduct/sum)</td>
</tr>

<tr>
<td class="org-left">\(\phi \rightarrow \psi\)</td>
<td class="org-left">\(A \rightarrow B\) (function)</td>
</tr>

<tr>
<td class="org-left">\(\bot\)</td>
<td class="org-left">\(0\) (empty type)</td>
</tr>
</tbody>
</table>
</div>

<div class="definition" id="org67b847e">
<span class="block-title">Product type introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(s : A\)}
\AxiomC{\(t : B\)}
\RightLabel{\(\Pi i\)}
\BinaryInfC{\((s, t) : A \times B\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(t : A \times B\)}
\RightLabel{\(\Pi e_{1}\)}
\UnaryInfC{\(\pi_1(t) : A\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(t : A \times B\)}
\RightLabel{\(\Pi e_{2}\)}
\UnaryInfC{\(\pi_2(t) : B\)}
\end{bprooftree}
\end{gather*}

<p>
Computation rules: \(\pi_1(s, t) \longrightarrow s\) and \(\pi_2(s, t) \longrightarrow t\).
</p>
</div>

<div class="definition" id="org3910296">
<span class="block-title">Function type introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(x : A\)}
\noLine
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(t : B\)}
\RightLabel{\(\rightarrow i\)}
\UnaryInfC{\(\lambda x . t : A \rightarrow B\)}
\end{bprooftree}
\qquad
\quad
\begin{bprooftree}
\AxiomC{\(t : A \rightarrow B\)}
\AxiomC{\(u : A\)}
\RightLabel{\(\rightarrow e\)}
\BinaryInfC{\(tu : B\)}
\end{bprooftree}
\end{gather*}

<p>
Computation rule (beta reduction): \((\lambda x : A . t)\, u \longrightarrow t[x := u]\).
</p>

<p>
Substitution requires first renaming bound variables in \(t\) so they are distinct from free variables in \(u\).
</p>
</div>

<div class="lexample" id="org3f30f13">
<span class="block-title">Derived term: swap for products</span>
<p>
Construct a term of type \(A \times B \rightarrow B \times A\).
</p>

\begin{logicproof}{2}
\begin{subproof}
x : A \times B & assumption \\
\pi_1(x) : A & \(\Pi e_1 (1)\) \\
\pi_2(x) : B & \(\Pi e_2 (1)\) \\
(\pi_2(x), \pi_1(x)) : B \times A & \(\Pi i (3)(2)\)
\end{subproof}
\lambda x : A \times B . (\pi_2(x), \pi_1(x)) : A \times B \rightarrow B \times A & \(\rightarrow i (1{-}4)\)
\end{logicproof}
</div>

<div class="definition" id="org360d400">
<span class="block-title">Coproduct (sum) type introduction and elimination</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(t : A\)}
\RightLabel{\(+ i_{1}\)}
\UnaryInfC{\(\iota_1(t) : A + B\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(t : B\)}
\RightLabel{\(+ i_2\)}
\UnaryInfC{\(\iota_2(t) : A + B\)}
\end{bprooftree}
\end{gather*}

<p>
Elimination by case analysis:
</p>

\begin{prooftree}
\AxiomC{\(s : A + B\)}
\AxiomC{\(x : A\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(t : C\)}
\def\extraVskip{2pt}
\AxiomC{\(y : B\)}
\noLine
\def\extraVskip{0pt}
\UnaryInfC{\(\vdots\)}
\noLine
\UnaryInfC{\(u : C\)}
\def\extraVskip{2pt}
\TrinaryInfC{\(\mathbf{case}\; s\; (\iota_1(x) \mapsto t \mid \iota_2(y) \mapsto u) : C\)}
\end{prooftree}

<p>
Computation rules:
</p>
\begin{align*}
\mathbf{case}\; \iota_1(s)\; (\iota_1(x) \mapsto t \mid \iota_2(y) \mapsto u) &\longrightarrow t[x := s] \\
\mathbf{case}\; \iota_2(s)\; (\iota_1(x) \mapsto t \mid \iota_2(y) \mapsto u) &\longrightarrow u[y := s]
\end{align*}
</div>

<div class="remark" id="orgeaca779">
<span class="block-title">Empty type</span>
<p>
The empty type \(0\) has no introduction rule (no closed terms of type \(0\) can be constructed).
</p>

\begin{prooftree}
\AxiomC{\(t : 0\)}
\UnaryInfC{\(\mathbf{empty}(t) : A\)}
\end{prooftree}

<p>
This is the type-theoretic counterpart of \(\bot e\) (<i>ex falso quodlibet</i>).
</p>
</div>

</details>
</div>
<div id="outline-container-orgaf040f2" class="outline-2">
<details>
<summary>
<h2 id="orgaf040f2">Lecture 2: First order logic and dependent type theory</h2>
</summary>
<div class="outline-text-2" id="text-orgaf040f2">
</div>
<div class="definition" id="orgc980949">
<span class="block-title">Predicate logic: syntax</span>
<p>
Extends propositional logic with predicates.
\[
\phi ::= p(t_1, \dots, t_n) \mid \phi \land \phi \mid \phi \lor \phi \mid \phi \rightarrow \phi \mid \bot \mid \forall x . \phi \mid \exists x . \phi
\]
We add <i>predicates</i> expressing relations and <i>constants and function symbols</i> expressing elements. Every function symbol has an <b>arity</b> \(\geq 1\). Likewise we interpret formulas as having an arity \(\geq 0\).
</p>

<p>
<b>Terms</b> express elements:
\[
t ::= x \mid c \mid f(t_1, \dots, t_n)
\]
where \(c\) represents constants, \(f\) a function symbol of arity \(n\).
</p>
</div>

<div class="lexample" id="org539c4e7">
<span class="block-title">Expressing properties of integers</span>
<ul class="org-ul">
<li>Constants: \(0, 1\)</li>
<li>Function symbols: \(+, \cdot\) both of arity 2.</li>
</ul>

<p>
Examples of terms: \(z\), \(x + y\), \(x \cdot (y + (z + 1))\).
</p>

<p>
Predicates: \(=\) and \(\leq\), both of arity 2.
</p>

<p>
Example formula (with one free variable \(x\)):
\[
\exists y . \exists z . \exists w . \exists v . \; x = y \cdot y + z \cdot z + w \cdot w + v \cdot v
\]
</p>
</div>

<div class="definition" id="orgfd53abc">
<span class="block-title">The propositional universe</span>
<p>
To integrate predicate logic and type theory, introduce a special type \(\Prop\) — the <b>type of propositions</b>, called the propositional universe.
</p>
</div>

<div class="definition" id="org4128f9e">
<span class="block-title">Basic formation rules for \(\Prop\)</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(\phi : \Prop\)}
\AxiomC{\(\psi : \Prop\)}
\RightLabel{\(\land\)-form}
\BinaryInfC{\(\phi \land \psi : \Prop\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\phi : \Prop\)}
\AxiomC{\(\psi : \Prop\)}
\RightLabel{\(\lor\)-form}
\BinaryInfC{\(\phi \lor \psi : \Prop\)}
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(\phi : \Prop\)}
\AxiomC{\(\psi : \Prop\)}
\RightLabel{\(\rightarrow\)-form}
\BinaryInfC{\(\phi \rightarrow \psi : \Prop\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{}
\RightLabel{\(\bot\)-form}
\UnaryInfC{\(\bot : \Prop\)}
\end{bprooftree}
\end{gather*}

<p>
Often we make the context explicit, e.g.:
\[
p : \Prop,\; q : \Prop \vdash p \land q \rightarrow q \land p : \Prop
\]
</p>
</div>

<div class="definition" id="orgbd9d8a8">
<span class="block-title">Formation rules for quantifiers in \(\Prop\)</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{[\(x : A\)]}
\noLine
\UnaryInfC{\(\phi : \Prop\)}
\RightLabel{\(\forall\)-form}
\UnaryInfC{\(\forall x : A . \phi : \Prop\)}
\end{bprooftree}
\qquad\qquad\qquad
\begin{bprooftree}
\AxiomC{[\(x : A\)]}
\noLine
\UnaryInfC{\(\phi : \Prop\)}
\RightLabel{\(\exists\)-form}
\UnaryInfC{\(\exists x : A . \phi : \Prop\)}
\end{bprooftree}
\end{gather*}

<p>
An alternative is to include connectives and quantifiers as typed constants:
\[
\rightarrow,\; \land,\; \lor : \Prop \rightarrow \Prop \rightarrow \Prop
\]
\[
\exists,\; \forall : (A \rightarrow \Prop) \rightarrow \Prop
\]
</p>
</div>

<div class="remark" id="orgce49a86">
<span class="block-title">Three judgement forms for \(\Prop\)</span>
<ol class="org-ol">
<li>\(t : A\) — \(t\) is of type \(A\)</li>
<li>\(\phi : \Prop\) — \(\phi\) is a proposition</li>
<li>\(\phi\) — \(\phi\) is true</li>
</ol>
</div>

<div class="definition" id="org526b73d">
<span class="block-title">Proof rules for the universal quantifier</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{[\(z : A\)]}
\noLine
\UnaryInfC{\(\phi\)}
\RightLabel{\(\forall i\)}
\UnaryInfC{\(\forall z : A . \phi\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(\forall x : A . \phi\)}
\AxiomC{\(t : A\)}
\RightLabel{\(\forall e\)}
\BinaryInfC{\(\phi[x := t]\)}
\end{bprooftree}
\end{gather*}

<ul class="org-ul">
<li>In \(\forall i\), \(z\) must not appear free outside the box (i.e. not free in the context).</li>
<li>In \(\forall e\), every free occurrence of \(x\) in \(\phi\) is replaced by \(t\), with renaming of bound variables if necessary.</li>
</ul>
</div>

<div class="definition" id="org67a5cc4">
<span class="block-title">Proof rules for the existential quantifier</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{$t : A$}
\AxiomC{$\phi[x := t]$}
\RightLabel{$\exists i$}
\BinaryInfC{$\exists x : A.\ \phi$}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{$\exists x : A.\ \phi$}
\AxiomC{[$x : A$]}
\noLine
\UnaryInfC{$\phi$}
\noLine
\UnaryInfC{$\psi$}
\RightLabel{$\exists e$}
\BinaryInfC{$\psi$}
\end{bprooftree}
\end{gather*}

<p>
In \(\exists e\): \(\psi : \Prop\) must be provable outside the box, and \(\psi\) cannot contain \(x\) free.
</p>
</div>

<div class="lexample" id="org83f3391">
<span class="block-title">Unary predicate as a function</span>
\begin{logicproof}{2}
p : A \rightarrow \Prop & assumption \\
\begin{subproof}
  x : A & assumption \\
  px : \Prop & \(\rightarrow e\)
\end{subproof}
\forall x : A . px : \Prop & \(\forall\)-form (2--3)
\end{logicproof}

<p>
Thus \(\underbrace{p : A \rightarrow \Prop}_{p \text{ is a unary predicate}} \vdash \forall x : A . px : \Prop\).
</p>

<p>
A unary predicate is a function from a type into propositions. For binary predicates we may use currying \(q : A \rightarrow A \rightarrow \Prop\) or pairs \(q : A \times A \rightarrow \Prop\).
</p>
</div>

<div class="proposition" id="org08c9ac7">
<p>
\[
p : A \rightarrow \Prop,\; q : A \rightarrow \Prop \;\vdash\; (\forall x : A . px) \rightarrow (\forall x : A . qx) \rightarrow (\forall x : A . px \land qx)
\]
So to speak, universal quantifier commutes with conjunction. Note this is an instance of <a href="broken-link.html" class="broken-link">RAPL</a>.
</p>
</div>

<div class="proof" id="org36a7a01">
\begin{logicproof}{2}
p : A \rightarrow \Prop & assumption \\
q : A \rightarrow \Prop & assumption \\
\forall x : A . px & assumption \\
\forall y : A . qy & assumption \\
z : A & assumption \\
pz & \(\forall e\) (3)(5) \\
qz & \(\forall e\) (4)(5) \\
pz \land qz & \(\land i\) (6)(7) \\
\forall z : A . pz \land qz & \(\forall i\) (5--8) \\
(\forall y : A . qy) \rightarrow (\forall z : A . pz \land qz) & \(\rightarrow i\) (4--9) \\
(\forall x : A . px) \rightarrow (\forall y : A . qy) \rightarrow (\forall z : A . pz \land qz) & \(\rightarrow i\) (3--10)
\end{logicproof}
</div>

<div class="remark" id="org64c48db">
<span class="block-title">Judgements for types — the universe \(\Type\)</span>
<p>
Replacing the grammar for types with a universe \(\Type\), our judgements are now:
</p>

<ul class="org-ul">
<li>\(\phi\) — \(\phi\) is true</li>
<li>\(t : A\) — \(t\) is of type \(A\)</li>
<li>\(\phi : \Prop\) — \(\phi\) is a proposition</li>
<li>\(A : \Type\) — \(A\) is a type</li>
</ul>

<p>
Formation rules for type constructors:
</p>

\begin{gather*}
\begin{bprooftree}
\AxiomC{\(A : \Type\)}
\AxiomC{\(B : \Type\)}
\BinaryInfC{\(A \times B : \Type\)}
\noLine
\UnaryInfC{\(A + B : \Type\)}
\noLine
\UnaryInfC{\(A \rightarrow B : \Type\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(0 : \Type\)}
\end{bprooftree}
\end{gather*}

<p>
Thus when we introduce a concept, we give it four kinds of rule:
</p>
<ol class="org-ol">
<li>Formation rules</li>
<li>Introduction rules</li>
<li>Elimination rules</li>
<li>Computation rules</li>
</ol>
</div>

<div class="lexample" id="orgcbaaf3e">
<span class="block-title">Dependent product example</span>
<p>
\[
\Pi (n : \mathbb{N}) . \operatorname{Vector}_{\mathbb{N}}\, n
\]
is the type of functions \(f\) such that for each \(n : \mathbb{N}\), \(f(n) : \operatorname{Vector}_{\mathbb{N}}\, n\). Examples:
</p>

<ul class="org-ul">
<li>\(n \mapsto \overbrace{0 \cdots 0}^{n}\) — the zero sequence of length \(n\)</li>
<li>\(n \mapsto 1\, 2 \cdots n\) — the counting sequence of length \(n\)</li>
</ul>
</div>

</details>
</div>
<div id="outline-container-org66e16ec" class="outline-2">
<details>
<summary>
<h2 id="org66e16ec">Lecture 3: Dependent type theory 2</h2>
</summary>
<div class="outline-text-2" id="text-org66e16ec">
</div>
<div class="definition" id="org5c71b6f">
<span class="block-title">Natural numbers type</span>
<p>
The type \(\operatorname{nat}\) is given by
</p>

\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\RightLabel{formation rule}
\UnaryInfC{\(\operatorname{nat} : \Type\) }
\end{bprooftree}
\end{gather*}

\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(0 : \operatorname{nat}\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(t : \operatorname{nat}\)}
\RightLabel{Introduction rules}
\UnaryInfC{\(\operatorname{succ} t : \operatorname{nat}\) }
\end{bprooftree}
\end{gather*}
</div>

<div class="definition" id="org3942418">
<span class="block-title">List types</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(A : \Type\)}
\RightLabel{type of lists of elements of type \(A\)}
\UnaryInfC{\(\operatorname{List} A : \Type\) }
\end{bprooftree}
\end{gather*}

\begin{gather*}
\begin{bprooftree}
\AxiomC{\(A : \Type\)}
\UnaryInfC{\(\operatorname{nil} : \operatorname{List} A\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(a : A\)}
\AxiomC{\(as : \operatorname{List} A\)}
\RightLabel{Introduction}
\BinaryInfC{\(\operatorname{cons} a\, as : \operatorname{List} A\) }
\end{bprooftree}
\end{gather*}

<p>
Alternatively, we can think of this type as given by
</p>
<ol class="org-ol">
<li>A constant \(\operatorname{nil} : \operatorname{List} A\)</li>
<li>A map \(\operatorname{cons} : A \rightarrow \operatorname{List} A \rightarrow \operatorname{List} A\)</li>
</ol>
</div>

<div class="definition" id="org69cb300">
<span class="block-title">Vector types</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(A : \Type\)}
\AxiomC{\(n : \operatorname{nat}\)}
\BinaryInfC{\(\operatorname{Vector} A \, n : \Type\)}
\end{bprooftree}
\end{gather*}

\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(\operatorname{nil} : \operatorname{Vec} 0\, A\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(a : A\)}
\AxiomC{\(as : \operatorname{Vector} A\, n \)}
\BinaryInfC{\(\operatorname{cons} n\, a \, ax : \operatorname{Vector} A \, (\operatorname{succ} n)\)}
\end{bprooftree}
\end{gather*}
<p>
Alternatively, we can think of it as given by
</p>
<ol class="org-ol">
<li>A constant \(\operatorname{nil} : \operatorname{Vec} 0 \, A\)</li>
<li>A map \(\operatorname{cons} : A \rightarrow \operatorname{Vec} A \, n \rightarrow \operatorname{Vec}  A \, (\operatorname{succ} n)\)</li>
</ol>
<p>
The map including the dependent \(n\) means we really have a family of maps, which we give as a dependent product:
\[
\operatorname{cons} : \prod(n : \operatorname{nat}) .\,  A \rightarrow \operatorname{Vec} A \, n \rightarrow \operatorname{Vec}  A \, (\operatorname{succ} n)
\]
Hence why \(\operatorname{cons}\) takes the additional argument \(n\). Vectors form a <b>dependent type</b>.
</p>
</div>

<div class="definition" id="org683db1d">
<span class="block-title">Dependent product rules</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{[\(x : A\)]}
\noLine
\UnaryInfC{\(B : \Type\)}
\RightLabel{\(\Pi\)f}
\UnaryInfC{\(\Pi(x : A) . B : \Type\)}
\end{bprooftree}
\qquad
\begin{bprooftree}
\AxiomC{[\(x : A\)]}
\noLine
\UnaryInfC{\(t : B\)}
\RightLabel{\(\Pi\)i}
\UnaryInfC{\(\lambda x : A . t : \Pi(x : A) . B\) }
\end{bprooftree}
\qquad
\begin{bprooftree}
\AxiomC{\(s : \Pi (x : A).\, B\)}
\AxiomC{\(t : A\)}
\RightLabel{\(\Pi\)e}
\BinaryInfC{\(st : B[t / x]\)}
\end{bprooftree}
\end{gather*}

<p>
We also have the computation rule
\[
(\lambda x : A . t) u \longrightarrow t[u/x].
\]
</p>

<p>
Note that these rules match to the rules for \(\rightarrow\). In type theory, once you have dependent product, we don't need the \(\rightarrow\) type as a primitive anymore, because it is defineable. In particular, reduces to the ordinary function type \(A \rightarrow B\) when \(B\) does not depend on \(x\), \(\Pi(x : A) . B\).
</p>
</div>

<div class="definition" id="org0f58f36">
<span class="block-title">Dependent sum types</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(A : \Type\)}
\AxiomC{[\(x : A\)]}
\noLine
\UnaryInfC{\(B : \Type\)}
\RightLabel{\(\Sigma\)-form}
\BinaryInfC{\(\Sigma (x : A) . \, B : \Type\)}
\end{bprooftree}
\qquad
\qquad
\begin{bprooftree}
\AxiomC{\(s : A\)}
\AxiomC{\(t : B[s/x]\)}
\RightLabel{\(\Sigma\)-intro}
\BinaryInfC{\((s, t) : \Sigma(x : A). \, B\)}
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(t : \Sigma(x : A).\, B\)}
\RightLabel{\(\Sigma\)-elim-1}
\UnaryInfC{\(\pi_1(t) : A\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(t : \Sigma(x : A).\, B\)}
\RightLabel{\(\Sigma\)-elim-2}
\UnaryInfC{\(\pi_2(t) : B[\pi_1(t) / x]\) }
\end{bprooftree}
\end{gather*}

<p>
We also define the computation rules
</p>
\begin{align*}
\pi_1(s, t) &\longrightarrow s \\
\pi_2(s, t) &\longrightarrow t
\end{align*}

<p>
Intuitively, \(\Sigma(x : A). B\) is the type where elements are tagged elements
\[
\operatorname{in}_a(b)
\]
where \(a : A\) and \(b : B[a/x]\). Equivalently, we can give the tagging with pairs \((a, b)\) for \(a : A\) and \(b : B[a/x]\).
</p>
</div>

<div class="remark" id="org619b8db">
<span class="block-title">Product types</span>
<p>
We can define the product types using dependent sums using
\[
A \times B := \Sigma(x : A) . \, B
\]
where \(B\) does not depend on \(A\).
</p>
</div>

<div class="remark" id="orgc78eb28">
<span class="block-title">Types and their elements</span>
<ul class="org-ul">
<li>\(0\) has no elements</li>
<li>\(A \times B\) has pairs \((a, b)\) where \(a : A\) and \(b : B\)</li>
<li>\(A + B\) has tagged elements \(\iota_1(a)\) where \(a : A\) or \(\iota_2(b)\) where \(b : B\)</li>
<li>\(A \rightarrow B\) has functions of domain \(A\) and codomain \(B\)</li>
<li>\(\Pi (x : A).\, B\) has functions mapping elements \(a : B\) to elements of type \(B[a/x]\).</li>
<li>\(\Sigma (x : A). \, B\) has pairs \((a, b)\) where \(a : A\) and \(b : B[a/x]\)</li>
</ul>
<p>
We can also consider a primitive unit type.
</p>
</div>

<div class="remark" id="orgdcdc03f">
<span class="block-title">Brouwer-Heyting-Kolmogorov interpretation of logic</span>
<ul class="org-ul">
<li>\(\bot\) has no proof.</li>
<li>A proof of \(\phi \land \psi\) is a pair \((a, b)\) where \(a\) proves \(\phi\) and \(b\) proves \(\psi\).</li>
<li>A proof of \(\phi \lor \psi\) is either \(\iota_1(a)\) where \(a\) is a proof of \(\phi\) or \(\iota_2(b)\) where \(b\) is a proof of \(\psi\).</li>
<li>A proof of \(\phi \rightarrow \psi\) is a function that maps a proof of \(\phi\) to a proof of \(\psi\).</li>
<li>A proof of \(\forall x : A . \phi\) is a function that takes an element \(a : A\) to a proof of \(\phi[a/x]\).</li>
<li>A proof of \(\exists x : A . \phi\) is a pair \(a, b\) where \(a : A\) and \(b\) is a proof of \(\phi[a/x]\).</li>
</ul>
</div>

<div class="remark" id="org35f0489">
<span class="block-title">Propositions as types: Curry-Howard correspondence</span>
<p>
We replace logical formulas (proposition) with types whose elements are proofs of the propositions.
</p>
\begin{align*}
\bot &\longrightarrow 0 \\
\phi \land \psi &\longrightarrow A \times B \\
\phi \lor \psi &\longrightarrow A + B \\
\phi \rightarrow \psi &\longrightarrow A \rightarrow B \\
\forall x : A .\, \phi &\longrightarrow \Pi(x : A) . \, B \\
\exists x : A .\, \Phi &\longrightarrow \Sigma(x : A) . \, B
\end{align*}

<p>
With this approach we do not need an explicit propositional universe \(\Prop\). This works but we have a better way.
</p>
</div>

<div class="remark" id="orgc39c65d">
<span class="block-title">Propositions as subterminal types</span>
<p>
This is the modern approach to embedding logic in type theory.
</p>
<ul class="org-ul">
<li>If \(\phi : \Prop\), then \(\phi : \Type\), i.e. \(\Prop\) is a subuniverse of \(\Type\)</li>
<li><p>
\(\Prop\) is closed under \(\Pi\) types, meaning
</p>
 \begin{prooftree}
 \AxiomC{\(A : \Type\)}
 \noLine
 \UnaryInfC{\(x : A\)}
 \noLine
 \UnaryInfC{\(\phi : \Prop\)}
\UnaryInfC{\(\Pi(x : A). \, B : \Prop\) }
 \end{prooftree}</li>
<li>If \(\phi : \Prop\), then \(\phi\) is <b>subterminal</b>, if \(a, b : \phi\), then \(a = b\).</li>
<li>We also take \(\Prop : \Type\) - impredicativity.</li>
</ul>
</div>

<div class="remark" id="orgdee10f0">
<span class="block-title">The Scott-Prawitz encoding of intuitionistic logic</span>
<p>
Taking type theory with \(\Pi\) as the only type constructor is enough for logic.
Also taking inductive types allows us to do mathematics and computer science.
</p>

<ul class="org-ul">
<li>\(\bot\): \(\Pi(p : \Prop) . \,p\)</li>
<li>\(\phi \land \psi\): \( \Pi (p : \Prop) . (\phi \rightarrow \psi \rightarrow p) \rightarrow p \)</li>
<li>\(\phi \lor \psi\):\( \Pi (p : \Prop) . (\phi \rightarrow p) \rightarrow (\psi \rightarrow p) \rightarrow p \)</li>
<li>\(\phi \rightarrow \psi\) : \(\phi \rightarrow \psi\)</li>
<li>\(\forall x : A . \phi\) :\(  \Pi (x : A) . \phi\)</li>
<li>\(\exists x : A . \phi\): \(  \Pi (p : \Prop) \left( \Pi(x : A) . (\phi \rightarrow p) \right) \rightarrow p\)</li>
</ul>
</div>

</details>
</div>
<div id="outline-container-org0e466d9" class="outline-2">
<details>
<summary>
<h2 id="org0e466d9">Lecture 4: Dependent type theory 3</h2>
</summary>
<div class="outline-text-2" id="text-org0e466d9">
<p>
We have the basic judgement forms
</p>
<ul class="org-ul">
<li>\(A : \Type\)</li>
<li>\(t : A\)  wherein we had to prove \(A : \Type\)</li>
<li>\(S \equiv t : A\) meaning \(s\) and \(t\) are judgementally equal.</li>
</ul>

<p>
and the derived judgment forms
</p>
<ul class="org-ul">
<li>\(\Phi : \Prop\) is given by an instancce of \(t : A\) and \(A : \Type\)</li>
<li>\(t : \Prop\) means \(\_ : \phi\), so \(\phi\) must be inhabited. We say the term is a <b>witness</b> for \(\phi\).</li>
</ul>

<p>
We will look at judgemental equality today. It turns out to be crucial.
</p>
</div>
<p>
We want to produce an elimination rule for the naturals.
</p>
<div class="definition" id="orgc2b8391">
<span class="block-title">Induction rule</span>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(t : \operatorname{nat}\)}
\AxiomC{\(P : \operatorname{nat} \rightarrow \Prop\)}
\AxiomC{\(P0\)}
\AxiomC{\(x : \operatorname{nat}, Px \vdash p(\operatorname{succ x})\)}
\QuaternaryInfC{\(Pt\)}
\end{bprooftree}
\end{gather*}
</div>

<p>
Instead of a rule-based formulation, we assume typed constants that are "equivalent" to the rules. Our introduction rules are terms \(0 : \operatorname{nat}\) and \(\operatorname{succ} : \operatorname{nat} \rightarrow \operatorname{nat}\). Note that we cannot derive that \(\operatorname{succ}\) is a function by our previous definition, but we can define \(\lambda x : \operatorname{nat} . \operatorname{succ} x : \operatorname{nat} \rightarrow \operatorname{nat}\).
</p>

<p>
Likewise, rather than defining the induction rule as above, we can formulate it as an axiom in logic.
</p>
<div class="definition" id="org82d7b6f">
<span class="block-title">Induction axiom</span>
<p>
\[
\operatorname{Ind} : P : \operatorname{nat} \rightarrow\Prop .\, \left( P0 \rightarrow (\forall x : \operatorname{nat} .\, Px \rightarrow P (\operatorname{succ} x)) \rightarrow \forall x : \operatorname{nat} .\, Px \right)
\]
</p>
</div>

<p>
A mathematical proof in set theory derives the recursion principle from this. If we have any set \(A\) and \(a : A\) and \(f : A \rightarrow A\), then there exists a unique function \(r : \N \rightarrow A\) such that we have \(r(0) = a\) and \(r(n + 1) = f(r(n))\).
</p>

<p>
Building on the classical intuition, we generalize the induction axiom by replacing the	\(\forall\) with the dependent product, constructing an explicit <b>recursor</b> function.
</p>

<div class="definition" id="orgc5663f1">
<p>
\[
R_{\operatorname{nat}} : \prod P : \operatorname{nat} \rightarrow \Type .\, \left( P0 \rightarrow \left( \prod x : \operatorname{nat} .\, Px \rightarrow P(\operatorname{succ} x) \right) \right) \rightarrow \prod x : \operatorname{nat}.\, Px
\]
</p>
</div>

<p>
We can use the recursor to formulate a computation rule.
</p>

<div class="definition" id="orgb6a1d72">
<p>
Say we have \(P : \operatorname{nat} \rightarrow \Type\), \(b : P_0\), \(f : \prod (x : \operatorname{nat} .\,Px \rightarrow P(\operatorname{succ} x))\). Then we have a term
\[
R_{\operatorname{nat}}P\, b\, f\, : \prod(x : \operatorname{nat}) .\, Px
\]
which we can apply as
</p>
\begin{align*}
R_{\operatorname{nat}} P\, b\, f\, 0 &\longrightarrow b : P0\\
R_{\operatorname{nat}} P\, b\, f\, (\operatorname{succ} n) &\longrightarrow f \left( R_{\operatorname{nat}} P\, b\, f\, n\right) : P(\operatorname{succ} n)
\end{align*}
</div>

<div class="lexample" id="org41e6f75">
<p>
We define the function
</p>
\begin{align*}
\operatorname{add} : \operatorname{nat} &\rightarrow \operatorname{nat}\rightarrow \operatorname{nat}\\
\operatorname{add} &:=  \lambda m : \operatorname{nat} .\, \lambda n : \operatorname{nat} .\,
R_{\operatorname{nat}} (\lambda \_ : \operatorname{nat}) \,m\, (\lambda\_ : \operatorname{nat} .\, \lambda x : \operatorname{nat} .\, \operatorname{succ} x) \, n
\end{align*}

<p>
Let us prove \(1 + 1 = 2\).
</p>
\begin{align*}
\operatorname{add} \, (\operatorname{succ} 0)\, (\operatorname{succ} 0) &\longrightarrow^{ * } R_{\operatorname{nat}} (\lambda \_ : \operatorname{nat} . \operatorname{nat}) (\operatorname{succ} 0 )\, (\lambda \_ : \operatorname{nat} . \operatorname{nat}) (\operatorname{succ} 0 )\, \\
&\longrightarrow (\lambda \_ : \operatorname{nat} .\, \lambda x : \operatorname{nat}.\, \operatorname{succ} x)  \, 0 \, (R_{\operatorname{nat}} (\lambda \_ : \operatorname{nat} .\, \operatorname{nat}) \, (\operatorname{succ} 0) \, \operatorname{\lambda \_ : \operatorname{nat} .\, \lambda x : \operatorname{nat} .\, \operatorname{succ} x} 0) \\
&\longrightarrow^{ * } \operatorname{succ} (*R_{\operatorname{nat}} \, (\lambda \_ : \operatorname{nat} .\, \operatorname{nat}) \, (\operatorname{succ} 0)\, (\lambda \_ : \operatorname{nat} .\, \lambda x : \operatorname{nat} .\, \operatorname{succ} x) 0) \\
&\rightarrow \operatorname{oper}(\operatorname{oper} 0)
\end{align*}
</div>

</details>
</div>
<div class="taglist"><a href="https://www.jure-smolar.com/tags.html">Tags</a>: <a href="https://www.jure-smolar.com/tag-lecture-notes.html">lecture-notes</a> </div>]]></description>
  <category><![CDATA[lecture-notes]]></category>
  <link>https://www.jure-smolar.com/20260217080921-logika_v_racunalnistvu.html</link>
  <guid>https://www.jure-smolar.com/20260217080921-logika_v_racunalnistvu.html</guid>
  <pubDate>Tue, 10 Mar 2026 09:41:30 +0100</pubDate>
</item>
<item>
  <title><![CDATA[Računska zahtevnost (Cabello)]]></title>
  <description><![CDATA[
<p>
Warning: The notes are not optimized for HTML (yet). Without warranty.
</p>
<div id="outline-container-orgc37c32f" class="outline-2">
<details>
<summary>
<h2 id="orgc37c32f">Lecture 1: Motivation</h2>
</summary>
<div class="outline-text-2" id="text-orgc37c32f">
</div>
<div class="lexample" id="orgdd5e39c">
<p>
For a matrix \(A \in \R^{n \times n}\)  we usually define a determinant as
\[
\det(A) = \sum\limits_{\sigma} \sgn(\sigma) . \prod\limits_{i \in [n]} a_{i, \sigma(i)}.
\]
</p>
</div>

<p>
Looking at it as a computational problem that inputs the matrix \(A\) and outputs the determinant \(\det(A)\). How quickly can we compute it?
</p>

<div class="remark" id="org3ba8cb9">
<ol class="org-ol">
<li>We can compute it in \(O(n!)\) time by directly applying the definition. Using the stirling approximation, this is something like \(O(\sqrt{2\pi n} (\frac{n}{e})^n)\) time, which is very inefficient.</li>
<li>Using Gaussian elimination \(A = LUP\), we can compute the determinant as \(\det(A) = \det(L) \cdot \det(U) \cdot \det(P)\). We have \(O(n^3)\).</li>
<li>We can compute it in \(O(n^{\omega})\) time by using fast matrix multiplication algorithms, where \(\omega < 2.375\).</li>
</ol>
</div>

<p>
This gives us a general view of what happens.
</p>
<ul class="org-ul">
<li>The reduction from step 1 to 2 is significant, we go from superexponential to a polynomial algorithm.</li>
<li>When we get a polynomial time algorithm, we try to reduce it as much as possible.</li>
<li>We cannot get linear time, since the input is itself quadratic.</li>
<li>For \(O(n^2)\), we do not know.</li>
<li>But we have a state of the art solution in \(O(n^{2.375})\).</li>
</ul>

<div class="remark" id="org4ba25c2">
<p>
There's a problem with the example though. The \(O(n^3)\) talks about sums and products, which are nonconstant as time goes on. Choosing the pivot carefully, we can get polynomial time, but it can be much greater.
</p>

<p>
We can fix this by taking a finite field, say \(\Z_7\). There's fundamentally more informations as \(n\) grows. Picking a finite field is a common "hack".
</p>

<p>
We should be careful with this. Nobody is careful with this.
</p>
</div>

<div class="lexample" id="orgc9aa6d8">
<p>
\[
\operatorname{perm}(A) = \sum\limits_{\sigma} \prod\limits_{i \in [n]} a_{i, \sigma(i)}
\]
</p>
</div>

<p>
This is an analogous problem which can again be computed by definition which is again computable in \(O(n!)\). But here we do not know of a polynomial time algorithm.
</p>

<div class="remark" id="org6063774">
<ul class="org-ul">
<li>For instance, the permanent of a \(\Z_2\) matrix is the number of perfect matchings in a bipartite graph.</li>
<li>Note that we can compute a single perfect matching in a bipartite graph (optimisation methods/linear programming).</li>
<li>We do not know how to count such matchings in polynomial time.</li>
<li>Can we generate a perfect matching uniformly at random in the set of perfect matchings in a bipartite graph?
We again do not know how to do it in polynomial time.</li>
</ul>
</div>

<div class="lexample" id="org11f433c">
<p>
The naive algorithm checks divisors up to \(n\) (or up to \(\sqrt{n}\)). Assuming that checking \(i \mid n\) takes constant time, this would give us \(\approx\sqrt{n}\) steps.
</p>
</div>

<div class="remark" id="orgacd9b15">
<p>
Here's a trap. It's polynomial in \(n\), but not polynomial in \(\log_2(n)\). The more correct size of the input is the number of digits. Then \(\sqrt{n} \approx 2^{\frac{1}{2}\log_2n}\), which is exponential in the input size.
</p>

<p>
Since the 70s, it is known that we have a \(\log_2n\) polynomial time algorithm that tests primality with high probability, where there are no false positives, but might be false negatives, i.e. it might say a composite number is prime with probability \(\leq \frac{1}{4}\). This is in randomized polynomial time. To improve the odds, we can rerun the algorithm repeatedly.
</p>

<p>
In 2002, Aggraval, Kayal, Sexena showed there exists a deterministic polynomial time algorithm which recognises prime numbers.
</p>
</div>

<div class="lexample" id="orgb7299db">
<p>
For a natural number, return a number that divides it or mark it prime.
</p>
</div>

<div class="remark" id="org6276d52">
<p>
We do not know how to factorize in polynomial time (deterministic or rational).
</p>
</div>

<div class="remark" id="org0f1e5ba">
<ul class="org-ul">
<li>If problem \(A\) can be solved in polynomial time, then problem \(B\) can be solved in polynomial time. (Reduction)</li>
<li>If we have sets of problems with some given properties \(X, Y\), we're looking at \(X \subseteq Y\) or \(X = Y\).</li>
<li>Problem \(X\) needs at least time/space \(\approx n^2\), say. (Lower bound)</li>
</ul>
<p>
The lower bound problems are very very few, and usually very weak.
</p>
</div>

</details>
</div>
<div id="outline-container-orgc0b48f0" class="outline-2">
<details>
<summary>
<h2 id="orgc0b48f0">Lecture 2: Basic definitions</h2>
</summary>
<div class="outline-text-2" id="text-orgc0b48f0">
</div>
<div class="remark" id="org14c16a7">
<p>
If we have integers \(a, b\) of length \(n\), we learned in primary school to add them in \(O(n)\) and multiplying them in \(O(n^2)\). In fact, we can get multiplication down to \(O(n\log n)\) using a galactic algorithm. Even so, using FFT, we have more practical algorithms of \(O(n \log^2 n)\).
</p>

<p>
Still, we do not know if this \(\log\) factor is required and multiplication really is more computationally demanding.
</p>
</div>

<div class="definition" id="org507b94e">
<span class="block-title">Encodings</span>
<p>
An <b>encoding</b> is a function
\[
e : \text{ inputs} \rightarrow \left\{ 0, 1 \right\}^{ * }.
\]
</p>

<p>
(We could use some other alphabet, but we use binary encodings on the computer.)
</p>

<p>
We assume a fixed <i>explicit</i> encodings in this course. This means that we always have an explicit input, e.g. we could give a number recursively in terms of its digits, but we still always assume it to be given explicitly.
</p>
</div>

<div class="definition" id="orgb577201">
<span class="block-title">Decision Problems</span>
<p>
A computational problem with boolean output.
</p>

<p>
The fiber of true becomes interesting as an object of study. When we view it in an encoding, it is
\[
L = \left\{ w \in \left\{ 0, 1 \right\}^{ * } \mid P(w) \right\} ,
\]
which is a language. So decision problems are recognising a language. (For now?) we only care about decidable languages.
</p>

<p>
An additional detail to sweep under the rug is that we assume \(P(w)\) also checks the validity of \(w\), i.e. we never think about encoding problems as such.
</p>
</div>

<div class="definition" id="org322d931">
<span class="block-title">\(O\)-notation</span>
<p>
\[ \begin{aligned}
f &= O(g(n)) \iff \exists C \in \R .\exists n_0 \in \N . \forall n \geq n_0 . f(n) \leq C \cdot g(n) \\
f &=  \Omega(g) \iff g = O(f) \\
f &= \Theta(g) \iff f = O(g) \text{ in } g = O(f)
\end{aligned}
\]
We also use the little \(o\) notation, which indicates a weak upper bound:
\[
f = o(g) \iff \exists  n_0 \in \N . \forall C > 0 .  \forall n \geq n_0 . f(n) \leq C g(n)
\]
i.e. all since we have enough additional complexity, it dominates any constant. We get
\[
f = o(g) \implies \lim_{n \rightarrow \infty} \frac{f}{g} = 0
\]
</p>

<p>
Likewise we define
\[
f = \omega(g) \iff g = o(f).
\]
</p>
</div>

<div class="remark" id="orge6f0c33">
<p>
For computational complexity, we want an explicit notion of time and space, which is better done in Turing machines than, say, \(\lambda\)-calculus. The definiton is very robust - we have several equivalent variants we can deploy when need be.
</p>
</div>

<div class="definition" id="org9bb2df7">
<span class="block-title">Deterministic Turing Machines</span>
<p>
We define it as \((\Gamma, \sqcup, Q, q_s, q_h, \delta)\) where \(\delta : \Gamma \times Q \rightarrow \Gamma \times Q \times \left\{ -1, 0, 1 \right\}\) is the transition function.
</p>

<p>
The definition of the TM doesn't itself speak of the tape state. We also define a <b>configuration</b> of the TM \(M\) as \((q, t, i)\) where \(q\) is the state of the control unit, \(t : \Z \rightarrow \Gamma\) the state of the tape and \(i \in \Z\) the position of the head. The initial configuration is then \((q_s, in, 0)\). The input is always right from 0.
</p>
</div>

<div class="definition" id="org7be437b">
<span class="block-title">Recognising a Language</span>
<p>
A TM \(M\) recognizes a language \(L\) if
</p>
<ol class="org-ol">
<li>For every input, \(M\) halts</li>
<li>\(\forall \omega \in L .\,\) applying \(M\) to \(\omega\) finishes with \(q_{\text{accept}}\)</li>
<li>\(\forall \omega \not\in L .\,\) applying \(M\) to \(\omega\) finishes with \(q_{\text{reject}}\)</li>
</ol>
</div>

<div class="remark" id="org6584553">
<p>
There exist undecidable languages.
</p>
</div>

<div class="lexample" id="org64dc7e2">
<p>
An example is the halting problem.
</p>
<ul class="org-ul">
<li>Input: a Turing machine \(M\) and \(\omega\).</li>
<li>Output: Does the Turing machine \(M\) with input \(\omega\) halt?</li>
</ul>
</div>

<div class="lexample" id="org3d52593">
<p>
Another example is <a href="broken-link.html" class="broken-link">Hilbert's 10th problem</a>:
</p>
<ul class="org-ul">
<li>Input: A polynomial with multiple variables and coefficients in \(\Z\).</li>
<li>Output: Does the polynomial have a zero in \(\Z\)?</li>
</ul>
</div>

<div class="definition" id="org079fa74">
<span class="block-title">Running Time</span>
<p>
Let \(M\) be a TM. We define
</p>
\begin{align*}
\operatorname{time} : {\N} &\rightarrow \N \cup \left\{ \infty \right\} \\
n &\mapsto \text{ maximum time that \(M\) runs over all inputs of length \(n\)}
\end{align*}
</div>

<div class="remark" id="org43f4984">
<p>
Note: A Turing machine has time complexity \(O(n)\) or \(\Omega(n \log n)\). We cannot have something like \(\Theta(n \sqrt{\log n})\).
</p>
</div>

<div class="definition" id="orgb86ffe2">
<span class="block-title">Computing Functions</span>
<p>
It computes a function
\[
f : \Sigma_1^{ * } \rightarrow \Sigma_2^{ * }
\]
if
</p>
<ul class="org-ul">
<li>\(M\) always finishes for \(\omega \in \Sigma_1^{ * }\)</li>
<li>\(M\) has a halting state \(q_{h}\)</li>
<li>At the end the tape contains \(f(\omega)\) and all blanks around.</li>
</ul>
<p>
In particular this means we need \(\Gamma \supseteq \Sigma_1 \cup \Sigma_2 \) .
</p>

<p>
This is more general than decideability, which reduces to the case \(f : \Sigma^{ * } \rightarrow \left\{ 0, 1 \right\}\).
</p>
</div>

<div class="proposition" id="org310d05e">
<p>
\(M\) computes a function \(f : \left\{ 0, 1 \right\}^{ * }\) in time \(\operatorname{time}_M(n)\) using \(\abs{\Gamma} = k\) symbols.
Then there exists another TM \(\widetilde{M}\) that computes \(f\) which uses symbols \(\widetilde{\Gamma} = \left\{ 0, 1, \sqcup \right\}\) and has time complexity
\[
\operatorname{time}_{\widetilde{M}}(n) = O(\operatorname{time}_M(n) + n^2).
\]
Note that the \(O\) constant depends on the original TM.
</p>
</div>

<div class="proof" id="orgc1aeb2c">
<p>
The idea is that we define and use an injection encoding all original symbols (including blank)
\[
\Gamma \hookrightarrow \left\{ 0, 1, \sqcup \right\}^{k}
\]
where we encode each symbol as a \(k\)-chunk. \(\widetilde{Q}\) records partial readings for blocks. One step of \(M\) becomes \(O(k)\) steps of \(\widetilde{M}\).
</p>

<p>
The \(O(n^2)\) term comes only from copying the data.
</p>
</div>

</details>
</div>
<div id="outline-container-org27ce5bb" class="outline-2">
<details>
<summary>
<h2 id="org27ce5bb">Lecture 3: Deterministic Turing Machines</h2>
</summary>
<div class="outline-text-2" id="text-org27ce5bb">
</div>
<div class="definition" id="orgb0f7ea1">
<span class="block-title">\(k\)-tape Turing Machine</span>
<p>
A \(k\)-tape Turing machine has \(k\) tapes. It's equivalent to consider transition functions which move just one or all tape-heads at once. Sometimes one of the tapes is considered to be read-only and considered as an input tape, likewise sometimes we only have an output tape, etc.
</p>
</div>

<div class="theorem" id="orgadb5073">
<p>
If there exists a TM with \(k\) tapes that recognizes \(L\) in time \(T(n)\), then there exists a 1-tape TM that recognizes \(L\) in time
\[
O(T(n)^2).
\]
</p>

<p>
In particular, if \(k\)-tape \(M\) runs in polynomial time, so does the 1 tape version.
</p>
</div>

<div class="proof" id="orgaef0ca9">
<p>
The idea is that we intercalate the tapes. Use states to remember from which tape of \(M\) we are reading in \(\widetilde{M}\).
</p>

<p>
The new set of symbols for \(\widetilde{M}\) is
\[
\widetilde{\Gamma} = \Gamma \cup \left\{ \widehat{a} \mid a \in \Gamma \right\}
\]
where the symbol \(\widehat{a}\) in the tape indicates the head of the given tape is there.
</p>

<p>
We get \(\widetilde{Q} = Q \times \widehat{\Gamma}^k \times [k] \cup O(1) \text{ states}\)
</p>
</div>

<div class="remark" id="orgf299490">
<p>
This is a <b>data-oblivious</b> construction, we access the data following the same pattern, independent of the actual data. The quadratic term comes from the fact we need to read the whole tape on each step.
</p>
</div>

<div class="remark" id="org0fb0b8a">
<p>
Same idea as the bijection \(\N \cong \Z\). Or store pairs and use \(\Gamma^2\).
</p>
</div>

<div class="theorem" id="orgce58e6a">
<p>
Whenever there exists a TM \(M\) of some type that recognizes a language \(L\), there exists another \(TM\) \(\widetilde{M}\) of some other type that recognizes \(L\). Moreover,
\[
\operatorname{time}_{\widetilde{M}}(n) = O\left((\operatorname{time}_M(n))^{\text{constant}}\right)
\]
</p>
</div>

<div class="definition" id="orgd8970ec">
<span class="block-title">DTIME</span>
<p>
We say that \(\operatorname{DTIME}(f(n))\) is the set of languages \(L\) such that there exists a TM \(M\) that recognizes \(L\) and has
\[
\operatorname{time}_M(n) = O(f(n)).
\]
</p>

<p>
We usually take the \(TM\) to be a \(k\)-tape machine for some constant \(k\).
</p>
</div>

<div class="remark" id="orgd3744a7">
<p>
This is a non-robust definition.
</p>
</div>

<div class="definition" id="org2466309">
<span class="block-title">PTIME</span>
<p>
We define
\[
\operatorname{P} = \bigcup\limits_{d \geq 1} \operatorname{DTIME}(n^d).
\]
</p>
</div>

<div class="remark" id="orgf2ce188">
<p>
A problem \(\in \operatorname{P}\) is
</p>
<ul class="org-ul">
<li>A decision problem</li>
<li>that can be recognized in polynomial time</li>
</ul>
</div>

<div class="remark" id="org79d2fe1">
<p>
Note that \(\operatorname{P}\) is a natural definition.
</p>
<ul class="org-ul">
<li>Constants are not relevant. For instance, we can get constant speed-up using more symbols.</li>
<li>It's robust wrt the type of the TM.</li>
<li>Computers, contra TMs, have (finite) RAM.</li>
<li>This ends up making no difference, we can simulate indexed access using a TM (with quadratic blowup), using counters.</li>
<li>\(\operatorname{P}\) is closed wrt to taking calls to other programs in \(\operatorname{P}\) that do not grow the output.
An issue would be a program which doubles the input.</li>
<li>Currently, all of the physically realizable notions of computation give the same definition of polynomial time.</li>
</ul>
</div>

<div class="definition" id="org29bf1b6">
<span class="block-title">EXP</span>
<p>
We define
\[
\operatorname{EXP} = \bigcup\limits_{d \geq 1} \operatorname{DTIME} \left( 2^{n^{d}} \right)
\]
</p>
</div>

<div class="definition" id="org8aba3ae">
<span class="block-title">Quasipolynomial Time</span>
\begin{align*}
\operatorname{QuasiP} &= \bigcup\limits_{d \geq 1} \operatorname{DTIME} \left( 2^{\log(n)^{d}} \right) \\
&= \bigcup\limits_{d \geq 1} \operatorname{ DTIME} \left( n^{\log(n)^{d}} \right)
\end{align*}
</div>

<div class="remark" id="orgd7383b5">
<p>
\[
\operatorname{P} \subseteq \operatorname{QuasiP} \subset \operatorname{EXP}.
\]
In general these are strict inclusions, but we do not know that yet at this point in the course.
</p>
</div>

<div class="definition" id="org356d388">
<span class="block-title">Universal Turing Machine</span>
<p>
An <b>Universal Turing machine</b> is a TM \(\mathcal{U}\) that takes as input \(\left< M, x \right>\), where \(M\) is (a description of) a Turing machine, \(x\) is an input word to \(M\), and returns \(M(x)\), i.e. what the TM \(M\) would give for input \(x\).
</p>

<p>
Furthermore, \(\mathcal{U}\) simulates the computation of \(M(x)\).
</p>
</div>

<div class="remark" id="orgadfa214">
<p>
Notes:
</p>
<ul class="org-ul">
<li>The universal TM corresponds to an interpreter.</li>
<li>\(\mathcal{U}\) can have a fixed number of symbols and states but can simulate arbitrary TMs.</li>
<li>Universal TMs exist and can simulate \(M(x)\) efficiently. We can do it with quadratic blowup with 1 tape. With multiple tapes, we can get the blowup down to \(n \log n\).</li>
</ul>
</div>

</details>
</div>
<div id="outline-container-org66db59e" class="outline-2">
<details>
<summary>
<h2 id="org66db59e">Lecture 4: Nondeterministic computing</h2>
</summary>
<div class="outline-text-2" id="text-org66db59e">
</div>
<div class="definition" id="org1fcf7e7">
<span class="block-title">Nondeterministic Turing Machine</span>
<p>
A nondeterministic Turing machine with 1 tape has transition function
\[
\delta : Q \times \Gamma \rightarrow \pot(Q\times \Gamma \times \left\{ 0, -1, 1 \right\})
\]
which maps a state to a set of states, corresponding to the options of the next state. Note that we have no explicit choice over the branching.
</p>
</div>

<div class="definition" id="orgb9bb029">
<span class="block-title">Language Recognition for NTM</span>
<p>
A Nondeterministic Turing machine accepts a language \(L\) if
</p>
<ul class="org-ul">
<li>It always finishes its computation</li>
<li>If \(\omega \in L\), there must exist a computation path that finishes with \(q_{\text{accept}}\).</li>
<li>If \(\omega \not\in L\), all possible branches must finish with \(q_{\text{reject}}\).</li>
</ul>
</div>

<div class="definition" id="org817ef95">
<p>
Let \(M\) be a NTM. Then
</p>
\begin{align*}
\operatorname{time}_M(n) = &\text{ max of the number of steps of all inputs of size } \\
&n \text{ and over all possible choices made non-deterministically}
\end{align*}

<p>
Our definition takes the maximum over all inputs and choices. One can also take the definition where we take the minimum over the choices, but we must be more careful in this instance. For time complexity, both definitions are equivalent - we can always add a counter and keep track of the steps and memory.
</p>
</div>

<p>
We also have a time complexity class for nondeterministic Turing machines.
</p>
<div class="definition" id="org987d89b">
\begin{align*}
\operatorname{NTIME}(f(n)) = &\text{languages or decision problems} \\
& \text{that can be recognized by a NTM \(M\) with} time \\
\operatorname{time}_M(n) = O(f(n)).
\end{align*}
</div>

<div class="definition" id="orgebd620a">
<p>
\[
\operatorname{NP} = \bigcup\limits_{d \geq 1} \operatorname{NTIME}(n^d).
\]
This is the decision problems for which there exists a NTM \(M\) that solves the problem in \(O(n^d)\) for some constant \(d \leq 1\).
</p>

<p>
Note that \(\operatorname{P} \subseteq \operatorname{NP}\), since a deterministic TM is also a nondeterministic TM.
</p>
</div>

<div class="remark" id="org1d4e6bd">
<p>
A big question of computability is whether \(\operatorname{P} = \operatorname{NP}\). It is thought to be an inequality, but we do not know how to approach the problem.
</p>
</div>

<div class="lemma" id="orgcf6399c">
<span class="block-title">An alternative characterization of \(\operatorname{NP}\)</span>
<p>
\(L \in \operatorname{NP}\) if and only if there exists a polynomial time deterministic TM \(M\) and a polynomial \(p\) such that
\[
\forall x \in \left\{ 0, 1 \right\}^{ * } .\,  x \in L \iff \exists y \in \left\{ 0, 1 \right\}^{p(\abs{x})} .\, M(x, y) = 1,
\]
i.e. \(M\) accepts \((x, y)\). We call \(y\) a <b>certificate</b> for \(x\).
</p>

<p>
Note that if the answer is no, there exists no certificate. This means any possible certificate we take will reject.
</p>
</div>

<div class="proof" id="org3bf1862">
<p>
The idea is that we can take \(y\) to be the encoding of the choices made by the machine.
</p>

<ul class="org-ul">
<li><p>
\((\implies)\): Let \(L \in \operatorname{NP}\). There exists a NTM \(M\) that runs in polynomial time \(\operatorname{time}_M(n) = q(n)\). Then
\[
  x \in L \iff \text{ a computation path accepts } x
  \]
We design a deterministic TM \(\widetilde{M}\) that has one extension tape \(T\). In the new tape, we write an encoding of the choices made by \(M\) to accept \(x\). We take  what is written as \(y\). For \(\widetilde{M}\) we make a deterministic transition function that uses the tape \(T\) as additional input which \(\widetilde{M}\) consults to collapse the choice of next state.
</p>

<p>
When \(M\) rejects \(x\), all computation paths lead to rejection, so in particular every \(y\) written in \(T\) leads to rejection in \(\widetilde{M}\).
</p></li>
<li>\(\impliedby\): Say there exists a TM \(M\) with the desired properties and polynomial time complexity. Thus
\[
  x \in L \iff \text{ a computation path accepts } x.
    \]
We define the nondeterministic TM to write \(y\). This means we have \(2^{p(n)}\) options for computation paths. We use a counter to keep track of how much of the certificate we have written. NB that we took the certificate to always be of the length \(p(\abs{x})\). Then after writing out \(y\), we run our \(M(x,y)\). In the branch where \(M(x, y) = 1\), \(\widetilde{M}\) accepts \(x\).</li>
</ul>
</div>

<div class="lexample" id="org0110679">
<p>
An example of a problem in \(\operatorname{NP}\) is computing the independent set. We take a graph \(G\) and \(k \in \N\) as an input and we're computing a set \(U \subseteq V(G)\) such that \(\abs{U} \geq k\) such that
\[
\not\exists u, v \in E(G) . \, \left\{ u, v \right\} \subseteq U
\]
</p>

<p>
A certificate in this case is a \(U \subseteq V(G)\) that satisfies the condition.
</p>
</div>

</details>
</div>
<div class="taglist"><a href="https://www.jure-smolar.com/tags.html">Tags</a>: <a href="https://www.jure-smolar.com/tag-lecture-notes.html">lecture-notes</a> </div>]]></description>
  <category><![CDATA[lecture-notes]]></category>
  <link>https://www.jure-smolar.com/20260224141106-racunska_zahtevnost.html</link>
  <guid>https://www.jure-smolar.com/20260224141106-racunska_zahtevnost.html</guid>
  <pubDate>Tue, 10 Mar 2026 09:41:30 +0100</pubDate>
</item>
<item>
  <title><![CDATA[Teorija programskih jezikov (Pretnar)]]></title>
  <description><![CDATA[
<div id="outline-container-orgb63f6b7" class="outline-2">
<details>
<summary>
<h2 id="orgb63f6b7">Lecture 1: Praksa programskih jezikov</h2>
</summary>
<div class="outline-text-2" id="text-orgb63f6b7">
</div>
<div class="remark" id="org434e69d">
<p>
Razlika med tem kako je jezik implementiran in kako je standardiziran.
</p>
</div>

<div class="definition" id="org2157189">
<span class="block-title">Sintaksa in semantika</span>
<p>
Sintaksa opisuje kako napišemo programe. Semantika opisuje kaj pomenijo.
</p>
</div>

<div class="definition" id="orgb72d1b0">
<span class="block-title">Konkretna in abstraktna sintaksa</span>
<p>
Konkretna sintaksa: zaporedja črk, ki jih zapišemo (besedilo).
Abstraktna sintaksa: syntax trees (AST - abstract syntax tree).
</p>
</div>

<div class="remark" id="org28e41b8">
<p>
Semantiko lahko podajamo na različne načine.
</p>
<ul class="org-ul">
<li>Specificirano z implementacijo</li>
<li>Specificirano s prozo</li>
<li>Specificirano z matematičnimi simboli</li>
<li>Specificirano z matematičnimi objekti (denotacijska semantika)</li>
</ul>
</div>

<div class="remark" id="orgd55c654">
<span class="block-title">Faze urejevalnika</span>
<ol class="org-ol">
<li>Razčlenjevalnik (Parser): Prevodba iz konkretne sintakse v abstraktno sintakso (AST)</li>
<li>Obogatitev drevesa: Preverjanje tipov, optimizacija, ipd.</li>
<li>Interpreter/Compiler: Tolmačimo ali prevedemo v drug jezik/strojno kodo</li>
</ol>
</div>

<div class="lexample" id="org8ae362d">
<span class="block-title">Jezik Imp</span>
<p>
Najpreprostejši učni jezik za definicijo semantike.
</p>

<p>
Implementirali smo type checker.
</p>
</div>

</details>
</div>
<div id="outline-container-org26b9e72" class="outline-2">
<details>
<summary>
<h2 id="org26b9e72">Lecture 2: Indukcija</h2>
</summary>
<div class="outline-text-2" id="text-org26b9e72">
<p>
Podatkovne tipe specificiramo z <i>indukcijo</i>.
</p>
</div>
<div class="definition" id="orgfe832d2">
<p>
\(\N\) je definirana kot najmanjša množica, kjer je
</p>
<ul class="org-ul">
<li>\(0 \in \N\)</li>
<li>\(n \in \N \implies n^{ + } \in \N\)</li>
</ul>

<p>
To zapišemo tudi s pravili izpeljave:
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(0 \in \N\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(n \in \N\)}
\UnaryInfC{\(n^{ + } \in \N\)}
\end{bprooftree}
\end{gather*}
</div>

<div class="definition" id="org7628957">
<p>
Aritmetične izraze lahko podamo kot
\[
e ::= \underline{n} \mid -e \mid e_1 + e_2 \mid e_1 * e_2,
\]
ali s pravili izpeljave:
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{\(n \in \Z\)}
\UnaryInfC{\(\underline{n} \in \mathbb{E}\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(e \in \mathbb{E}\)}
\UnaryInfC{\(-e \in \mathbb{E}\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(e_1 \in \mathbb{E}\)}
\AxiomC{\(e_2 \in \mathbb{E}\)}
\BinaryInfC{\(e_1 + e_2 \in \mathbb{E}\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(e_1 \in \mathbb{E}\)}
\AxiomC{\(e_2 \in \mathbb{E}\)}
\BinaryInfC{\(e_1 * e_2 \in \mathbb{E}\)}
\end{bprooftree}
\end{gather*}

<p>
Z drevesom izpeljave lahko ekonomično pišemo dokaze vsebovanosti.
</p>
</div>

<div class="definition" id="org6257855">
<p>
Induktivna definicija sodosti naravnih števil:
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(0\) je sodo}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(n\) je sodo}
\UnaryInfC{\(n^{ ++ }\) je sodo}
\end{bprooftree}
\end{gather*}
</div>

<div class="definition" id="orgd4bbe27">
<p>
Induktivna definicija relacije manjšega ali enakosti:
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(n \leq n\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(m \leq n\)}
\UnaryInfC{\(m \leq n^{ + }\)}
\end{bprooftree}
\end{gather*}

<p>
Alternativna (ekvivalentna) definicija:
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(0 \leq n\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(m \leq n\)}
\UnaryInfC{\(m^{ + } \leq n^{ + }\)}
\end{bprooftree}
\end{gather*}

<p>
Obe definiciji podata ekvivalentno relacijo.
</p>
</div>

<div class="definition" id="org8d3402b">
<p>
Induktivno relacijo \(R \subseteq X\) lahko predstavimo z družino induktivnih množic \((D_x)_{x \in X}\), kjer \(D_x\) predstavlja množico dokazov, da je \(x \in R\).
</p>

<p>
Obratno, iz vsake družine \((D_x)_{x \in X}\) lahko definiramo relacijo \(R \subseteq X\) kot
\[
R = \left\{ x \in X \mid D_x \neq \emptyset \right\}.
\]
</p>
</div>

<div class="lexample" id="orgaec3d36">
<p>
Definirajmo družino \((S_n)_{n \in \N}\) s pravili
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(\text{NicSodo} \in S_{0}\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(d \in S_n\)}
\UnaryInfC{\(\text{NaslNaslSodo } d \in S_{n^{ ++ }}\)}
\end{bprooftree}
\end{gather*}

<p>
Elementi \(S_n\) so dokazni drevesi, da je \(n\) sodo.
</p>
</div>

<div class="remark" id="org14182b1">
<p>
Pri aritmetičnih izrazih:
</p>
<ul class="org-ul">
<li>Ker imamo konstante, moramo imeti vsaj \(I_0 = \{\underline{n} \mid n \in \Z\}\)</li>
<li>Zaradi pravila \(\operatorname{Plus}\) imamo tudi \((\underline{0} + \underline{0}) \in I_1\), podobno za \(\operatorname{Krat}\) in \(\operatorname{Minus}\)</li>
<li>Iz teh dobimo dodatne elemente, kot so \(((\underline{0} + \underline{0}) * \underline{0}) \in I_2\)</li>
</ul>

<p>
Ideja je, da na vsakem koraku iz do sedaj zgrajenih elementov \(I_n\) dobimo množico \(I_{n+1}\). To konstrukcijo bomo opisali s funktorjem.
</p>
</div>

<div class="lexample" id="org5ea7566">
<span class="block-title">Funktor za naravna števila</span>
<p>
Naravna števila predstavimo s funktorjem
\[
FX = 1 + X
\]
</p>

<p>
Tu \(X\) predstavlja že sestavljene elemente. Iterirana aplikacija predstavlja dodajanje vseh novih izrazov na danem koraku:
</p>
<ul class="org-ul">
<li>\(I_0 = \emptyset\)</li>
<li>\(I_1 = 1 + \emptyset = \{\iota_0(\cdot)\}\)</li>
<li>\(I_2 = 1 + I_1 = \{\iota_0(\cdot), \iota_1(\iota_0(\cdot))\}\)</li>
<li>\(I_3 = 1 + I_2 = \{\iota_0(\cdot), \iota_1(\iota_0(\cdot)), \iota_1(\iota_1(\iota_0(\cdot)))\}\)</li>
</ul>

<p>
In tako dalje. Pišemo \(\iota_0(\cdot) = 0\) in \(n^{ + } = \iota_1(n)\).
</p>
</div>

<div class="lexample" id="org0e012e5">
<p>
Aritmetične izraze predstavimo s funktorjem
\[
FX = \Z + X + 2X^2
\]
</p>

<p>
kjer \(\Z\) predstavlja konstante, \(X\) unarni operatorji in \(2X^2\) binarni operatorji.
</p>
</div>
<div class="theorem" id="orgfbc52b7">
<p>
Naj bo \(F\) funktor, ki je monoton in Scottovo zvezen. Potem ima \(F\) najmanjšo fiksno točko, ki jo označimo z \(\mu F\).
</p>

<p>
Monotonost: \(X \subseteq Y \implies FX \subseteq FY\)
</p>

<p>
Scottova zveznost:
\[
F\left(\bigcup_{i=1}^{\infty} X_i\right) = \bigcup_{i=1}^{\infty} FX_i
\]
</p>

<p>
Najmanjša fiksna točka je
\[
\mu F = \bigcup_{i=1}^{\infty} F^i \emptyset
\]
</p>

<p>
To je najmanjša množica, zaprta za \(F\):
\[
FX \subseteq X \implies \mu F \subseteq X
\]
</p>

<p>
Opomba: Potenčna množica ni Scottovo zvezna.
</p>
</div>

<div class="proof" id="org4f91754">
<p>
Pišimo \(I_0 = \emptyset\) in \(I_{n+1} = FI_n\) ter \(I = \bigcup_{i=1}^{\infty} I_i\).
</p>

<p>
Najprej pokažimo, da je \(\mu F\) fiksna točka.
</p>

<p>
\textit{(1) \(I \subseteq FI\)):}
</p>

<p>
Imamo \(I_0 = \emptyset \subseteq I_1\), zato je po monotonosti tudi \(I_1 = F\emptyset \subseteq FI_1 = I_2\), in tako dalje. Zato \(I_n \subseteq FI_n\) za vsak \(n\). Potem je
\[
I = \bigcup_j I_j \subseteq \bigcup_j FI_j \subseteq FI.
\]
</p>

<p>
Zadnja inkluzija velja, ker je \(I_j \subseteq I\) za vsak \(j\), zato je \(FI_j \subseteq FI\) po monotonosti, torej tudi \(\bigcup_j FI_j \subseteq FI\).
</p>

<p>
\textit{(2) \(FI \subseteq I\)):}
</p>

<p>
Naj bo \(x \in FI\). Po definiciji \(x\) nastane iz končno mnogo elementov \(I_k\) za neki fiksni \(k\). Zato je \(x \in FI_k = I_{k+1} \subseteq I\). Torej \(FI \subseteq I\).
</p>

<p>
\textit{(3) Minimalnost:} Če je \(FX \subseteq X\), je \(I \subseteq X\).
</p>

<p>
Imamo \(\emptyset \subseteq X\). Ker je \(F\emptyset \subseteq FX \subseteq X\), je \(I_1 \subseteq X\). Induktivno, če je \(I_j \subseteq X\), je \(I_{j+1} = FI_j \subseteq FX \subseteq X\). Zato je
\[
I = \bigcup_{j=1}^{\infty} I_j \subseteq X.
\]
</p>
</div>

</details>
</div>
<div id="outline-container-org71f79b2" class="outline-2">
<details>
<summary>
<h2 id="org71f79b2">Lecture 3: Indukcija 2</h2>
</summary>
<div class="outline-text-2" id="text-org71f79b2">
</div>
<div class="remark" id="orgef204fb">
<p>
Lastnost \(\mu F\) lahko uporabimo za dokazovanje z indukcijo.
</p>

<p>
Naj bo \(P \subseteq \mu F\) zaprta za \(F\), torej \(FP \subseteq P\). Po izreku sledi \(P = \mu F\).
</p>
</div>
<div class="lexample" id="org44acb51">
<p>
\(P \subseteq \N\) naj bo nek predikat na \(\N\), zaprt za \(F : X \rightarrow 1 + X\). Razpišim \(FP \subseteq P\).
</p>

\begin{align*}
FP &\subseteq P \\
n \in FP &\implies n \in P \\
n \in 1 + P &\implies n \in P \\
n = \iota_0( * ) \lor \exists m \in P . \, n \iota_1(n) & \implies n \in P
\end{align*}

<p>
To pomeni, da imamo
\[
0 \in P \lor \forall m \in \N \implies m \in P \implies m^{ + } \in P
\]
Rekonstruirali smo načelo indukcije za naravna števila.
</p>
</div>
<div id="outline-container-orgfe8419a" class="outline-3">
<details>
<summary>
<h3 id="orgfe8419a">Konstrukcija primitivne rekurzije</h3>
</summary>
<div class="outline-text-3" id="text-orgfe8419a">
<div class="lexample" id="orgefcbf9e">
<p>
S pomočjo funktorja \(F\) lahko izrazimo tudi primitivno rekurzivne funkcije na \(\mu F\).
</p>

<p>
Recimo, za \(\operatorname{ev} : \mathbb{E} \rightarrow \Z\) imamo
</p>
\begin{align*}
\operatorname{ev}(\underline{n}) &= n
\operatorname{ev}(e_1 + e_2) &= \operatorname{ev}(e_1) + \operatorname{ev}(e_2)
\operatorname{ev}(e_1 * e_2) &= \operatorname{ev}(e_1) \cdot \operatorname{ev}(e_2)
\operatorname{ev}(-e) &= -\operatorname{ev}(e)
\end{align*}

<p>
NB primitivno rekurzivna funkcija je podana že s štirimi funkcijami:
</p>
\begin{align*}
\alpha_{1} &: \N \rightarrow \Z
\alpha_{2} &: \Z \times \Z \rightarrow \Z
\alpha_{3} &: \Z\times \Z\rightarrow \Z
\alpha_{4} &: \Z \rightarrow \Z
\end{align*}
<p>
kar lahko predstavimo ravno s preslikavo
\[
\alpha : \N + \Z \times \Z + \Z \times \Z + \Z \rightarrow \Z.
\]
To je ravno \(F\Z\). To je <b>algebra</b> za funktor \(F\).
</p>
</div>
</div>

</details>
</div>
<div class="definition" id="orga534a1a">
<p>
Algebra za funktor \(F\) je
</p>
<ul class="org-ul">
<li>Množica \(X\)</li>
<li>Preslikava \(\alpha : FX \rightarrow X\)</li>
</ul>
<p>
Homomorfizem algebr je homomorfizm algebr.
</p>
</div>
<div id="outline-container-org24b0e90" class="outline-3">
<details>
<summary>
<h3 id="org24b0e90">Trditev: Obstoj začetne algebre.</h3>
</summary>
<div class="outline-text-3" id="text-org24b0e90">
<div class="proposition" id="org6d16f60">
<p>
Algebra \((\mu F, \operatorname{id} : \mu F = F \mu F \rightarrow F \mu F)\) je <b>začetna algebra</b> za \(F\). Za poljubno algebro \(X, \alpha\) obstaja enoličen homomorfizem \(\alpha : \mu F \rightarrow X\).
</p>
</div>
</div>

</details>
</div>

</details>
</div>
<div id="outline-container-org3df33c5" class="outline-2">
<details>
<summary>
<h2 id="org3df33c5">Lecture 3: Metateorija programskih jezikov</h2>
</summary>
<div class="outline-text-2" id="text-org3df33c5">
</div>
<div class="definition" id="orgaebffbd">
<span class="block-title">Sintaksa jezika Imp</span>
<p>
Za množico lokacij \(l \in \mathbb{L}\) definiramo sinkakso jezika
</p>
\begin{align*}
e &::= \underline{n} \mid e_1 + e_2 \mid e_1 * e_2 \mid -e \mid l \\
b &::= \text{true} \mid \text{false} \mid e_1 < e_2 \mid e_1 = e_2 \mid e_1 > e_2 \\
c &::= \text{skip} \mid c_1 ; c_2 \mid \text{if } b \text{ then } c_1 \text{ else } c_2 \mid l := e \mid \text{while } b \text{ do } c
\end{align*}
</div>

<p>
Semantiko izrazov bomo podali operacijsko &#x2013; prek relacij, ki bodo opisale korake računanja. Imamo dve različici.
</p>
<div class="remark" id="org6877440">
<ul class="org-ul">
<li>Mali koraki: \((2 + 4) * 7 \rightsquigarrow 6 * 7 \rightsquigarrow 42\)</li>
<li>Veliki koraki: \((2 + 4) * 7\ \rightsquigarrow 42)</li>
</ul>
</div>
<div id="outline-container-org03525dd" class="outline-3">
<details>
<summary>
<h3 id="org03525dd">Imp - Semantika</h3>
</summary>
<div class="outline-text-3" id="text-org03525dd">
<div class="definition" id="orgb961780">
<span class="block-title">Semantika jezika Imp</span>
<p>
Naj bo \(\mathbb{S} = \Z_{\bot}^{\mathbb{L}}\) množica stanj pomnilnika. Evaluacijo aritmetičnih izrazov podamo z relacijo \(s, e \Downarrow n \subseteq \mathbb{S} \times \mathbb{E} \times \Z\).
</p>

\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(S, \underline{n} \Downarrow n\) }
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(S, e_1 \Downarrow n_1\)}
\AxiomC{\(S, e_2 \Downarrow n_2\)}
\BinaryInfC{\(S, e_1 + e_2 \Downarrow n_1 + n_2\)}
\end{bprooftree}
\qquad
\begin{bprooftree}
\AxiomC{\(S, e_1 \Downarrow n_1\)}
\AxiomC{\(S, e_2 \Downarrow n_2\)}
\BinaryInfC{\(S, e_1 * e_2 \Downarrow n_1 \cdot n_2\)}
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(S, e \Downarrow n\)}
\UnaryInfC{\(S, -e \Downarrow -n\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(s(l) \neq \bot\)}
\UnaryInfC{\(s, l \Downarrow s(l)\) }
\end{bprooftree}
\end{gather*}

<p>
Za logične izraze imamo relacijo \(s, b \Downarrow r \in \mathbb{B} = \left\{ \mathit{tt}, \mathit{ff} \right\}\)
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(S, \text{true} \Downarrow \mathit{tt} \)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(S, \text{false} \Downarrow \mathit{ff} \)}
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(S, e_1 \Downarrow n_1\)}
\AxiomC{\(S, e_2 \Downarrow n_2\)}
\AxiomC{\(n_1 < n_2\)}
\TrinaryInfC{\(S, e_1 < e_2 \Downarrow \mathit{tt}\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(S, e_1 \Downarrow n_1\)}
\AxiomC{\(S, e_2 \Downarrow n_2\)}
\AxiomC{\(n_1 \geq n_2\)}
\TrinaryInfC{\(S, e_1 < e_2 \Downarrow \mathit{ff}\)}
\end{bprooftree}
\end{gather*}
<p>
in podobno za ostale.
</p>

\begin{prooftree}
\AxiomC{\(S, c_1 \leadsto S', c_1'\)}
\UnaryInfC{\(S, (c_1 ; c_2) \leadsto S', (c_1', c_2)\)}
\end{prooftree}

\begin{prooftree}
\AxiomC{\(\)}
\UnaryInfC{\(S, (\text{skip} ; c_2) \leadsto S, c_2\)}
\end{prooftree}

\begin{prooftree}
\AxiomC{\(S, b \Downarrow \mathit{tt}\)}
\UnaryInfC{\(S,\ \text{if } b \text{ then } c_1 \text{ else } c_2 \leadsto S, c_1\)}
\end{prooftree}
<p>
Podobno za \(\mathit{ff}\) in \(c_2\).
</p>

\begin{prooftree}
\AxiomC{\(S, e \Downarrow n\)}
\UnaryInfC{\(S, l := e \leadsto S[l \mapsto n], \text{ skip}\)}
\end{prooftree}

\begin{prooftree}
\AxiomC{\(S, b \Downarrow \mathit{ff}\)}
\UnaryInfC{\(S, \text{ while } b \text{ do } c \leadsto S, \text{ skip}\)}
\end{prooftree}

\begin{prooftree}
\AxiomC{\(S, b \Downarrow \mathit{tt}\)}
\UnaryInfC{\(S, \text{ while } b \text{ do } c \leadsto S, (c ; \text{ while } b \text{ do } c)\)}
\end{prooftree}

<p>
Da izključimo možnost neveljavnega branja iz pomnilnika, podajmo relacije za preverjanje veljavnosti. Z \(L\) označimo množice lokacij. Pišemo \(L \vdash e\) ko je \(e\) veljavna za veljavne lokacije \(L\).
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(L \vdash \underline{n}\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(L \vdash e_1\)}
\AxiomC{\(L \vdash e_2\)}
\BinaryInfC{\(L \vdash e_1 + e_2\)}
\end{bprooftree}
\quad \text{ podobno za ostale operacije. } \\
\begin{bprooftree}
\AxiomC{\(l \in L\)}
\UnaryInfC{\(L \vdash l\) }
\end{bprooftree}
\end{gather*}
<p>
Podobno za \(L \vdash b\). Moramo še podati pravila oblike \(L \vdash c, L'\).
</p>
\begin{gather*}
\begin{bprooftree}
\AxiomC{}
\UnaryInfC{\(L \vdash \text{ skip}, L\) }
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(L \vdash c_1, L'\)}
\AxiomC{\(L' \vdash c_2, L''\)}
\BinaryInfC{\(L \vdash (c_1 ; c_2), L''\) }
\end{bprooftree}
\\
\begin{bprooftree}
\AxiomC{\(L \vdash b\)}
\AxiomC{\(L \vdash c_1, L_1\)}
\AxiomC{\(L \vdash c_2, L_2\)}
\TrinaryInfC{\(L \vdash \text{ if } b \text{ then } c_1 \text{ else } c_2, L_1 \cap L_2\)}
\end{bprooftree}
\text{ lahko bi vzeli tudi samo } L \text{ (lokalni bind)}
\\
\begin{bprooftree}
\AxiomC{\(L \vdash b\)}
\AxiomC{\(L \vdash c, L'\)}
\BinaryInfC{\(L \vdash \text{ while } b \text{ do } c, L\)}
\end{bprooftree}
\quad
\begin{bprooftree}
\AxiomC{\(L \vdash e\)}
\UnaryInfC{\(L \vdash l := e, L \cup \left\{ l \right\}\) }
\end{bprooftree}
\end{gather*}
</div>
</div>

</details>
</div>
<p>
S tem lahko končno podamo netrivialno drevo izpeljave.
</p>
<div class="lexample" id="orgf421982">
\begin{prooftree}
\AxiomC{}
\UnaryInfC{\(S, \underline{3} \Downarrow 3\)}
\AxiomC{\(S(a) = 10 \neq \bot\)}
\UnaryInfC{\(S, a \Downarrow 10\)}
\AxiomC{}
\UnaryInfC{\(S, b \Downarrow 4\)}
\BinaryInfC{\(S, a + b \Downarrow 14\)}
\BinaryInfC{\(S, \underline{3} * (a + b) \Downarrow 42\)}
\end{prooftree}
</div>
<div class="proposition" id="orgdebecb1">
<span class="block-title">Napredek</span>
<p>
Naj bo \(L \subseteq \left\{ l \mid S(l) \neq \bot  \right\}\) in naj velja \(L \vdash c, L'\).
</p>

<p>
Tedaj velja:
</p>
<ul class="org-ul">
<li>Bodisi \(c = \text{skip}\)</li>
<li>Bodisi obstajata \(s', c'\), da velja \(s, c \leadsto s', c'\)</li>
</ul>
</div>

<div class="proof" id="orgcb732c5">
<p>
Z indukcijo na \(L \vdash c, L'\) na drevo izpeljave.
</p>

<p>
Recimo, da je zadnje uporabljeno pravilo:
</p>
<ul class="org-ul">
<li>\begin{prooftree}
\AxiomC{}
\UnaryInfC{\(L \vdash \text{skip, } L\) }</li>
</ul>
<p>
\end{prooftree}
Potem velja \(c = \) skip.
</p>
<ul class="org-ul">
<li>\begin{prooftree}</li>
</ul>
<p>
\AxiomC{\(L \vdash c_1, L'\)}
\AxiomC{\(L' \vdash c_2, L''\)}
\BinaryInfC{\(L \vdash (c_1 ; c_2), L''\)}
 \end{prooftree}
 po indukcijski predpostavki za \(L \vdash c_1, L'\) velja
</p>
<ol class="org-ol">
<li>bodisi \(c_1 = \) skip, zato \(s, (\text{skip} ; c_2) \leadsto s, c_2\).</li>
<li>bodisi \(s, c_1 \leadsto s', c_1'\), zato \(s, (c_1 ; c_2) \leadsto s', (c_1'; c_2)\).</li>
</ol>
<p>
in tako dalje.
</p>
</div>
<div class="proposition" id="org343233a">
<span class="block-title">Ohranitev</span>
<p>
Naj velja \(L \vdash c, L'\) in \(s, c \leadsto s', c' za nek \(L \subseteq \left\{ l \mid s(l) \neq \bot \right\} \).
</p>

<p>
Tedaj velja tudi \(L'' \vdash c', L'\) za nek \(L \subseteq L''\), da velja
\[
L'' \subseteq \left\{ l \mid s'(l) \neq \bot \right\}.
\]
</p>
</div>

<div class="lexample" id="org11197a5">
<p>
Če imamo \(\underbrace{\emptyset}_{L} \vdash (l := 3, m := 4), \underbrace{\left\{ l, m \right\}}_{L'}\) je potem \(L'' = \left\{ l \right\}\).
</p>
</div>

</details>
</div>
<div class="taglist"><a href="https://www.jure-smolar.com/tags.html">Tags</a>: <a href="https://www.jure-smolar.com/tag-lecture-notes.html">lecture-notes</a> </div>]]></description>
  <category><![CDATA[lecture-notes]]></category>
  <link>https://www.jure-smolar.com/20260220110630-teorija_programskih_jezikov.html</link>
  <guid>https://www.jure-smolar.com/20260220110630-teorija_programskih_jezikov.html</guid>
  <pubDate>Tue, 10 Mar 2026 09:41:30 +0100</pubDate>
</item>
<item>
  <title><![CDATA[Kardinalna aritmetika (Simpson)]]></title>
  <description><![CDATA[
<p>
Warning: The notes are not optimized for HTML (yet). Without warranty.
</p>
<div id="outline-container-org16fcc2b" class="outline-2">
<details>
<summary>
<h2 id="org16fcc2b">Lecture 1 - Introduction</h2>
</summary>
<div class="outline-text-2" id="text-org16fcc2b">
</div>
<div class="definition" id="org65e6120">
<span class="block-title">Continuum Hypothesis</span>
<p>
Every infinite subset of \(\R\) is either in bijection with \(\N\) or in bijection with \(\R\).
</p>

<p>
This is independent from ZFC.
</p>
</div>

<p>
We also have a more explicit stronger version.
</p>

<div class="definition" id="orgda3d5d7">
<span class="block-title">ACH: The \(\aleph\) continuum hypothesis</span>
<p>
\[
2^{\aleph_0} = \aleph_1
\]
as an equation in cardinal arithmetic. Note that this version implies the regular continuum hypothesis.
</p>
</div>

<div class="remark" id="org06afb9d">
<ul class="org-ul">
<li>Interrelationship with general math</li>
<li>Touted as a foundation for mathematics</li>
<li>Leads to new interesting areas of mathematics</li>
<li>Provides the tools for studying independence questions</li>
</ul>
</div>

<div class="definition" id="orgc7a52e9">
<p>
We give the axioms in a way that mirrors the way mathematicians actually use them.
</p>

<p>
Our axioms will tell us which classes can be sets:
</p>
<ul class="org-ul">
<li>Assume a <b>universe</b> \(\mathcal{U}\) of all mathematical entities that we may use as elements of sets.</li>
<li>A collection of elements of the universe is called a <b>class</b>.</li>
<li>If \(P(x)\) is a property of elements of \(\mathcal{U}\), then \(\{x \mid P(x)\}\) satisfies
\[
  y \in \{x \mid P(x)\} \iff P(y).
  \]</li>
<li>A <b>set</b> is a class that is itself an element of \(\mathcal{U}\).</li>
</ul>
</div>

<div class="theorem" id="org97cf345">
<span class="block-title">Russell's Paradox</span>
<p>
Not every class is a set.
</p>
</div>

<div class="proof" id="orgc3d7606">
<p>
Let
\[
\underline{R} = \{x \mid x \text{ is a set and } x \not\in x\}
\]
be a class. If \(\underline{R}\) were a set, then
\[
\underline{R} \in \underline{R} \iff \underline{R} \not\in \underline{R},
\]
a contradiction.
</p>
</div>

<div class="axiom" id="org95b0228">
<span class="block-title">Extensionality</span>
<p>
If \(\underline{X}, \underline{Y}\) are classes and \(\forall z.\, z \in \underline{X} \iff z \in \underline{Y}\), then \(\underline{X} = \underline{Y}\).
</p>
</div>

<div class="axiom" id="orgfa1748e">
<span class="block-title">Empty Set</span>
<p>
\(\emptyset := \{x \mid \bot\}\) is a set.
</p>
</div>

<div class="axiom" id="org1870d52">
<span class="block-title">Pairing</span>
<p>
For any \(x, y\), \(\{x, y\} := \{z \mid z = x \lor z = y\}\) is a set. In particular \(\{x\} := \{x,x\}\) is a set.
</p>
</div>

<div class="axiom" id="org3854c40">
<span class="block-title">Union</span>
<p>
For a class \(\underline{X}\) of sets,
\[
\bigcup \underline{X} := \{z \mid \exists Y \in \underline{X}.\, z \in Y\}.
\]
If \(X\) is a set of sets, then \(\bigcup X\) is a set.
</p>
</div>

<div class="axiom" id="orgb8cc253">
<span class="block-title">Powerset</span>
<p>
For a class \(\underline{X}\), we define its <b>powerclass</b> as
\[
\mathcal{P}\underline{X} := \{Y \mid Y \text{ is a subset of } \underline{X}\}.
\]
If \(X\) is a set, then \(\mathcal{P}X\) is a set. We call it a <b>powerset</b>.
</p>
</div>

<div class="axiom" id="org16b6cf1">
<span class="block-title">Separation</span>
<p>
If \(X\) is a set and \(P(x)\) is a property of elements of \(\mathcal{U}\), then
\[
\{x \in X \mid P(x)\}
\]
is a set.
</p>
</div>

<div class="axiom" id="org28434f8">
<span class="block-title">Replacement</span>
<p>
If \(X\) is a set and \(F : X \rightarrow \mathcal{U}\) is a class function, then \(\operatorname{image}(F)\) is a set.
</p>

<p>
A <b>class function</b> from \(\underline{X}\) to \(\underline{Y}\) is a property \(F(x,y)\) of elements \(x,y\) of \(\mathcal{U}\) satisfying:
</p>
<ol class="org-ol">
<li>For all \(x \in \underline{X}\) there exists a unique \(y \in \underline{Y}\) such that \(F(x,y)\).</li>
<li>If \(F(x,y)\), then \(x \in \underline{X}\) and \(y \in \underline{Y}\).</li>
</ol>
<p>
Then
\[
\operatorname{image}(F) := \{y \in \underline{Y} \mid \exists x \in \underline{X}.\, F(x,y)\}.
\]
</p>
</div>

<div class="definition" id="orgd18a1ff">
<span class="block-title">Product of Classes</span>
<p>
A <b>product</b> of classes \(\underline{X}\) and \(\underline{Y}\) is a class \(\underline{X} \times \underline{Y}\) together with class functions \(\pi_1 : \underline{X} \times \underline{Y} \rightarrow \underline{X}\) and \(\pi_2 : \underline{X} \times \underline{Y} \rightarrow \underline{Y}\) satisfying
\[
\forall x \in \underline{X}.\, \forall y \in \underline{Y}.\, \exists! z \in \underline{X} \times \underline{Y}.\, \pi_1(z) = x \land \pi_2(z) = y.
\]
</p>
</div>

<div class="proposition" id="org4e61a44">
<span class="block-title">Uniqueness of Products</span>
<p>
Any two products of \(\underline{X}\) and \(\underline{Y}\) are isomorphic.
</p>
</div>

<div class="theorem" id="org3ea6268">
<span class="block-title">Existence of Products</span>
<p>
For every \(\underline{X}\) and \(\underline{Y}\), a product \(\underline{X} \times \underline{Y}\) with \(\pi_1, \pi_2\) exists.
</p>
</div>

<div class="proof" id="org6585b5f">
<p>
Define
\[
\underline{X} \times \underline{Y} := \left\{ \left\{ \{x\}, \{x, y\} \right\} \mid x \in \underline{X},\, y \in \underline{Y} \right\}
\]
and
\[
\pi_1(z) := \text{the unique } x \in \underline{X} \text{ such that } \exists y \in \underline{Y}.\, z = \{\{x\}, \{x,y\}\},
\]
and similarly for \(\pi_2\).
</p>
</div>

<div class="proposition" id="orgce24727">
<p>
If \(X\) and \(Y\) are sets, then so is \(X \times Y\).
</p>
</div>

<div class="definition" id="org80b8f82">
<p>
Suppose \(F : \underline{X} \rightarrow \underline{Y}\) is a class function. Its <b>graph</b> is
\[
\Gamma(F) := \{(x, y) \in \underline{X} \times \underline{Y} \mid y = F(x)\} \subseteq \underline{X} \times \underline{Y}.
\]
If \(X\) is a set and \(F : X \rightarrow Y\) is a class function, then \(\Gamma(F)\) is a set by Replacement.
</p>

<p>
The <b>exponential class</b> is defined as
\[
\underline{Y}^{X} := \left\{ \Gamma(F) \mid F : X \rightarrow \underline{Y} \text{ is a function} \right\}.
\]
</p>
</div>

<div class="proposition" id="orga524a21">
<p>
If \(Y\) is a set then \(Y^X\) is a set.
</p>
</div>

<div class="definition" id="orgf2f9ea9">
<span class="block-title">Natural Number Structure</span>
<p>
A <b>natural number structure</b> is a triple \((\underline{N}, 0, S)\) where \(\underline{N}\) is a class, \(0 \in \underline{N}\), and \(S : \underline{N} \rightarrow \underline{N}\) satisfying:
</p>
<ol class="org-ol">
<li>\(S\) is injective: \(\forall x, y \in \underline{N}.\, S(x) = S(y) \implies x = y\).</li>
<li>Acyclicity: \(\forall x \in \underline{N}.\, S(x) \neq 0\).</li>
<li>Induction: if \(\underline{X}\) satisfies \(0 \in \underline{X}\) and \(\forall x \in \underline{N}.\, x \in \underline{X} \implies S(x) \in \underline{X}\), then \(\underline{N} \subseteq \underline{X}\).</li>
</ol>
</div>

<div class="theorem" id="org0ae47cf">
<p>
A natural number structure exists.
</p>
</div>

<div class="proof" id="org53469c7">
<p>
Construct \(\underline{N}\) as the class of Von Neumann natural numbers (see below).
</p>
</div>

<div class="theorem" id="orgba107ba">
<span class="block-title">Recursion Theorem</span>
<p>
Suppose \(\mathcal{A}\) is a class, \(a \in \mathcal{A}\), and \(F : \mathcal{A} \rightarrow \mathcal{A}\). Then there exists a unique class function \(R : \underline{N} \rightarrow \mathcal{A}\) such that
</p>
<ol class="org-ol">
<li>\(R(0) = a\),</li>
<li>\(R(S(x)) = F(R(x))\).</li>
</ol>
</div>

<div class="theorem" id="orgf782444">
<span class="block-title">Parametrised Recursion Theorem</span>
<p>
Suppose \(\mathcal{A}\) is a class, \(\mathcal{Z}\) is a class, \(a : \mathcal{Z} \rightarrow \mathcal{A}\), and \(F : \mathcal{Z} \times \mathcal{A} \rightarrow \mathcal{A}\). Then there exists a unique class function \(R : \mathcal{Z} \times \underline{N} \rightarrow \mathcal{A}\) such that
</p>
<ol class="org-ol">
<li>\(R(z, 0) = a(z)\),</li>
<li>\(R(z, S(x)) = F(z, R(z, x))\).</li>
</ol>
</div>

<div class="definition" id="orgb884938">
<p>
Apply the PRT with \(\mathcal{A} = \underline{N}\), \(\mathcal{Z} = \underline{N}\), \(B(z) = z\), and \(F(z, x) = S(x)\). The unique resulting
\[
R : \underline{N} \times \underline{N} \rightarrow \underline{N}
\]
satisfies
</p>
\begin{align*}
R(z, 0) &= z, \\
R(z, S(x)) &= S(R(z, x)).
\end{align*}
<p>
This \(R\) is <b>addition</b> on \(\underline{N}\).
</p>
</div>

<div class="definition" id="org205a84e">
<span class="block-title">Von Neumann Natural Numbers</span>
<p>
For a set \(n\) define \(n^{+} := n \cup \{n\}\). A set \(X\) is a <b>vN-number</b> if:
</p>
<ol class="org-ol">
<li>For every subset \(Y \subseteq X\) satisfying
\[
   \emptyset \in X \implies \emptyset \in Y \quad \text{and} \quad \forall z \in Y.\, z^{ + } \in X \implies z^{ + } \in Y,
   \]
it holds that \(Y = X\).</li>
<li>\(X = \emptyset\) or \(\exists z \in X\) such that \(X = z^{+}\).</li>
</ol>

<p>
The class of all vN-numbers is
\[
\mathrm{vN} := \{x \mid x \text{ is a set and a vN-number}\}.
\]
</p>
</div>

<div class="axiom" id="org679ec68">
<span class="block-title">Axiom of Infinity</span>
<p>
The Von Neumann natural numbers structure is a set. Equivalently:
\[
\exists X.\, \emptyset \in X \land \forall y \in X.\, y \text{ is a set} \implies y^{+} \in X.
\]
</p>
</div>

<div class="remark" id="org5fac76a">
<p>
The axioms of set theory (ZFC-style, synthetic formulation):
</p>
<ul class="org-ul">
<li>Extensionality</li>
<li>Empty Set</li>
<li>Pairing</li>
<li>Powerset</li>
<li>Separation</li>
<li>Replacement</li>
<li>Axiom of Infinity</li>
</ul>
</div>

</details>
</div>
<div id="outline-container-orgbcfb69f" class="outline-2">
<details>
<summary>
<h2 id="orgbcfb69f">Lecture 2 - Comparison of cardinalities</h2>
</summary>
<div class="outline-text-2" id="text-orgbcfb69f">
</div>
<div class="remark" id="org56f46f8">
<p>
Suppose \(A\) is a set and \(\underline{B}\) a class and we have
\[
A \twoheadrightarrow \underline{B}
\]
surjective, then \(\underline{B}\) is a set (replacement).
</p>

<p>
Suppose \(\underline{A}\) is a class and \(B\) a set and we have
\[
A \underline{}\rightarrowtail B,
\]
then \(\underline{A}\) is a set (separation + replacement).
</p>

<p>
We will see how crazily big sets will get, hence them being small really is only in comparison to classes.
</p>
</div>

<div class="definition" id="org390e57e">
<p>
Two sets \(A, B\) <b>have the same cardinality</b> (bijective correspondene, isomorphic, equipotent), if there exists a bijective function
\[
f : A \rightarrow B.
\]
</p>

<p>
Our notation will be
\[
\abs{A} = \abs{B}.
\]
We don't yet have an independent meaning for \(\abs{A}\).
</p>
</div>

<div class="remark" id="orgdc86b35">
<p>
Since \(\abs{\cdot} = \abs{\cdot}\) is an isomorphism, it is in particular an equivalence relation.
</p>
</div>

<div class="definition" id="org3990db5">
<p>
A set \(A\) has cardinality less than or equal to a set \(B\) if there exists an injective function
\[
i : A\rightarrowtail B.
\]
</p>

<p>
We write
\[
\abs{A} \leq \abs{B}.
\]
</p>
</div>

<div class="remark" id="org6e5d6fe">
<ul class="org-ul">
<li>The relation is obviously reflexive and transitive due to monomorphism composition.</li>
<li>We have antisymmetry due to a deeper theorem: CSB.</li>
<li>We also wonder about linear ordering - we will get this, but only under choice.</li>
</ul>
</div>

<div class="theorem" id="org91aecbf">
<span class="block-title">Cantor-Schröder-Bernstein</span>
<p>
Assume \(\abs{A} \leq \abs{B}\) and \(\abs{B} \leq \abs{A}\). Then \(\abs{A} = \abs{B}\).
</p>
</div>

<div class="proof" id="org6e43279">
<p>
We have injective functions
\[
f : A \rightarrow B \quad g : B \rightarrow A.
\]
Define \(A_0 = A\) and \(B_0 = \im(g)\).
</p>

<p>
Then
\[
g \circ f : A \rightarrow B_0
\]
is injective so \(\abs{A_0} \leq \abs{B_0}\). By using the CSB lemma, we have
\[
\abs{A} = \abs{A_0}  = \abs{B_0} = \abs{B}.
\]
</p>
</div>

<div class="lemma" id="org55f356e">
<span class="block-title">CSB Lemma</span>
<p>
If \(B_0 \subseteq A_0\) and \(\abs{A_0} \leq \abs{B_0}\), then \(\abs{B_0} = \abs{A_0}\).
</p>
</div>

<div class="proof" id="orgdea27dc">
<p>
Let \(f : A_0 \rightarrow B_0\) be injective. Define
</p>
\begin{align*}
A_{n+1} &:= f(A_n) \\
B_{n+1} &:= f(B_n)
\end{align*}

<p>
Define \(C_n = A_n \setminus B_n \) and
\[
C = \bigcup\limits_n C_n
\]
and
\[
D = A_0 \setminus C
\]
Then
\[
f : C \rightarrow C \setminus C_0
\]
is a bijection.
</p>

<p>
Then
\[
B_0 = B \uplus C \setminus C_0 \cong D \uplus C = A_0.
\]
</p>
</div>

<div class="definition" id="org36a345b">
<p>
A set \(A\) has cardinality strictly less than a set \(B\) if
\[
\abs{A} < \abs{B} :\iff \abs{A} \leq \abs{B} \land \abs{A} \neq \abs{B}.
\]
</p>
</div>

<div class="remark" id="orge26f308">
<ul class="org-ul">
<li>Irreflexive and transitive.</li>
<li>\(\abs{A} \leq \abs{B} < \abs{C} \leq \abs{D} \implies \abs{A} < \abs{D}\).</li>
<li>Not linear, even with choice.</li>
</ul>
</div>

<div class="definition" id="org6f3ced6">
<p>
\(\abs{A} \ll \abs{B} :\iff \abs{A} \leq \abs{B}\) and there is no surjection from \(A\) to \(B\).
</p>

<p>
If \(\abs{A} \ll \abs{B}\), then \(\abs{A} < \abs{B}\), and we again have the sandwiching property
\[
\abs{A} \leq \abs{B} \ll \abs{C} \leq \abs{D} \implies \abs{A} \ll \abs{D}.
\]
</p>
</div>

<div class="definition" id="orga17cdbd">
<span class="block-title">Standard Finite Sets</span>
<p>
The standard finite sets are, for \(n \in \N\),
\[
[n] = \{m \in \N \mid m < n\}.
\]
</p>

<p>
Herein we define
\[
[\cdot] : \N \rightarrow \pot \N
\]
using the recursion theorem.
</p>
</div>

<div class="proposition" id="org7710c5f">
<span class="block-title">Properties of Standard Finite Sets</span>
<ul class="org-ul">
<li>\[
 \forall m, n \in \N . \abs{[m]} \leq \abs{[n]} \iff m \leq n.
 \]</li>
<li>\[
  \forall n \in \N . \abs{[n]} \ll \abs{\N}
  \]</li>
</ul>
<p>
In particular, \(\N\)  is not finite.
</p>
</div>


<div class="proof" id="orge1593c8">
<p>
The left implication is trivial.
</p>

<p>
Right implication, use induction.
</p>
</div>

<div class="definition" id="org487fa35">
<span class="block-title">Finite Set</span>
<p>
A set \(A\) is <b>finite</b> if there exists \(n \in \N\) such that \(\abs{A} = \abs{[n]}\). In this case we define \(\abs{A} = n\).
</p>

<p>
Note that this is well defined, since there is a unique such \(n\).
</p>
</div>

<div class="proposition" id="orgda7ed66">
<span class="block-title">Properties of Finite Sets</span>
<ul class="org-ul">
<li>If we have \(A\) finite and \(A \twoheadrightarrow B\), then \(B\) is finite</li>
<li>If \(B\) is finite and \(A \rightarrowtail B\), then \(A\) is finite</li>
</ul>
</div>

<div class="remark" id="orgc696147">
<p>
Think about how we could define finiteness without referring to the structure of \(\N\).
</p>
</div>

<div class="definition" id="org77c764f">
<span class="block-title">Infinite Set</span>
<p>
A set \(A\) is <b>infinite</b> if it is not finite.
</p>
</div>

<div class="theorem" id="orga9492b3">
<span class="block-title">Characterisation of Infinite Sets</span>
<p>
Consider the following.
</p>
<ol class="org-ol">
<li>\(X\) is infinite.</li>
<li>There exists a proper subset \(X' \subseteq X\) such that \(\abs{X} = \abs{X'}\).</li>
<li>There exists a proper injection \(i : X \rightarrowtail X\).</li>
<li>\(\abs{\N} \leq \abs{X}\).</li>
</ol>
<p>
We also call statement 2 Dedekind infinite.
</p>

<p>
Then we have
\[
1 \impliedby 2 \iff 3 \iff 4.
\]
But \(1 \implies 4\) requires the axiom of (countable) choice.
</p>
</div>

<div class="proof" id="orgc07eecc">
<ul class="org-ul">
<li><p>
\(1 \implies 4\).
Suppose \(X\) is infinite. We define an injection, that is a sequence of distinct elements of \(X\).
Suppose \((x_i)_{0 \leq i < n}\) is given.
Since \(X\) is infinite, the function \(i \mapsto x_i : [n] \rightarrow X\) is not a bijection, but it is an injection, hence it cannot be surjective.
Thus we can choose
\[
  x_n \in X \setminus \{x_i \mid 0 \leq i < n\} \neq \emptyset.
  \]
The above defines an infinite sequence \((x_n)_{n \in \N}\) of distinct elements of \(X\). This gives the injection \(i : \N \rightarrowtail X\) defined by \(i(n) = x_n\).
</p>

<p>
Note that this version of the proof relies on the <a href="/20260219120854-kardinalna_aritmetika.html">axiom of dependent choice</a>. The relation is defined on finite sequences of elements from \(X\), relating two sequences if the second extends the first.
</p></li>
</ul>
</div>

<div class="axiom" id="orge17d3a2">
<span class="block-title">Axiom of Dependent Choice</span>
<p>
If a binary relation \(R \subseteq X \times X\) is total, that is \(\forall x \in X . \exists y \in X . xRy\), then for any \(x_0 \in X\), there exists an infinite sequence \((x_n)_{n \in \N}\) such that
\[
\forall n \in \N . x_n R x_{n+1}.
\]
</p>
</div>

<div class="definition" id="org6a6087c">
<span class="block-title">Aleph Zero</span>
<p>
We define \(\aleph_0 = \abs{\N}\).
</p>
</div>

<div class="definition" id="org6815a59">
<span class="block-title">Countable Set</span>
<ul class="org-ul">
<li>A set \(X\) is <b>countable</b> if \(\abs{X} \leq \aleph_0\).</li>
<li>If \(X\) is countable and infinite, then we call it <b>countably infinite</b>.</li>
</ul>

<p>
Examples of countable sets are \(\N, \Z, \Q, \N \times \N\).
</p>

<p>
Countable sets are closed under finite product, disjoint finite union, countable union, countable product, \(\dots\)
Also if \(A\) is countable and \(A \twoheadrightarrow B\), then \(B\) is countable.
Likewise if \(B\) is countable and \(A \rightarrowtail B\), then \(A\) is countable.
</p>
</div>

<div class="definition" id="org2bb6e5c">
<span class="block-title">Uncountable Set</span>
<p>
A set \(X\) is <b>uncountable</b> if it is not countable.
</p>
</div>

<div class="theorem" id="orgd6cc8c1">
<span class="block-title">Cantor's Theorem</span>
<p>
For every set \(X\), we have \(\abs{X} \ll \abs{\pot X}\).
</p>
</div>

<div class="proof" id="org9d88d31">
<p>
We have the injection \(i : X \rightarrowtail \pot X\) defined by \(i(x) = \{x\}\). Thus \(\abs{X} \leq \abs{\pot X}\).
Suppose \(g : X \twoheadrightarrow \pot X\) is a surjection. Define
\[
S = \{x \in X \mid x \not\in g(x)\}.
\]
So \(S \in \pot X\) and
\[
\forall x \in X . x\in S \iff x \not\in g(x).
\]
Since \(g\) is a surjection, there exists \(y \in X\) such that \(g(y) = S\).
</p>

<p>
But then \(y \in g(y) \iff y \in S \iff y \not\in g(y)\), a contradiction. Thus there is no surjection from \(X\) to \(\pot X\), so indeed \(\abs{X} \ll \abs{\pot X}\).
</p>
</div>

<div class="corollary" id="orgac16395">
<span class="block-title">The Real Numbers are Uncountable</span>
<p>
Since \(\R\) is in bijection with \(\pot \N\), we have \(\abs{\R} = \abs{\pot \N}\). By Cantor's theorem, \(\abs{\N} \ll \abs{\pot \N}\), so \(\R\) is uncountable.
</p>
</div>

</details>
</div>
<div id="outline-container-orgfa3b812" class="outline-2">
<details>
<summary>
<h2 id="orgfa3b812">Lecture 3 - Basic Cardinal Arithmetic</h2>
</summary>
<div class="outline-text-2" id="text-orgfa3b812">
</div>
<div class="definition" id="orgb6c78e5">
<span class="block-title">Covariant Powerclass Functor</span>
<p>
The covariant powerclass operation is functorial. That is, if \(f : X \rightarrow Y\) is a function, then we have a function
\[
\mathcal{P}f : \mathcal{P}X \rightarrow \mathcal{P}Y
\]
defined by \(\mathcal{P}f(A) = \{f(a)  \mid a \in A\}\). Note that \(\mathcal{P}\) preserves identities and composition.
</p>
</div>

<div class="proposition" id="orgd7914ac">
<p>
The operation \(X \mapsto \mathcal{P}X\) on sets \(X\) preserves cardinal inequalities:
</p>
\begin{align*}
\abs{X} \leq \abs{Y} &\implies \abs{\mathcal{P}X} \leq \abs{\mathcal{P}Y}, \\
\abs{X} = \abs{Y} &\implies \abs{\mathcal{P}X} = \abs{\mathcal{P}Y}.
\end{align*}
</div>

<div class="proof" id="org9de78ee">
<p>
Functors preserve isomorphisms and split monomorphisms.
</p>
</div>

<div class="remark" id="orgb44eb84">
<p>
We also consider the functoriality of the products, exponentials, and coproducts. They're also functorial, and preserve isomorphisms and monomorphisms.
</p>
</div>

<div class="proposition" id="org5a87d42">
<p>
If \(\abs{X} = \abs{X'}\) and \(\abs{Y} = \abs{Y'}\), then
</p>
\begin{align*}
\abs{X \times Y} &= \abs{X' \times Y'}, \\
\abs{X + Y} &= \abs{X' + Y'}, \\
\abs{Y^X} &= \abs{(Y')^{(X')}}.
\end{align*}

<p>
Note in the first two cases we can also take \(\leq\). In the last case,
\[
\abs{Y^X} = \abs{(Y')^{(X')}}
\]
holds, except when \(X = Y = Y' = \emptyset \neq X'\). The reason we have a corner case corresponds to the fact that functors preserve sections, not general monomorphisms.
</p>
</div>

<div class="definition" id="org044c4bd">
<span class="block-title">Cardinal Arithmetic Operations</span>
<p>
We've already defined \(n\) as the cardinality \(\abs{[n]}\) and \(\aleph_0 = \abs{\N}\). We also define
</p>
\begin{align*}
\abs{X} + \abs{Y} &:= \abs{X + Y}, \\
\abs{X} \cdot \abs{Y} &:= \abs{X \times Y}, \\
\abs{Y}^{\abs{X}} &:= \abs{Y^X}.
\end{align*}
</div>

<div class="proposition" id="orga12d59d">
<span class="block-title">Cardinal Monoid Laws</span>
<p>
The following hold for all sets \(X, Y, Z\).
</p>

<ol class="org-ol">
<li><p>
<b>Addition is a commutative monoid with unit 0:</b>
</p>
\begin{align*}
\abs{X} + 0 &= \abs{X} = 0 + \abs{X}, \\
\abs{X} + \abs{Y} &= \abs{Y} + \abs{X}, \\
\abs{X} + (\abs{Y} + \abs{Z}) &= (\abs{X} + \abs{Y}) + \abs{Z}.
\end{align*}</li>

<li><p>
<b>Multiplication is a commutative monoid with unit 1:</b>
</p>
\begin{align*}
\abs{X} \cdot 1 &= \abs{X} = 1 \cdot \abs{X}, \\
\abs{X} \cdot \abs{Y} &= \abs{Y} \cdot \abs{X}, \\
\abs{X} \cdot (\abs{Y} \cdot \abs{Z}) &= (\abs{X} \cdot \abs{Y}) \cdot \abs{Z}.
\end{align*}</li>

<li><p>
<b>Distributivity and annihilation:</b>
</p>
\begin{align*}
\abs{X} \cdot 0 &= 0, \\
\abs{X} \cdot (\abs{Y} + \abs{Z}) &= \abs{X} \cdot \abs{Y} + \abs{X} \cdot \abs{Z}.
\end{align*}</li>

<li><p>
<b>Exponentiation laws:</b>
</p>
\begin{align*}
\abs{X}^0 &= 1, \\
\abs{X}^1 &= \abs{X}, \\
\abs{X}^{\abs{Y} + \abs{Z}} &= \abs{X}^{\abs{Y}} \cdot \abs{X}^{\abs{Z}}, \\
\abs{X}^{\abs{Y} \cdot \abs{Z}} &= (\abs{X}^{\abs{Y}})^{\abs{Z}}, \\
1^{\abs{X}} &= 1, \\
(\abs{X} \cdot \abs{Y})^{\abs{Z}} &= \abs{X}^{\abs{Z}} \cdot \abs{Y}^{\abs{Z}}.
\end{align*}</li>
</ol>
</div>

<div class="proof" id="org9a0125b">
<p>
For instance, to prove \(\abs{X}^{\abs{Y} \cdot \abs{Z}} = (\abs{X}^{\abs{Y}})^{\abs{Z}}\), we establish the bijection \(\Lambda : X^{Y \times Z} \rightarrow (X^Y)^Z\)
\[
\Lambda(g : Y \times Z \rightarrow X) := \lambda z \in Z . \lambda y \in Y . g(y, z).
\]
</p>
</div>

<div class="remark" id="org7a423cf">
<p>
In ordinary arithmetic, we have
</p>
\begin{align*}
x + z &= y + z \implies x = y, \\
x \cdot z &= y \cdot z \implies x = y \text{ (if \(z \neq 0\))}.
\end{align*}
<p>
But in cardinal arithmetic, cancellation fails. In particular:
\[
\aleph_0 + 0 = \aleph_0 + \aleph_0,
\]
but \(0 \neq \aleph_0\). Likewise,
\[
1 \cdot \aleph_0 = \aleph_0 = \aleph_0 \cdot \aleph_0,
\]
but \(1 \neq \aleph_0\).
</p>
</div>

<div class="definition" id="org34cf658">
<span class="block-title">Idempotent Cardinal</span>
<p>
We say that \(\abs{X}\) is <b>idempotent</b> (or <b>its own square</b>) if \(\abs{X} = \abs{X} \cdot \abs{X}\).
</p>

<p>
For instance, \(\aleph_0\) is idempotent.
</p>
</div>

<div class="lemma" id="orgd11c8c3">
<p>
If \(\abs{X} \geq 2\) and \(\abs{X}\) is idempotent, then
</p>
<ol class="org-ol">
<li>\(\aleph_0 \leq \abs{X}\), i.e., \(X\) is Dedekind infinite, and</li>
<li>\(\abs{X} = \abs{X} + \abs{X}\).</li>
</ol>
</div>

<div class="proof" id="orgacd407e">
<p>
Let's show the second point first. We have
\[
\abs{X} \leq \abs{X} + \abs{X}
\]
since we have two obvious injections. Next,
\[
\abs{X} + \abs{X} = \abs{X} \cdot 2 \leq \abs{X} \cdot \abs{X} = \abs{X}
\]
first by distributivity and then by assumption. Thus \(\abs{X} = \abs{X} + \abs{X}\) by the Cantor-Schröder-Bernstein theorem.
</p>

<p>
For the first point, note that \(X\) is Dedekind infinite, since we have the injection
\[
x \mapsto f(0, x)
\]
by the bijection \(f : X \times X \rightarrow X\).
</p>
</div>

<div class="proposition" id="org8de3de4">
<p>
If \(\abs{X} \geq 2\) and \(\abs{X}\) is idempotent, then \(2^{\abs{X}}\) is also idempotent.
</p>
</div>

<div class="proof" id="orge0fdae0">
<p>
We have
</p>
\begin{align*}
2^{\abs{X}} \cdot 2^{\abs{X}} &= 2^{\abs{X} + \abs{X}} \\
&= 2^{\abs{X}} \text{ (by the previous lemma)}
\end{align*}
</div>

<div class="remark" id="org36d9c87">
<p>
If \(X\) is infinite and \(Y \subseteq X\) satisfies \(\abs{Y} \ll \abs{X}\), then we might expect
\[
\abs{X \setminus Y} = \abs{X}.
\]
This holds assuming the axiom of choice. The proof of this is nonetheless quite involved.
</p>
</div>

<div class="theorem" id="org98b6caf">
<p>
If \(\abs{X}\) is idempotent and \(Y \subseteq X\) is such that \(\abs{Y} \ll \abs{X}\), then \(\abs{X \setminus Y} = \abs{X}\).
</p>
</div>

<div class="proof" id="org33709f3">
<p>
Consider the following diagram:
\[
Y \xhookrightarrow{\subseteq} X \xrightarrow{f} X \times X \xrightarrow{\pi_1} X
\]
Because \(\abs{Y} \ll \abs{X}\), the composition is not a surjection.
</p>

<p>
So there exists \(x_0 \in X\) such that for all \(y \in Y\), we have \(f(y) = (x_1, x_2)\) where \(x_1 \neq x_0\). We therefore have an injective function
\[
X \xrightarrow{x \mapsto (x_0, x)} (X \times X) \setminus f(Y).
\]
Then
\[
\abs{X} \leq \abs{(X \times X) \setminus f(Y)} = \abs{X \setminus Y}
\]
because \(f\) is a bijection.
</p>

<p>
Clearly we also have \(\abs{X \setminus Y} \leq \abs{X}\). By the Cantor-Schröder-Bernstein theorem, we have \(\abs{X \setminus Y} = \abs{X}\).
</p>
</div>

<div class="theorem" id="org719ceb9">
<span class="block-title">Cantor's Theorem</span>
<p>
For any set \(X\), we have
\[
\abs{X} \ll 2^{\abs{X}}.
\]
</p>
</div>

<div class="theorem" id="org239dcf7">
<span class="block-title">Continuum Hypothesis (Cardinal form)</span>
<p>
If \(\aleph_0 \leq \abs{X} \leq 2^{\aleph_0}\), then either \(\abs{X} = \aleph_0\) or \(\abs{X} = 2^{\aleph_0}\).
</p>
</div>

<div class="theorem" id="org3edff5e">
<span class="block-title">Generalized Continuum Hypothesis (GCH)</span>
<p>
If we have
\[
\aleph_0 \leq \abs{Z} \leq \abs{X} \leq 2^{\abs{Z}},
\]
then either \(\abs{X} = \abs{Z}\) or \(\abs{X} = 2^{\abs{Z}}\).
</p>
</div>

<div class="remark" id="orgd555c29">
<p>
Gödel showed that GCH is consistent with the axioms of set theory.
</p>
</div>

</details>
</div>
<div id="outline-container-org166512b" class="outline-2">
<details>
<summary>
<h2 id="org166512b">Lecture 4 - Ordinals</h2>
</summary>
<div class="outline-text-2" id="text-org166512b">
</div>
<div class="remark" id="org36d2296">
<p>
We can come to the notion of an ordinal through two main ways.
</p>

<ol class="org-ol">
<li><b>Ordinals measure order type:</b> Ordinals represent the order type of a well-ordered set.</li>

<li><b>Ordinals as extended numbers:</b> We can think of ordinals as an extended number system for counting.</li>
</ol>

<p>
This counting proceeds through the natural numbers, then through \(\omega\), then continues as:
</p>
\begin{align*}
0, 1, 2, 3, 4, 5, \dots, \\
\omega, \omega + 1, \omega + 2, \omega + 3, \dots, \\
\omega \cdot 2, \omega \cdot 2 + 1, \dots, \omega \cdot 3, \omega \cdot 3 + 1, \dots, \\
\omega^2, \omega^2 + 1, \dots, \omega^2 + \omega, \dots, \omega^3, \dots
\end{align*}

<p>
Eventually we reach ordinals like
\[
\omega^{\omega^{\omega^{\dots}}}
\]
and even a pattern of \(\omega\) many exponentiations. We call this ordinal \(\varepsilon_0\). This is the smallest ordinal \(\alpha\) satisfying
\[
\alpha = \omega^{\alpha},
\]
the smallest fixed point of exponentiation by \(\omega\). Then we continue to \(\varepsilon_1\) and so on.
</p>

<p>
But this collection is still countable. We can then ascend to \(\omega_1\), the smallest uncountable ordinal. Repeating the pattern, we obtain \(\omega_2\), \(\omega_{\omega}\), \(\omega_{\omega_1}\), and so forth.
</p>

<p>
We construct this structure by adjoining to the natural numbers the rule that for any collection of ordinals, we can always form the next smallest ordinal that follows all of them.
</p>
</div>

</details>
</div>
<div class="taglist"><a href="https://www.jure-smolar.com/tags.html">Tags</a>: <a href="https://www.jure-smolar.com/tag-lecture-notes.html">lecture-notes</a> </div>]]></description>
  <category><![CDATA[lecture-notes]]></category>
  <link>https://www.jure-smolar.com/20260219120854-kardinalna_aritmetika.html</link>
  <guid>https://www.jure-smolar.com/20260219120854-kardinalna_aritmetika.html</guid>
  <pubDate>Tue, 10 Mar 2026 09:41:30 +0100</pubDate>
</item>
<item>
  <title><![CDATA[Unija z rangom]]></title>
  <description><![CDATA[
<p>
A test post from my old notes. The content is not very well written or well-organised, but it has both a code block and \(\LaTeX\), so serves as a good test for the site's features.
</p>
<div id="outline-container-org4e1beb1" class="outline-2">
<h2 id="org4e1beb1"><span class="section-number-2">1.</span> Operations:</h2>
<div class="outline-text-2" id="text-1">
<ul class="org-ul">
<li><code>singleton(x)</code> . ustvari singleton \(\{x\}\)</li>
<li><code>find(x)</code>           . poišči predstavnika komponente, ki vsebuje \(x\)</li>
<li><code>merge(x, y)</code>   . združi komponenti/množici, v katerih sta \(x\) in \(y\)</li>
</ul>
</div>
</div>
<div id="outline-container-orgc27ca1d" class="outline-2">
<h2 id="orgc27ca1d"><span class="section-number-2">2.</span> Unija z rangom</h2>
<div class="outline-text-2" id="text-2">
<p>
Množice prestavimo z DAG, kjer gre iz vsakega elementa natanko ena povezava
Potem ima vsaka komponenta natanko en ponor.
</p>

<p>
To shranimo z dvema tabelama, v eni imamo predhodnik od vsakega elementa (če je v enojcu je sam svoj prednik),
v drugi pa <code>rang</code> elementa.
</p>
</div>
</div>
<div id="outline-container-org6bbefa1" class="outline-2">
<h2 id="org6bbefa1"><span class="section-number-2">3.</span> Lastnosti ranga za union-find</h2>
<div class="outline-text-2" id="text-3">
<ol class="org-ol">
<li><code>rang(x)</code> &lt; <code>rang(π(x))</code>, če <code>x≠π(x)</code>.</li>
<li>Če je \(x\) ranga \(k\), ima \(x\) pod sabo vsaj \(2^k\) vozlišč (vključno s seboj).</li>
<li>Če imamo \(n\) elementov, imamo lahko največ \(\frac{n}{2^k}\) vozlišč ranga \(k\).</li>
<li>Sledi, da je maksimalen rang lahko \(\log n\)</li>
</ol>
</div>
<div id="outline-container-orgc48e433" class="outline-3">
<h3 id="orgc48e433"><span class="section-number-3">3.1.</span> Primer:</h3>
<div class="outline-text-3" id="text-3-1">
<p>
Vzemimo \(\{A,C,D,F,G,H\}\) in \(\{B,E\}\).
</p>

<p>
Tabela:
</p>
<table>


<colgroup>
<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">

<col  class="org-left">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">x</th>
<th scope="col" class="org-left">A</th>
<th scope="col" class="org-left">B</th>
<th scope="col" class="org-left">C</th>
<th scope="col" class="org-left">D</th>
<th scope="col" class="org-left">E</th>
<th scope="col" class="org-left">F</th>
<th scope="col" class="org-left">G</th>
<th scope="col" class="org-left">H</th>
<th scope="col" class="org-left">&#xa0;</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">π(x)</td>
<td class="org-left">F</td>
<td class="org-left">E</td>
<td class="org-left">H</td>
<td class="org-left">H</td>
<td class="org-left">E</td>
<td class="org-left">H</td>
<td class="org-left">D</td>
<td class="org-left">H</td>
<td class="org-left">&lt;- Predhodnik</td>
</tr>

<tr>
<td class="org-left">rang(x)</td>
<td class="org-left">0</td>
<td class="org-left">0</td>
<td class="org-left">0</td>
<td class="org-left">1</td>
<td class="org-left">1</td>
<td class="org-left">1</td>
<td class="org-left">0</td>
<td class="org-left">2</td>
<td class="org-left">&lt;- Globina drevesa pod x</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org1bf534a" class="outline-3">
<h3 id="org1bf534a"><span class="section-number-3">3.2.</span> Operacije:</h3>
<div class="outline-text-3" id="text-3-2">
<div class="org-src-container">
<pre class="src src-python"><span class="org-keyword">from</span> functools <span class="org-keyword">import</span> <span class="org-builtin">reduce</span>

<span class="org-variable-name">&#960;</span> <span class="org-operator">=</span> <span class="org-rainbow-delimiters-depth-1">{}</span>
<span class="org-variable-name">rang</span> <span class="org-operator">=</span> <span class="org-rainbow-delimiters-depth-1">{}</span>

<span class="org-keyword">def</span> <span class="org-function-name">singleton</span><span class="org-rainbow-delimiters-depth-1">(</span>x<span class="org-rainbow-delimiters-depth-1">)</span>:
      <span class="org-variable-name">&#960;</span><span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">=</span> x
      <span class="org-variable-name">rang</span><span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">=</span> 0
      <span class="org-keyword">return</span> x

<span class="org-keyword">def</span> <span class="org-function-name">find</span><span class="org-rainbow-delimiters-depth-1">(</span>x<span class="org-rainbow-delimiters-depth-1">)</span>:
      <span class="org-keyword">while</span> x <span class="org-operator">!=</span> &#960;<span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span>:
          <span class="org-variable-name">x</span> <span class="org-operator">=</span> &#960;<span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span>
      <span class="org-keyword">return</span> x

<span class="org-keyword">def</span> <span class="org-function-name">find_amortized</span><span class="org-rainbow-delimiters-depth-1">(</span>x<span class="org-rainbow-delimiters-depth-1">)</span>:
      <span class="org-doc">"Na vsakem koraku malo flattenaj"</span>
      <span class="org-keyword">if</span> x <span class="org-operator">!=</span> &#960;<span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span>:
          <span class="org-variable-name">&#960;</span><span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">=</span> find_amortized<span class="org-rainbow-delimiters-depth-1">(</span>&#960;<span class="org-rainbow-delimiters-depth-2">[</span>x<span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">)</span>
      <span class="org-keyword">return</span> &#960;<span class="org-rainbow-delimiters-depth-1">[</span>x<span class="org-rainbow-delimiters-depth-1">]</span>

<span class="org-keyword">def</span> <span class="org-function-name">merge</span><span class="org-rainbow-delimiters-depth-1">(</span>x, y<span class="org-rainbow-delimiters-depth-1">)</span>:
      <span class="org-variable-name">p_x</span> <span class="org-operator">=</span> find<span class="org-rainbow-delimiters-depth-1">(</span>x<span class="org-rainbow-delimiters-depth-1">)</span>
      <span class="org-variable-name">p_y</span> <span class="org-operator">=</span> find<span class="org-rainbow-delimiters-depth-1">(</span>y<span class="org-rainbow-delimiters-depth-1">)</span>
      <span class="org-keyword">if</span> p_x <span class="org-operator">==</span> p_y:
            <span class="org-keyword">return</span> p_x
      <span class="org-keyword">else</span>:
            <span class="org-keyword">if</span> rang<span class="org-rainbow-delimiters-depth-1">[</span>p_x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">&gt;</span> rang<span class="org-rainbow-delimiters-depth-1">[</span>p_y<span class="org-rainbow-delimiters-depth-1">]</span>:
                  <span class="org-variable-name">&#960;</span><span class="org-rainbow-delimiters-depth-1">[</span>p_y<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">=</span> p_x
                  <span class="org-keyword">return</span> p_x
            <span class="org-keyword">else</span>:
                  <span class="org-variable-name">&#960;</span><span class="org-rainbow-delimiters-depth-1">[</span>p_x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">=</span> p_y
                  <span class="org-keyword">if</span> rang<span class="org-rainbow-delimiters-depth-1">[</span>p_x<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">==</span> rang<span class="org-rainbow-delimiters-depth-1">[</span>p_y<span class="org-rainbow-delimiters-depth-1">]</span>:
                        <span class="org-variable-name">rang</span><span class="org-rainbow-delimiters-depth-1">[</span>p_y<span class="org-rainbow-delimiters-depth-1">]</span> <span class="org-operator">+=</span> 1
                        <span class="org-keyword">return</span> p_y


  <span class="org-comment-delimiter"># </span><span class="org-comment">Primer od prej:
</span>
  <span class="org-comment-delimiter">#</span><span class="org-comment">for el in ["A", "B", "C", "D", "E", "F", "G", "H"]:
</span>  <span class="org-comment-delimiter">#    </span><span class="org-comment">singleton(el)
</span>  <span class="org-comment-delimiter">#</span><span class="org-comment">reduce(merge, ["A", "C", "D", "F", "G", "H"])
</span>  <span class="org-comment-delimiter">#</span><span class="org-comment">reduce(merge, ["B", "E"])
</span>
<span class="org-variable-name">&#960;</span> <span class="org-operator">=</span> <span class="org-rainbow-delimiters-depth-1">[</span>0,0,1,3,3,4<span class="org-rainbow-delimiters-depth-1">]</span>
<span class="org-variable-name">rang</span> <span class="org-operator">=</span> <span class="org-rainbow-delimiters-depth-1">[</span>2,1,0,2,1,0<span class="org-rainbow-delimiters-depth-1">]</span>

<span class="org-builtin">print</span><span class="org-rainbow-delimiters-depth-1">(</span>&#960;<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-builtin">print</span><span class="org-rainbow-delimiters-depth-1">(</span>rang<span class="org-rainbow-delimiters-depth-1">)</span>

find_amortized<span class="org-rainbow-delimiters-depth-1">(</span>2<span class="org-rainbow-delimiters-depth-1">)</span>

<span class="org-builtin">print</span><span class="org-rainbow-delimiters-depth-1">(</span>&#960;<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-builtin">print</span><span class="org-rainbow-delimiters-depth-1">(</span>rang<span class="org-rainbow-delimiters-depth-1">)</span>

</pre>
</div>

<pre class="example">
[0, 0, 1, 3, 3, 4]
[2, 1, 0, 2, 1, 0]
[0, 0, 0, 3, 3, 4]
[2, 1, 0, 2, 1, 0]
</pre>


<p>
Načeloma <code>singleton</code> in <code>merge</code> ne rabita vračati, to je le zavoljo primera, saj lahko s tem uporabimo reduce za konstrukcijo množice.
Rezultat se razlikuje od zgornje postavitve, ker več DAG-ov predstavlja isto množico. Če se drevo nariše, se jasno vidi, da množici predstavljata isto particijo.
</p>
</div>
<div id="outline-container-org375bd78" class="outline-4">
<h4 id="org375bd78"><span class="section-number-4">3.2.1.</span> Zahtevnosti:</h4>
<div class="outline-text-4" id="text-3-2-1">
<ul class="org-ul">
<li>Singleton: \(O(1)\)</li>
<li>Poišči: \(O(\log n)\)</li>
<li>Amortiziran poišči: \(O(\log^*|V|)\)</li>
<li>Združi \(O(\log n)\)</li>
</ul>

<p>
Z izboljšavo dobimo <a href="broken-link.html" class="broken-link">amortizirano časovno zahtevnost</a>.
</p>
</div>
</div>
<div id="outline-container-orge18175a" class="outline-4">
<h4 id="orge18175a"><span class="section-number-4">3.2.2.</span> Opomba:</h4>
<div class="outline-text-4" id="text-3-2-2">
<p>
Z uporabo amortiziranega poišči je tudi združi amortizirane časovne zahtevnosti (saj je le dva poišči in nekaj konstantnih operacij).
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-org020fdc1" class="outline-2">
<h2 id="org020fdc1"><span class="section-number-2">4.</span> Union-find with path compression</h2>
<div class="outline-text-2" id="text-4">
</div>
<div id="outline-container-org966fdd4" class="outline-3">
<h3 id="org966fdd4"><span class="section-number-3">4.1.</span> Back</h3>
<div class="outline-text-3" id="text-4-1">
<p>
Koliko nas stane paket \(m\) operacij <code>poišči</code> na \(n\) vozliščih?
</p>
<ul class="org-ul">
<li>\(\log^*n\) - kolikokrat moramo zaporedoma narediti logaritem, da pridemo na 1 ali manj.</li>
<li>\(\log\log\log\log 1000 \leq 1 \implies \log^{*}1000 = 4\)</li>
<li><code>Poišči</code> nas stane v povprečju \(O(\log^{*}n)\)</li>
<li>V resnici bi zaporedje \(m\) operacij stalo \(O(m\log^{*}n) + O(n\log^{*}n)\).</li>
</ul>

<p>
Rang se ohranja, a ne predstavlja več globine drevesa. Range razdelimo na intervale:
\[ [1], [2], [3, 4], [5, 16], [17, 2^{16}], [2^{16} + 1, 2^{2^{16}}], \dots
\]
Ko vozlišče ranga iz \([k + 1, 2^k]\) neha biti koren, mu damo žepnino \(2^k\) žetonov.
En žeton porabi en skok po povezavi. Vozlišč iz tega intervala je največ
\[ \frac{n}{2^{k+1}} + \frac{n}{2^{k+2}} + \cdots + \frac{n}{2^{2^k}} \leq \frac{n}{2^k}
\]
Vsak interval dobi največ \(n\) žepnin. Intervalov je največ \(\log^{*}n\). Operacija <code>poišči(x)</code> porabi toliko, kot je dolga veriga:
\[
x = y_0 \rightarrow y_1 \rightarrow \cdots \rightarrow y_r
\]
Vrednosti \(\rang(y_i)\) in \(\rang(\pi(y_i))\) sta lahko ali v različnih intervalih, kar se lahko zgodi le \(\log^{*}n\)-krat, ali pa v istem intervalu. V tem primeru \(y_{i}\) prispeva en žeton, s čimer smo povečali \(\rang(\pi(y_i))\). V kombinaciji z večimi združi se to lahko zgodi kvečjemu \(2^k\)-krat, saj je vozlišč največ \(\frac{n}{2^k}\). Torej imamo dovolj žepnine.
</p>
</div>
</div>
</div>
<div class="taglist"></div>]]></description>
  <link>https://www.jure-smolar.com/20211125173234-union_find.html</link>
  <guid>https://www.jure-smolar.com/20211125173234-union_find.html</guid>
  <pubDate>Wed, 02 Feb 2022 00:00:00 +0100</pubDate>
</item>
</channel>
</rss>
