| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Products |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Product where |
| 10 |
|
| 11 |
open import Level using (Level; _⊔_) |
| 12 |
open import Relation.Nullary.Negation.Core using (¬_) |
| 13 |
|
| 14 |
private |
| 15 |
variable |
| 16 |
a b c ℓ p q r s : Level |
| 17 |
A B C : Set a |
| 18 |
|
| 19 |
------------------------------------------------------------------------ |
| 20 |
-- Definition of dependent products |
| 21 |
|
| 22 |
open import Data.Product.Base public |
| 23 |
|
| 24 |
-- These are here as they are not 'basic' but instead "very dependent", |
| 25 |
-- i.e. the result type depends on the full input 'point' (x , y). |
| 26 |
map-Σ : {B : A → Set b} {P : A → Set p} {Q : {x : A} → P x → B x → Set q} → |
| 27 |
(f : (x : A) → B x) → (∀ {x} → (y : P x) → Q y (f x)) → |
| 28 |
((x , y) : Σ A P) → Σ (B x) (Q y) |
| 29 |
map-Σ f g (x , y) = (f x , g y) |
| 30 |
|
| 31 |
-- This is a "non-dependent" version of map-Σ whereby the input is actually |
| 32 |
-- a pair (i.e. _×_ ) but the output type still depends on the input 'point' (x , y). |
| 33 |
map-Σ′ : {B : A → Set b} {P : Set p} {Q : P → Set q} → |
| 34 |
(f : (x : A) → B x) → ((x : P) → Q x) → ((x , y) : A × P) → B x × Q y |
| 35 |
map-Σ′ f g (x , y) = (f x , g y) |
| 36 |
|
| 37 |
-- This is a generic zipWith for Σ where different functions are applied to each |
| 38 |
-- component pair, and recombined. |
| 39 |
zipWith : {P : A → Set p} {Q : B → Set q} {R : C → Set r} {S : (x : C) → R x → Set s} |
| 40 |
(_∙_ : A → B → C) → (_∘_ : ∀ {x y} → P x → Q y → R (x ∙ y)) → |
| 41 |
(_*_ : (x : C) → (y : R x) → S x y) → |
| 42 |
((a , p) : Σ A P) → ((b , q) : Σ B Q) → S (a ∙ b) (p ∘ q) |
| 43 |
zipWith _∙_ _∘_ _*_ (a , p) (b , q) = (a ∙ b) * (p ∘ q) |
| 44 |
|
| 45 |
------------------------------------------------------------------------ |
| 46 |
-- Negation of existential quantifier |
| 47 |
|
| 48 |
∄ : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) |
| 49 |
∄ P = ¬ ∃ P |
| 50 |
|
| 51 |
-- Unique existence (parametrised by an underlying equality). |
| 52 |
|
| 53 |
∃! : {A : Set a} → (A → A → Set ℓ) → (A → Set b) → Set (a ⊔ b ⊔ ℓ) |
| 54 |
∃! _≈_ B = ∃ λ x → B x × (∀ {y} → B y → x ≈ y) |
| 55 |
|
| 56 |
-- Syntax |
| 57 |
|
| 58 |
infix 2 ∄-syntax |
| 59 |
|
| 60 |
∄-syntax : ∀ {A : Set a} → (A → Set b) → Set (a ⊔ b) |
| 61 |
∄-syntax = ∄ |
| 62 |
|
| 63 |
syntax ∄-syntax (λ x → B) = ∄[ x ] B |