2014-12-22 20:33:29 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
2014-12-23 20:35:06 +00:00
|
|
|
|
Module: data.bool
|
2014-12-22 20:33:29 +00:00
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
|
-/
|
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
|
import logic.eq
|
2014-10-02 00:51:17 +00:00
|
|
|
|
open eq eq.ops decidable
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-07-22 16:49:54 +00:00
|
|
|
|
namespace bool
|
2015-01-26 19:31:12 +00:00
|
|
|
|
local attribute bor [reducible]
|
|
|
|
|
local attribute band [reducible]
|
2014-07-05 05:22:26 +00:00
|
|
|
|
|
2014-09-05 05:31:52 +00:00
|
|
|
|
theorem dichotomy (b : bool) : b = ff ∨ b = tt :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on b (or.inl rfl) (or.inr rfl)
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem cond_ff {A : Type} (t e : A) : cond ff t e = e :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-05 05:22:26 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem cond_tt {A : Type} (t e : A) : cond tt t e = t :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-09-05 05:31:52 +00:00
|
|
|
|
theorem ff_ne_tt : ¬ ff = tt :=
|
|
|
|
|
assume H : ff = tt, absurd
|
2015-03-07 03:20:48 +00:00
|
|
|
|
(calc true = cond tt true false : cond_tt
|
|
|
|
|
... = cond ff true false : H
|
|
|
|
|
... = false : cond_ff)
|
2014-09-05 05:31:52 +00:00
|
|
|
|
true_ne_false
|
2014-07-05 07:43:10 +00:00
|
|
|
|
|
2015-03-05 01:56:50 +00: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-07 03:20:48 +00:00
|
|
|
|
theorem tt_bor (a : bool) : bor tt a = tt :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a || b := bor a b
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bor_tt (a : bool) : a || tt = tt :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem ff_bor (a : bool) : ff || a = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bor_ff (a : bool) : a || ff = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bor_self (a : bool) : a || a = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-10-05 16:50:55 +00:00
|
|
|
|
theorem bor.comm (a b : bool) : a || b = b || a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-10-05 16:50:55 +00:00
|
|
|
|
theorem bor.assoc (a b c : bool) : (a || b) || c = a || (b || c) :=
|
2015-03-07 03:20:48 +00:00
|
|
|
|
match a with
|
|
|
|
|
| ff := by rewrite *ff_bor
|
|
|
|
|
| tt := by rewrite *tt_bor
|
|
|
|
|
end
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem or_of_bor_eq {a b : bool} : a || b = tt → a = tt ∨ b = tt :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.rec_on a
|
2014-09-05 05:31:52 +00:00
|
|
|
|
(assume H : ff || b = tt,
|
2015-03-07 03:20:48 +00:00
|
|
|
|
have Hb : b = tt, from !ff_bor ▸ H,
|
2014-09-05 05:31:52 +00:00
|
|
|
|
or.inr Hb)
|
|
|
|
|
(assume H, or.inl rfl)
|
2014-07-27 19:50:57 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem ff_band (a : bool) : ff && a = ff :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem tt_band (a : bool) : tt && a = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem band_ff (a : bool) : a && ff = ff :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem band_tt (a : bool) : a && tt = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem band_self (a : bool) : a && a = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-10-05 16:50:55 +00:00
|
|
|
|
theorem band.comm (a b : bool) : a && b = b && a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
|
|
|
|
(bool.cases_on b rfl rfl)
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2014-10-05 16:50:55 +00:00
|
|
|
|
theorem band.assoc (a b c : bool) : (a && b) && c = a && (b && c) :=
|
2015-03-07 03:20:48 +00:00
|
|
|
|
match a with
|
|
|
|
|
| ff := by rewrite *ff_band
|
|
|
|
|
| tt := by rewrite *tt_band
|
|
|
|
|
end
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem band_elim_left {a b : bool} (H : a && b = tt) : a = tt :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
or.elim (dichotomy a)
|
|
|
|
|
(assume H0 : a = ff,
|
|
|
|
|
absurd
|
2015-03-07 03:20:48 +00:00
|
|
|
|
(calc ff = ff && b : ff_band
|
|
|
|
|
... = a && b : H0
|
2014-09-05 05:31:52 +00:00
|
|
|
|
... = tt : H)
|
|
|
|
|
ff_ne_tt)
|
|
|
|
|
(assume H1 : a = tt, H1)
|
2014-07-27 19:50:57 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem band_elim_right {a b : bool} (H : a && b = tt) : b = tt :=
|
|
|
|
|
band_elim_left (!band.comm ⬝ H)
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bnot_bnot (a : bool) : bnot (bnot a) = a :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
bool.cases_on a rfl rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bnot_false : bnot ff = tt :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-03-07 03:20:48 +00:00
|
|
|
|
theorem bnot_true : bnot tt = ff :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
rfl
|
2014-07-19 19:08:52 +00:00
|
|
|
|
|
2015-02-11 20:49:27 +00:00
|
|
|
|
end bool
|
2014-08-01 00:48:51 +00:00
|
|
|
|
|
2015-02-11 20:49:27 +00:00
|
|
|
|
open bool
|
2014-11-07 16:41:14 +00:00
|
|
|
|
|
2015-02-25 20:34:49 +00:00
|
|
|
|
protected definition bool.is_inhabited [instance] : inhabited bool :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
inhabited.mk ff
|
|
|
|
|
|
2015-02-25 20:34:49 +00:00
|
|
|
|
protected definition bool.has_decidable_eq [instance] : decidable_eq bool :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
take a b : bool,
|
|
|
|
|
bool.rec_on a
|
|
|
|
|
(bool.rec_on b (inl rfl) (inr ff_ne_tt))
|
|
|
|
|
(bool.rec_on b (inr (ne.symm ff_ne_tt)) (inl rfl))
|