Chapter 5

Propositions as types, Absurd, Trivial and the universe

Chapter 4 treated = as a type whose elements are proofs. This section extends that reading to all of Pie’s types, which is the Curry–Howard correspondence. It then looks at Absurd, which has no elements, and Trivial, which has exactly one, and at their unusual equality rules. It ends with the universe U and with what Pie does to keep U out of itself.

5.1Curry–Howard

A type can be read as a proposition, and an element of the type as a proof of itW. A. Howard. The Formulae-as-Types Notion of Construction. In J. P. Seldin and J. R. Hindley, editors, To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pages 479–490. Academic Press, London, 1980.

Table 5.1: Reading Pie types as propositions. The arrow →→ in the logic column is implication.

logicPie type
∀x:A. P\forall x{:}A.\,P(Π ((x A)) P)
P→QP \rightarrow Q(→ P Q)
∃x:A. P\exists x{:}A.\,P(Σ ((x A)) P)
P∧QP \wedge Q(Pair P Q)
P∨QP \vee Q(Either P Q)
⊤\topTrivial
⊥\botAbsurd
¬P\neg P(→ P Absurd)
a=ba = b(= A a b)

Table 5.1 lists the translation. Pie has no separate logic. The checker that accepts a proof is the same checker that accepts a program, and a proof normalizes like any other expression.

The proofs are constructive. A proof of ∃m. m=n+1\exists m.\, m = n+1 is a pair whose car is the witness mm, so we can take the witness out of the proof and compute with it:

succ-exists.pie

(claim succ-exists
  (Π ((n Nat))
    (Σ ((m Nat))
      (= Nat m (add1 n)))))
(define succ-exists
  (λ (n)
    (cons (add1 n) (same (add1 n)))))
(succ-exists 4)
(car (succ-exists 4))
(the (Σ ((m Nat))
      (= Nat m 5))
  (cons 5
    (same 5)))
(the Nat 5)

A predicate is a function into U, such as Even of Section 3.5, which sends nn to a Σ-type that pairs a half with a proof that nn is its double. A proof of a disjunction says which side holds, as the run of even-or-odd there shows. A proof of a negation is a function into Absurd, the subject of the next subsection.

5.2Absurd and ex falso

Absurd is the empty type. It synthesizes U like any other type (typechecker.rkt:415–416), but it has no constructor, so a closed expression of type Absurd must contain a hole, as (the Absurd TODO) does (Section 10.1). Its only eliminator is ind-Absurd, the principle ex falso quodlibet:

Γ⊢t⇐𝖠𝖻𝗌𝗎𝗋𝖽⇝t′Γ⊢m⇐𝖴⇝m′Γ⊢(ind-Absurd t m)⇒m′⇝(ind-Absurd t′ m′)  (IndAbsurd) \dfrac{\Gamma \vdash t \Leftarrow \mathsf{Absurd} \rightsquigarrow t' \qquad \Gamma \vdash m \Leftarrow \mathsf{U} \rightsquigarrow m'}{\Gamma \vdash \texttt{(ind-Absurd}\ t\ m\texttt{)} \Rightarrow m' \rightsquigarrow \texttt{(ind-Absurd}\ t'\ m'\texttt{)}} \; (\text{IndAbsurd})

The code follows the rule premise by premise (typechecker.rkt:417–420):

417     [`(ind-Absurd ,tgt ,mot)
418      (go-on ((tgt-out (check Γ r tgt 'ABSURD))
419              (mot-out (check Γ r mot 'UNIVERSE)))
420        (go `(the ,mot-out (ind-Absurd ,tgt-out ,mot-out))))]

The motive is a type, not a function from Absurd to types as in the other ind- forms (Table 3.1). When the result type should mention the target x, the motive can mention x directly, because x is already in Γ.

There is no constructor to compute with, so ind-Absurd never reduces. do-ind-Absurd has a clause for a neutral target and no other (normalize.rkt:239–243):

