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