diff --git a/library/data/bool/decl.lean b/library/data/bool/decl.lean new file mode 100644 index 000000000..6eac93fb4 --- /dev/null +++ b/library/data/bool/decl.lean @@ -0,0 +1,8 @@ +-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. +-- Released under Apache 2.0 license as described in the file LICENSE. +-- Author: Leonardo de Moura +import data.unit.decl + +inductive bool : Type := + ff : bool, + tt : bool diff --git a/library/data/bool/default.lean b/library/data/bool/default.lean new file mode 100644 index 000000000..8d4c46ff6 --- /dev/null +++ b/library/data/bool/default.lean @@ -0,0 +1,4 @@ +-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. +-- Released under Apache 2.0 license as described in the file LICENSE. +-- Author: Leonardo de Moura +import data.bool.decl data.bool.ops data.bool.thms diff --git a/library/data/bool/ops.lean b/library/data/bool/ops.lean new file mode 100644 index 000000000..2318ec5f9 --- /dev/null +++ b/library/data/bool/ops.lean @@ -0,0 +1,22 @@ +-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. +-- Released under Apache 2.0 license as described in the file LICENSE. +-- Author: Leonardo de Moura +import general_notation data.bool.decl + +namespace bool + definition cond {A : Type} (b : bool) (t e : A) := + rec_on b e t + + definition bor (a b : bool) := + rec_on a (rec_on b ff tt) tt + + notation a || b := bor a b + + definition band (a b : bool) := + rec_on a ff (rec_on b ff tt) + + notation a && b := band a b + + definition bnot (a : bool) := + rec_on a tt ff +end bool diff --git a/library/data/bool.lean b/library/data/bool/thms.lean similarity index 89% rename from library/data/bool.lean rename to library/data/bool/thms.lean index e509b59f3..5539056e1 100644 --- a/library/data/bool.lean +++ b/library/data/bool/thms.lean @@ -1,17 +1,13 @@ -- Copyright (c) 2014 Microsoft Corporation. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Leonardo de Moura -import general_notation +import data.bool.ops import logic.connectives logic.decidable logic.inhabited open eq eq.ops decidable -inductive bool : Type := - ff : bool, - tt : bool namespace bool - definition cond {A : Type} (b : bool) (t e : A) := - rec_on b e t + reducible bor band rec_on theorem dichotomy (b : bool) : b = ff ∨ b = tt := cases_on b (or.inl rfl) (or.inr rfl) @@ -26,12 +22,9 @@ namespace bool assume H : ff = tt, absurd (calc true = cond tt true false : !cond.tt⁻¹ ... = cond ff true false : {H⁻¹} - ... = false : !cond.ff) + ... = false : cond.ff) true_ne_false - definition bor (a b : bool) := - rec_on a (rec_on b ff tt) tt - theorem bor.tt_left (a : bool) : bor tt a = tt := rfl @@ -69,11 +62,6 @@ namespace bool or.inr Hb) (assume H, or.inl rfl) - definition band (a b : bool) := - rec_on a ff (rec_on b ff tt) - - notation a && b := band a b - theorem band.ff_left (a : bool) : ff && a = ff := rfl @@ -115,9 +103,6 @@ namespace bool theorem band.eq_tt_elim_right {a b : bool} (H : a && b = tt) : b = tt := band.eq_tt_elim_left (!band.comm ⬝ H) - definition bnot (a : bool) := - rec_on a tt ff - theorem bnot.bnot (a : bool) : bnot (bnot a) = a := cases_on a rfl rfl @@ -135,4 +120,5 @@ namespace bool rec_on a (rec_on b (inl rfl) (inr ff_ne_tt)) (rec_on b (inr (ne.symm ff_ne_tt)) (inl rfl)) + end bool