refactor(library): mark 'decidable' theorems as definitions
If we don't do that, then any 'if' term that uses one of these theorems will get "stuck". That is, the kernel will not be able to reduce them because theorems are always opaque
This commit is contained in:
parent
41acc10d49
commit
3ca1264f61
12 changed files with 30 additions and 29 deletions
|
@ -138,7 +138,7 @@ namespace bool
|
||||||
protected theorem is_inhabited [instance] : inhabited bool :=
|
protected theorem is_inhabited [instance] : inhabited bool :=
|
||||||
inhabited.mk ff
|
inhabited.mk ff
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] : decidable_eq bool :=
|
protected definition has_decidable_eq [instance] : decidable_eq bool :=
|
||||||
take a b : bool,
|
take a b : bool,
|
||||||
rec_on a
|
rec_on a
|
||||||
(rec_on b (inl rfl) (inr ff_ne_tt))
|
(rec_on b (inl rfl) (inr ff_ne_tt))
|
||||||
|
|
|
@ -203,8 +203,9 @@ exists_intro (pr1 (rep a))
|
||||||
a = psub (rep a) : (psub_rep a)⁻¹
|
a = psub (rep a) : (psub_rep a)⁻¹
|
||||||
... = psub (pair (pr1 (rep a)) (pr2 (rep a))) : {(prod_ext (rep a))⁻¹}))
|
... = psub (pair (pr1 (rep a)) (pr2 (rep a))) : {(prod_ext (rep a))⁻¹}))
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] : decidable_eq ℤ :=
|
-- TODO it should not be opaque.
|
||||||
take a b : ℤ, _
|
protected opaque definition has_decidable_eq [instance] : decidable_eq ℤ :=
|
||||||
|
_
|
||||||
|
|
||||||
irreducible int
|
irreducible int
|
||||||
definition of_nat [coercion] (n : ℕ) : ℤ := psub (pair n 0)
|
definition of_nat [coercion] (n : ℕ) : ℤ := psub (pair n 0)
|
||||||
|
|
|
@ -422,8 +422,8 @@ Hn⁻¹ ▸ congr_arg of_nat (to_nat_of_nat n)
|
||||||
theorem of_nat_nonneg (n : ℕ) : of_nat n ≥ 0 :=
|
theorem of_nat_nonneg (n : ℕ) : of_nat n ≥ 0 :=
|
||||||
iff.mp (iff.symm (le_of_nat _ _)) zero_le
|
iff.mp (iff.symm (le_of_nat _ _)) zero_le
|
||||||
|
|
||||||
theorem le_decidable [instance] {a b : ℤ} : decidable (a ≤ b) :=
|
definition le_decidable [instance] {a b : ℤ} : decidable (a ≤ b) :=
|
||||||
have aux : ∀x, decidable (0 ≤ x), from
|
have aux : Πx, decidable (0 ≤ x), from
|
||||||
take x,
|
take x,
|
||||||
have H : 0 ≤ x ↔ of_nat (to_nat x) = x, from
|
have H : 0 ≤ x ↔ of_nat (to_nat x) = x, from
|
||||||
iff.intro
|
iff.intro
|
||||||
|
@ -432,9 +432,9 @@ have aux : ∀x, decidable (0 ≤ x), from
|
||||||
decidable_iff_equiv _ (iff.symm H),
|
decidable_iff_equiv _ (iff.symm H),
|
||||||
decidable_iff_equiv (aux _) (iff.symm (le_iff_sub_nonneg a b))
|
decidable_iff_equiv (aux _) (iff.symm (le_iff_sub_nonneg a b))
|
||||||
|
|
||||||
theorem ge_decidable [instance] {a b : ℤ} : decidable (a ≥ b)
|
definition ge_decidable [instance] {a b : ℤ} : decidable (a ≥ b) := _
|
||||||
theorem lt_decidable [instance] {a b : ℤ} : decidable (a < b)
|
definition lt_decidable [instance] {a b : ℤ} : decidable (a < b) := _
|
||||||
theorem gt_decidable [instance] {a b : ℤ} : decidable (a > b)
|
definition gt_decidable [instance] {a b : ℤ} : decidable (a > b) := _
|
||||||
|
|
||||||
--to_nat_neg is already taken... rename?
|
--to_nat_neg is already taken... rename?
|
||||||
theorem to_nat_negative {a : ℤ} (H : a ≤ 0) : (to_nat a) = -a :=
|
theorem to_nat_negative {a : ℤ} (H : a ≤ 0) : (to_nat a) = -a :=
|
||||||
|
|
|
@ -204,7 +204,7 @@ induction_on l
|
||||||
from H3 ▸ rfl,
|
from H3 ▸ rfl,
|
||||||
exists_intro _ (exists_intro _ H4)))
|
exists_intro _ (exists_intro _ H4)))
|
||||||
|
|
||||||
theorem mem_is_decidable [instance] {H : decidable_eq T} {x : T} {l : list T} : decidable (x ∈ l) :=
|
definition mem_is_decidable [instance] {H : decidable_eq T} {x : T} {l : list T} : decidable (x ∈ l) :=
|
||||||
rec_on l
|
rec_on l
|
||||||
(decidable.inr (iff.false_elim mem_nil))
|
(decidable.inr (iff.false_elim mem_nil))
|
||||||
(λ (h : T) (l : list T) (iH : decidable (x ∈ l)),
|
(λ (h : T) (l : list T) (iH : decidable (x ∈ l)),
|
||||||
|
|
|
@ -105,7 +105,7 @@ induction_on n
|
||||||
absurd H ne)
|
absurd H ne)
|
||||||
(take k IH H, IH (succ_inj H))
|
(take k IH H, IH (succ_inj H))
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] : decidable_eq ℕ :=
|
protected definition has_decidable_eq [instance] : decidable_eq ℕ :=
|
||||||
take n m : ℕ,
|
take n m : ℕ,
|
||||||
have general : ∀n, decidable (n = m), from
|
have general : ∀n, decidable (n = m), from
|
||||||
rec_on m
|
rec_on m
|
||||||
|
|
|
@ -230,7 +230,7 @@ le_trans (mul_le_right H1 m) (mul_le_left H2 k)
|
||||||
|
|
||||||
-- mul_le_[left|right]_inv below
|
-- mul_le_[left|right]_inv below
|
||||||
|
|
||||||
theorem le_decidable [instance] (n m : ℕ) : decidable (n ≤ m) :=
|
definition le_decidable [instance] (n m : ℕ) : decidable (n ≤ m) :=
|
||||||
have general : ∀n, decidable (n ≤ m), from
|
have general : ∀n, decidable (n ≤ m), from
|
||||||
rec_on m
|
rec_on m
|
||||||
(take n,
|
(take n,
|
||||||
|
@ -422,9 +422,9 @@ theorem not_le_imp_gt {n m : ℕ} (H : ¬ n ≤ m) : n > m :=
|
||||||
or.resolve_right le_or_gt H
|
or.resolve_right le_or_gt H
|
||||||
|
|
||||||
-- The following three theorems are automatically proved using the instance le_decidable
|
-- The following three theorems are automatically proved using the instance le_decidable
|
||||||
theorem lt_decidable [instance] (n m : ℕ) : decidable (n < m)
|
definition lt_decidable [instance] (n m : ℕ) : decidable (n < m) := _
|
||||||
theorem gt_decidable [instance] (n m : ℕ) : decidable (n > m)
|
definition gt_decidable [instance] (n m : ℕ) : decidable (n > m) := _
|
||||||
theorem ge_decidable [instance] (n m : ℕ) : decidable (n ≥ m)
|
definition ge_decidable [instance] (n m : ℕ) : decidable (n ≥ m) := _
|
||||||
|
|
||||||
-- Note: interaction with multiplication under "positivity"
|
-- Note: interaction with multiplication under "positivity"
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace option
|
||||||
protected theorem is_inhabited [instance] (A : Type) : inhabited (option A) :=
|
protected theorem is_inhabited [instance] (A : Type) : inhabited (option A) :=
|
||||||
inhabited.mk none
|
inhabited.mk none
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] {A : Type} (H : decidable_eq A) : decidable_eq (option A) :=
|
protected definition has_decidable_eq [instance] {A : Type} (H : decidable_eq A) : decidable_eq (option A) :=
|
||||||
take o₁ o₂ : option A,
|
take o₁ o₂ : option A,
|
||||||
rec_on o₁
|
rec_on o₁
|
||||||
(rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))
|
(rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))
|
||||||
|
|
|
@ -48,7 +48,7 @@ section
|
||||||
protected theorem is_inhabited [instance] (H1 : inhabited A) (H2 : inhabited B) : inhabited (prod A B) :=
|
protected theorem is_inhabited [instance] (H1 : inhabited A) (H2 : inhabited B) : inhabited (prod A B) :=
|
||||||
inhabited.destruct H1 (λa, inhabited.destruct H2 (λb, inhabited.mk (pair a b)))
|
inhabited.destruct H1 (λa, inhabited.destruct H2 (λb, inhabited.mk (pair a b)))
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] (H1 : decidable_eq A) (H2 : decidable_eq B) : decidable_eq (A × B) :=
|
protected definition has_decidable_eq [instance] (H1 : decidable_eq A) (H2 : decidable_eq B) : decidable_eq (A × B) :=
|
||||||
take u v : A × B,
|
take u v : A × B,
|
||||||
have H3 : u = v ↔ (pr1 u = pr1 v) ∧ (pr2 u = pr2 v), from
|
have H3 : u = v ↔ (pr1 u = pr1 v) ∧ (pr2 u = pr2 v), from
|
||||||
iff.intro
|
iff.intro
|
||||||
|
|
|
@ -41,7 +41,7 @@ section
|
||||||
protected theorem is_inhabited [instance] {a : A} (H : P a) : inhabited {x, P x} :=
|
protected theorem is_inhabited [instance] {a : A} (H : P a) : inhabited {x, P x} :=
|
||||||
inhabited.mk (tag a H)
|
inhabited.mk (tag a H)
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] (H : decidable_eq A) : decidable_eq {x, P x} :=
|
protected definition has_decidable_eq [instance] (H : decidable_eq A) : decidable_eq {x, P x} :=
|
||||||
take a1 a2 : {x, P x},
|
take a1 a2 : {x, P x},
|
||||||
have H1 : (a1 = a2) ↔ (elt_of a1 = elt_of a2), from
|
have H1 : (a1 = a2) ↔ (elt_of a1 = elt_of a2), from
|
||||||
iff.intro (assume H, eq.subst H rfl) (assume H, equal H),
|
iff.intro (assume H, eq.subst H rfl) (assume H, equal H),
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace sum
|
||||||
protected theorem is_inhabited_right [instance] {A B : Type} (H : inhabited B) : inhabited (A ⊎ B) :=
|
protected theorem is_inhabited_right [instance] {A B : Type} (H : inhabited B) : inhabited (A ⊎ B) :=
|
||||||
inhabited.mk (inr A (default B))
|
inhabited.mk (inr A (default B))
|
||||||
|
|
||||||
protected theorem has_eq_decidable [instance] {A B : Type} (H1 : decidable_eq A) (H2 : decidable_eq B) :
|
protected definition has_eq_decidable [instance] {A B : Type} (H1 : decidable_eq A) (H2 : decidable_eq B) :
|
||||||
decidable_eq (A ⊎ B) :=
|
decidable_eq (A ⊎ B) :=
|
||||||
take s1 s2 : A ⊎ B,
|
take s1 s2 : A ⊎ B,
|
||||||
rec_on s1
|
rec_on s1
|
||||||
|
|
|
@ -18,6 +18,6 @@ namespace unit
|
||||||
protected theorem is_inhabited [instance] : inhabited unit :=
|
protected theorem is_inhabited [instance] : inhabited unit :=
|
||||||
inhabited.mk ⋆
|
inhabited.mk ⋆
|
||||||
|
|
||||||
protected theorem has_decidable_eq [instance] : decidable_eq unit :=
|
protected definition has_decidable_eq [instance] : decidable_eq unit :=
|
||||||
take (a b : unit), inl (equal a b)
|
take (a b : unit), inl (equal a b)
|
||||||
end unit
|
end unit
|
||||||
|
|
|
@ -10,10 +10,10 @@ inr : ¬p → decidable p
|
||||||
|
|
||||||
namespace decidable
|
namespace decidable
|
||||||
|
|
||||||
theorem true_decidable [instance] : decidable true :=
|
definition true_decidable [instance] : decidable true :=
|
||||||
inl trivial
|
inl trivial
|
||||||
|
|
||||||
theorem false_decidable [instance] : decidable false :=
|
definition false_decidable [instance] : decidable false :=
|
||||||
inr not_false_trivial
|
inr not_false_trivial
|
||||||
|
|
||||||
protected theorem induction_on {p : Prop} {C : Prop} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C :=
|
protected theorem induction_on {p : Prop} {C : Prop} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C :=
|
||||||
|
@ -38,7 +38,7 @@ decidable.rec
|
||||||
theorem em (p : Prop) {H : decidable p} : p ∨ ¬p :=
|
theorem em (p : Prop) {H : decidable p} : p ∨ ¬p :=
|
||||||
induction_on H (λ Hp, or.inl Hp) (λ Hnp, or.inr Hnp)
|
induction_on H (λ Hp, or.inl Hp) (λ Hnp, or.inr Hnp)
|
||||||
|
|
||||||
theorem by_cases {a : Prop} {b : Type} {C : decidable a} (Hab : a → b) (Hnab : ¬a → b) : b :=
|
definition by_cases {a : Prop} {b : Type} {C : decidable a} (Hab : a → b) (Hnab : ¬a → b) : b :=
|
||||||
rec_on C (assume Ha, Hab Ha) (assume Hna, Hnab Hna)
|
rec_on C (assume Ha, Hab Ha) (assume Hna, Hnab Hna)
|
||||||
|
|
||||||
theorem by_contradiction {p : Prop} {Hp : decidable p} (H : ¬p → false) : p :=
|
theorem by_contradiction {p : Prop} {Hp : decidable p} (H : ¬p → false) : p :=
|
||||||
|
@ -46,7 +46,7 @@ or.elim (em p)
|
||||||
(assume H1 : p, H1)
|
(assume H1 : p, H1)
|
||||||
(assume H1 : ¬p, false_elim (H H1))
|
(assume H1 : ¬p, false_elim (H H1))
|
||||||
|
|
||||||
theorem and_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
definition and_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
||||||
decidable (a ∧ b) :=
|
decidable (a ∧ b) :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha : a, rec_on Hb
|
(assume Ha : a, rec_on Hb
|
||||||
|
@ -54,7 +54,7 @@ rec_on Ha
|
||||||
(assume Hnb : ¬b, inr (and.not_right a Hnb)))
|
(assume Hnb : ¬b, inr (and.not_right a Hnb)))
|
||||||
(assume Hna : ¬a, inr (and.not_left b Hna))
|
(assume Hna : ¬a, inr (and.not_left b Hna))
|
||||||
|
|
||||||
theorem or_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
definition or_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
||||||
decidable (a ∨ b) :=
|
decidable (a ∨ b) :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha : a, inl (or.inl Ha))
|
(assume Ha : a, inl (or.inl Ha))
|
||||||
|
@ -62,12 +62,12 @@ rec_on Ha
|
||||||
(assume Hb : b, inl (or.inr Hb))
|
(assume Hb : b, inl (or.inr Hb))
|
||||||
(assume Hnb : ¬b, inr (or.not_intro Hna Hnb)))
|
(assume Hnb : ¬b, inr (or.not_intro Hna Hnb)))
|
||||||
|
|
||||||
theorem not_decidable [instance] {a : Prop} (Ha : decidable a) : decidable (¬a) :=
|
definition not_decidable [instance] {a : Prop} (Ha : decidable a) : decidable (¬a) :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha, inr (not_not_intro Ha))
|
(assume Ha, inr (not_not_intro Ha))
|
||||||
(assume Hna, inl Hna)
|
(assume Hna, inl Hna)
|
||||||
|
|
||||||
theorem iff_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
definition iff_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
||||||
decidable (a ↔ b) :=
|
decidable (a ↔ b) :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha, rec_on Hb
|
(assume Ha, rec_on Hb
|
||||||
|
@ -78,7 +78,7 @@ rec_on Ha
|
||||||
(assume Hnb : ¬b, inl
|
(assume Hnb : ¬b, inl
|
||||||
(iff.intro (assume Ha, absurd Ha Hna) (assume Hb, absurd Hb Hnb))))
|
(iff.intro (assume Ha, absurd Ha Hna) (assume Hb, absurd Hb Hnb))))
|
||||||
|
|
||||||
theorem implies_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
definition implies_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
||||||
decidable (a → b) :=
|
decidable (a → b) :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha : a, rec_on Hb
|
(assume Ha : a, rec_on Hb
|
||||||
|
@ -86,12 +86,12 @@ rec_on Ha
|
||||||
(assume Hnb : ¬b, inr (assume H : a → b, absurd (H Ha) Hnb)))
|
(assume Hnb : ¬b, inr (assume H : a → b, absurd (H Ha) Hnb)))
|
||||||
(assume Hna : ¬a, inl (assume Ha, absurd Ha Hna))
|
(assume Hna : ¬a, inl (assume Ha, absurd Ha Hna))
|
||||||
|
|
||||||
theorem decidable_iff_equiv {a b : Prop} (Ha : decidable a) (H : a ↔ b) : decidable b :=
|
definition decidable_iff_equiv {a b : Prop} (Ha : decidable a) (H : a ↔ b) : decidable b :=
|
||||||
rec_on Ha
|
rec_on Ha
|
||||||
(assume Ha : a, inl (iff.elim_left H Ha))
|
(assume Ha : a, inl (iff.elim_left H Ha))
|
||||||
(assume Hna : ¬a, inr (iff.elim_left (iff.flip_sign H) Hna))
|
(assume Hna : ¬a, inr (iff.elim_left (iff.flip_sign H) Hna))
|
||||||
|
|
||||||
theorem decidable_eq_equiv {a b : Prop} (Ha : decidable a) (H : a = b) : decidable b :=
|
definition decidable_eq_equiv {a b : Prop} (Ha : decidable a) (H : a = b) : decidable b :=
|
||||||
decidable_iff_equiv Ha (eq_to_iff H)
|
decidable_iff_equiv Ha (eq_to_iff H)
|
||||||
|
|
||||||
end decidable
|
end decidable
|
||||||
|
|
Loading…
Reference in a new issue