Predicate logic in Lean
Like with propositional logic, Lean has the rules of predicate logic embedded within it.
As we discussed, predicates are analogous to functions which output propositions. We can declare predicates in Lean as ‘
A new subtlety is variable (α : Type)
. In predicate logic, we have domain of discourse, which is the source of values for the input variables of our predicates. In Lean, we have to declare that we have some source of inputs of our predicates. This notation tells Lean that we have something α
whose type is the generic Type
.
Then A
is a predicate on a single variable and B
is one on two variables.
We can understand $\forall x~ A(x)$ as saying that no matter what the value of $x$ is we have a proof of $A(x)$. In this way, we can think of a proof of $\forall x~ A(x)$ as a function whose inputs are $x$’s and whose outputs are proofs of $A(x)$.
In Lean, this is how ∀
is understood. For example, if we look at
we will see
Given any pair of propositions P
and Q
, the “theorem” not_true
produces a (sorried) proof of P → Q
. Lean represents this using a ∀
.
Since ∀
is implemented via as a function, the introduction and elimination rules are familiar.
Next, let’s look at the existential quantifier ∃
.
Given a domain of discourse α
and a predicate A : α → Prop
, the existential quantification ∃ x, A x
is a proposition. This is what Exists
models.
Then, we have our introduction and elimination rules for ∃
built in to Exists
. Existential introduction takes
- a domain of discourse
α
(which Lean tries to infer from the context), - a predicate
p : α → Prop
(inferred if possible), - and a value
(w : α)
and yields a function that converts proofs of the proposition to p w
to an existentially quantified proposition.
Elimination will take
- a domain of discourse
α
(inferred), - a predicate
p
(inferred), - a proposition
b
, - a proof of
∃ x, p x
, - a proof of
∀ (a : α), p a → b
(ie a function with inputsa
and a proof ofp a
and output a proof ofb
),
and will return a proof of b
. If we have some value where p
is true and for any value p x
implies b
, then we can conclude b
.
Here are simple example uses.
Next, we have equality, $=$.
Equality at its most basic level is a special named predicate on two variables. But, we remember it satisfies some properties. Firstly, reflexivity, symmetry, and transistivity. These becomes ways to build equality.
There are also substitution rules for equality, one involving function application and one for predicates.