Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ refactor ] Function.Definitions, adding Function.Definitions.Strict module #2567

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Algebra/Morphism/Construct/Terminal.agda
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open import Algebra.Bundles.Raw
open import Algebra.Morphism.Structures

open import Data.Product.Base using (_,_)
open import Function.Definitions using (StrictlySurjective)
open import Function.Definitions.Strict using (StrictlySurjective)
import Relation.Binary.Morphism.Definitions as Rel
open import Relation.Binary.Morphism.Structures

Expand Down
2 changes: 1 addition & 1 deletion src/Data/Fin/Permutation.agda
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open import Function.Bundles using (_↔_; Injection; Inverse; mk↔ₛ′)
open import Function.Construct.Composition using (_↔-∘_)
open import Function.Construct.Identity using (↔-id)
open import Function.Construct.Symmetry using (↔-sym)
open import Function.Definitions using (StrictlyInverseˡ; StrictlyInverseʳ)
open import Function.Definitions.Strict using (StrictlyInverseˡ; StrictlyInverseʳ)
open import Function.Properties.Inverse using (↔⇒↣)
open import Function.Base using (_∘_)
open import Level using (0ℓ)
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Product/Function/Dependent/Propositional.agda
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ open import Function.Properties.Inverse.HalfAdjointEquivalence
using (↔⇒≃; _≃_; ≃⇒↔)
open import Function.Consequences.Propositional
using (inverseʳ⇒injective; strictlySurjective⇒surjective)
open import Function.Definitions using (Inverseˡ; Inverseʳ; Injective; StrictlySurjective)
open import Function.Definitions using (Inverseˡ; Inverseʳ; Injective)
open import Function.Definitions.Strict using (StrictlySurjective)
open import Function.Bundles
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
open import Relation.Binary.PropositionalEquality.Properties as ≡
Expand Down
1 change: 1 addition & 0 deletions src/Data/Sum/Function/Setoid.agda
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open import Relation.Binary
open import Function.Base
open import Function.Bundles
open import Function.Definitions
open import Function.Definitions.Strict
open import Level

private
Expand Down
1 change: 1 addition & 0 deletions src/Function.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open import Function.Core public
open import Function.Base public
open import Function.Strict public
open import Function.Definitions public
open import Function.Definitions.Strict public
open import Function.Structures public
open import Function.Structures.Biased public
open import Function.Bundles public
1 change: 1 addition & 0 deletions src/Function/Bundles.agda
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Function.Bundles where

open import Function.Base using (_∘_)
open import Function.Definitions
open import Function.Definitions.Strict
import Function.Structures as FunctionStructures
open import Level using (Level; _⊔_; suc)
open import Data.Product.Base using (_,_; proj₁; proj₂)
Expand Down
8 changes: 5 additions & 3 deletions src/Function/Consequences.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Function.Consequences where

open import Data.Product.Base as Product
open import Function.Definitions
open import Function.Definitions.Strict
open import Level using (Level)
open import Relation.Binary.Core using (Rel)
open import Relation.Binary.Bundles using (Setoid)
Expand Down Expand Up @@ -104,11 +105,12 @@ inverseʳ⇒strictlyInverseʳ : ∀ (≈₁ : Rel A ℓ₁) (≈₂ : Rel B ℓ
Reflexive ≈₂ →
Inverseʳ ≈₁ ≈₂ f f⁻¹ →
StrictlyInverseʳ ≈₁ f f⁻¹
inverseʳ⇒strictlyInverseʳ _ _ refl sinv x = sinv refl
inverseʳ⇒strictlyInverseʳ {f = f} {f⁻¹ = f⁻¹} ≈₁ ≈₂ =
inverseˡ⇒strictlyInverseˡ {f = f⁻¹} {f⁻¹ = f} ≈₂ ≈₁

strictlyInverseʳ⇒inverseʳ : Transitive ≈₁ →
Congruent ≈₂ ≈₁ f⁻¹ →
StrictlyInverseʳ ≈₁ f f⁻¹ →
Inverseʳ ≈₁ ≈₂ f f⁻¹
strictlyInverseʳ⇒inverseʳ trans cong sinv {x} y≈f⁻¹x =
trans (cong y≈f⁻¹x) (sinv x)
strictlyInverseʳ⇒inverseʳ {≈₁ = ≈₁} {≈₂ = ≈₂} {f⁻¹ = f⁻¹} {f = f} =
strictlyInverseˡ⇒inverseˡ {≈₂ = ≈₁} {≈₁ = ≈₂} {f = f⁻¹} {f⁻¹ = f}
11 changes: 7 additions & 4 deletions src/Function/Consequences/Propositional.agda
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module Function.Consequences.Propositional
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; cong)
open import Relation.Binary.PropositionalEquality.Properties
using (setoid)
open import Function.Definitions
import Function.Definitions as Definitions
open import Function.Definitions.Strict as Strict
open import Relation.Nullary.Negation.Core using (contraposition)

