2014-12-22 15:33:29 -05: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-11-30 20:34:12 -08:00
|
|
|
|
import logic.eq
|
2014-10-01 17:51:17 -07:00
|
|
|
|
open eq eq.ops decidable
|
2014-08-19 19:32:44 -07:00
|
|
|
|
|
2014-07-22 09:49:54 -07:00
|
|
|
|
namespace bool
|
2015-01-26 11:31:12 -08:00
|
|
|
|
local attribute bor [reducible]
|
|
|
|
|
local attribute band [reducible]
|
2014-07-04 22:22:26 -07:00
|
|
|
|
|
2014-09-04 22:31:52 -07:00
|
|
|
|
theorem dichotomy (b : bool) : b = ff ∨ b = tt :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on b (or.inl rfl) (or.inr rfl)
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem cond_ff {A : Type} (t e : A) : cond ff t e = e :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-04 22:22:26 -07:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem cond_tt {A : Type} (t e : A) : cond tt t e = t :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-04 17:56:50 -08:00
|
|
|
|
theorem eq_tt_of_ne_ff : ∀ {a : bool}, a ≠ ff → a = tt
|
|
|
|
|
| @eq_tt_of_ne_ff tt H := rfl
|
|
|
|
|
| @eq_tt_of_ne_ff ff H := absurd rfl H
|
|
|
|
|
|
|
|
|
|
theorem eq_ff_of_ne_tt : ∀ {a : bool}, a ≠ tt → a = ff
|
|
|
|
|
| @eq_ff_of_ne_tt tt H := absurd rfl H
|
|
|
|
|
| @eq_ff_of_ne_tt ff H := rfl
|
|
|
|
|
|
|
|
|
|
theorem absurd_of_eq_ff_of_eq_tt {B : Prop} {a : bool} (H₁ : a = ff) (H₂ : a = tt) : B :=
|
|
|
|
|
absurd (H₁⁻¹ ⬝ H₂) ff_ne_tt
|
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem tt_bor (a : bool) : bor tt a = tt :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2014-10-21 14:08:07 -07:00
|
|
|
|
notation a || b := bor a b
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bor_tt (a : bool) : a || tt = tt :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem ff_bor (a : bool) : ff || a = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bor_ff (a : bool) : a || ff = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bor_self (a : bool) : a || a = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2014-10-05 09:50:55 -07:00
|
|
|
|
theorem bor.comm (a b : bool) : a || b = b || a :=
|
2015-05-03 21:40:33 -07:00
|
|
|
|
by cases a; repeat (cases b | reflexivity)
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2014-10-05 09:50:55 -07:00
|
|
|
|
theorem bor.assoc (a b c : bool) : (a || b) || c = a || (b || c) :=
|
2015-03-06 19:20:48 -08:00
|
|
|
|
match a with
|
|
|
|
|
| ff := by rewrite *ff_bor
|
|
|
|
|
| tt := by rewrite *tt_bor
|
|
|
|
|
end
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem or_of_bor_eq {a b : bool} : a || b = tt → a = tt ∨ b = tt :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.rec_on a
|
2015-07-21 09:10:56 -07:00
|
|
|
|
(suppose ff || b = tt,
|
|
|
|
|
have b = tt, from !ff_bor ▸ this,
|
|
|
|
|
or.inr this)
|
|
|
|
|
(suppose tt || b = tt,
|
|
|
|
|
or.inl rfl)
|
2014-07-27 12:50:57 -07:00
|
|
|
|
|
2015-03-30 04:55:28 -07:00
|
|
|
|
theorem bor_inl {a b : bool} (H : a = tt) : a || b = tt :=
|
|
|
|
|
by rewrite H
|
|
|
|
|
|
|
|
|
|
theorem bor_inr {a b : bool} (H : b = tt) : a || b = tt :=
|
|
|
|
|
bool.rec_on a (by rewrite H) (by rewrite H)
|
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem ff_band (a : bool) : ff && a = ff :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem tt_band (a : bool) : tt && a = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem band_ff (a : bool) : a && ff = ff :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem band_tt (a : bool) : a && tt = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem band_self (a : bool) : a && a = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2014-10-05 09:50:55 -07:00
|
|
|
|
theorem band.comm (a b : bool) : a && b = b && a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2014-10-05 09:50:55 -07:00
|
|
|
|
theorem band.assoc (a b c : bool) : (a && b) && c = a && (b && c) :=
|
2015-03-06 19:20:48 -08:00
|
|
|
|
match a with
|
|
|
|
|
| ff := by rewrite *ff_band
|
|
|
|
|
| tt := by rewrite *tt_band
|
|
|
|
|
end
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem band_elim_left {a b : bool} (H : a && b = tt) : a = tt :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
or.elim (dichotomy a)
|
2015-07-21 09:10:56 -07:00
|
|
|
|
(suppose a = ff,
|
2014-09-04 22:31:52 -07:00
|
|
|
|
absurd
|
2015-03-06 19:20:48 -08:00
|
|
|
|
(calc ff = ff && b : ff_band
|
2015-07-21 09:10:56 -07:00
|
|
|
|
... = a && b : this
|
2014-09-04 22:31:52 -07:00
|
|
|
|
... = tt : H)
|
|
|
|
|
ff_ne_tt)
|
2015-07-21 09:10:56 -07:00
|
|
|
|
(suppose a = tt, this)
|
2014-07-27 12:50:57 -07:00
|
|
|
|
|
2015-03-30 04:55:28 -07:00
|
|
|
|
theorem band_intro {a b : bool} (H₁ : a = tt) (H₂ : b = tt) : a && b = tt :=
|
|
|
|
|
by rewrite [H₁, H₂]
|
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem band_elim_right {a b : bool} (H : a && b = tt) : b = tt :=
|
|
|
|
|
band_elim_left (!band.comm ⬝ H)
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bnot_bnot (a : bool) : bnot (bnot a) = a :=
|
2015-02-11 12:49:27 -08:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bnot_false : bnot ff = tt :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-03-06 19:20:48 -08:00
|
|
|
|
theorem bnot_true : bnot tt = ff :=
|
2014-09-04 22:31:52 -07:00
|
|
|
|
rfl
|
2014-07-19 20:08:52 +01:00
|
|
|
|
|
2015-07-03 17:38:23 -07:00
|
|
|
|
theorem eq_tt_of_bnot_eq_ff {a : bool} : bnot a = ff → a = tt :=
|
|
|
|
|
bool.cases_on a (by contradiction) (λ h, rfl)
|
|
|
|
|
|
|
|
|
|
theorem eq_ff_of_bnot_eq_tt {a : bool} : bnot a = tt → a = ff :=
|
|
|
|
|
bool.cases_on a (λ h, rfl) (by contradiction)
|
2015-02-11 12:49:27 -08:00
|
|
|
|
end bool
|