module Padova2025.Explorations.CZF where
Sets as trees
open import Padova2025.ProgrammingBasics.Booleans open import Padova2025.ProgrammingBasics.Naturals.Base open import Padova2025.ProvingBasics.Negation open import Padova2025.ProvingBasics.Connectives.Existential open import Padova2025.ProvingBasics.Connectives.Conjunction open import Padova2025.ProvingBasics.Termination.Gas open import Agda.Primitive
Set theory and type theory in all their flavors can both be used as
foundations for large parts of mathematics. And they are interconnected:
Within set theory, we can build models of type theory, and within type
theory, we can build models of set theory. The latter is the purpose of
this module: We will introduce a type V
whose elements
represent sets as in set theory. We will have constants like
β
(representing the empty set) and N
(representing the set of natural numbers), functions like
union
(for taking the union of a set of sets), a global
membership relation called _β_
, and so on. We will then
also be able to study the properties of this model of set theory: Does
the axiom of choice hold? The powerset axiom?
The model we will describe is Peter Aczelβs sets as trees
model. We represent sets by arbitrarily-branching trees; for instance,
the set { x, {y,z}, {0,1,2,...} }
is represented by the
following tree:
* β±ββ² β± β β² β± β β² β± β β² β± β β² x * * β± β² β±ββ² y z 0 1 2 ...
In Agda, we express this idea as follows.
data V : Setβ where sup : {I : Set} β (I β V) β V
The constructor sup
takes an indexing type
I
and an I
-indexed family of trees and returns
a new tree with those trees as the children of its root. In the
beginning, we do not know any trees; to get off the ground, we use the
empty family of trees:
β : V β = sup {β₯} empty-function -- just a root node without children where empty-function : β₯ β V empty-function ()
Given trees x
and y
, we can create a new
tree whose root has x
and y
as its
children:
pair : V β V β V pair x y = sup {Bool} f -- a root node with two children where f : Bool β V f false = x f true = y
The following function is supposed to map a set x
to the
singleton set { x }
, i.e.Β a tree x
to a tree
whose root has exactly one child, namely x
.
singleton : V β V singleton = {!!}
The following function is supposed to input two sets x
and y
and output the ordered Kuratowski pair
{ {x}, {x,y} }
.
kuratowski : V β V β V kuratowski = {!!}
For some results below, the following two projection functions are nice to have. They allow us to access the indexing type or the family without having to pattern match on the set in question.
Index : V β Set Index (sup {I} f) = I
fam : (x : V) β Index x β V fam (sup {I} f) = f
The set-theoretic natural numbers
In set theory, the natural numbers are often bootstrapped from the empty set as follows.
0 β {}
1 β { 0 } = { {} } = 0 βͺ {0}
2 β { 0, 1 } = { {}, {{}} } = 1 βͺ {1}
3 β { 0, 1, 2 } = { {}, {{}}, {{},{{}}} } = 2 βͺ {2}
In other words, a number is identified with its set of predecessors;
the number zero does not have any predecessors and is hence represented
by the empty set. To mimic this construction in Agda, let us implement
the function next
which inputs a set X
and
outputs X βͺ {X}
.
next : V β V next = {!!}
With next
in place, we can convert every actual natural
number into its set-theoretic representationβ¦
fromβ : β β V fromβ = {!!}
β¦and thereby obtain the set of natural numbers:
N : V N = sup {β} fromβ
An equivalence relation
In set theory, the sets { x, y }
and
{ y, x }
are deemed equal; however, in Agda, the trees
pair x y
and pair y x
are distinct:
* *
β± β² vs. β± β²
x y y x
We hence need to introduce an equivalence relation _β_
expressing that two trees represent the same set.
infix 4 _β_ _β_ : V β V β Set sup {I} f β sup {J} g = ((i : I) β β[ j ] (f i β g j)) Γ ((j : J) β β[ i ] (g j β f i)) -- "Every child `f i` is equivalent to one of the children of `sup g`, -- and vice versa."
β-refl : {x : V} β x β x β-refl = {!!}
β-sym : {x y : V} β x β y β y β x β-sym = {!!}
β-trans : {x y z : V} β x β y β y β z β x β z β-trans = {!!}
The membership relation
Fundamental to set theory is the membership relation β. This relation is also responsible for one of the most discernible differences between set theory and type theory: In set theory, for any two sets X and Y, the expression βXβββYβ is always a well-defined assertionβperhaps provable, perhaps refutable, but in any case a syntactically correctly formed proposition.
In contrast, in most flavors of type theory, the typing judgment
X : Y
is never a mathematically interesting question.
Instead, the typing judgment is decidableβindeed, verifying
well-typedness is what Agdaβs kernel is all about. Either X
is mechanically known to be of type Y
, or it has some other
type (or is just ill-typed).
_β_ : V β V β Set x β y = β[ i ] (fam y i β x) -- "x is an element of sup f iff it is equivalent to one of the -- children of sup f."
cong-β : {x y z : V} β x β y β z β x β z β y cong-β = {!!}
cong-β' : {x y z : V} β x β y β x β z β y β z cong-β' = {!!}
As a basic sanity check, every child f i
is an element
of sup f
; the following is a convenience function for some
of the proofs below.
β-basic : {x : V} β (i : Index x) β fam x i β x β-basic = {!!}
Axiom of extensionality
infix 4 _β_ _β_ : {β β' : Level} β Set β β Set β' β Set (β β β') A β B = (A β B) Γ (B β A)
A basic principle in set theory is that sets are determined by their
elements: Two sets are equal if and only if they have the same elements.
Our sets-as-trees model of set theory validates this principle (if we
replace strict equality by _β_
).
extensionalityβ : {x y : V} β ((z : V) β z β x β z β y) β x β y extensionalityβ = {!!}
extensionalityβ : {x y : V} β x β y β ((z : V) β z β x β z β y) extensionalityβ = {!!}
Basic set construction axioms
existence-empty-set : β[ x ] ((y : V) β y β x β β₯) existence-empty-set = {!!}
pairing-axiom : (x y : V) β β[ z ] (x β z Γ y β z) pairing-axiom = {!!}
union : V β V union = {!!}
union-axiom : (x : V) β β[ y ] ((z : V) β z β y β β[ w ] (z β w Γ w β x))
union-axiom x = ?
-- TODO: Format as exercise
In the vincinity of Russellβs paradox
no-set-contains-itself : (v : V) β v β v β β₯ no-set-contains-itself = {!!}
It is tempting to introduce a set u
of all sets, as
follows:
u : V
u = sup {V} (Ξ» x β x)
However, this attempt is rejected by Agda with the comment
βSetβ != Set
when checking that the expression
V
has type Set
β. The children of a node need
to be indexed by a small type, a type in Set
; but
V
itself is not a small type, but rather a type in
Setβ
.
Agda supports the unsafe option --type-in-type
,
collapsing the universe hierarchy. The definition of u
is
then well-typed, and a contradiction can be derived as follows.
uβu : u β u
uβu = u , β-refl
contradiction : β₯
contradiction = no-set-contains-itself u uβu
Make this explorable in a submodule