2014-07-19 19:09:47 +00:00
|
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
-- Author: Leonardo de Moura
|
2014-08-01 00:48:51 +00:00
|
|
|
|
|
|
|
|
|
import logic.connectives.basic logic.connectives.eq
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
|
|
|
|
namespace decidable
|
2014-08-01 00:48:51 +00:00
|
|
|
|
|
2014-07-22 16:43:18 +00:00
|
|
|
|
inductive decidable (p : Prop) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
|
inl : p → decidable p,
|
|
|
|
|
inr : ¬p → decidable p
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem true_decidable [instance] : decidable true :=
|
2014-08-04 05:58:12 +00:00
|
|
|
|
inl trivial
|
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem false_decidable [instance] : decidable false :=
|
2014-08-04 05:58:12 +00:00
|
|
|
|
inr not_false_trivial
|
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem induction_on {p : Prop} {C : Prop} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C :=
|
|
|
|
|
decidable_rec H1 H2 H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
definition rec_on [inline] {p : Prop} {C : Type} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) :
|
|
|
|
|
C :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
decidable_rec H1 H2 H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem irrelevant {p : Prop} (d1 d2 : decidable p) : d1 = d2 :=
|
|
|
|
|
decidable_rec
|
|
|
|
|
(assume Hp1 : p, decidable_rec
|
2014-08-20 02:32:44 +00:00
|
|
|
|
(assume Hp2 : p, congr_arg inl (refl Hp1)) -- using proof irrelevance for Prop
|
2014-08-27 01:27:39 +00:00
|
|
|
|
(assume Hnp2 : ¬p, absurd_elim Hp1 Hnp2)
|
2014-07-29 02:58:57 +00:00
|
|
|
|
d2)
|
|
|
|
|
(assume Hnp1 : ¬p, decidable_rec
|
2014-08-27 01:27:39 +00:00
|
|
|
|
(assume Hp2 : p, absurd_elim Hp2 Hnp1)
|
2014-08-20 02:32:44 +00:00
|
|
|
|
(assume Hnp2 : ¬p, congr_arg inr (refl Hnp1)) -- using proof irrelevance for Prop
|
2014-07-29 02:58:57 +00:00
|
|
|
|
d2)
|
|
|
|
|
d1
|
2014-07-22 10:54:28 +00:00
|
|
|
|
|
2014-08-04 05:58:12 +00:00
|
|
|
|
theorem em (p : Prop) {H : decidable p} : p ∨ ¬p :=
|
|
|
|
|
induction_on H (λ Hp, or_inl Hp) (λ Hnp, or_inr Hnp)
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem by_cases {a b : Prop} {C : decidable a} (Hab : a → b) (Hnab : ¬a → b) : b :=
|
|
|
|
|
or_elim (em a) (assume Ha, Hab Ha) (assume Hna, Hnab Hna)
|
|
|
|
|
|
2014-08-04 05:58:12 +00:00
|
|
|
|
theorem by_contradiction {p : Prop} {Hp : decidable p} (H : ¬p → false) : p :=
|
|
|
|
|
or_elim (em p)
|
|
|
|
|
(assume H1 : p, H1)
|
|
|
|
|
(assume H1 : ¬p, false_elim p (H H1))
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem and_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
|
|
|
|
decidable (a ∧ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha : a, rec_on Hb
|
|
|
|
|
(assume Hb : b, inl (and_intro Ha Hb))
|
|
|
|
|
(assume Hnb : ¬b, inr (and_not_right a Hnb)))
|
|
|
|
|
(assume Hna : ¬a, inr (and_not_left b Hna))
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem or_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
|
|
|
|
decidable (a ∨ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha : a, inl (or_inl Ha))
|
|
|
|
|
(assume Hna : ¬a, rec_on Hb
|
|
|
|
|
(assume Hb : b, inl (or_inr Hb))
|
|
|
|
|
(assume Hnb : ¬b, inr (or_not_intro Hna Hnb)))
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem not_decidable [instance] {a : Prop} (Ha : decidable a) : decidable (¬a) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha, inr (not_not_intro Ha))
|
|
|
|
|
(assume Hna, inl Hna)
|
2014-07-20 00:09:37 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem iff_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
|
|
|
|
decidable (a ↔ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha, rec_on Hb
|
|
|
|
|
(assume Hb : b, inl (iff_intro (assume H, Hb) (assume H, Ha)))
|
2014-07-31 21:05:33 +00:00
|
|
|
|
(assume Hnb : ¬b, inr (assume H : a ↔ b, absurd (iff_elim_left H Ha) Hnb)))
|
2014-07-29 02:58:57 +00:00
|
|
|
|
(assume Hna, rec_on Hb
|
2014-07-31 21:05:33 +00:00
|
|
|
|
(assume Hb : b, inr (assume H : a ↔ b, absurd (iff_elim_right H Hb) Hna))
|
2014-08-22 00:54:50 +00:00
|
|
|
|
(assume Hnb : ¬b, inl
|
2014-08-27 01:27:39 +00:00
|
|
|
|
(iff_intro (assume Ha, absurd_elim Ha Hna) (assume Hb, absurd_elim Hb Hnb))))
|
2014-07-20 00:09:37 +00:00
|
|
|
|
|
2014-08-22 00:54:50 +00:00
|
|
|
|
theorem implies_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
|
|
|
|
decidable (a → b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha : a, rec_on Hb
|
|
|
|
|
(assume Hb : b, inl (assume H, Hb))
|
|
|
|
|
(assume Hnb : ¬b, inr (assume H : a → b, absurd (H Ha) Hnb)))
|
2014-08-27 01:27:39 +00:00
|
|
|
|
(assume Hna : ¬a, inl (assume Ha, absurd_elim Ha Hna))
|
2014-08-03 00:00:01 +00:00
|
|
|
|
|
2014-08-04 04:41:01 +00:00
|
|
|
|
theorem decidable_iff_equiv {a b : Prop} (Ha : decidable a) (H : a ↔ b) : decidable b :=
|
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha : a, inl (iff_elim_left H Ha))
|
|
|
|
|
(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 :=
|
|
|
|
|
decidable_iff_equiv Ha (eq_to_iff H)
|
|
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end decidable
|