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
|
|
|
|
|
2014-08-28 01:39:55 +00:00
|
|
|
|
import logic.core.connectives
|
2014-07-19 19:09:47 +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-09-04 22:03:59 +00:00
|
|
|
|
namespace decidable
|
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition true_decidable [instance] : decidable true :=
|
2014-08-04 05:58:12 +00:00
|
|
|
|
inl trivial
|
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition false_decidable [instance] : decidable false :=
|
2014-08-04 05:58:12 +00:00
|
|
|
|
inr not_false_trivial
|
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected theorem induction_on {p : Prop} {C : Prop} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
decidable.rec H1 H2 H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected definition rec_on {p : Prop} {C : Type} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) :
|
2014-08-22 00:54:50 +00:00
|
|
|
|
C :=
|
2014-09-04 22:03:59 +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 :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
decidable.rec
|
|
|
|
|
(assume Hp1 : p, decidable.rec
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(assume Hp2 : p, congr_arg inl (eq.refl Hp1)) -- using proof irrelevance for Prop
|
2014-08-28 01:34:09 +00:00
|
|
|
|
(assume Hnp2 : ¬p, absurd Hp1 Hnp2)
|
2014-07-29 02:58:57 +00:00
|
|
|
|
d2)
|
2014-09-04 22:03:59 +00:00
|
|
|
|
(assume Hnp1 : ¬p, decidable.rec
|
2014-08-28 01:34:09 +00:00
|
|
|
|
(assume Hp2 : p, absurd Hp2 Hnp1)
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(assume Hnp2 : ¬p, congr_arg inr (eq.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 :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
induction_on H (λ Hp, or.inl Hp) (λ Hnp, or.inr Hnp)
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition by_cases {a : Prop} {b : Type} {C : decidable a} (Hab : a → b) (Hnab : ¬a → b) : b :=
|
2014-09-08 07:16:20 +00:00
|
|
|
|
rec_on C (assume Ha, Hab Ha) (assume Hna, Hnab Hna)
|
2014-08-22 00:54:50 +00:00
|
|
|
|
|
2014-08-04 05:58:12 +00:00
|
|
|
|
theorem by_contradiction {p : Prop} {Hp : decidable p} (H : ¬p → false) : p :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
or.elim (em p)
|
2014-08-04 05:58:12 +00:00
|
|
|
|
(assume H1 : p, H1)
|
2014-09-02 02:44:04 +00:00
|
|
|
|
(assume H1 : ¬p, false_elim (H H1))
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition and_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
2014-08-22 00:54:50 +00:00
|
|
|
|
decidable (a ∧ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha : a, rec_on Hb
|
2014-09-04 23:36:06 +00:00
|
|
|
|
(assume Hb : b, inl (and.intro Ha Hb))
|
2014-09-05 00:44:53 +00:00
|
|
|
|
(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-09-30 16:02:37 +00:00
|
|
|
|
definition or_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
2014-08-22 00:54:50 +00:00
|
|
|
|
decidable (a ∨ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(assume Ha : a, inl (or.inl Ha))
|
2014-07-29 02:58:57 +00:00
|
|
|
|
(assume Hna : ¬a, rec_on Hb
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(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-09-30 16:02:37 +00:00
|
|
|
|
definition 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-09-30 16:02:37 +00:00
|
|
|
|
definition iff_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
2014-08-22 00:54:50 +00:00
|
|
|
|
decidable (a ↔ b) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
rec_on Ha
|
|
|
|
|
(assume Ha, rec_on Hb
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(assume Hb : b, inl (iff.intro (assume H, Hb) (assume H, Ha)))
|
|
|
|
|
(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-09-05 04:25:21 +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-09-05 04:25:21 +00:00
|
|
|
|
(iff.intro (assume Ha, absurd Ha Hna) (assume Hb, absurd Hb Hnb))))
|
2014-07-20 00:09:37 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition implies_decidable [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) :
|
2014-08-22 00:54:50 +00:00
|
|
|
|
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-28 01:34:09 +00:00
|
|
|
|
(assume Hna : ¬a, inl (assume Ha, absurd Ha Hna))
|
2014-08-03 00:00:01 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition decidable_iff_equiv {a b : Prop} (Ha : decidable a) (H : a ↔ b) : decidable b :=
|
2014-08-04 04:41:01 +00:00
|
|
|
|
rec_on Ha
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(assume Ha : a, inl (iff.elim_left H Ha))
|
|
|
|
|
(assume Hna : ¬a, inr (iff.elim_left (iff.flip_sign H) Hna))
|
2014-08-04 04:41:01 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
definition decidable_eq_equiv {a b : Prop} (Ha : decidable a) (H : a = b) : decidable b :=
|
2014-08-04 04:41:01 +00:00
|
|
|
|
decidable_iff_equiv Ha (eq_to_iff H)
|
|
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end decidable
|
2014-09-08 05:22:04 +00:00
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
|
definition decidable_eq (A : Type) := Π (a b : A), decidable (a = b)
|