| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Sum combinators for propositional equality preserving functions |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Sum.Function.Propositional where |
| 10 |
|
| 11 |
open import Data.Sum.Base using (_⊎_) |
| 12 |
open import Data.Sum.Function.Setoid |
| 13 |
using (_⊎-function_; _⊎-equivalence_; _⊎-injection_; _⊎-surjection_ |
| 14 |
; _⊎-leftInverse_; _⊎-rightInverse_; _⊎-bijection_; _⊎-inverse_) |
| 15 |
open import Data.Sum.Relation.Binary.Pointwise using (Pointwise-≡↔≡; _⊎ₛ_) |
| 16 |
open import Function.Construct.Composition as Compose |
| 17 |
open import Function.Related.Propositional |
| 18 |
using (_∼[_]_; implication; reverseImplication; equivalence; injection; |
| 19 |
reverseInjection; leftInverse; surjection; bijection) |
| 20 |
open import Function.Base using (id) |
| 21 |
open import Function.Bundles |
| 22 |
using (Inverse; _⟶_; _⇔_; _↣_; _↠_; _↩_; _↪_; _⤖_; _↔_) |
| 23 |
open import Function.Properties.Inverse as Inv |
| 24 |
using (Inverse⇒Equivalence; Inverse⇒Bijection; Inverse⇒Injection |
| 25 |
; Inverse⇒Surjection) |
| 26 |
open import Level using (Level; _⊔_) |
| 27 |
open import Relation.Binary.Core using (REL) |
| 28 |
open import Relation.Binary.Bundles using (Setoid) |
| 29 |
open import Relation.Binary.PropositionalEquality.Properties using (setoid) |
| 30 |
|
| 31 |
private |
| 32 |
variable |
| 33 |
a b c d : Level |
| 34 |
A B C D : Set a |
| 35 |
|
| 36 |
|
| 37 |
------------------------------------------------------------------------ |
| 38 |
-- Helper lemma |
| 39 |
|
| 40 |
private |
| 41 |
liftViaInverse : {R : ∀ {a b ℓ₁ ℓ₂} → REL (Setoid a ℓ₁) (Setoid b ℓ₂) (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂)} → |
| 42 |
(∀ {a b c ℓ₁ ℓ₂ ℓ₃} {S : Setoid a ℓ₁} {T : Setoid b ℓ₂} {U : Setoid c ℓ₃} → R S T → R T U → R S U) → |
| 43 |
(∀ {a b ℓ₁ ℓ₂} {S : Setoid a ℓ₁} {T : Setoid b ℓ₂} → Inverse S T → R S T) → |
| 44 |
(R (setoid A) (setoid C) → R (setoid B) (setoid D) → R (setoid A ⊎ₛ setoid B) (setoid C ⊎ₛ setoid D)) → |
| 45 |
R (setoid A) (setoid C) → R (setoid B) (setoid D) → |
| 46 |
R (setoid (A ⊎ B)) (setoid (C ⊎ D)) |
| 47 |
liftViaInverse trans inv⇒R lift RAC RBD = |
| 48 |
Inv.transportVia trans inv⇒R (Inv.sym (Pointwise-≡↔≡ _ _)) (lift RAC RBD) (Pointwise-≡↔≡ _ _) |
| 49 |
|
| 50 |
------------------------------------------------------------------------ |
| 51 |
-- Combinators for various function types |
| 52 |
|
| 53 |
infixr 1 _⊎-⟶_ _⊎-⇔_ _⊎-↣_ _⊎-↩_ _⊎-↪_ _⊎-↔_ |
| 54 |
|
| 55 |
_⊎-⟶_ : A ⟶ B → C ⟶ D → (A ⊎ C) ⟶ (B ⊎ D) |
| 56 |
_⊎-⟶_ = liftViaInverse Compose.function Inv.toFunction _⊎-function_ |
| 57 |
|
| 58 |
|
| 59 |
_⊎-⇔_ : A ⇔ B → C ⇔ D → (A ⊎ C) ⇔ (B ⊎ D) |
| 60 |
_⊎-⇔_ = liftViaInverse Compose.equivalence Inverse⇒Equivalence _⊎-equivalence_ |
| 61 |
|
| 62 |
_⊎-↣_ : A ↣ B → C ↣ D → (A ⊎ C) ↣ (B ⊎ D) |
| 63 |
_⊎-↣_ = liftViaInverse Compose.injection Inverse⇒Injection _⊎-injection_ |
| 64 |
|
| 65 |
_⊎-↠_ : A ↠ B → C ↠ D → (A ⊎ C) ↠ (B ⊎ D) |
| 66 |
_⊎-↠_ = liftViaInverse Compose.surjection Inverse⇒Surjection _⊎-surjection_ |
| 67 |
|
| 68 |
_⊎-↩_ : A ↩ B → C ↩ D → (A ⊎ C) ↩ (B ⊎ D) |
| 69 |
_⊎-↩_ = liftViaInverse Compose.leftInverse Inverse.leftInverse _⊎-leftInverse_ |
| 70 |
|
| 71 |
_⊎-↪_ : A ↪ B → C ↪ D → (A ⊎ C) ↪ (B ⊎ D) |
| 72 |
_⊎-↪_ = liftViaInverse Compose.rightInverse Inverse.rightInverse _⊎-rightInverse_ |
| 73 |
|
| 74 |
_⊎-⤖_ : A ⤖ B → C ⤖ D → (A ⊎ C) ⤖ (B ⊎ D) |
| 75 |
_⊎-⤖_ = liftViaInverse Compose.bijection Inverse⇒Bijection _⊎-bijection_ |
| 76 |
|
| 77 |
_⊎-↔_ : A ↔ B → C ↔ D → (A ⊎ C) ↔ (B ⊎ D) |
| 78 |
_⊎-↔_ = liftViaInverse Compose.inverse id _⊎-inverse_ |
| 79 |
|
| 80 |
infixr 1 _⊎-cong_ |
| 81 |
|
| 82 |
_⊎-cong_ : ∀ {k} → A ∼[ k ] B → C ∼[ k ] D → (A ⊎ C) ∼[ k ] (B ⊎ D) |
| 83 |
_⊎-cong_ {k = implication} = _⊎-⟶_ |
| 84 |
_⊎-cong_ {k = reverseImplication} = _⊎-⟶_ |
| 85 |
_⊎-cong_ {k = equivalence} = _⊎-⇔_ |
| 86 |
_⊎-cong_ {k = injection} = _⊎-↣_ |
| 87 |
_⊎-cong_ {k = reverseInjection} = _⊎-↣_ |
| 88 |
_⊎-cong_ {k = leftInverse} = _⊎-↪_ |
| 89 |
_⊎-cong_ {k = surjection} = _⊎-↠_ |
| 90 |
_⊎-cong_ {k = bijection} = _⊎-↔_ |