L∃∀N-verified Quantum Information Theory

  • RRS to QIC891, Fall 2026

  • Lecture 4, 2026-09-24

\Gamma ⊢ t : T

Coming back to the questions

  • Axioms

  • Universes

  • Sets vs types

    • with a proof of set equality, setEq by funext and propext --

  • Metaprogramming types

  • Equalities,

    • rfl the theorem, and rfl the tactic

  • More complex mathematical structures

    • Lean's structure and class

Everything has a type

  • Does something like #check have a type?

    • Yes, it has, as it should.

    • Error from #check #check is about how Lean is built.

    • Separation from the metaprogramming.

    • Not everything is a type.

open Lean Elab Command Meta -- #check #check -- Unexpected token #check; expected term #print Lean.Parser.Command.check
def Lean.Parser.Command.check : Parser.Parser := Parser.withCache `Lean.Parser.Command.check (Parser.withAntiquot (Parser.mkAntiquot "check" `Lean.Parser.Command.check) (Parser.leadingNode `Lean.Parser.Command.check 1024 (Parser.symbol "#check " >> Parser.termParser)))
#check Lean.Parser.Command.check
Lean.Parser.Command.check : Parser.Parser
#print Lean.Elab.Command.CommandElab
@[reducible] def Lean.Elab.Command.CommandElab : Type := Syntax → CommandElabM Unit

What is “equality of propositions”?

#check propext -- Propositional extensionality
propext {a b : Prop} : (a ↔ b) → a = b
variable {a b : Prop} #check a = b -- To understand this equation, consider
a = b : Prop
example (hab : a = b) (p : Prop → Prop) (ha : p a) : p b := Eq.subst hab ha /- `p _` can be `c And _`. So take `p := fun q => c And q` to be true (`p a`). Then assume `a = b`. Lean can substitute `a` for `b` such that `p b` holds. If this `p(a)` holds, then `a` individually does. Because `a = b`, `b` also holds. So `p b := c And b` must also hold. -/
example (hab : a ↔ b) (p : Prop → Prop) (ha : p a) : p b := by exact Iff.subst hab ha -- `Iff.subst` uses `propext` and `Eq.subst`! variable {a b : Type u} #check Eq a b -- Underlying notation of `a = b` -- `Eq.{u}` is _polymorphic_
a = b : Prop
variable {a : Type u} {b : Type v} #check Eq a b
a = sorry : Prop

Different notions of equality

  • “Syntax equality” :=

    • def name : type := term

    • theorem name : type := term

  • rfl : a = a is proof of a = b only when a and b are def. eq.

Equalities in code

#check 2 = 2
2 = 2 : Prop
#check @Eq.{u}
@Eq : {α : Sort u} → α → α → Prop
#check Eq 2 2
2 = 2 : Prop
#eval 2 = 2 -- `true` or `True`?
true
#check 2 == 2
2 == 2 : Bool
#eval 2 == 2
true
#check BEq -- *class* with `beq : α → α → Bool` -- (i.e. structure with canon instance) -- Init/Prelude.lean
BEq.{u} (α : Type u) : Type u
#check BEq Nat
BEq ℕ : Type
#eval decide (2 = 2) -- Connects `Prop` to `Bool`
true
#check BEq 2 2

More complex mathematical definitions

  • Mathlib_surfing in Blackboard.lean

Structures and classes

  • Lean's structure and class are used to define

    • structure CPTPMap m n 𝕜, in QuantumInfo

    • Matrix m n α contains instances, e.g. Matrix.add

      • HermitianMat, in QuantumInfo

      • MState.instCoe

    • class InnerProductSpace, in Mathlib

      • Typeclass resolution