Skip to content

Add some type relations and isomorphisms #2419

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

Merged
merged 13 commits into from
Dec 6, 2024
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Bug-fixes
Non-backwards compatible changes
--------------------------------

In `Function.Related.TypeIsomorphisms`, the unprimed versions are more level polymorphic; and the primed versions retain `Level` homogeneous types for the `Semiring` axioms to hold.

Minor improvements
------------------

Expand Down Expand Up @@ -341,6 +343,11 @@ Additions to existing modules
m≤pred[n]⇒suc[m]≤n : .{{NonZero n}} → m ≤ pred n → suc m ≤ n
```

* In `Data.Product.Function.Dependent.Propositional`:
```agda
congˡ : ∀ {k} → (∀ {x} → A x ∼[ k ] B x) → Σ I A ∼[ k ] Σ I B
```

* New lemmas in `Data.Rational.Properties`:
```agda
nonNeg+nonNeg⇒nonNeg : ∀ p .{{_ : NonNegative p}} q .{{_ : NonNegative q}} → NonNegative (p + q)
Expand Down Expand Up @@ -377,6 +384,15 @@ Additions to existing modules
_≡?_ : DecidableEquality (Vec A n)
```

* In `Function.Related.TypeIsomorphisms`:
```agda
Σ-distribˡ-⊎ : (∃ λ a → P a ⊎ Q a) ↔ (∃ P ⊎ ∃ Q)
Σ-distribʳ-⊎ : (Σ (A ⊎ B) P) ↔ (Σ A (P ∘ inj₁) ⊎ Σ B (P ∘ inj₂))
×-distribˡ-⊎ : (A × (B ⊎ C)) ↔ (A × B ⊎ A × C)
×-distribʳ-⊎ : ((A ⊎ B) × C) ↔ (A × C ⊎ B × C)
∃-≡ : ∀ (P : A → Set b) {x} → P x ↔ (∃[ y ] y ≡ x × P y)
```

* In `Relation.Binary.Bundles`:
```agda
record DecPreorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂))
Expand Down
5 changes: 4 additions & 1 deletion src/Data/Product/Function/Dependent/Propositional.agda
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open import Function.Related.Propositional
implication; reverseImplication; equivalence; injection;
reverseInjection; leftInverse; surjection; bijection)
open import Function.Base using (_$_; _∘_; _∘′_)
open import Function.Properties.Inverse using (↔⇒↠; ↔⇒⟶; ↔⇒⟵; ↔-sym; ↔⇒↩)
open import Function.Properties.Inverse using (↔⇒↠; ↔⇒⟶; ↔⇒⟵; ↔-sym; ↔⇒↩; refl)
open import Function.Properties.RightInverse using (↩⇒↪; ↪⇒↩)
open import Function.Properties.Inverse.HalfAdjointEquivalence
using (↔⇒≃; _≃_; ≃⇒↔)
Expand Down Expand Up @@ -316,3 +316,6 @@ cong {B = B} {k = reverseInjection} I↔J A↢B = Σ-↣ (↔-sym I↔J) (swap
cong {B = B} {k = leftInverse} I↔J A↩B = ↩⇒↪ (Σ-↩ (↔⇒↩ (↔-sym I↔J)) (↪⇒↩ (swap-coercions {k = leftInverse} B I↔J A↩B)))
cong {k = surjection} I↔J A↠B = Σ-↠ (↔⇒↠ I↔J) A↠B
cong {k = bijection} I↔J A↔B = Σ-↔ I↔J A↔B

congˡ : ∀ {k} → (∀ {x} → A x ∼[ k ] B x) → Σ I A ∼[ k ] Σ I B
congˡ = cong (refl _)
52 changes: 40 additions & 12 deletions src/Function/Related/TypeIsomorphisms.agda
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open import Axiom.Extensionality.Propositional using (Extensionality)
open import Data.Bool.Base using (true; false)
open import Data.Empty.Polymorphic using (⊥; ⊥-elim)
open import Data.Product.Base as Product
using (_×_; Σ; curry; uncurry; _,_; -,_; <_,_>; proj₁; proj₂; ∃₂; ∃)
using (_×_; Σ; curry; uncurry; _,_; -,_; <_,_>; proj₁; proj₂; ∃₂; ∃; ∃-syntax)
open import Data.Product.Function.NonDependent.Propositional
open import Data.Sum.Base as Sum
open import Data.Sum.Properties using (swap-involutive)
Expand Down Expand Up @@ -106,26 +106,46 @@ private
⊎-identity ℓ = ⊎-identityˡ ℓ , ⊎-identityʳ ℓ

------------------------------------------------------------------------
-- Properties of × and ⊎
-- Properties of Σ and ⊎

-- × distributes over ⊎
-- Σ distributes over ⊎

×-distribˡ-⊎ : ∀ ℓ → _DistributesOverˡ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribˡ-⊎ ℓ _ _ _ = mk↔ₛ′
Σ-distribˡ-⊎ : {P : A → Set a} {Q : A → Set b} →
(∃ λ a → P a ⊎ Q a) ↔ (∃ P ⊎ ∃ Q)
Σ-distribˡ-⊎ = mk↔ₛ′
(uncurry λ x → [ inj₁ ∘′ (x ,_) , inj₂ ∘′ (x ,_) ]′)
[ Product.map₂ inj₁ , Product.map₂ inj₂ ]′
[ (λ _ → refl) , (λ _ → refl) ]
(uncurry λ _ → [ (λ _ → refl) , (λ _ → refl) ])

×-distribʳ-⊎ : ∀ ℓ → _DistributesOverʳ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribʳ-⊎ ℓ _ _ _ = mk↔ₛ′
(uncurry [ curry inj₁ , curry inj₂ ]′)
[ Product.map₁ inj₁ , Product.map₁ inj₂ ]′
Σ-distribʳ-⊎ : {P : A ⊎ B → Set c} →
(Σ (A ⊎ B) P) ↔ (Σ A (P ∘ inj₁) ⊎ Σ B (P ∘ inj₂))
Σ-distribʳ-⊎ = mk↔ₛ′
(uncurry [ curry inj₁ , curry inj₂ ])
[ Product.dmap inj₁ id , Product.dmap inj₂ id ]
[ (λ _ → refl) , (λ _ → refl) ]
(uncurry [ (λ _ _ → refl) , (λ _ _ → refl) ])

×-distrib-⊎ : ∀ ℓ → _DistributesOver_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distrib-⊎ ℓ = ×-distribˡ-⊎ ℓ , ×-distribʳ-⊎ ℓ
------------------------------------------------------------------------
-- Properties of × and ⊎

-- × distributes over ⊎
-- primed variants are less level polymorphic

×-distribˡ-⊎ : (A × (B ⊎ C)) ↔ (A × B ⊎ A × C)
×-distribˡ-⊎ = Σ-distribˡ-⊎

×-distribˡ-⊎′ : ∀ ℓ → _DistributesOverˡ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribˡ-⊎′ ℓ _ _ _ = ×-distribˡ-⊎

×-distribʳ-⊎ : ((A ⊎ B) × C) ↔ (A × C ⊎ B × C)
×-distribʳ-⊎ = Σ-distribʳ-⊎

×-distribʳ-⊎′ : ∀ ℓ → _DistributesOverʳ_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distribʳ-⊎′ ℓ _ _ _ = ×-distribʳ-⊎

×-distrib-⊎′ : ∀ ℓ → _DistributesOver_ {ℓ = ℓ} _↔_ _×_ _⊎_
×-distrib-⊎′ ℓ = ×-distribˡ-⊎′ ℓ , ×-distribʳ-⊎′ ℓ

------------------------------------------------------------------------
-- ⊥, ⊤, _×_ and _⊎_ form a commutative semiring
Expand Down Expand Up @@ -228,7 +248,7 @@ private
×-⊎-isCommutativeSemiring k ℓ = isCommutativeSemiringˡ record
{ +-isCommutativeMonoid = ⊎-isCommutativeMonoid k ℓ
; *-isCommutativeMonoid = ×-isCommutativeMonoid k ℓ
; distribʳ = λ A B C → ↔⇒ (×-distribʳ-⊎ ℓ A B C)
; distribʳ = λ _ _ _ → ↔⇒ ×-distribʳ-⊎
; zeroˡ = ↔⇒ ∘ ×-zeroˡ ℓ
}

Expand Down Expand Up @@ -332,3 +352,11 @@ True↔ ( true because [p]) irr =
mk↔ₛ′ (λ _ → invert [p]) (λ _ → _) (irr _) (λ _ → refl)
True↔ (false because ofⁿ ¬p) _ =
mk↔ₛ′ (λ()) (invert (ofⁿ ¬p)) (λ x → flip contradiction ¬p x) (λ ())

------------------------------------------------------------------------
-- Relating a predicate to an existentially quantified one with the
-- restriction that the quantified variable is equal to the given one

∃-≡ : ∀ (P : A → Set b) {x} → P x ↔ (∃[ y ] y ≡ x × P y)
∃-≡ P {x} = mk↔ₛ′ (λ Px → x , refl , Px) (λ where (_ , refl , Py) → Py)
(λ where (_ , refl , _) → refl) (λ where _ → refl)
Loading