239(define (do-ind-Absurd tgt-v mot-v)
240  (match (now tgt-v)
241    [(NEU (!! ABSURD) ne)
242     (NEU mot-v
243          (N-ind-Absurd ne (THE 'UNIVERSE mot-v)))]))

The bare ABSURD at line 241 is a pattern variable, not the symbol 'ABSURD, so the clause accepts a neutral of any type. This is harmless on well-typed input (Section 8.7).In a well-typed program the target is always a neutral value of type Absurd (a variable, a hole, or a stuck elimination), so this single case suffices.

efq.pie

(claim efq (Π ((A U)) (→ Absurd A)))
(define efq (λ (A bot) (ind-Absurd bot A)))
efq
[…]
  (λ (A bot)
    (ind-Absurd (the Absurd bot)
       A)))

Read-back inserted the annotation (the Absurd bot), for a reason given in Section 5.3.

To refute an equation between distinct constructors, the standard technique is to transport a trivial proof along it with replace (Section 4.4). The motive sends 0 to Trivial and every add1 to Absurd:

zero-not-one.pie

(claim zero-not-one (→ (= Nat 0 1) Absurd))
(define zero-not-one
  (λ (p)
    (replace p
      (λ (n) (which-Nat n Trivial (λ (k) Absurd)))
      sole)))
zero-not-one
(the (→ (= Nat 0 1)
       Absurd)
  (λ (p)
    (the Absurd
      (replace p
[…]
        sole))))

replace checks its base against the motive at from, which computes to Trivial, so sole fits. It synthesizes the motive at to, which computes to Absurd (typechecker.rkt:427–440). The motive has to be written with a non-dependent eliminator such as which-Nat, which synthesizes the type of its base, and Trivial synthesizes U (typechecker.rkt:356–357). An ind-Nat motive would have to return U, which is impossible (Section 3.2). The normal form keeps the replace, because its target p is a variable, and wraps it in (the Absurd …) because its type is Absurd.

5.3η for Trivial and Absurd

Trivial has one element, sole, which synthesizes Trivial (typechecker.rkt:358–359). It has no eliminator, since taking sole apart teaches nothing, but it has an η-rule, which makes every expression of type Trivial, a variable included, definitionally equal to sole. The rule lives in read-back, which ignores the value entirely when the type is Trivial (normalize.rkt:592):

592    [('TRIVIAL _) 'sole] ;; η-expansion

trivial-eta.pie

(check-same (→ Trivial Trivial) (λ (x) sole) (λ (y) y))
(the (→ Trivial (Pair Trivial Trivial))
  (λ (x) (cons x x)))
(the (Π ((x Trivial) (y Trivial)) (= Trivial x y))
  (λ (x y) (same sole)))
(the (→ Trivial
       (Pair Trivial Trivial))
  (λ (x)
    (cons sole sole)))
(the (→ Trivial Trivial
       (= Trivial sole sole))
  (λ (x y)
    (same sole)))

The check-same succeeds silently. In the first result the body (cons x x) has become (cons sole sole). In the second the variables have vanished from the printed type. Read-back turned x and y into sole, and the resugarer then printed the Π, which no longer mentions its variables, as an arrow (Section 9.6).

Absurd has no closed elements, so a rule that makes all of its elements equal only identifies hypothetical proofs, such as two variables of type Absurd. Pie has this rule, in two halves. Read-back wraps every neutral of type Absurd in an annotation (normalize.rkt:596–599, and the same for the target of a stuck ind-Absurd at 656–659):

596    [('ABSURD (NEU _ ne))
597     ;; This type annotation is half of the η law. See the
598     ;; implementation of α-equiv? for the other half.
599     `(the Absurd ,(read-back-neutral Γ ne))]

α-equivalence then equates any two annotated terms, whatever is inside (alpha.rkt:69–70):

69    ;; η for Absurd relies on read-back inserting an annotation
70    [(`(the Absurd ,_) `(the Absurd ,_)) #t]

Neither half works alone. Without the annotation, α-equivalence would compare x with y by name. Without the α-rule, the annotation would be inert.So any two proofs of Absurd are equal. The next file uses the rule three times:

absurd-eta.pie

(check-same (→ (→ (= Nat 2 3) Absurd)
               (→ (= Nat 2 3) Absurd)
               (→ (= Nat 2 3) Absurd))
  (λ (f g) f)
  (λ (f g) g))
(check-same (→ Absurd Absurd Nat)
  (λ (x y) (ind-Absurd x Nat))
  (λ (x y) (ind-Absurd y Nat)))
(claim abs-eta (Π ((x Absurd) (y Absurd)) (= Absurd x y)))
(define abs-eta (λ (x y) (same x)))
abs-eta
(the (Π ((x Absurd)
         (y Absurd))
      (= Absurd
        (the Absurd x)
        (the Absurd y)))
  (λ (x y)
    (same (the Absurd x))))

same needs x ≡ x and y ≡ x at Absurd, and the second holds by the rule above. The two check-sames succeed silently. The first compares two proofs of a negation, f and g. Π-η applies both to a fresh variable, and the two results are neutrals of type Absurd. The second compares two stuck ind-Absurds, whose targets read back inside the annotation.

The rule identifies elements of Absurd, not everything in a context that contains one. Under a hypothesis x : Absurd, (ind-Absurd x Nat) and 0 are still different Nats, and check-same rejects them (absurd-no-collapse.pie).Other systems differ here. Agda has η for record types, which covers its unit type, but no definitional η for its empty type. In Lean 4, False lives in Prop, which has definitional proof irrelevance, so any two proofs of False are definitionally equal. Table 8.2 in Section 8.4 collects all of Pie’s η-rules.

5.4The universe U

Types are values, so they need a type of their own. That type is U. Four rules govern it:

Γ⊢𝖴 𝗍𝗒𝗉𝖾  (UType)Γ⊢𝖭𝖺𝗍⇒𝖴  (NatU) \dfrac{}{\Gamma \vdash \mathsf{U}\ \mathsf{type}} \; (\text{UType}) \qquad\qquad \dfrac{}{\Gamma \vdash \mathsf{Nat} \Rightarrow \mathsf{U}} \; (\text{NatU}) Γ⊢A⇐𝖴⇝A′Γ,x:A′⊢B⇐𝖴⇝B′Γ⊢(Π ((x A)) B)⇒𝖴⇝(Π ((x A′)) B′)  (PiU) \dfrac{\Gamma \vdash A \Leftarrow \mathsf{U} \rightsquigarrow A' \qquad \Gamma, x{:}A' \vdash B \Leftarrow \mathsf{U} \rightsquigarrow B'}{\Gamma \vdash \texttt{(}\Pi\ \texttt{((}x\ A\texttt{))}\ B\texttt{)} \Rightarrow \mathsf{U} \rightsquigarrow \texttt{(}\Pi\ \texttt{((}x\ A'\texttt{))}\ B'\texttt{)}} \; (\text{PiU}) Γ⊢e⇐𝖴⇝cΓ⊢e 𝗍𝗒𝗉𝖾⇝c  (ElU) \dfrac{\Gamma \vdash e \Leftarrow \mathsf{U} \rightsquigarrow c}{\Gamma \vdash e\ \mathsf{type} \rightsquigarrow c} \; (\text{ElU})

UType is the line ['U (go 'U)] of is-type (typechecker.rkt:96), NatU is at line 205, and the other base types are alike. PiU is at 226–235: a type former is in U only if its parts are, and Σ, List, =, Vec and Either follow the same pattern (Table 2.1). ElU, the last clause of is-type (typechecker.rkt:179–192), applies when no type former matches and asks whether the expression checks against U.Martin-Löf distinguishes universes “à la Russell”, whose elements are themselves types, from universes “à la Tarski”, which need a decoding function, often called 𝖤𝗅\mathsf{El}. Pie’s U is of the first kind.Per Martin-Löf. Intuitionistic Type Theory. Bibliopolis, Naples, 1984. Notes by Giovanni Sambin There is no decoding step, so a defined Pear : U can appear after the, as below.

What is missing is a rule that gives U itself a type. synth has a clause for U, and it fails (typechecker.rkt:206–208):

206     ['U (stop (src-loc e)
207               `(U
208                 "is a type, but it does not have a type."))]

U-in-U.pie

(the U U)
 U is a type, but it does not have a type.
  location...:
   U-in-U.pie:2:7

So there are two different judgments. “AA type” says that AA may be used as a type. “A⇐𝖴A \Leftarrow \mathsf{U}” says that AA is an element of the universe. Every element of U is a type, by ElU, but the converse fails. U is a type and not an element of U. Any type built from U, such as (List U) or (Π ((A U)) (→ A A)), is also a type and not an element of U. For the List case, is-type checks the element type with is-type (161–163), while the U rule checks it against U (408–410). The next program shows both sides; the comments number the forms that print.

universe.pie

(claim Pear U)
(define Pear (Pair Nat Nat))
(the Pear (cons 3 5)) ; (1)
(claim types (List U))
(define types (:: Nat (:: Atom nil)))
types ; (2)
(Π ((A U)) (→ A A)) ; (3)
(the (Π ((A U)) U) (λ (B) B)) ; (4)
U ; (5)
(claim id (Π ((A U)) (→ A A)))
(define id (λ (A a) a))
(id Nat 3) ; (6)
(the (Pair Nat Nat)
  (cons 3 5))
(the (List U)
  (:: Nat
    (:: Atom nil)))
(Π ((A U))
 (→ A
   A))
(the (→ U
       U)
  (λ (B)
    B))
U
(the Nat 3)

(List U) is a type with an inhabitant, a list of two types. A function from types to types, (λ (B) B), is fine too. Its type (→ U U) is a type but not an element of U. In (6), id takes the type Nat as its first argument. (Π ((A U)) (→ A A)) and U print without the, because synthesis fails for them (Section 9.5).

Treating such a type as an element of U, as in (the U (List U)), fails with the same message, located at the inner U (List-U.pie).

Pie is therefore predicative. A type that quantifies over all types is not itself one of the types it quantifies over, so the polymorphic id cannot be applied to its own type (id-self.pie). A universe that contains itself, 𝖴:𝖴\mathsf{U} : \mathsf{U}, makes the type theory inconsistent. This is Girard’s paradoxJean-Yves Girard. Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. Thèse d’État, Université Paris VII, 1972, simplified by HurkensAntonius J. C. Hurkens. A Simplification of Girard’s Paradox. In Typed Lambda Calculi and Applications (TLCA ’95), volume 902 of Lecture Notes in Computer Science, pages 266–278. Springer, 1995. Martin-Löf’s predicative type theory avoids it by keeping each universe out of itselfPer Martin-Löf. An Intuitionistic Theory of Types: Predicative Part. In H. E. Rose and J. C. Shepherdson, editors, Logic Colloquium ’73, volume 80 of Studies in Logic and the Foundations of Mathematics, pages 73–118. North-Holland, Amsterdam, 1975.

Agda has a hierarchy Set ℓ\ell with universe polymorphism over levels. Rocq has a cumulative hierarchy Type@{i} and, in addition, an impredicative universe Prop. Lean 4 has a non-cumulative hierarchy Sort u with universe polymorphism, whose bottom Sort 0 is the impredicative Prop. Table 10.1 in Chapter 10 compares the systems. Most systems then add a tower of universes 𝖴0:𝖴1:𝖴2:⋯\mathsf{U}_0 : \mathsf{U}_1 : \mathsf{U}_2 : \cdots, so that (Π ((A U)) (→ A A)) would live in the next universe up. Pie stops at one. It has no hierarchy, no cumulativity and no universe polymorphism. Types built from U can be written and used, but nothing classifies them. In exchange the checker needs no universe levels and no constraints between them.