module Realisability.Data.Bool {ℓ} (𝔸 : PCA ℓ) where
open S 𝔸
private variable
: Level
ℓ' : Type ℓ'
V A B C : ↯ ⌞ 𝔸 ⌟ a b
Booleans in a PCA🔗
We construct booleans in a partial combinatory algebra by defining boolean values to be functions which select one of their two arguments. In effect, we are defining booleans so that the program is simply Therefore, we have:
: ↯⁺ 𝔸
`true = val ⟨ x ⟩ ⟨ y ⟩ x
`true
: ↯⁺ 𝔸
`false = val ⟨ x ⟩ ⟨ y ⟩ y `false
We define an overloaded notation for constructing terms which case on a boolean.
_then_else_
`if: ⦃ _ : To-term V A ⦄ ⦃ _ : To-term V B ⦄ ⦃ _ : To-term V C ⦄
→ A → B → C → Termʰ V
= x `· y `· z `if x then y else z
We can prove the following properties: applying `true
and `false
to a single argument results in a
defined value; `true
selects its
first argument; and `false
selects
its second argument.
abstract
: ⌞ a ⌟ → ⌞ `true ⋆ a ⌟
`true↓₁ = subst ⌞_⌟ (sym (abs-βₙ [] ((_ , x) ∷ []))) (abs↓ _ _)
`true↓₁ x
: ⌞ a ⌟ → ⌞ `false ⋆ a ⌟
`false↓₁ = subst ⌞_⌟ (sym (abs-βₙ [] ((_ , ah) ∷ []))) (abs↓ _ _)
`false↓₁ ah
: ⌞ a ⌟ → ⌞ b ⌟ → `true ⋆ a ⋆ b ≡ a
`true-β {a} {b} ah bh = abs-βₙ [] ((b , bh) ∷ (a , ah) ∷ [])
`true-β
: ⌞ a ⌟ → ⌞ b ⌟ → `false ⋆ a ⋆ b ≡ b
`false-β {a} {b} ah bh = abs-βₙ [] ((b , bh) ∷ (a , ah) ∷ []) `false-β
We can define negation using `if_then_else_
,
and show that it computes as expected.
: ↯⁺ 𝔸
`not = val ⟨ x ⟩ `if x then `false else `true
`not
abstract
: `not ⋆ `true ≡ `false .fst
`not-βt = abs-β _ [] `true ∙ abs-βₙ [] (`true ∷ `false ∷ [])
`not-βt
: `not ⋆ `false ≡ `true .fst
`not-βf = abs-β _ [] `false ∙ abs-βₙ [] (`true ∷ `false ∷ []) `not-βf