| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Non-dependent product combinators for setoid equality preserving |
| 5 |
-- functions |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
module Data.Product.Function.NonDependent.Setoid where |
| 11 |
|
| 12 |
open import Data.Product.Base as Product |
| 13 |
open import Data.Product.Relation.Binary.Pointwise.NonDependent using (_×ₛ_) |
| 14 |
open import Level using (Level) |
| 15 |
open import Relation.Binary.Bundles using (Setoid) |
| 16 |
open import Function.Bundles |
| 17 |
using (Func; Equivalence; Injection; Surjection; Bijection; LeftInverse; |
| 18 |
RightInverse; Inverse) |
| 19 |
|
| 20 |
private |
| 21 |
variable |
| 22 |
a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂ : Level |
| 23 |
a ℓ : Level |
| 24 |
A B C D : Setoid a ℓ |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Combinators for equality preserving functions |
| 28 |
|
| 29 |
proj₁ₛ : Func (A ×ₛ B) A |
| 30 |
proj₁ₛ = record { to = proj₁ ; cong = proj₁ } |
| 31 |
|
| 32 |
proj₂ₛ : Func (A ×ₛ B) B |
| 33 |
proj₂ₛ = record { to = proj₂ ; cong = proj₂ } |
| 34 |
|
| 35 |
<_,_>ₛ : Func A B → Func A C → Func A (B ×ₛ C) |
| 36 |
< f , g >ₛ = record |
| 37 |
{ to = < to f , to g > |
| 38 |
; cong = < cong f , cong g > |
| 39 |
} where open Func |
| 40 |
|
| 41 |
swapₛ : Func (A ×ₛ B) (B ×ₛ A) |
| 42 |
swapₛ = < proj₂ₛ , proj₁ₛ >ₛ |
| 43 |
|
| 44 |
------------------------------------------------------------------------ |
| 45 |
-- Function bundles |
| 46 |
|
| 47 |
_×-function_ : Func A B → Func C D → Func (A ×ₛ C) (B ×ₛ D) |
| 48 |
f ×-function g = record |
| 49 |
{ to = Product.map (to f) (to g) |
| 50 |
; cong = Product.map (cong f) (cong g) |
| 51 |
} where open Func |
| 52 |
|
| 53 |
infixr 2 _×-equivalence_ _×-injection_ _×-left-inverse_ |
| 54 |
|
| 55 |
_×-equivalence_ : Equivalence A B → Equivalence C D → |
| 56 |
Equivalence (A ×ₛ C) (B ×ₛ D) |
| 57 |
_×-equivalence_ f g = record |
| 58 |
{ to = Product.map (to f) (to g) |
| 59 |
; from = Product.map (from f) (from g) |
| 60 |
; to-cong = Product.map (to-cong f) (to-cong g) |
| 61 |
; from-cong = Product.map (from-cong f) (from-cong g) |
| 62 |
} where open Equivalence |
| 63 |
|
| 64 |
_×-injection_ : Injection A B → Injection C D → |
| 65 |
Injection (A ×ₛ C) (B ×ₛ D) |
| 66 |
f ×-injection g = record |
| 67 |
{ to = Product.map (to f) (to g) |
| 68 |
; cong = Product.map (cong f) (cong g) |
| 69 |
; injective = Product.map (injective f) (injective g) |
| 70 |
} where open Injection |
| 71 |
|
| 72 |
_×-surjection_ : Surjection A B → Surjection C D → |
| 73 |
Surjection (A ×ₛ C) (B ×ₛ D) |
| 74 |
f ×-surjection g = record |
| 75 |
{ to = Product.map (to f) (to g) |
| 76 |
; cong = Product.map (cong f) (cong g) |
| 77 |
; surjective = λ y → Product.zip _,_ (λ ff gg x₂ → (ff (proj₁ x₂)) , (gg (proj₂ x₂))) (surjective f (proj₁ y)) (surjective g (proj₂ y)) |
| 78 |
} where open Surjection |
| 79 |
|
| 80 |
_×-bijection_ : Bijection A B → Bijection C D → |
| 81 |
Bijection (A ×ₛ C) (B ×ₛ D) |
| 82 |
f ×-bijection g = record |
| 83 |
{ to = Product.map (to f) (to g) |
| 84 |
; cong = Product.map (cong f) (cong g) |
| 85 |
; bijective = Product.map (injective f) (injective g) , |
| 86 |
λ { (y₀ , y₁) → Product.zip _,_ (λ {ff gg (x₀ , x₁) → ff x₀ , gg x₁}) (surjective f y₀) (surjective g y₁)} |
| 87 |
} where open Bijection |
| 88 |
|
| 89 |
_×-leftInverse_ : LeftInverse A B → LeftInverse C D → |
| 90 |
LeftInverse (A ×ₛ C) (B ×ₛ D) |
| 91 |
f ×-leftInverse g = record |
| 92 |
{ to = Product.map (to f) (to g) |
| 93 |
; from = Product.map (from f) (from g) |
| 94 |
; to-cong = Product.map (to-cong f) (to-cong g) |
| 95 |
; from-cong = Product.map (from-cong f) (from-cong g) |
| 96 |
; inverseˡ = λ x → inverseˡ f (proj₁ x) , inverseˡ g (proj₂ x) |
| 97 |
} where open LeftInverse |
| 98 |
|
| 99 |
_×-rightInverse_ : RightInverse A B → RightInverse C D → |
| 100 |
RightInverse (A ×ₛ C) (B ×ₛ D) |
| 101 |
f ×-rightInverse g = record |
| 102 |
{ to = Product.map (to f) (to g) |
| 103 |
; from = Product.map (from f) (from g) |
| 104 |
; to-cong = Product.map (to-cong f) (to-cong g) |
| 105 |
; from-cong = Product.map (from-cong f) (from-cong g) |
| 106 |
; inverseʳ = λ x → inverseʳ f (proj₁ x) , inverseʳ g (proj₂ x) |
| 107 |
} where open RightInverse |
| 108 |
|
| 109 |
infixr 2 _×-surjection_ _×-inverse_ |
| 110 |
|
| 111 |
_×-inverse_ : Inverse A B → Inverse C D → |
| 112 |
Inverse (A ×ₛ C) (B ×ₛ D) |
| 113 |
f ×-inverse g = record |
| 114 |
{ to = Product.map (to f) (to g) |
| 115 |
; from = Product.map (from f) (from g) |
| 116 |
; to-cong = Product.map (to-cong f) (to-cong g) |
| 117 |
; from-cong = Product.map (from-cong f) (from-cong g) |
| 118 |
; inverse = (λ x → inverseˡ f (proj₁ x) , inverseˡ g (proj₂ x)) , |
| 119 |
(λ x → inverseʳ f (proj₁ x) , inverseʳ g (proj₂ x)) |
| 120 |
} where open Inverse |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
------------------------------------------------------------------------ |
| 125 |
-- DEPRECATED NAMES |
| 126 |
------------------------------------------------------------------------ |
| 127 |
-- Please use the new names as continuing support for the old names is |
| 128 |
-- not guaranteed. |
| 129 |
|
| 130 |
-- Version 2.0 |
| 131 |
|
| 132 |
_×-left-inverse_ = _×-leftInverse_ |
| 133 |
{-# WARNING_ON_USAGE _×-left-inverse_ |
| 134 |
"Warning: _×-left-inverse_ was deprecated in v2.0. |
| 135 |
Please use _×-leftInverse_ instead." |
| 136 |
#-} |