2023-12-06 21:47:23 -05:00
|
|
|
|
load "misc.quox"
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
namespace bool {
|
|
|
|
|
|
2023-12-06 21:47:23 -05:00
|
|
|
|
def0 Bool : ★ = {true, false}
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def if-dep : 0.(P : Bool → ★) → (b : Bool) → ω.(P 'true) → ω.(P 'false) → P b =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ P b t f ⇒ case b return b' ⇒ P b' of { 'true ⇒ t; 'false ⇒ f }
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def if : 0.(A : ★) → (b : Bool) → ω.A → ω.A → A =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ A ⇒ if-dep (λ _ ⇒ A)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def0 if-same : (A : ★) → (b : Bool) → (x : A) → if A b x x ≡ x : A =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ A b x ⇒ if-dep (λ b' ⇒ if A b' x x ≡ x : A) b (δ _ ⇒ x) (δ _ ⇒ x)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def if2 : 0.(A B : ★) → (b : Bool) → ω.A → ω.B → if¹ ★ b A B =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ A B ⇒ if-dep (λ b ⇒ if-dep¹ (λ _ ⇒ ★) b A B)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
2023-12-06 21:47:23 -05:00
|
|
|
|
def0 T : Bool → ★ = λ b ⇒ if¹ ★ b True False
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def dup! : (b : Bool) → [ω. Sing Bool b] =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ b ⇒
|
|
|
|
|
case b return b' ⇒ [ω. Sing Bool b'] of {
|
|
|
|
|
'true ⇒ [('true, [δ _ ⇒ 'true])];
|
|
|
|
|
'false ⇒ [('false, [δ _ ⇒ 'false])]
|
|
|
|
|
}
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def dup : Bool → [ω. Bool] =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ b ⇒ appω (Sing Bool b) Bool (λ b' ⇒ sing.val Bool b b') (dup! b)
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
def true-not-false : Not ('true ≡ 'false : Bool) =
|
2023-12-06 21:47:23 -05:00
|
|
|
|
λ eq ⇒ coe (𝑖 ⇒ T (eq @𝑖)) 'true
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- [todo] infix
|
2023-12-06 21:47:23 -05:00
|
|
|
|
def and : Bool → ω.Bool → Bool = λ a b ⇒ if Bool a b 'false
|
|
|
|
|
def or : Bool → ω.Bool → Bool = λ a b ⇒ if Bool a 'true b
|
|
|
|
|
def not : Bool → Bool = λ b ⇒ if Bool b 'false 'true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def0 not-not : (b : Bool) → not (not b) ≡ b : Bool =
|
|
|
|
|
λ b ⇒
|
|
|
|
|
case b return b' ⇒ not (not b') ≡ b' : Bool
|
|
|
|
|
of { 'true ⇒ δ _ ⇒ 'true; 'false ⇒ δ _ ⇒ 'false }
|
2023-12-01 12:52:23 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-06 21:47:23 -05:00
|
|
|
|
def0 Bool = bool.Bool
|