WIP

Knaster-Tarski theorem in type theory

Based on a very patient and kind explanation by bollu. It’s taking me more than four months to understand the gist of this theorem and its implication and uses, hopefully writing down what I got to so far will be helpful on this quest.

statement: the set of fixed points of a monotone function over a complete lattice is itself a complete lattice. we will need a bunch of definitions around lattices to get to the theorem.

A lattice is a set of elements LL such that

  1. there exists two binary operations meet()meet (\land) and join()join (\lor) such that
  1. there exists two elements \top and \bot such that
  1. there exists a partial order, which we indicate as \le, such that

From the definitions we have:

Other examples:

We can also reason the other way around and get a lattice out of a partial order: consider Q[0,1]\mathbb{Q}[0,1] with order relation \le, we need to define meetmeet and joinjoin.

We can have a lattice with d=d = \top, a=a = \bot and ac=aa \land c = a, bc=ab \land c = a

         d
        / \
       b   c
        \ /
         a

In this case:

         d
        / \
       c   e
       | x |
       b   f
        \ /
         a

We have a lattice with d=d = \top, a=a = \bot and bf=eb \land f = e, but also bf=cb \land f = c? In this lattice we can’t decide what’s the actual LUB between c and e. This goes against the actual definition of join, hence this is not a lattice. To make this a proper lattice we can just add:

      d
     / \
    c - e
    | x |
    b   f
     \ /
      a

meaning that bf=cb \land f = c since cec \le e, and it can’t be bf=eb \land f = e since ee is not the least upper bound.

If a partial order fails to become a lattice it’s usually because there’s no \top, no \bot or two elements don’t have a unique LUB\GLB.

We now need to define a complete lattice. Given the above definitions, we can reason about meet and join over sets with different number of elements:

from which it follows for S=S = \empty that meet()=p    (i,pxi)(k(i,kxi)    kp)meet () = p \iff (\forall i\in \empty, p\le x_i) \land (\forall k (\forall i\in \empty, k\le x_i) \implies k \le p) where:

  1. (i,pxi)(\forall i\in \empty, p\le x_i) is always true, since the existence of a certain xi,ix_i, i\in \empty to compare pp against is itself a contradiction.
  2. (i,kxi)(\forall i\in \empty, k\le x_i) is always true for the same reason leaving us with k,kp\forall k, k\le p, meaning p=p = \top.

meet finds the highest point in the lattice that is lower than the given points (GLB) and in particular, the lattice definition ensures that if such point exists, it is unique.

Let’s consider the set L=N{S    SNS}L = \mathbb{N} \cup \{S\;|\; S \subseteq \mathbb{N} \land |S|\le \infty\}, i.e., containing the set of natural numbers and any subset of natural numbers with finite cardinality. Let’s make sure this is actually a lattice by defining:

Let’s consider the infinite family of elements in this lattice c={0},{2},{4},...,{2n},nNc = \{0\}, \{2\}, \{4\}, ..., \{2n\}, \forall n\in \mathbb{N}: The points in CC do not have a LUB in LL!

While this structure is a lattice, it is not a complete lattice: pairs (or more in general, finite collections of elements) have a LUB (join, or in this case \cup suffices), but not every infinite collection does. To handle the join over an infinite collection of elements, we need more guarantees.

The same happens for meet: let’s consider L={S    S=SN:S=}L' = \{S\;|\; S = \empty \lor S \subseteq \mathbb{N} : |S| = \infty\}, which looks something like:


       / | \
      /  |  \
  ℕ\{0}  |  ℕ\{2} ...
         |      |
        ℕ\{1}   |
            \   |
             \  |
            ℕ\{1, 2}
             ...
        {}

We can build an infinite collection of elements whose intersections is finite, for example consider c=N\{1},N\{1,2},{4},...,N\{1,2,...,k+1},kNc = \mathbb{N}\backslash \{1\}, \mathbb{N}\backslash \{1,2\}, \{4\}, ..., \mathbb{N}\backslash \{1, 2, ..., k + 1\}, \forall k\in \mathbb{N}. any finite intersection of the elements in cc will only miss a finite number of elements (“from the highest kk onwards”), however the intersection over all the elements in cc fill have finite cardinality and will eventually like {0}L\{0\} \notin L', since {0}\{0\} is common to every element of the collection.

Incomplete lattices often have the structure of LL: everything works up to finite collections of elements, but when meet/join need to handle an infinite number of elements, the structure stops working.

Other examples:

Moving on with the theorem statement, we need to define a monotone function on a partial order \le. Let f:ABf : A \rightarrow B, where AA has a partial order given by \le and BB has a partial order given by \sqsubseteq.

ff is monotone     a,aA,aa    f(a)f(a)\iff \forall a, a'\in A, a\le a' \implies f(a) \sqsubseteq f(a') with f(a),f(a)Af(a), f(a')\in A

Basically, a function is monotone if it preserves the order relation existing in the codomain into the domain, without establishing a relation between the two order relation themselves (no hypothesis is required for le,le, \sqsubseteq).

We then define a fixed point: given f:AAf : A\rightarrow A and xAx\in A, we say xx is a fixed point (FP)     x=f(x)\iff x = f(x).

