Skip to content

Commit

Permalink
feat(data/fintype/order): bool is a boolean algebra (#11694)
Browse files Browse the repository at this point in the history
Provide the `boolean_algebra` instance for `bool` and use the machinery from `data.fintype.order` to deduce `complete_boolean_algebra bool` and `complete_linear_order bool`.
  • Loading branch information
YaelDillies committed Jan 29, 2022
1 parent fc4e471 commit 49b8b91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/data/bool/basic.lean
Expand Up @@ -138,6 +138,11 @@ theorem eq_tt_of_bnot_eq_ff : ∀ {a : bool}, bnot a = ff → a = tt := dec_triv

theorem eq_ff_of_bnot_eq_tt : ∀ {a : bool}, bnot a = tt → a = ff := dec_trivial

@[simp] lemma band_bnot_self : ∀ x, x && !x = ff := dec_trivial
@[simp] lemma bnot_band_self : ∀ x, !x && x = ff := dec_trivial
@[simp] lemma bor_bnot_self : ∀ x, x || !x = tt := dec_trivial
@[simp] lemma bnot_bor_self : ∀ x, !x || x = tt := dec_trivial

theorem bxor_comm : ∀ a b, bxor a b = bxor b a := dec_trivial
@[simp] theorem bxor_assoc : ∀ a b c, bxor (bxor a b) c = bxor a (bxor b c) := dec_trivial
theorem bxor_left_comm : ∀ a b c, bxor a (bxor b c) = bxor b (bxor a c) := dec_trivial
Expand Down
2 changes: 2 additions & 0 deletions src/data/fintype/order.lean
Expand Up @@ -38,6 +38,7 @@ Those are marked as `def` to avoid typeclass loops.
We provide a few instances for concrete types:
* `fin.complete_linear_order`
* `bool.complete_linear_order`
* `bool.complete_boolean_algebra`
-/

open finset
Expand Down Expand Up @@ -141,3 +142,4 @@ noncomputable instance {n : ℕ} : complete_linear_order (fin (n + 1)) :=
fintype.to_complete_linear_order _

noncomputable instance : complete_linear_order bool := fintype.to_complete_linear_order _
noncomputable instance : complete_boolean_algebra bool := fintype.to_complete_boolean_algebra _
15 changes: 15 additions & 0 deletions src/order/boolean_algebra.lean
Expand Up @@ -808,3 +808,18 @@ instance pi.boolean_algebra {ι : Type u} {α : ι → Type v} [∀ i, boolean_a
.. pi.has_compl,
.. pi.bounded_order,
.. pi.distrib_lattice }

instance : boolean_algebra bool := boolean_algebra.of_core
{ sup := bor,
le_sup_left := bool.left_le_bor,
le_sup_right := bool.right_le_bor,
sup_le := λ _ _ _, bool.bor_le,
inf := band,
inf_le_left := bool.band_le_left,
inf_le_right := bool.band_le_right,
le_inf := λ _ _ _, bool.le_band,
le_sup_inf := dec_trivial,
compl := bnot,
inf_compl_le_bot := λ a, a.band_bnot_self.le,
top_le_sup_compl := λ a, a.bor_bnot_self.ge,
..bool.linear_order, ..bool.bounded_order }
3 changes: 3 additions & 0 deletions src/order/lattice.lean
Expand Up @@ -940,3 +940,6 @@ See note [reducible non-instances]. -/
..hf_inj.lattice f map_sup map_inf, }

end lift

--To avoid noncomputability poisoning from `bool.complete_boolean_algebra`
instance : distrib_lattice bool := linear_order.to_distrib_lattice

0 comments on commit 49b8b91

Please sign in to comment.