| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The type for booleans and some operations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Bool.Base where |
| 10 |
|
| 11 |
open import Data.Unit.Base using (⊤) |
| 12 |
open import Data.Empty using (⊥) |
| 13 |
open import Level using (Level) |
| 14 |
|
| 15 |
private |
| 16 |
variable |
| 17 |
a : Level |
| 18 |
A : Set a |
| 19 |
|
| 20 |
------------------------------------------------------------------------ |
| 21 |
-- The boolean type |
| 22 |
|
| 23 |
open import Agda.Builtin.Bool public |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
-- Relations |
| 27 |
|
| 28 |
infix 4 _≤_ _<_ |
| 29 |
|
| 30 |
data _≤_ : Bool → Bool → Set where |
| 31 |
f≤t : false ≤ true |
| 32 |
b≤b : ∀ {b} → b ≤ b |
| 33 |
|
| 34 |
data _<_ : Bool → Bool → Set where |
| 35 |
f<t : false < true |
| 36 |
|
| 37 |
------------------------------------------------------------------------ |
| 38 |
-- Boolean operations |
| 39 |
|
| 40 |
infixr 6 _∧_ |
| 41 |
infixr 5 _∨_ _xor_ |
| 42 |
|
| 43 |
not : Bool → Bool |
| 44 |
not true = false |
| 45 |
not false = true |
| 46 |
|
| 47 |
_∧_ : Bool → Bool → Bool |
| 48 |
true ∧ b = b |
| 49 |
false ∧ b = false |
| 50 |
|
| 51 |
_∨_ : Bool → Bool → Bool |
| 52 |
true ∨ b = true |
| 53 |
false ∨ b = b |
| 54 |
|
| 55 |
_xor_ : Bool → Bool → Bool |
| 56 |
true xor b = not b |
| 57 |
false xor b = b |
| 58 |
|
| 59 |
------------------------------------------------------------------------ |
| 60 |
-- Conversion to Set |
| 61 |
|
| 62 |
-- A function mapping true to an inhabited type and false to an empty |
| 63 |
-- type. |
| 64 |
T : Bool → Set |
| 65 |
T true = ⊤ |
| 66 |
T false = ⊥ |
| 67 |
|
| 68 |
------------------------------------------------------------------------ |
| 69 |
-- Other operations |
| 70 |
|
| 71 |
infix 0 if_then_else_ |
| 72 |
|
| 73 |
if_then_else_ : Bool → A → A → A |
| 74 |
if true then t else f = t |
| 75 |
if false then t else f = f |