RRS to QIC891, Fall 2026
Lecture 4, 2026-09-24
\Gamma ⊢ t : T
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
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
#printdef 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))) 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)))#checkLean.Parser.Command.check : Parser.Parser Lean.Parser.Command.check
Lean.Parser.Command.check : Parser.Parser#print@[reducible] def Lean.Elab.Command.CommandElab : Type :=
Syntax → CommandElabM Unit Lean.Elab.Command.CommandElab
@[reducible] def Lean.Elab.Command.CommandElab : Type :=
Syntax → CommandElabM Unit
#checkpropext {a b : Prop} : (a ↔ b) → a = b propext
-- Propositional extensionality
propext {a b : Prop} : (a ↔ b) → a = bvariable {a b : Prop}
#checka = b : Prop a = b
-- To understand this equation, consider
a = b : Propexample
(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 := bya:Propb:Prophab:a ↔ bp:Prop → Propha:p a⊢ p b exact Iff.subst hab haAll goals completed! 🐙
-- `Iff.subst` uses `propext` and `Eq.subst`!
variable {a b : Type u}
#checka = b : Prop Eq a b
-- Underlying notation of `a = b`
-- `Eq.{u}` is _polymorphic_
a = b : Propvariable {a : Type u} {b : Type v}
#checka = sorry : Prop Eq a bApplication type mismatch: The argument
b
has type
Type v
of sort `Type (v + 1)` but is expected to have type
Type u
of sort `Type (u + 1)` in the application
a = b
a = sorry : Prop
“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.
Propositional_Eq in Blackboard.lean
Boolean equality, BEq, or ==.
In contrast: Bool type or Prop type?
#check2 = 2 : Prop 2 = 2
2 = 2 : Prop#check@Eq : {α : Sort u} → α → α → Prop @Eq.{u}
@Eq : {α : Sort u} → α → α → Prop#check2 = 2 : Prop Eq 2 2
2 = 2 : Prop#evaltrue 2 = 2
-- `true` or `True`?
true
#check2 == 2 : Bool 2 == 2
2 == 2 : Bool#evaltrue 2 == 2
true#checkBEq.{u} (α : Type u) : Type u BEq
-- *class* with `beq : α → α → Bool`
-- (i.e. structure with canon instance)
-- Init/Prelude.lean
BEq.{u} (α : Type u) : Type u#checkBEq ℕ : Type BEq Nat
BEq ℕ : Type#evaltrue decide (2 = 2)
-- Connects `Prop` to `Bool`
true#check BEq 2failed to synthesize instance of type class
OfNat (Type ?u.7) 2
numerals are polymorphic in Lean, but the numeral `2` cannot be used in a context where the expected type is
Type ?u.7
due to the absence of the instance above
Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command. 2
Mathlib_surfing in Blackboard.lean
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