Basic logic properties #
This file is one of the earliest imports in mathlib.
Implementation notes #
Theorems that require decidability hypotheses are in the namespace Decidable
.
Classical versions are in the namespace Classical
.
Equations
Wrapper for adding elementary propositions to the type class systems. Warning: this can easily be abused. See the rest of this docstring for details.
Certain propositions should not be treated as a class globally, but sometimes it is very convenient to be able to use the type class system in specific circumstances.
For example, ZMod p
is a field if and only if p
is a prime number.
In order to be able to find this field instance automatically by type class search,
we have to turn p.prime
into an instance implicit assumption.
On the other hand, making Nat.prime
a class would require a major refactoring of the library,
and it is questionable whether making Nat.prime
a class is desirable at all.
The compromise is to add the assumption [Fact p.prime]
to ZMod.field
.
In particular, this class is not intended for turning the type class system into an automated theorem prover for first order logic.
- out : p
Instances
Equations
- instDecidableFact = decidable_of_iff p ⋯
Swaps two pairs of arguments to a function.
Equations
- Function.swap₂ f i₂ j₂ i₁ j₁ = f i₁ j₁ i₂ j₂
Instances For
Declarations about propositional connectives #
Declarations about implies
#
Alias of Decidable.not_imp_symm
.
Alias of the forward direction of and_rotate
.
Declarations about distributivity #
Declarations about iff
De Morgan's laws #
Declarations about equality #
Alias of ne_of_mem_of_not_mem
.
Alias of ne_of_mem_of_not_mem'
.
Alias of forall_cond_comm
.
Alias of forall_mem_comm
.
Alias of ne_of_eq_of_ne
.
Alias of ne_of_ne_of_eq
.
Declarations about quantifiers #
We intentionally restrict the type of α
in this lemma so that this is a safer to use in simp
than forall_swap
.
Alias of propext
.
The axiom of propositional extensionality. It asserts that if propositions
a
and b
are logically equivalent (i.e. we can prove a
from b
and vice versa),
then a
and b
are equal, meaning that we can replace a
with b
in all
contexts.
For simple expressions like a ∧ c ∨ d → e
we can prove that because all the logical
connectives respect logical equivalence, we can replace a
with b
in this expression
without using propext
. However, for higher order expressions like P a
where
P : Prop → Prop
is unknown, or indeed for a = b
itself, we cannot replace a
with b
without an axiom which says exactly this.
This is a relatively uncontroversial axiom, which is intuitionistically valid.
It does however block computation when using #reduce
to reduce proofs directly
(which is not recommended), meaning that canonicity,
the property that all closed terms of type Nat
normalize to numerals,
fails to hold when this (or any) axiom is used:
set_option pp.proofs true
def foo : Nat := by
have : (True → True) ↔ True := ⟨λ _ => trivial, λ _ _ => trivial⟩
have := propext this ▸ (2 : Nat)
exact this
#reduce foo
-- propext { mp := fun x x => True.intro, mpr := fun x => True.intro } ▸ 2
#eval foo -- 2
#eval
can evaluate it to a numeral because the compiler erases casts and
does not evaluate proofs, so propext
, whose return type is a proposition,
can never block it.
Instances For
See IsEmpty.forall_iff
for the False
version.
Classical lemmas #
Any prop p
is decidable classically. A shorthand for Classical.propDecidable
.
Equations
- Classical.dec p = inferInstance
Instances For
Any type α
has decidable equality classically.
Equations
- Classical.decEq α = inferInstance
Instances For
Construct a function from a default value H0
, and a function to use if there exists a value
satisfying the predicate.
Equations
- Classical.existsCases H0 H = if h : ∃ (a : α), p a then H (Classical.choose h) ⋯ else H0
Instances For
A version of Classical.indefiniteDescription
which is definitionally equal to a pair.
In Lean 4, this definition is defeq to Classical.indefiniteDescription
,
so it is deprecated.
Equations
- Classical.subtype_of_exists h = ⟨Classical.choose h, ⋯⟩
Instances For
A version of byContradiction
that uses types instead of propositions.
Equations
Instances For
Classical.byContradiction'
is equivalent to lean's axiom Classical.choice
.
Equations
- Classical.choice_of_byContradiction' contra H = contra ⋯
Instances For
Alias of Classical.axiomOfChoice
.
the axiom of choice
Alias of Classical.byCases
.
Alias of Classical.byContradiction
.
Alias of Classical.propComplete
.
This function has the same type as Exists.recOn
, and can be used to case on an equality,
but Exists.recOn
can only eliminate into Prop, while this version eliminates into any universe
using the axiom of choice.
Equations
- h.classicalRecOn H = H (Classical.choose h) ⋯
Instances For
Declarations about bounded quantifiers #
Alias of forall₂_congr
.
Alias of exists_mem_of_exists
.
Alias of exists_of_exists_mem
.
A two-argument function applied to two ite
s is a ite
of that two-argument function
applied to each of the branches.