module Realisability.Data.Pair {β„“} (𝔸 : PCA β„“) where

Pairs in a PCAπŸ”—

We define an encoding for pairs in a partial combinatory algebra in terms of the encoding of booleans in a PCA. The pairing of and is the function and the pairing function is this abstracted over and

`pair : ↯⁺ 𝔸
`pair = val ⟨ a ⟩ ⟨ b ⟩ ⟨ i ⟩ `if i then a else b

The projection functions simply apply a pair to either `true or `false depending.

`fst : ↯⁺ 𝔸
`fst = val ⟨ p ⟩ p `· `true

`snd : ↯⁺ 𝔸
`snd = val ⟨ p ⟩ p `· `false

Our standard battery of lemmas follows: `pair is defined when applied to two arguments, and the first and second projections compute as expected.

abstract
  `pair↓₂ : ⌞ a ⌟ β†’ ⌞ b ⌟ β†’ ⌞ `pair ⋆ a ⋆ b ⌟
  `pair↓₂ {a} {b} ah bh = subst ⌞_⌟ (sym (abs-Ξ²β‚™ [] ((b , bh) ∷ (a , ah) ∷ []))) (abs↓ _ _)

  `fst-Ξ² : ⌞ a ⌟ β†’ ⌞ b ⌟ β†’ `fst ⋆ (`pair ⋆ a ⋆ b) ≑ a
  `fst-Ξ² {a} {b} ah bh =
    `fst ⋆ (`pair ⋆ a ⋆ b)  β‰‘βŸ¨ abs-Ξ² _ [] (_ , `pair↓₂ ah bh) βŸ©β‰‘
    `pair ⋆ a ⋆ b ⋆ `true   β‰‘βŸ¨ abs-Ξ²β‚™ [] (`true ∷ (b , bh) ∷ (a , ah) ∷ []) βŸ©β‰‘
    `true ⋆ a ⋆ b           β‰‘βŸ¨ `true-Ξ² ah bh βŸ©β‰‘
    a                       ∎

  `snd-Ξ² : ⌞ a ⌟ β†’ ⌞ b ⌟ β†’ `snd ⋆ (`pair ⋆ a ⋆ b) ≑ b
  `snd-Ξ² {a} {b} ah bh =
    `snd ⋆ (`pair ⋆ a ⋆ b)  β‰‘βŸ¨ abs-Ξ² _ [] (_ , `pair↓₂ ah bh) βŸ©β‰‘
    `pair ⋆ a ⋆ b ⋆ `false  β‰‘βŸ¨ abs-Ξ²β‚™ [] (`false ∷ (b , bh) ∷ (a , ah) ∷ []) βŸ©β‰‘
    `false ⋆ a ⋆ b          β‰‘βŸ¨ `false-Ξ² ah bh βŸ©β‰‘
    b                       ∎