We now have enough definitions to go back to the theorem statement: given a function f:LLf: L\rightarrow L that is monotone, with LL being a complete lattice, then we know:

  1. ff has a FP
  2. let SS be the set of FPs of ff, then \exists at least one least FP, i.e., one element sSs\in S smaller than all other FPs
  3. the set of FPs SS is a complete sub-lattice of LL

Example: let’s consider L={x    xN}L = \{x \;|\; x\subseteq \mathbb{N}\} with partial order \subseteq:

  1. f(x)=xf(x) = x, in which case the set of FPs is S=LS = L
  2. f(x)={1}f(x)=\{1\}, meaning SS only contains one element: {1}\{1\}. Note that S={{1}}S = \{\{1\}\} is itself a complete lattice!
  3. f(x)=x{1,2}f(x) = x\cup \{1, 2\} with fixed points {1,2}\{1, 2\}, {1,2,3}\{1, 2, 3\}, … and therefore S={x    {1,2}x}S = \{x \;|\; \{1, 2\} \subseteq x\} : SS is the set of subsets xx of N\mathbb{N} such that the subset {1,2}\{1, 2\} is contained in xx. With this in mind, we define for the sublattice:

The final objective of my effort with this theorem, is to understand its implication in type theory and in particular concerning types definitions in Lean, so let’s try to move towards that domain.

Let’s consider L={xxN}L = \{x | x \subseteq \mathbb{N}\} and introduce the concept of indicator function II: when we say S,SN\forall S, S \subseteq \mathbb{N}, we really are defining a function IS:NBI_S: \mathbb{N}\rightarrow \mathbb{B} where aS    IS(a)=Truea\in S \iff I_S(a) = True. We can re-interpret lattices considering this idea. B\mathbb{B} is a complete lattice, with =True\top = True and =False\bot = False, meet=&&meet = \&\&, join=join = ||. From this lattice, we derive a new lattice NB\mathbb{N}\rightarrow \mathbb{B} by pointwise definition:

Knaster-Tarski theorem in analysis

A more analytical explanation. We construct a lattice using N\mathbb{N} and adding two arbitrary elements \top and \bot:


      0, 1, 2, ...

forming a complete lattice with:

We now consider any set X: the space of functions [X,L]={f    XL}[X, L] = \{f \;|\; X\rightarrow L\} will be a complete lattice, with

in particular, the lattice is complete, in fact:

We instantiate this construction with X=NX = \mathbb{N} and L=NL = \mathbb{N} equipped with ,\bot, \top (L=NL=\mathbb{N}\top\bot). This construction contains, for example:

these weird functions are all finite approximations of the factorial function (up to a- certain x).

We now can build a monotone function from this space of functions to itself m=(NL)(NL)m = (\mathbb{N} \rightarrow L) \rightarrow (\mathbb{N} \rightarrow L), i.e. m(f)=xif    x=0    then  1    else    xf(n1)m(f) = x\mapsto if\;\; x = 0\;\; then\; 1\;\; else\;\; x * f(n - 1):

                         0          1          2          3          4          5       ...
    f0 = fun x => ⊥      ⊥          ⊥ ...
    f1 = m f0            1          ⊥          ⊥ ... we cheat, because we're multiplying a natural number by ⊥!
    f2 = m f1            1          1          ⊥          ⊥         ⊥ ...
    f3 = m f2            1          1          2          ⊥          ⊥ ...
    f4 = m f3            1          1          2          6          ⊥ ...
    f1 ∪ f2              1          1          ⊥ ... we take the join (upper) element of {f1(0), f(0)}, etc.

given two said functions we define fg    x,f(x)g(x)    m(f)m(g)f \le g \iff \forall x, f(x) ≤ g(x) \implies m(f) \le m(g)

A concrete construction of naturals using this setting:

For example, let’s consider a function with no fixed points: f(x)=x+1f(x) = x + 1 in the lattice R[0,1]\mathbb{R}[0,1]: we can’t get a set of elements out of this function.

Think about the lattice R[0,1]\mathbb{R}[0,1] for “normal functions” (i.e. real analysis). Then think about sets: e.g. the set of naturals SS (each set is a node of the lattice), with the lattice structure given by ∪,\cap, \cup, the monotone function we consider to reason about the theorem is such that: S{zero}{sS,succ(s)}S\mapsto \{zero\}\cup \{\forall s\in S, succ(s)\}: Knaster Tarski allows to use the recursive definitions to create an actual “math object”.

For example, if we consider a function with no fixed points over RR\mathbb{R}\rightarrow \mathbb{R}, e.g. f(x)=x+1f (x) = x + 1 In lean, the positivity check verifies that the function we’re using to build a type is monotone!

For example, when defining the type Nat, the constructor might have a parameter of type Nat, e.g. :

    Nat : 
    | zero : Nat
    | succ (n : Nat) : Nat

the positivity check ensures that the function f mapping a set of candidates for Nat to a new, larger set is indeed a monotone function on the lattice of all possible subsets of Nat. On the complete lattice L = \{S \;|\;\ S\subseteq \mathbb{N}}, the function we use to construct the type is f(S)={0}{sS,succ(s)}f(S) = \{0\}\cup \{\forall s\in S, succ(s)\} and checking its monotonicity ensures that the ff has a fixed point, i.e. a set S=f(S)S = f(S) ensuring the validity of the construction.

TODO: find an example with a non monotone function!