import Function.Consequences.Setoid (setoid A) (setoid B) as Setoid
Expand All @@ -37,17 +38,19 @@ private
f : A → B
f⁻¹ : B → A

open Definitions (_≡_ {A = A}) (_≡_ {A = B})

strictlySurjective⇒surjective : StrictlySurjective _≡_ f →
Surjective _≡_ _≡_ f
Surjective f
strictlySurjective⇒surjective =
Setoid.strictlySurjective⇒surjective (cong _)

strictlyInverseˡ⇒inverseˡ : ∀ f → StrictlyInverseˡ _≡_ f f⁻¹ →
Inverseˡ _≡_ _≡_ f f⁻¹
Inverseˡ f f⁻¹
strictlyInverseˡ⇒inverseˡ f =
Setoid.strictlyInverseˡ⇒inverseˡ (cong _)

strictlyInverseʳ⇒inverseʳ : ∀ f → StrictlyInverseʳ _≡_ f f⁻¹ →
Inverseʳ _≡_ _≡_ f f⁻¹
Inverseʳ f f⁻¹
strictlyInverseʳ⇒inverseʳ f =
Setoid.strictlyInverseʳ⇒inverseʳ (cong _)
1 change: 1 addition & 0 deletions src/Function/Consequences/Setoid.agda
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Function.Consequences.Setoid
where

open import Function.Definitions
open import Function.Definitions.Strict
open import Relation.Nullary.Negation.Core

import Function.Consequences as C
Expand Down
65 changes: 22 additions & 43 deletions src/Function/Definitions.agda
Original file line number Diff line number Diff line change
@@ -1,64 +1,43 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions for types of functions.
-- Definitions for types of functions,
-- wrt to `_≈₁_` equality over the domain
-- and `_≈₂_` equality over the codomain.
------------------------------------------------------------------------

-- The contents of this file should usually be accessed from `Function`.

