| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Correctness proofs for container combinators |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Container.Combinator.Properties where |
| 10 |
|
| 11 |
open import Axiom.Extensionality.Propositional using (Extensionality) |
| 12 |
open import Data.Container.Core using (Container; ⟦_⟧) |
| 13 |
open import Data.Container.Combinator |
| 14 |
open import Data.Product.Base as P |
| 15 |
using (∃; _,_; proj₁; proj₂; <_,_>; uncurry; curry) |
| 16 |
open import Data.Sum.Base as S using (inj₁; inj₂; [_,_]′; [_,_]) |
| 17 |
open import Function.Base as F using (_∘′_) |
| 18 |
open import Function.Bundles using (_↔_; mk↔ₛ′) |
| 19 |
open import Level using (_⊔_; lower) |
| 20 |
open import Relation.Binary.PropositionalEquality.Core |
| 21 |
using (_≡_; _≗_; refl; cong) |
| 22 |
open import Relation.Nullary.Negation.Core using (contradiction) |
| 23 |
|
| 24 |
-- I have proved some of the correctness statements under the |
| 25 |
-- assumption of functional extensionality. I could have reformulated |
| 26 |
-- the statements using suitable setoids, but I could not be bothered. |
| 27 |
|
| 28 |
module Identity where |
| 29 |
|
| 30 |
correct : ∀ {s p x} {X : Set x} → ⟦ id {s} {p} ⟧ X ↔ F.id X |
| 31 |
correct {X = X} = mk↔ₛ′ from-id to-id (λ _ → refl) (λ _ → refl) |
| 32 |
|
| 33 |
module Constant (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′) where |
| 34 |
|
| 35 |
correct : ∀ {x p y} (X : Set x) {Y : Set y} → ⟦ const {x} {p ⊔ y} X ⟧ Y ↔ F.const X Y |
| 36 |
correct {x} {y} X {Y} = mk↔ₛ′ (from-const X) (to-const X) (λ _ → refl) from∘to |
| 37 |
where |
| 38 |
from∘to : (x : ⟦ const X ⟧ Y) → to-const X (proj₁ x) ≡ x |
| 39 |
from∘to xs = cong (proj₁ xs ,_) (ext (λ x → contradiction x lower )) |
| 40 |
|
| 41 |
module Composition {s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where |
| 42 |
|
| 43 |
correct : ∀ {x} {X : Set x} → ⟦ C₁ ∘ C₂ ⟧ X ↔ (⟦ C₁ ⟧ F.∘ ⟦ C₂ ⟧) X |
| 44 |
correct {X = X} = mk↔ₛ′ (from-∘ C₁ C₂) (to-∘ C₁ C₂) (λ _ → refl) (λ _ → refl) |
| 45 |
|
| 46 |
module Product (ext : ∀ {ℓ ℓ′} → Extensionality ℓ ℓ′) |
| 47 |
{s₁ s₂ p₁ p₂} (C₁ : Container s₁ p₁) (C₂ : Container s₂ p₂) where |
| 48 |
|
| 49 |
correct : ∀ {x} {X : Set x} → ⟦ C₁ × C₂ ⟧ X ↔ (⟦ C₁ ⟧ X P.× ⟦ C₂ ⟧ X) |
| 50 |
correct {X = X} = mk↔ₛ′ (from-× C₁ C₂) (to-× C₁ C₂) (λ _ → refl) from∘to |
| 51 |
where |
| 52 |
from∘to : (to-× C₁ C₂) F.∘ (from-× C₁ C₂) ≗ F.id |
| 53 |
from∘to (s , f) = |
| 54 |
cong (s ,_) (ext [ (λ _ → refl) , (λ _ → refl) ]) |
| 55 |
|
| 56 |
module IndexedProduct {i s p} {I : Set i} (Cᵢ : I → Container s p) where |
| 57 |
|
| 58 |
correct : ∀ {x} {X : Set x} → ⟦ Π I Cᵢ ⟧ X ↔ (∀ i → ⟦ Cᵢ i ⟧ X) |
| 59 |
correct {X = X} = mk↔ₛ′ (from-Π I Cᵢ) (to-Π I Cᵢ) (λ _ → refl) (λ _ → refl) |
| 60 |
|
| 61 |
module Sum {s₁ s₂ p} (C₁ : Container s₁ p) (C₂ : Container s₂ p) where |
| 62 |
|
| 63 |
correct : ∀ {x} {X : Set x} → ⟦ C₁ ⊎ C₂ ⟧ X ↔ (⟦ C₁ ⟧ X S.⊎ ⟦ C₂ ⟧ X) |
| 64 |
correct {X = X} = mk↔ₛ′ (from-⊎ C₁ C₂) (to-⊎ C₁ C₂) to∘from from∘to |
| 65 |
where |
| 66 |
from∘to : (to-⊎ C₁ C₂) F.∘ (from-⊎ C₁ C₂) ≗ F.id |
| 67 |
from∘to (inj₁ s₁ , f) = refl |
| 68 |
from∘to (inj₂ s₂ , f) = refl |
| 69 |
|
| 70 |
to∘from : (from-⊎ C₁ C₂) F.∘ (to-⊎ C₁ C₂) ≗ F.id |
| 71 |
to∘from = [ (λ _ → refl) , (λ _ → refl) ] |
| 72 |
|
| 73 |
module IndexedSum {i s p} {I : Set i} (C : I → Container s p) where |
| 74 |
|
| 75 |
correct : ∀ {x} {X : Set x} → ⟦ Σ I C ⟧ X ↔ (∃ λ i → ⟦ C i ⟧ X) |
| 76 |
correct {X = X} = mk↔ₛ′ (from-Σ I C) (to-Σ I C) (λ _ → refl) (λ _ → refl) |
| 77 |
|
| 78 |
module ConstantExponentiation {i s p} {I : Set i} (C : Container s p) where |
| 79 |
|
| 80 |
correct : ∀ {x} {X : Set x} → ⟦ const[ I ]⟶ C ⟧ X ↔ (I → ⟦ C ⟧ X) |
| 81 |
correct = IndexedProduct.correct (F.const C) |