{-# OPTIONS --cubical-compatible --safe #-}

module Function.Definitions where

open import Data.Product.Base using (∃; _×_)
open import Level using (Level)
open import Relation.Binary.Core using (Rel)

private
variable
a ℓ₁ ℓ₂ : Level
A B : Set a

------------------------------------------------------------------------
-- Basic definitions

module _
(_≈₁_ : Rel A ℓ₁) -- Equality over the domain
(_≈₂_ : Rel B ℓ₂) -- Equality over the codomain
module Function.Definitions
{a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} (_≈₁_ : Rel A ℓ₁) (_≈₂_ : Rel B ℓ₂)
where

Congruent : (A → B) → Set _
Congruent f = ∀ {x y} → x ≈₁ y → f x ≈₂ f y

Injective : (A → B) → Set _
Injective f = ∀ {x y} → f x ≈₂ f y → x ≈₁ y

Surjective : (A → B) → Set _
Surjective f = ∀ y → ∃ λ x → ∀ {z} → z ≈₁ x → f z ≈₂ y

Bijective : (A → B) → Set _
Bijective f = Injective f × Surjective f
open import Data.Product.Base using (∃; _×_)

Inverseˡ : (A → B) → (B → A) → Set _
Inverseˡ f g = ∀ {x y} → y ≈₁ g x → f y ≈₂ x
------------------------------------------------------------------------
-- Basic definitions

Inverseʳ : (A → B) → (B → A) → Set _
Inverseʳ f g = ∀ {x y} → y ≈₂ f x → g y ≈₁ x
Congruent : (A → B) → Set _
Congruent f = ∀ {x y} → x ≈₁ y → f x ≈₂ f y

Inverseᵇ : (A → B) → (B → A) → Set _
Inverseᵇ f g = Inverseˡ f g × Inverseʳ f g
Injective : (A → B) → Set _
Injective f = ∀ {x y} → f x ≈₂ f y → x ≈₁ y

------------------------------------------------------------------------
-- Strict definitions
Surjective : (A → B) → Set _
Surjective f = ∀ y → ∃ λ x → ∀ {z} → z ≈₁ x → f z ≈₂ y

-- These are often easier to use once but much harder to compose and
-- reason about.
Bijective : (A → B) → Set _
Bijective f = Injective f × Surjective f

StrictlySurjective : Rel B ℓ₂ → (AB) → Set _
StrictlySurjective _≈₂_ f = ∀ y∃ λ x → f x ≈₂ y
Inverseˡ : (A → B) → (BA) → Set _
Inverseˡ f g = ∀ {x y}y ≈₁ g x → f y ≈₂ x

StrictlyInverseˡ : Rel B ℓ₂ → (A → B) → (B → A) → Set _
StrictlyInverseˡ _≈₂_ f g = ∀ yf (g y) ≈₂ y
Inverseʳ : (A → B) → (B → A) → Set _
Inverseʳ f g = ∀ {x y}y ≈₂ f x → g y ≈₁ x

StrictlyInverseʳ : Rel A ℓ₁ → (A → B) → (B → A) → Set _
StrictlyInverseʳ _≈₁_ f g = ∀ x → g (f x) ≈₁ x
Inverseᵇ : (A → B) → (B → A) → Set _
Inverseᵇ f g = Inverseˡ f g × Inverseʳ f g
37 changes: 37 additions & 0 deletions src/Function/Definitions/Strict.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Definitions for types of functions.
------------------------------------------------------------------------

-- The contents of this file should usually be accessed from `Function`.

{-# OPTIONS --cubical-compatible --safe #-}

open import Relation.Binary.Core using (Rel)

module Function.Definitions.Strict {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where

open import Data.Product.Base using (∃)
open import Level using (Level)

private
variable
b : Level
B : Set b

------------------------------------------------------------------------
-- Strict definitions

-- These are often easier to use once but much harder to compose and
-- reason about.

StrictlySurjective : (B → A) → Set _
StrictlySurjective f = ∀ y → ∃ λ x → f x ≈ y

StrictlyInverseˡ : (B → A) → (A → B) → Set _
StrictlyInverseˡ f g = ∀ y → f (g y) ≈ y

StrictlyInverseʳ : (A → B) → (B → A) → Set _
StrictlyInverseʳ g f = StrictlyInverseˡ f g

1 change: 1 addition & 0 deletions src/Function/Structures.agda
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Function.Structures {a b ℓ₁ ℓ₂}
open import Data.Product.Base as Product using (∃; _×_; _,_)
open import Function.Base
open import Function.Definitions
open import Function.Definitions.Strict
open import Level using (_⊔_)

------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/Function/Structures/Biased.agda
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Function.Structures.Biased {a b ℓ₁ ℓ₂}
open import Data.Product.Base as Product using (∃; _×_; _,_)
open import Function.Base
open import Function.Definitions
open import Function.Definitions.Strict
open import Function.Structures _≈₁_ _≈₂_
open import Function.Consequences.Setoid
open import Level using (_⊔_)
Expand Down