Search is not available for this dataset
text
string | meta
dict |
---|---|
module Issue152 where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
f : ℕ → ℕ
f 0 with zero
f 0 | n = n
f 1 with zero
f 1 | n = n
f n = n
g : ℕ → ℕ
g 0 with zero
g zero | n = n
g 1 with zero
g (suc zero) | n = n
g n = n
h : ℕ → ℕ
h zero with zero
h 0 | n = n
h (suc zero) with zero
h 1 | n = n
h n = n
|
{
"alphanum_fraction": 0.5074257426,
"avg_line_length": 12.2424242424,
"ext": "agda",
"hexsha": "3d9a1dc882daf6666acd8d6ec21af235ded28e4a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue152.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue152.agda",
"max_line_length": 28,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue152.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 173,
"size": 404
}
|
module Structure.Operator.Vector where
open import Functional using (swap)
import Lvl
open import Logic
open import Logic.Propositional
open import Structure.Setoid
open import Structure.Operator.Field
open import Structure.Operator.Group
open import Structure.Operator.Monoid
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Operator
open import Type
record VectorSpace {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ}
{V : Type{ℓᵥ}} ⦃ _ : Equiv{ℓᵥₑ}(V) ⦄
{S : Type{ℓₛ}} ⦃ _ : Equiv{ℓₛₑ}(S) ⦄
(_+ᵥ_ : V → V → V)
(_⋅ₛᵥ_ : S → V → V)
(_+ₛ_ : S → S → S)
(_⋅ₛ_ : S → S → S)
: Stmt{ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ ℓᵥₑ Lvl.⊔ ℓᵥ} where
constructor intro
field
⦃ scalarField ⦄ : Field(_+ₛ_)(_⋅ₛ_)
⦃ vectorCommutativeGroup ⦄ : CommutativeGroup(_+ᵥ_)
open Field(scalarField)
renaming (
𝟎 to 𝟎ₛ ;
𝟏 to 𝟏ₛ ;
_−_ to _−ₛ_ ;
_/_ to _/ₛ_ ;
−_ to −ₛ_ ;
⅟ to ⅟ₛ ;
[+]-group to [+ₛ]-group ;
[+]-commutativity to [+ₛ]-commutativity ;
[+]-monoid to [+ₛ]-monoid ;
[+]-binary-operator to [+ₛ]-binary-operator ;
[+]-associativity to [+ₛ]-associativity ;
[+]-identity-existence to [+ₛ]-identity-existence ;
[+]-identity to [+ₛ]-identity ;
[+]-identityₗ to [+ₛ]-identityₗ ;
[+]-identityᵣ to [+ₛ]-identityᵣ ;
[+]-inverse-existence to [+ₛ]-inverse-existence ;
[+]-inverse to [+ₛ]-inverse ;
[+]-inverseₗ to [+ₛ]-inverseₗ ;
[+]-inverseᵣ to [+ₛ]-inverseᵣ ;
[−]-function to [−ₛ]-function ;
[⋅]-binary-operator to [⋅ₛ]-binary-operator ;
[⋅]-associativity to [⋅ₛ]-associativity ;
[⋅]-identity-existence to [⋅ₛ]-identity-existence ;
[⋅]-identity to [⋅ₛ]-identity ;
[⋅]-identityₗ to [⋅ₛ]-identityₗ ;
[⋅]-identityᵣ to [⋅ₛ]-identityᵣ ;
[⋅]-inverseₗ to [⋅ₛ]-inverseₗ ;
[⋅]-inverseᵣ to [⋅ₛ]-inverseᵣ ;
distinct-identities to distinct-identitiesₛ
) public
open CommutativeGroup(vectorCommutativeGroup)
renaming (
id to 𝟎ᵥ ;
inv to −ᵥ_ ;
inv-op to _−ᵥ_ ;
group to [+ᵥ]-group;
commutativity to [+ᵥ]-commutativity;
monoid to [+ᵥ]-monoid ;
binary-operator to [+ᵥ]-binary-operator ;
associativity to [+ᵥ]-associativity ;
identity-existence to [+ᵥ]-identity-existence ;
identity to [+ᵥ]-identity ;
identityₗ to [+ᵥ]-identityₗ ;
identityᵣ to [+ᵥ]-identityᵣ ;
inverse-existence to [+ᵥ]-inverse-existence ;
inverse to [+ᵥ]-inverse ;
inverseₗ to [+ᵥ]-inverseₗ ;
inverseᵣ to [+ᵥ]-inverseᵣ ;
inv-function to [−ᵥ]-function
) public
field
⦃ [⋅ₛᵥ]-binaryOperator ⦄ : BinaryOperator(_⋅ₛᵥ_)
[⋅ₛ][⋅ₛᵥ]-compatibility : Names.Compatibility(_⋅ₛ_)(_⋅ₛᵥ_) -- TODO: This is semigroup action
⦃ [⋅ₛᵥ]-identity ⦄ : Identityₗ(_⋅ₛᵥ_)(𝟏ₛ)
⦃ [⋅ₛᵥ][+ᵥ]-distributivityₗ ⦄ : Distributivityₗ(_⋅ₛᵥ_)(_+ᵥ_)
[⋅ₛᵥ][+ₛ][+ᵥ]-distributivityᵣ : Names.DistributivityPatternᵣ(_⋅ₛᵥ_)(_+ₛ_)(_+ᵥ_) -- TODO: This is ∀? → Preserving₂
_⋅ᵥₛ_ = swap(_⋅ₛᵥ_)
record VectorSpaceVObject {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ}
{S : Type{ℓₛ}} ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄
(_+ₛ_ : S → S → S)
(_⋅ₛ_ : S → S → S)
: Stmt{ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ Lvl.𝐒(ℓᵥₑ Lvl.⊔ ℓᵥ)}
where
constructor intro
field
{Vector} : Type{ℓᵥ}
⦃ Vector-equiv ⦄ : Equiv{ℓᵥₑ}(Vector)
_+ᵥ_ : Vector → Vector → Vector
_⋅ₛᵥ_ : S → Vector → Vector
⦃ vectorSpace ⦄ : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_)
open VectorSpace(vectorSpace) public
record VectorSpaceObject {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ} : Stmt{Lvl.𝐒(ℓₛₑ Lvl.⊔ ℓₛ Lvl.⊔ ℓᵥₑ Lvl.⊔ ℓᵥ)} where
constructor intro
field
{Vector} : Type{ℓᵥ}
⦃ equiv-Vector ⦄ : Equiv{ℓᵥₑ}(Vector)
{Scalar} : Type{ℓₛ}
⦃ equiv-Scalar ⦄ : Equiv{ℓₛₑ}(Scalar)
_+ᵥ_ : Vector → Vector → Vector
_⋅ₛᵥ_ : Scalar → Vector → Vector
_+ₛ_ : Scalar → Scalar → Scalar
_⋅ₛ_ : Scalar → Scalar → Scalar
⦃ vectorSpace ⦄ : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_)
open VectorSpace(vectorSpace) public
|
{
"alphanum_fraction": 0.5466274332,
"avg_line_length": 36.8166666667,
"ext": "agda",
"hexsha": "df1114e11e271e0265439a20afa30477173d3311",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Vector.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Vector.agda",
"max_line_length": 117,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Vector.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1859,
"size": 4418
}
|
module Data.Char.Ranges where
open import Data.Char
open import Data.List
open import Data.Nat
open import Function
charRange : ℕ -> ℕ -> List Char
charRange start amount = applyUpTo (λ x -> fromℕ $ x + start) amount
UCletters : List Char
UCletters = charRange 65 26
LCletters : List Char
LCletters = charRange 97 26
greekLCletters : List Char
greekLCletters = charRange 945 25
greekUCletters : List Char
greekUCletters = charRange 913 25
symbols : List Char
symbols =
applyUpTo (λ x -> fromℕ $ x + 33) 15
++ applyUpTo (λ x -> fromℕ $ x + 58) 7
++ applyUpTo (λ x -> fromℕ $ x + 91) 6
++ applyUpTo (λ x -> fromℕ $ x + 123) 4
digits : List Char
digits = charRange 48 10
letters : List Char
letters = UCletters ++ LCletters
|
{
"alphanum_fraction": 0.701897019,
"avg_line_length": 21.0857142857,
"ext": "agda",
"hexsha": "e0cac015c993a9919abccab7b72ecd40d4732979",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/Char/Ranges.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/Char/Ranges.agda",
"max_line_length": 68,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/Char/Ranges.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 248,
"size": 738
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Complete.Properties {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Product
open import Relation.Binary
open import Categories.Category.Complete
open import Categories.Category.Complete.Finitely
open import Categories.Category.Construction.Functors
open import Categories.Diagram.Limit as Lim
open import Categories.Diagram.Limit.Properties
open import Categories.Diagram.Equalizer.Limit C
open import Categories.Diagram.Cone.Properties
open import Categories.Object.Product.Limit C
open import Categories.Object.Terminal.Limit C
open import Categories.Functor
open import Categories.Functor.Continuous
open import Categories.Functor.Properties
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_)
import Categories.Category.Construction.Cones as Co
import Categories.Morphism.Reasoning as MR
import Categories.Morphism as Mor
import Categories.Morphism.Properties as Morₚ
private
variable
o′ ℓ′ e′ o″ ℓ″ e″ : Level
module C = Category C
module _ (Com : Complete o′ ℓ′ e′ C) where
Complete⇒FinitelyComplete : FinitelyComplete C
Complete⇒FinitelyComplete = record
{ cartesian = record
{ terminal = limit⇒⊥ (Com (⊥⇒limit-F _ _ _))
; products = record
{ product = λ {A B} → limit⇒product (Com (product⇒limit-F _ _ _ A B))
}
}
; equalizer = λ f g → limit⇒equalizer (Com (equalizer⇒limit-F _ _ _ f g))
}
module _ {D : Category o′ ℓ′ e′} (Com : Complete o″ ℓ″ e″ D) where
private
D^C = Functors C D
module D^C = Category D^C
module D = Category D
module _ {J : Category o″ ℓ″ e″} (F : Functor J D^C) where
private
module J = Category J
module F = Functor F
open F
module F₀ j = Functor (F₀ j)
module F₁ {a b} (f : a J.⇒ b) = NaturalTransformation (F₁ f)
F[-,_] : C.Obj → Functor J D
F[-, X ] = record
{ F₀ = λ j → F₀.₀ j X
; F₁ = λ f → F₁.η f X
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = λ eq → F-resp-≈ eq -- this application cannot be eta reduced
}
F[-,-] : Functor C (Functors J D)
F[-,-] = record
{ F₀ = F[-,_]
; F₁ = λ f → ntHelper record
{ η = λ j → F₀.₁ j f
; commute = λ g → F₁.sym-commute g f
}
; identity = F₀.identity _
; homomorphism = F₀.homomorphism _
; F-resp-≈ = λ eq → F₀.F-resp-≈ _ eq
}
module F[-,-] = Functor F[-,-]
module LimFX X = Limit (Com F[-, X ])
open LimFX hiding (commute)
K⇒lim : ∀ {X Y} (f : X C.⇒ Y) K → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) K , limit Y ]
K⇒lim f K = rep-cone _ (nat-map-Cone (F[-,-].₁ f) K)
lim⇒lim : ∀ {X Y} (f : X C.⇒ Y) → Co.Cones F[-, Y ] [ nat-map-Cone (F[-,-].₁ f) (limit X) , limit Y ]
lim⇒lim f = K⇒lim f (limit _)
module lim⇒lim {X Y} (f : X C.⇒ Y) = Co.Cone⇒ F[-, Y ] (lim⇒lim f)
module FCone (K : Co.Cone F) where
open Co.Cone F K public
module N = Functor N
module ψ j = NaturalTransformation (ψ j)
module FCone⇒ {K K′ : Co.Cone F} (K⇒K′ : Co.Cone⇒ F K K′) where
open Co.Cone⇒ F K⇒K′ public
module arr = NaturalTransformation arr
FXcone : ∀ X → (K : Co.Cone F) → Co.Cone F[-, X ]
FXcone X K = record
{ N = N.₀ X
; apex = record
{ ψ = λ j → ψ.η j X
; commute = λ f → commute f -- this application cannot be eta reduced
}
}
where open FCone K
⊤ : Co.Cone F
⊤ = record
{ N = record
{ F₀ = λ X → apex X
; F₁ = λ {A B} f → lim⇒lim.arr f
; identity = λ {X} →
terminal.!-unique X record
{ arr = D.id
; commute = D.identityʳ ○ ⟺ (elimˡ (F₀.identity _))
}
; homomorphism = λ {X Y Z} {f g} →
terminal.!-unique₂ Z
{nat-map-Cone (F[-,-].₁ (g C.∘ f)) (limit X)}
{terminal.! Z}
{record { commute = λ {j} →
begin
proj Z j ∘ lim⇒lim.arr g ∘ lim⇒lim.arr f
≈⟨ pullˡ (lim⇒lim.commute g) ⟩
(F₀.₁ j g ∘ proj Y j) ∘ lim⇒lim.arr f
≈⟨ pullʳ (lim⇒lim.commute f) ⟩
F₀.₁ j g ∘ F₀.₁ j f ∘ proj X j
≈˘⟨ pushˡ (F₀.homomorphism j) ⟩
F₀.₁ j (g C.∘ f) ∘ proj X j
∎ }}
; F-resp-≈ = λ {A B} {f g} eq → terminal.!-unique B record
{ commute = lim⇒lim.commute g ○ ∘-resp-≈ˡ (F₀.F-resp-≈ _ (C.Equiv.sym eq)) }
}
; apex = record
{ ψ = λ j → ntHelper record
{ η = λ X → proj X j
; commute = λ _ → LimFX.commute _
}
; commute = λ f {X} → limit-commute X f
}
}
where open D
open D.HomReasoning
open MR D
K⇒⊤′ : ∀ X {K} → Co.Cones F [ K , ⊤ ] → Co.Cones F[-, X ] [ FXcone X K , LimFX.limit X ]
K⇒⊤′ X {K} K⇒⊤ = record
{ arr = arr.η X
; commute = comm
}
where open FCone⇒ K⇒⊤ renaming (commute to comm)
complete : Limit F
complete = record
{ terminal = record
{ ⊤ = ⊤
; ! = λ {K} →
let module K = FCone K
in record
{ arr = ntHelper record
{ η = λ X → rep X (FXcone X K)
; commute = λ {X Y} f →
terminal.!-unique₂ Y
{nat-map-Cone (F[-,-].₁ f) (FXcone X K)}
{record { commute = λ {j} →
begin
proj Y j ∘ rep Y (FXcone Y K) ∘ K.N.₁ f ≈⟨ pullˡ (LimFX.commute Y) ⟩
K.ψ.η j Y ∘ K.N.F₁ f ≈⟨ K.ψ.commute j f ⟩
F₀.₁ j f ∘ K.ψ.η j X ∎ }}
{record { commute = λ {j} →
begin
proj Y j ∘ lim⇒lim.arr f ∘ rep X (FXcone X K) ≈⟨ pullˡ (lim⇒lim.commute f) ⟩
(F₀.₁ j f ∘ proj X j) ∘ rep X (FXcone X K) ≈⟨ pullʳ (LimFX.commute X) ⟩
F₀.₁ j f ∘ K.ψ.η j X ∎ }}
}
; commute = λ {_} {X} → LimFX.commute X
}
; !-unique = λ K⇒⊤ {X} → terminal.!-unique X (K⇒⊤′ X K⇒⊤)
}
}
where open D
open D.HomReasoning
open MR D
ev : C.Obj → Functor D^C D
ev = evalF C D
module _ (L : Limit F) (X : C.Obj) where
private
module ev = Functor (ev X)
open Mor D^C
module DM = Mor D
open Morₚ D
open D.HomReasoning
open MR D
L′ : Limit (ev X ∘F F)
L′ = Com (ev X ∘F F)
Fiso : F[-, X ] ≃ ev X ∘F F
Fiso = record
{ F⇒G = ntHelper record
{ η = λ _ → D.id
; commute = λ _ → id-comm-sym ○ D.∘-resp-≈ˡ (introʳ (F₀.identity _))
}
; F⇐G = ntHelper record
{ η = λ _ → D.id
; commute = λ _ → D.∘-resp-≈ʳ (elimʳ (F₀.identity _)) ○ id-comm-sym
}
; iso = λ _ → record
{ isoˡ = D.identity²
; isoʳ = D.identity²
}
}
apex-iso : Limit.apex L ≅ Limit.apex complete
apex-iso = up-to-iso F L complete
apex-iso′ : Limit.apex (Com F[-, X ]) DM.≅ Limit.apex L′
apex-iso′ = ≃⇒lim≅ Fiso (Com F[-, X ]) L′
project-iso : Functor.F₀ (Limit.apex L) X DM.≅ Limit.apex L′
project-iso = record
{ from = ai.from D.∘ from.η X
; to = to.η X D.∘ ai.to
; iso = Iso-∘ (record { isoˡ = isoˡ ; isoʳ = isoʳ }) ai.iso
}
where open _≅_ apex-iso
module from = NaturalTransformation from
module to = NaturalTransformation to
module ai = DM._≅_ apex-iso′
Functors-Complete : Complete o″ ℓ″ e″ D^C
Functors-Complete F = complete F
evalF-Continuous : ∀ X → Continuous o″ ℓ″ e″ (evalF C D X)
evalF-Continuous X {J} {F} L = Com (evalF C D X ∘F F) , project-iso F L X
|
{
"alphanum_fraction": 0.4815907482,
"avg_line_length": 34.3076923077,
"ext": "agda",
"hexsha": "5e6b420205cef42344186a2b5a0bfd0a5f20226d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Complete/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2810,
"size": 8474
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Wedge.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.HITs.Pushout.Base
open import Cubical.Data.Unit
_⋁_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Type (ℓ-max ℓ ℓ')
_⋁_ (A , ptA) (B , ptB) = Pushout {A = Unit} {B = A} {C = B} (λ _ → ptA) (λ _ → ptB)
-- pointed versions
_⋁∙ₗ_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋁∙ₗ B = (A ⋁ B) , (inl (snd A))
_⋁∙ᵣ_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋁∙ᵣ B = (A ⋁ B) , (inr (snd B))
-- Wedge sum of Units is contractible
isContr-Unit⋁Unit : isContr ((Unit , tt) ⋁ (Unit , tt))
fst isContr-Unit⋁Unit = inl tt
snd isContr-Unit⋁Unit (inl tt) = refl
snd isContr-Unit⋁Unit (inr tt) = push tt
snd isContr-Unit⋁Unit (push tt i) j = push tt (i ∧ j)
|
{
"alphanum_fraction": 0.6226851852,
"avg_line_length": 32,
"ext": "agda",
"hexsha": "4c35559e3bd2ef6990ae291831a10e7a990ef2e8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 389,
"size": 864
}
|
open import Agda.Builtin.Nat
data Tm : Nat → Set where
UP : ∀ {n} → Tm n → Tm n
!_ : ∀ {n} → Tm n → Tm (suc n)
! UP t = UP (! t)
data Ty : Nat → Set where
⊥ : ∀ {n} → Ty n
_∶_ : ∀ {n} → Tm n → Ty n → Ty (suc n)
data Cx : Set where
∅ : Cx
_,_ : ∀ {n} → Cx → Ty n → Cx
data _⊇_ : Cx → Cx → Set where
base : ∅ ⊇ ∅
weak : ∀ {Γ Γ′ n} {A : Ty n} → Γ′ ⊇ Γ → (Γ′ , A) ⊇ Γ
lift : ∀ {Γ Γ′ n} {A : Ty n} → Γ′ ⊇ Γ → (Γ′ , A) ⊇ (Γ , A)
data True (Γ : Cx) : ∀ {n} → Ty n → Set where
up : ∀ {n} {t : Tm n} {A : Ty n} → True Γ (t ∶ A) → True Γ ((! t) ∶ (t ∶ A))
ren-true--pass : ∀ {n Γ Γ′} {A : Ty n} → Γ′ ⊇ Γ → True Γ A → True Γ′ A
ren-true--pass η (up j) = up (ren-true--pass η j)
ren-true--fail : ∀ {Γ Γ′ A} → Γ′ ⊇ Γ → True Γ A → True Γ′ A
ren-true--fail η (up j) = up (ren-true--fail η j)
|
{
"alphanum_fraction": 0.4396014944,
"avg_line_length": 26.7666666667,
"ext": "agda",
"hexsha": "fae21973f9d6f515b6699c88aa4437fb8518b50d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1982.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1982.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1982.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 412,
"size": 803
}
|
-- {-# OPTIONS --allow-unsolved-metas #-}
module Issue2369.OpenIP where
test : Set
test = {!!} -- unsolved interaction point
-- postulate A : {!!}
|
{
"alphanum_fraction": 0.6315789474,
"avg_line_length": 15.2,
"ext": "agda",
"hexsha": "e5a54e046edada1e975f19fd667de7df8f5ec006",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2369/OpenIP.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2369/OpenIP.agda",
"max_line_length": 42,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2369/OpenIP.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 42,
"size": 152
}
|
module Generic.Lib.Equality.Coerce where
open import Generic.Lib.Intro
open import Generic.Lib.Equality.Propositional
open import Generic.Lib.Decidable
open import Generic.Lib.Data.Product
Coerce′ : ∀ {α β} -> α ≡ β -> Set α -> Set β
Coerce′ refl = id
coerce′ : ∀ {α β} {A : Set α} -> (q : α ≡ β) -> A -> Coerce′ q A
coerce′ refl = id
uncoerce′ : ∀ {α β} {A : Set α} -> (q : α ≡ β) -> Coerce′ q A -> A
uncoerce′ refl = id
inspectUncoerce′ : ∀ {α β} {A : Set α}
-> (q : α ≡ β) -> (p : Coerce′ q A) -> ∃ λ x -> p ≡ coerce′ q x
inspectUncoerce′ refl x = x , refl
split : ∀ {α β γ δ} {A : Set α} {B : A -> Set β} {C : Set γ}
-> (q : α ⊔ β ≡ δ) -> Coerce′ q (Σ A B) -> (∀ x -> B x -> C) -> C
split q p g = uncurry g (uncoerce′ q p)
decCoerce′ : ∀ {α β} {A : Set α} -> (q : α ≡ β) -> IsSet A -> IsSet (Coerce′ q A)
decCoerce′ refl = id
data Coerce {β} : ∀ {α} -> α ≡ β -> Set α -> Set β where
coerce : ∀ {A} -> A -> Coerce refl A
qcoerce : ∀ {α β} {A : Set α} {q : α ≡ β} -> A -> Coerce q A
qcoerce {q = refl} = coerce
|
{
"alphanum_fraction": 0.5272206304,
"avg_line_length": 31.7272727273,
"ext": "agda",
"hexsha": "db8e9fca435ac642408830fa94125050bc08981d",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Equality/Coerce.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Equality/Coerce.agda",
"max_line_length": 81,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Equality/Coerce.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 424,
"size": 1047
}
|
module Function.Equals where
import Lvl
open import Functional
import Function.Names as Names
open import Logic
open import Logic.Propositional
open import Structure.Setoid
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Type
module Dependent {ℓ₁ ℓ₂ ℓₑ₂} {A : Type{ℓ₁}} {B : A → Type{ℓ₂}} ⦃ equiv-B : ∀{a} → Equiv{ℓₑ₂}(B(a)) ⦄ where
infixl 15 _⊜_
-- Function equivalence. When the types and all their values are shared/equivalent.
record _⊜_ (f : (a : A) → B(a)) (g : (a : A) → B(a)) : Stmt{ℓ₁ Lvl.⊔ ℓ₂ Lvl.⊔ ℓₑ₂} where
constructor intro
field
proof : (f Names.⊜ g)
instance
[⊜]-reflexivity : Reflexivity(_⊜_)
Reflexivity.proof([⊜]-reflexivity) = intro(reflexivity(_≡_) ⦃ Equiv.reflexivity(equiv-B) ⦄)
instance
[⊜]-symmetry : Symmetry(_⊜_)
Symmetry.proof([⊜]-symmetry) (intro fg) = intro(symmetry(_≡_) ⦃ Equiv.symmetry(equiv-B) ⦄ fg)
instance
[⊜]-transitivity : Transitivity(_⊜_)
Transitivity.proof([⊜]-transitivity) (intro fg) (intro gh) = intro(transitivity(_≡_) ⦃ Equiv.transitivity(equiv-B) ⦄ fg gh)
instance
[⊜]-equivalence : Equivalence(_⊜_)
[⊜]-equivalence = record{}
instance
[⊜]-equiv : Equiv((a : A) → B(a))
[⊜]-equiv = intro(_⊜_) ⦃ [⊜]-equivalence ⦄
instance
[⊜]-sub : (_≡_) ⊆₂ (_⊜_)
_⊆₂_.proof [⊜]-sub (intro proof) = intro proof
module _ {ℓ₁ ℓ₂ ℓₑ₂} {A : Type{ℓ₁}} {B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ where
private module D = Dependent {A = A} {B = const B} ⦃ equiv-B ⦄
open D using (module _⊜_ ; intro) public
_⊜_ = D._⊜_
[⊜]-reflexivity = D.[⊜]-reflexivity
[⊜]-symmetry = D.[⊜]-symmetry
[⊜]-transitivity = D.[⊜]-transitivity
[⊜]-equivalence = D.[⊜]-equivalence
[⊜]-equiv = D.[⊜]-equiv
[⊜]-sub = D.[⊜]-sub
|
{
"alphanum_fraction": 0.614668856,
"avg_line_length": 32.625,
"ext": "agda",
"hexsha": "c83a8952163633a19bb5d3028b827c80ee6e137a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Function/Equals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Function/Equals.agda",
"max_line_length": 127,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Function/Equals.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 761,
"size": 1827
}
|
------------------------------------------------------------------------------
-- Proving mirror (mirror t) = t using a list of trees
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.MirrorListSL where
open import Algebra
open import Function
open import Data.List hiding ( reverse )
open import Data.List.Properties
open import Data.Product hiding ( map )
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
module LM {A : Set} = Monoid (++-monoid A)
------------------------------------------------------------------------------
-- Auxiliary functions
reverse : {A : Set} → List A → List A
reverse [] = []
reverse (x ∷ xs) = reverse xs ++ x ∷ []
++-rightIdentity : {A : Set}(xs : List A) → xs ++ [] ≡ xs
++-rightIdentity = proj₂ LM.identity
reverse-++ : {A : Set}(xs ys : List A) →
reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++ [] ys = sym (++-rightIdentity (reverse ys))
reverse-++ (x ∷ xs) [] = cong (λ x' → reverse x' ++ x ∷ [])
(++-rightIdentity xs)
reverse-++ (x ∷ xs) (y ∷ ys) =
begin
reverse (xs ++ y ∷ ys) ++ x ∷ []
≡⟨ cong (λ x' → x' ++ x ∷ []) (reverse-++ xs (y ∷ ys)) ⟩
(reverse (y ∷ ys) ++ reverse xs) ++ x ∷ []
≡⟨ LM.assoc (reverse (y ∷ ys)) (reverse xs) (x ∷ []) ⟩
reverse (y ∷ ys) ++ reverse (x ∷ xs)
∎
------------------------------------------------------------------------------
-- The rose tree type.
data Tree (A : Set) : Set where
tree : A → List (Tree A) → Tree A
------------------------------------------------------------------------------
-- The mirror function.
{-# TERMINATING #-}
mirror : {A : Set} → Tree A → Tree A
mirror (tree a ts) = tree a (reverse (map mirror ts))
-- The proof of the property.
mirror-involutive : {A : Set} → (t : Tree A) → mirror (mirror t) ≡ t
helper : {A : Set} → (ts : List (Tree A)) →
reverse (map mirror (reverse (map mirror ts))) ≡ ts
mirror-involutive (tree a []) = refl
mirror-involutive (tree a (t ∷ ts)) =
begin
tree a (reverse (map mirror (reverse (map mirror ts) ++ mirror t ∷ [])))
≡⟨ cong (tree a) (helper (t ∷ ts)) ⟩
tree a (t ∷ ts)
∎
helper [] = refl
helper (t ∷ ts) =
begin
reverse (map mirror (reverse (map mirror ts) ++ mirror t ∷ []))
≡⟨ cong reverse
(map-++-commute mirror (reverse (map mirror ts)) (mirror t ∷ []))
⟩
reverse (map mirror (reverse (map mirror ts)) ++
(map mirror (mirror t ∷ [])))
≡⟨ subst (λ x → (reverse (map mirror (reverse (map mirror ts)) ++
(map mirror (mirror t ∷ [])))) ≡ x)
(reverse-++ (map mirror (reverse (map mirror ts)))
(map mirror (mirror t ∷ [])))
refl
⟩
reverse (map mirror (mirror t ∷ [])) ++
reverse (map mirror (reverse (map mirror ts)))
≡⟨ refl ⟩
mirror (mirror t) ∷ reverse (map mirror (reverse (map mirror ts)))
≡⟨ cong (flip _∷_ (reverse (map mirror (reverse (map mirror ts)))))
(mirror-involutive t)
⟩
t ∷ reverse (map mirror (reverse (map mirror ts)))
≡⟨ cong (_∷_ t) (helper ts) ⟩
t ∷ ts
∎
|
{
"alphanum_fraction": 0.4708284714,
"avg_line_length": 34.9795918367,
"ext": "agda",
"hexsha": "51117904898c9ca06aded5613817fff7298b3bbf",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/Mirror/MirrorListSL.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/Mirror/MirrorListSL.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/Mirror/MirrorListSL.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 939,
"size": 3428
}
|
module NativeIO where
open import Unit public
open import Data.List
open import Data.Nat
open import Data.String.Base using (String) public
{-# FOREIGN GHC import qualified Data.Text #-}
{-# FOREIGN GHC import qualified System.Environment #-}
postulate
NativeIO : Set → Set
nativeReturn : {A : Set} → A → NativeIO A
_native>>=_ : {A B : Set} → NativeIO A → (A → NativeIO B) → NativeIO B
{-# BUILTIN IO NativeIO #-}
{-# COMPILE GHC NativeIO = type IO #-}
{-# COMPILE GHC nativeReturn = (\_ -> return :: a -> IO a) #-}
{-# COMPILE GHC _native>>=_ = (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-}
postulate
nativeGetLine : NativeIO String
nativePutStrLn : String → NativeIO Unit
{-# COMPILE GHC nativePutStrLn = (\ s -> putStrLn (Data.Text.unpack s)) #-}
{-# COMPILE GHC nativeGetLine = (fmap Data.Text.pack getLine) #-}
postulate
getArgs : NativeIO (List String)
primShowNat : ℕ → String
{-# COMPILE GHC primShowNat = Data.Text.pack . show #-}
{-# COMPILE GHC getArgs = fmap (map Data.Text.pack) System.Environment.getArgs #-}
--
-- Debug function
--
{-# FOREIGN GHC import qualified Debug.Trace as Trace #-}
{-# FOREIGN GHC
debug = flip Trace.trace
debug' :: c -> Data.Text.Text -> c
debug' c txt = debug c (Data.Text.unpack txt)
#-}
postulate debug : {A : Set} → A → String → A
--debug {A} a s = a
{-# COMPILE GHC debug = (\x -> debug') #-}
postulate debug₁ : {A : Set₁} → A → String → A
-- debug₁ {A} a s = a
{-# COMPILE GHC debug₁ = (\x -> debug') #-}
|
{
"alphanum_fraction": 0.6273209549,
"avg_line_length": 23.9365079365,
"ext": "agda",
"hexsha": "e57efaf93b2cbdbf0e5791bcdf73c2b0d127c9f6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "src/NativeIO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "src/NativeIO.agda",
"max_line_length": 86,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "src/NativeIO.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 430,
"size": 1508
}
|
-- {-# OPTIONS -v tc.lhs.top:15 #-}
-- {-# OPTIONS -v term:20 #-}
-- Andreas, 2014-11-08, following a complaint by Francesco Mazzoli
open import Common.Prelude
data Subst : (d : Nat) → Set where
c₁ : ∀ {d} → Subst d → Subst d
c₂ : ∀ d₁ d₂ → Subst d₁ → Subst d₂ → Subst (suc d₁ + d₂)
postulate
comp : ∀ {d₁ d₂} → Subst d₁ → Subst d₂ → Subst (d₁ + d₂)
lookup : ∀ d → Nat → Subst d → Set₁
lookup d zero (c₁ ρ) = Set
lookup d (suc v) (c₁ ρ) = lookup d v ρ
lookup .(suc d₁ + d₂) v (c₂ d₁ d₂ ρ σ) = lookup (d₁ + d₂) v (comp ρ σ)
-- The dot pattern here is actually normalized, so it is
--
-- suc (d₁ + d₂)
--
-- the recursive call it with (d₁ + d₂).
-- In such simple cases, Agda can now recognize that the pattern is
-- constructor applied to call argument, which is valid descent.
-- This should termination check now.
-- Note however, that Agda only looks for syntactic equality,
-- since it is not allowed to normalize terms on the rhs (yet).
hidden : ∀{d} → Nat → Subst d → Set₁
hidden zero (c₁ ρ) = Set
hidden (suc v) (c₁ ρ) = hidden v ρ
hidden v (c₂ d₁ d₂ ρ σ) = hidden v (comp ρ σ)
-- This should also termination check, and looks pretty magical... ;-)
|
{
"alphanum_fraction": 0.5982498011,
"avg_line_length": 32.2307692308,
"ext": "agda",
"hexsha": "a970e2a252d00ef82b803c4835e035f909a6de0b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/SubTermination.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/SubTermination.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/SubTermination.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 423,
"size": 1257
}
|
-- Evidence producing divmod.
module Numeric.Nat.DivMod where
open import Prelude
open import Control.WellFounded
open import Tactic.Nat
open import Tactic.Nat.Reflect
open import Tactic.Nat.Exp
open import Numeric.Nat.Properties
private
lemModAux′ : ∀ k m b j → modAux k m (suc j + b) j ≡ modAux 0 m b m
lemModAux′ k m b zero = refl
lemModAux′ k m b (suc j) = lemModAux′ (suc k) m b j
lemModAux : ∀ k m b j → modAux k m (suc b + j) j ≡ modAux 0 m b m
lemModAux k m b j = (λ z → modAux k m (suc z) j) $≡ auto ⟨≡⟩ lemModAux′ k m b j
lemDivAux′ : ∀ k m b j → divAux k m (suc j + b) j ≡ divAux (suc k) m b m
lemDivAux′ k m b zero = refl
lemDivAux′ k m b (suc j) = lemDivAux′ k m b j
lemDivAux : ∀ k m b j → divAux k m (suc b + j) j ≡ divAux (suc k) m b m
lemDivAux k m b j = (λ z → divAux k m (suc z) j) $≡ auto ⟨≡⟩ lemDivAux′ k m b j
modLessAux : ∀ k m n j → k + j < suc m → modAux k m n j < suc m
modLessAux k m zero j lt = by lt
modLessAux k m (suc n) zero _ = modLessAux 0 m n m auto
modLessAux k m (suc n) (suc j) lt = modLessAux (suc k) m n j (by lt)
modLess : ∀ a b → a mod suc b < suc b
modLess a b = fast-diff $ modLessAux 0 b a b auto
divAuxGt : ∀ k a b j → a ≤ j → divAux k b a j ≡ k
divAuxGt k zero b j lt = refl
divAuxGt k (suc a) b zero lt = refute lt
divAuxGt k (suc a) b (suc j) lt = divAuxGt k a b j (by lt)
modAuxGt : ∀ k a b j → a ≤ j → modAux k b a j ≡ k + a
modAuxGt k zero b j lt = auto
modAuxGt k (suc a) b zero lt = refute lt
modAuxGt k (suc a) b (suc j) lt = by (modAuxGt (suc k) a b j (by lt))
qr-mul : (b q r : Nat) → Nat
qr-mul b q r = q * suc b + r
divmodAux : ∀ k a b → Acc _<_ a → qr-mul b (divAux k b a b) (modAux 0 b a b) ≡ qr-mul b k a
divmodAux k a b wf with compare b a
divmodAux k a b wf | greater lt =
let leq : a ≤ b
leq = by lt in
qr-mul b $≡ divAuxGt k a b b leq
*≡ modAuxGt 0 a b b leq
divmodAux k a .a wf | equal refl =
qr-mul a $≡ divAuxGt k a a a (diff! 0)
*≡ modAuxGt 0 a a a (diff! 0)
divmodAux k ._ b (acc wf) | less (diff! j) =
qr-mul b $≡ lemDivAux k b j b *≡ lemModAux 0 b j b ⟨≡⟩
by (divmodAux (suc k) j b (wf j auto))
divmod-spec : ∀ a b′ → let b = suc b′ in a div b * b + a mod b ≡ a
divmod-spec a b = eraseEquality (divmodAux 0 a b (wfNat a))
--- Public definitions ---
data DivMod (a b : Nat) : Set where
qr : ∀ q r → r < b → q * b + r ≡ a → DivMod a b
quot : ∀ {a b} → DivMod a b → Nat
quot (qr q _ _ _) = q
rem : ∀ {a b} → DivMod a b → Nat
rem (qr _ r _ _) = r
rem-less : ∀ {a b} (d : DivMod a b) → rem d < b
rem-less (qr _ _ lt _) = lt
quot-rem-sound : ∀ {a b} (d : DivMod a b) → quot d * b + rem d ≡ a
quot-rem-sound (qr _ _ _ eq) = eq
syntax divMod b a = a divmod b
divMod : ∀ b {{_ : NonZero b}} a → DivMod a b
divMod zero {{}} a
divMod (suc b) a = qr (a div suc b) (a mod suc b) (modLess a b) (divmod-spec a b)
{-# INLINE divMod #-}
--- Properties ---
mod-less : ∀ b {{_ : NonZero b}} a → a mod b < b
mod-less zero {{}} _
mod-less (suc b) a = rem-less (a divmod suc b)
divmod-sound : ∀ b {{_ : NonZero b}} a → (a div b) * b + a mod b ≡ a
divmod-sound zero {{}} _
divmod-sound (suc b) a = quot-rem-sound (a divmod suc b)
private
divmod-unique′ : (b q₁ q₂ r₁ r₂ : Nat) → r₁ < b → r₂ < b → q₁ * b + r₁ ≡ q₂ * b + r₂ → q₁ ≡ q₂ × r₁ ≡ r₂
divmod-unique′ b zero zero r₁ r₂ lt₁ lt₂ eq = refl , eq
divmod-unique′ b zero (suc q₂) ._ r₂ lt₁ lt₂ refl = refute lt₁
divmod-unique′ b (suc q₁) zero r₁ ._ lt₁ lt₂ refl = refute lt₂
divmod-unique′ b (suc q₁) (suc q₂) r₁ r₂ lt₁ lt₂ eq =
first (cong suc) $ divmod-unique′ b q₁ q₂ r₁ r₂ lt₁ lt₂ (by eq)
divmod-unique : ∀ {a b} (d₁ d₂ : DivMod a b) → quot d₁ ≡ quot d₂ × rem d₁ ≡ rem d₂
divmod-unique (qr q₁ r₁ lt₁ eq₁) (qr q₂ r₂ lt₂ eq₂) =
case divmod-unique′ _ q₁ q₂ r₁ r₂ lt₁ lt₂ (eq₁ ⟨≡⟩ʳ eq₂) of
λ p → eraseEquality (fst p) , eraseEquality (snd p)
quot-unique : ∀ {a b} (d₁ d₂ : DivMod a b) → quot d₁ ≡ quot d₂
quot-unique d₁ d₂ = fst (divmod-unique d₁ d₂)
rem-unique : ∀ {a b} (d₁ d₂ : DivMod a b) → rem d₁ ≡ rem d₂
rem-unique d₁ d₂ = snd (divmod-unique d₁ d₂)
instance
ShowDivMod : ∀ {a b} → Show (DivMod a b)
showsPrec {{ShowDivMod {a} {b}}} p (qr q r _ _) =
showParen (p >? 0) $ shows a ∘ showString " == "
∘ shows q ∘ showString " * " ∘ shows b ∘ showString " + " ∘ shows r
|
{
"alphanum_fraction": 0.5700179533,
"avg_line_length": 36.5245901639,
"ext": "agda",
"hexsha": "a852fe5f593182d0c34b584bcdf2cfec5f4ead2c",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/DivMod.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/DivMod.agda",
"max_line_length": 106,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/DivMod.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 1898,
"size": 4456
}
|
-- Positivity for functions in instantiated parameterised modules.
module Issue421 where
module Foo (_ : Set₁) where
Id : Set → Set
Id n = n
module FooApp = Foo Set
data ⊤ : Set where
tt : ⊤
⟦_⟧₁ : ⊤ → Set → Set
⟦ tt ⟧₁ x = FooApp.Id x
-- works: ⟦ tt ⟧ x = Foo.Id Set x
data μ₁ x : Set where
fix : ⟦ x ⟧₁ (μ₁ x) -> μ₁ x
-- Instantiating the module in another parameterised module:
module Matrices (J : Set) where
Id : (J → Set) → J → Set
Id m i = m i
data Poly : Set where
id : (D : Poly) -> Poly
module Dim (I : Set) where
module M = Matrices I
⟦_⟧₂ : Poly → (I → Set) → (I → Set)
⟦ id D ⟧₂ x i = M.Id x i
data μ₂ (p : Poly) (i : I) : Set where
fix : ⟦ p ⟧₂ (μ₂ p) i -> μ₂ p i
|
{
"alphanum_fraction": 0.5724233983,
"avg_line_length": 18.8947368421,
"ext": "agda",
"hexsha": "d8a19b95114ada432dd4a0fb86222fd6c4981663",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue421.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue421.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue421.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 279,
"size": 718
}
|
module ObsEq2 where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Fin : Nat -> Set where
fz : {n : Nat} -> Fin (suc n)
fs : {n : Nat} -> Fin n -> Fin (suc n)
infixr 40 _::_ _,_
data List (X : Set) : Set where
ε : List X
_::_ : X -> List X -> List X
record One : Set where
Π : (S : Set)(T : S -> Set) -> Set
Π S T = (x : S) -> T x
data Σ (S : Set)(T : S -> Set) : Set where
_,_ : (s : S) -> T s -> Σ S T
split : {S : Set}{T : S -> Set}{P : Σ S T -> Set}
(p : (s : S)(t : T s) -> P (s , t)) ->
(x : Σ S T) -> P x
split p (s , t) = p s t
fst : {S : Set}{T : S -> Set}(x : Σ S T) -> S
fst = split \s t -> s
snd : {S : Set}{T : S -> Set}(x : Σ S T) -> T (fst x)
snd = split \s t -> t
mutual
data ∗ : Set where
/Π/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
/Σ/ : (S : ∗)(T : [ S ] -> ∗) -> ∗
/Fin/ : Nat -> ∗
/D/ : (I : ∗)(A : [ I ] -> ∗)(R : (i : [ I ]) -> [ A i ] -> List [ I ])
-> [ I ] -> ∗
[_] : ∗ -> Set
[ /Π/ S T ] = Π [ S ] \s -> [ T s ]
[ /Σ/ S T ] = Σ [ S ] \s -> [ T s ]
[ /Fin/ n ] = Fin n
[ /D/ I A R i ] = Σ [ A i ] \a -> [ Kids I (/D/ I A R) (R i a) ]
Kids : (I : ∗)(P : [ I ] -> ∗) -> List [ I ] -> ∗
Kids I P ε = /Fin/ (suc zero)
Kids I P (i :: is) = /Σ/ (P i) \_ -> Kids I P is
/0/ : ∗
/0/ = /Fin/ zero
/1/ : ∗
/1/ = /Fin/ (suc zero)
/2/ : ∗
/2/ = /Fin/ (suc (suc zero))
Branches : {n : Nat}(P : Fin n -> Set) -> Set
Branches {zero} P = One
Branches {suc n} P = Σ (P fz) \_ -> Branches {n} \x -> P (fs x)
case : {n : Nat}{P : Fin n -> Set} -> Branches P -> (x : Fin n) -> P x
case pps fz = fst pps
case pps (fs x) = case (snd pps) x
infixr 40 _⟶_
infixr 60 _×_
_⟶_ : ∗ -> ∗ -> ∗
S ⟶ T = /Π/ S \_ -> T
_×_ : ∗ -> ∗ -> ∗
S × T = /Σ/ S \_ -> T
NatR : [ /1/ ] -> [ /2/ ] -> List [ /1/ ]
NatR _ fz = ε
NatR _ (fs fz) = fz :: ε
NatR _ (fs (fs ()))
/Nat/ : ∗
/Nat/ = /D/ /1/ (\_ -> /2/) NatR fz
/zero/ : [ /Nat/ ]
/zero/ = fz , fz
/suc/ : [ /Nat/ ⟶ /Nat/ ]
/suc/ n = fs fz , n , fz
Hyps : (I : ∗)(K : [ I ] -> ∗)
(P : (i : [ I ]) -> [ K i ] -> ∗)
(is : List [ I ]) -> [ Kids I K is ] -> ∗
Hyps I K P ε _ = /1/
Hyps I K P (i :: is) (k , ks) = /Σ/ (P i k) \_ -> Hyps I K P is ks
recs : (I : ∗)(K : [ I ] -> ∗)
(P : (i : [ I ]) -> [ K i ] -> ∗)
(e : (i : [ I ])(k : [ K i ]) -> [ P i k ])
(is : List [ I ])(ks : [ Kids I K is ]) -> [ Hyps I K P is ks ]
recs I K P e ε _ = fz
recs I K P e (i :: is) (k , ks) = ( e i k , recs I K P e is ks )
elim : (I : ∗)(A : [ I ] -> ∗)(R : (i : [ I ]) -> [ A i ] -> List [ I ])
(P : (i : [ I ]) -> [ /D/ I A R i ] -> ∗) ->
[( (/Π/ I \i -> /Π/ (A i) \a ->
/Π/ (Kids I (/D/ I A R) (R i a)) \ks ->
Hyps I (/D/ I A R) P (R i a) ks ⟶ P i (a , ks)) ⟶
/Π/ I \i -> /Π/ (/D/ I A R i) \x -> P i x )]
elim I A R P p i (a , ks) =
p i a ks (recs I (/D/ I A R) P (elim I A R P p) (R i a) ks)
natElim : (P : [ /Nat/ ] -> ∗) ->
[( P /zero/ ⟶
(/Π/ /Nat/ \n -> P n ⟶ P (/suc/ n)) ⟶
/Π/ /Nat/ P )]
natElim P pz ps = elim /1/ (\_ -> /2/) NatR (case (P , _))
(case ( case (case ((\_ -> pz ) , _ )
, (split \n -> case (split (\h _ -> ps n h) , _ )) , _ ) , _ ))
fz
plus : [ /Nat/ ⟶ /Nat/ ⟶ /Nat/ ]
plus x y = natElim (\_ -> /Nat/) y (\_ -> /suc/) x
{-
elim /1/ (\_ -> /2/) NatR (\_ _ -> /Nat/)
(\_ -> case
((\_ _ -> y )
, split (\_ _ -> split (\n _ -> /suc/ n ) ) , _ ) )
fz x
-}
mutual
_⇔_ : ∗ -> ∗ -> ∗
/Π/ S0 T0 ⇔ /Π/ S1 T1 =
(S1 ⇔ S0) ×
/Π/ S1 \s1 -> /Π/ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⟶ (T0 s0 ⇔ T1 s1)
/Σ/ S0 T0 ⇔ /Σ/ S1 T1 =
(S0 ⇔ S1) ×
/Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶ (T0 s0 ⇔ T1 s1)
/Fin/ _ ⇔ /Π/ _ _ = /0/
/Fin/ _ ⇔ /Σ/ _ _ = /0/
/Fin/ _ ⇔ /D/ _ _ _ _ = /0/
/Π/ _ _ ⇔ /Fin/ _ = /0/
/Σ/ _ _ ⇔ /Fin/ _ = /0/
/D/ _ _ _ _ ⇔ /Fin/ _ = /0/
/Fin/ zero ⇔ /Fin/ zero = /1/
/Fin/ (suc m) ⇔ /Fin/ (suc n) = /Fin/ m ⇔ /Fin/ n
/D/ I0 A0 R0 i0 ⇔ /D/ I1 A1 R1 i1 =
(I0 ⇔ I1) ×
(/Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶ (A0 i0 ⇔ A1 i1)) ×
(/Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
/Π/ (A0 i0) \a0 -> /Π/ (A1 i1) \a1 -> (A0 i0 > a0 ≅ A1 i1 > a1) ⟶
Eqs I0 (R0 i0 a0) I1 (R1 i1 a1)) ×
(I0 > i0 ≅ I1 > i1)
_ ⇔ _ = /0/
Eqs : (I0 : ∗) -> List [ I0 ] -> (I1 : ∗) -> List [ I1 ] -> ∗
Eqs _ ε _ ε = /1/
Eqs I0 (i0 :: is0) I1 (i1 :: is1) = (I0 > i0 ≅ I1 > i1) × Eqs I0 is0 I1 is1
Eqs _ _ _ _ = /0/
_>_≅_>_ : (S : ∗) -> [ S ] -> (T : ∗) -> [ T ] -> ∗
/Π/ S0 T0 > f0 ≅ /Π/ S1 T1 > f1 =
/Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶
(T0 s0 > f0 s0 ≅ T1 s1 > f1 s1)
/Σ/ S0 T0 > p0 ≅ /Σ/ S1 T1 > p1 =
let s0 : [ S0 ] ; s0 = fst p0
s1 : [ S1 ] ; s1 = fst p1
in (S0 > s0 ≅ S1 > s1) × (T0 s0 > snd p0 ≅ T1 s1 > snd p1)
/Fin/ (suc n0) > fz ≅ /Fin/ (suc n1) > fz = /1/
/Fin/ (suc n0) > fs x0 ≅ /Fin/ (suc n1) > fs x1 =
/Fin/ n0 > x0 ≅ /Fin/ n1 > x1
/D/ I0 A0 R0 i0 > (a0 , ks0) ≅ /D/ I1 A1 R1 i1 > (a1 , ks1) =
(A0 i0 > a0 ≅ A1 i1 > a1) ×
(Kids I0 (/D/ I0 A0 R0) (R0 i0 a0) > ks0 ≅
Kids I1 (/D/ I1 A1 R1) (R1 i1 a1) > ks1)
_ > _ ≅ _ > _ = /0/
Resp : (S : ∗)(P : [ S ] -> ∗)
{s0 s1 : [ S ]} -> [ (S > s0 ≅ S > s1) ⟶ (P s0 ⇔ P s1) ]
Resp = {! !}
[_>_] : (S : ∗)(s : [ S ]) -> [ S > s ≅ S > s ]
[_>_] = {! !}
KidsResp : (I0 : ∗)(I1 : ∗) -> [ I0 ⇔ I1 ] ->
(P0 : [ I0 ] -> ∗)(P1 : [ I1 ] -> ∗) ->
[( /Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
(P0 i0 ⇔ P1 i1) )] ->
(is0 : List [ I0 ])(is1 : List [ I1 ]) ->
[ Eqs I0 is0 I1 is1 ] ->
[ Kids I0 P0 is0 ⇔ Kids I1 P1 is1 ]
KidsResp = {! !}
mutual
_>_<_!_ : (S : ∗) -> [ S ] -> (T : ∗) -> [ S ⇔ T ] -> [ T ]
/Π/ S0 T0 > f0 < /Π/ S1 T1 ! Q =
let S1S0 : [ S1 ⇔ S0 ]
S1S0 = fst Q
T0T1 : [( /Π/ S1 \s1 -> /Π/ S0 \s0 -> (S1 > s1 ≅ S0 > s0) ⟶
(T0 s0 ⇔ T1 s1) )]
T0T1 = snd Q
in \s1 ->
let s0 : [ S0 ]
s0 = S1 > s1 < S0 ! S1S0
s1s0 : [( S1 > s1 ≅ S0 > s0 )]
s1s0 = [| S1 > s1 < S0 ! S1S0 |]
in T0 s0 > f0 s0 < T1 s1 ! T0T1 s1 s0 s1s0
/Σ/ S0 T0 > p0 < /Σ/ S1 T1 ! Q =
let S0S1 : [ S0 ⇔ S1 ]
S0S1 = fst Q
T0T1 : [( /Π/ S0 \s0 -> /Π/ S1 \s1 -> (S0 > s0 ≅ S1 > s1) ⟶
(T0 s0 ⇔ T1 s1) )]
T0T1 = snd Q
s0 : [ S0 ]
s0 = fst p0
s1 : [ S1 ]
s1 = S0 > s0 < S1 ! S0S1
s0s1 : [ S0 > s0 ≅ S1 > s1 ]
s0s1 = [| S0 > s0 < S1 ! S0S1 |]
t0 : [ T0 s0 ]
t0 = snd p0
t1 : [ T1 s1 ]
t1 = T0 s0 > t0 < T1 s1 ! T0T1 s0 s1 s0s1
in s1 , t1
/Fin/ (suc n0) > fz < /Fin/ (suc n1) ! Q = fz
/Fin/ (suc n0) > fs x < /Fin/ (suc n1) ! Q = fs (/Fin/ n0 > x < /Fin/ n1 ! Q)
/D/ I0 A0 R0 i0 > (a0 , ks0) < /D/ I1 A1 R1 i1 ! Q =
let I01 : [ I0 ⇔ I1 ] ; I01 = fst Q
A01 : [( /Π/ I0 \i0 -> /Π/ I1 \i1 ->
(I0 > i0 ≅ I1 > i1) ⟶ (A0 i0 ⇔ A1 i1) )]
A01 = fst (snd Q)
R01 : [( /Π/ I0 \i0 -> /Π/ I1 \i1 -> (I0 > i0 ≅ I1 > i1) ⟶
/Π/ (A0 i0) \a0 -> /Π/ (A1 i1) \a1 ->
(A0 i0 > a0 ≅ A1 i1 > a1) ⟶
Eqs I0 (R0 i0 a0) I1 (R1 i1 a1) )]
R01 = fst (snd (snd Q))
i01 : [ I0 > i0 ≅ I1 > i1 ] ; i01 = snd (snd (snd Q))
in (/Σ/ (A0 i0) \a0 -> Kids I0 (/D/ I0 A0 R0) (R0 i0 a0)) > (a0 , ks0) <
(/Σ/ (A1 i1) \a1 -> Kids I1 (/D/ I1 A1 R1) (R1 i1 a1)) !
A01 i0 i1 i01 ,
\x0 x1 x01 ->
KidsResp I0 I1 I01
(/D/ I0 A0 R0) (/D/ I1 A1 R1) (\j0 j1 j01 -> I01 , A01 , R01 , j01 )
(R0 i0 x0) (R1 i1 x1) (R01 i0 i1 i01 x0 x1 x01)
/Π/ _ _ > _ < /Σ/ _ _ ! ()
/Π/ _ _ > _ < /Fin/ _ ! ()
/Π/ _ _ > _ < /D/ _ _ _ _ ! ()
/Σ/ _ _ > _ < /Π/ _ _ ! ()
/Σ/ _ _ > _ < /Fin/ _ ! ()
/Σ/ _ _ > _ < /D/ _ _ _ _ ! ()
/D/ _ _ _ _ > _ < /Π/ _ _ ! ()
/D/ _ _ _ _ > _ < /Σ/ _ _ ! ()
/D/ _ _ _ _ > _ < /Fin/ _ ! ()
/Fin/ _ > _ < /Π/ _ _ ! ()
/Fin/ _ > _ < /Σ/ _ _ ! ()
/Fin/ zero > () < /Fin/ zero ! _
/Fin/ zero > _ < /Fin/ (suc n) ! ()
/Fin/ (suc n) > _ < /Fin/ zero ! ()
/Fin/ _ > _ < /D/ _ _ _ _ ! ()
[|_>_<_!_|] : (S : ∗)(s : [ S ])(T : ∗)(q : [ S ⇔ T ]) ->
[ S > s ≅ T > (S > s < T ! q) ]
[| S > s < T ! q |] = {! !}
ext : (S : ∗)(T : [ S ] -> ∗)(f g : [ /Π/ S T ]) ->
[( /Π/ S \x -> T x > f x ≅ T x > g x )] ->
[ /Π/ S T > f ≅ /Π/ S T > g ]
ext S T f g h s0 s1 s01 =
(T s0 > f s0 ≅ T s0 > g s0) > h s0 < (T s0 > f s0 ≅ T s1 > g s1) !
Resp S (\s1 -> T s0 > f s0 ≅ T s1 > g s1) s01
plusZeroLemma : [ (/Nat/ ⟶ /Nat/) > (\x -> plus x /zero/) ≅
(/Nat/ ⟶ /Nat/) > (\x -> plus /zero/ x) ]
plusZeroLemma = ext /Nat/ (\_ -> /Nat/)
(\x -> plus x /zero/) (\x -> plus /zero/ x) (natElim (\x ->
/Nat/ > plus x /zero/ ≅ /Nat/ > plus /zero/ x) (fz , fz)
(\n h -> [ (/Nat/ ⟶ /Nat/) > /suc/ ] (plus n /zero/) n h ))
|
{
"alphanum_fraction": 0.3495575221,
"avg_line_length": 30.5405405405,
"ext": "agda",
"hexsha": "cc46487518c7958fdb4b2fb355295f18d8d24509",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/OTT/ObsEq2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/OTT/ObsEq2.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/OTT/ObsEq2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 4694,
"size": 9040
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Group.EilenbergMacLane.Properties where
open import Cubical.Algebra.Group.EilenbergMacLane.Base renaming (elim to EM-elim)
open import Cubical.Algebra.Group.EilenbergMacLane.WedgeConnectivity
open import Cubical.Algebra.Group.EilenbergMacLane.GroupStructure
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.AbGroup.TensorProduct
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Loopspace
open import Cubical.Functions.Morphism
open import Cubical.Data.Sigma
open import Cubical.Data.Nat hiding (_·_)
open import Cubical.HITs.Truncation as Trunc
renaming (rec to trRec; elim to trElim)
open import Cubical.HITs.EilenbergMacLane1 renaming (rec to EMrec)
open import Cubical.HITs.Truncation
renaming (elim to trElim ; rec to trRec ; rec2 to trRec2)
open import Cubical.HITs.Susp
private
variable ℓ ℓ' ℓ'' : Level
isConnectedEM₁ : (G : Group ℓ) → isConnected 2 (EM₁ G)
isConnectedEM₁ G = ∣ embase ∣ , h
where
h : (y : hLevelTrunc 2 (EM₁ G)) → ∣ embase ∣ ≡ y
h = trElim (λ y → isOfHLevelSuc 1 (isOfHLevelTrunc 2 ∣ embase ∣ y))
(elimProp G (λ x → isOfHLevelTrunc 2 ∣ embase ∣ ∣ x ∣) refl)
module _ {G' : AbGroup ℓ} where
private
G = fst G'
open AbGroupStr (snd G') renaming (_+_ to _+G_)
isConnectedEM : (n : ℕ) → isConnected (suc n) (EM G' n)
fst (isConnectedEM zero) = ∣ 0g ∣
snd (isConnectedEM zero) y = isOfHLevelTrunc 1 _ _
isConnectedEM (suc zero) = isConnectedEM₁ (AbGroup→Group G')
fst (isConnectedEM (suc (suc n))) = ∣ 0ₖ _ ∣
snd (isConnectedEM (suc (suc n))) =
trElim (λ _ → isOfHLevelTruncPath)
(trElim (λ _ → isOfHLevelSuc (3 + n) (isOfHLevelTruncPath {n = (3 + n)}))
(raw-elim G'
(suc n)
(λ _ → isOfHLevelTrunc (3 + n) _ _)
refl))
module _ (Ĝ : Group ℓ) where
private
G = fst Ĝ
open GroupStr (snd Ĝ)
emloop-id : emloop 1g ≡ refl
emloop-id =
emloop 1g ≡⟨ rUnit (emloop 1g) ⟩
emloop 1g ∙ refl ≡⟨ cong (emloop 1g ∙_) (rCancel (emloop 1g) ⁻¹) ⟩
emloop 1g ∙ (emloop 1g ∙ (emloop 1g) ⁻¹) ≡⟨ ∙assoc _ _ _ ⟩
(emloop 1g ∙ emloop 1g) ∙ (emloop 1g) ⁻¹ ≡⟨ cong (_∙ emloop 1g ⁻¹)
((emloop-comp Ĝ 1g 1g) ⁻¹) ⟩
emloop (1g · 1g) ∙ (emloop 1g) ⁻¹ ≡⟨ cong (λ g → emloop {Group = Ĝ} g
∙ (emloop 1g) ⁻¹)
(·IdR 1g) ⟩
emloop 1g ∙ (emloop 1g) ⁻¹ ≡⟨ rCancel (emloop 1g) ⟩
refl ∎
emloop-inv : (g : G) → emloop (inv g) ≡ (emloop g) ⁻¹
emloop-inv g =
emloop (inv g) ≡⟨ rUnit (emloop (inv g)) ⟩
emloop (inv g) ∙ refl ≡⟨ cong (emloop (inv g) ∙_)
(rCancel (emloop g) ⁻¹) ⟩
emloop (inv g) ∙ (emloop g ∙ (emloop g) ⁻¹) ≡⟨ ∙assoc _ _ _ ⟩
(emloop (inv g) ∙ emloop g) ∙ (emloop g) ⁻¹ ≡⟨ cong (_∙ emloop g ⁻¹)
((emloop-comp Ĝ (inv g) g) ⁻¹) ⟩
emloop (inv g · g) ∙ (emloop g) ⁻¹ ≡⟨ cong (λ h → emloop {Group = Ĝ} h
∙ (emloop g) ⁻¹)
(·InvL g) ⟩
emloop 1g ∙ (emloop g) ⁻¹ ≡⟨ cong (_∙ (emloop g) ⁻¹) emloop-id ⟩
refl ∙ (emloop g) ⁻¹ ≡⟨ (lUnit ((emloop g) ⁻¹)) ⁻¹ ⟩
(emloop g) ⁻¹ ∎
isGroupoidEM₁ : isGroupoid (EM₁ Ĝ)
isGroupoidEM₁ = emsquash
--------- Ω (EM₁ G) ≃ G ---------
{- since we write composition in diagrammatic order,
and function composition in the other order,
we need right multiplication here -}
rightEquiv : (g : G) → G ≃ G
rightEquiv g = isoToEquiv isom
where
isom : Iso G G
isom .Iso.fun = _· g
isom .Iso.inv = _· inv g
isom .Iso.rightInv h =
(h · inv g) · g ≡⟨ (·Assoc h (inv g) g) ⁻¹ ⟩
h · inv g · g ≡⟨ cong (h ·_) (·InvL g) ⟩
h · 1g ≡⟨ ·IdR h ⟩ h ∎
isom .Iso.leftInv h =
(h · g) · inv g ≡⟨ (·Assoc h g (inv g)) ⁻¹ ⟩
h · g · inv g ≡⟨ cong (h ·_) (·InvR g) ⟩
h · 1g ≡⟨ ·IdR h ⟩ h ∎
compRightEquiv : (g h : G)
→ compEquiv (rightEquiv g) (rightEquiv h) ≡ rightEquiv (g · h)
compRightEquiv g h = equivEq (funExt (λ x → (·Assoc x g h) ⁻¹))
CodesSet : EM₁ Ĝ → hSet ℓ
CodesSet = EMrec Ĝ (isOfHLevelTypeOfHLevel 2) (G , is-set) RE REComp
where
RE : (g : G) → Path (hSet ℓ) (G , is-set) (G , is-set)
RE g = Σ≡Prop (λ X → isPropIsOfHLevel {A = X} 2) (ua (rightEquiv g))
lemma₁ : (g h : G) → Square
(ua (rightEquiv g)) (ua (rightEquiv (g · h)))
refl (ua (rightEquiv h))
lemma₁ g h = invEq
(Square≃doubleComp (ua (rightEquiv g)) (ua (rightEquiv (g · h)))
refl (ua (rightEquiv h)))
(ua (rightEquiv g) ∙ ua (rightEquiv h)
≡⟨ (uaCompEquiv (rightEquiv g) (rightEquiv h)) ⁻¹ ⟩
ua (compEquiv (rightEquiv g) (rightEquiv h))
≡⟨ cong ua (compRightEquiv g h) ⟩
ua (rightEquiv (g · h)) ∎)
REComp : (g h : G) → Square (RE g) (RE (g · h)) refl (RE h)
REComp g h = ΣSquareSet (λ _ → isProp→isSet isPropIsSet) (lemma₁ g h)
Codes : EM₁ Ĝ → Type ℓ
Codes x = CodesSet x .fst
encode : (x : EM₁ Ĝ) → embase ≡ x → Codes x
encode x p = subst Codes p 1g
decode : (x : EM₁ Ĝ) → Codes x → embase ≡ x
decode = elimSet Ĝ (λ x → isOfHLevelΠ 2 (λ c → isGroupoidEM₁ (embase) x))
emloop λ g → ua→ λ h → emcomp h g
decode-encode : (x : EM₁ Ĝ) (p : embase ≡ x) → decode x (encode x p) ≡ p
decode-encode x p = J (λ y q → decode y (encode y q) ≡ q)
(emloop (transport refl 1g) ≡⟨ cong emloop (transportRefl 1g) ⟩
emloop 1g ≡⟨ emloop-id ⟩ refl ∎) p
encode-decode : (x : EM₁ Ĝ) (c : Codes x) → encode x (decode x c) ≡ c
encode-decode = elimProp Ĝ (λ x → isOfHLevelΠ 1 (λ c → CodesSet x .snd _ _))
λ g → encode embase (decode embase g) ≡⟨ refl ⟩
encode embase (emloop g) ≡⟨ refl ⟩
transport (ua (rightEquiv g)) 1g ≡⟨ uaβ (rightEquiv g) 1g ⟩
1g · g ≡⟨ ·IdL g ⟩
g ∎
ΩEM₁Iso : Iso (Path (EM₁ Ĝ) embase embase) G
Iso.fun ΩEM₁Iso = encode embase
Iso.inv ΩEM₁Iso = emloop
Iso.rightInv ΩEM₁Iso = encode-decode embase
Iso.leftInv ΩEM₁Iso = decode-encode embase
ΩEM₁≡ : (Path (EM₁ Ĝ) embase embase) ≡ G
ΩEM₁≡ = isoToPath ΩEM₁Iso
--------- Ω (EMₙ₊₁ G) ≃ EMₙ G ---------
module _ {G : AbGroup ℓ} where
open AbGroupStr (snd G)
renaming (_+_ to _+G_ ; -_ to -G_ ; +Assoc to +AssocG)
CODE : (n : ℕ) → EM G (suc (suc n)) → TypeOfHLevel ℓ (3 + n)
CODE n =
trElim (λ _ → isOfHLevelTypeOfHLevel (3 + n))
λ { north → EM G (suc n) , hLevelEM G (suc n)
; south → EM G (suc n) , hLevelEM G (suc n)
; (merid a i) → fib n a i}
where
fib : (n : ℕ) → (a : EM-raw G (suc n))
→ Path (TypeOfHLevel _ (3 + n))
(EM G (suc n) , hLevelEM G (suc n))
(EM G (suc n) , hLevelEM G (suc n))
fib zero a = Σ≡Prop (λ _ → isPropIsOfHLevel 3)
(isoToPath (addIso 1 a))
fib (suc n) a = Σ≡Prop (λ _ → isPropIsOfHLevel (4 + n))
(isoToPath (addIso (suc (suc n)) ∣ a ∣))
decode' : (n : ℕ) (x : EM G (suc (suc n))) → CODE n x .fst → 0ₖ (suc (suc n)) ≡ x
decode' n =
trElim (λ _ → isOfHLevelΠ (4 + n)
λ _ → isOfHLevelPath (4 + n) (isOfHLevelTrunc (4 + n)) _ _)
λ { north → f n
; south → g n
; (merid a i) → main a i}
where
f : (n : ℕ) → _
f n = σ-EM' n
g : (n : ℕ) → EM G (suc n) → ∣ ptEM-raw ∣ ≡ ∣ south ∣
g n x = σ-EM' n x ∙ cong ∣_∣ₕ (merid ptEM-raw)
lem₂ : (n : ℕ) (a x : _)
→ Path (Path (EM G (suc (suc n))) _ _)
((λ i → cong ∣_∣ₕ (σ-EM n x) i) ∙ sym (cong ∣_∣ₕ (σ-EM n a)) ∙ (λ i → ∣ merid a i ∣ₕ))
(g n (EM-raw→EM G (suc n) x))
lem₂ zero a x =
cong (f zero x ∙_)
(cong (_∙ cong ∣_∣ₕ (merid a)) (cong (cong ∣_∣ₕ) (symDistr (merid a) (sym (merid embase)))
∙ cong-∙ ∣_∣ₕ (merid embase) (sym (merid a)))
∙∙ sym (∙assoc _ _ _)
∙∙ cong (cong ∣_∣ₕ (merid embase) ∙_) (lCancel (cong ∣_∣ₕ (merid a)))
∙ sym (rUnit _))
lem₂ (suc n) a x =
cong (f (suc n) ∣ x ∣ ∙_)
((cong (_∙ cong ∣_∣ₕ (merid a)) (cong (cong ∣_∣ₕ) (symDistr (merid a) (sym (merid north)))
∙ cong-∙ ∣_∣ₕ (merid north) (sym (merid a)))
∙∙ sym (∙assoc _ _ _)
∙∙ cong (cong ∣_∣ₕ (merid north) ∙_) (lCancel (cong ∣_∣ₕ (merid a)))
∙ sym (rUnit _)))
lem : (n : ℕ) (x a : EM-raw G (suc n))
→ f n (transport (sym (cong (λ x → CODE n x .fst) (cong ∣_∣ₕ (merid a))))
(EM-raw→EM G (suc n) x))
≡ cong ∣_∣ₕ (σ-EM n x) ∙ sym (cong ∣_∣ₕ (σ-EM n a))
lem zero x a = (λ i → cong ∣_∣ₕ (merid (transportRefl x i -[ 1 ]ₖ a) ∙ sym (merid embase)))
∙∙ σ-EM'-hom zero x (-ₖ a)
∙∙ cong (f zero x ∙_) (σ-EM'-ₖ zero a)
lem (suc n) x a =
cong (f (suc n)) (λ i → transportRefl ∣ x ∣ i -[ 2 + n ]ₖ ∣ a ∣)
∙∙ σ-EM'-hom (suc n) ∣ x ∣ (-ₖ ∣ a ∣)
∙∙ cong (f (suc n) ∣ x ∣ ∙_) (σ-EM'-ₖ (suc n) ∣ a ∣)
main : (a : _)
→ PathP (λ i → CODE n ∣ merid a i ∣ₕ .fst
→ 0ₖ (suc (suc n)) ≡ ∣ merid a i ∣ₕ) (f n) (g n)
main a =
toPathP (funExt
(EM-elim _ (λ _ → isOfHLevelPathP (2 + (suc n)) (isOfHLevelTrunc (4 + n) _ _) _ _)
λ x →
((λ i → transp (λ j → Path (EM G (2 + n)) ∣ ptEM-raw ∣ ∣ merid a (i ∨ j) ∣)
i (compPath-filler (lem n x a i) (cong ∣_∣ₕ (merid a)) i) ))
∙∙ sym (∙assoc _ _ _)
∙∙ lem₂ n a x))
encode' : (n : ℕ) (x : EM G (suc (suc n))) → 0ₖ (suc (suc n)) ≡ x → CODE n x .fst
encode' n x p = subst (λ x → CODE n x .fst) p (0ₖ (suc n))
decode'-encode' : (n : ℕ) (x : EM G (2 + n)) (p : 0ₖ (2 + n) ≡ x)
→ decode' n x (encode' n x p) ≡ p
decode'-encode' zero x =
J (λ x p → decode' 0 x (encode' 0 x p) ≡ p)
(σ-EM'-0ₖ 0)
decode'-encode' (suc n) x =
J (λ x p → decode' (suc n) x (encode' (suc n) x p) ≡ p)
(σ-EM'-0ₖ (suc n))
encode'-decode' : (n : ℕ) (x : _)
→ encode' n (0ₖ (suc (suc n))) (decode' n (0ₖ (suc (suc n))) x) ≡ x
encode'-decode' zero x =
cong (encode' zero (0ₖ 2)) (cong-∙ ∣_∣ₕ (merid x) (sym (merid embase)))
∙∙ substComposite (λ x → CODE zero x .fst)
(cong ∣_∣ₕ (merid x)) (sym (cong ∣_∣ₕ (merid ptEM-raw))) embase
∙∙ (cong (subst (λ x₁ → CODE zero x₁ .fst) (λ i → ∣ merid embase (~ i) ∣ₕ))
(λ i → lUnitₖ 1 (transportRefl x i) i)
∙ (λ i → rUnitₖ 1 (transportRefl x i) i))
encode'-decode' (suc n) =
trElim (λ _ → isOfHLevelTruncPath {n = 4 + n})
λ x → cong (encode' (suc n) (0ₖ (3 + n))) (cong-∙ ∣_∣ₕ (merid x) (sym (merid north)))
∙∙ substComposite (λ x → CODE (suc n) x .fst)
(cong ∣_∣ₕ (merid x)) (sym (cong ∣_∣ₕ (merid ptEM-raw))) (0ₖ (2 + n))
∙∙ cong (subst (λ x₁ → CODE (suc n) x₁ .fst) (λ i → ∣ merid ptEM-raw (~ i) ∣ₕ))
(λ i → lUnitₖ (2 + n) (transportRefl ∣ x ∣ₕ i) i)
∙ (λ i → rUnitₖ (2 + n) (transportRefl ∣ x ∣ₕ i) i)
Iso-EM-ΩEM+1 : (n : ℕ) → Iso (EM G n) (typ (Ω (EM∙ G (suc n))))
Iso-EM-ΩEM+1 zero = invIso (ΩEM₁Iso (AbGroup→Group G))
Iso.fun (Iso-EM-ΩEM+1 (suc zero)) = decode' 0 (0ₖ 2)
Iso.inv (Iso-EM-ΩEM+1 (suc zero)) = encode' 0 (0ₖ 2)
Iso.rightInv (Iso-EM-ΩEM+1 (suc zero)) = decode'-encode' 0 (0ₖ 2)
Iso.leftInv (Iso-EM-ΩEM+1 (suc zero)) = encode'-decode' 0
Iso.fun (Iso-EM-ΩEM+1 (suc (suc n))) = decode' (suc n) (0ₖ (3 + n))
Iso.inv (Iso-EM-ΩEM+1 (suc (suc n))) = encode' (suc n) (0ₖ (3 + n))
Iso.rightInv (Iso-EM-ΩEM+1 (suc (suc n))) = decode'-encode' (suc n) (0ₖ (3 + n))
Iso.leftInv (Iso-EM-ΩEM+1 (suc (suc n))) = encode'-decode' (suc n)
EM≃ΩEM+1 : (n : ℕ) → EM G n ≃ typ (Ω (EM∙ G (suc n)))
EM≃ΩEM+1 n = isoToEquiv (Iso-EM-ΩEM+1 n)
-- Some properties of the isomorphism
EM→ΩEM+1 : (n : ℕ) → EM G n → typ (Ω (EM∙ G (suc n)))
EM→ΩEM+1 n = Iso.fun (Iso-EM-ΩEM+1 n)
ΩEM+1→EM : (n : ℕ) → typ (Ω (EM∙ G (suc n))) → EM G n
ΩEM+1→EM n = Iso.inv (Iso-EM-ΩEM+1 n)
EM→ΩEM+1-0ₖ : (n : ℕ) → EM→ΩEM+1 n (0ₖ n) ≡ refl
EM→ΩEM+1-0ₖ zero = emloop-1g _
EM→ΩEM+1-0ₖ (suc zero) = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
EM→ΩEM+1-0ₖ (suc (suc n)) = cong (cong ∣_∣ₕ) (rCancel (merid ptEM-raw))
EM→ΩEM+1-hom : (n : ℕ) (x y : EM G n)
→ EM→ΩEM+1 n (x +[ n ]ₖ y) ≡ EM→ΩEM+1 n x ∙ EM→ΩEM+1 n y
EM→ΩEM+1-hom zero x y = emloop-comp _ x y
EM→ΩEM+1-hom (suc zero) x y = σ-EM'-hom zero x y
EM→ΩEM+1-hom (suc (suc n)) x y = σ-EM'-hom (suc n) x y
ΩEM+1→EM-hom : (n : ℕ) → (p q : typ (Ω (EM∙ G (suc n))))
→ ΩEM+1→EM n (p ∙ q) ≡ (ΩEM+1→EM n p) +[ n ]ₖ (ΩEM+1→EM n q)
ΩEM+1→EM-hom n =
morphLemmas.isMorphInv (λ x y → x +[ n ]ₖ y) (_∙_) (EM→ΩEM+1 n)
(EM→ΩEM+1-hom n) (ΩEM+1→EM n)
(Iso.rightInv (Iso-EM-ΩEM+1 n)) (Iso.leftInv (Iso-EM-ΩEM+1 n))
ΩEM+1→EM-refl : (n : ℕ) → ΩEM+1→EM n refl ≡ 0ₖ n
ΩEM+1→EM-refl zero = transportRefl 0g
ΩEM+1→EM-refl (suc zero) = refl
ΩEM+1→EM-refl (suc (suc n)) = refl
EM→ΩEM+1∙ : (n : ℕ) → EM∙ G n →∙ Ω (EM∙ G (suc n))
EM→ΩEM+1∙ n .fst = EM→ΩEM+1 n
EM→ΩEM+1∙ zero .snd = emloop-1g (AbGroup→Group G)
EM→ΩEM+1∙ (suc zero) .snd = cong (cong ∣_∣ₕ) (rCancel (merid embase))
EM→ΩEM+1∙ (suc (suc n)) .snd = cong (cong ∣_∣ₕ) (rCancel (merid north))
EM≃ΩEM+1∙ : (n : ℕ) → EM∙ G n ≡ Ω (EM∙ G (suc n))
EM≃ΩEM+1∙ n = ua∙ (EM≃ΩEM+1 n) (EM→ΩEM+1-0ₖ n)
isHomogeneousEM : (n : ℕ) → isHomogeneous (EM∙ G n)
isHomogeneousEM n x =
ua∙ (isoToEquiv (addIso n x)) (lUnitₖ n x)
-- Some HLevel lemmas about function spaces (EM∙ G n →∙ EM∙ H m), mainly used for
-- the cup product
module _ where
open AbGroupStr renaming (_+_ to comp)
isContr-↓∙ : {G : AbGroup ℓ} {H : AbGroup ℓ'} (n : ℕ) → isContr (EM∙ G (suc n) →∙ EM∙ H n)
fst (isContr-↓∙ {G = G} {H = H} zero) = (λ _ → 0g (snd H)) , refl
snd (isContr-↓∙{G = G} {H = H} zero) (f , p) =
Σ≡Prop (λ x → is-set (snd H) _ _)
(funExt (raw-elim G 0 (λ _ → is-set (snd H) _ _) (sym p)))
fst (isContr-↓∙ {G = G} {H = H} (suc n)) = (λ _ → 0ₖ (suc n)) , refl
fst (snd (isContr-↓∙ {G = G} {H = H} (suc n)) f i) x =
trElim {B = λ x → 0ₖ (suc n) ≡ fst f x}
(λ _ → isOfHLevelPath (4 + n) (isOfHLevelSuc (3 + n) (hLevelEM H (suc n))) _ _)
(raw-elim _ _ (λ _ → hLevelEM H (suc n) _ _) (sym (snd f)))
x i
snd (snd (isContr-↓∙ (suc n)) f i) j = snd f (~ i ∨ j)
isContr-↓∙' : {G : AbGroup ℓ} {H : AbGroup ℓ'} (n : ℕ)
→ isContr ((EM-raw G (suc n) , ptEM-raw) →∙ EM∙ H n)
isContr-↓∙' zero = isContr-↓∙ zero
fst (isContr-↓∙' (suc n)) = (λ _ → 0ₖ (suc n)) , refl
fst (snd (isContr-↓∙' {H = H} (suc n)) f i) x =
raw-elim _ _ {A = λ x → 0ₖ (suc n) ≡ fst f x}
(λ _ → hLevelEM H (suc n) _ _) (sym (snd f)) x i
snd (snd (isContr-↓∙' (suc n)) f i) j = snd f (~ i ∨ j)
isOfHLevel→∙EM : ∀ {ℓ} {A : Pointed ℓ} {G : AbGroup ℓ'} (n m : ℕ)
→ isOfHLevel (suc m) (A →∙ EM∙ G n)
→ isOfHLevel (suc (suc m)) (A →∙ EM∙ G (suc n))
isOfHLevel→∙EM {A = A} {G = G} n m hlev = step₃
where
step₁ : isOfHLevel (suc m) (A →∙ Ω (EM∙ G (suc n)))
step₁ =
subst (isOfHLevel (suc m))
(λ i → A →∙ ua∙ {A = Ω (EM∙ G (suc n))} {B = EM∙ G n}
(invEquiv (EM≃ΩEM+1 n))
(ΩEM+1→EM-refl n) (~ i)) hlev
step₂ : isOfHLevel (suc m) (typ (Ω (A →∙ EM∙ G (suc n) ∙)))
step₂ = isOfHLevelRetractFromIso (suc m) (invIso (invIso (ΩfunExtIso _ _))) step₁
step₃ : isOfHLevel (suc (suc m)) (A →∙ EM∙ G (suc n))
step₃ = isOfHLevelΩ→isOfHLevel m
λ f → subst (λ x → isOfHLevel (suc m) (typ (Ω x)))
(isHomogeneous→∙ (isHomogeneousEM (suc n)) f)
step₂
isOfHLevel↑∙ : {G : AbGroup ℓ} {H : AbGroup ℓ'}
→ ∀ n m → isOfHLevel (2 + n) (EM∙ G (suc m) →∙ EM∙ H (suc (n + m)))
isOfHLevel↑∙ zero m = isOfHLevel→∙EM m 0 (isContr→isProp (isContr-↓∙ m))
isOfHLevel↑∙ (suc n) m = isOfHLevel→∙EM (suc (n + m)) (suc n) (isOfHLevel↑∙ n m)
isOfHLevel↑∙' : {G : AbGroup ℓ} {H : AbGroup ℓ'}
→ ∀ n m → isOfHLevel (2 + n) (EM-raw∙ G (suc m) →∙ EM∙ H (suc (n + m)))
isOfHLevel↑∙' zero m = isOfHLevel→∙EM m 0 (isContr→isProp (isContr-↓∙' m))
isOfHLevel↑∙' (suc n) m = isOfHLevel→∙EM (suc (n + m)) (suc n) (isOfHLevel↑∙' n m)
→∙EMPath : ∀ {ℓ} {G : AbGroup ℓ} (A : Pointed ℓ') (n : ℕ)
→ Ω (A →∙ EM∙ G (suc n) ∙) ≡ (A →∙ EM∙ G n ∙)
→∙EMPath {G = G} A n =
ua∙ (isoToEquiv (ΩfunExtIso A (EM∙ G (suc n)))) refl
∙ (λ i → (A →∙ EM≃ΩEM+1∙ {G = G} n (~ i) ∙))
private
contr∙-lem : {G : AbGroup ℓ} {H : AbGroup ℓ'} {L : AbGroup ℓ''} (n m : ℕ)
→ isContr (EM∙ G (suc n) →∙ (EM∙ H (suc m) →∙ EM∙ L (suc (n + m)) ∙))
fst (contr∙-lem n m) = (λ _ → (λ _ → 0ₖ _) , refl), refl
snd (contr∙-lem {G = G} {H = H} {L = L} n m) (f , p) =
→∙Homogeneous≡ (isHomogeneous→∙ (isHomogeneousEM _))
(sym (funExt (help n f p)))
where
help : (n : ℕ) → (f : EM G (suc n) → EM∙ H (suc m) →∙ EM∙ L (suc (n + m)))
→ f (snd (EM∙ G (suc n))) ≡ snd (EM∙ H (suc m) →∙ EM∙ L (suc (n + m)) ∙)
→ (x : _) → (f x) ≡ ((λ _ → 0ₖ _) , refl)
help zero f p =
raw-elim G zero
(λ _ → isOfHLevel↑∙ zero m _ _) p
help (suc n) f p =
trElim (λ _ → isOfHLevelPath (4 + n)
(subst (λ x → isOfHLevel x (EM∙ H (suc m) →∙ EM∙ L (suc ((suc n) + m))))
(λ i → suc (suc (+-comm (suc n) 1 i)))
(isOfHLevelPlus' {n = 1} (3 + n) (isOfHLevel↑∙ (suc n) m))) _ _)
(raw-elim G (suc n)
(λ _ → isOfHLevel↑∙ (suc n) m _ _) p)
isOfHLevel↑∙∙ : {G : AbGroup ℓ} {H : AbGroup ℓ'} {L : AbGroup ℓ''}
→ ∀ n m l → isOfHLevel (2 + l) (EM∙ G (suc n)
→∙ (EM∙ H (suc m)
→∙ EM∙ L (suc (suc (l + n + m))) ∙))
isOfHLevel↑∙∙ {G = G} {H = H} {L = L} n m zero =
isOfHLevelΩ→isOfHLevel 0 λ f
→ subst
isProp (cong (λ x → typ (Ω x))
(isHomogeneous→∙ (isHomogeneous→∙ (isHomogeneousEM _)) f))
(isOfHLevelRetractFromIso 1 (ΩfunExtIso _ _) h)
where
h : isProp (EM∙ G (suc n)
→∙ (Ω (EM∙ H (suc m)
→∙ EM∙ L (suc (suc (n + m))) ∙)))
h =
subst isProp
(λ i → EM∙ G (suc n)
→∙ (→∙EMPath {G = L} (EM∙ H (suc m)) (suc (n + m)) (~ i)))
(isContr→isProp (contr∙-lem n m))
isOfHLevel↑∙∙ {G = G} {H = H} {L = L} n m (suc l) =
isOfHLevelΩ→isOfHLevel (suc l)
λ f →
subst (isOfHLevel (2 + l))
(cong (λ x → typ (Ω x))
(isHomogeneous→∙ (isHomogeneous→∙ (isHomogeneousEM _)) f))
(isOfHLevelRetractFromIso (2 + l) (ΩfunExtIso _ _) h)
where
h : isOfHLevel (2 + l)
(EM∙ G (suc n)
→∙ (Ω (EM∙ H (suc m)
→∙ EM∙ L (suc (suc (suc (l + n + m)))) ∙)))
h =
subst (isOfHLevel (2 + l))
(λ i → EM∙ G (suc n)
→∙ →∙EMPath {G = L} (EM∙ H (suc m)) (suc (suc (l + n + m))) (~ i))
(isOfHLevel↑∙∙ n m l)
-- A homomorphism φ : G → H of AbGroups induces a homomorphism
-- φ' : K(G,n) → K(H,n)
inducedFun-EM-raw : {G' : AbGroup ℓ} {H' : AbGroup ℓ'}
→ AbGroupHom G' H'
→ ∀ n
→ EM-raw G' n → EM-raw H' n
inducedFun-EM-raw f =
elim+2 (fst f)
(EMrec _ emsquash embase
(λ g → emloop (fst f g))
λ g h → compPathR→PathP (sym
(sym (lUnit _)
∙∙ cong (_∙ (sym (emloop (fst f h))))
(cong emloop (IsGroupHom.pres· (snd f) g h)
∙ emloop-comp _ (fst f g) (fst f h))
∙∙ sym (∙assoc _ _ _)
∙∙ cong (emloop (fst f g) ∙_) (rCancel _)
∙∙ sym (rUnit _))))
(λ n ind → λ { north → north
; south → south
; (merid a i) → merid (ind a) i} )
inducedFun-EM-rawIso : {G' : AbGroup ℓ} {H' : AbGroup ℓ'}
→ AbGroupEquiv G' H'
→ ∀ n → Iso (EM-raw G' n) (EM-raw H' n)
Iso.fun (inducedFun-EM-rawIso e n) = inducedFun-EM-raw (_ , (snd e)) n
Iso.inv (inducedFun-EM-rawIso e n) = inducedFun-EM-raw (_ , isGroupHomInv e) n
Iso.rightInv (inducedFun-EM-rawIso e n) = h n
where
h : (n : ℕ) → section (inducedFun-EM-raw (fst e .fst , snd e) n)
(inducedFun-EM-raw (invEq (fst e) , isGroupHomInv e) n)
h = elim+2
(secEq (fst e))
(elimSet _ (λ _ → emsquash _ _) refl
(λ g → compPathR→PathP
((sym (cong₂ _∙_ (cong emloop (secEq (fst e) g)) (sym (lUnit _))
∙ rCancel _)))))
λ n p → λ { north → refl
; south → refl
; (merid a i) k → merid (p a k) i}
Iso.leftInv (inducedFun-EM-rawIso e n) = h n
where
h : (n : ℕ) → retract (Iso.fun (inducedFun-EM-rawIso e n))
(Iso.inv (inducedFun-EM-rawIso e n))
h = elim+2
(retEq (fst e))
(elimSet _ (λ _ → emsquash _ _) refl
(λ g → compPathR→PathP
((sym (cong₂ _∙_ (cong emloop (retEq (fst e) g)) (sym (lUnit _))
∙ rCancel _)))))
λ n p → λ { north → refl
; south → refl
; (merid a i) k → merid (p a k) i}
Iso→EMIso : {G : AbGroup ℓ} {H : AbGroup ℓ'}
→ AbGroupEquiv G H → ∀ n → Iso (EM G n) (EM H n)
Iso→EMIso is zero = inducedFun-EM-rawIso is zero
Iso→EMIso is (suc zero) = inducedFun-EM-rawIso is 1
Iso→EMIso is (suc (suc n)) = mapCompIso (inducedFun-EM-rawIso is (suc (suc n)))
EM⊗-commIso : {G : AbGroup ℓ} {H : AbGroup ℓ'}
→ ∀ n → Iso (EM (G ⨂ H) n) (EM (H ⨂ G) n)
EM⊗-commIso {G = G} {H = H} = Iso→EMIso (GroupIso→GroupEquiv ⨂-commIso)
EM⊗-assocIso : {G : AbGroup ℓ} {H : AbGroup ℓ'} {L : AbGroup ℓ''}
→ ∀ n → Iso (EM (G ⨂ (H ⨂ L)) n) (EM ((G ⨂ H) ⨂ L) n)
EM⊗-assocIso = Iso→EMIso (GroupIso→GroupEquiv (GroupEquiv→GroupIso ⨂assoc))
|
{
"alphanum_fraction": 0.5015569587,
"avg_line_length": 42.8185185185,
"ext": "agda",
"hexsha": "bdaf181663420eb381663995bab9ea7f0c7b7d34",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/Properties.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10008,
"size": 23122
}
|
------------------------------------------------------------------------
-- Representation-independent results for non-dependent lenses
------------------------------------------------------------------------
import Equality.Path as P
module Lens.Non-dependent
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as Bij using (module _↔_)
open import Equality.Decision-procedures equality-with-J
open import Equivalence equality-with-J using (_≃_)
open import Erased.Cubical eq
open import Function-universe equality-with-J as F hiding (_∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as T using (∥_∥)
open import Surjection equality-with-J using (_↠_)
private
variable
a b c c₁ c₂ c₃ l : Level
A B : Type a
Lens₁ Lens₂ Lens₃ : Type a → Type b → Type c
------------------------------------------------------------------------
-- Some existence results
-- There is, in general, no lens for the first projection from a
-- Σ-type, assuming that lenses with contractible domains have
-- contractible codomains.
no-first-projection-lens :
(Lens : Type → Type → Type a) →
@0 (∀ {A B} → Lens A B → Contractible A → Contractible B) →
¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool
no-first-projection-lens _ contractible-to-contractible l =
_↔_.to Erased-⊥↔⊥
[ $⟨ singleton-contractible _ ⟩
Contractible (Singleton true) ↝⟨ contractible-to-contractible l ⟩
Contractible Bool ↝⟨ mono₁ 0 ⟩
Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□
⊥ □
]
-- A variant of the previous result: If A is merely inhabited, and one
-- can "project" out a boolean from a value of type A, but this
-- boolean is necessarily true, then there is no lens corresponding to
-- this projection (if the get-set law holds).
no-singleton-projection-lens :
{Lens : Type l}
(get : Lens → A → Bool)
(set : Lens → A → Bool → A)
(get-set : ∀ l a b → get l (set l a b) ≡ b) →
∥ A ∥ →
(bool : A → Bool) →
(∀ x → bool x ≡ true) →
¬ ∃ λ (l : Lens) →
∀ x → get l x ≡ bool x
no-singleton-projection-lens
get set get-set x bool is-true (l , get≡bool) =
_↔_.to Erased-⊥↔⊥
[ (flip (T.rec ⊥-propositional) x λ x →
Bool.true≢false
(true ≡⟨ sym $ is-true _ ⟩
bool (set l x false) ≡⟨ sym $ get≡bool _ ⟩
get l (set l x false) ≡⟨ get-set _ _ _ ⟩∎
false ∎))
]
------------------------------------------------------------------------
-- Statements of preservation results, and some related lemmas
-- Lens-like things with getters and setters.
record Has-getter-and-setter
(Lens : Type a → Type b → Type c) :
Type (lsuc (a ⊔ b ⊔ c)) where
field
-- Getter.
get : {A : Type a} {B : Type b} → Lens A B → A → B
-- Typeter.
set : {A : Type a} {B : Type b} → Lens A B → A → B → A
-- A statement of what it means for two lenses to have the same getter
-- and setter.
Same-getter-and-setter :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
{A : Type a} {B : Type b} →
Lens₁ A B → Lens₂ A B → Type (a ⊔ b)
Same-getter-and-setter ⦃ L₁ = L₁ ⦄ ⦃ L₂ = L₂ ⦄ l₁ l₂ =
get L₁ l₁ ≡ get L₂ l₂ ×
set L₁ l₁ ≡ set L₂ l₂
where
open Has-getter-and-setter
-- A statement of what it means for a function to preserve getters and
-- setters for all inputs.
Preserves-getters-and-setters-→ :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
(A : Type a) (B : Type b) →
(Lens₁ A B → Lens₂ A B) →
Type (a ⊔ b ⊔ c₁)
Preserves-getters-and-setters-→ {Lens₁ = Lens₁} A B f =
(l : Lens₁ A B) → Same-getter-and-setter (f l) l
-- A statement of what it means for a logical equivalence to preserve
-- getters and setters.
Preserves-getters-and-setters-⇔ :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
(A : Type a) (B : Type b) →
(Lens₁ A B ⇔ Lens₂ A B) →
Type (a ⊔ b ⊔ c₁ ⊔ c₂)
Preserves-getters-and-setters-⇔ A B eq =
Preserves-getters-and-setters-→ A B (_⇔_.to eq) ×
Preserves-getters-and-setters-→ A B (_⇔_.from eq)
-- Composition preserves Preserves-getters-and-setters-→.
Preserves-getters-and-setters-→-∘ :
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
⦃ L₃ : Has-getter-and-setter Lens₃ ⦄
{f : Lens₂ A B → Lens₃ A B}
{g : Lens₁ A B → Lens₂ A B} →
Preserves-getters-and-setters-→ A B f →
Preserves-getters-and-setters-→ A B g →
Preserves-getters-and-setters-→ A B (f ∘ g)
Preserves-getters-and-setters-→-∘ p-f p-g _ =
trans (proj₁ (p-f _)) (proj₁ (p-g _))
, trans (proj₂ (p-f _)) (proj₂ (p-g _))
-- Composition preserves Preserves-getters-and-setters-⇔.
Preserves-getters-and-setters-⇔-∘ :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
{Lens₃ : Type a → Type b → Type c₃}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
⦃ L₃ : Has-getter-and-setter Lens₃ ⦄
{f : Lens₂ A B ⇔ Lens₃ A B}
{g : Lens₁ A B ⇔ Lens₂ A B} →
Preserves-getters-and-setters-⇔ A B f →
Preserves-getters-and-setters-⇔ A B g →
Preserves-getters-and-setters-⇔ A B (f F.∘ g)
Preserves-getters-and-setters-⇔-∘ p-f p-g =
Preserves-getters-and-setters-→-∘ (proj₁ p-f) (proj₁ p-g)
, Preserves-getters-and-setters-→-∘ (proj₂ p-g) (proj₂ p-f)
-- The function inverse preserves Preserves-getters-and-setters-⇔.
Preserves-getters-and-setters-⇔-inverse :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
{f : Lens₁ A B ⇔ Lens₂ A B} →
Preserves-getters-and-setters-⇔ A B f →
Preserves-getters-and-setters-⇔ A B (inverse f)
Preserves-getters-and-setters-⇔-inverse = swap
-- If the forward direction of a split surjection preserves getters
-- and setters, then both directions do.
Preserves-getters-and-setters-→-↠-⇔ :
{Lens₁ : Type a → Type b → Type c₁}
{Lens₂ : Type a → Type b → Type c₂}
⦃ L₁ : Has-getter-and-setter Lens₁ ⦄
⦃ L₂ : Has-getter-and-setter Lens₂ ⦄
(f : Lens₁ A B ↠ Lens₂ A B) →
Preserves-getters-and-setters-→ A B (_↠_.to f) →
Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence f)
Preserves-getters-and-setters-→-↠-⇔ ⦃ L₁ = L₁ ⦄ ⦃ L₂ = L₂ ⦄ f p =
p
, λ l →
(get L₁ (_↠_.from f l) ≡⟨ sym $ proj₁ $ p (_↠_.from f l) ⟩
get L₂ (_↠_.to f (_↠_.from f l)) ≡⟨ cong (get L₂) $ _↠_.right-inverse-of f _ ⟩∎
get L₂ l ∎)
, (set L₁ (_↠_.from f l) ≡⟨ sym $ proj₂ $ p (_↠_.from f l) ⟩
set L₂ (_↠_.to f (_↠_.from f l)) ≡⟨ cong (set L₂) $ _↠_.right-inverse-of f _ ⟩∎
set L₂ l ∎)
where
open Has-getter-and-setter
|
{
"alphanum_fraction": 0.5858668858,
"avg_line_length": 35.7941176471,
"ext": "agda",
"hexsha": "00d5a56a3bc6a335b883ec9aef68bd97f01ffe78",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent.agda",
"max_line_length": 89,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 2581,
"size": 7302
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Concrete.System
open import LibraBFT.Impl.Consensus.Types
import LibraBFT.Concrete.Properties.VotesOnce as VO
import LibraBFT.Concrete.Properties.PreferredRound as PR
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK (λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk})
-- This module collects in one place the obligations an
-- implementation must meet in order to enjoy the properties
-- proved in Abstract.Properties.
module LibraBFT.Concrete.Obligations where
record ImplObligations : Set (ℓ+1 ℓ-RoundManager) where
field
-- Structural obligations:
sps-cor : StepPeerState-AllValidParts
-- Semantic obligations:
--
-- VotesOnce:
vo₁ : VO.ImplObligation₁
vo₂ : VO.ImplObligation₂
-- PreferredRound:
pr₁ : PR.ImplObligation₁
|
{
"alphanum_fraction": 0.7437395659,
"avg_line_length": 35.2352941176,
"ext": "agda",
"hexsha": "7b2653e7c035342d5dbd1dfdbd015a70cdeb9188",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_line_length": 146,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 332,
"size": 1198
}
|
-- Andreas, 2018-05-11, issue #3051
-- Allow pattern synonyms in mutual blocks
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
id : ∀ {a} {A : Set a} → A → A
id x = x
_∘′_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(B → C) → (A → B) → (A → C)
f ∘′ g = λ x → f (g x)
_×̇_ : ∀{A C : Set} {B : A → Set} {D : C → Set}
(f : A → C) (g : ∀{a} → B a → D (f a)) → Σ A B → Σ C D
(f ×̇ g) (x , y) = f x , g y
mutual
data Cxt : Set₁ where
_▷_ : (Γ : Cxt) (A : C⦅ Γ ⦆ → Set) → Cxt
C⦅_⦆ : Cxt → Set
C⦅ Γ ▷ A ⦆ = Σ C⦅ Γ ⦆ A
mutual
data _≤_ : (Δ Γ : Cxt) → Set₁ where
id≤ : ∀{Γ} → Γ ≤ Γ
weak : ∀{Γ Δ A} (τ : Δ ≤ Γ) → (Δ ▷ A) ≤ Γ
lift' : ∀{Γ Δ A A'} (τ : Δ ≤ Γ) (p : A' ≡ (A ∘′ τ⦅ τ ⦆)) → (Δ ▷ A') ≤ (Γ ▷ A)
pattern lift τ = lift' τ refl
τ⦅_⦆ : ∀{Γ Δ} (τ : Δ ≤ Γ) → C⦅ Δ ⦆ → C⦅ Γ ⦆
τ⦅ id≤ ⦆ = id
τ⦅ weak τ ⦆ = τ⦅ τ ⦆ ∘′ fst
τ⦅ lift τ ⦆ = τ⦅ τ ⦆ ×̇ id
-- Should pass.
|
{
"alphanum_fraction": 0.4126473741,
"avg_line_length": 23.9230769231,
"ext": "agda",
"hexsha": "247f90893de7f1fd57b5324bd55036db94866c9f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3051.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3051.agda",
"max_line_length": 81,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3051.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 532,
"size": 933
}
|
{-# OPTIONS --without-K #-}
module Everything where
open import AC
open import Equivalence
open import Fiber
open import Functoriality
open import FunExt
open import GroupoidStructure
open import HIT.Interval
open import Homotopy
open import J
open import K
open import NTypes
open import NTypes.Contractible
open import NTypes.Coproduct
open import NTypes.Empty
open import NTypes.HedbergsTheorem
open import NTypes.Id
open import NTypes.Nat
open import NTypes.Negation
open import NTypes.Product
open import NTypes.Sigma
open import NTypes.Unit
open import NTypes.Universe
open import PathOperations
open import PathStructure.Coproduct
open import PathStructure.Empty
open import PathStructure.Id.Ap
open import PathStructure.Id.Tr
open import PathStructure.Nat
open import PathStructure.Product
open import PathStructure.Sigma
open import PathStructure.Unit
open import PathStructure.UnitNoEta
open import Sigma
open import Transport
open import Types
open import Univalence
|
{
"alphanum_fraction": 0.848825332,
"avg_line_length": 24.475,
"ext": "agda",
"hexsha": "f0c2bd8c32638be38ef79705175a75074f472cfe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/Everything.agda",
"max_line_length": 35,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 227,
"size": 979
}
|
-- Jesper, 2019-07-27. Cut down this example from a latent bug in
-- @antiUnify@, which was using @unAbs@ instead of @absBody@.
{-# OPTIONS --double-check #-}
open import Agda.Primitive
postulate
I : Set
T : ∀ {p} → Set (lsuc p) → Set (lsuc p)
t : ∀ {p} → (B : Set (lsuc p)) → (I → I → Set) → B → T B
x0 : I
R0 : I → I → Set
P0 : ∀ p → R0 x0 x0 → Set p
d0 : R0 x0 x0
C : ∀ {p} (X : Set) (x : (T (X → Set p))) → Set
f : ∀ {p} (R : I → I → Set) (P : R x0 x0 → Set p)
→ {{_ : C (R x0 x0) (t (R x0 x0 → Set p) R P)}}
→ (d : R x0 x0) → P d
instance
iDP : ∀ {p} → C (R0 x0 x0) (t (R0 x0 x0 → Set p) R0 (P0 p))
fails : ∀ p → P0 p d0
fails p = f _ (P0 p) d0
|
{
"alphanum_fraction": 0.4826086957,
"avg_line_length": 23.7931034483,
"ext": "agda",
"hexsha": "1ade97167ba6feca9f5fa9d8ccc7bb5c6df8c255",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/AntiUnifyBug.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/AntiUnifyBug.agda",
"max_line_length": 65,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/AntiUnifyBug.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 323,
"size": 690
}
|
module UnknownNameInFixityDecl where
infix 40 _+_
infixr 60 _*_
|
{
"alphanum_fraction": 0.7910447761,
"avg_line_length": 9.5714285714,
"ext": "agda",
"hexsha": "398be791f0e705877464bf352e83caf8fc168743",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/UnknownNameInFixityDecl.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/UnknownNameInFixityDecl.agda",
"max_line_length": 36,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/UnknownNameInFixityDecl.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 25,
"size": 67
}
|
open import Nat
open import Prelude
open import List
open import contexts
open import core
open import lemmas-env
module lemmas-progress where
typ-inhabitance-pres : ∀{Δ Σ' Γ E e τ} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
Σ[ r ∈ result ] (Δ , Σ' ⊢ r ·: τ)
typ-inhabitance-pres Γ⊢E ta@(TAFix e-ta) = _ , (TAFix Γ⊢E ta)
typ-inhabitance-pres Γ⊢E (TAVar x∈Γ)
with env-all-Γ Γ⊢E x∈Γ
... | _ , x∈E , r-ta = _ , r-ta
typ-inhabitance-pres Γ⊢E (TAApp _ f-ta arg-ta)
with typ-inhabitance-pres Γ⊢E f-ta | typ-inhabitance-pres Γ⊢E arg-ta
... | _ , rf-ta | _ , rarg-ta = _ , TAApp rf-ta rarg-ta
typ-inhabitance-pres Γ⊢E TAUnit = _ , TAUnit
typ-inhabitance-pres Γ⊢E (TAPair _ ta1 ta2)
with typ-inhabitance-pres Γ⊢E ta1 | typ-inhabitance-pres Γ⊢E ta2
... | _ , r-ta1 | _ , r-ta2 = _ , TAPair r-ta1 r-ta2
typ-inhabitance-pres Γ⊢E (TAFst ta)
with typ-inhabitance-pres Γ⊢E ta
... | _ , r-ta = _ , TAFst r-ta
typ-inhabitance-pres Γ⊢E (TASnd ta)
with typ-inhabitance-pres Γ⊢E ta
... | _ , r-ta = _ , TASnd r-ta
typ-inhabitance-pres Γ⊢E (TACtor d∈Σ' c∈d e-ta)
with typ-inhabitance-pres Γ⊢E e-ta
... | _ , r-ta = _ , TACtor d∈Σ' c∈d r-ta
typ-inhabitance-pres Γ⊢E (TACase d∈Σ' e-ta h1 h2)
with typ-inhabitance-pres Γ⊢E e-ta
... | _ , r-ta = _ , TACase d∈Σ' Γ⊢E r-ta h1 λ form →
let _ , _ , _ , h5 , h6 = h2 form in
_ , h5 , h6
typ-inhabitance-pres Γ⊢E (TAHole u∈Δ) = _ , TAHole u∈Δ Γ⊢E
typ-inhabitance-pres Γ⊢E (TAAsrt _ e-ta1 e-ta2) = _ , TAUnit
|
{
"alphanum_fraction": 0.5628853268,
"avg_line_length": 37.7209302326,
"ext": "agda",
"hexsha": "7ee71d63b6168465b2d9cf6b4116b3025b40abf9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "lemmas-progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnat-myth-",
"max_issues_repo_path": "lemmas-progress.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "lemmas-progress.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 720,
"size": 1622
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Crypto.Crypto.Hash as Hash
import LibraBFT.Impl.OBM.Crypto as Crypto
import LibraBFT.Impl.Types.OnChainConfig.ValidatorSet as ValidatorSet
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.Prelude
module LibraBFT.Impl.Types.BlockInfo where
gENESIS_EPOCH : Epoch
gENESIS_EPOCH = {-Epoch-} 0
gENESIS_ROUND : Round
gENESIS_ROUND = {-Round-} 0
gENESIS_VERSION : Version
gENESIS_VERSION = Version∙new 0 0
empty : BlockInfo
empty = BlockInfo∙new
gENESIS_EPOCH
gENESIS_ROUND
Hash.valueZero
Hash.valueZero
gENESIS_VERSION
nothing
genesis : HashValue → ValidatorSet → Either ErrLog BlockInfo
genesis genesisStateRootHash validatorSet = do
vv ← ValidatorVerifier.from-e-abs validatorSet
pure $ BlockInfo∙new
gENESIS_EPOCH
gENESIS_ROUND
Hash.valueZero
genesisStateRootHash
gENESIS_VERSION
--gENESIS_TIMESTAMP_USECS
(just (EpochState∙new {-Epoch-} 1 vv))
mockGenesis : Maybe ValidatorSet → Either ErrLog BlockInfo
mockGenesis
= genesis
(Crypto.obmHashVersion gENESIS_VERSION) -- OBM-LBFT-DIFF : Crypto.aCCUMULATOR_PLACEHOLDER_HASH
∘ fromMaybe ValidatorSet.empty
hasReconfiguration : BlockInfo → Bool
hasReconfiguration = is-just ∘ (_^∙ biNextEpochState)
|
{
"alphanum_fraction": 0.7573221757,
"avg_line_length": 29.875,
"ext": "agda",
"hexsha": "8f81e7f4d91c09a7a4cd1a42d8af02ad5bb13b25",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Types/BlockInfo.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Types/BlockInfo.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Types/BlockInfo.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 473,
"size": 1673
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
-- TODO-2: The following import should be eliminated and replaced
-- with the necessary module parameters (PK and MetaHonestPK)
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig
-- This module brings in the base types used through libra
-- and those necessary for the abstract model.
module LibraBFT.Abstract.Types
(UID : Set)
(NodeId : Set)
(𝓔 : EpochConfig UID NodeId)
where
open EpochConfig 𝓔
-- A member of an epoch is considered "honest" iff its public key is honest.
Meta-Honest-Member : EpochConfig.Member 𝓔 → Set
Meta-Honest-Member α = Meta-Honest-PK (getPubKey α)
-- Naturally, if two witnesses that two authors belong
-- in the epoch are the same, then the authors are also the same.
--
-- This proof is very Galois-like, because of the way we structured
-- our partial isos. It's actually pretty nice! :)
member≡⇒author≡ : ∀{α β}
→ (authorα : Is-just (isMember? α))
→ (authorβ : Is-just (isMember? β))
→ to-witness authorα ≡ to-witness authorβ
→ α ≡ β
member≡⇒author≡ {α} {β} a b prf
with isMember? α | inspect isMember? α
...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ a)
member≡⇒author≡ {α} {β} (just _) b prf
| just ra | [ RA ]
with isMember? β | inspect isMember? β
...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ b)
member≡⇒author≡ {α} {β} (just _) (just _) prf
| just ra | [ RA ]
| just rb | [ RB ]
= trans (sym (author-nodeid-id RA))
(trans (cong toNodeId prf)
(author-nodeid-id RB))
|
{
"alphanum_fraction": 0.6474226804,
"avg_line_length": 38.8,
"ext": "agda",
"hexsha": "ec3a18f0fe33bd2d573b7e5fee97c38818ebc3ba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Abstract/Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Abstract/Types.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Abstract/Types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 591,
"size": 1940
}
|
import Categories.2-Category
import Categories.2-Functor
import Categories.Adjoint
import Categories.Adjoint.Construction.EilenbergMoore
import Categories.Adjoint.Construction.Kleisli
import Categories.Adjoint.Equivalence
import Categories.Adjoint.Instance.0-Truncation
import Categories.Adjoint.Instance.01-Truncation
import Categories.Adjoint.Instance.Core
import Categories.Adjoint.Instance.Discrete
import Categories.Adjoint.Instance.PosetCore
import Categories.Adjoint.Instance.StrictCore
import Categories.Adjoint.Mate
import Categories.Adjoint.Properties
import Categories.Adjoint.RAPL
import Categories.Bicategory
import Categories.Bicategory.Bigroupoid
import Categories.Bicategory.Construction.1-Category
import Categories.Bicategory.Instance.Cats
import Categories.Bicategory.Instance.EnrichedCats
import Categories.Category
import Categories.Category.BicartesianClosed
import Categories.Category.Cartesian
import Categories.Category.Cartesian.Properties
import Categories.Category.CartesianClosed
import Categories.Category.CartesianClosed.Canonical
import Categories.Category.CartesianClosed.Locally
import Categories.Category.CartesianClosed.Locally.Properties
import Categories.Category.Closed
import Categories.Category.Cocartesian
import Categories.Category.Cocomplete
import Categories.Category.Cocomplete.Finitely
import Categories.Category.Complete
import Categories.Category.Complete.Finitely
import Categories.Category.Construction.0-Groupoid
import Categories.Category.Construction.Arrow
import Categories.Category.Construction.Cocones
import Categories.Category.Construction.Comma
import Categories.Category.Construction.Cones
import Categories.Category.Construction.Coproduct
import Categories.Category.Construction.Core
import Categories.Category.Construction.EilenbergMoore
import Categories.Category.Construction.Elements
import Categories.Category.Construction.EnrichedFunctors
import Categories.Category.Construction.F-Algebras
import Categories.Category.Construction.Fin
import Categories.Category.Construction.Functors
import Categories.Category.Construction.Graphs
import Categories.Category.Construction.Grothendieck
import Categories.Category.Construction.Kleisli
import Categories.Category.Construction.Path
import Categories.Category.Construction.Presheaves
import Categories.Category.Construction.Properties.Comma
import Categories.Category.Construction.Pullbacks
import Categories.Category.Construction.Thin
import Categories.Category.Core
import Categories.Category.Discrete
import Categories.Category.Equivalence
import Categories.Category.Finite
import Categories.Category.Groupoid
import Categories.Category.Groupoid.Properties
import Categories.Category.Indiscrete
import Categories.Category.Instance.Cats
import Categories.Category.Instance.EmptySet
import Categories.Category.Instance.FamilyOfSets
import Categories.Category.Instance.Globe
import Categories.Category.Instance.Groupoids
import Categories.Category.Instance.One
import Categories.Category.Instance.PointedSets
import Categories.Category.Instance.Posets
import Categories.Category.Instance.Properties.Cats
import Categories.Category.Instance.Properties.Posets
import Categories.Category.Instance.Properties.Setoids
import Categories.Category.Instance.Setoids
import Categories.Category.Instance.Sets
import Categories.Category.Instance.Simplex
import Categories.Category.Instance.SimplicialSet
import Categories.Category.Instance.SingletonSet
import Categories.Category.Instance.Span
import Categories.Category.Instance.StrictCats
import Categories.Category.Instance.StrictGroupoids
import Categories.Category.Instance.Zero
import Categories.Category.Monoidal
import Categories.Category.Monoidal.Braided
import Categories.Category.Monoidal.Braided.Properties
import Categories.Category.Monoidal.Closed
import Categories.Category.Monoidal.Closed.IsClosed
import Categories.Category.Monoidal.Closed.IsClosed.Diagonal
import Categories.Category.Monoidal.Closed.IsClosed.Dinatural
import Categories.Category.Monoidal.Closed.IsClosed.Identity
import Categories.Category.Monoidal.Closed.IsClosed.L
import Categories.Category.Monoidal.Closed.IsClosed.Pentagon
import Categories.Category.Monoidal.Construction.Minus2
import Categories.Category.Monoidal.Core
import Categories.Category.Monoidal.Instance.Cats
import Categories.Category.Monoidal.Instance.One
import Categories.Category.Monoidal.Instance.Setoids
import Categories.Category.Monoidal.Instance.Sets
import Categories.Category.Monoidal.Instance.StrictCats
import Categories.Category.Monoidal.Properties
import Categories.Category.Monoidal.Reasoning
import Categories.Category.Monoidal.Symmetric
import Categories.Category.Monoidal.Traced
import Categories.Category.Monoidal.Utilities
import Categories.Category.Product
import Categories.Category.Product.Properties
import Categories.Category.RigCategory
import Categories.Category.SetoidDiscrete
import Categories.Category.Site
import Categories.Category.Slice
import Categories.Category.Slice.Properties
import Categories.Category.SubCategory
import Categories.Category.Topos
import Categories.Category.WithFamilies
import Categories.Comonad
import Categories.Diagram.Cocone
import Categories.Diagram.Cocone.Properties
import Categories.Diagram.Coend
import Categories.Diagram.Coequalizer
import Categories.Diagram.Coequalizer.Properties
import Categories.Diagram.Colimit
import Categories.Diagram.Colimit.DualProperties
import Categories.Diagram.Colimit.Lan
import Categories.Diagram.Colimit.Properties
import Categories.Diagram.Cone
import Categories.Diagram.Cone.Properties
import Categories.Diagram.Duality
import Categories.Diagram.End
import Categories.Diagram.End.Properties
import Categories.Diagram.Equalizer
import Categories.Diagram.Finite
import Categories.Diagram.Limit
import Categories.Diagram.Limit.Properties
import Categories.Diagram.Limit.Ran
import Categories.Diagram.Pullback
import Categories.Diagram.Pullback.Limit
import Categories.Diagram.Pullback.Properties
import Categories.Diagram.Pushout
import Categories.Diagram.Pushout.Properties
import Categories.Diagram.SubobjectClassifier
import Categories.Enriched.Category
import Categories.Enriched.Functor
import Categories.Enriched.NaturalTransformation
import Categories.Enriched.NaturalTransformation.NaturalIsomorphism
import Categories.Enriched.Over.One
import Categories.Functor
import Categories.Functor.Algebra
import Categories.Functor.Bifunctor
import Categories.Functor.Bifunctor.Properties
import Categories.Functor.Coalgebra
import Categories.Functor.Cocontinuous
import Categories.Functor.Construction.Constant
import Categories.Functor.Construction.Diagonal
import Categories.Functor.Construction.LiftSetoids
import Categories.Functor.Construction.Limit
import Categories.Functor.Construction.Zero
import Categories.Functor.Continuous
import Categories.Functor.Core
import Categories.Functor.Equivalence
import Categories.Functor.Fibration
import Categories.Functor.Groupoid
import Categories.Functor.Hom
import Categories.Functor.Instance.0-Truncation
import Categories.Functor.Instance.01-Truncation
import Categories.Functor.Instance.Core
import Categories.Functor.Instance.Discrete
import Categories.Functor.Instance.SetoidDiscrete
import Categories.Functor.Instance.StrictCore
import Categories.Functor.Monoidal
import Categories.Functor.Power
import Categories.Functor.Power.Functorial
import Categories.Functor.Power.NaturalTransformation
import Categories.Functor.Presheaf
import Categories.Functor.Profunctor
import Categories.Functor.Properties
import Categories.Functor.Representable
import Categories.Functor.Slice
import Categories.GlobularSet
import Categories.Kan
import Categories.Kan.Duality
import Categories.Minus2-Category
import Categories.Minus2-Category.Construction.Indiscrete
import Categories.Minus2-Category.Instance.One
import Categories.Minus2-Category.Properties
import Categories.Monad
import Categories.Monad.Duality
import Categories.Monad.Idempotent
import Categories.Monad.Strong
import Categories.Morphism
import Categories.Morphism.Cartesian
import Categories.Morphism.Duality
import Categories.Morphism.HeterogeneousIdentity
import Categories.Morphism.HeterogeneousIdentity.Properties
import Categories.Morphism.IsoEquiv
import Categories.Morphism.Isomorphism
import Categories.Morphism.Properties
import Categories.Morphism.Reasoning
import Categories.Morphism.Reasoning.Core
import Categories.Morphism.Reasoning.Iso
import Categories.Morphism.Universal
import Categories.NaturalTransformation
import Categories.NaturalTransformation.Core
import Categories.NaturalTransformation.Dinatural
import Categories.NaturalTransformation.Equivalence
import Categories.NaturalTransformation.Hom
import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence
import Categories.NaturalTransformation.NaturalIsomorphism.Functors
import Categories.NaturalTransformation.NaturalIsomorphism.Properties
import Categories.NaturalTransformation.Properties
import Categories.Object.Coproduct
import Categories.Object.Duality
import Categories.Object.Exponential
import Categories.Object.Initial
import Categories.Object.Product
import Categories.Object.Product.Construction
import Categories.Object.Product.Core
import Categories.Object.Product.Morphisms
import Categories.Object.Terminal
import Categories.Object.Zero
import Categories.Pseudofunctor
import Categories.Pseudofunctor.Instance.EnrichedUnderlying
import Categories.Utils.EqReasoning
import Categories.Utils.Product
import Categories.Yoneda
import Categories.Yoneda.Properties
import Relation.Binary.Construct.Symmetrize
|
{
"alphanum_fraction": 0.8912211767,
"avg_line_length": 42.4166666667,
"ext": "agda",
"hexsha": "2f30f271df46533d1b5574e1c6bf8ac088408770",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1850,
"size": 9671
}
|
module Membership where
open import Data.Sum
open import Data.List
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.List.Any as Any
open Any.Membership-≡
-- _∈_
∈-++-pos : ∀ {A : Set} {x : A} xs ys → x ∈ xs ++ ys
→ (x ∈ xs) ⊎ (x ∈ ys)
∈-++-pos [] ys x∈ = inj₂ x∈
∈-++-pos (x ∷ xs) ys (here refl) = inj₁ (here refl)
∈-++-pos (x ∷ xs) ys (there x∈) with ∈-++-pos xs ys x∈
... | inj₁ x∈xs = inj₁ (there x∈xs)
... | inj₂ x∈ys = inj₂ x∈ys
∈-++-r : ∀ {A : Set} {x : A} xs {ys}
→ x ∈ ys → x ∈ (xs ++ ys)
∈-++-r [] x∈ = x∈
∈-++-r (y ∷ xs) x∈ = there (∈-++-r xs x∈)
∈-++-l : ∀ {A : Set} {x : A} {xs} ys
→ x ∈ xs → x ∈ (xs ++ ys)
∈-++-l ys (here refl) = here refl
∈-++-l ys (there x∈) = there (∈-++-l ys x∈)
∈-++-weaken : ∀ {A : Set} {x : A} xs ys zs
→ x ∈ (xs ++ zs) → x ∈ (xs ++ ys ++ zs)
∈-++-weaken [] ys zs x∈ = ∈-++-r ys x∈
∈-++-weaken (x ∷ xs) ys zs (here refl) = here refl
∈-++-weaken (_ ∷ xs) ys zs (there x∈) = there (∈-++-weaken xs ys zs x∈)
-- _∉_
∉-++-l : ∀ {A : Set} {x : A} xs ys → x ∉ xs ++ ys → x ∉ xs
∉-++-l ._ ys x∉xs++ys (here eq) = x∉xs++ys (here eq)
∉-++-l .(x' ∷ xs) ys x∉xs++ys (there {x'} {xs} pxs) =
∉-++-l xs ys (λ p → x∉xs++ys (there p)) pxs
∉-++-r : ∀ {A : Set} {x : A} xs ys → x ∉ xs ++ ys → x ∉ ys
∉-++-r [] ys x∉xs++ys x∈ys = x∉xs++ys x∈ys
∉-++-r (x' ∷ xs) ys x∉xs++ys x∈ys = ∉-++-r xs ys (λ p → x∉xs++ys (there p)) x∈ys
postulate
∉-∷ : ∀ {A : Set} {y x : A} {xs}
→ ¬ (y ≡ x) → y ∉ xs → y ∉ (x ∷ xs)
∉-++-join : ∀ {A : Set} {x : A}
→ ∀ xs ys → x ∉ xs → x ∉ ys → x ∉ xs ++ ys
∉-++-join [] ys x∉xs x∉ys x∈ys = x∉ys x∈ys
∉-++-join (_ ∷ xs) ys x∉xs x∉ys (here refl) = x∉xs (here refl)
∉-++-join (_ ∷ xs) ys x∉xxs x∉ys (there pxs) = ∉-++-join xs ys (λ x∉xs → x∉xxs (there x∉xs)) x∉ys pxs
∉-++-weaken : ∀ {A : Set} {x : A} xs ys zs
→ x ∉ (xs ++ ys ++ zs) → x ∉ (xs ++ zs)
∉-++-weaken xs ys zs x∉xyz x∈xz = x∉xyz (∈-++-weaken xs ys zs x∈xz)
∉-∷-hd : ∀ {A : Set} {x y : A} xs → x ∉ (y ∷ xs) → ¬ (x ≡ y)
∉-∷-hd {x} {._} xs x∉ refl = x∉ (here refl)
∉-∷-tl : ∀ {A : Set} {x y : A} xs → x ∉ (y ∷ xs) → x ∉ xs
∉-∷-tl {x} {y} xs x∉ x∈ = x∉ (there x∈)
|
{
"alphanum_fraction": 0.4338768116,
"avg_line_length": 32.9552238806,
"ext": "agda",
"hexsha": "ca9c959e679dc6a96a0a6b990dd18c359a489311",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z",
"max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ajnavarro/language-dataset",
"max_forks_repo_path": "data/github.com/scmu/foundations-harper/63f170677b07f78ce19cee228e98fc9abbdb19e7/08.LNumStr->/Membership.agda",
"max_issues_count": 91,
"max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ajnavarro/language-dataset",
"max_issues_repo_path": "data/github.com/scmu/foundations-harper/63f170677b07f78ce19cee228e98fc9abbdb19e7/08.LNumStr->/Membership.agda",
"max_line_length": 101,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ajnavarro/language-dataset",
"max_stars_repo_path": "data/github.com/scmu/foundations-harper/63f170677b07f78ce19cee228e98fc9abbdb19e7/08.LNumStr->/Membership.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z",
"num_tokens": 1149,
"size": 2208
}
|
{-# OPTIONS --without-K #-}
module hott.loop where
open import hott.loop.core public
open import hott.loop.properties public
open import hott.loop.level public
open import hott.loop.sum public
|
{
"alphanum_fraction": 0.7835051546,
"avg_line_length": 24.25,
"ext": "agda",
"hexsha": "28a52cd64f0dc56e45111f1a907bd58442e4b80e",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/loop.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/loop.agda",
"max_line_length": 39,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/hott/loop.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 39,
"size": 194
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.DiffInt.Base where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.SetQuotients.Base
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
rel : (ℕ × ℕ) → (ℕ × ℕ) → Type₀
rel (a₀ , b₀) (a₁ , b₁) = x ≡ y
where
x = a₀ + b₁
y = a₁ + b₀
ℤ = (ℕ × ℕ) / rel
open import Cubical.Data.Nat.Literals public
instance
fromNatDiffInt : HasFromNat ℤ
fromNatDiffInt = record { Constraint = λ _ → Unit ; fromNat = λ n → [ n , 0 ] }
instance
fromNegDiffInt : HasFromNeg ℤ
fromNegDiffInt = record { Constraint = λ _ → Unit ; fromNeg = λ n → [ 0 , n ] }
|
{
"alphanum_fraction": 0.6574923547,
"avg_line_length": 23.3571428571,
"ext": "agda",
"hexsha": "a09f28bf24274dc3a3e3360e37746058d97fee64",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/cubical",
"max_forks_repo_path": "Cubical/Data/DiffInt/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/cubical",
"max_issues_repo_path": "Cubical/Data/DiffInt/Base.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/cubical",
"max_stars_repo_path": "Cubical/Data/DiffInt/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 230,
"size": 654
}
|
module Structure.Category.Functor.Contravariant where
open import Logic.Predicate
import Lvl
open import Structure.Category.Functor
open import Structure.Category.Dual
open import Structure.Category
open import Structure.Setoid
open import Type
private variable ℓ ℓₒ ℓₘ ℓₗₒ ℓₗₘ ℓᵣₒ ℓᵣₘ ℓₑ ℓₗₑ ℓᵣₑ : Lvl.Level
private variable Obj Objₗ Objᵣ : Type{ℓ}
private variable Morphism Morphismₗ Morphismᵣ : Objₗ → Objᵣ → Type{ℓ}
module _
⦃ morphism-equivₗ : ∀{x y : Objₗ} → Equiv{ℓₗₑ}(Morphismₗ x y) ⦄
⦃ morphism-equivᵣ : ∀{x y : Objᵣ} → Equiv{ℓᵣₑ}(Morphismᵣ x y) ⦄
(Categoryₗ : Category(Morphismₗ))
(Categoryᵣ : Category(Morphismᵣ))
where
ContravariantFunctor : (Objₗ → Objᵣ) → Type
ContravariantFunctor = Functor (dualCategory Categoryₗ) Categoryᵣ
module ContravariantFunctor = Functor{Categoryₗ = dualCategory Categoryₗ}{Categoryᵣ = Categoryᵣ}
module _
⦃ morphism-equiv : ∀{x y : Obj} → Equiv{ℓₑ}(Morphism x y) ⦄
(Category : Category(Morphism))
where
ContravariantEndofunctor = ContravariantFunctor(Category)(Category)
module ContravariantEndofunctor = ContravariantFunctor(Category)(Category)
_→ᶜᵒⁿᵗʳᵃᵛᵃʳⁱᵃⁿᵗᶠᵘⁿᶜᵗᵒʳ_ : CategoryObject{ℓₗₒ}{ℓₗₘ}{ℓₗₑ} → CategoryObject{ℓᵣₒ}{ℓᵣₘ}{ℓᵣₑ} → Type
catₗ →ᶜᵒⁿᵗʳᵃᵛᵃʳⁱᵃⁿᵗᶠᵘⁿᶜᵗᵒʳ catᵣ = ∃(ContravariantFunctor (CategoryObject.category(catₗ)) ((CategoryObject.category(catᵣ))))
⟲ᶜᵒⁿᵗʳᵃᵛᵃʳⁱᵃⁿᵗᶠᵘⁿᶜᵗᵒʳ_ : CategoryObject{ℓₒ}{ℓₘ}{ℓₑ} → Type
⟲ᶜᵒⁿᵗʳᵃᵛᵃʳⁱᵃⁿᵗᶠᵘⁿᶜᵗᵒʳ cat = cat →ᶜᵒⁿᵗʳᵃᵛᵃʳⁱᵃⁿᵗᶠᵘⁿᶜᵗᵒʳ cat
module _ (C₁ C₂ : CategoryObject{ℓₒ}{ℓₘ}{ℓₑ}) where
open import Logic.Propositional
open import Structure.Relator.Equivalence
open CategoryObject ⦃ … ⦄
open Category ⦃ … ⦄
open ArrowNotation
open Functor ⦃ … ⦄
private open module MorphismEquiv₁ {x}{y} = Equivalence (Equiv-equivalence ⦃ morphism-equiv ⦃ C₁ ⦄ {x}{y} ⦄) using ()
private open module MorphismEquiv₂ {x}{y} = Equivalence (Equiv-equivalence ⦃ morphism-equiv ⦃ C₂ ⦄ {x}{y} ⦄) using ()
instance _ = C₁
instance _ = C₂
contravariant-functor-def-dual : (dual(C₁) →ᶠᵘⁿᶜᵗᵒʳ C₂) ↔ (C₁ →ᶠᵘⁿᶜᵗᵒʳ dual(C₂))
contravariant-functor-def-dual = [↔]-intro l r where
l : (dual(C₁) →ᶠᵘⁿᶜᵗᵒʳ C₂) ← (C₁ →ᶠᵘⁿᶜᵗᵒʳ dual(C₂))
∃.witness (l ([∃]-intro F)) = F
Functor.map (∃.proof (l _)) = map
Functor.map-function (∃.proof (l _)) = map-function
Functor.op-preserving (∃.proof (l _)) = op-preserving
Functor.id-preserving (∃.proof (l _)) = id-preserving
r : (dual(C₁) →ᶠᵘⁿᶜᵗᵒʳ C₂) → (C₁ →ᶠᵘⁿᶜᵗᵒʳ dual(C₂))
∃.witness (r ([∃]-intro F)) = F
Functor.map (∃.proof (r _)) = map
Functor.map-function (∃.proof (r _)) = map-function
Functor.op-preserving (∃.proof (r _)) = op-preserving
Functor.id-preserving (∃.proof (r _)) = id-preserving
|
{
"alphanum_fraction": 0.7019406811,
"avg_line_length": 39.0142857143,
"ext": "agda",
"hexsha": "c00c5ff13553050462245849baf0496ccff5cae7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Category/Functor/Contravariant.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Category/Functor/Contravariant.agda",
"max_line_length": 123,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Category/Functor/Contravariant.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1392,
"size": 2731
}
|
{-# OPTIONS --rewriting --allow-unsolved-metas #-}
postulate _↦_ : Set → Set → Set
{-# BUILTIN REWRITE _↦_ #-}
postulate
X : Set
P : Set → Set → Set
P-rewr : (A : Set) → (P A A ↦ X)
{-# REWRITE P-rewr #-}
f : (B : Set → Set) {x y : Set} → P (B x) (B y)
f = {!!}
|
{
"alphanum_fraction": 0.5018315018,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "ecbd29e52abbf57f99248172fa4903dbc7054d02",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3774.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3774.agda",
"max_line_length": 50,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3774.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 112,
"size": 273
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sublist-related properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Sublist.Propositional.Properties {a} {A : Set a} where
open import Data.List using (map)
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Relation.Unary.Any.Properties using (here-injective; there-injective)
open import Data.List.Relation.Binary.Sublist.Propositional
hiding (map)
import Data.List.Relation.Binary.Sublist.Setoid.Properties
as SetoidProperties
open import Function
open import Relation.Binary.PropositionalEquality as P hiding ([_])
open import Relation.Unary as U using (Pred)
------------------------------------------------------------------------
-- Re-exporting setoid properties
open SetoidProperties (P.setoid A) public
hiding (map⁺)
------------------------------------------------------------------------
-- map
module _ {b} {B : Set b} where
map⁺ : ∀ {as bs} (f : A → B) → as ⊆ bs → map f as ⊆ map f bs
map⁺ f = SetoidProperties.map⁺ (setoid A) (setoid B) (cong f)
------------------------------------------------------------------------
-- The `lookup` function induced by a proof that `xs ⊆ ys` is injective
module _ {p} {P : Pred A p} where
lookup-injective : ∀ {xs ys} {p : xs ⊆ ys} {v w : Any P xs} →
lookup p v ≡ lookup p w → v ≡ w
lookup-injective {p = []} {}
lookup-injective {p = _ ∷ʳ _} {v} {w} =
lookup-injective ∘′ there-injective
lookup-injective {p = x≡y ∷ _} {here pv} {here pw} =
cong here ∘′ subst-injective x≡y ∘′ here-injective
lookup-injective {p = _ ∷ _} {there v} {there w} =
cong there ∘′ lookup-injective ∘′ there-injective
lookup-injective {p = _ ∷ _} {here _} {there _} ()
lookup-injective {p = _ ∷ _} {there _} {here _} ()
|
{
"alphanum_fraction": 0.5349070819,
"avg_line_length": 38.2884615385,
"ext": "agda",
"hexsha": "9916d43b6c0f92e468076f3ec59063f7c8226ce9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional/Properties.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 520,
"size": 1991
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function using (_∘_; _$_; flip; id)
open import Cubical.Foundations.Logic hiding (_⇒_; _⇔_) renaming (⇔toPath to hProp⇔toPath)
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Binary.Definitions
open import Cubical.Relation.Nullary.Decidable hiding (¬_)
open import Cubical.Data.Maybe using (just; nothing; Dec→Maybe; map-Maybe)
open import Cubical.Data.Sum.Base as Sum using (inl; inr)
open import Cubical.Data.Empty using (⊥; isProp⊥) renaming (elim to ⊥-elim)
open import Cubical.HITs.PropositionalTruncation
private
variable
a b ℓ ℓ₁ ℓ₂ ℓ₃ p : Level
A : Type a
B : Type b
------------------------------------------------------------------------
-- Equality properties
≡ₚReflexive : Reflexive (_≡ₚ_ {A = A})
≡ₚReflexive = ∣ refl ∣
≡ₚSymmetric : Symmetric (_≡ₚ_ {A = A})
≡ₚSymmetric = map sym
≡ₚTransitive : Transitive (_≡ₚ_ {A = A})
≡ₚTransitive = map2 _∙_
≡ₚSubstitutive : Substitutive (_≡ₚ_ {A = A}) ℓ
≡ₚSubstitutive P = elim (λ _ → isPropΠ λ _ → P _ .snd) (subst (λ x → P x .fst))
------------------------------------------------------------------------
-- Substitutive properties
module _ (_∼_ : Rel A ℓ₁) (P : Rel A p) where
subst→respˡ : Substitutive _∼_ p → P Respectsˡ _∼_
subst→respˡ subst {y} x′∼x Px′y = subst (flip P y) x′∼x Px′y
subst→respʳ : Substitutive _∼_ p → P Respectsʳ _∼_
subst→respʳ subst {x} y′∼y Pxy′ = subst (P x) y′∼y Pxy′
subst→resp₂ : Substitutive _∼_ p → P Respects₂ _∼_
subst→resp₂ subst = subst→respʳ subst , subst→respˡ subst
module _ (_∼_ : Rel A ℓ) (P : A → hProp p) where
P-resp→¬P-resp : Symmetric _∼_ → P Respects _∼_ → (¬_ ∘ P) Respects _∼_
P-resp→¬P-resp sym resp x∼y ¬Px Py = ¬Px (resp (sym x∼y) Py)
Respectsʳ≡ₚ : (_∼_ : Rel A ℓ) → _∼_ Respectsʳ _≡ₚ_
Respectsʳ≡ₚ _∼_ = subst→respʳ _≡ₚ_ _∼_ ≡ₚSubstitutive
Respectsˡ≡ₚ : (_∼_ : Rel A ℓ) → _∼_ Respectsˡ _≡ₚ_
Respectsˡ≡ₚ _∼_ = subst→respˡ _≡ₚ_ _∼_ ≡ₚSubstitutive
Respects₂≡ₚ : (_∼_ : Rel A ℓ) → _∼_ Respects₂ _≡ₚ_
Respects₂≡ₚ _∼_ = subst→resp₂ _≡ₚ_ _∼_ ≡ₚSubstitutive
------------------------------------------------------------------------
-- Proofs for non-strict orders
module _ (_≤_ : Rel A ℓ) where
rawtotal→FromEq : RawTotal _≤_ → FromEq _≤_
rawtotal→FromEq total {x} {y} x≡y with total x y
... | inl x∼y = x∼y
... | inr y∼x = Respectsʳ≡ₚ _≤_ x≡y (Respectsˡ≡ₚ _≤_ (≡ₚSymmetric x≡y) y∼x)
total→FromEq : Total _≤_ → FromEq _≤_
total→FromEq total {x} {y} x≡y = elim (λ _ → (x ≤ y) .snd)
(λ {
(inl x∼y) → x∼y
; (inr y∼x) → Respectsʳ≡ₚ _≤_ x≡y (Respectsˡ≡ₚ _≤_ (≡ₚSymmetric x≡y) y∼x)
}) (total x y)
------------------------------------------------------------------------
-- Proofs for strict orders
module _ (_<_ : Rel A ℓ) where
trans∧irr→asym : Transitive _<_ → Irreflexive _<_ → Asymmetric _<_
trans∧irr→asym transitive irrefl x<y y<x = irrefl (transitive x<y y<x)
irr∧antisym→asym : Irreflexive _<_ → Antisymmetric _<_ → Asymmetric _<_
irr∧antisym→asym irrefl antisym x<y y<x = irrefl→tonoteq irrefl x<y (antisym x<y y<x)
where
irrefl→tonoteq : Irreflexive _<_ → ToNotEq _<_
irrefl→tonoteq irrefl {x} {y} x<y x≡y = irrefl (substₚ (λ z → x < z) (≡ₚSymmetric x≡y) x<y)
asym→antisym : Asymmetric _<_ → Antisymmetric _<_
asym→antisym asym x<y y<x = ⊥-elim (asym x<y y<x)
asym→irr : Asymmetric _<_ → Irreflexive _<_
asym→irr asym {x} x<x = asym x<x x<x
tri→asym : Trichotomous _<_ → Asymmetric _<_
tri→asym compare {x} {y} x<y x>y with compare x y
... | tri< _ _ x≯y = x≯y x>y
... | tri≡ _ _ x≯y = x≯y x>y
... | tri> x≮y _ _ = x≮y x<y
tri→irr : Trichotomous _<_ → Irreflexive _<_
tri→irr compare {x} x<x with compare x x
... | tri< _ _ x≮x = x≮x x<x
... | tri≡ _ _ x≮x = x≮x x<x
... | tri> x≮x _ _ = x≮x x<x
tri→dec≡ : Trichotomous _<_ → Discrete A
tri→dec≡ compare x y with compare x y
... | tri< _ x≢y _ = no x≢y
... | tri≡ _ x≡y _ = yes x≡y
... | tri> _ x≢y _ = no x≢y
tri→dec< : Trichotomous _<_ → Decidable _<_
tri→dec< compare x y with compare x y
... | tri< x<y _ _ = yes x<y
... | tri≡ x≮y _ _ = no x≮y
... | tri> x≮y _ _ = no x≮y
------------------------------------------------------------------------
-- Without Loss of Generality
module _ {R : Rel A ℓ₁} {Q : Rel A ℓ₂} where
wlog : Total R → Symmetric Q →
R ⇒ Q → Universal Q
wlog r-total q-sym prf a b = elim (λ _ → Q a b .snd)
(λ {
(inl Rab) → prf Rab
; (inr Rba) → q-sym (prf Rba)
}) (r-total a b)
------------------------------------------------------------------------
-- Other proofs
module _ {P : REL A B p} where
dec→weaklyDec : Decidable P → WeaklyDecidable P
dec→weaklyDec dec x y = Dec→Maybe (dec x y)
module _ {P : Rel A ℓ₁} {Q : Rel A ℓ₂} (f : P ⇒ Q) where
map-Reflexive : Reflexive P → Reflexive Q
map-Reflexive reflx = f reflx
map-FromEq : FromEq P → FromEq Q
map-FromEq fromEq p = f (fromEq p)
cmap-Irreflexive : Irreflexive Q → Irreflexive P
cmap-Irreflexive irrefl x≡x = irrefl (f x≡x)
cmap-ToNotEq : ToNotEq Q → ToNotEq P
cmap-ToNotEq toNotEq x = toNotEq (f x)
module _ {P : REL A B ℓ₁} {Q : REL A B ℓ₂} (f : P ⇒ Q) where
map-Universal : Universal P → Universal Q
map-Universal u x y = f (u x y)
map-NonEmpty : NonEmpty P → NonEmpty Q
map-NonEmpty = map (λ (x , p) → x , map (λ (y , q) → y , f q) p)
module _ {P : REL A B ℓ₁} {Q : REL B A ℓ₂} where
flip-RawConnex : RawConnex P Q → RawConnex Q P
flip-RawConnex f x y = Sum.swap (f y x)
flip-Connex : Connex P Q → Connex Q P
flip-Connex f x y = map Sum.swap (f y x)
module _ (_∼_ : Rel A ℓ) where
reflx→fromeq : Reflexive _∼_ → FromEq _∼_
reflx→fromeq reflx {x} p = substₚ (x ∼_) p reflx
fromeq→reflx : FromEq _∼_ → Reflexive _∼_
fromeq→reflx fromEq = fromEq ∣ refl ∣
irrefl→tonoteq : Irreflexive _∼_ → ToNotEq _∼_
irrefl→tonoteq irrefl {x} {y} x<y x≡y = irrefl (substₚ (x ∼_) (≡ₚSymmetric x≡y) x<y)
tonoteq→irrefl : ToNotEq _∼_ → Irreflexive _∼_
tonoteq→irrefl toNotEq x<x = toNotEq x<x ∣ refl ∣
------------------------------------------------------------------------
-- Proofs for propositional relations only
isPropIsPropValued : {R : RawREL A B ℓ} → isProp (isPropValued R)
isPropIsPropValued a b i x y = isPropIsProp (a x y) (b x y) i
module _ (R : Rel A ℓ) where
isPropReflexive : isProp (Reflexive R)
isPropReflexive a b i {x} = R x x .snd a b i
isPropFromEq : isProp (FromEq R)
isPropFromEq a b i {x} {y} p = R x y .snd (a p) (b p) i
isPropIrreflexive : isProp (Irreflexive R)
isPropIrreflexive a b i {x} xRx = isProp⊥ (a xRx) (b xRx) i
isPropToNotEq : isProp (ToNotEq R)
isPropToNotEq a b i {x} {y} xRy x≡y = isProp⊥ (a xRy x≡y) (b xRy x≡y) i
isPropAsymmetric : isProp (Asymmetric R)
isPropAsymmetric a b i {x} {y} xRy yRx = isProp⊥ (a xRy yRx) (b xRy yRx) i
isProp⇒ : (R : REL A B ℓ₁) (Q : REL A B ℓ₂) → isProp (R ⇒ Q)
isProp⇒ R Q a b i {x} {y} xRy = Q x y .snd (a xRy) (b xRy) i
isPropSym : (R : REL A B ℓ₁) (Q : REL B A ℓ₂) → isProp (Sym R Q)
isPropSym R Q = isProp⇒ R (flip Q)
isPropTrans : ∀ {c} {C : Type c}
(P : REL A B ℓ₁) (Q : REL B C ℓ₂) (R : REL A C ℓ₃) →
isProp (Trans P Q R)
isPropTrans P Q R a b i {x} {_} {z} xPy yQz = R x z .snd (a xPy yQz) (b xPy yQz) i
isPropAntisym : (R : REL A B ℓ₁) (Q : REL B A ℓ₂) (E : REL A B ℓ₃) → isProp (Antisym R Q E)
isPropAntisym R Q E a b i {x} {y} xRy yQx = E x y .snd (a xRy yQx) (b xRy yQx) i
module _ (R : REL A B ℓ) where
Universal→isContrValued : Universal R → ∀ {a b} → isContr ⟨ R a b ⟩
Universal→isContrValued univr {a} {b} = univr a b , R a b .snd _
------------------------------------------------------------------------
-- Bidirectional implication and equality
⇔toPath : {R : REL A B ℓ} {Q : REL A B ℓ} → R ⇔ Q → R ≡ Q
⇔toPath (R⇒Q , Q⇒R) = funExt (λ x → funExt (λ y → hProp⇔toPath R⇒Q Q⇒R))
|
{
"alphanum_fraction": 0.5763236022,
"avg_line_length": 32.7287449393,
"ext": "agda",
"hexsha": "856b0149b74f4375c8c06365eb91b7126a1e277c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Properties.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3404,
"size": 8084
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- "Finite" sets indexed on coinductive "natural" numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types --guardedness #-}
module Codata.Musical.Cofin where
open import Codata.Musical.Notation
open import Codata.Musical.Conat as Conat using (Coℕ; suc; ∞ℕ)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Function
------------------------------------------------------------------------
-- The type
-- Note that Cofin ∞ℕ is /not/ finite. Note also that this is not a
-- coinductive type, but it is indexed on a coinductive type.
data Cofin : Coℕ → Set where
zero : ∀ {n} → Cofin (suc n)
suc : ∀ {n} (i : Cofin (♭ n)) → Cofin (suc n)
suc-injective : ∀ {m} {p q : Cofin (♭ m)} → (Cofin (suc m) ∋ suc p) ≡ suc q → p ≡ q
suc-injective refl = refl
------------------------------------------------------------------------
-- Some operations
fromℕ : ℕ → Cofin ∞ℕ
fromℕ zero = zero
fromℕ (suc n) = suc (fromℕ n)
toℕ : ∀ {n} → Cofin n → ℕ
toℕ zero = zero
toℕ (suc i) = suc (toℕ i)
fromFin : ∀ {n} → Fin n → Cofin (Conat.fromℕ n)
fromFin zero = zero
fromFin (suc i) = suc (fromFin i)
toFin : ∀ n → Cofin (Conat.fromℕ n) → Fin n
toFin zero ()
toFin (suc n) zero = zero
toFin (suc n) (suc i) = suc (toFin n i)
import Codata.Cofin as C
fromMusical : ∀ {n} → Cofin n → C.Cofin (Conat.fromMusical n)
fromMusical zero = C.zero
fromMusical (suc n) = C.suc (fromMusical n)
toMusical : ∀ {n} → C.Cofin n → Cofin (Conat.toMusical n)
toMusical C.zero = zero
toMusical (C.suc n) = suc (toMusical n)
|
{
"alphanum_fraction": 0.5475138122,
"avg_line_length": 30.1666666667,
"ext": "agda",
"hexsha": "cb278711777ab9a701ad37e40b1878d9cc836744",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Musical/Cofin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 590,
"size": 1810
}
|
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
module Number.Coercions where
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Data.Unit.Base -- Unit
open import Cubical.Data.Empty -- ⊥
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
open import Number.Postulates
open import Number.Inclusions
open import Number.Base
open import MoreNatProperties
open ℕⁿ
open ℤᶻ
open ℚᶠ
open ℝʳ
open ℂᶜ
open PatternsProp
module Coerce-ℕ↪ℤ where
open ℤ
open IsROrderedCommSemiringInclusion -- ℕ↪ℤinc
private f = ℕ↪ℤ
abstract
coerce-ℕ↪ℤ : ∀{p} → (x : Number (isNat , p)) → PositivityKindInterpretation isInt (coerce-PositivityKind isNat isInt p) (ℕ↪ℤ (num x))
coerce-ℕ↪ℤ {⁇x⁇} (x ,, q) = lift tt
coerce-ℕ↪ℤ {x#0} (x ,, q) = preserves-#0 ℕ↪ℤinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℕ↪ℤ {0≤x} (x ,, q) = preserves-0≤ ℕ↪ℤinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℕ↪ℤ {0<x} (x ,, q) = preserves-0< ℕ↪ℤinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℕ↪ℤ {x≤0} (x ,, q) = preserves-≤0 ℕ↪ℤinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℕ↪ℚ where
open ℚ
open IsROrderedCommSemiringInclusion -- ℕ↪ℚinc
private f = ℕ↪ℚ
abstract
coerce-ℕ↪ℚ : ∀{p} → (x : Number (isNat , p)) → PositivityKindInterpretation isRat (coerce-PositivityKind isNat isRat p) (ℕ↪ℚ (num x))
coerce-ℕ↪ℚ {⁇x⁇} (x ,, q) = lift tt
coerce-ℕ↪ℚ {x#0} (x ,, q) = preserves-#0 ℕ↪ℚinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℕ↪ℚ {0≤x} (x ,, q) = preserves-0≤ ℕ↪ℚinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℕ↪ℚ {0<x} (x ,, q) = preserves-0< ℕ↪ℚinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℕ↪ℚ {x≤0} (x ,, q) = preserves-≤0 ℕ↪ℚinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℕ↪ℝ where
open ℝ
open IsROrderedCommSemiringInclusion -- ℕ↪ℝinc
private f = ℕ↪ℝ
abstract
coerce-ℕ↪ℝ : ∀{p} → (x : Number (isNat , p)) → PositivityKindInterpretation isReal (coerce-PositivityKind isNat isReal p) (ℕ↪ℝ (num x))
coerce-ℕ↪ℝ {⁇x⁇} (x ,, q) = lift tt
coerce-ℕ↪ℝ {x#0} (x ,, q) = preserves-#0 ℕ↪ℝinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℕ↪ℝ {0≤x} (x ,, q) = preserves-0≤ ℕ↪ℝinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℕ↪ℝ {0<x} (x ,, q) = preserves-0< ℕ↪ℝinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℕ↪ℝ {x≤0} (x ,, q) = preserves-≤0 ℕ↪ℝinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℕ↪ℂ where
open ℂ
open Isℕ↪ℂ -- ℕ↪ℂinc
private f = ℕ↪ℂ
abstract
coerce-ℕ↪ℂ : ∀{p} → (x : Number (isNat , p)) → PositivityKindInterpretation isComplex (coerce-PositivityKind isNat isComplex p) (ℕ↪ℂ (num x))
coerce-ℕ↪ℂ {⁇x⁇} (x ,, q) = lift tt
coerce-ℕ↪ℂ {x#0} (x ,, q) = transport (λ i → f x # preserves-0 ℕ↪ℂinc i) (preserves-# ℕ↪ℂinc _ _ q)
coerce-ℕ↪ℂ {0≤x} (x ,, q) = lift tt
coerce-ℕ↪ℂ {0<x} (x ,, q) = transport (λ i → f x # preserves-0 ℕ↪ℂinc i) (preserves-# ℕ↪ℂinc _ _ (ℕ.#-sym _ _ (ℕ.<-implies-# _ _ q)))
coerce-ℕ↪ℂ {x≤0} (x ,, q) = lift tt
module Coerce-ℤ↪ℚ where
open ℚ
open IsROrderedCommRingInclusion -- ℤ↪ℚinc
private f = ℤ↪ℚ
abstract
coerce-ℤ↪ℚ : ∀{p} → (x : Number (isInt , p)) → PositivityKindInterpretation isRat (coerce-PositivityKind isInt isRat p) (ℤ↪ℚ (num x))
coerce-ℤ↪ℚ {⁇x⁇} (x ,, q) = lift tt
coerce-ℤ↪ℚ {x#0} (x ,, q) = preserves-#0 ℤ↪ℚinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℤ↪ℚ {0≤x} (x ,, q) = preserves-0≤ ℤ↪ℚinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℤ↪ℚ {0<x} (x ,, q) = preserves-0< ℤ↪ℚinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℤ↪ℚ {x<0} (x ,, q) = preserves-<0 ℤ↪ℚinc _ q -- transport (λ i → f x < preserves-0 i) (preserves-< _ _ q)
coerce-ℤ↪ℚ {x≤0} (x ,, q) = preserves-≤0 ℤ↪ℚinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℤ↪ℝ where
open ℝ
open IsROrderedCommRingInclusion -- ℤ↪ℝinc
private f = ℤ↪ℝ
abstract
coerce-ℤ↪ℝ : ∀{p} → (x : Number (isInt , p)) → PositivityKindInterpretation isReal (coerce-PositivityKind isInt isReal p) (ℤ↪ℝ (num x))
coerce-ℤ↪ℝ {⁇x⁇} (x ,, q) = lift tt
coerce-ℤ↪ℝ {x#0} (x ,, q) = preserves-#0 ℤ↪ℝinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℤ↪ℝ {0≤x} (x ,, q) = preserves-0≤ ℤ↪ℝinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℤ↪ℝ {0<x} (x ,, q) = preserves-0< ℤ↪ℝinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℤ↪ℝ {x<0} (x ,, q) = preserves-<0 ℤ↪ℝinc _ q -- transport (λ i → f x < preserves-0 i) (preserves-< _ _ q)
coerce-ℤ↪ℝ {x≤0} (x ,, q) = preserves-≤0 ℤ↪ℝinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℤ↪ℂ where
open ℂ
open Isℤ↪ℂ -- ℤ↪ℂinc
private f = ℤ↪ℂ
abstract
coerce-ℤ↪ℂ : ∀{p} → (x : Number (isInt , p)) → PositivityKindInterpretation isComplex (coerce-PositivityKind isInt isComplex p) (ℤ↪ℂ (num x))
coerce-ℤ↪ℂ {⁇x⁇} (x ,, q) = lift tt
coerce-ℤ↪ℂ {x#0} (x ,, q) = transport (λ i → f x # preserves-0 ℤ↪ℂinc i) (preserves-# ℤ↪ℂinc _ _ q)
coerce-ℤ↪ℂ {0≤x} (x ,, q) = lift tt
coerce-ℤ↪ℂ {0<x} (x ,, q) = transport (λ i → f x # preserves-0 ℤ↪ℂinc i) (preserves-# ℤ↪ℂinc _ _ (ℤ.#-sym _ _ (ℤ.<-implies-# _ _ q)))
coerce-ℤ↪ℂ {x<0} (x ,, q) = transport (λ i → f x # preserves-0 ℤ↪ℂinc i) (preserves-# ℤ↪ℂinc _ _ (ℤ.<-implies-# _ _ q) )
coerce-ℤ↪ℂ {x≤0} (x ,, q) = lift tt
module Coerce-ℚ↪ℝ where
open ℝ
open IsROrderedFieldInclusion -- ℚ↪ℝinc
private f = ℚ↪ℝ
abstract
coerce-ℚ↪ℝ : ∀{p} → (x : Number (isRat , p)) → PositivityKindInterpretation isReal (coerce-PositivityKind isRat isReal p) (ℚ↪ℝ (num x))
coerce-ℚ↪ℝ {⁇x⁇} (x ,, q) = lift tt
coerce-ℚ↪ℝ {x#0} (x ,, q) = preserves-#0 ℚ↪ℝinc _ q -- transport (λ i → f x # preserves-0 i) (preserves-# _ _ q)
coerce-ℚ↪ℝ {0≤x} (x ,, q) = preserves-0≤ ℚ↪ℝinc _ q -- transport (λ i → preserves-0 i ≤ f x) (preserves-≤ _ _ q)
coerce-ℚ↪ℝ {0<x} (x ,, q) = preserves-0< ℚ↪ℝinc _ q -- transport (λ i → preserves-0 i < f x) (preserves-< _ _ q)
coerce-ℚ↪ℝ {x<0} (x ,, q) = preserves-<0 ℚ↪ℝinc _ q -- transport (λ i → f x < preserves-0 i) (preserves-< _ _ q)
coerce-ℚ↪ℝ {x≤0} (x ,, q) = preserves-≤0 ℚ↪ℝinc _ q -- transport (λ i → f x ≤ preserves-0 i) (preserves-≤ _ _ q)
module Coerce-ℚ↪ℂ where
open ℂ
open IsRFieldInclusion -- ℚ↪ℂinc
private f = ℚ↪ℂ
abstract
coerce-ℚ↪ℂ : ∀{p} → (x : Number (isRat , p)) → PositivityKindInterpretation isComplex (coerce-PositivityKind isRat isComplex p) (ℚ↪ℂ (num x))
coerce-ℚ↪ℂ {⁇x⁇} (x ,, q) = lift tt
coerce-ℚ↪ℂ {x#0} (x ,, q) = preserves-#0 ℚ↪ℂinc _ q -- transport (λ i → f x # preserves-0 ℚ↪ℂinc i) (preserves-# ℚ↪ℂinc _ _ q)
coerce-ℚ↪ℂ {0≤x} (x ,, q) = lift tt
coerce-ℚ↪ℂ {0<x} (x ,, q) = transport (λ i → f x # preserves-0 ℚ↪ℂinc i) (preserves-# ℚ↪ℂinc _ _ (ℚ.#-sym _ _ (ℚ.<-implies-# _ _ q)))
coerce-ℚ↪ℂ {x<0} (x ,, q) = transport (λ i → f x # preserves-0 ℚ↪ℂinc i) (preserves-# ℚ↪ℂinc _ _ (ℚ.<-implies-# _ _ q) )
coerce-ℚ↪ℂ {x≤0} (x ,, q) = lift tt
module Coerce-ℝ↪ℂ where
-- open ℂ
open IsRFieldInclusion -- ℝ↪ℂinc
private f = ℝ↪ℂ
abstract
coerce-ℝ↪ℂ : ∀{p} → (x : Number (isReal , p)) → PositivityKindInterpretation isComplex (coerce-PositivityKind isReal isComplex p) (ℝ↪ℂ (num x))
coerce-ℝ↪ℂ {⁇x⁇} (x ,, q) = lift tt
coerce-ℝ↪ℂ {x#0} (x ,, q) = preserves-#0 ℝ↪ℂinc _ q -- transport (λ i → f x # preserves-0 ℝ↪ℂinc i) (preserves-# ℝ↪ℂinc _ _ q)
coerce-ℝ↪ℂ {0≤x} (x ,, q) = lift tt
coerce-ℝ↪ℂ {0<x} (x ,, q) = transport (λ i → f x ℂ.# preserves-0 ℝ↪ℂinc i) (preserves-# ℝ↪ℂinc _ _ (ℝ.#-sym _ _ (ℝ.<-implies-# _ _ q)))
coerce-ℝ↪ℂ {x<0} (x ,, q) = transport (λ i → f x ℂ.# preserves-0 ℝ↪ℂinc i) (preserves-# ℝ↪ℂinc _ _ (ℝ.<-implies-# _ _ q) )
coerce-ℝ↪ℂ {x≤0} (x ,, q) = lift tt
-- NOTE: typechecking of this module is very slow
-- the cause might be opening of the ten `IsXInclusion` instances
-- it could be related to https://github.com/agda/agda/issues/1646 (Exponential module chain leads to infeasible scope checking)
-- YES: this is the case. After shifting the module arguments from `open` into the code, checking became instant again
-- does this make anything faster?
open Coerce-ℕ↪ℤ public
open Coerce-ℕ↪ℚ public
open Coerce-ℕ↪ℝ public
open Coerce-ℕ↪ℂ public
open Coerce-ℤ↪ℚ public
open Coerce-ℤ↪ℝ public
open Coerce-ℤ↪ℂ public
open Coerce-ℚ↪ℝ public
open Coerce-ℚ↪ℂ public
open Coerce-ℝ↪ℂ public
coerce : (from : NumberKind)
→ (to : NumberKind)
→ from ≤ₙₗ to
→ ∀{p}
→ Number (from , p)
→ Number (to , coerce-PositivityKind from to p)
coerce isNat isNat q {p} x = x
coerce isInt isInt q {p} x = x
coerce isRat isRat q {p} x = x
coerce isReal isReal q {p} x = x
coerce isComplex isComplex q {p} x = x
coerce isNat isInt q {p} x = (ℕ↪ℤ (num x) ,, coerce-ℕ↪ℤ x)
coerce isNat isRat q {p} x = (ℕ↪ℚ (num x) ,, coerce-ℕ↪ℚ x)
coerce isNat isReal q {p} x = (ℕ↪ℝ (num x) ,, coerce-ℕ↪ℝ x)
coerce isNat isComplex q {p} x = (ℕ↪ℂ (num x) ,, coerce-ℕ↪ℂ x)
coerce isInt isRat q {p} x = (ℤ↪ℚ (num x) ,, coerce-ℤ↪ℚ x)
coerce isInt isReal q {p} x = (ℤ↪ℝ (num x) ,, coerce-ℤ↪ℝ x)
coerce isInt isComplex q {p} x = (ℤ↪ℂ (num x) ,, coerce-ℤ↪ℂ x)
coerce isRat isReal q {p} x = (ℚ↪ℝ (num x) ,, coerce-ℚ↪ℝ x)
coerce isRat isComplex q {p} x = (ℚ↪ℂ (num x) ,, coerce-ℚ↪ℂ x)
coerce isReal isComplex q {p} x = (ℝ↪ℂ (num x) ,, coerce-ℝ↪ℂ x)
--coerce x y = nothing
coerce isInt isNat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isNat , p)} (k+x+sy≢x _ _ _ q)
coerce isRat isNat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isNat , p)} (k+x+sy≢x _ _ _ q)
coerce isRat isInt r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isInt , p)} (k+x+sy≢x _ _ _ q)
coerce isReal isNat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isNat , p)} (k+x+sy≢x _ _ _ q)
coerce isReal isInt r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isInt , p)} (k+x+sy≢x _ _ _ q)
coerce isReal isRat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isRat , p)} (k+x+sy≢x _ _ _ q)
coerce isComplex isNat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isNat , coerce-PositivityKind isComplex isNat p)} (k+x+sy≢x _ _ _ q)
coerce isComplex isInt r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isInt , coerce-PositivityKind isComplex isInt p)} (k+x+sy≢x _ _ _ q)
coerce isComplex isRat r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isRat , coerce-PositivityKind isComplex isRat p)} (k+x+sy≢x _ _ _ q)
coerce isComplex isReal r@(k , q) {p} x = ⊥-elim {A = λ _ → Number (isReal , coerce-PositivityKind isComplex isReal p)} (k+x+sy≢x _ _ _ q)
|
{
"alphanum_fraction": 0.5912078153,
"avg_line_length": 56.3,
"ext": "agda",
"hexsha": "974e07c80bb74ed4a3ea37c3e7454f43bb488075",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Coercions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Coercions.agda",
"max_line_length": 147,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Coercions.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 5246,
"size": 11260
}
|
module Control.Exception where
open import IO
import Control.Exception.Primitive as Prim
bracket : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → IO A → (A → IO B) → (A → IO C) → IO C
bracket io final body = lift (Prim.bracket (run io) (λ a1 → run (final a1)) (λ a2 → run (body a2)))
|
{
"alphanum_fraction": 0.6202090592,
"avg_line_length": 35.875,
"ext": "agda",
"hexsha": "723eede5206a6a4fd1e5a03709e96b62de31596d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c710fde0b0904cb3c02c54142a938d12a4463b0a",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ilya-fiveisky/agda-exceptions",
"max_forks_repo_path": "src/Control/Exception.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c710fde0b0904cb3c02c54142a938d12a4463b0a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ilya-fiveisky/agda-exceptions",
"max_issues_repo_path": "src/Control/Exception.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c710fde0b0904cb3c02c54142a938d12a4463b0a",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ilya-fiveisky/agda-exceptions",
"max_stars_repo_path": "src/Control/Exception.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 102,
"size": 287
}
|
open import Oscar.Prelude
module Oscar.Class.Bind where
module _
(𝔉 : ∀ {𝔣} → Ø 𝔣 → Ø 𝔣)
𝔬₁ 𝔬₂
where
𝓫ind = ∀ {𝔒₁ : Ø 𝔬₁} {𝔒₂ : Ø 𝔬₂} → 𝔉 𝔒₁ → (𝔒₁ → 𝔉 𝔒₂) → 𝔉 𝔒₂
record 𝓑ind : Ø ↑̂ (𝔬₁ ∙̂ 𝔬₂) where
infixl 6 bind
field bind : 𝓫ind
syntax bind m f = f =<< m
open 𝓑ind ⦃ … ⦄ public
|
{
"alphanum_fraction": 0.5424836601,
"avg_line_length": 19.125,
"ext": "agda",
"hexsha": "4dd0098ee2d33ca69e56eb1bce168863ec0c4c17",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Bind.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Bind.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Bind.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 183,
"size": 306
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Concrete.Obligations
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import Util.Prelude
open EpochConfig
open import Yasm.Base
open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
-- In this module, we assume that the implementation meets its
-- obligations, and use this assumption to prove that, in any reachable
-- state, the implementatioon enjoys one of the per-epoch correctness
-- conditions proved in Abstract.Properties. It can be extended to other
-- properties later.
module LibraBFT.Concrete.Properties
(iiah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms)
(st : SystemState)
(r : WithInitAndHandlers.ReachableSystemState iiah st)
(𝓔 : EpochConfig)
(𝓔-∈sys : ParamsWithInitAndHandlers.EpochConfig∈Sys iiah st 𝓔)
(impl-correct : ImplObligations iiah 𝓔)
where
open WithEC
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Abs
open import LibraBFT.Concrete.Intermediate 𝓔 (ConcreteVoteEvidence 𝓔)
import LibraBFT.Concrete.Obligations.VotesOnce 𝓔 (ConcreteVoteEvidence 𝓔) as VO-obl
import LibraBFT.Concrete.Obligations.PreferredRound 𝓔 (ConcreteVoteEvidence 𝓔) as PR-obl
open import LibraBFT.Concrete.Properties.VotesOnce as VO
open import LibraBFT.Concrete.Properties.PreferredRound as PR
open import LibraBFT.ImplShared.Util.HashCollisions iiah
open ImplObligations impl-correct
open PerEpoch 𝓔
open PerState st
open PerReachableState r
{- Although the `Concrete` modules are currently specified in terms of the implementation types used by
the implementation we are proving correct, the important aspect of the `Concrete` modules is to
reduce implementation obligations specified in the `Abstract` modules to being about `Vote`s sent.
These properties are stated in terms of an `IntermediateSystemState`, which is derived from a
`ReachableSystemState` for an implementation-specific system configuration.
The `Concrete` modules could be refactored to enable verifying a broader range of implementations,
including those that use entirely different implementation types. In more detail, the `Concrete`
modules would be parameterized by (at least):
- `SystemTypeParameters`;
- `SystemInitAndHandlers`;
- a predicate to satisy the requirements of PeerCanSignForPK, and a proof that it is stable
- a function from a `ReachableSystemState` of a system instantiated with
the provided `SystemTypeParameters` to an `IntermediateSystemState`;
- proof that the `InSys` predicate is stable for the given types (i.e., if a Record is InSys
according to the IntermediateSystemState for the prestate of a transition, then it is also
InSys according to the IntermediateSystemState for the poststate of that transition.
- an implementation Vote type
- machinery for accessing signatures of Votes, and for deriving abstract Votes from them
- proof that two Votes with the same signature represent the same abstract vote
- ...
This will also break existing proofs and require them to be reworked in terms of these module
parameters.
TODO-NOT-DO: Refactor Concrete so that it is independent of implementation types, thus making
it more general for a wider range of implementations. As our main motivation is verifying an
implementation (and perhaps variations on it) that use the same types, we do not consider it
worthwhile at this time.
-}
open IntermediateSystemState intSystemState
-- This module parameter asserts that there are no hash collisions between Blocks *in the system*,
-- allowing us to eliminate that case when the abstract properties claim it is the case.
module _ (no-collisions-InSys : NoCollisions InSys) where
--------------------------------------------------------------------------------------------
-- * A /ValidSysState/ is one in which both peer obligations are obeyed by honest peers * --
--------------------------------------------------------------------------------------------
record ValidSysState {ℓ}(𝓢 : IntermediateSystemState ℓ) : Set (ℓ+1 ℓ0 ℓ⊔ ℓ) where
field
vss-votes-once : VO-obl.Type 𝓢
vss-preferred-round : PR-obl.Type 𝓢
open ValidSysState public
validState : ValidSysState intSystemState
validState = record
{ vss-votes-once = VO.Proof.voo iiah 𝓔 sps-cor bsvc bsvr v≢0 ∈BI? iro vo₂ r
; vss-preferred-round = PR.Proof.prr iiah 𝓔 sps-cor bsvr v≢0 ∈BI? v4rc iro pr₁ pr₂ r 𝓔-∈sys
}
open All-InSys-props InSys
open WithAssumptions InSys no-collisions-InSys
-- We can now invoke the various abstract correctness properties. Note that the arguments are
-- expressed in Abstract terms (RecordChain, CommitRule). Proving the corresponding properties
-- for the actual implementation will involve proving that the implementation decides to commit
-- only if it has evidence of the required RecordChains and CommitRules such that the records in
-- the RecordChains are all "InSys" according to the implementation's notion thereof (defined in
-- Concrete.System.intSystemState).
ConcCommitsDoNotConflict :
∀{q q'}
→ {rc : RecordChain (Abs.Q q)} → All-InSys rc
→ {rc' : RecordChain (Abs.Q q')} → All-InSys rc'
→ {b b' : Abs.Block}
→ CommitRule rc b
→ CommitRule rc' b'
→ (Abs.B b) ∈RC rc' ⊎ (Abs.B b') ∈RC rc
ConcCommitsDoNotConflict =
CommitsDoNotConflict
(VO-obl.proof intSystemState (vss-votes-once validState))
(PR-obl.proof intSystemState (vss-preferred-round validState))
module _ (∈QC⇒AllSent : Complete InSys) where
ConcCommitsDoNotConflict'
: ∀{o o' q q'}
→ {rcf : RecordChainFrom o (Abs.Q q)} → All-InSys rcf
→ {rcf' : RecordChainFrom o' (Abs.Q q')} → All-InSys rcf'
→ {b b' : Abs.Block}
→ CommitRuleFrom rcf b
→ CommitRuleFrom rcf' b'
→ Σ (RecordChain (Abs.Q q')) ((Abs.B b) ∈RC_)
⊎ Σ (RecordChain (Abs.Q q)) ((Abs.B b') ∈RC_)
ConcCommitsDoNotConflict' =
CommitsDoNotConflict'
(VO-obl.proof intSystemState (vss-votes-once validState))
(PR-obl.proof intSystemState (vss-preferred-round validState))
∈QC⇒AllSent
|
{
"alphanum_fraction": 0.6806958474,
"avg_line_length": 50.5531914894,
"ext": "agda",
"hexsha": "e073a55647c3deb63bd2ef89780da6375d48ee0f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Concrete/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Concrete/Properties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Concrete/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1805,
"size": 7128
}
|
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
data ⊥ : Set where
data Zero : Set where
zero : Zero
data One : Set where
suc : Zero → One
data _≤_ : One → Zero → Set where
_≤?_ : ∀ m n → m ≤ n → ⊥
suc m ≤? zero = λ ()
thm : (f : suc zero ≤ zero → ⊥) → suc zero ≤? zero ≡ f
thm f = refl
-- (λ ()) zero x != f x of type ⊥
-- ^^^^
|
{
"alphanum_fraction": 0.543715847,
"avg_line_length": 16.6363636364,
"ext": "agda",
"hexsha": "874d3313ffa5215d542cad4bed9740060230997c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue3002.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue3002.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue3002.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 141,
"size": 366
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Diagram.End.Properties where
open import Level
open import Data.Product using (Σ; _,_)
open import Function using (_$_)
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Construction.Functors
open import Categories.Category.Construction.TwistedArrow
open import Categories.Category.Equivalence
open import Categories.Category.Equivalence.Preserves
open import Categories.Diagram.Cone
open import Categories.Diagram.End as ∫
open import Categories.Diagram.Limit
open import Categories.Diagram.Wedge
open import Categories.Diagram.Wedge.Properties
open import Categories.Functor hiding (id)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Instance.Twisted
import Categories.Morphism as M
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.Dinatural
open import Categories.Object.Terminal as Terminal
import Categories.Category.Construction.Wedges as Wedges
open import Categories.Object.Terminal
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D E : Category o ℓ e
module _ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
open Wedges F
-- Being an End is the same as being a Terminal object in the category of Wedges
End⇒Terminal : End F → Terminal Wedges
End⇒Terminal c = record
{ ⊤ = wedge
; ⊤-is-terminal = record
{ ! = λ {A} → record { u = factor A ; commute = universal }
; !-unique = λ {A} f → unique {A} (Wedge-Morphism.commute f)
}
}
where
open End c
Terminal⇒End : Terminal Wedges → End F
Terminal⇒End i = record
{ wedge = ⊤
; factor = λ W → u {W₁ = W} !
; universal = commute !
; unique = λ {_} {g} x → !-unique (record { u = g ; commute = x })
}
where
open Terminal.Terminal i
open Wedge-Morphism
module _ {C : Category o ℓ e}
(F : Functor E (Functors (Product (Category.op C) C) D)) where
private
module C = Category C
module D = Category D
module E = Category E
module NT = NaturalTransformation
open D
open HomReasoning
open MR D
open Functor F
open End hiding (E)
open NT using (η)
EndF : (∀ X → End (F₀ X)) → Functor E D
EndF end = record
{ F₀ = λ X → End.E (end X)
; F₁ = F₁′
; identity = λ {A} → unique (end A) (id-comm ○ ∘-resp-≈ˡ (⟺ identity))
; homomorphism = λ {A B C} {f g} → unique (end C) $ λ {Z} → begin
dinatural.α (end C) Z ∘ F₁′ g ∘ F₁′ f ≈⟨ pullˡ (universal (end C)) ⟩
(η (F₁ g) (Z , Z) ∘ dinatural.α (end B) Z) ∘ F₁′ f ≈⟨ pullʳ (universal (end B)) ⟩
η (F₁ g) (Z , Z) ∘ η (F₁ f) (Z , Z) ∘ dinatural.α (end A) Z ≈˘⟨ pushˡ homomorphism ⟩
η (F₁ (g E.∘ f)) (Z , Z) ∘ dinatural.α (end A) Z ∎
; F-resp-≈ = λ {A B f g} eq → unique (end B) $ λ {Z} → begin
dinatural.α (end B) Z ∘ F₁′ g ≈⟨ universal (end B) ⟩
η (F₁ g) (Z , Z) ∘ dinatural.α (end A) Z ≈˘⟨ F-resp-≈ eq ⟩∘⟨refl ⟩
η (F₁ f) (Z , Z) ∘ dinatural.α (end A) Z ∎
}
where F₁′ : ∀ {X Y} → X E.⇒ Y → End.E (end X) ⇒ End.E (end Y)
F₁′ {X} {Y} f = factor (end Y) $ record
{ E = End.E (end X)
; dinatural = F₁ f <∘ dinatural (end X)
}
-- A Natural Transformation between two functors induces an arrow between the
-- (object part of) the respective ends.
module _ {P Q : Functor (Product (Category.op C) C) D} (P⇒Q : NaturalTransformation P Q) where
open End renaming (E to end)
open Category D
end-η : {ep : End P} {eq : End Q} → end ep ⇒ end eq
end-η {ep} {eq} = factor eq (record
{ E = End.E ep
; dinatural = dtHelper record
{ α = λ c → η (c , c) ∘ dinatural.α ep c
; commute = λ {C} {C′} f → begin
Q.₁ (C.id , f) ∘ (η (C , C) ∘ αp C) ∘ D.id ≈⟨ pullˡ sym-assoc ⟩
((Q.₁ (C.id , f) ∘ η (C , C)) ∘ αp C) ∘ D.id ≈⟨ (nt.sym-commute (C.id , f) ⟩∘⟨refl ⟩∘⟨refl) ⟩
((η (C , C′) ∘ P.₁ (C.id , f)) ∘ αp C) ∘ D.id ≈⟨ assoc² ⟩
η (C , C′) ∘ (P.₁ (C.id , f) ∘ αp C ∘ D.id) ≈⟨ (refl⟩∘⟨ αp-comm f) ⟩
η (C , C′) ∘ P.₁ (f , C.id) ∘ αp C′ ∘ D.id ≈˘⟨ assoc² ⟩
((η (C , C′) ∘ P.₁ (f , C.id)) ∘ αp C′) ∘ D.id ≈⟨ (nt.commute (f , C.id) ⟩∘⟨refl ⟩∘⟨refl) ⟩
((Q.₁ (f , C.id) ∘ η (C′ , C′)) ∘ αp C′) ∘ D.id ≈⟨ pushˡ assoc ⟩
Q.₁ (f , C.id) ∘ (η (C′ , C′) ∘ αp C′) ∘ D.id ∎
}
})
where
module nt = NaturalTransformation P⇒Q
open nt using (η)
open HomReasoning
module C = Category C
module D = Category D
module P = Functor P
module Q = Functor Q
open DinaturalTransformation (dinatural ep) renaming (α to αp; commute to αp-comm)
open DinaturalTransformation (dinatural eq) renaming (α to αq; commute to αq-comm)
open Wedge
open MR D
-- The real start of the End Calculus. Maybe need to move such properties elsewhere?
-- This is an unpacking of the lhs of Eq. (25) of Loregian's book.
module _ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
private
Eq = ConesTwist≅Wedges F
module O = M D
open M (Wedges.Wedges F)
open Functor
open StrongEquivalence Eq renaming (F to F⇒)
-- Ends and Limits are equivalent, in the category Wedge F
End-as-Limit : (end : End F) → (l : Limit (Twist C D F)) → End.wedge end ≅ F₀ F⇒ (Limit.terminal.⊤ l)
End-as-Limit end l = Terminal.up-to-iso (Wedges.Wedges F) (End⇒Terminal F end) (pres-Terminal Eq terminal)
where
open Limit l
-- Which then induces that the objects, in D, are also equivalent.
End-as-Limit-on-Obj : (end : End F) → (l : Limit (Twist C D F)) → End.E end O.≅ Limit.apex l
End-as-Limit-on-Obj end l = record
{ from = Wedge-Morphism.u (M._≅_.from X≅Y)
; to = Wedge-Morphism.u (M._≅_.to X≅Y)
; iso = record
{ isoˡ = M._≅_.isoˡ X≅Y
; isoʳ = M._≅_.isoʳ X≅Y
}
}
where
X≅Y = End-as-Limit end l
open Category D
|
{
"alphanum_fraction": 0.5842606031,
"avg_line_length": 37.1317365269,
"ext": "agda",
"hexsha": "af793ead165f97c7406efa7abc2e83c23f53b48f",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/End/Properties.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/End/Properties.agda",
"max_line_length": 108,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/End/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 2243,
"size": 6201
}
|
{-# OPTIONS --cubical --safe #-}
open import Relation.Binary
open import Prelude hiding (Decidable)
module Data.List.Relation.Binary.Lexicographic {e ℓ₁ ℓ₂} {E : Type e} (ord : TotalOrder E ℓ₁ ℓ₂) where
open import Data.List
import Path as ≡
open TotalOrder ord renaming (refl to ≤-refl)
import Data.Empty.UniversePolymorphic as Poly
import Data.Unit.UniversePolymorphic as Poly
infix 4 _<′_
_<′_ : List E → List E → Type (e ℓ⊔ ℓ₁ ℓ⊔ ℓ₂)
xs <′ [] = Poly.⊥
[] <′ y ∷ ys = Poly.⊤
x ∷ xs <′ y ∷ ys = (x < y) ⊎ ((x ≡ y) × (xs <′ ys))
infix 4 _≤′_
_≤′_ : List E → List E → Type (e ℓ⊔ ℓ₁ ℓ⊔ ℓ₂)
[] ≤′ ys = Poly.⊤
x ∷ xs ≤′ [] = Poly.⊥
x ∷ xs ≤′ y ∷ ys = (x < y) ⊎ ((x ≡ y) × (xs ≤′ ys))
<′-trans : Transitive _<′_
<′-trans {[]} {y ∷ ys} {z ∷ zs} p q = Poly.tt
<′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inl q) = inl (<-trans p q)
<′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inr q) = inl (subst (_ <_) (fst q) p)
<′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr p) (inl q) = inl (subst (_< _) (sym (fst p)) q)
<′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr (p , ps)) (inr (q , qs)) = inr (p ; q , <′-trans ps qs)
≤′-trans : Transitive _≤′_
≤′-trans {[]} {ys} {zs} p q = Poly.tt
≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inl q) = inl (<-trans p q)
≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inl p) (inr q) = inl (subst (_ <_) (fst q) p)
≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr p) (inl q) = inl (subst (_< _) (sym (fst p)) q)
≤′-trans {x ∷ xs} {y ∷ ys} {z ∷ zs} (inr (p , ps)) (inr (q , qs)) = inr (p ; q , ≤′-trans ps qs)
≤′-antisym : Antisymmetric _≤′_
≤′-antisym {[]} {[]} p q = refl
≤′-antisym {x ∷ xs} {y ∷ ys} (inl p) (inl q) = ⊥-elim (asym p q)
≤′-antisym {x ∷ xs} {y ∷ ys} (inl p) (inr q) = ⊥-elim (irrefl (subst (_< _) (sym (fst q)) p))
≤′-antisym {x ∷ xs} {y ∷ ys} (inr p) (inl q) = ⊥-elim (irrefl (subst (_< _) (sym (fst p)) q))
≤′-antisym {x ∷ xs} {y ∷ ys} (inr (p , ps)) (inr (_ , qs)) = cong₂ _∷_ p (≤′-antisym ps qs)
≤′-refl : Reflexive _≤′_
≤′-refl {[]} = Poly.tt
≤′-refl {x ∷ xs} = inr (refl , ≤′-refl)
<′-asym : Asymmetric _<′_
<′-asym {x ∷ xs} {y ∷ ys} (inl p) (inl q) = asym p q
<′-asym {x ∷ xs} {y ∷ ys} (inl p) (inr q) = irrefl (subst (_< _) (sym (fst q)) p)
<′-asym {x ∷ xs} {y ∷ ys} (inr p) (inl q) = irrefl (subst (_< _) (sym (fst p)) q)
<′-asym {x ∷ xs} {y ∷ ys} (inr p) (inr q) = <′-asym (snd p) (snd q)
≮′⇒≥′ : ∀ {xs ys} → ¬ (xs <′ ys) → ys ≤′ xs
≮′⇒≥′ {xs} {[]} p = Poly.tt
≮′⇒≥′ {[]} {y ∷ ys} p = ⊥-elim (p _)
≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys with compare x y
≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | lt x<y = ⊥-elim (xs≮ys (inl x<y))
≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | eq x≡y = inr (sym x≡y , ≮′⇒≥′ (xs≮ys ∘ inr ∘ _,_ x≡y))
≮′⇒≥′ {x ∷ xs} {y ∷ ys} xs≮ys | gt x>y = inl x>y
<′-conn : Connected _<′_
<′-conn xs≮ys ys≮xs = ≤′-antisym (≮′⇒≥′ ys≮xs) (≮′⇒≥′ xs≮ys)
<′-irrefl : Irreflexive _<′_
<′-irrefl {x ∷ xs} (inl x<x) = irrefl x<x
<′-irrefl {x ∷ xs} (inr xs<xs) = <′-irrefl (snd xs<xs)
≰′⇒>′ : ∀ {xs ys} → ¬ (xs ≤′ ys) → ys <′ xs
≰′⇒>′ {[]} xs≰ys = ⊥-elim (xs≰ys _)
≰′⇒>′ {x ∷ xs} {[]} xs≰ys = Poly.tt
≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys with compare x y
≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | lt x<y = ⊥-elim (xs≰ys (inl x<y))
≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | eq x≡y = inr (sym x≡y , ≰′⇒>′ (xs≰ys ∘ inr ∘ _,_ x≡y))
≰′⇒>′ {x ∷ xs} {y ∷ ys} xs≰ys | gt x>y = inl x>y
≮′-cons : ∀ {x y xs ys} → x ≡ y → ¬ (xs <′ ys) → ¬ (x ∷ xs <′ y ∷ ys)
≮′-cons x≡y xs≮ys (inl x<y) = irrefl (subst (_< _) x≡y x<y)
≮′-cons x≡y xs≮ys (inr (x≡y₁ , x∷xs<y∷ys)) = xs≮ys x∷xs<y∷ys
_<′?_ : Decidable _<′_
xs <′? [] = no (λ ())
[] <′? (y ∷ ys) = yes Poly.tt
(x ∷ xs) <′? (y ∷ ys) with compare x y
((x ∷ xs) <′? (y ∷ ys)) | lt x<y = yes (inl x<y)
((x ∷ xs) <′? (y ∷ ys)) | eq x≡y = map-dec (inr ∘ _,_ x≡y) (≮′-cons x≡y) (xs <′? ys)
((x ∷ xs) <′? (y ∷ ys)) | gt x>y = no (<′-asym (inl x>y))
listOrd : TotalOrder (List E) _ _
StrictPreorder._<_ (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = _<′_
StrictPreorder.trans (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = <′-trans
StrictPreorder.irrefl (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder listOrd)) = <′-irrefl
StrictPartialOrder.conn (TotalOrder.strictPartialOrder listOrd) = <′-conn
Preorder._≤_ (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = _≤′_
Preorder.refl (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = ≤′-refl
Preorder.trans (PartialOrder.preorder (TotalOrder.partialOrder listOrd)) = ≤′-trans
PartialOrder.antisym (TotalOrder.partialOrder listOrd) = ≤′-antisym
TotalOrder._<?_ listOrd = _<′?_
TotalOrder.≰⇒> listOrd = ≰′⇒>′
TotalOrder.≮⇒≥ listOrd = ≮′⇒≥′
|
{
"alphanum_fraction": 0.523366508,
"avg_line_length": 42.7962962963,
"ext": "agda",
"hexsha": "29560794ce492e865b0e2fa733a16e398586cc59",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/List/Relation/Binary/Lexicographic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/List/Relation/Binary/Lexicographic.agda",
"max_line_length": 110,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/List/Relation/Binary/Lexicographic.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 2388,
"size": 4622
}
|
------------------------------------------------------------------------
-- Equivalence between omniscience principles
------------------------------------------------------------------------
-- http://math.fau.edu/lubarsky/Separating%20LLPO.pdf
-- https://pdfs.semanticscholar.org/deb5/23b6078032c845d8041ee6a5383fec41191c.pdf
-- http://www.math.lmu.de/~schwicht/pc16transparencies/ishihara/lecture1.pdf
-- https://ncatlab.org/nlab/show/weak+excluded+middle
------------------------------------------------------------------------
-- -> : implication
-- <=> : equivalence
-- ∧ : conjunction
{-
EM <=> DNE <=> Peirce <=> MI <=> DEM₁ <=> DEM₂-----┐
| | | | v
| | v v EM⁻¹ <=> DNE⁻¹
| | DGP ¬ ¬ EM <=> DNS
| | |
| | v
| | WEM <=> DEM₃ <=> DN-distrib-⊎
v v |
LPO KS-------------┐
/ \ | \
/ \ | \
v v v v
Σ-Call/CC <=> MP WLPO <=> Σ-Π-DGP -> PFP -> WPFP
|\ |
| \ v
| \ LLPO <=> Σ-DGP <=> Π-DGP
| \ |
v v v
WMP MP∨
-}
-- WLPO ∧ MP -> LPO
-- WLPO ∧ WMP -> LPO
-- WMP ∧ MP∨ -> MP
-- WPFP ∧ MP -> LPO
-- WPFP ∧ MP∨ -> WLPO
-- WPFP ∧ LLPO -> WLPO
-- Inhabited ∧ LPO <=> Searchable
-- MR <=> Σ-Σ-Peirce
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Constructive.Axiom.Properties.Base where
-- agda-stdlib
open import Axiom.Extensionality.Propositional
open import Level renaming (suc to lsuc; zero to lzero)
open import Data.Bool using (Bool; true; false; not)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤; tt)
open import Data.Sum as Sum
open import Data.Product as Prod
open import Data.Nat as ℕ using (ℕ; zero; suc; _≤_; s≤s; z≤n; _≤?_; _+_; _*_)
import Data.Nat.Properties as ℕₚ
import Data.Nat.Induction as ℕInd
open import Data.Fin using (Fin)
import Data.Fin.Properties as Finₚ
open import Function.Base
import Function.Equality as Eq
import Function.Equivalence as Eqv
import Function.LeftInverse as LInv -- TODO use new packages
import Induction.WellFounded as Ind
open import Relation.Binary
using (tri≈; tri<; tri>; Rel; Trichotomous)
open import Relation.Binary.PropositionalEquality hiding (Extensionality) -- TODO remove
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
-- agda-misc
open import Constructive.Axiom
import Constructive.Axiom.Properties.Base.Lemma as Lemma
open import Constructive.Combinators
open import Constructive.Common
open import TypeTheory.HoTT.Data.Sum.Properties using (isProp-⊎)
open import TypeTheory.HoTT.Relation.Nullary.Negation.Properties
using (isProp-¬)
-- Properties
aclt : ∀ {a b p} {A : Set a} {B : Set b} → ACLT A B p
aclt f = (λ x → proj₁ (f x)) , (λ x → proj₂ (f x))
lower-dne : ∀ a b → DNE (a ⊔ b) → DNE a
lower-dne a b dne = lower ∘′ dne ∘′ DN-map (lift {ℓ = b})
lower-wem : ∀ a b → WEM (a ⊔ b) → WEM a
lower-wem a b wem with wem
... | inj₁ ¬Lx = inj₁ λ x → ¬Lx (lift {ℓ = b} x)
... | inj₂ ¬¬Lx = inj₂ λ ¬A → ¬¬Lx λ LA → ¬A (lower LA)
-- LPO for finite set
lpo-Fin : ∀ {n p} → LPO (Fin n) p
lpo-Fin = dec⇒dec⊎ ∘ Finₚ.any? ∘ DecU⇒decidable
dec-dns-i : ∀ {a p} {A : Set a} {P : A → Set p} → DecU P → DNS-i P
dec-dns-i P? ∀¬¬P = DN-intro (P?⇒∀¬¬P→∀P P? ∀¬¬P)
-- TODO
-- dns-Fin : ∀ {n p} → DNS (Fin n) p
------------------------------------------------------------------------
-- Equivalence between classical proposition
------------------------------------------------------------------------
-- DNE <=> EM
dne⇒em : ∀ {a} → DNE a → EM a
dne⇒em dne = dne DN-Dec⊎
em⇒dne : ∀ {a} → EM a → DNE a
em⇒dne em = A⊎B→¬B→A em
-- Peirce => DNE, EM => Peirce
peirce⇒dne : ∀ {a b} → Peirce a b → DNE a
peirce⇒dne peirce ¬¬A =
peirce {B = Lift _ ⊥} λ A→B → ⊥-elim (¬¬A λ x → lower $ A→B x)
em⇒peirce : ∀ {a b} → EM a → Peirce a b
em⇒peirce em f = Sum.[ id , [[A→B]→A]→¬A→A f ] em
-- DEM₁ => EM, DNE => DEM₁
dem₁⇒em : ∀ {a} → DEM₁ a a → EM a
dem₁⇒em dem₁ = dem₁ (uncurry (flip _$_))
dne⇒dem₁ : ∀ {a b} → DNE (a ⊔ b) → DEM₁ a b
dne⇒dem₁ dne g = dne (g ∘ ¬[A⊎B]→¬A׬B)
-- DNE <=> DEM₂
dne⇒dem₂ : ∀ {a} → DNE a → DEM₂ a a
dne⇒dem₂ dne f = Prod.map dne dne $ ¬[A⊎B]→¬A׬B f
dem₂⇒dne : ∀ {a} → DEM₂ a lzero → DNE a
dem₂⇒dne dem₂ ¬¬A = uncurry id (dem₂ Sum.[ (λ f → ¬¬A (f ∘′ const)) , _$ tt ])
-- DNE => DEM₃
dne⇒dem₃ : ∀ {a b} → DNE (a ⊔ b) → DEM₃ a b
dne⇒dem₃ dne ¬[A×B] = dne (¬[A×B]→¬¬[¬A⊎¬B] ¬[A×B])
-- Converse of contraposition
dne⇒contraposition-converse : ∀ {a b} → DNE a →
{A : Set a} {B : Set b} → (¬ A → ¬ B) → B → A
dne⇒contraposition-converse dne ¬A→¬B b = dne $ contraposition ¬A→¬B (DN-intro b)
contraposition-converse⇒dne : ∀ {a} → ({A B : Set a} → (¬ A → ¬ B) → B → A) →
DNE a
contraposition-converse⇒dne f = f DN-intro
-- MI <=> EM
mi⇒em : ∀ {a} → MI a a → EM a
mi⇒em f = Sum.swap $ f id
em⇒mi : ∀ {a b} → EM a → MI a b
em⇒mi em f = Sum.swap $ Sum.map₁ f em
-- EM <=> [¬A→B]→A⊎B
em⇒[¬A→B]→A⊎B : ∀ {a b} → EM a → {A : Set a} {B : Set b} → (¬ A → B) → A ⊎ B
em⇒[¬A→B]→A⊎B em f = Sum.map₂ f em
[¬A→B]→A⊎B⇒em : ∀ {a} → ({A B : Set a} → (¬ A → B) → A ⊎ B) → EM a
[¬A→B]→A⊎B⇒em f = f id
-- Properties of WEM
em⇒wem : ∀ {a} → EM a → WEM a
em⇒wem em {A = A} = em {A = ¬ A}
-- WEM <=> DEM₃
wem⇒dem₃ : ∀ {a} → WEM a → DEM₃ a a
wem⇒dem₃ wem ¬[A×B] with wem | wem
... | inj₁ ¬A | _ = inj₁ ¬A
... | inj₂ ¬¬A | inj₁ ¬B = inj₂ ¬B
... | inj₂ ¬¬A | inj₂ ¬¬B = ⊥-elim $ DN-undistrib-× (¬¬A , ¬¬B) ¬[A×B]
dem₃⇒wem : ∀ {a} → DEM₃ a a → WEM a
dem₃⇒wem dem₃ = dem₃ ¬[A׬A]
dgp-i⇒DN-distrib-⊎-i : ∀ {a b} {A : Set a} {B : Set b} →
DGP-i A B → ¬ ¬ (A ⊎ B) → ¬ ¬ A ⊎ ¬ ¬ B
dgp-i⇒DN-distrib-⊎-i dgp-i ¬¬[A⊎B] =
Sum.map (λ B→A ¬A → ¬¬[A⊎B] Sum.[ ¬A , contraposition B→A ¬A ])
(λ A→B ¬B → ¬¬[A⊎B] Sum.[ contraposition A→B ¬B , ¬B ])
(Sum.swap dgp-i)
-- WEM <=> DN-distrib-⊎
wem⇒DN-distrib-⊎ : ∀ {a b} → WEM (a ⊔ b) →
{A : Set a} {B : Set b} → ¬ ¬ (A ⊎ B) → ¬ ¬ A ⊎ ¬ ¬ B
wem⇒DN-distrib-⊎ {a} {b} wem ¬¬[A⊎B] with lower-wem a b wem | lower-wem b a wem
... | inj₁ ¬A | inj₁ ¬B = ⊥-elim $ ¬¬[A⊎B] (¬A׬B→¬[A⊎B] (¬A , ¬B))
... | inj₁ ¬A | inj₂ ¬¬B = inj₂ ¬¬B
... | inj₂ ¬¬A | _ = inj₁ ¬¬A
DN-distrib-⊎⇒wem : ∀ {a} → ({A B : Set a} → ¬ ¬ (A ⊎ B) → ¬ ¬ A ⊎ ¬ ¬ B) → WEM a
DN-distrib-⊎⇒wem DN-distrib-⊎ = Sum.swap $ Sum.map₂ TN-to-N $ DN-distrib-⊎ DN-Dec⊎
-- WEM-i ∧ Stable => Dec⊎
wem-i∧stable⇒dec⊎ : ∀ {a} {A : Set a} → WEM-i A → Stable A → Dec⊎ A
wem-i∧stable⇒dec⊎ (inj₁ x) stable = inj₂ x
wem-i∧stable⇒dec⊎ (inj₂ y) stable = inj₁ (stable y)
-- EM => DGP => WEM
em⇒dgp : ∀ {a b} → EM (a ⊔ b) → DGP a b
em⇒dgp em = em⇒[¬A→B]→A⊎B em ¬[A→B]→B→A
dgp-i⇒dem₃-i : ∀ {a b} {A : Set a} {B : Set b} → DGP-i A B → DEM₃-i A B
dgp-i⇒dem₃-i dgp-i ¬[A×B] =
Sum.map (λ A→B → contraposition (λ x → x , A→B x) ¬[A×B])
(λ B→A → contraposition (λ y → B→A y , y) ¬[A×B])
dgp-i
dgp⇒dem₃ : ∀ {a b} → DGP a b → DEM₃ a b
dgp⇒dem₃ dgp ¬[A×B] = dgp-i⇒dem₃-i dgp ¬[A×B]
dgp⇒wem : ∀ {a} → DGP a a → WEM a
dgp⇒wem dgp = dem₃⇒wem $ dgp⇒dem₃ dgp
-- Properties of DNS
-- DNE => DNS
dne⇒dns : ∀ {a p} {A : Set a} → DNE (a ⊔ p) → DNS A (a ⊔ p)
dne⇒dns dne f = λ x → x λ y → dne (f y)
-- DNS <=> ¬ ¬ EM
dns⇒¬¬em : ∀ {a} → ({A : Set (lsuc a)} → DNS A a) → ¬ ¬ EM a
dns⇒¬¬em dns = DN-map (λ x {A} → x A) $ dns (λ _ → DN-Dec⊎)
¬¬em⇒dns : ∀ {a} → ¬ ¬ EM a → ({A : Set a} → DNS A a)
¬¬em⇒dns ¬¬em =
λ ∀x→¬¬Px ¬[∀x→Px] → ¬¬em λ em → ¬[∀x→Px] (λ x → em⇒dne em (∀x→¬¬Px x))
-- call/cc is classical
call/cc⇒dne : ∀ {a} → Call/CC a → DNE a
call/cc⇒dne call/cc ¬¬A = call/cc λ ¬A → ⊥-elim (¬¬A ¬A)
em⇒call/cc : ∀ {a} → EM a → Call/CC a
em⇒call/cc em ¬A→A = Sum.[ id , ¬A→A ] em
-- DNE <=> ¬[A׬B]→A→B
dne⇒¬[A׬B]→A→B : ∀ {a b} → DNE (a ⊔ b) →
{A : Set a} {B : Set b} → ¬ (A × ¬ B) → A → B
dne⇒¬[A׬B]→A→B dne = dne λ x → x λ y z → ⊥-elim (y (z , (λ w → x λ u v → w)))
¬[A׬B]→A→B⇒dne : ∀ {a} → ({A B : Set a} → ¬ (A × ¬ B) → A → B) → DNE a
¬[A׬B]→A→B⇒dne f ¬¬A = f (uncurry id) ¬¬A
-- EM <=> [A→B]→¬A⊎B
em⇒[A→B]→¬A⊎B : ∀ {a b} → EM b → {A : Set a} {B : Set b} → (A → B) → ¬ A ⊎ B
em⇒[A→B]→¬A⊎B em f = Sum.swap (Sum.map₂ (contraposition f) em)
[A→B]→¬A⊎B⇒em : ∀ {a} → ({A B : Set a} → (A → B) → ¬ A ⊎ B) → EM a
[A→B]→¬A⊎B⇒em f = Sum.swap (f id)
dne⇒¬[A→¬B]→A×B : ∀ {a b} → DNE (a ⊔ b) →
{A : Set a} {B : Set b} → ¬ (A → ¬ B) → A × B
dne⇒¬[A→¬B]→A×B dne f = dne λ ¬[A×B] → f λ x y → ¬[A×B] (x , y)
-- the counterexample principle
dne⇒¬[A→B]→A׬B : ∀ {a b} → DNE (a ⊔ b) →
{A B : Set a} {B : Set b} → ¬ (A → B) → A × ¬ B
dne⇒¬[A→B]→A׬B dne f =
dne λ ¬[A׬B] → f λ x → ⊥-elim (¬[A׬B] (x , (λ y → f (const y))))
¬[A→B]→A׬B⇒dne : ∀ {a} → ({A B : Set a} → ¬ (A → B) → A × ¬ B) → DNE a
¬[A→B]→A׬B⇒dne {a} f ¬¬A with f {B = Lift a ⊥} λ A→L⊥ → ¬¬A λ x → lower $ A→L⊥ x
... | x , _ = x
dne⇒ip : ∀ {a b c} → DNE (a ⊔ b ⊔ c) → IP a b c
dne⇒ip dne q f = dne (DN-ip q f)
-- Properties of DNE⁻¹ and EM⁻¹
em⇒em⁻¹ : ∀ {a} → EM a → EM⁻¹ a
em⇒em⁻¹ em _ = em
-- DNE⁻¹ <=> EM⁻¹
dne⁻¹⇒em⁻¹ : ∀ {a} → Extensionality a lzero → DNE⁻¹ a → EM⁻¹ a
dne⁻¹⇒em⁻¹ ext dne⁻¹ isP = dne⁻¹ isP′ DN-Dec⊎
where
isP′ : ∀ x y → x ≡ y
isP′ = isProp-⊎ ¬[A׬A] isP (isProp-¬ ext)
em⁻¹⇒dne⁻¹ : ∀ {a} → EM⁻¹ a → DNE⁻¹ a
em⁻¹⇒dne⁻¹ em⁻¹ isP = dec⊎⇒stable (em⁻¹ isP)
-----------------------------------------------------------------------
-- Properties of LPO, LLPO, WLPO, MP, MP⊎, WMP, KS, PFP, WPFP, Σ-DGP,
-- Π-DGP, Σ-Π-DGP, Σ-Call/CC
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-- Convert between alternative forms
-- MP <=> MR
mp⇒mr : ∀ {a p} {A : Set a} → MP A p → MR A p
mp⇒mr mp P? ¬¬∃P = P?⇒∃¬¬P→∃P P? $ mp (¬-DecU P?) (¬¬∃P→¬∀¬P ¬¬∃P)
mr⇒mp : ∀ {a p} {A : Set a} → MR A p → MP A p
mr⇒mp mr P? ¬∀P = mr (¬-DecU P?) (P?⇒¬∀P→¬¬∃¬P P? ¬∀P)
-- WLPO <=> WLPO-Alt
wlpo⇒wlpo-Alt : ∀ {a p} {A : Set a} → WLPO A p → WLPO-Alt A p
wlpo⇒wlpo-Alt wlpo P? = Sum.map ∀¬P→¬∃P ¬∀¬P→¬¬∃P (wlpo (¬-DecU P?))
wlpo-Alt⇒wlpo : ∀ {a p} {A : Set a} → WLPO-Alt A p → WLPO A p
wlpo-Alt⇒wlpo wlpo-Alt P? =
Sum.map (P?⇒¬∃¬P→∀P P?) ¬¬∃¬P→¬∀P (wlpo-Alt (¬-DecU P?))
-- MP⊎ <=> MP⊎-Alt
mp⊎⇒mp⊎-Alt : ∀ {a p} {A : Set a} → MP⊎ A p → MP⊎-Alt A p
mp⊎⇒mp⊎-Alt mp⊎ P? Q? =
Sum.map (contraposition ∀P→¬∃¬P) (contraposition ∀P→¬∃¬P) ∘′
mp⊎ (¬-DecU P?) (¬-DecU Q?) ∘′
contraposition (Prod.map (P?⇒¬∃¬P→∀P P?) (P?⇒¬∃¬P→∀P Q?))
mp⊎-Alt⇒mp⊎ : ∀ {a p} {A : Set a} → MP⊎-Alt A p → MP⊎ A p
mp⊎-Alt⇒mp⊎ mp⊎-Alt P? Q? =
Sum.map (contraposition ¬∃P→∀¬P) (contraposition ¬∃P→∀¬P) ∘′
mp⊎-Alt (¬-DecU P?) (¬-DecU Q?) ∘′
contraposition (Prod.map ∀¬P→¬∃P ∀¬P→¬∃P)
-- MP⊎ <=> MP∨
mp⊎⇒mp∨ : ∀ {a p} {A : Set a} → MP⊎ A p → MP∨ A p
mp⊎⇒mp∨ mp⊎ P? Q? ¬¬∃x→Px⊎Qx = mp⊎ P? Q? ([¬¬∃x→Px⊎Qx]→¬[¬∃P׬∃Q] ¬¬∃x→Px⊎Qx)
mp∨⇒mp⊎ : ∀ {a p} {A : Set a} → MP∨ A p → MP⊎ A p
mp∨⇒mp⊎ mp∨ P? Q? ¬[¬∃P׬∃Q] = mp∨ P? Q? (¬[¬∃P׬∃Q]→¬¬∃x→Px⊎Qx ¬[¬∃P׬∃Q])
-- LLPO <=> LLPO-Alt
llpo⇒llpo-Alt : ∀ {a p} {A : Set a} → LLPO A p → LLPO-Alt A p
llpo⇒llpo-Alt llpo P? Q? =
Sum.map (P?⇒¬∃¬P→∀P P?) (P?⇒¬∃¬P→∀P Q?) ∘′
llpo (¬-DecU P?) (¬-DecU Q?) ∘′
contraposition (¬A׬B→¬[A⊎B] ∘ Prod.map ∃¬P→¬∀P ∃¬P→¬∀P)
llpo-Alt⇒llpo : ∀ {a p} {A : Set a} → LLPO-Alt A p → LLPO A p
llpo-Alt⇒llpo llpo-Alt P? Q? =
Sum.map ∀¬P→¬∃P ∀¬P→¬∃P ∘′
llpo-Alt (¬-DecU P?) (¬-DecU Q?) ∘′
DN-map (Sum.map ¬∃P→∀¬P ¬∃P→∀¬P) ∘′ ¬[A×B]→¬¬[¬A⊎¬B]
-- LLPO <=> LLPO-ℕ
llpo⇒llpo-ℕ : ∀ {p} → LLPO ℕ p → LLPO-ℕ p
llpo⇒llpo-ℕ llpo P? ∀mn→m≢n→Pm⊎Pn with
llpo (λ n → ¬-DecU P? (2 * n)) (λ n → ¬-DecU P? (1 + 2 * n))
(uncurry (Lemma.lemma₁ ∀mn→m≢n→Pm⊎Pn))
... | inj₁ ¬∃n→¬P2n = inj₁ (P?⇒¬∃¬P→∀P (λ n → P? (2 * n)) ¬∃n→¬P2n)
... | inj₂ ¬∃n→¬P1+2n = inj₂ (P?⇒¬∃¬P→∀P (λ n → P? (suc (2 * n))) ¬∃n→¬P1+2n)
private
module _ {p} {P Q : ℕ → Set p} (P? : DecU P) (Q? : DecU Q) where
combine : DecU (λ n → Sum.[ P , Q ] (Lemma.parity n))
combine n with Lemma.parity n
... | inj₁ m = P? m
... | inj₂ m = Q? m
{-
lemma : ¬ (∃ P × ∃ Q) → ∀ m n → m ≢ n →
Sum.[ (λ o → ¬ P o) , (λ o → ¬ Q o) ] (Lemma.parity m) ⊎
Sum.[ (λ o → ¬ P o) , (λ o → ¬ Q o) ] (Lemma.parity n)
lemma _ m n m≢n with
Lemma.parity n | inspect Lemma.parity n | Lemma.parity m | inspect Lemma.parity m
... | inj₁ o | [ eq₁ ] | inj₁ p | [ eq₂ ] = {! !}
... | inj₁ o | [ eq₁ ] | inj₂ p | [ eq₂ ] = {! !}
... | inj₂ o | [ eq₁ ] | inj₁ p | [ eq₂ ] = {! !}
... | inj₂ o | [ eq₁ ] | inj₂ p | [ eq₂ ] = {! !}
llpo-ℕ⇒llpo-Alt : ∀ {p} → LLPO-ℕ p → LLPO-Alt ℕ p
llpo-ℕ⇒llpo-Alt llpo-ℕ P? Q? ¬¬[∀P⊎∀Q] with llpo-ℕ (combine P? Q?) {! !}
... | inj₁ ∀n→[P,Q]parity[2*n] =
inj₁ λ n → subst Sum.[ _ , _ ] (Lemma.parity-even n) (∀n→[P,Q]parity[2*n] n)
... | inj₂ ∀n→[P,Q]parity[1+2*n] =
inj₂ λ n → subst Sum.[ _ , _ ] (Lemma.parity-odd n) (∀n→[P,Q]parity[1+2*n] n)
-}
-----------------------------------------------------------------------
-- Implications
-- EM => LPO
em⇒lpo : ∀ {a p} {A : Set a} → EM (a ⊔ p) → LPO A p
em⇒lpo em _ = em
-- LPO => LLPO
lpo⇒llpo : ∀ {a p} {A : Set a} → LPO A p → LLPO A p
lpo⇒llpo lpo P? Q? ¬[∃P×∃Q] with lpo P? | lpo Q?
... | inj₁ ∃P | inj₁ ∃Q = contradiction (∃P , ∃Q) ¬[∃P×∃Q]
... | inj₁ ∃P | inj₂ ¬∃Q = inj₂ ¬∃Q
... | inj₂ ¬∃P | _ = inj₁ ¬∃P
-- LPO <=> WLPO-Alt ∧ MR
lpo⇒wlpo-Alt : ∀ {a p} {A : Set a} → LPO A p → WLPO-Alt A p
lpo⇒wlpo-Alt lpo P? = ¬-dec⊎ (lpo P?)
lpo⇒mr : ∀ {a p} {A : Set a} → LPO A p → MR A p
lpo⇒mr lpo P? = dec⊎⇒stable (lpo P?)
wlpo-Alt∧mr⇒lpo : ∀ {a p} {A : Set a} → WLPO-Alt A p → MR A p → LPO A p
wlpo-Alt∧mr⇒lpo wlpo-Alt mr P? = wem-i∧stable⇒dec⊎ (wlpo-Alt P?) (mr P?)
-- WLPO => LLPO-Alt
wlpo⇒llpo-Alt : ∀ {a p} {A : Set a} → WLPO A p → LLPO-Alt A p
wlpo⇒llpo-Alt wlpo P? Q? ¬¬[∀P⊎∀Q] with wlpo P? | wlpo Q?
... | inj₁ ∀P | _ = inj₁ ∀P
... | inj₂ ¬∀P | inj₁ ∀Q = inj₂ ∀Q
... | inj₂ ¬∀P | inj₂ ¬∀Q = contradiction (¬A׬B→¬[A⊎B] (¬∀P , ¬∀Q)) ¬¬[∀P⊎∀Q]
-- WEM => WLPO-Alt
wem⇒wlpo-Alt : ∀ {a p} {A : Set a} → WEM (a ⊔ p) → WLPO-Alt A p
wem⇒wlpo-Alt wem P? = wem
-- (WMP ∧ MP∨) <=> MR
mr⇒wmp : ∀ {a p} {A : Set a} → MR A p → WMP A p
mr⇒wmp mr {P = P} P? pp =
mr P? $ Sum.[ id , (λ ¬¬∃x→Px׬Px _ → f ¬¬∃x→Px׬Px) ] (pp P?)
where
f : ¬ ¬ ∃ (λ x → P x × ¬ P x) → ⊥
f ¬¬∃x→Px׬Px = ⊥-stable $ DN-map (¬[A׬A] ∘ proj₂) ¬¬∃x→Px׬Px
-- MR => MP∨
mr⇒mp∨ : ∀ {a p} {A : Set a} → MR A p → MP∨ A p
mr⇒mp∨ mr {P = P} {Q = Q} P? Q? ¬¬∃x→Px⊎Qx =
Sum.map DN-intro DN-intro $ ∃-distrib-⊎ $
mr {P = λ x → P x ⊎ Q x} (DecU-⊎ P? Q?) ¬¬∃x→Px⊎Qx
-- WMP ∧ MP∨ => MR
-- α = P, β = Q, γ = R in [2]
wmp∧mp∨⇒mr : ∀ {a p} {A : Set a} → WMP A p → MP∨ A p → MR A p
wmp∧mp∨⇒mr {a} {p} {A} wmp mp∨ {P = P} P? ¬¬∃P = wmp P? Lem.¬¬∃Q⊎¬¬∃R
where
module Lem {Q : A → Set p} (Q? : DecU Q) where
R : A → Set p
R x = P x × ¬ Q x
¬¬∃x→Qx⊎Rx : ¬ ¬ ∃ λ x → Q x ⊎ R x
¬¬∃x→Qx⊎Rx = DN-map f ¬¬∃P
where
f : ∃ P → ∃ (λ x → Q x ⊎ (P x × ¬ Q x))
f (x , Px) = x , Sum.map₂ (Px ,_) (Q? x)
R? : DecU R
R? = DecU-× P? (¬-DecU Q?)
¬¬∃Q⊎¬¬∃R : ¬ ¬ ∃ Q ⊎ ¬ ¬ ∃ R
¬¬∃Q⊎¬¬∃R = mp∨ Q? R? ¬¬∃x→Qx⊎Rx
-- Properties that required to prove `llpo⇒Σ-dgp`
record HasProperties
{a} r p (A : Set a) : Set (a ⊔ lsuc r ⊔ lsuc p)
where
field
_<_ : Rel A r
<-cmp : Trichotomous _≡_ _<_
<-any-dec : {P : A → Set p} → DecU P → DecU (λ n → ∃ λ m → (m < n) × P m)
<-wf : Ind.WellFounded _<_
private
¬∃¬→∀ : ∀ {P : A → Set p} {x} →
DecU P → ¬ (∃ λ y → y < x × ¬ P y) → ∀ y → y < x → P y
¬∃¬→∀ {x} P? ¬∃y→y<x׬Py y y<x =
DecU⇒stable P? y λ ¬Py → ¬∃y→y<x׬Py (y , (y<x , ¬Py))
<-all-dec : {P : A → Set p} → DecU P → DecU (λ n → ∀ i → i < n → P i)
<-all-dec P? n with <-any-dec (¬-DecU P?) n
... | inj₁ (m , m<n , ¬Pm) = inj₂ λ ∀i→i<n→Pi → ¬Pm (∀i→i<n→Pi m m<n)
... | inj₂ ¬∃m→m<n׬Pm = inj₁ (¬∃¬→∀ P? ¬∃m→m<n׬Pm)
First : (A → Set p) → A → Set (a ⊔ p ⊔ r)
First P x = (∀ y → y < x → ¬ P y) × P x
First? : {P : A → Set p} → DecU P → DecU (First P)
First? P? = DecU-× (<-all-dec (¬-DecU P?)) P?
None : (A → Set p) → A → Set (a ⊔ p ⊔ r)
None P x = (∀ y → y < x → ¬ P y) × ¬ P x
None? : {P : A → Set p} → DecU P → DecU (None P)
None? P? = DecU-× (<-all-dec (¬-DecU P?)) (¬-DecU P?)
∃⊎None : {P : A → Set p} → DecU P → ∀ x → ∃ P ⊎ None P x
∃⊎None P? x with P? x | <-any-dec P? x
... | inj₁ Px | _ = inj₁ (x , Px)
... | inj₂ ¬Px | inj₁ (y , _ , Py) = inj₁ (y , Py)
... | inj₂ ¬Px | inj₂ ¬∃ =
inj₂ ((λ y y<x Py → ¬∃ (y , (y<x , Py))) , ¬Px)
findFirst : {P : A → Set p} → DecU P →
∃ P → ∃ (First P)
findFirst {P} P? (x , Px) = go x (<-wf x) Px
where
go : ∀ x → Ind.Acc _<_ x → P x → ∃ λ y → (∀ i → i < y → ¬ P i) × P y
go x (Ind.acc rs) Px with <-any-dec P? x
... | inj₁ (y , y<x , Py) = go y (rs y y<x) Py
... | inj₂ ¬∃y→y<x×Py =
x , (λ i i<x Pi → ¬∃y→y<x×Py (i , (i<x , Pi))) , Px
First-unique : ∀ {P : A → Set p} {x y} → First P x → First P y → x ≡ y
First-unique {P} {x} {y} (∀i→i<x→¬Pi , Px) (∀i→i<y→¬Pi , Py) with <-cmp x y
... | tri< x<y _ _ = contradiction Px (∀i→i<y→¬Pi x x<y)
... | tri≈ _ x≡y _ = x≡y
... | tri> _ _ x>y = contradiction Py (∀i→i<x→¬Pi y x>y)
module HasPropertiesLemma
{P Q : A → Set p} (P? : DecU P) (Q? : DecU Q)
where
R S : A → Set (r ⊔ p ⊔ a)
R x = First P x × None Q x
S x = First Q x × None P x
R? : DecU R
R? = DecU-× (First? P?) (None? Q?)
S? : DecU S
S? = DecU-× (First? Q?) (None? P?)
¬[∃R×∃S] : ¬ (∃ R × ∃ S)
¬[∃R×∃S] ((x , (∀i→i<x→¬Pi , Px) , ∀i→i<x→¬Qi , ¬Qx) ,
(y , (∀i→i<y→¬Qi , Qy) , ∀i→i<y→¬Pi , ¬Py )) with <-cmp x y
... | tri< x<y _ _ = ∀i→i<y→¬Pi x x<y Px
... | tri≈ _ x≡y _ = ¬Py (subst P x≡y Px)
... | tri> _ _ y<x = ∀i→i<x→¬Qi y y<x Qy
¬∃R→∃P→∃Q : ¬ ∃ R → ∃ P → ∃ Q
¬∃R→∃P→∃Q ¬∃R ∃P with findFirst P? ∃P
¬∃R→∃P→∃Q ¬∃R ∃P | x , firstP with ∃⊎None Q? x
¬∃R→∃P→∃Q ¬∃R ∃P | x , firstP | inj₁ ∃Q = ∃Q
¬∃R→∃P→∃Q ¬∃R ∃P | x , firstP | inj₂ noneQ =
contradiction (x , firstP , noneQ) ¬∃R
¬∃S→∃Q→∃P : ¬ ∃ S → ∃ Q → ∃ P
¬∃S→∃Q→∃P ¬∃S ∃Q with findFirst Q? ∃Q
¬∃S→∃Q→∃P ¬∃S ∃Q | x , firstQ with ∃⊎None P? x
¬∃S→∃Q→∃P ¬∃S ∃Q | x , firstQ | inj₁ ∃P = ∃P
¬∃S→∃Q→∃P ¬∃S ∃Q | x , firstQ | inj₂ noneP =
contradiction (x , firstQ , noneP) ¬∃S
-- Proposition 8.6.1. [1]
-- Σ-DGP <=> LLPO
llpo⇒Σ-dgp : ∀ {r p a} {A : Set a} → HasProperties r p A →
LLPO A (p ⊔ a ⊔ r) → Σ-DGP A p
llpo⇒Σ-dgp has llpo {P = P} {Q} P? Q? =
Sum.map ¬∃R→∃P→∃Q ¬∃S→∃Q→∃P ¬∃R⊎¬∃S
where
open HasProperties has
open HasPropertiesLemma P? Q?
¬∃R⊎¬∃S : ¬ ∃ R ⊎ ¬ ∃ S
¬∃R⊎¬∃S = llpo R? S? ¬[∃R×∃S]
Σ-dgp⇒llpo : ∀ {a p} {A : Set a} → Σ-DGP A p → LLPO A p
Σ-dgp⇒llpo Σ-dgp P? Q? ¬[∃P×∃Q] = dgp-i⇒dem₃-i (Σ-dgp P? Q?) ¬[∃P×∃Q]
-- Σ-DGP => MP∨
Σ-dgp⇒mp∨ : ∀ {p a} {A : Set a} → Σ-DGP A p → MP∨ A p
Σ-dgp⇒mp∨ Σ-dgp {P = P} {Q} P? Q? ¬¬[∃x→Px⊎Qx] = ¬¬∃P⊎¬¬∃Q
where
¬¬[∃P⊎∃Q] : ¬ ¬ (∃ P ⊎ ∃ Q)
¬¬[∃P⊎∃Q] = DN-map ∃-distrib-⊎ ¬¬[∃x→Px⊎Qx]
¬¬∃P⊎¬¬∃Q : ¬ ¬ ∃ P ⊎ ¬ ¬ ∃ Q
¬¬∃P⊎¬¬∃Q = dgp-i⇒DN-distrib-⊎-i (Σ-dgp P? Q?) ¬¬[∃P⊎∃Q]
-- Σ-DGP => Π-DGP
Σ-dgp⇒Π-dgp : ∀ {p a} {A : Set a} → Σ-DGP A p → Π-DGP A p
Σ-dgp⇒Π-dgp Σ-dgp P? Q? =
Sum.map (P?⇒[∃¬P→∃¬Q]→∀Q→∀P Q?) (P?⇒[∃¬P→∃¬Q]→∀Q→∀P P?)
(Σ-dgp (¬-DecU Q?) (¬-DecU P?))
-- Π-DGP => LLPO-Alt
Π-dgp⇒llpo-Alt : ∀ {a p} {A : Set a} → Π-DGP A p → LLPO-Alt A p
Π-dgp⇒llpo-Alt Π-dgp P? Q? = Sum.map (P?⇒¬¬∀P→∀P P?) (P?⇒¬¬∀P→∀P Q?) ∘′
dgp-i⇒DN-distrib-⊎-i (Π-dgp P? Q?)
-- LLPO => MP∨
llpo⇒mp∨ : ∀ {r p a} {A : Set a} →
HasProperties r p A → LLPO A (p ⊔ a ⊔ r) → MP∨ A p
llpo⇒mp∨ has llpo = Σ-dgp⇒mp∨ (llpo⇒Σ-dgp has llpo)
ℕ-hasProperties : ∀ p → HasProperties lzero p ℕ
ℕ-hasProperties _ = record
{ _<_ = ℕ._<_
; <-cmp = ℕₚ.<-cmp
; <-any-dec = Lemma.ℕ<-any-dec
; <-wf = ℕInd.<-wellFounded
}
ℕ-llpo⇒mp∨ : ∀ {p} → LLPO ℕ p → MP∨ ℕ p
ℕ-llpo⇒mp∨ = llpo⇒mp∨ (ℕ-hasProperties _)
ℕ-llpo⇒Σ-dgp : ∀ {p} → LLPO ℕ p → Σ-DGP ℕ p
ℕ-llpo⇒Σ-dgp = llpo⇒Σ-dgp (ℕ-hasProperties _)
-- Proposition 8.6.1. [1]
-- WLPO <=> Σ-Π-DGP
wlpo⇒Σ-Π-dgp : ∀ {a p} {A : Set a} → WLPO A p → Σ-Π-DGP A p
wlpo⇒Σ-Π-dgp wlpo P? Q? with wlpo Q?
... | inj₁ ∀Q = inj₁ λ _ → ∀Q
... | inj₂ ¬∀Q = inj₂ λ ∀Q → ⊥-elim $ ¬∀Q ∀Q
Σ-Π-dgp⇒wlpo : ∀ {a p} {A : Set a} → Σ-Π-DGP A p → WLPO A p
Σ-Π-dgp⇒wlpo Σ-Π-dgp P? with Σ-Π-dgp (¬-DecU P?) P?
... | inj₁ ∃¬P→∀P = inj₁ (P?⇒[∃¬P→∀P]→∀P P? ∃¬P→∀P)
... | inj₂ ∀P→∃¬P = inj₂ λ ∀P → ∃¬P→¬∀P (∀P→∃¬P ∀P) ∀P
-- Question 15 [1]
-- MR <=> Σ-Call/CC
mr⇒Σ-call/cc : ∀ {a p} {A : Set a} → MR A p → Σ-Call/CC A p
mr⇒Σ-call/cc mr P? = mr P? ∘′ [¬A→A]→¬¬A
Σ-call/cc⇒mr : ∀ {a p} {A : Set a} → Σ-Call/CC A p → MR A p
Σ-call/cc⇒mr Σ-call/cc P? ¬¬∃P = Σ-call/cc P? λ ¬∃P → ⊥-elim $ ¬¬∃P ¬∃P
-- Question 15 [1]
-- MR <=> Σ-Σ-Peirce
mr⇒Σ-Σ-peirce : ∀ {a p} {A : Set a} → MR A p → Σ-Σ-Peirce A p
mr⇒Σ-Σ-peirce mr P? Q? [∃P→∃Q]→∃P = mr P? ([[A→B]→A]→¬¬A [∃P→∃Q]→∃P)
Σ-Σ-peirce⇒mr : ∀ {a p} {A : Set a} → Σ-Σ-Peirce A p → MR A p
Σ-Σ-peirce⇒mr {A = A} Σ-Σ-peirce P? =
[[[A→B]→A]→A]→¬B→¬¬A→A (Σ-Σ-peirce {Q = λ _ → Lift _ ⊥} P? (λ _ → inj₂ lower))
f
where
f : Σ A (λ _ → Lift _ ⊥) → ⊥
f (_ , ())
-- MR => Σ-Π-Peirce
mr⇒Σ-Π-peirce : ∀ {a p} {A : Set a} → MR A p → Σ-Π-Peirce A p
mr⇒Σ-Π-peirce mr P? Q? [∃P→∀Q]→∃P = mr P? ([[A→B]→A]→¬¬A [∃P→∀Q]→∃P)
-- Inhabited ∧ Σ-Π-peirce => MR
inhabited∧Σ-Π-peirce⇒mr : ∀ {a p} {A : Set a} →
Inhabited A → Σ-Π-Peirce A p → MR A p
inhabited∧Σ-Π-peirce⇒mr {p = p} {A} inhabited Σ-Π-peirce P? =
[[[A→B]→A]→A]→¬B→¬¬A→A (Σ-Π-peirce {Q = λ _ → Lift _ ⊥} P? (λ _ → inj₂ lower))
f
where
f : ¬ ((x : A) → Lift p ⊥)
f ∀x→L⊥ = lower (∀x→L⊥ inhabited)
-- Proposition 6.4.1. [1]
-- WMP ∧ WLPO-Alt => LPO
wmp∧wlpo-Alt⇒lpo : ∀ {a p} {A : Set a} → WMP A p → WLPO-Alt A p → LPO A p
wmp∧wlpo-Alt⇒lpo {a} {p} {A} wmp wlpo-Alt {P = P} P? with wlpo-Alt P?
... | inj₁ ¬∃P = inj₂ ¬∃P
... | inj₂ ¬¬∃P = inj₁ (wmp P? Lem.res)
where
module Lem {Q : A → Set p} (Q? : DecU Q) where
R : A → Set p
R x = P x × ¬ Q x
R? : DecU R
R? = DecU-× P? (¬-DecU Q?)
¬∃R⊎¬¬∃R : ¬ ∃ R ⊎ ¬ ¬ ∃ R
¬∃R⊎¬¬∃R = wlpo-Alt R?
res : ¬ ¬ ∃ Q ⊎ (¬ ¬ ∃ λ x → P x × ¬ Q x)
res = Sum.map₁ (λ ¬∃R ¬∃Q → ¬¬∃P (f ¬∃R ¬∃Q)) ¬∃R⊎¬¬∃R
where
f : ¬ ∃ R → ¬ ∃ Q → ¬ ∃ P
f ¬∃R ¬∃Q (x , Px) = ¬∃R (x , (Px , ¬∃P→∀¬P ¬∃Q x))
-- direct proof of WLPO => MP⊎
wlpo-Alt⇒mp⊎ : ∀ {a p} {A : Set a} → WLPO-Alt A p → MP⊎ A p
wlpo-Alt⇒mp⊎ wlpo-Alt P? Q? ¬[¬∃P׬∃Q] with wlpo-Alt P? | wlpo-Alt Q?
... | inj₁ ¬∃P | inj₁ ¬∃Q = ⊥-elim $ ¬[¬∃P׬∃Q] (¬∃P , ¬∃Q)
... | inj₁ ¬∃P | inj₂ ¬¬∃Q = inj₂ ¬¬∃Q
... | inj₂ ¬¬∃P | _ = inj₁ ¬¬∃P
-- EM => KS
em⇒ks : ∀ {a p} q {A : Set a} (x : A) → EM p → KS A p q
em⇒ks q x em P with em {A = P}
em⇒ks q x em P | inj₁ xP =
(λ _ → Lift q ⊤) , (λ _ → inj₁ (lift tt)) , ((λ _ → x , lift tt) , (λ _ → xP))
em⇒ks q x em P | inj₂ ¬P =
(λ _ → Lift q ⊥) , (λ _ → inj₂ lower) ,
((λ xP → ⊥-elim $ ¬P xP) , (λ A×L⊥ → ⊥-elim $ lower $ proj₂ A×L⊥))
-- KS => PFP
ks⇒pfp : ∀ {a p q} {A : Set a} → KS A (a ⊔ p) q → PFP A p q
ks⇒pfp ks {P = P} P? = ks (∀ x → P x)
-- PFP => WPFP
pfp⇒wpfp : ∀ {a p q} {A : Set a} → PFP A p q → WPFP A p q
pfp⇒wpfp pfp {P = P} P? with pfp P?
... | Q , Q? , ∀P→∃Q , ∃Q→∀P = (λ x → ¬ Q x) , (¬-DecU Q? , (f , g))
where
f : (∀ x → P x) → ¬ (∀ x → ¬ Q x)
f ∀P = ∃P→¬∀¬P (∀P→∃Q ∀P)
g : (¬ (∀ x → ¬ Q x)) → ∀ x → P x
g = P?⇒[∃Q→∀P]→¬∀¬Q→∀P P? ∃Q→∀P
-- WLPO => PFP
wlpo⇒pfp : ∀ {a p} q {A : Set a} → Inhabited A → WLPO A p → PFP A p q
wlpo⇒pfp {p = p} q xA wlpo {P = P} P? with wlpo P?
... | inj₁ ∀P = (λ _ → Lift q ⊤) , (λ _ → inj₁ (lift tt)) , (f , g)
where
f : (∀ x → P x) → ∃ λ x → Lift q ⊤
f _ = xA , lift tt
g : (∃ λ x → Lift q ⊤) → (∀ x → P x)
g _ = ∀P
... | inj₂ ¬∀P = (λ _ → Lift q ⊥) , (λ _ → inj₂ lower) , f , g
where
f : (∀ x → P x) → ∃ (λ x → Lift q ⊥)
f ∀P = ⊥-elim $ ¬∀P ∀P
g : ∃ (λ x → Lift q ⊥) → ∀ x → P x
g (x , L⊥) = ⊥-elim $ lower L⊥
-- WLPO => WPFP
wlpo⇒wpfp : ∀ {a p} q {A : Set a} → Inhabited A → WLPO A p → WPFP A p q
wlpo⇒wpfp q xA wlpo = pfp⇒wpfp (wlpo⇒pfp q xA wlpo)
-- Proposition 6.2.3 [1]
-- WPFP ∧ MP⊎-Alt => WLPO
wpfp∧mp⊎-Alt⇒wlpo : ∀ {a p} {A : Set a} → WPFP A p p → MP⊎-Alt A p → WLPO A p
wpfp∧mp⊎-Alt⇒wlpo wpfp mp⊎-Alt {P = P} P? with wpfp P?
... | Q , Q? , ∀P→¬∀Q , ¬∀Q→∀P = Sum.map₁ ¬∀Q→∀P (Sum.swap ¬∀P⊎¬∀Q)
where
¬[∀P×∀Q] : ¬ ((∀ x → P x) × (∀ x → Q x))
¬[∀P×∀Q] (∀P , ∀Q) = ∀P→¬∀Q ∀P ∀Q
¬∀P⊎¬∀Q : ¬ (∀ x → P x) ⊎ ¬ (∀ x → Q x)
¬∀P⊎¬∀Q = mp⊎-Alt P? Q? ¬[∀P×∀Q]
-- WPFP ∧ LLPO-Alt => WLPO
wpfp∧llpo-Alt⇒wlpo : ∀ {a p} {A : Set a} → WPFP A p p → LLPO-Alt A p → WLPO A p
wpfp∧llpo-Alt⇒wlpo wpfp llpo-Alt {P = P} P? with wpfp P?
... | Q , Q? , ∀P→¬∀Q , ¬∀Q→∀P = Sum.map₂ (λ ∀Q ∀P → ∀P→¬∀Q ∀P ∀Q) ∀P⊎∀Q
where
∀P⊎∀Q : (∀ x → P x) ⊎ (∀ x → Q x)
∀P⊎∀Q = llpo-Alt P? Q? (DN-map (Sum.swap ∘′ Sum.map₂ ¬∀Q→∀P) DN-Dec⊎)
-- WPFP ∧ MR <=> LPO
wpfp∧mr⇒lpo : ∀ {a p} {A : Set a} → WPFP A p p → MR A p → LPO A p
wpfp∧mr⇒lpo wpfp mr =
wlpo-Alt∧mr⇒lpo (wlpo⇒wlpo-Alt (wpfp∧mp⊎-Alt⇒wlpo wpfp (mp⊎⇒mp⊎-Alt
(mp∨⇒mp⊎ (mr⇒mp∨ mr)))))
mr
-- Proposition 1.2.1.2 in [1]
{-
lpo⇒P1212 : ∀ {p} → LPO ℕ p →
{P : ℕ → Set p} → DecU P →
(∃ λ N → ∀ n → N ≤ n → ¬ P n) ⊎ (Σ (ℕ → ℕ) λ k → ∀ n → P (k n))
lpo⇒P1212 {p} lpo {P} P? = {! !}
where
R : ℕ → Set p
R k = ∀ n → k ≤ n → ¬ P n
-- use lpo
R? : DecU R
R? k = ?
-}
-- Searchable set
-- Searchable <=> Inhabited ∧ LPO
searchable⇒lpo : ∀ {a p} {A : Set a} → Searchable A p → LPO A p
searchable⇒lpo searchable P? with searchable (¬-DecU P?)
... | x₀ , ¬Px₀→∀¬P = Sum.[ (λ Px₀ → inj₁ (x₀ , Px₀)) ,
(λ ¬Px₀ → inj₂ (∀¬P→¬∃P (¬Px₀→∀¬P ¬Px₀))) ]′
(P? x₀)
searchable⇒inhabited : ∀ {a p} {A : Set a} →
Searchable A p → Inhabited A
searchable⇒inhabited {p = p} searchable =
proj₁ (searchable {P = λ _ → Lift p ⊤} λ _ → inj₁ (lift tt))
inhabited∧lpo⇒searchable : ∀ {a p} {A : Set a} →
Inhabited A → LPO A p → Searchable A p
inhabited∧lpo⇒searchable inhabited lpo P? with lpo (¬-DecU P?)
... | inj₁ (x , ¬Px) = x , (λ Px → contradiction Px ¬Px)
... | inj₂ ¬∃¬P = inhabited , (λ _ → P?⇒¬∃¬P→∀P P? ¬∃¬P)
-- [1] Hannes Diener "Constructive Reverse Mathematics"
-- [2] Hajime lshihara "Markov’s principle, Church’s thesis and LindeUf’s theorem"
|
{
"alphanum_fraction": 0.4437779999,
"avg_line_length": 34.6269230769,
"ext": "agda",
"hexsha": "cb19637a9f5179415875ccc4391a9b8ff29f8c6e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Constructive/Axiom/Properties/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Constructive/Axiom/Properties/Base.agda",
"max_line_length": 88,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Constructive/Axiom/Properties/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 14283,
"size": 27009
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
{-
This file shows that the property of the natural numbers being a homotopy-initial algebra of
the functor (1 + _) is equivalent to fulfilling a closely related inductive elimination principle.
Proofing the latter is trivial, since the typechecker does the work for us.
For details see the paper [Homotopy-initial algebras in type theory](https://arxiv.org/abs/1504.05531)
by Steve Awodey, Nicola Gambino and Kristina Sojakova.
-}
module Cubical.Data.Nat.Algebra where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
hiding (section)
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Reflection.StrictEquiv
open import Cubical.Data.Nat.Base
private
variable
ℓ ℓ' : Level
record NatAlgebra ℓ : Type (ℓ-suc ℓ) where
field
Carrier : Type ℓ
alg-zero : Carrier
alg-suc : Carrier → Carrier
record NatMorphism (A : NatAlgebra ℓ) (B : NatAlgebra ℓ') : Type (ℓ-max ℓ ℓ') where
open NatAlgebra
field
morph : A .Carrier → B .Carrier
comm-zero : morph (A .alg-zero) ≡ B .alg-zero
comm-suc : morph ∘ A .alg-suc ≡ B .alg-suc ∘ morph
record NatFiber (N : NatAlgebra ℓ') ℓ : Type (ℓ-max ℓ' (ℓ-suc ℓ)) where
open NatAlgebra N
field
Fiber : Carrier → Type ℓ
fib-zero : Fiber alg-zero
fib-suc : ∀ {n} → Fiber n → Fiber (alg-suc n)
record NatSection {N : NatAlgebra ℓ'} (F : NatFiber N ℓ) : Type (ℓ-max ℓ' ℓ) where
open NatAlgebra N
open NatFiber F
field
section : ∀ n → Fiber n
sec-comm-zero : section alg-zero ≡ fib-zero
sec-comm-suc : ∀ n → section (alg-suc n) ≡ fib-suc (section n)
isNatHInitial : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ))
isNatHInitial N ℓ = (M : NatAlgebra ℓ) → isContr (NatMorphism N M)
isNatInductive : NatAlgebra ℓ' → (ℓ : Level) → Type (ℓ-max ℓ' (ℓ-suc ℓ))
isNatInductive N ℓ = (S : NatFiber N ℓ) → NatSection S
module AlgebraPropositionality {N : NatAlgebra ℓ'} where
open NatAlgebra N
isPropIsNatHInitial : isProp (isNatHInitial N ℓ)
isPropIsNatHInitial = isPropΠ (λ _ → isPropIsContr)
-- under the assumption that some shape is nat-inductive, the type of sections over any fiber
-- is propositional
module SectionProp (ind : isNatInductive N ℓ) {F : NatFiber N ℓ} (S T : NatSection F) where
open NatFiber
open NatSection
ConnectingFiber : NatFiber N ℓ
Fiber ConnectingFiber n = S .section n ≡ T .section n
fib-zero ConnectingFiber = S .sec-comm-zero ∙∙ refl ∙∙ sym (T .sec-comm-zero)
fib-suc ConnectingFiber {n} sntn = S .sec-comm-suc n ∙∙ (λ i → F .fib-suc (sntn i)) ∙∙ sym (T .sec-comm-suc n)
open NatSection (ind ConnectingFiber)
renaming (section to α ; sec-comm-zero to ζ ; sec-comm-suc to σ)
squeezeSquare : ∀{a}{A : Type a}{w x y z : A} (p : w ≡ x) {q : x ≡ y} (r : z ≡ y)
→ (P : w ≡ z) → (sq : P ≡ p ∙∙ q ∙∙ sym r) → I → I → A
squeezeSquare p {q} r P sq i j = transport (sym (PathP≡doubleCompPathʳ p P q r)) sq i j
S≡T : S ≡ T
section (S≡T i) n = α n i
sec-comm-zero (S≡T i) j = squeezeSquare (S .sec-comm-zero) (T .sec-comm-zero) (α alg-zero) ζ j i
sec-comm-suc (S≡T i) n j = squeezeSquare (S .sec-comm-suc n) (T .sec-comm-suc n) (α (alg-suc n)) (σ n) j i
isPropIsNatInductive : isProp (isNatInductive N ℓ)
isPropIsNatInductive a b i F = SectionProp.S≡T a (a F) (b F) i
module AlgebraHInd→HInit {N : NatAlgebra ℓ'} (ind : isNatInductive N ℓ) (M : NatAlgebra ℓ) where
open NatAlgebra
open NatFiber
ConstFiberM : NatFiber N ℓ
Fiber ConstFiberM _ = M .Carrier
fib-zero ConstFiberM = M .alg-zero
fib-suc ConstFiberM = M .alg-suc
morph→section : NatMorphism N M → NatSection ConstFiberM
morph→section x = record { section = morph ; sec-comm-zero = comm-zero ; sec-comm-suc = λ i n → comm-suc n i }
where open NatMorphism x
section→morph : NatSection ConstFiberM → NatMorphism N M
section→morph x = record { morph = section ; comm-zero = sec-comm-zero ; comm-suc = λ n i → sec-comm-suc i n }
where open NatSection x
Morph≡Section : NatSection ConstFiberM ≡ NatMorphism N M
Morph≡Section = ua e
where
unquoteDecl e = declStrictEquiv e section→morph morph→section
isContrMorph : isContr (NatMorphism N M)
isContrMorph = subst isContr Morph≡Section (inhProp→isContr (ind ConstFiberM) (AlgebraPropositionality.SectionProp.S≡T ind))
open NatAlgebra
open NatFiber
open NatSection
open NatMorphism
module AlgebraHInit→Ind (N : NatAlgebra ℓ') ℓ (hinit : isNatHInitial N (ℓ-max ℓ' ℓ)) (F : NatFiber N (ℓ-max ℓ' ℓ)) where
ΣAlgebra : NatAlgebra (ℓ-max ℓ' ℓ)
Carrier ΣAlgebra = Σ (N .Carrier) (F .Fiber)
alg-zero ΣAlgebra = N .alg-zero , F .fib-zero
alg-suc ΣAlgebra (n , fn) = N .alg-suc n , F .fib-suc fn
-- the fact that we have to lift the Carrier obstructs readability a bit
-- this is the same algebra as N, but lifted into the correct universe
LiftN : NatAlgebra (ℓ-max ℓ' ℓ)
Carrier LiftN = Lift {_} {ℓ} (N .Carrier)
alg-zero LiftN = lift (N .alg-zero)
alg-suc LiftN = lift ∘ N .alg-suc ∘ lower
_!_ : ∀ {x y} → x ≡ y → F .Fiber x → F .Fiber y
_!_ = subst (F .Fiber)
-- from homotopy initiality of N we get
-- 1) an algebra morphism μ from N → Σ N F together with proofs of commutativity with the algebras
-- 2) projecting out the first component after μ, called α, will turn out to be the identity function
-- 3) witnesses that μ respects the definitions given in ΣAlgebra
-- a) at zero the witnesses are ζ and ζ-h
-- b) at suc the witnesses are σ and σ-h
open NatMorphism (hinit ΣAlgebra .fst) renaming (morph to μ ; comm-zero to μ-zc ; comm-suc to μ-sc)
module _ n where open Σ (μ n) public renaming (fst to α ; snd to α-h)
-- module _ i where open Σ (μ-zc i) public renaming (fst to ζ ; snd to ζ-h)
ζ : α (N .alg-zero) ≡ N .alg-zero
ζ i = μ-zc i .fst
ζ-h : PathP (λ i → F .Fiber (ζ i)) (α-h (N .alg-zero)) (F .fib-zero)
ζ-h i = μ-zc i .snd
-- module _ n i where open Σ (μ-sc i n) public renaming (fst to σ ; snd to σ-h)
σ : ∀ n → α (N .alg-suc n) ≡ N .alg-suc (α n)
σ n i = μ-sc i n .fst
σ-h : ∀ n → PathP (λ i → F .Fiber (σ n i)) (α-h (N .alg-suc n)) (F .fib-suc (α-h n))
σ-h n i = μ-sc i n .snd
-- liftMorph would be the identity morphism if it weren't for size issues
liftMorph : NatMorphism N LiftN
liftMorph = record { morph = lift ; comm-zero = refl ; comm-suc = refl }
-- instead of abstractly defining morphism composition and a projection algebra morphism
-- from Σ N F → N, define the composite directly. comm-zero and comm-suc thus are
-- defined without path composition
fst∘μ : NatMorphism N LiftN
morph fst∘μ = lift ∘ α
comm-zero fst∘μ i = lift (ζ i)
comm-suc fst∘μ i n = lift (σ n i)
fst∘μ≡id : fst∘μ ≡ liftMorph
fst∘μ≡id = isContr→isProp (hinit LiftN) _ _
-- we get a proof that the index is preserved uniformly
P : ∀ n → α n ≡ n
P n i = lower (fst∘μ≡id i .morph n)
-- we also have proofs that α cancels after the algebra of N
Q-zero : α (N .alg-zero) ≡ N .alg-zero
Q-zero = ζ
Q-suc : ∀ n → α (N .alg-suc n) ≡ N .alg-suc n
Q-suc n = σ n ∙ cong (N .alg-suc) (P n)
-- but P and Q are the same up to homotopy
P-zero : P (N .alg-zero) ≡ Q-zero
P-zero i j = hcomp (λ k → λ where
(i = i0) → lower (fst∘μ≡id j .comm-zero (~ k))
(i = i1) → ζ (j ∨ ~ k)
(j = i0) → ζ (~ k)
(j = i1) → N .alg-zero
) (N .alg-zero)
P-suc : ∀ n → P (N .alg-suc n) ≡ Q-suc n
P-suc n i j = hcomp (λ k → λ where
(i = i0) → lower (fst∘μ≡id j .comm-suc (~ k) n)
(i = i1) → compPath-filler' (σ n) (cong (N .alg-suc) (P n)) k j
(j = i0) → σ n (~ k)
(j = i1) → N .alg-suc n
) (N .alg-suc (P n j))
Fsection : NatSection F
section Fsection n = P n ! α-h n
sec-comm-zero Fsection =
P (N .alg-zero) ! α-h (N .alg-zero)
≡[ i ]⟨ P-zero i ! α-h _ ⟩
Q-zero ! α-h (N .alg-zero)
≡⟨ fromPathP ζ-h ⟩
F .fib-zero
∎
sec-comm-suc Fsection n =
P (N .alg-suc n) ! α-h (N .alg-suc n)
≡[ i ]⟨ P-suc n i ! α-h _ ⟩
Q-suc n ! α-h (N .alg-suc n)
≡⟨ substComposite (F .Fiber) (σ n) (cong (N .alg-suc) (P n)) _ ⟩
cong (N .alg-suc) (P n) ! (σ n ! α-h (N .alg-suc n))
≡[ i ]⟨ cong (N .alg-suc) (P n) ! fromPathP (σ-h n) i ⟩
cong (N .alg-suc) (P n) ! (F .fib-suc (α-h n))
≡⟨ substCommSlice (F .Fiber) (F .Fiber ∘ N .alg-suc) (λ _ → F .fib-suc) (P n) (α-h n) ⟩
F .fib-suc (P n ! α-h n)
∎
isNatInductive≡isNatHInitial : {N : NatAlgebra ℓ'} (ℓ : Level)
→ isNatInductive N (ℓ-max ℓ' ℓ) ≡ isNatHInitial N (ℓ-max ℓ' ℓ)
isNatInductive≡isNatHInitial {_} {N} ℓ = hPropExt isPropIsNatInductive isPropIsNatHInitial ind→init init→ind where
open AlgebraPropositionality
open AlgebraHInit→Ind N ℓ renaming (Fsection to init→ind)
open AlgebraHInd→HInit renaming (isContrMorph to ind→init)
-- given two homotopy initial algebras there is a path between the algebras
-- this implies moreover that the carrier types are isomorphic
-- according to 5.16 in the paper this could be strengthened to isContr (N ≡ M)
isNatHInitial→algebraPath : {N M : NatAlgebra ℓ}
→ (hinitN : isNatHInitial N ℓ) (hinitM : isNatHInitial M ℓ)
→ N ≡ M
isNatHInitial→algebraPath {N = N} {M} hinitN hinitM = N≡M where
open Σ (hinitN M) renaming (fst to N→M)
open Σ (hinitM N) renaming (fst to M→N)
idN : NatMorphism N N
idN = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl }
idM : NatMorphism M M
idM = record { morph = λ x → x ; comm-zero = refl ; comm-suc = refl }
N→M→N : NatMorphism N N
morph N→M→N = morph M→N ∘ morph N→M
comm-zero N→M→N = (λ i → morph M→N (comm-zero N→M i)) ∙ comm-zero M→N
comm-suc N→M→N = (λ i → morph M→N ∘ comm-suc N→M i) ∙ (λ i → comm-suc M→N i ∘ morph N→M)
nmn≡idn : N→M→N ≡ idN
nmn≡idn = isContr→isProp (hinitN N) _ _
M→N→M : NatMorphism M M
morph M→N→M = morph N→M ∘ morph M→N
comm-zero M→N→M = (λ i → morph N→M (comm-zero M→N i)) ∙ comm-zero N→M
comm-suc M→N→M = (λ i → morph N→M ∘ comm-suc M→N i) ∙ (λ i → comm-suc N→M i ∘ morph M→N)
mnm≡idm : M→N→M ≡ idM
mnm≡idm = isContr→isProp (hinitM M) _ _
carrier≡ : N .Carrier ≡ M .Carrier
carrier≡ = isoToPath (iso (N→M .morph) (M→N .morph) (λ x i → mnm≡idm i .morph x) (λ x i → nmn≡idn i .morph x))
zero≡ : PathP (λ i → carrier≡ i) (N .alg-zero) (M .alg-zero)
zero≡ = toPathP λ i → transportRefl (N→M .comm-zero i) i
suc≡ : PathP (λ i → carrier≡ i → carrier≡ i) (N .alg-suc) (M .alg-suc)
suc≡ = toPathP (
transport refl ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transport refl
≡[ i ]⟨ transportReflF i ∘ N→M .morph ∘ N .alg-suc ∘ M→N .morph ∘ transportReflF i ⟩
N→M .morph ∘ N .alg-suc ∘ M→N .morph
≡[ i ]⟨ N→M .comm-suc i ∘ M→N .morph ⟩
M .alg-suc ∘ N→M .morph ∘ M→N .morph
≡[ i ]⟨ M .alg-suc ∘ mnm≡idm i .morph ⟩
M .alg-suc
∎) where
transportReflF : transport refl ≡ (λ x → x)
transportReflF = funExt transportRefl
N≡M : N ≡ M
Carrier (N≡M i) = carrier≡ i
alg-zero (N≡M i) = zero≡ i
alg-suc (N≡M i) = suc≡ i
-- the payoff, it is straight forward to define the algebra and show inductiveness of ℕ
NatAlgebraℕ : NatAlgebra ℓ-zero
Carrier NatAlgebraℕ = ℕ
alg-zero NatAlgebraℕ = zero
alg-suc NatAlgebraℕ = suc
isNatInductiveℕ : isNatInductive NatAlgebraℕ ℓ
section (isNatInductiveℕ F) = nat-sec where
nat-sec : ∀ n → F .Fiber n
nat-sec zero = F .fib-zero
nat-sec (suc n) = F .fib-suc (nat-sec n)
sec-comm-zero (isNatInductiveℕ F) = refl
sec-comm-suc (isNatInductiveℕ F) n = refl
isNatHInitialℕ : isNatHInitial NatAlgebraℕ ℓ
isNatHInitialℕ = transport (isNatInductive≡isNatHInitial _) isNatInductiveℕ
|
{
"alphanum_fraction": 0.6330762213,
"avg_line_length": 40.19,
"ext": "agda",
"hexsha": "26b424e98ca018a0284cc40e2076c09b69d58b40",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Data/Nat/Algebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Data/Nat/Algebra.agda",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Data/Nat/Algebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4607,
"size": 12057
}
|
------------------------------------------------------------------------
-- A variant of Paolo Capriotti's variant of higher lenses
------------------------------------------------------------------------
{-# OPTIONS --cubical #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Capriotti.Variant
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id)
open import Bijection equality-with-J as B using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as T using (∥_∥; ∣_∣)
open import Preimage equality-with-J as Preimage
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq
import Lens.Non-dependent.Higher eq as Higher
private
variable
a b p : Level
A B : Type a
P Q : A → Type p
------------------------------------------------------------------------
-- Coherently-constant
-- Coherently constant type-valued functions.
--
-- This definition is based on Paolo Capriotti's definition of higher
-- lenses, but uses a family of equivalences instead of an equality.
Coherently-constant :
{A : Type a} → (A → Type p) → Type (a ⊔ lsuc p)
Coherently-constant {p = p} {A = A} P =
∃ λ (Q : ∥ A ∥ → Type p) → ∀ x → P x ≃ Q ∣ x ∣
-- A preservation lemma for Coherently-constant.
--
-- Note that P and Q must target the same universe.
Coherently-constant-map :
{P : A → Type p} {Q : B → Type p}
(f : B → A) →
(∀ x → P (f x) ≃ Q x) →
Coherently-constant P → Coherently-constant Q
Coherently-constant-map {P = P} {Q = Q} f P≃Q (R , P≃R) =
R ∘ T.∥∥-map f
, λ x →
Q x ↝⟨ inverse $ P≃Q x ⟩
P (f x) ↝⟨ P≃R (f x) ⟩□
R ∣ f x ∣ □
-- Coherently-constant is, in a certain sense, closed under Σ.
--
-- This lemma is due to Paolo Capriotti.
Coherently-constant-Σ :
Coherently-constant P →
Coherently-constant Q →
Coherently-constant (λ x → ∃ λ (y : P x) → Q (x , y))
Coherently-constant-Σ {P = P} {Q = Q} (P′ , p) (Q′ , q) =
(λ x → ∃ λ (y : P′ x) →
Q′ (T.elim
(λ x → P′ x → ∥ ∃ P ∥)
(λ _ → Π-closure ext 1 λ _ →
T.truncation-is-proposition)
(λ x y → ∣ x , _≃_.from (p x) y ∣)
x y))
, (λ x →
(∃ λ (y : P x) → Q (x , y)) ↝⟨ (Σ-cong (p x) λ y →
Q (x , y) ↝⟨ q (x , y) ⟩
Q′ ∣ x , y ∣ ↝⟨ ≡⇒≃ $ cong Q′ $ T.truncation-is-proposition _ _ ⟩□
Q′ ∣ x , _≃_.from (p x) (_≃_.to (p x) y) ∣ □) ⟩□
(∃ λ (y : P′ ∣ x ∣) → Q′ ∣ x , _≃_.from (p x) y ∣) □)
------------------------------------------------------------------------
-- The lens type family
-- Paolo Capriotti's variant of higher lenses, but with a family of
-- equivalences instead of an equality.
Lens : Type a → Type b → Type (lsuc (a ⊔ b))
Lens A B = ∃ λ (get : A → B) → Coherently-constant (get ⁻¹_)
-- Some derived definitions (based on Capriotti's).
module Lens {A : Type a} {B : Type b} (l : Lens A B) where
-- A getter.
get : A → B
get = proj₁ l
-- A predicate.
H : Pow a ∥ B ∥
H = proj₁ (proj₂ l)
-- An equivalence.
get⁻¹-≃ : ∀ b → get ⁻¹ b ≃ H ∣ b ∣
get⁻¹-≃ = proj₂ (proj₂ l)
-- All the getter's "preimages" are equivalent.
get⁻¹-constant : (b₁ b₂ : B) → get ⁻¹ b₁ ≃ get ⁻¹ b₂
get⁻¹-constant b₁ b₂ =
get ⁻¹ b₁ ↝⟨ get⁻¹-≃ b₁ ⟩
H ∣ b₁ ∣ ↝⟨ ≡⇒≃ $ cong H $ T.truncation-is-proposition _ _ ⟩
H ∣ b₂ ∣ ↝⟨ inverse $ get⁻¹-≃ b₂ ⟩□
get ⁻¹ b₂ □
-- The two directions of get⁻¹-constant.
get⁻¹-const : (b₁ b₂ : B) → get ⁻¹ b₁ → get ⁻¹ b₂
get⁻¹-const b₁ b₂ = _≃_.to (get⁻¹-constant b₁ b₂)
get⁻¹-const⁻¹ : (b₁ b₂ : B) → get ⁻¹ b₂ → get ⁻¹ b₁
get⁻¹-const⁻¹ b₁ b₂ = _≃_.from (get⁻¹-constant b₁ b₂)
-- Some coherence properties.
get⁻¹-const-∘ :
(b₁ b₂ b₃ : B) (p : get ⁻¹ b₁) →
get⁻¹-const b₂ b₃ (get⁻¹-const b₁ b₂ p) ≡ get⁻¹-const b₁ b₃ p
get⁻¹-const-∘ b₁ b₂ b₃ p =
_≃_.from (get⁻¹-≃ b₃)
(≡⇒→ (cong H $ T.truncation-is-proposition _ _)
(_≃_.to (get⁻¹-≃ b₂)
(_≃_.from (get⁻¹-≃ b₂)
(≡⇒→ (cong H $ T.truncation-is-proposition _ _)
(_≃_.to (get⁻¹-≃ b₁) p))))) ≡⟨ cong (_≃_.from (get⁻¹-≃ _) ∘ ≡⇒→ _) $
_≃_.right-inverse-of (get⁻¹-≃ _) _ ⟩
_≃_.from (get⁻¹-≃ b₃)
(≡⇒→ (cong H $ T.truncation-is-proposition _ _)
(≡⇒→ (cong H $ T.truncation-is-proposition _ _)
(_≃_.to (get⁻¹-≃ b₁) p))) ≡⟨ cong (λ eq → _≃_.from (get⁻¹-≃ _) (_≃_.to eq (_≃_.to (get⁻¹-≃ _) _))) $ sym $
≡⇒≃-trans ext _ _ ⟩
_≃_.from (get⁻¹-≃ b₃)
(≡⇒→ (trans (cong H $ T.truncation-is-proposition _ _)
(cong H $ T.truncation-is-proposition _ _))
(_≃_.to (get⁻¹-≃ b₁) p)) ≡⟨ cong (λ eq → _≃_.from (get⁻¹-≃ b₃) (≡⇒→ eq _)) $
trans (sym $ cong-trans _ _ _) $
cong (cong H) $ mono₁ 1 T.truncation-is-proposition _ _ ⟩∎
_≃_.from (get⁻¹-≃ b₃)
(≡⇒→ (cong H $ T.truncation-is-proposition _ _)
(_≃_.to (get⁻¹-≃ b₁) p)) ∎
get⁻¹-const-id :
(b : B) (p : get ⁻¹ b) → get⁻¹-const b b p ≡ p
get⁻¹-const-id b p =
get⁻¹-const b b p ≡⟨ sym $ _≃_.left-inverse-of (get⁻¹-constant _ _) _ ⟩
get⁻¹-const⁻¹ b b (get⁻¹-const b b (get⁻¹-const b b p)) ≡⟨ cong (get⁻¹-const⁻¹ b b) $ get⁻¹-const-∘ _ _ _ _ ⟩
get⁻¹-const⁻¹ b b (get⁻¹-const b b p) ≡⟨ _≃_.left-inverse-of (get⁻¹-constant _ _) _ ⟩∎
p ∎
get⁻¹-const-inverse :
(b₁ b₂ : B) (p : get ⁻¹ b₁) →
get⁻¹-const b₁ b₂ p ≡ get⁻¹-const⁻¹ b₂ b₁ p
get⁻¹-const-inverse b₁ b₂ p =
sym $ _≃_.to-from (get⁻¹-constant _ _) (
get⁻¹-const b₂ b₁ (get⁻¹-const b₁ b₂ p) ≡⟨ get⁻¹-const-∘ _ _ _ _ ⟩
get⁻¹-const b₁ b₁ p ≡⟨ get⁻¹-const-id _ _ ⟩∎
p ∎)
-- A setter.
set : A → B → A
set a b = $⟨ get⁻¹-const _ _ ⟩
(get ⁻¹ get a → get ⁻¹ b) ↝⟨ _$ (a , refl _) ⟩
get ⁻¹ b ↝⟨ proj₁ ⟩□
A □
-- Lens laws.
get-set : ∀ a b → get (set a b) ≡ b
get-set a b =
get (proj₁ (get⁻¹-const (get a) b (a , refl _))) ≡⟨ proj₂ (get⁻¹-const (get a) b (a , refl _)) ⟩∎
b ∎
set-get : ∀ a → set a (get a) ≡ a
set-get a =
proj₁ (get⁻¹-const (get a) (get a) (a , refl _)) ≡⟨ cong proj₁ $ get⁻¹-const-id _ _ ⟩∎
a ∎
set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
set-set a b₁ b₂ =
proj₁ (get⁻¹-const (get (set a b₁)) b₂ (set a b₁ , refl _)) ≡⟨ elim¹
(λ {b} eq →
proj₁ (get⁻¹-const (get (set a b₁)) b₂ (set a b₁ , refl _)) ≡
proj₁ (get⁻¹-const b b₂ (set a b₁ , eq)))
(refl _)
(get-set a b₁) ⟩
proj₁ (get⁻¹-const b₁ b₂ (set a b₁ , get-set a b₁)) ≡⟨⟩
proj₁ (get⁻¹-const b₁ b₂
(get⁻¹-const (get a) b₁ (a , refl _))) ≡⟨ cong proj₁ $ get⁻¹-const-∘ _ _ _ _ ⟩∎
proj₁ (get⁻¹-const (get a) b₂ (a , refl _)) ∎
-- TODO: Can get-set-get and get-set-set be proved for the lens laws
-- given above?
instance
-- The lenses defined above have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
------------------------------------------------------------------------
-- Equality characterisation lemmas
-- An equality characterisation lemma.
equality-characterisation₁ :
{A : Type a} {B : Type b} {l₁ l₂ : Lens A B} →
Block "equality-characterisation" →
let open Lens in
(l₁ ≡ l₂)
≃
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b p →
subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym g) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p)
equality-characterisation₁ {a = a} {l₁ = l₁} {l₂ = l₂} ⊠ =
l₁ ≡ l₂ ↝⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ Σ-assoc ⟩
((get l₁ , H l₁) , get⁻¹-≃ l₁) ≡ ((get l₂ , H l₂) , get⁻¹-≃ l₂) ↔⟨ inverse B.Σ-≡,≡↔≡ ⟩
(∃ λ (eq : (get l₁ , H l₁) ≡ (get l₂ , H l₂)) →
subst (λ (g , H) → ∀ b → g ⁻¹ b ≃ H ∣ b ∣) eq (get⁻¹-≃ l₁) ≡
get⁻¹-≃ l₂) ↝⟨ (Σ-cong-contra ≡×≡↔≡ λ _ → F.id) ⟩
(∃ λ ((g , h) : get l₁ ≡ get l₂ × H l₁ ≡ H l₂) →
subst (λ (g , H) → ∀ b → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁) ≡
get⁻¹-≃ l₂) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
subst (λ (g , H) → ∀ b → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁) ≡
get⁻¹-≃ l₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse $
Eq.extensionality-isomorphism ext) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b → subst (λ (g , H) → ∀ b → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁) b ≡
get⁻¹-≃ l₂ b) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_≡ _) $ sym $
push-subst-application _ _) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b → subst (λ (g , H) → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁ b) ≡
get⁻¹-≃ l₂ b) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → inverse $
≃-to-≡↔≡ ext) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b p →
_≃_.to (subst (λ (g , H) → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁ b)) p ≡
_≃_.to (get⁻¹-≃ l₂ b) p) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_≡ _) $ lemma _ _ _ _) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b p →
subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym g) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) □
where
open Lens
lemma : ∀ _ _ _ _ → _ ≡ _
lemma g h b p =
_≃_.to (subst (λ (g , H) → g ⁻¹ b ≃ H ∣ b ∣)
(cong₂ _,_ g h) (get⁻¹-≃ l₁ b)) p ≡⟨ cong (_$ p) Eq.to-subst ⟩
subst (λ (g , H) → g ⁻¹ b → H ∣ b ∣)
(cong₂ _,_ g h) (_≃_.to (get⁻¹-≃ l₁ b)) p ≡⟨ subst-→ ⟩
subst (λ (g , H) → H ∣ b ∣) (cong₂ _,_ g h)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (λ (g , H) → g ⁻¹ b) (sym $ cong₂ _,_ g h) p)) ≡⟨ subst-∘ _ _ _ ⟩
subst (_$ ∣ b ∣) (cong proj₂ $ cong₂ _,_ g h)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (λ (g , H) → g ⁻¹ b) (sym $ cong₂ _,_ g h) p)) ≡⟨ cong₂ (λ p q → subst (λ (H : Pow a _) → H ∣ b ∣)
p (_≃_.to (get⁻¹-≃ l₁ b) q))
(cong-proj₂-cong₂-, _ _)
(subst-∘ _ _ _) ⟩
subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (cong proj₁ $ sym $ cong₂ _,_ g h) p)) ≡⟨ cong (λ eq → subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) eq p))) $
trans (cong-sym _ _) $
cong sym $ cong-proj₁-cong₂-, _ _ ⟩∎
subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym g) p)) ∎
-- Another equality characterisation lemma.
equality-characterisation₂ :
{l₁ l₂ : Lens A B} →
Block "equality-characterisation" →
let open Lens in
(l₁ ≡ l₂)
≃
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p)
equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} ⊠ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⊠ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
∀ b p →
subst (_$ ∣ b ∣) h
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym g) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) ↝⟨ (Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ →
Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ →
F.id) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∀ b p →
subst (_$ ∣ b ∣) (⟨ext⟩ h)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_≡ _) $
subst-ext _ _) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) □
where
open Lens
-- Yet another equality characterisation lemma.
equality-characterisation₃ :
{A : Type a} {B : Type b}
{l₁ l₂ : Lens A B} →
Block "equality-characterisation" →
Univalence (a ⊔ b) →
let open Lens in
(l₁ ≡ l₂)
≃
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) →
∀ b p →
_≃_.to (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p)
equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} ⊠ univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⊠ ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) ↝⟨ (∃-cong λ _ →
Σ-cong-contra (∀-cong ext λ _ → inverse $ ≡≃≃ univ) λ _ → F.id) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) →
∀ b p →
subst P.id (≃⇒≡ univ (h ∣ b ∣))
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_≡ _) $
trans (subst-id-in-terms-of-≡⇒↝ equivalence) $
cong (λ eq → _≃_.to eq _) $
_≃_.right-inverse-of (≡≃≃ univ) _) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) →
∀ b p →
_≃_.to (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b) (subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) □
where
open Lens
------------------------------------------------------------------------
-- Conversion functions
-- The lenses defined above can be converted to and from the lenses
-- defined in Higher.
Lens⇔Higher-lens : Lens A B ⇔ Higher.Lens A B
Lens⇔Higher-lens {A = A} {B = B} = record
{ to = λ (g , H , eq) → record
{ R = Σ ∥ B ∥ H
; equiv =
A ↔⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩
(∃ λ (a : A) → ∃ λ (b : B) → g a ≡ b) ↔⟨ ∃-comm ⟩
(∃ λ (b : B) → g ⁻¹ b) ↝⟨ ∃-cong eq ⟩
(∃ λ (b : B) → H ∣ b ∣) ↝⟨ (Σ-cong (inverse T.∥∥×≃) λ _ → ≡⇒↝ _ $ cong H $ T.truncation-is-proposition _ _) ⟩
(∃ λ ((b , _) : ∥ B ∥ × B) → H b) ↔⟨ Σ-assoc F.∘
(∃-cong λ _ → ×-comm) F.∘
inverse Σ-assoc ⟩□
Σ ∥ B ∥ H × B □
; inhabited = proj₁
}
; from = λ l →
Higher.Lens.get l
, (λ _ → Higher.Lens.R l)
, (λ b → inverse (Higher.remainder≃get⁻¹ l b))
}
-- The conversion preserves getters and setters.
Lens⇔Higher-lens-preserves-getters-and-setters :
Preserves-getters-and-setters-⇔ A B Lens⇔Higher-lens
Lens⇔Higher-lens-preserves-getters-and-setters =
(λ l@(g , H , eq) →
refl _
, ⟨ext⟩ λ a → ⟨ext⟩ λ b →
let h₁ = _≃_.to (eq (g a)) (a , refl _)
h₂ =
_≃_.from (≡⇒≃ (cong H _))
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _))
(≡⇒→ (cong H _) h₁))
h₃ = ≡⇒→ (cong H _) h₁
lemma =
h₂ ≡⟨ sym $ subst-in-terms-of-inverse∘≡⇒↝ equivalence _ _ _ ⟩
subst H _
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _))
(≡⇒→ (cong H _) h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _)
(subst (H ∘ proj₁)
(sym (_≃_.left-inverse-of T.∥∥×≃ (∣ g a ∣ , b)))
x)) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst H _
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of T.∥∥×≃ _))
(subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _) x) $
subst-∘ _ _ _ ⟩
subst H _ (subst H _ (subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ T.truncation-is-proposition _ _) x) $
subst-subst _ _ _ _ ⟩
subst H _ (subst H _ h₁) ≡⟨ subst-subst _ _ _ _ ⟩
subst H _ h₁ ≡⟨ cong (λ eq → subst H eq h₁) $
mono₁ 1 T.truncation-is-proposition _ _ ⟩
subst H _ h₁ ≡⟨ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩∎
≡⇒→ (cong H _) h₁ ∎
in
Higher.Lens.set (_⇔_.to Lens⇔Higher-lens l) a b ≡⟨⟩
proj₁ (_≃_.from (eq b) h₂) ≡⟨ cong (λ h → proj₁ (_≃_.from (eq b) h)) lemma ⟩
proj₁ (_≃_.from (eq b) h₃) ≡⟨⟩
Lens.set l a b ∎)
, (λ l →
refl _
, ⟨ext⟩ λ a → ⟨ext⟩ λ b →
Lens.set (_⇔_.from Lens⇔Higher-lens l) a b ≡⟨⟩
_≃_.from (Higher.Lens.equiv l)
( ≡⇒→ (cong (λ _ → Higher.Lens.R l) _)
(Higher.Lens.remainder l a)
, b
) ≡⟨ cong (λ eq → _≃_.from (Higher.Lens.equiv l) (≡⇒→ eq _ , b)) $
cong-const _ ⟩
_≃_.from (Higher.Lens.equiv l)
(≡⇒→ (refl _) (Higher.Lens.remainder l a) , b) ≡⟨ cong (λ f → _≃_.from (Higher.Lens.equiv l) (f _ , b)) $
≡⇒→-refl ⟩
_≃_.from (Higher.Lens.equiv l)
(Higher.Lens.remainder l a , b) ≡⟨⟩
Higher.Lens.set l a b ∎)
-- Lens A B is equivalent to Higher.Lens A B (assuming univalence).
Lens≃Higher-lens :
{A : Type a} {B : Type b} →
Block "conversion" →
Univalence (a ⊔ b) →
Lens A B ≃ Higher.Lens A B
Lens≃Higher-lens {A = A} {B = B} ⊠ univ =
Eq.↔→≃ to from to∘from from∘to
where
to = _⇔_.to Lens⇔Higher-lens
from = _⇔_.from Lens⇔Higher-lens
to∘from : ∀ l → to (from l) ≡ l
to∘from l = _↔_.from (Higher.equality-characterisation₂ ⊠ univ)
( (∥ B ∥ × R ↔⟨ (drop-⊤-left-× λ r → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
T.truncation-is-proposition
(inhabited r)) ⟩□
R □)
, (λ a →
≡⇒→ (cong (λ _ → R) (T.truncation-is-proposition _ _))
(remainder a) ≡⟨ cong (λ eq → ≡⇒→ eq _) $ cong-const _ ⟩
≡⇒→ (refl _) (remainder a) ≡⟨ cong (_$ _) ≡⇒→-refl ⟩∎
remainder a ∎)
, (λ _ → refl _)
)
where
open Higher.Lens l
from∘to : ∀ l → from (to l) ≡ l
from∘to l = _≃_.from (equality-characterisation₃ ⊠ univ)
( (λ _ → refl _)
, Σ∥B∥H≃H
, (λ b p@(a , get-a≡b) →
_≃_.to (Σ∥B∥H≃H ∣ b ∣)
(_≃_.from (Higher.remainder≃get⁻¹ (to l) b)
(subst (_⁻¹ b) (sym (⟨ext⟩ λ _ → refl _)) p)) ≡⟨ cong (_≃_.to (Σ∥B∥H≃H ∣ b ∣) ∘
_≃_.from (Higher.remainder≃get⁻¹ (to l) b)) $
trans (cong (flip (subst (_⁻¹ b)) p) $
trans (cong sym ext-refl) $
sym-refl) $
subst-refl _ _ ⟩
_≃_.to (Σ∥B∥H≃H ∣ b ∣)
(_≃_.from (Higher.remainder≃get⁻¹ (to l) b) p) ≡⟨⟩
_≃_.to (Σ∥B∥H≃H ∣ b ∣) (Higher.Lens.remainder (to l) a) ≡⟨⟩
subst H _
(≡⇒→ (cong H _) (_≃_.to (get⁻¹-≃ (get a)) (a , refl _))) ≡⟨ cong (subst H _) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst H _ (subst H _ (_≃_.to (get⁻¹-≃ (get a)) (a , refl _))) ≡⟨ subst-subst _ _ _ _ ⟩
subst H _ (_≃_.to (get⁻¹-≃ (get a)) (a , refl _)) ≡⟨ cong (λ eq → subst H eq (_≃_.to (get⁻¹-≃ (get a)) (a , refl _))) $
mono₁ 1 T.truncation-is-proposition _ _ ⟩
subst H (cong ∣_∣ get-a≡b)
(_≃_.to (get⁻¹-≃ (get a)) (a , refl _)) ≡⟨ elim¹
(λ {b} eq →
subst H (cong ∣_∣ eq)
(_≃_.to (get⁻¹-≃ (get a)) (a , refl _)) ≡
_≃_.to (get⁻¹-≃ b) (a , eq))
(
subst H (cong ∣_∣ (refl _))
(_≃_.to (get⁻¹-≃ (get a)) (a , refl _)) ≡⟨ trans (cong (flip (subst H) _) $ cong-refl _) $
subst-refl _ _ ⟩
_≃_.to (get⁻¹-≃ (get a)) (a , refl _) ∎)
_ ⟩∎
_≃_.to (get⁻¹-≃ b) p ∎)
)
where
open Lens l
Σ∥B∥H≃H = λ b →
Σ ∥ B ∥ H ↔⟨ (drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
T.truncation-is-proposition b) ⟩□
H b □
-- The equivalence preserves getters and setters.
Lens≃Higher-lens-preserves-getters-and-setters :
{A : Type a} {B : Type b}
(bl : Block "conversion")
(univ : Univalence (a ⊔ b)) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (Lens≃Higher-lens bl univ))
Lens≃Higher-lens-preserves-getters-and-setters ⊠ _ =
Lens⇔Higher-lens-preserves-getters-and-setters
------------------------------------------------------------------------
-- Identity
-- An identity lens.
id : {A : Type a} → Lens A A
id =
P.id
, (λ _ → ↑ _ ⊤)
, (λ a →
P.id ⁻¹ a ↔⟨ _⇔_.to contractible⇔↔⊤ $ Preimage.id⁻¹-contractible _ ⟩
⊤ ↔⟨ inverse B.↑↔ ⟩□
↑ _ ⊤ □)
------------------------------------------------------------------------
-- Some results related to fibres of Lens.set
-- When proving that Lens.set ⁻¹ s is a proposition, for
-- s : A → B → A, one can assume that B is inhabited.
--
-- This result is due to Andrea Vezzosi.
[codomain-inhabited→proposition]→proposition :
{s : A → B → A} →
(B → Is-proposition (Lens.set ⁻¹ s)) ≃
Is-proposition (Lens.set ⁻¹ s)
[codomain-inhabited→proposition]→proposition {B = B} {s = s} =
block λ b →
(B → Is-proposition (Lens.set ⁻¹ s)) ↝⟨ inverse $ T.universal-property (H-level-propositional ext 1) ⟩
(∥ B ∥ → Is-proposition (Lens.set ⁻¹ s)) ↔⟨⟩
(∥ B ∥ → (p q : Lens.set ⁻¹ s) → p ≡ q) ↔⟨ (∀-cong ext λ _ → Π-comm) F.∘ Π-comm ⟩
((p q : Lens.set ⁻¹ s) → ∥ B ∥ → p ≡ q) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → lemma b _ _) ⟩
((p q : Lens.set ⁻¹ s) → p ≡ q) ↔⟨⟩
Is-proposition (Lens.set ⁻¹ s) □
where
open Lens
lemma :
(b : Block "equality-characterisation") →
(p₁ p₂ : Lens.set ⁻¹ s) →
(∥ B ∥ → p₁ ≡ p₂) ≃ (p₁ ≡ p₂)
lemma b p₁@(l₁ , eq₁) p₂@(l₂ , eq₂) =
(∥ B ∥ → p₁ ≡ p₂) ↝⟨ (∀-cong ext λ _ → ec) ⟩
(∥ B ∥ →
∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ T.push-∥∥ (∣_∣ ∘ get l₁) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∥ B ∥ →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ (∃-cong λ _ → T.push-∥∥ P.id) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∥ B ∥ →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → T.push-∥∥ ∣_∣) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∥ B ∥ →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → T.drop-∥∥ (∣_∣ ∘ get l₁)) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ inverse ec ⟩□
p₁ ≡ p₂ □
where
ec =
p₁ ≡ p₂ ↔⟨ inverse B.Σ-≡,≡↔≡ ⟩
(∃ λ (l : l₁ ≡ l₂) →
subst (λ l → Lens.set l ≡ s) l eq₁ ≡ eq₂) ↝⟨ (∃-cong λ _ → inverse $
Eq.≃-≡ $ inverse $ Eq.extensionality-isomorphism ext) ⟩
(∃ λ (l : l₁ ≡ l₂) →
ext⁻¹ (subst (λ l → Lens.set l ≡ s) l eq₁) ≡ ext⁻¹ eq₂) ↝⟨ (∃-cong λ _ → inverse $
Eq.extensionality-isomorphism ext) ⟩
(∃ λ (l : l₁ ≡ l₂) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s) l eq₁) a ≡
ext⁻¹ eq₂ a) ↝⟨ (Σ-cong-contra (inverse $ equality-characterisation₂ b) λ _ → F.id) ⟩
(∃ λ (l : ∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
l) eq₁) a ≡
ext⁻¹ eq₂ a) ↔⟨ (∃-cong λ _ → inverse Σ-assoc) F.∘ inverse Σ-assoc ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
∃ λ (f : ∀ b p →
subst P.id (h ∣ b ∣)
(_≃_.to (get⁻¹-≃ l₁ b)
(subst (_⁻¹ b) (sym (⟨ext⟩ g)) p)) ≡
_≃_.to (get⁻¹-≃ l₂ b) p) →
∀ a → ext⁻¹ (subst (λ l → Lens.set l ≡ s)
(_≃_.from (equality-characterisation₂ b)
(g , h , f)) eq₁) a ≡
ext⁻¹ eq₂ a) □
-- The previous result holds also for the lenses in Higher (assuming
-- univalence).
[codomain-inhabited→proposition]→proposition-for-higher :
{A : Type a} {B : Type b} {s : A → B → A} →
Univalence (a ⊔ b) →
(B → Is-proposition (Higher.Lens.set ⁻¹ s)) ≃
Is-proposition (Higher.Lens.set ⁻¹ s)
[codomain-inhabited→proposition]→proposition-for-higher
{A = A} {B = B} {s = s} univ =
(B → Is-proposition (Higher.Lens.set ⁻¹ s)) ↝⟨ (∀-cong ext λ _ → H-level-cong ext 1 lemma) ⟩
(B → Is-proposition (Lens.set ⁻¹ s)) ↝⟨ [codomain-inhabited→proposition]→proposition ⟩
Is-proposition (Lens.set ⁻¹ s) ↝⟨ inverse $ H-level-cong ext 1 lemma ⟩□
Is-proposition (Higher.Lens.set ⁻¹ s) □
where
lemma : Higher.Lens.set ⁻¹ s ≃ Lens.set ⁻¹ s
lemma = block λ b →
(∃ λ (l : Higher.Lens A B) → Higher.Lens.set l ≡ s) ↝⟨ (Σ-cong (inverse $ Lens≃Higher-lens b univ) λ l →
≡⇒↝ _ $ cong (_≡ s) $ sym $ proj₂ $
proj₂ (Lens≃Higher-lens-preserves-getters-and-setters b univ) l) ⟩□
(∃ λ (l : Lens A B) → Lens.set l ≡ s) □
-- If a certain variant of Higher.lenses-equal-if-setters-equal can be
-- proved, then Higher.Lens.set ⁻¹ s is a proposition (assuming
-- univalence).
lenses-equal-if-setters-equal→set⁻¹-proposition :
{A : Type a} {B : Type b}
(univ : Univalence (a ⊔ b)) →
((l₁ l₂ : Higher.Lens A B) →
B →
(s : Higher.Lens.set l₁ ≡ Higher.Lens.set l₂) →
∃ λ (l : l₁ ≡ l₂) → cong Higher.Lens.set l ≡ s) →
(s : A → B → A) →
Is-proposition (Higher.Lens.set ⁻¹ s)
lenses-equal-if-setters-equal→set⁻¹-proposition
{B = B} univ lenses-equal-if-setters-equal s =
$⟨ lemma ⟩
(B → Is-proposition (Higher.Lens.set ⁻¹ s)) ↝⟨ [codomain-inhabited→proposition]→proposition-for-higher univ ⟩□
Is-proposition (Higher.Lens.set ⁻¹ s) □
where
lemma : B → Is-proposition (Higher.Lens.set ⁻¹ s)
lemma b (l₁ , set-l₁≡s) (l₂ , set-l₂≡s) = Σ-≡,≡→≡
lemma₁
(subst (λ l → set l ≡ s) lemma₁ set-l₁≡s ≡⟨ subst-∘ _ _ _ ⟩
subst (_≡ s) (cong set lemma₁) set-l₁≡s ≡⟨ subst-trans-sym ⟩
trans (sym (cong set lemma₁)) set-l₁≡s ≡⟨ cong (λ eq → trans (sym eq) set-l₁≡s) lemma₂ ⟩
trans (sym (trans set-l₁≡s (sym set-l₂≡s))) set-l₁≡s ≡⟨ cong (λ eq → trans eq set-l₁≡s) $ sym-trans _ _ ⟩
trans (trans (sym (sym set-l₂≡s)) (sym set-l₁≡s)) set-l₁≡s ≡⟨ trans-[trans-sym]- _ _ ⟩
sym (sym set-l₂≡s) ≡⟨ sym-sym _ ⟩∎
set-l₂≡s ∎)
where
open Higher.Lens
lemma′ =
lenses-equal-if-setters-equal l₁ l₂ b
(set l₁ ≡⟨ set-l₁≡s ⟩
s ≡⟨ sym set-l₂≡s ⟩∎
set l₂ ∎)
lemma₁ = proj₁ lemma′
lemma₂ = proj₂ lemma′
-- If a certain variant of Higher.lenses-equal-if-setters-equal can be
-- proved, then lenses with equal setters are equal (assuming
-- univalence).
lenses-equal-if-setters-equal→lenses-equal-if-setters-equal :
{A : Type a} {B : Type b} →
Univalence (a ⊔ b) →
((l₁ l₂ : Higher.Lens A B) →
B →
(s : Higher.Lens.set l₁ ≡ Higher.Lens.set l₂) →
∃ λ (l : l₁ ≡ l₂) → cong Higher.Lens.set l ≡ s) →
(l₁ l₂ : Higher.Lens A B) →
Higher.Lens.set l₁ ≡ Higher.Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal→lenses-equal-if-setters-equal
univ lenses-equal-if-setters-equal l₁ l₂ s =
cong proj₁ (
(l₁ , s) ≡⟨ lenses-equal-if-setters-equal→set⁻¹-proposition
univ lenses-equal-if-setters-equal (Higher.Lens.set l₂) _ _ ⟩∎
(l₂ , refl _) ∎)
|
{
"alphanum_fraction": 0.3809158002,
"avg_line_length": 43.7038369305,
"ext": "agda",
"hexsha": "0fb63f8925659b1f6e4d92fd34486bd8d5901bc7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant.agda",
"max_line_length": 144,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Capriotti/Variant.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 13164,
"size": 36449
}
|
module README where
------------------------------------------------------------------------
-- The Agda standard library, version 1.3
--
-- Authors: Nils Anders Danielsson, Matthew Daggitt, Guillaume Allais
-- with contributions from Andreas Abel, Stevan Andjelkovic,
-- Jean-Philippe Bernardy, Peter Berry, Bradley Hardy Joachim Breitner,
-- Samuel Bronson, Daniel Brown, Jacques Carette, James Chapman,
-- Liang-Ting Chen, Dominique Devriese, Dan Doel, Érdi Gergő,
-- Zack Grannan, Helmut Grohne, Simon Foster, Liyang Hu, Jason Hu,
-- Patrik Jansson, Alan Jeffrey, Wen Kokke, Evgeny Kotelnikov,
-- Sergei Meshveliani, Eric Mertens, Darin Morrison, Guilhem Moulin,
-- Shin-Cheng Mu, Ulf Norell, Noriyuki Ohkawa, Nicolas Pouillard,
-- Andrés Sicard-Ramírez, Lex van der Stoep, Sandro Stucki, Milo Turner,
-- Noam Zeilberger and other anonymous contributors.
------------------------------------------------------------------------
-- This version of the library has been tested using Agda 2.6.1.
-- The library comes with a .agda-lib file, for use with the library
-- management system.
-- Currently the library does not support the JavaScript compiler
-- backend.
------------------------------------------------------------------------
-- Module hierarchy
------------------------------------------------------------------------
-- The top-level module names of the library are currently allocated
-- as follows:
--
-- • Algebra
-- Abstract algebra (monoids, groups, rings etc.), along with
-- properties needed to specify these structures (associativity,
-- commutativity, etc.), and operations on and proofs about the
-- structures.
-- • Axiom
-- Types and consequences of various additional axioms not
-- necessarily included in Agda, e.g. uniqueness of identity
-- proofs, function extensionality and excluded middle.
import README.Axiom
-- • Category
-- Category theory-inspired idioms used to structure functional
-- programs (functors and monads, for instance).
-- • Codata
-- Coinductive data types and properties. There are two different
-- approaches taken. The `Codata` folder contains the new more
-- standard approach using sized types. The `Codata.Musical`
-- folder contains modules using the old musical notation.
-- • Data
-- Data types and properties.
import README.Data
-- • Function
-- Combinators and properties related to functions.
-- • Foreign
-- Related to the foreign function interface.
-- • Induction
-- A general framework for induction (includes lexicographic and
-- well-founded induction).
-- • IO
-- Input/output-related functions.
-- • Level
-- Universe levels.
-- • Reflection
-- Support for reflection.
-- • Relation
-- Properties of and proofs about relations.
-- • Size
-- Sizes used by the sized types mechanism.
-- • Strict
-- Provides access to the builtins relating to strictness.
-- • Tactic
-- Tactics for automatic proof generation
------------------------------------------------------------------------
-- A selection of useful library modules
------------------------------------------------------------------------
-- Note that module names in source code are often hyperlinked to the
-- corresponding module. In the Emacs mode you can follow these
-- hyperlinks by typing M-. or clicking with the middle mouse button.
-- • Some data types
import Data.Bool -- Booleans.
import Data.Char -- Characters.
import Data.Empty -- The empty type.
import Data.Fin -- Finite sets.
import Data.List -- Lists.
import Data.Maybe -- The maybe type.
import Data.Nat -- Natural numbers.
import Data.Product -- Products.
import Data.String -- Strings.
import Data.Sum -- Disjoint sums.
import Data.Unit -- The unit type.
import Data.Vec -- Fixed-length vectors.
-- • Some co-inductive data types
import Codata.Stream -- Streams.
import Codata.Colist -- Colists.
-- • Some types used to structure computations
import Category.Functor -- Functors.
import Category.Applicative -- Applicative functors.
import Category.Monad -- Monads.
-- • Equality
-- Propositional equality:
import Relation.Binary.PropositionalEquality
-- Convenient syntax for "equational reasoning" using a preorder:
import Relation.Binary.Reasoning.Preorder
-- Solver for commutative ring or semiring equalities:
import Algebra.Solver.Ring
-- • Properties of functions, sets and relations
-- Monoids, rings and similar algebraic structures:
import Algebra
-- Negation, decidability, and similar operations on sets:
import Relation.Nullary
-- Properties of homogeneous binary relations:
import Relation.Binary
-- • Induction
-- An abstraction of various forms of recursion/induction:
import Induction
-- Well-founded induction:
import Induction.WellFounded
-- Various forms of induction for natural numbers:
import Data.Nat.Induction
-- • Support for coinduction
import Codata.Musical.Notation
import Codata.Thunk
-- • IO
import IO
------------------------------------------------------------------------
-- Record hierarchies
------------------------------------------------------------------------
-- When an abstract hierarchy of some sort (for instance semigroup →
-- monoid → group) is included in the library the basic approach is to
-- specify the properties of every concept in terms of a record
-- containing just properties, parameterised on the underlying
-- operations, sets etc.:
--
-- record IsSemigroup {A} (≈ : Rel A) (∙ : Op₂ A) : Set where
-- open FunctionProperties ≈
-- field
-- isEquivalence : IsEquivalence ≈
-- assoc : Associative ∙
-- ∙-cong : ∙ Preserves₂ ≈ ⟶ ≈ ⟶ ≈
--
-- More specific concepts are then specified in terms of the simpler
-- ones:
--
-- record IsMonoid {A} (≈ : Rel A) (∙ : Op₂ A) (ε : A) : Set where
-- open FunctionProperties ≈
-- field
-- isSemigroup : IsSemigroup ≈ ∙
-- identity : Identity ε ∙
--
-- open IsSemigroup isSemigroup public
--
-- Note here that `open IsSemigroup isSemigroup public` ensures that the
-- fields of the isSemigroup record can be accessed directly; this
-- technique enables the user of an IsMonoid record to use underlying
-- records without having to manually open an entire record hierarchy.
-- This is not always possible, though. Consider the following definition
-- of preorders:
--
-- record IsPreorder {A : Set}
-- (_≈_ : Rel A) -- The underlying equality.
-- (_∼_ : Rel A) -- The relation.
-- : Set where
-- field
-- isEquivalence : IsEquivalence _≈_
-- -- Reflexivity is expressed in terms of an underlying equality:
-- reflexive : _≈_ ⇒ _∼_
-- trans : Transitive _∼_
--
-- module Eq = IsEquivalence isEquivalence
--
-- ...
--
-- The Eq module in IsPreorder is not opened publicly, because it
-- contains some fields which clash with fields or other definitions
-- in IsPreorder.
-- Records packing up properties with the corresponding operations,
-- sets, etc. are also defined:
--
-- record Semigroup : Set₁ where
-- infixl 7 _∙_
-- infix 4 _≈_
-- field
-- Carrier : Set
-- _≈_ : Rel Carrier
-- _∙_ : Op₂ Carrier
-- isSemigroup : IsSemigroup _≈_ _∙_
--
-- open IsSemigroup isSemigroup public
--
-- setoid : Setoid
-- setoid = record { isEquivalence = isEquivalence }
--
-- record Monoid : Set₁ where
-- infixl 7 _∙_
-- infix 4 _≈_
-- field
-- Carrier : Set
-- _≈_ : Rel Carrier
-- _∙_ : Op₂ Carrier
-- ε : Carrier
-- isMonoid : IsMonoid _≈_ _∙_ ε
--
-- open IsMonoid isMonoid public
--
-- semigroup : Semigroup
-- semigroup = record { isSemigroup = isSemigroup }
--
-- open Semigroup semigroup public using (setoid)
--
-- Note that the Monoid record does not include a Semigroup field.
-- Instead the Monoid /module/ includes a "repackaging function"
-- semigroup which converts a Monoid to a Semigroup.
-- The above setup may seem a bit complicated, but we think it makes the
-- library quite easy to work with, while also providing enough
-- flexibility.
------------------------------------------------------------------------
-- More documentation
------------------------------------------------------------------------
-- Examples of how decidability is handled in the library.
import README.Decidability
-- Some examples showing how the case expression can be used.
import README.Case
-- Some examples showing how combinators can be used to emulate
-- "functional reasoning"
import README.Function.Reasoning
-- An example showing how to use the debug tracing mechanism to inspect
-- the behaviour of compiled Agda programs.
import README.Debug.Trace
-- An exploration of the generic programs acting on n-ary functions and
-- n-ary heterogeneous products
import README.Nary
-- Explaining the inspect idiom: use case, equivalent handwritten
-- auxiliary definitions, and implementation details.
import README.Inspect
-- Explaining string formats and the behaviour of printf
import README.Text.Printf
-- Showcasing the pretty printing module
import README.Text.Pretty
-- Explaining how to display tables of strings:
import README.Text.Tabular
-- Explaining how to display a tree:
import README.Text.Tree
-- Explaining how to use the automatic solvers
import README.Tactic.MonoidSolver
import README.Tactic.RingSolver
-- Explaining how the Haskell FFI works
import README.Foreign.Haskell
------------------------------------------------------------------------
-- Core modules
------------------------------------------------------------------------
-- Some modules have names ending in ".Core". These modules are
-- internal, and have (mostly) been created to avoid mutual recursion
-- between modules. They should not be imported directly; their
-- contents are reexported by other modules.
------------------------------------------------------------------------
-- All library modules
------------------------------------------------------------------------
-- For short descriptions of every library module, see Everything;
-- to exclude unsafe modules, see EverythingSafe:
import Everything
import EverythingSafe
-- Note that the Everything* modules are generated automatically. If
-- you have downloaded the library from its Git repository and want
-- to type check README then you can (try to) construct Everything by
-- running "cabal install && GenerateEverything".
-- Note that all library sources are located under src or ffi. The
-- modules README, README.* and Everything are not really part of the
-- library, so these modules are located in the top-level directory
-- instead.
|
{
"alphanum_fraction": 0.6399116348,
"avg_line_length": 31.04,
"ext": "agda",
"hexsha": "9b7feba893425a97f52cbd564bce3e19e23969bf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/README.agda",
"max_line_length": 73,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/README.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 2385,
"size": 10864
}
|
-- Note: out of order true and false. Confuses the
-- values if we mess up and compile it to a fresh
-- datatype instead of Haskell Bool.
data Two : Set where tt ff : Two
{-# BUILTIN BOOL Two #-}
{-# BUILTIN FALSE ff #-}
{-# BUILTIN TRUE tt #-}
-- Note: out of order nil and cons. Causes segfault
-- if we mess up and compile it to a fresh datatype
-- instead of Haskell lists.
data List {a} (A : Set a) : Set a where
_∷_ : A → List A → List A
[] : List A
{-# BUILTIN LIST List #-}
postulate
String : Set
Char : Set
{-# BUILTIN STRING String #-}
{-# BUILTIN CHAR Char #-}
primitive
primStringToList : String → List Char
primStringFromList : List Char → String
primStringEquality : String → String → Two
drop1 : {A : Set} → List A → List A
drop1 (x ∷ xs) = xs
drop1 [] = []
postulate
drop1' : List Char → List Char
{-# COMPILE GHC drop1' = drop 1 #-}
onList : (List Char → List Char) → String → String
onList f s = primStringFromList (f (primStringToList s))
postulate
_==_ : String → String → Two
{-# COMPILE GHC _==_ = (==) #-}
show : Two → String
show tt = onList drop1 "TRUE"
show ff = onList drop1' "FALSE"
record One : Set where
{-# COMPILE GHC One = data () (()) #-}
postulate IO : Set → Set
{-# BUILTIN IO IO #-}
{-# COMPILE GHC IO = type IO #-}
{-# FOREIGN GHC import qualified Data.Text.IO #-}
postulate putStrLn : String → IO One
{-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
postulate _>>_ : IO One → IO One → IO One
{-# COMPILE GHC _>>_ = (>>) #-}
main : IO One
main = do
putStrLn (show ("foo" == "bar"))
putStrLn (show ("foo" == "foo"))
|
{
"alphanum_fraction": 0.6259351621,
"avg_line_length": 22.9142857143,
"ext": "agda",
"hexsha": "2ea3d39da1cb8f97d098087b01917ca7fe270fb3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue2821.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue2821.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue2821.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 471,
"size": 1604
}
|
module ch1 where
data 𝔹 : Set where
tt : 𝔹
ff : 𝔹
_||_ : 𝔹 -> 𝔹 -> 𝔹
tt || _ = tt
ff || b = b
data day : Set where
monday : day
tuesday : day
wednesday : day
thursday : day
friday : day
saturday : day
sunday : day
nextday : day -> day
nextday monday = tuesday
nextday tuesday = wednesday
nextday wednesday = thursday
nextday thursday = friday
nextday friday = saturday
nextday saturday = sunday
nextday sunday = monday
data suit : Set where
hearts : suit
spades : suit
diamonds : suit
clubs : suit
is-red : suit -> 𝔹
is-red hearts = tt
is-red spades = ff
is-red diamonds = tt
is-red clubs = ff
|
{
"alphanum_fraction": 0.6608280255,
"avg_line_length": 14.2727272727,
"ext": "agda",
"hexsha": "79495aeff0bc37206f71290df1e9df7161c993ae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8593e7ea70e95c145b2d8911a9a5f29f3016dafe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "razvan-panda/Verified-Functional-Programming-in-Agda",
"max_forks_repo_path": "ch1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8593e7ea70e95c145b2d8911a9a5f29f3016dafe",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "razvan-panda/Verified-Functional-Programming-in-Agda",
"max_issues_repo_path": "ch1.agda",
"max_line_length": 28,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8593e7ea70e95c145b2d8911a9a5f29f3016dafe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "razvan-panda/Verified-Functional-Programming-in-Agda",
"max_stars_repo_path": "ch1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 216,
"size": 628
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lexicographic products of binary relations
------------------------------------------------------------------------
-- The definition of lexicographic product used here is suitable if
-- the left-hand relation is a (non-strict) partial order.
{-# OPTIONS --without-K --safe #-}
module Data.Product.Relation.Binary.Lex.NonStrict where
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Sum using (inj₁; inj₂)
open import Relation.Binary
open import Relation.Binary.Consequences
import Relation.Binary.Construct.NonStrictToStrict as Conv
open import Data.Product.Relation.Binary.Pointwise.NonDependent as Pointwise
using (Pointwise)
import Data.Product.Relation.Binary.Lex.Strict as Strict
module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where
------------------------------------------------------------------------
-- A lexicographic ordering over products
×-Lex : (_≈₁_ _≤₁_ : Rel A₁ ℓ₁) (_≤₂_ : Rel A₂ ℓ₂) → Rel (A₁ × A₂) _
×-Lex _≈₁_ _≤₁_ _≤₂_ = Strict.×-Lex _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_
------------------------------------------------------------------------
-- Some properties which are preserved by ×-Lex (under certain
-- assumptions).
×-reflexive : ∀ _≈₁_ _≤₁_ {_≈₂_} _≤₂_ →
_≈₂_ ⇒ _≤₂_ →
(Pointwise _≈₁_ _≈₂_) ⇒ (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-reflexive _≈₁_ _≤₁_ _≤₂_ refl₂ =
Strict.×-reflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_ refl₂
×-transitive : ∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
∀ {_≤₂_} → Transitive _≤₂_ →
Transitive (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-transitive {_≈₁_} {_≤₁_} po₁ {_≤₂_} trans₂ =
Strict.×-transitive
{_<₁_ = Conv._<_ _≈₁_ _≤₁_}
isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
(Conv.<-trans _ _ po₁)
{_≤₂_} trans₂
where open IsPartialOrder po₁
×-antisymmetric :
∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
∀ {_≈₂_ _≤₂_} → Antisymmetric _≈₂_ _≤₂_ →
Antisymmetric (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-antisymmetric {_≈₁_} {_≤₁_}
po₁ {_≤₂_ = _≤₂_} antisym₂ =
Strict.×-antisymmetric {_<₁_ = Conv._<_ _≈₁_ _≤₁_}
≈-sym₁ irrefl₁ asym₁
{_≤₂_ = _≤₂_} antisym₂
where
open IsPartialOrder po₁
open Eq renaming (refl to ≈-refl₁; sym to ≈-sym₁)
irrefl₁ : Irreflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
irrefl₁ = Conv.<-irrefl _≈₁_ _≤₁_
asym₁ : Asymmetric (Conv._<_ _≈₁_ _≤₁_)
asym₁ = trans∧irr⟶asym {_≈_ = _≈₁_}
≈-refl₁ (Conv.<-trans _ _ po₁) irrefl₁
×-respects₂ :
∀ {_≈₁_ _≤₁_} → IsEquivalence _≈₁_ → _≤₁_ Respects₂ _≈₁_ →
∀ {_≈₂_ _≤₂_ : Rel A₂ ℓ₂} → _≤₂_ Respects₂ _≈₂_ →
(×-Lex _≈₁_ _≤₁_ _≤₂_) Respects₂ (Pointwise _≈₁_ _≈₂_)
×-respects₂ eq₁ resp₁ resp₂ =
Strict.×-respects₂ eq₁ (Conv.<-resp-≈ _ _ eq₁ resp₁) resp₂
×-decidable : ∀ {_≈₁_ _≤₁_} → Decidable _≈₁_ → Decidable _≤₁_ →
∀ {_≤₂_} → Decidable _≤₂_ →
Decidable (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-decidable dec-≈₁ dec-≤₁ dec-≤₂ =
Strict.×-decidable dec-≈₁ (Conv.<-decidable _ _ dec-≈₁ dec-≤₁)
dec-≤₂
×-total : ∀ {_≈₁_ _≤₁_} → Symmetric _≈₁_ → Decidable _≈₁_ →
Antisymmetric _≈₁_ _≤₁_ → Total _≤₁_ →
∀ {_≤₂_} → Total _≤₂_ →
Total (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-total {_≈₁_} {_≤₁_} sym₁ dec₁ antisym₁ total₁ {_≤₂_} total₂ =
total
where
tri₁ : Trichotomous _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
tri₁ = Conv.<-trichotomous _ _ sym₁ dec₁ antisym₁ total₁
total : Total (×-Lex _≈₁_ _≤₁_ _≤₂_)
total x y with tri₁ (proj₁ x) (proj₁ y)
... | tri< x₁<y₁ x₁≉y₁ x₁≯y₁ = inj₁ (inj₁ x₁<y₁)
... | tri> x₁≮y₁ x₁≉y₁ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
... | tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁ with total₂ (proj₂ x) (proj₂ y)
... | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
... | inj₂ x₂≥y₂ = inj₂ (inj₂ (sym₁ x₁≈y₁ , x₂≥y₂))
-- Some collections of properties which are preserved by ×-Lex
-- (under certain assumptions).
×-isPartialOrder :
∀ {_≈₁_ _≤₁_} → IsPartialOrder _≈₁_ _≤₁_ →
∀ {_≈₂_ _≤₂_} → IsPartialOrder _≈₂_ _≤₂_ →
IsPartialOrder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-isPartialOrder {_≈₁_} {_≤₁_} po₁
{_≤₂_ = _≤₂_} po₂ = record
{ isPreorder = record
{ isEquivalence = Pointwise.×-isEquivalence
(isEquivalence po₁)
(isEquivalence po₂)
; reflexive = ×-reflexive _≈₁_ _≤₁_ _≤₂_ (reflexive po₂)
; trans = ×-transitive po₁ {_≤₂_ = _≤₂_} (trans po₂)
}
; antisym = ×-antisymmetric {_≤₁_ = _≤₁_} po₁
{_≤₂_ = _≤₂_} (antisym po₂)
}
where open IsPartialOrder
×-isTotalOrder :
∀ {_≈₁_ _≤₁_} → Decidable _≈₁_ → IsTotalOrder _≈₁_ _≤₁_ →
∀ {_≈₂_ _≤₂_} → IsTotalOrder _≈₂_ _≤₂_ →
IsTotalOrder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-isTotalOrder {_≤₁_ = _≤₁_} ≈₁-dec to₁ {_≤₂_ = _≤₂_} to₂ = record
{ isPartialOrder = ×-isPartialOrder
(isPartialOrder to₁) (isPartialOrder to₂)
; total = ×-total {_≤₁_ = _≤₁_} (Eq.sym to₁) ≈₁-dec
(antisym to₁) (total to₁)
{_≤₂_ = _≤₂_} (total to₂)
}
where open IsTotalOrder
×-isDecTotalOrder :
∀ {_≈₁_ _≤₁_} → IsDecTotalOrder _≈₁_ _≤₁_ →
∀ {_≈₂_ _≤₂_} → IsDecTotalOrder _≈₂_ _≤₂_ →
IsDecTotalOrder (Pointwise _≈₁_ _≈₂_) (×-Lex _≈₁_ _≤₁_ _≤₂_)
×-isDecTotalOrder {_≤₁_ = _≤₁_} to₁ {_≤₂_ = _≤₂_} to₂ = record
{ isTotalOrder = ×-isTotalOrder (_≟_ to₁)
(isTotalOrder to₁)
(isTotalOrder to₂)
; _≟_ = Pointwise.×-decidable (_≟_ to₁) (_≟_ to₂)
; _≤?_ = ×-decidable (_≟_ to₁) (_≤?_ to₁) (_≤?_ to₂)
}
where open IsDecTotalOrder
------------------------------------------------------------------------
-- "Packages" can also be combined.
module _ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} where
×-poset : Poset ℓ₁ ℓ₂ _ → Poset ℓ₃ ℓ₄ _ → Poset _ _ _
×-poset p₁ p₂ = record
{ isPartialOrder = ×-isPartialOrder
(isPartialOrder p₁) (isPartialOrder p₂)
} where open Poset
×-totalOrder : DecTotalOrder ℓ₁ ℓ₂ _ → TotalOrder ℓ₃ ℓ₄ _ →
TotalOrder _ _ _
×-totalOrder t₁ t₂ = record
{ isTotalOrder = ×-isTotalOrder T₁._≟_ T₁.isTotalOrder T₂.isTotalOrder
}
where
module T₁ = DecTotalOrder t₁
module T₂ = TotalOrder t₂
×-decTotalOrder : DecTotalOrder ℓ₁ ℓ₂ _ → DecTotalOrder ℓ₃ ℓ₄ _ →
DecTotalOrder _ _ _
×-decTotalOrder t₁ t₂ = record
{ isDecTotalOrder = ×-isDecTotalOrder
(isDecTotalOrder t₁) (isDecTotalOrder t₂)
} where open DecTotalOrder
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
_×-isPartialOrder_ = ×-isPartialOrder
{-# WARNING_ON_USAGE _×-isPartialOrder_
"Warning: _×-isPartialOrder_ was deprecated in v0.15.
Please use ×-isPartialOrder instead."
#-}
_×-isDecTotalOrder_ = ×-isDecTotalOrder
{-# WARNING_ON_USAGE _×-isDecTotalOrder_
"Warning: _×-isDecTotalOrder_ was deprecated in v0.15.
Please use ×-isDecTotalOrder instead."
#-}
_×-poset_ = ×-poset
{-# WARNING_ON_USAGE _×-poset_
"Warning: _×-poset_ was deprecated in v0.15.
Please use ×-poset instead."
#-}
_×-totalOrder_ = ×-totalOrder
{-# WARNING_ON_USAGE _×-totalOrder_
"Warning: _×-totalOrder_ was deprecated in v0.15.
Please use ×-totalOrder instead."
#-}
_×-decTotalOrder_ = ×-decTotalOrder
{-# WARNING_ON_USAGE _×-decTotalOrder_
"Warning: _×-decTotalOrder_ was deprecated in v0.15.
Please use ×-decTotalOrder instead."
#-}
×-≈-respects₂ = ×-respects₂
{-# WARNING_ON_USAGE ×-≈-respects₂
"Warning: ×-≈-respects₂ was deprecated in v0.15.
Please use ×-respects₂ instead."
#-}
|
{
"alphanum_fraction": 0.5544554455,
"avg_line_length": 37.875,
"ext": "agda",
"hexsha": "a1f6f46ecd6fd03c588834a85c90a84751640b37",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/Relation/Binary/Lex/NonStrict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/Relation/Binary/Lex/NonStrict.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/Relation/Binary/Lex/NonStrict.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3162,
"size": 8181
}
|
-- Andreas, 2013-03-22
-- {-# OPTIONS -v tc.lhs:40 #-}
module Issue279-3 where
module M (X : Set) where
data R : Set where
r : X → R
postulate
P Q : Set
open M P
shouldn't-check : M.R Q → Q
shouldn't-check (r q) = q
-- Agda uses the type of the original constructor
--
-- M.r {X : Set} : X → R X
--
-- instead of the type of the copied constructor
--
-- r : P → R
--
-- If one changes the domain to _, it will be resolved to
-- R, which is M.R P, and q gets assigned type P, leading
-- to expected failure.
-- Fixed this issue by comparing the parameter reconstructed
-- from the domain, Q, to the parameter of the unambiguous
-- constructor r, which is P.
|
{
"alphanum_fraction": 0.6449704142,
"avg_line_length": 20.4848484848,
"ext": "agda",
"hexsha": "7022d4e3472de17fbfce998aa50647961946500c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue279-3.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue279-3.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue279-3.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 206,
"size": 676
}
|
module BasicIS4.Metatheory.DyadicHilbert-TarskiOvergluedDyadicImplicit where
open import BasicIS4.Syntax.DyadicHilbert public
open import BasicIS4.Semantics.TarskiOvergluedDyadicImplicit public
open ImplicitSyntax (_⊢_) (mono²⊢) public
-- Completeness with respect to a particular model.
module _ {{_ : Model}} where
reify : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊢ A
reify {α P} s = syn s
reify {A ▻ B} s = syn (s refl⊆²)
reify {□ A} s = syn (s refl⊆²)
reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))
reify {⊤} s = unit
reify⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊩⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Additional useful equipment.
module _ {{_ : Model}} where
⟪K⟫ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊩ B ▻ A
⟪K⟫ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in app ck (reify a′) ⅋ K a′
⟪S⟫′ : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊩ A ▻ B ▻ C → Γ ⁏ Δ ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ {A} {B} {C} s₁ ψ = let s₁′ = mono²⊩ {A ▻ B ▻ C} ψ s₁
t = syn (s₁′ refl⊆²)
in app cs t ⅋ λ s₂ ψ′ →
let s₁″ = mono²⊩ {A ▻ B ▻ C} (trans⊆² ψ ψ′) s₁
s₂′ = mono²⊩ {A ▻ B} ψ′ s₂
t′ = syn (s₁″ refl⊆²)
u = syn (s₂′ refl⊆²)
in app (app cs t′) u ⅋ ⟪S⟫ s₁″ s₂′
_⟪D⟫_ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊩ □ (A ▻ B) → Γ ⁏ Δ ⊩ □ A → Γ ⁏ Δ ⊩ □ B
(s₁ ⟪D⟫ s₂) ψ = let t ⅋ s₁′ = s₁ ψ
u ⅋ a = s₂ ψ
in app (app cdist t) u ⅋ s₁′ ⟪$⟫ a
_⟪D⟫′_ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊩ □ (A ▻ B) → Γ ⁏ Δ ⊩ □ A ▻ □ B
_⟪D⟫′_ {A} {B} s₁ ψ = let s₁′ = mono²⊩ {□ (A ▻ B)} ψ s₁
in app cdist (reify (λ {_} ψ′ → s₁′ ψ′)) ⅋ _⟪D⟫_ s₁′
⟪↑⟫ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ □ A → Γ ⁏ Δ ⊩ □ □ A
⟪↑⟫ {A} s ψ = app cup (syn (s ψ)) ⅋ λ ψ′ → s (trans⊆² ψ ψ′)
_⟪,⟫′_ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊩ B ▻ A ∧ B
_⟪,⟫′_ {A} a ψ = let a′ = mono²⊩ {A} ψ a
in app cpair (reify a′) ⅋ _,_ a′
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A
eval (var i) γ δ = lookup i γ
eval (app t u) γ δ = eval t γ δ ⟪$⟫ eval u γ δ
eval ci γ δ = K (ci ⅋ I)
eval ck γ δ = K (ck ⅋ ⟪K⟫)
eval cs γ δ = K (cs ⅋ ⟪S⟫′)
eval (mvar i) γ δ = mlookup i δ
eval (box t) γ δ = λ ψ → let δ′ = mono²⊩⋆ ψ δ
in mmulticut (reify⋆ δ′) (box t) ⅋
eval t ∙ δ′
eval cdist γ δ = K (cdist ⅋ _⟪D⟫′_)
eval cup γ δ = K (cup ⅋ ⟪↑⟫)
eval cdown γ δ = K (cdown ⅋ ⟪↓⟫)
eval cpair γ δ = K (cpair ⅋ _⟪,⟫′_)
eval cfst γ δ = K (cfst ⅋ π₁)
eval csnd γ δ = K (csnd ⅋ π₂)
eval unit γ δ = ∙
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ _⊩ᵅ_ = λ Π P → Π ⊢ α P
; mono²⊩ᵅ = mono²⊢
}
-- Soundness with respect to the canonical model.
reflectᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊩ A
reflectᶜ {α P} t = t ⅋ t
reflectᶜ {A ▻ B} t = λ ψ → let t′ = mono²⊢ ψ t
in t′ ⅋ λ a → reflectᶜ (app t′ (reify a))
reflectᶜ {□ A} t = λ ψ → let t′ = mono²⊢ ψ t
in t′ ⅋ reflectᶜ (down t′)
reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)
reflectᶜ {⊤} t = ∙
reflectᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
mrefl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ □⋆ Δ
mrefl⊩⋆ = reflectᶜ⋆ mrefl⊢⋆
trans⊩⋆ : ∀ {Γ Γ′ Δ Δ′ Ξ} → Γ ⁏ Δ ⊩⋆ Γ′ ⧺ (□⋆ Δ′) → Γ′ ⁏ Δ′ ⊩⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ Δ} → Γ ⁏ Δ ⊨ A → Γ ⁏ Δ ⊢ A
quot s = reify (s refl⊩⋆ mrefl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
|
{
"alphanum_fraction": 0.4419942474,
"avg_line_length": 31.1343283582,
"ext": "agda",
"hexsha": "9b8458090690a56c0ca60e5cc5912d4a73b9f06b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIS4/Metatheory/DyadicHilbert-TarskiOvergluedDyadicImplicit.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIS4/Metatheory/DyadicHilbert-TarskiOvergluedDyadicImplicit.agda",
"max_line_length": 78,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIS4/Metatheory/DyadicHilbert-TarskiOvergluedDyadicImplicit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 2087,
"size": 4172
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to bag and set equality
------------------------------------------------------------------------
-- Bag and set equality are defined in Data.List.Any.
module Data.List.Any.BagAndSetEquality where
open import Algebra
open import Algebra.FunctionProperties
open import Category.Monad
open import Data.List as List
import Data.List.Properties as LP
open import Data.List.Any as Any using (Any); open Any.Any
open import Data.List.Any.Properties
open import Data.Product
open import Data.Sum
open import Function
open import Function.Equality using (_⟨$⟩_)
import Function.Equivalence as FE
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Related as Related using (↔⇒; ⌊_⌋; ⌊_⌋→; ⇒→)
open import Function.Related.TypeIsomorphisms
open import Relation.Binary
import Relation.Binary.EqReasoning as EqR
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≗_)
open import Relation.Binary.Sum
open import Relation.Nullary
open Any.Membership-≡
private
module Eq {k a} {A : Set a} = Setoid ([ k ]-Equality A)
module Ord {k a} {A : Set a} = Preorder ([ k ]-Order A)
module ×⊎ {k ℓ} = CommutativeSemiring (×⊎-CommutativeSemiring k ℓ)
open module ListMonad {ℓ} = RawMonad (List.monad {ℓ = ℓ})
module ListMonoid {a} {A : Set a} = Monoid (List.monoid A)
------------------------------------------------------------------------
-- Congruence lemmas
-- _∷_ is a congruence.
∷-cong : ∀ {a k} {A : Set a} {x₁ x₂ : A} {xs₁ xs₂} →
x₁ ≡ x₂ → xs₁ ∼[ k ] xs₂ → x₁ ∷ xs₁ ∼[ k ] x₂ ∷ xs₂
∷-cong {x₂ = x} {xs₁} {xs₂} P.refl xs₁≈xs₂ {y} =
y ∈ x ∷ xs₁ ↔⟨ sym $ ∷↔ (_≡_ y) ⟩
(y ≡ x ⊎ y ∈ xs₁) ∼⟨ (y ≡ x ∎) ⊎-cong xs₁≈xs₂ ⟩
(y ≡ x ⊎ y ∈ xs₂) ↔⟨ ∷↔ (_≡_ y) ⟩
y ∈ x ∷ xs₂ ∎
where open Related.EquationalReasoning
-- List.map is a congruence.
map-cong : ∀ {ℓ k} {A B : Set ℓ} {f₁ f₂ : A → B} {xs₁ xs₂} →
f₁ ≗ f₂ → xs₁ ∼[ k ] xs₂ →
List.map f₁ xs₁ ∼[ k ] List.map f₂ xs₂
map-cong {ℓ} {f₁ = f₁} {f₂} {xs₁} {xs₂} f₁≗f₂ xs₁≈xs₂ {x} =
x ∈ List.map f₁ xs₁ ↔⟨ sym $ map↔ {a = ℓ} {b = ℓ} {p = ℓ} ⟩
Any (λ y → x ≡ f₁ y) xs₁ ∼⟨ Any-cong (↔⇒ ∘ helper) xs₁≈xs₂ ⟩
Any (λ y → x ≡ f₂ y) xs₂ ↔⟨ map↔ {a = ℓ} {b = ℓ} {p = ℓ} ⟩
x ∈ List.map f₂ xs₂ ∎
where
open Related.EquationalReasoning
helper : ∀ y → x ≡ f₁ y ↔ x ≡ f₂ y
helper y = record
{ to = P.→-to-⟶ (λ x≡f₁y → P.trans x≡f₁y ( f₁≗f₂ y))
; from = P.→-to-⟶ (λ x≡f₂y → P.trans x≡f₂y (P.sym $ f₁≗f₂ y))
; inverse-of = record
{ left-inverse-of = λ _ → P.proof-irrelevance _ _
; right-inverse-of = λ _ → P.proof-irrelevance _ _
}
}
-- _++_ is a congruence.
++-cong : ∀ {a k} {A : Set a} {xs₁ xs₂ ys₁ ys₂ : List A} →
xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →
xs₁ ++ ys₁ ∼[ k ] xs₂ ++ ys₂
++-cong {a} {xs₁ = xs₁} {xs₂} {ys₁} {ys₂} xs₁≈xs₂ ys₁≈ys₂ {x} =
x ∈ xs₁ ++ ys₁ ↔⟨ sym $ ++↔ {a = a} {p = a} ⟩
(x ∈ xs₁ ⊎ x ∈ ys₁) ∼⟨ xs₁≈xs₂ ⊎-cong ys₁≈ys₂ ⟩
(x ∈ xs₂ ⊎ x ∈ ys₂) ↔⟨ ++↔ {a = a} {p = a} ⟩
x ∈ xs₂ ++ ys₂ ∎
where open Related.EquationalReasoning
-- concat is a congruence.
concat-cong : ∀ {a k} {A : Set a} {xss₁ xss₂ : List (List A)} →
xss₁ ∼[ k ] xss₂ → concat xss₁ ∼[ k ] concat xss₂
concat-cong {a} {xss₁ = xss₁} {xss₂} xss₁≈xss₂ {x} =
x ∈ concat xss₁ ↔⟨ sym $ concat↔ {a = a} {p = a} ⟩
Any (Any (_≡_ x)) xss₁ ∼⟨ Any-cong (λ _ → _ ∎) xss₁≈xss₂ ⟩
Any (Any (_≡_ x)) xss₂ ↔⟨ concat↔ {a = a} {p = a} ⟩
x ∈ concat xss₂ ∎
where open Related.EquationalReasoning
-- The list monad's bind is a congruence.
>>=-cong : ∀ {ℓ k} {A B : Set ℓ} {xs₁ xs₂} {f₁ f₂ : A → List B} →
xs₁ ∼[ k ] xs₂ → (∀ x → f₁ x ∼[ k ] f₂ x) →
(xs₁ >>= f₁) ∼[ k ] (xs₂ >>= f₂)
>>=-cong {ℓ} {xs₁ = xs₁} {xs₂} {f₁} {f₂} xs₁≈xs₂ f₁≈f₂ {x} =
x ∈ (xs₁ >>= f₁) ↔⟨ sym $ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩
Any (λ y → x ∈ f₁ y) xs₁ ∼⟨ Any-cong (λ x → f₁≈f₂ x) xs₁≈xs₂ ⟩
Any (λ y → x ∈ f₂ y) xs₂ ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩
x ∈ (xs₂ >>= f₂) ∎
where open Related.EquationalReasoning
-- _⊛_ is a congruence.
⊛-cong : ∀ {ℓ k} {A B : Set ℓ} {fs₁ fs₂ : List (A → B)} {xs₁ xs₂} →
fs₁ ∼[ k ] fs₂ → xs₁ ∼[ k ] xs₂ → fs₁ ⊛ xs₁ ∼[ k ] fs₂ ⊛ xs₂
⊛-cong fs₁≈fs₂ xs₁≈xs₂ =
>>=-cong fs₁≈fs₂ λ f →
>>=-cong xs₁≈xs₂ λ x →
_ ∎
where open Related.EquationalReasoning
-- _⊗_ is a congruence.
⊗-cong : ∀ {ℓ k} {A B : Set ℓ} {xs₁ xs₂ : List A} {ys₁ ys₂ : List B} →
xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →
(xs₁ ⊗ ys₁) ∼[ k ] (xs₂ ⊗ ys₂)
⊗-cong {ℓ} xs₁≈xs₂ ys₁≈ys₂ =
⊛-cong (⊛-cong (Ord.refl {x = [ _,_ {a = ℓ} {b = ℓ} ]})
xs₁≈xs₂)
ys₁≈ys₂
------------------------------------------------------------------------
-- Other properties
-- _++_ and [] form a commutative monoid, with either bag or set
-- equality as the underlying equality.
commutativeMonoid : ∀ {a} → Symmetric-kind → Set a →
CommutativeMonoid _ _
commutativeMonoid {a} k A = record
{ Carrier = List A
; _≈_ = λ xs ys → xs ∼[ ⌊ k ⌋ ] ys
; _∙_ = _++_
; ε = []
; isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = Eq.isEquivalence
; assoc = λ xs ys zs →
Eq.reflexive (ListMonoid.assoc xs ys zs)
; ∙-cong = ++-cong
}
; identityˡ = λ xs {x} → x ∈ xs ∎
; comm = λ xs ys {x} →
x ∈ xs ++ ys ↔⟨ ++↔++ {a = a} {p = a} xs ys ⟩
x ∈ ys ++ xs ∎
}
}
where open Related.EquationalReasoning
-- The only list which is bag or set equal to the empty list (or a
-- subset or subbag of the list) is the empty list itself.
empty-unique : ∀ {k a} {A : Set a} {xs : List A} →
xs ∼[ ⌊ k ⌋→ ] [] → xs ≡ []
empty-unique {xs = []} _ = P.refl
empty-unique {xs = _ ∷ _} ∷∼[] with ⇒→ ∷∼[] (here P.refl)
... | ()
-- _++_ is idempotent (under set equality).
++-idempotent : ∀ {a} {A : Set a} →
Idempotent (λ (xs ys : List A) → xs ∼[ set ] ys) _++_
++-idempotent {a} xs {x} =
x ∈ xs ++ xs ∼⟨ FE.equivalence ([ id , id ]′ ∘ _⟨$⟩_ (Inverse.from $ ++↔ {a = a} {p = a}))
(_⟨$⟩_ (Inverse.to $ ++↔ {a = a} {p = a}) ∘ inj₁) ⟩
x ∈ xs ∎
where open Related.EquationalReasoning
-- The list monad's bind distributes from the left over _++_.
>>=-left-distributive :
∀ {ℓ} {A B : Set ℓ} (xs : List A) {f g : A → List B} →
(xs >>= λ x → f x ++ g x) ∼[ bag ] (xs >>= f) ++ (xs >>= g)
>>=-left-distributive {ℓ} xs {f} {g} {y} =
y ∈ (xs >>= λ x → f x ++ g x) ↔⟨ sym $ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩
Any (λ x → y ∈ f x ++ g x) xs ↔⟨ sym (Any-cong (λ _ → ++↔ {a = ℓ} {p = ℓ}) (_ ∎)) ⟩
Any (λ x → y ∈ f x ⊎ y ∈ g x) xs ↔⟨ sym $ ⊎↔ {a = ℓ} {p = ℓ} {q = ℓ} ⟩
(Any (λ x → y ∈ f x) xs ⊎ Any (λ x → y ∈ g x) xs) ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟨ ×⊎.+-cong {ℓ = ℓ} ⟩ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩
(y ∈ (xs >>= f) ⊎ y ∈ (xs >>= g)) ↔⟨ ++↔ {a = ℓ} {p = ℓ} ⟩
y ∈ (xs >>= f) ++ (xs >>= g) ∎
where open Related.EquationalReasoning
-- The same applies to _⊛_.
⊛-left-distributive :
∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) xs₁ xs₂ →
fs ⊛ (xs₁ ++ xs₂) ∼[ bag ] (fs ⊛ xs₁) ++ (fs ⊛ xs₂)
⊛-left-distributive {B = B} fs xs₁ xs₂ = begin
fs ⊛ (xs₁ ++ xs₂) ≡⟨ P.refl ⟩
(fs >>= λ f → xs₁ ++ xs₂ >>= return ∘ f) ≡⟨ (LP.Monad.cong (P.refl {x = fs}) λ f →
LP.Monad.right-distributive xs₁ xs₂ (return ∘ f)) ⟩
(fs >>= λ f → (xs₁ >>= return ∘ f) ++
(xs₂ >>= return ∘ f)) ≈⟨ >>=-left-distributive fs ⟩
(fs >>= λ f → xs₁ >>= return ∘ f) ++
(fs >>= λ f → xs₂ >>= return ∘ f) ≡⟨ P.refl ⟩
(fs ⊛ xs₁) ++ (fs ⊛ xs₂) ∎
where open EqR ([ bag ]-Equality B)
private
-- If x ∷ xs is set equal to x ∷ ys, then xs and ys are not
-- necessarily set equal.
¬-drop-cons :
∀ {a} {A : Set a} {x : A} →
¬ (∀ {xs ys} → x ∷ xs ∼[ set ] x ∷ ys → xs ∼[ set ] ys)
¬-drop-cons {x = x} drop-cons
with FE.Equivalence.to x∼[] ⟨$⟩ here P.refl
where
x,x≈x : (x ∷ x ∷ []) ∼[ set ] [ x ]
x,x≈x = ++-idempotent [ x ]
x∼[] : [ x ] ∼[ set ] []
x∼[] = drop-cons x,x≈x
... | ()
-- However, the corresponding property does hold for bag equality.
drop-cons : ∀ {a} {A : Set a} {x : A} {xs ys} →
x ∷ xs ∼[ bag ] x ∷ ys → xs ∼[ bag ] ys
drop-cons {A = A} {x} {xs} {ys} x∷xs≈x∷ys {z} = record
{ to = P.→-to-⟶ $ f x∷xs≈x∷ys
; from = P.→-to-⟶ $ f $ Inv.sym x∷xs≈x∷ys
; inverse-of = record
{ left-inverse-of = f∘f x∷xs≈x∷ys
; right-inverse-of = f∘f $ Inv.sym x∷xs≈x∷ys
}
}
where
open Inverse
open P.≡-Reasoning
f : ∀ {xs ys z} → (z ∈ x ∷ xs) ↔ (z ∈ x ∷ ys) → z ∈ xs → z ∈ ys
f inv z∈xs with to inv ⟨$⟩ there z∈xs | left-inverse-of inv (there z∈xs)
f inv z∈xs | there z∈ys | left⁺ = z∈ys
f inv z∈xs | here z≡x | left⁺ with to inv ⟨$⟩ here z≡x | left-inverse-of inv (here z≡x)
f inv z∈xs | here z≡x | left⁺ | there z∈ys | left⁰ = z∈ys
f inv z∈xs | here P.refl | left⁺ | here P.refl | left⁰ with begin
here P.refl ≡⟨ P.sym left⁰ ⟩
from inv ⟨$⟩ here P.refl ≡⟨ left⁺ ⟩
there z∈xs ∎
... | ()
f∘f : ∀ {xs ys z}
(inv : (z ∈ x ∷ xs) ↔ (z ∈ x ∷ ys)) (p : z ∈ xs) →
f (Inv.sym inv) (f inv p) ≡ p
f∘f inv z∈xs with to inv ⟨$⟩ there z∈xs | left-inverse-of inv (there z∈xs)
f∘f inv z∈xs | there z∈ys | left⁺ with from inv ⟨$⟩ there z∈ys | right-inverse-of inv (there z∈ys)
f∘f inv z∈xs | there z∈ys | P.refl | .(there z∈xs) | _ = P.refl
f∘f inv z∈xs | here z≡x | left⁺ with to inv ⟨$⟩ here z≡x | left-inverse-of inv (here z≡x)
f∘f inv z∈xs | here z≡x | left⁺ | there z∈ys | left⁰ with from inv ⟨$⟩ there z∈ys | right-inverse-of inv (there z∈ys)
f∘f inv z∈xs | here z≡x | left⁺ | there z∈ys | P.refl | .(here z≡x) | _ with from inv ⟨$⟩ here z≡x
| right-inverse-of inv (here z≡x)
f∘f inv z∈xs | here z≡x | P.refl | there z∈ys | P.refl | .(here z≡x) | _ | .(there z∈xs) | _ = P.refl
f∘f inv z∈xs | here P.refl | left⁺ | here P.refl | left⁰ with begin
here P.refl ≡⟨ P.sym left⁰ ⟩
from inv ⟨$⟩ here P.refl ≡⟨ left⁺ ⟩
there z∈xs ∎
... | ()
|
{
"alphanum_fraction": 0.4731615925,
"avg_line_length": 39.1025641026,
"ext": "agda",
"hexsha": "bbda405f93ddd2daa596a0214097db43f8951040",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda",
"max_line_length": 125,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 4543,
"size": 10675
}
|
-- Issue 3536 reported by Malin Altenmüller
-- The problem was that the Treeless compiler reruns the clause
-- compiler, but without the split tree from the coverage
-- checker. However, the split tree is necessary to direct the clause
-- compiler.
data Unit : Set where
true : Unit
record R : Set where
coinductive
field
f1 : R
f2 : R
open R public
foo : Unit -> R
f1 (foo true) = foo true
f2 (foo b) = foo b
|
{
"alphanum_fraction": 0.706855792,
"avg_line_length": 20.1428571429,
"ext": "agda",
"hexsha": "697666a247367872da5abe338424f0ba16bd1ab5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3536.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3536.agda",
"max_line_length": 69,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3536.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 123,
"size": 423
}
|
{-# OPTIONS --termination-depth=2 #-}
module TerminationWithMerge where
data List (a : Set) : Set where
[] : List a
_∷_ : a -> List a -> List a
-- infix
postulate
a : Set
Bool : Set
_≤?_ : a -> a -> Bool
merge : List a -> List a -> List a
merge xs [] = xs
merge [] ys = ys
merge (x ∷ xs) (y ∷ ys) with x ≤? y
... | true = x ∷ merge xs (y ∷ ys)
... | false = y ∷ merge (x ∷ xs) ys
{- still cannot pass the termination checker, since
size(x :: xs) <= 1 + max(size(x),size(xs))
but the termination checker does not have maximum, and no
type information that tells it to ignore x in this caculation.
Solution: sized types!
-}
|
{
"alphanum_fraction": 0.5691411936,
"avg_line_length": 21.46875,
"ext": "agda",
"hexsha": "11688388e3005fa71fb700875364d993920a7cfe",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/TerminationWithMerge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/TerminationWithMerge.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/TerminationWithMerge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 214,
"size": 687
}
|
postulate
F : Set → Set
{-# POLARITY F ⚄ #-}
|
{
"alphanum_fraction": 0.5208333333,
"avg_line_length": 9.6,
"ext": "agda",
"hexsha": "b52f6a1171716d42ae1d3efdb7047814f6e11eb8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Invalid-polarity.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Invalid-polarity.agda",
"max_line_length": 20,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Invalid-polarity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 19,
"size": 48
}
|
data ⊥ : Set where
record ⊤ : Set where
constructor unit
data T : ⊥ → Set where
con : (i : ⊥) → T i
module M (x : ⊤) where
bar : (i : ⊥) → T i → ⊥
bar .i (con i) = i
module N where
foo : ⊥
foo = i
-- Should not be accepted.
-- Type signature should be `test : ⊥ → ⊥`
test : ⊥ → ⊥
test = N.foo
false : ⊥
false = M.test unit unit
|
{
"alphanum_fraction": 0.5081967213,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "9c1f9b9470428399247e1794fb51580e7a0575dc",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue4163.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue4163.agda",
"max_line_length": 44,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue4163.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 143,
"size": 366
}
|
module sn-calculus-confluence.potrec where
open import utility
open import sn-calculus
open import context-properties
using (->pot-view ; ->E-view)
open import sn-calculus-confluence.helper
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Properties
using (canθₛ-subset ; canθₛₕ-subset ; canθₛ-membership ; canθₛₕ-membership
; canθₛ-mergeˡ ; canθₛₕ-mergeˡ
; canθ-is-present ; canθ-is-absent
; canθₛₕ-emit ; canθₛ-emit
; term-raise ; canₛ-raise ; canₛₕ-raise
; term-nothin ; canₛ-term-nothin ; canₛₕ-term-nothin
; canₛ-if-true ; canₛ-if-false ; canₛₕ-if-true ; canₛₕ-if-false
; canₛ-capture-emit-signal ; canₛₕ-capture-set-shared)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; [] ; _∷_ ; [_])
open import Data.List.Any
using (Any ; here ; there ; any)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; _≟_ ; zero ; suc ; _+_)
open import Data.Product
using (Σ ; Σ-syntax ; _,_ ; proj₁ ; proj₂ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function
using (_∘_ ; id ; _∋_)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; trans ; cong ; subst ; module ≡-Reasoning)
open ->pot-view
open ->E-view
open term-nothin
open term-raise
open ≡-Reasoning
using (begin_ ; _∎ ; _≡⟨_⟩_ ; _≡⟨⟩_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
ρ-pot-conf-rec : ∀{p θ ql θl qr θr p≡ql E pin qin FV₀ BV₀ A Al Ar A≡Al}
→ {ρθ·psn⟶₁ρθl·ql : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θl , Al ⟩· ql)}
→ {ρθ·psn⟶₁ρθr·qr : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θr , Ar ⟩· qr)}
→ {p≐E⟦pin⟧ : p ≐ E ⟦ pin ⟧e}
→ {qr≐E⟦qin⟧ : qr ≐ E ⟦ qin ⟧e}
→ CorrectBinding (ρ⟨ θ , A ⟩· p) FV₀ BV₀
→ ->pot-view ρθ·psn⟶₁ρθl·ql p≡ql A≡Al
→ ->E-view ρθ·psn⟶₁ρθr·qr p≐E⟦pin⟧ qr≐E⟦qin⟧
→
(ρ⟨ θl , Al ⟩· ql sn⟶₁ ρ⟨ θr , Ar ⟩· qr) ⊎
(Σ[ s ∈ Term ]
Σ[ θo ∈ Env.Env ]
Σ[ Ao ∈ Ctrl ]
(ρ⟨ θl , Al ⟩· ql) sn⟶₁ (ρ⟨ θo , Ao ⟩· s)
× (ρ⟨ θr , Ar ⟩· qr) sn⟶₁ (ρ⟨ θo , Ao ⟩· s))
ρ-pot-conf-rec {p} {θ} {ql} {θl} {.(E ⟦ qin ⟧e)} {θr} {_} {E} {(ρ⟨ .θin , Ain ⟩· .qin)} {qin} {_} {_} {A} {.A} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)} {.(rmerge {θ} {θin} p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vmerge {.θ} {θin} {.p} {.qin} {.E})
with Env.Sig∈ S θin
... | yes S∈Domθin
rewrite SigMap.update-union-union S Signal.absent (Env.sig θ) (Env.sig θin) S∈ S∈Domθin
= inj₁ (ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ (θl ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋ rmerge {θl} {θin} p≐E⟦pin⟧)
... | no S∉Domθin
with Env.sig-←-irr-get {θ} {θin} {S} S∈ S∉Domθin -- θr ≡ (θ ← θin)
... | S∈Domθ←θin , θS≡⟨θ←θin⟩S
= inj₂
(_ , _ , A-max A Ain ,
subst (λ { θ* → ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ θ* , A-max A Ain ⟩· E ⟦ qin ⟧e})
((Env.set-sig {S} θ S∈ Signal.absent) ← θin ≡
Env.set-sig {S} (θ ← θin) S∈Domθ←θin Signal.absent ∋
cong (λ sig* → Θ sig* (Env.shr (θ ← θin)) (Env.var (θ ← θin)))
(SigMap.put-union-comm S Signal.absent (Env.sig θ) (Env.sig θin) S∉Domθin))
(ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ (θl ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋
rmerge {θl} {θin} p≐E⟦pin⟧) ,′
(ρ⟨ (θ ← θin) , A-max A Ain ⟩· E ⟦ qin ⟧e sn⟶₁ ρ⟨ (Env.set-sig {S} (θ ← θin) S∈Domθ←θin Signal.absent) , A-max A Ain ⟩· E ⟦ qin ⟧e ∋
(rabsence {θr} {_} {S} S∈Domθ←θin (trans (sym θS≡⟨θ←θin⟩S) θS≡unknown)
(λ S∈can-E⟦qin⟧-θ←θin →
S∉can-p-θ
(canθₛ-mergeˡ (Env.sig θ) Env.[]env cbp p≐E⟦pin⟧
S S∉Domθin S∈can-E⟦qin⟧-θ←θin)))))
ρ-pot-conf-rec {p} {θ} {ql} {θl} {.(E ⟦ qin ⟧e)} {θr} {_} {E} {(ρ⟨ .θin , Ain ⟩· qin)} {qin} {_} {_} {A} {Al} {Ar} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)} {.(rmerge p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vmerge {.θ} {θin} {.p} {.qin} {.E})
with Env.Shr∈ s θin
... | yes s∈Domθin
rewrite ShrMap.update-union-union s (SharedVar.ready , Env.shr-vals {s} θ s∈) (Env.shr θ) (Env.shr θin) s∈ s∈Domθin
= inj₁ (rmerge {θl} {θin} p≐E⟦pin⟧)
... | no s∉Domθin
with Env.shr-←-irr-get {θ} {θin} {s} s∈ s∉Domθin
... | s∈Domθ←θin , θs≡⟨θ←θin⟩s
= inj₂
(_ , _ , _ ,
subst (λ { θ* → ρ⟨ θl , A ⟩· ql sn⟶₁ ρ⟨ θ* , A-max A Ain ⟩· E ⟦ qin ⟧e })
(cong (λ shr* → Θ (Env.sig (θ ← θin)) shr* (Env.var (θ ← θin)))
(trans
(cong (λ shrval* →
ShrMap.union
(ShrMap.update (Env.shr θ) s (SharedVar.ready , proj₂ shrval*))
(Env.shr θin))
(ShrMap.U-∉-irr-get-help-m {_} {Env.shr θ} {Env.shr θin} {s}
s∈ s∉Domθin s∈Domθ←θin ))
(ShrMap.put-union-comm s (SharedVar.ready , Env.shr-vals {s} (θ ← θin) s∈Domθ←θin)
(Env.shr θ) (Env.shr θin) s∉Domθin)))
(rmerge {θl} {θin} p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθ←θin
(Data.Sum.map (trans (sym θs≡⟨θ←θin⟩s)) (trans (sym θs≡⟨θ←θin⟩s))
θs≡old⊎θs≡new)
(λ s∈can-E⟦qin⟧-θ←θin →
s∉can-p-θ
(canθₛₕ-mergeˡ (Env.sig θ) Env.[]env cbp p≐E⟦pin⟧
s s∉Domθin s∈can-E⟦qin⟧-θ←θin)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ qin ∣⇒ _)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(ris-present {θ} {S'} S'∈ θS'≡present p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vis-present {.θ} {S'} {S∈ = S'∈} {θS'≡present} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
((Signal.unknown ≡ Signal.present → _) ∋ λ ())
(trans (trans (sym θS≡unknown) (Env.sig-stats-∈-irr {S} {θ} S∈ S'∈)) θS'≡present)
... | no S'≠S =
inj₂
(_ , _ , _ ,
ris-present {θl} {S'}
(Env.sig-set-mono' {S'} {S} {θ} {_} {S∈} S'∈)
(Env.sig-putputget {S'} {S} {θ} S'≠S S'∈ S∈ _ θS'≡present)
p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧-θ →
S∉can-p-θ
(subst (Signal.unwrap S ∈_)
(cong proj₁ (sym (canθ-is-present (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡present)) )
S∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ _ ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(ris-absent {θ} {S'} S'∈ θS'≡absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vis-absent {.θ} {S'} {S∈ = S'∈} {θS'≡absent} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
((Signal.unknown ≡ Signal.absent → _) ∋ λ ())
(trans (trans (sym θS≡unknown) (Env.sig-stats-∈-irr {S} {θ} S∈ S'∈)) θS'≡absent)
... | no S'≠S =
inj₂
(_ , _ , _ ,
ris-absent {θl} {S'}
(Env.sig-set-mono' {S'} {S} {θ} {_} {S∈} S'∈)
(Env.sig-putputget {S'} {S} {θ} S'≠S S'∈ S∈ _ θS'≡absent)
p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧-θ →
S∉can-p-θ
(subst (Signal.unwrap S ∈_)
(cong proj₁ (sym (canθ-is-absent (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡absent)))
S∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ qin ∣⇒ _)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(ris-present {θ} {S'} S'∈ θS'≡present p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vis-present {.θ} {S'} {S∈ = S'∈} {θS'≡present} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
ris-present {θl} {S'} S'∈ θS'≡present p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧-θ →
s∉can-p-θ
(subst (SharedVar.unwrap s ∈_)
(cong (proj₂ ∘ proj₂)
(sym (canθ-is-present (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡present)))
s∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(present _ ∣⇒ _ ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(ris-absent {θ} {S'} S'∈ θS'≡absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vis-absent {.θ} {S'} {S∈ = S'∈} {θS'≡absent} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
ris-absent {θl} {S'} S'∈ θS'≡absent p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧-θ →
s∉can-p-θ
(subst (SharedVar.unwrap s ∈_)
(cong (proj₂ ∘ proj₂)
(sym (canθ-is-absent (Env.sig θ) S'∈ Env.[]env p≐E⟦pin⟧ θS'≡absent)))
s∈can-E⟦qin⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(emit S')} {.nothin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(remit {θ} {p} {S'} S'∈ θS'≢absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vemit {.θ} {.p} {S'} {.E} {S'∈} {θS'≢absent} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
remit {θl} {_} {S'} S'∈ θS'≢absent p≐E⟦pin⟧ ,′
rreadyness {θr} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-emit θ S'∈ Env.[]env p≐E⟦pin⟧
θS'≢absent
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧))
s s∈can-E⟦nothin⟧-θr)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(emit S')} {.nothin} {_} {_} {A} {Al} {Ar} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(remit {θ} {p} {S'} S'∈ θS'≢absent p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧}
(CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vemit {.θ} {.p} {S'} {.E} {S'∈} {θS'≢absent} {.p≐E⟦pin⟧})
with S' Signal.≟ S
... | yes refl =
⊥-elim
(S∉can-p-θ
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧)))
... | no S'≢S =
inj₂
(_ , _ , _ ,
remit {θl} {_} {S'}
(SigMap.insert-mono {_} {S'} {Env.sig θ} {S} {Signal.absent} S'∈)
(θS'≢absent ∘
trans
(sym (SigMap.putputget {_} {Env.sig θ} {S'} {S}
{_} {Signal.absent} S'≢S S'∈ S'∈Domθl refl)))
p≐E⟦pin⟧ ,′
subst (λ sig* → ρ⟨ θr , Ar ⟩· E ⟦ nothin ⟧e sn⟶₁ ρ⟨ (Θ sig* (Env.shr θ) (Env.var θ)) , Ar ⟩· E ⟦ nothin ⟧e)
(SigMap.put-comm {_} {Env.sig θ} {_} {_} {Signal.present} {Signal.absent} S'≢S)
(rabsence {θr} {_} {S}
S∈Domθr
(SigMap.putputget {_} {Env.sig θ} {S} {S'} {_} {Signal.present}
(S'≢S ∘ sym) S∈ S∈Domθr θS≡unknown)
(λ S''∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-emit θ S'∈ Env.[]env p≐E⟦pin⟧
θS'≢absent
(canθₛ-membership (Env.sig θ) 0 p Env.[]env S'
(λ θ* → canₛ-capture-emit-signal θ* p≐E⟦pin⟧))
S S''∈can-E⟦nothin⟧-θr))))
where S∈Domθr = SigMap.insert-mono {_} {S} {Env.sig θ} {S'} {Signal.present} S∈
S'∈Domθl = SigMap.insert-mono {_} {S'} {Env.sig θ} {S} {Signal.absent} S'∈
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(shared s' ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p')}
{_} {_} {A} {Al} {Ar} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rraise-shared e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vraise-shared {.θ} {.p} {s'} {e} {p'} {.E} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , Al ⟩· p) sn⟶₁
(ρ⟨ θl , Al ⟩· E ⟦ ρ⟨ ([s,δe]-env s' δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-shared e'' p≐E⟦pin⟧) ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦ρΘp'⟧-θ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ ([s,δe]-env s' (δ e')) , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ S*)
S S∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(shared s' ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.[ s' ↦ (SharedVar.old , δ e') ] VarMap.empty) , WAIT ⟩· p')}
{_} {_} {A} {Al} {Ar} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rraise-shared e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vraise-shared {.θ} {.p} {s'} {e} {p'} {.E} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , Al ⟩· p) sn⟶₁
(ρ⟨ θl , Al ⟩· E ⟦ ρ⟨ ([s,δe]-env s' δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-shared e'' p≐E⟦pin⟧) ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦ρΘp'⟧-θ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0
(E ⟦ ρ⟨ ([s,δe]-env s' (δ e')) , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-raise θ* (tshared (δ e') s' e p') p≐E⟦pin⟧ s*)
s s∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-shared-value-old {θ} {p} {s'} e' s'∈ θs'≡old p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-shared-value-old {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡old})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (θl-set-shr δe*) , GO ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-shared-value-old {θl} {_} {s'} e'' s'∈ θs'≡old p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θr)))
where
θl-set-shr : ℕ → Env
θl-set-shr n = Env.set-shr {s'} θl s'∈ SharedVar.new n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-shared-value-old {θ} {p} {s'} e' s'∈ θs'≡old p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-shared-value-old {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡old})
with s SharedVar.≟ s'
... | yes refl =
⊥-elim
(s∉can-p-θ
(canθₛₕ-membership (Env.sig θ) 0 p Env.[]env s
(λ θ* → canₛₕ-capture-set-shared θ* p≐E⟦pin⟧)))
... | no s≢s'
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ shr* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (Θ (Env.sig θl) shr* (Env.var θl)) , GO ⟩·
E ⟦ nothin ⟧e)
(cong Env.shr
(begin
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (δ e'')
≡⟨ cong (Env.set-shr {s'} θl s'∈Domθl SharedVar.new) (sym δe'≡δe'') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (δ e')
≡⟨ cong (λ sig* → Θ (Env.sig θ) sig* (Env.var θ))
(ShrMap.put-comm {_} {Env.shr θ} {_} {_}
{SharedVar.ready ,′ θs}
{SharedVar.new ,′ δ e'}
s≢s') ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready θs
≡⟨ cong (Env.set-shr {s} θr s∈Domθr SharedVar.ready ∘ proj₂) (sym θrs≡θs) ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready
(Env.shr-vals {s} θr s∈Domθr) ∎))
(rset-shared-value-old {θl} {_} {s'} e'' s'∈Domθl
(trans (cong proj₁ θls'≡θs') θs'≡old) p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθr
(Data.Sum.map (trans (cong proj₁ θrs≡θs)) (trans (cong proj₁ θrs≡θs))
θs≡old⊎θs≡new)
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θr)))
where
θs = Env.shr-vals {s} θ s∈
s∈Domθr = Env.shr-set-mono' {s} {s'} {θ} {SharedVar.new} {δ e'} {s'∈} s∈
θrs≡θs = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.new ,′ δ e'}
s≢s' s∈ s∈Domθr refl
s'∈Domθl = Env.shr-set-mono' {s'} {s} {θ} {SharedVar.ready} {θs} {s∈} s'∈
θls'≡θs' = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.ready ,′ θs}
(s≢s' ∘ sym) s'∈ s'∈Domθl refl
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-shared-value-new {θ} {p} {s'} e' s'∈ θs'≡new p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-shared-value-new {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡new})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (θl-set-shr δe*) , GO ⟩· E ⟦ nothin ⟧e)
(cong
(Env.shr-vals {s'} θ s'∈ +_)
(sym δe'≡δe''))
(rset-shared-value-new {θl} {_} {s'} e'' s'∈ θs'≡new p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θr →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θr)))
where
θl-set-shr : ℕ → Env
θl-set-shr n = Env.set-shr {s'} θl s'∈ SharedVar.new n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr} {_} {E}
{.(s' ⇐ e)} {.nothin} {_} {_} {GO} {GO} {GO} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-shared-value-new {θ} {p} {s'} e' s'∈ θs'≡new p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-shared-value-new {.θ} {.p} {s'} {e} {.E} {e'} {s'∈} {θs'≡new})
with s SharedVar.≟ s'
... | yes refl =
⊥-elim
(s∉can-p-θ
(canθₛₕ-membership (Env.sig θ) 0 p Env.[]env s
(λ θ* → canₛₕ-capture-set-shared θ* p≐E⟦pin⟧)))
... | no s≢s'
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ shr* →
ρ⟨ θl , GO ⟩· p sn⟶₁
ρ⟨ (Θ (Env.sig θl) shr* (Env.var θl)) , GO ⟩·
E ⟦ nothin ⟧e)
(cong Env.shr
(begin
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (Env.shr-vals {s'} θl s'∈Domθl + δ e'')
≡⟨ cong
(λ v* → Env.set-shr {s'} θl s'∈Domθl SharedVar.new (v* + δ e''))
(cong proj₂ θls'≡θs') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (θs' + δ e'')
≡⟨ cong (λ v* → Env.set-shr {s'} θl s'∈Domθl SharedVar.new
(θs' + v*))
(sym δe'≡δe'') ⟩
Env.set-shr {s'} θl s'∈Domθl SharedVar.new (θs' + δ e')
≡⟨ cong (λ sig* → Θ (Env.sig θ) sig* (Env.var θ))
(ShrMap.put-comm {_} {Env.shr θ} {_} {_}
{SharedVar.ready ,′ θs}
{SharedVar.new ,′ θs' + δ e'}
s≢s') ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready θs
≡⟨ cong (Env.set-shr {s} θr s∈Domθr SharedVar.ready ∘ proj₂) (sym θrs≡θs) ⟩
Env.set-shr {s} θr s∈Domθr SharedVar.ready
(Env.shr-vals {s} θr s∈Domθr) ∎))
(rset-shared-value-new {θl} {_} {s'} e'' s'∈Domθl
(trans (cong proj₁ θls'≡θs') θs'≡new) p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈Domθr
(Data.Sum.map (trans (cong proj₁ θrs≡θs)) (trans (cong proj₁ θrs≡θs))
θs≡old⊎θs≡new)
(λ s∈can-E⟦nothin⟧-θr →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-shr s' e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θr)))
where
θs' = Env.shr-vals {s'} θ s'∈
θs = Env.shr-vals {s} θ s∈
s∈Domθr = Env.shr-set-mono' {s} {s'} {θ} {SharedVar.new} {θs' + δ e'} {s'∈} s∈
θrs≡θs = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.new ,′ θs' + δ e'}
s≢s' s∈ s∈Domθr refl
s'∈Domθl = Env.shr-set-mono' {s'} {s} {θ} {SharedVar.ready} {θs} {s∈} s'∈
θls'≡θs' = ShrMap.putputget {_} {Env.shr θ} {_} {_} {_} {SharedVar.ready ,′ θs}
(s≢s' ∘ sym) s'∈ s'∈Domθl refl
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(var x ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p')}
{_} {_} {A} {.A} {.A} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rraise-var {θ} {p} {x} {p'} {e} e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vraise-var {.θ} {.p} {x} {p'} {e} {.E} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , A ⟩· p) sn⟶₁
(ρ⟨ θl , A ⟩· E ⟦ ρ⟨ ([x,δe]-env x δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-var {θl} {_} {x} {p'} {e} e'' p≐E⟦pin⟧) ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦ρΘp'⟧-θ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ [x,δe]-env x (δ e') , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ S*)
S S∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl}
{.(E ⟦ ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p' ⟧e)}
{.θ} {_} {E}
{.(var x ≔ e in: p')}
{.(ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p')}
{_} {_} {A} {.A} {.A} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rraise-var {θ} {p} {x} {p'} {e} e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vraise-var {.θ} {.p} {x} {p'} {e} {.E} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
(ρ⟨ θl , A ⟩· p) sn⟶₁
(ρ⟨ θl , A ⟩· E ⟦ ρ⟨ ([x,δe]-env x δe*) , WAIT ⟩· p' ⟧e))
(sym δe'≡δe'')
(rraise-var {θl} {_} {x} {p'} {e} e'' p≐E⟦pin⟧) ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦ρΘp'⟧-θ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ ρ⟨ [x,δe]-env x (δ e') , WAIT ⟩· p' ⟧e) p Env.[]env
(λ θ* S* → canₛ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-raise θ* (tvar (δ e') x e p') p≐E⟦pin⟧ s*)
s s∈can-E⟦ρΘp'⟧-θ)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr}
{_} {E} {.(x ≔ e)} {.nothin} {_} {_} {A} {.A} {.A} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rset-var {θ} {p} {x} {e} x∈ e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vset-var {.θ} {.p} {x} {e} {.E} {x∈} {e'} {.p≐E⟦pin⟧})
with ready-maint/irr S S∈ Signal.absent e'
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , A ⟩· p sn⟶₁
ρ⟨ (θl-set-var δe*) , A ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-var {θl} {_} {x} {e} x∈ e'' p≐E⟦pin⟧) ,′
rabsence {θr} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦nothin⟧-θ' →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ S*)
S S∈can-E⟦nothin⟧-θ')))
where
θl-set-var : ℕ → Env
θl-set-var n = Env.set-var {x} θl x∈ n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ nothin ⟧e)} {θr}
{_} {E} {.(x ≔ e)} {.nothin} {_} {_} {A} {.A} {.A} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rset-var {θ} {p} {x} {e} x∈ e' p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vset-var {.θ} {.p} {x} {e} {.E} {x∈} {e'} {.p≐E⟦pin⟧})
with ready-irr-on-irr-s/ready {θ} {e} s (Env.shr-vals {s} θ s∈) s∈ (θs≢ready θs≡old⊎θs≡new)
e'
where θs≢ready : typeof θs≡old⊎θs≡new → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready)
θs≢ready (inj₁ θs≡old) θs≡ready with trans (sym θs≡old) θs≡ready
... | ()
θs≢ready (inj₂ θs≡new) θs≡ready with trans (sym θs≡new) θs≡ready
... | ()
... | e'' , δe'≡δe'' =
inj₂
(_ , _ , _ ,
subst (λ δe* →
ρ⟨ θl , A ⟩· p sn⟶₁
ρ⟨ (θl-set-var δe*) , A ⟩· E ⟦ nothin ⟧e)
(sym δe'≡δe'')
(rset-var {θl} {_} {x} {e} x∈ e'' p≐E⟦pin⟧) ,′
rreadyness {θr} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦nothin⟧-θ' →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ nothin ⟧e) p Env.[]env
(λ θ* S* → canₛ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-term-nothin θ* θ* refl (tset-var x e) p≐E⟦pin⟧ s*)
s s∈can-E⟦nothin⟧-θ')))
where
θl-set-var : ℕ → Env
θl-set-var n = Env.set-var {x} θl x∈ n
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ th ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vif-false {.θ} {.p} {th} {.qin} {x} {.E} {x∈} {θx≡zero} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-false θ* p≐E⟦pin⟧ S*)
S S∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ th ∣⇒ qin)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vif-false {.θ} {.p} {th} {.qin} {x} {.E} {x∈} {θx≡zero} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-false {x = x} x∈ θx≡zero p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-false θ* p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-if-false θ* p≐E⟦pin⟧ s*)
s s∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ qin ∣⇒ els)} {qin} {_} {_} {_} {_} {_} {_}
{.(rabsence {θ} {p} {S} S∈ θS≡unknown S∉can-p-θ)}
{.(rif-true {x = x} {E} {n} x∈ θx≡suc p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
(vif-true {.θ} {.p} {.qin} {els} {x} {.E} {n} {x∈} {θx≡suc} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-true {x = x} x∈ θx≡suc p≐E⟦pin⟧ ,′
rabsence {θ} {_} {S} S∈ θS≡unknown
(λ S∈can-E⟦qin⟧ →
S∉can-p-θ
(canθₛ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-true θ* p≐E⟦pin⟧ S*)
S S∈can-E⟦qin⟧)))
ρ-pot-conf-rec {p} {θ} {.p} {θl} {.(E ⟦ qin ⟧e)} {.θ} {_} {E}
{.(if x ∣⇒ qin ∣⇒ els)} {qin} {_} {_} {_} {_} {_} {_}
{.(rreadyness {θ} {p} {s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
{.(rif-true {x = x} {E} {n} x∈ θx≡suc p≐E⟦pin⟧)}
{p≐E⟦pin⟧} {qr≐E⟦qin⟧} (CBρ cbp)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vif-true {.θ} {.p} {.qin} {els} {x} {.E} {n} {x∈} {θx≡suc} {.p≐E⟦pin⟧}) =
inj₂
(_ , _ , _ ,
rif-true {x = x} x∈ θx≡suc p≐E⟦pin⟧ ,′
rreadyness {θ} {_} {s} s∈ θs≡old⊎θs≡new
(λ s∈can-E⟦qin⟧ →
s∉can-p-θ
(canθₛₕ-subset (Env.sig θ) 0 (E ⟦ qin ⟧e) p Env.[]env
(λ θ* S* → canₛ-if-true θ* p≐E⟦pin⟧ S*)
(λ θ* s* → canₛₕ-if-true θ* p≐E⟦pin⟧ s*)
s s∈can-E⟦qin⟧)))
|
{
"alphanum_fraction": 0.4525395891,
"avg_line_length": 42.740397351,
"ext": "agda",
"hexsha": "3d58a993f4c6bc86cd5491e4665afdb5df87c7d6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-confluence/potrec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-confluence/potrec.agda",
"max_line_length": 137,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-confluence/potrec.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 16297,
"size": 32269
}
|
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
module _ {X : Set} {x : X} where
test : (p q : Σ X (x ≡_)) → p ≡ q
test (.x , refl) (z , q) = {!q!}
-- C-c C-c q RET:
-- WAS: test (_ , refl) (_ , refl)
-- WANT: preserved user-written pattern
-- test (.x , refl) (_ , refl)
test' : (p q : Σ X (x ≡_)) → p ≡ q
test' (x , refl) (z , q) = {!q!}
-- here it's fine!
-- C-c C-c q RET gives us:
-- test' (x , refl) (.x , refl) = {!!}
|
{
"alphanum_fraction": 0.4989200864,
"avg_line_length": 21.0454545455,
"ext": "agda",
"hexsha": "ba04725c981787f0f1fd29757c0ff4df31b32327",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue3964.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue3964.agda",
"max_line_length": 39,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue3964.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 185,
"size": 463
}
|
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
id : ∀ {a} {A : Set a} → A → A
id x = x
macro
my-macro : Term → TC ⊤
my-macro goal = bindTC
(getType (quote id))
λ idType → bindTC
(reduce idType)
λ _ → returnTC _
fails? : ⊤
fails? = my-macro
|
{
"alphanum_fraction": 0.6234177215,
"avg_line_length": 17.5555555556,
"ext": "agda",
"hexsha": "b5fb158af015480cd1cb25ce8d6416ddcc10f588",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue4585.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue4585.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue4585.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 109,
"size": 316
}
|
-----------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the heterogeneous sublist relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Sublist.Heterogeneous.Properties where
open import Level
open import Data.Bool.Base using (true; false)
open import Data.Empty
open import Data.List.Relation.Unary.All using (Null; []; _∷_)
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Base as List hiding (map; _∷ʳ_)
import Data.List.Properties as Lₚ
open import Data.List.Relation.Unary.Any.Properties
using (here-injective; there-injective)
open import Data.List.Relation.Binary.Pointwise as Pw using (Pointwise; []; _∷_)
open import Data.List.Relation.Binary.Sublist.Heterogeneous
open import Data.Maybe.Relation.Unary.All as MAll using (nothing; just)
open import Data.Nat.Base using (ℕ; _≤_; _≥_); open ℕ; open _≤_
import Data.Nat.Properties as ℕₚ
open import Data.Product using (∃₂; _×_; _,_; proj₂; uncurry)
open import Function.Base
open import Function.Bijection using (_⤖_; bijection)
open import Function.Equivalence using (_⇔_ ; equivalence)
open import Relation.Nullary.Reflects using (invert)
open import Relation.Nullary using (Dec; does; _because_; yes; no; ¬_)
open import Relation.Nullary.Negation using (¬?)
import Relation.Nullary.Decidable as Dec
open import Relation.Unary as U using (Pred)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Injectivity of constructors
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
∷-injectiveˡ : ∀ {x y xs ys} {px qx : R x y} {pxs qxs : Sublist R xs ys} →
(Sublist R (x ∷ xs) (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → px ≡ qx
∷-injectiveˡ P.refl = P.refl
∷-injectiveʳ : ∀ {x y xs ys} {px qx : R x y} {pxs qxs : Sublist R xs ys} →
(Sublist R (x ∷ xs) (y ∷ ys) ∋ px ∷ pxs) ≡ (qx ∷ qxs) → pxs ≡ qxs
∷-injectiveʳ P.refl = P.refl
∷ʳ-injective : ∀ {y xs ys} {pxs qxs : Sublist R xs ys} →
(Sublist R xs (y ∷ ys) ∋ y ∷ʳ pxs) ≡ (y ∷ʳ qxs) → pxs ≡ qxs
∷ʳ-injective P.refl = P.refl
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
length-mono-≤ : ∀ {as bs} → Sublist R as bs → length as ≤ length bs
length-mono-≤ [] = z≤n
length-mono-≤ (y ∷ʳ rs) = ℕₚ.≤-step (length-mono-≤ rs)
length-mono-≤ (r ∷ rs) = s≤s (length-mono-≤ rs)
------------------------------------------------------------------------
-- Conversion to and from Pointwise (proto-reflexivity)
fromPointwise : Pointwise R ⇒ Sublist R
fromPointwise [] = []
fromPointwise (p ∷ ps) = p ∷ fromPointwise ps
toPointwise : ∀ {as bs} → length as ≡ length bs →
Sublist R as bs → Pointwise R as bs
toPointwise {bs = []} eq [] = []
toPointwise {bs = b ∷ bs} eq (r ∷ rs) = r ∷ toPointwise (ℕₚ.suc-injective eq) rs
toPointwise {bs = b ∷ bs} eq (b ∷ʳ rs) =
⊥-elim $ ℕₚ.<-irrefl eq (s≤s (length-mono-≤ rs))
------------------------------------------------------------------------
-- Various functions' outputs are sublists
-- These lemmas are generalisations of results of the form `f xs ⊆ xs`.
-- (where _⊆_ stands for Sublist R). If R is reflexive then we can indeed
-- obtain `f xs ⊆ xs` from `xs ⊆ ys → f xs ⊆ ys`. The other direction is
-- only true if R is both reflexive and transitive.
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
tail-Sublist : ∀ {as bs} → Sublist R as bs →
MAll.All (λ as → Sublist R as bs) (tail as)
tail-Sublist [] = nothing
tail-Sublist (b ∷ʳ ps) = MAll.map (b ∷ʳ_) (tail-Sublist ps)
tail-Sublist (p ∷ ps) = just (_ ∷ʳ ps)
take-Sublist : ∀ {as bs} n → Sublist R as bs → Sublist R (take n as) bs
take-Sublist n (y ∷ʳ rs) = y ∷ʳ take-Sublist n rs
take-Sublist zero rs = minimum _
take-Sublist (suc n) [] = []
take-Sublist (suc n) (r ∷ rs) = r ∷ take-Sublist n rs
drop-Sublist : ∀ n → Sublist R ⇒ (Sublist R ∘′ drop n)
drop-Sublist n (y ∷ʳ rs) = y ∷ʳ drop-Sublist n rs
drop-Sublist zero rs = rs
drop-Sublist (suc n) [] = []
drop-Sublist (suc n) (r ∷ rs) = _ ∷ʳ drop-Sublist n rs
module _ {a b r p} {A : Set a} {B : Set b}
{R : REL A B r} {P : Pred A p} (P? : U.Decidable P) where
takeWhile-Sublist : ∀ {as bs} → Sublist R as bs → Sublist R (takeWhile P? as) bs
takeWhile-Sublist [] = []
takeWhile-Sublist (y ∷ʳ rs) = y ∷ʳ takeWhile-Sublist rs
takeWhile-Sublist {a ∷ as} (r ∷ rs) with does (P? a)
... | true = r ∷ takeWhile-Sublist rs
... | false = minimum _
dropWhile-Sublist : ∀ {as bs} → Sublist R as bs → Sublist R (dropWhile P? as) bs
dropWhile-Sublist [] = []
dropWhile-Sublist (y ∷ʳ rs) = y ∷ʳ dropWhile-Sublist rs
dropWhile-Sublist {a ∷ as} (r ∷ rs) with does (P? a)
... | true = _ ∷ʳ dropWhile-Sublist rs
... | false = r ∷ rs
filter-Sublist : ∀ {as bs} → Sublist R as bs → Sublist R (filter P? as) bs
filter-Sublist [] = []
filter-Sublist (y ∷ʳ rs) = y ∷ʳ filter-Sublist rs
filter-Sublist {a ∷ as} (r ∷ rs) with does (P? a)
... | true = r ∷ filter-Sublist rs
... | false = _ ∷ʳ filter-Sublist rs
------------------------------------------------------------------------
-- Various functions are increasing wrt _⊆_
-- We write f⁺ for the proof that `xs ⊆ ys → f xs ⊆ f ys`
-- and f⁻ for the one that `f xs ⊆ f ys → xs ⊆ ys`.
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
------------------------------------------------------------------------
-- _∷_
∷ˡ⁻ : ∀ {a as bs} → Sublist R (a ∷ as) bs → Sublist R as bs
∷ˡ⁻ (y ∷ʳ rs) = y ∷ʳ ∷ˡ⁻ rs
∷ˡ⁻ (r ∷ rs) = _ ∷ʳ rs
∷ʳ⁻ : ∀ {a as b bs} → ¬ R a b → Sublist R (a ∷ as) (b ∷ bs) →
Sublist R (a ∷ as) bs
∷ʳ⁻ ¬r (y ∷ʳ rs) = rs
∷ʳ⁻ ¬r (r ∷ rs) = ⊥-elim (¬r r)
∷⁻ : ∀ {a as b bs} → Sublist R (a ∷ as) (b ∷ bs) → Sublist R as bs
∷⁻ (y ∷ʳ rs) = ∷ˡ⁻ rs
∷⁻ (x ∷ rs) = rs
module _ {a b c d r} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
{R : REL C D r} where
------------------------------------------------------------------------
-- map
map⁺ : ∀ {as bs} (f : A → C) (g : B → D) →
Sublist (λ a b → R (f a) (g b)) as bs →
Sublist R (List.map f as) (List.map g bs)
map⁺ f g [] = []
map⁺ f g (y ∷ʳ rs) = g y ∷ʳ map⁺ f g rs
map⁺ f g (r ∷ rs) = r ∷ map⁺ f g rs
map⁻ : ∀ {as bs} (f : A → C) (g : B → D) →
Sublist R (List.map f as) (List.map g bs) →
Sublist (λ a b → R (f a) (g b)) as bs
map⁻ {[]} {bs} f g rs = minimum _
map⁻ {a ∷ as} {b ∷ bs} f g (_ ∷ʳ rs) = b ∷ʳ map⁻ f g rs
map⁻ {a ∷ as} {b ∷ bs} f g (r ∷ rs) = r ∷ map⁻ f g rs
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
------------------------------------------------------------------------
-- _++_
++⁺ : ∀ {as bs cs ds} → Sublist R as bs → Sublist R cs ds →
Sublist R (as ++ cs) (bs ++ ds)
++⁺ [] cds = cds
++⁺ (y ∷ʳ abs) cds = y ∷ʳ ++⁺ abs cds
++⁺ (ab ∷ abs) cds = ab ∷ ++⁺ abs cds
++⁻ : ∀ {as bs cs ds} → length as ≡ length bs →
Sublist R (as ++ cs) (bs ++ ds) → Sublist R cs ds
++⁻ {[]} {[]} eq rs = rs
++⁻ {a ∷ as} {b ∷ bs} eq rs = ++⁻ (ℕₚ.suc-injective eq) (∷⁻ rs)
++ˡ : ∀ {as bs} (cs : List B) → Sublist R as bs → Sublist R as (cs ++ bs)
++ˡ zs = ++⁺ (minimum zs)
++ʳ : ∀ {as bs} (cs : List B) → Sublist R as bs → Sublist R as (bs ++ cs)
++ʳ cs [] = minimum cs
++ʳ cs (y ∷ʳ rs) = y ∷ʳ ++ʳ cs rs
++ʳ cs (r ∷ rs) = r ∷ ++ʳ cs rs
------------------------------------------------------------------------
-- concat
concat⁺ : ∀ {ass bss} → Sublist (Sublist R) ass bss →
Sublist R (concat ass) (concat bss)
concat⁺ [] = []
concat⁺ (y ∷ʳ rss) = ++ˡ y (concat⁺ rss)
concat⁺ (rs ∷ rss) = ++⁺ rs (concat⁺ rss)
------------------------------------------------------------------------
-- take / drop
take⁺ : ∀ {m n as bs} → m ≤ n → Pointwise R as bs →
Sublist R (take m as) (take n bs)
take⁺ z≤n ps = minimum _
take⁺ (s≤s m≤n) [] = []
take⁺ (s≤s m≤n) (p ∷ ps) = p ∷ take⁺ m≤n ps
drop⁺ : ∀ {m n as bs} → m ≥ n → Sublist R as bs →
Sublist R (drop m as) (drop n bs)
drop⁺ {m} z≤n rs = drop-Sublist m rs
drop⁺ (s≤s m≥n) [] = []
drop⁺ (s≤s m≥n) (y ∷ʳ rs) = drop⁺ (ℕₚ.≤-step m≥n) rs
drop⁺ (s≤s m≥n) (r ∷ rs) = drop⁺ m≥n rs
drop⁺-≥ : ∀ {m n as bs} → m ≥ n → Pointwise R as bs →
Sublist R (drop m as) (drop n bs)
drop⁺-≥ m≥n pw = drop⁺ m≥n (fromPointwise pw)
drop⁺-⊆ : ∀ {as bs} m → Sublist R as bs →
Sublist R (drop m as) (drop m bs)
drop⁺-⊆ m = drop⁺ (ℕₚ.≤-refl {m})
module _ {a b r p q} {A : Set a} {B : Set b}
{R : REL A B r} {P : Pred A p} {Q : Pred B q}
(P? : U.Decidable P) (Q? : U.Decidable Q) where
⊆-takeWhile-Sublist : ∀ {as bs} →
(∀ {a b} → R a b → P a → Q b) →
Pointwise R as bs → Sublist R (takeWhile P? as) (takeWhile Q? bs)
⊆-takeWhile-Sublist rp⇒q [] = []
⊆-takeWhile-Sublist {a ∷ as} {b ∷ bs} rp⇒q (p ∷ ps) with P? a | Q? b
... | false because _ | _ = minimum _
... | true because _ | true because _ = p ∷ ⊆-takeWhile-Sublist rp⇒q ps
... | yes pa | no ¬qb = ⊥-elim $ ¬qb $ rp⇒q p pa
⊇-dropWhile-Sublist : ∀ {as bs} →
(∀ {a b} → R a b → Q b → P a) →
Pointwise R as bs → Sublist R (dropWhile P? as) (dropWhile Q? bs)
⊇-dropWhile-Sublist rq⇒p [] = []
⊇-dropWhile-Sublist {a ∷ as} {b ∷ bs} rq⇒p (p ∷ ps) with P? a | Q? b
... | true because _ | true because _ = ⊇-dropWhile-Sublist rq⇒p ps
... | true because _ | false because _ =
b ∷ʳ dropWhile-Sublist P? (fromPointwise ps)
... | false because _ | false because _ = p ∷ fromPointwise ps
... | no ¬pa | yes qb = ⊥-elim $ ¬pa $ rq⇒p p qb
⊆-filter-Sublist : ∀ {as bs} → (∀ {a b} → R a b → P a → Q b) →
Sublist R as bs → Sublist R (filter P? as) (filter Q? bs)
⊆-filter-Sublist rp⇒q [] = []
⊆-filter-Sublist rp⇒q (y ∷ʳ rs) with does (Q? y)
... | true = y ∷ʳ ⊆-filter-Sublist rp⇒q rs
... | false = ⊆-filter-Sublist rp⇒q rs
⊆-filter-Sublist {a ∷ as} {b ∷ bs} rp⇒q (r ∷ rs) with P? a | Q? b
... | true because _ | true because _ = r ∷ ⊆-filter-Sublist rp⇒q rs
... | false because _ | true because _ = _ ∷ʳ ⊆-filter-Sublist rp⇒q rs
... | false because _ | false because _ = ⊆-filter-Sublist rp⇒q rs
... | yes pa | no ¬qb = ⊥-elim $ ¬qb $ rp⇒q r pa
module _ {a r p} {A : Set a} {R : Rel A r} {P : Pred A p} (P? : U.Decidable P) where
takeWhile-filter : ∀ {as} → Pointwise R as as →
Sublist R (takeWhile P? as) (filter P? as)
takeWhile-filter [] = []
takeWhile-filter {a ∷ as} (p ∷ ps) with does (P? a)
... | true = p ∷ takeWhile-filter ps
... | false = minimum _
filter-dropWhile : ∀ {as} → Pointwise R as as →
Sublist R (filter P? as) (dropWhile (¬? ∘ P?) as)
filter-dropWhile [] = []
filter-dropWhile {a ∷ as} (p ∷ ps) with does (P? a)
... | true = p ∷ filter-Sublist P? (fromPointwise ps)
... | false = filter-dropWhile ps
------------------------------------------------------------------------
-- reverse
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
reverseAcc⁺ : ∀ {as bs cs ds} → Sublist R as bs → Sublist R cs ds →
Sublist R (reverseAcc cs as) (reverseAcc ds bs)
reverseAcc⁺ [] cds = cds
reverseAcc⁺ (y ∷ʳ abs) cds = reverseAcc⁺ abs (y ∷ʳ cds)
reverseAcc⁺ (r ∷ abs) cds = reverseAcc⁺ abs (r ∷ cds)
ʳ++⁺ : ∀ {as bs cs ds} →
Sublist R as bs →
Sublist R cs ds →
Sublist R (as ʳ++ cs) (bs ʳ++ ds)
ʳ++⁺ = reverseAcc⁺
reverse⁺ : ∀ {as bs} → Sublist R as bs → Sublist R (reverse as) (reverse bs)
reverse⁺ rs = reverseAcc⁺ rs []
reverse⁻ : ∀ {as bs} → Sublist R (reverse as) (reverse bs) → Sublist R as bs
reverse⁻ {as} {bs} p = cast (reverse⁺ p) where
cast = P.subst₂ (Sublist R) (Lₚ.reverse-involutive as) (Lₚ.reverse-involutive bs)
------------------------------------------------------------------------
-- Inversion lemmas
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} {a as b bs} where
∷⁻¹ : R a b → Sublist R as bs ⇔ Sublist R (a ∷ as) (b ∷ bs)
∷⁻¹ r = equivalence (r ∷_) ∷⁻
∷ʳ⁻¹ : ¬ R a b → Sublist R (a ∷ as) bs ⇔ Sublist R (a ∷ as) (b ∷ bs)
∷ʳ⁻¹ ¬r = equivalence (_ ∷ʳ_) (∷ʳ⁻ ¬r)
------------------------------------------------------------------------
-- Irrelevant special case
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
Sublist-[]-irrelevant : U.Irrelevant (Sublist R [])
Sublist-[]-irrelevant [] [] = P.refl
Sublist-[]-irrelevant (y ∷ʳ p) (.y ∷ʳ q) = P.cong (y ∷ʳ_) (Sublist-[]-irrelevant p q)
------------------------------------------------------------------------
-- (to/from)Any is a bijection
toAny-injective : ∀ {xs x} {p q : Sublist R [ x ] xs} → toAny p ≡ toAny q → p ≡ q
toAny-injective {p = y ∷ʳ p} {y ∷ʳ q} =
P.cong (y ∷ʳ_) ∘′ toAny-injective ∘′ there-injective
toAny-injective {p = _ ∷ p} {_ ∷ q} =
P.cong₂ (flip _∷_) (Sublist-[]-irrelevant p q) ∘′ here-injective
fromAny-injective : ∀ {xs x} {p q : Any (R x) xs} →
fromAny {R = R} p ≡ fromAny q → p ≡ q
fromAny-injective {p = here px} {here qx} = P.cong here ∘′ ∷-injectiveˡ
fromAny-injective {p = there p} {there q} =
P.cong there ∘′ fromAny-injective ∘′ ∷ʳ-injective
toAny∘fromAny≗id : ∀ {xs x} (p : Any (R x) xs) → toAny (fromAny {R = R} p) ≡ p
toAny∘fromAny≗id (here px) = P.refl
toAny∘fromAny≗id (there p) = P.cong there (toAny∘fromAny≗id p)
Sublist-[x]-bijection : ∀ {x xs} → (Sublist R [ x ] xs) ⤖ (Any (R x) xs)
Sublist-[x]-bijection = bijection toAny fromAny toAny-injective toAny∘fromAny≗id
------------------------------------------------------------------------
-- Relational properties
module Reflexivity
{a r} {A : Set a} {R : Rel A r}
(R-refl : Reflexive R) where
reflexive : _≡_ ⇒ Sublist R
reflexive P.refl = fromPointwise (Pw.refl R-refl)
refl : Reflexive (Sublist R)
refl = reflexive P.refl
open Reflexivity public
module Transitivity
{a b c r s t} {A : Set a} {B : Set b} {C : Set c}
{R : REL A B r} {S : REL B C s} {T : REL A C t}
(rs⇒t : Trans R S T) where
trans : Trans (Sublist R) (Sublist S) (Sublist T)
trans rs (y ∷ʳ ss) = y ∷ʳ trans rs ss
trans (y ∷ʳ rs) (s ∷ ss) = _ ∷ʳ trans rs ss
trans (r ∷ rs) (s ∷ ss) = rs⇒t r s ∷ trans rs ss
trans [] [] = []
open Transitivity public
module Antisymmetry
{a b r s e} {A : Set a} {B : Set b}
{R : REL A B r} {S : REL B A s} {E : REL A B e}
(rs⇒e : Antisym R S E) where
open ℕₚ.≤-Reasoning
antisym : Antisym (Sublist R) (Sublist S) (Pointwise E)
antisym [] [] = []
antisym (r ∷ rs) (s ∷ ss) = rs⇒e r s ∷ antisym rs ss
-- impossible cases
antisym (_∷ʳ_ {xs} {ys₁} y rs) (_∷ʳ_ {ys₂} {zs} z ss) =
⊥-elim $ ℕₚ.<-irrefl P.refl $ begin
length (y ∷ ys₁) ≤⟨ length-mono-≤ ss ⟩
length zs ≤⟨ ℕₚ.n≤1+n (length zs) ⟩
length (z ∷ zs) ≤⟨ length-mono-≤ rs ⟩
length ys₁ ∎
antisym (_∷ʳ_ {xs} {ys₁} y rs) (_∷_ {y} {ys₂} {z} {zs} s ss) =
⊥-elim $ ℕₚ.<-irrefl P.refl $ begin
length (z ∷ zs) ≤⟨ length-mono-≤ rs ⟩
length ys₁ ≤⟨ length-mono-≤ ss ⟩
length zs ∎
antisym (_∷_ {x} {xs} {y} {ys₁} r rs) (_∷ʳ_ {ys₂} {zs} z ss) =
⊥-elim $ ℕₚ.<-irrefl P.refl $ begin
length (y ∷ ys₁) ≤⟨ length-mono-≤ ss ⟩
length xs ≤⟨ length-mono-≤ rs ⟩
length ys₁ ∎
open Antisymmetry public
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} (R? : Decidable R) where
sublist? : Decidable (Sublist R)
sublist? [] ys = yes (minimum ys)
sublist? (x ∷ xs) [] = no λ ()
sublist? (x ∷ xs) (y ∷ ys) with R? x y
... | true because [r] =
Dec.map (∷⁻¹ (invert [r])) (sublist? xs ys)
... | false because [¬r] =
Dec.map (∷ʳ⁻¹ (invert [¬r])) (sublist? (x ∷ xs) ys)
module _ {a e r} {A : Set a} {E : Rel A e} {R : Rel A r} where
isPreorder : IsPreorder E R → IsPreorder (Pointwise E) (Sublist R)
isPreorder ER-isPreorder = record
{ isEquivalence = Pw.isEquivalence ER.isEquivalence
; reflexive = fromPointwise ∘ Pw.map ER.reflexive
; trans = trans ER.trans
} where module ER = IsPreorder ER-isPreorder
isPartialOrder : IsPartialOrder E R → IsPartialOrder (Pointwise E) (Sublist R)
isPartialOrder ER-isPartialOrder = record
{ isPreorder = isPreorder ER.isPreorder
; antisym = antisym ER.antisym
} where module ER = IsPartialOrder ER-isPartialOrder
isDecPartialOrder : IsDecPartialOrder E R →
IsDecPartialOrder (Pointwise E) (Sublist R)
isDecPartialOrder ER-isDecPartialOrder = record
{ isPartialOrder = isPartialOrder ER.isPartialOrder
; _≟_ = Pw.decidable ER._≟_
; _≤?_ = sublist? ER._≤?_
} where module ER = IsDecPartialOrder ER-isDecPartialOrder
module _ {a e r} where
preorder : Preorder a e r → Preorder _ _ _
preorder ER-preorder = record
{ isPreorder = isPreorder ER.isPreorder
} where module ER = Preorder ER-preorder
poset : Poset a e r → Poset _ _ _
poset ER-poset = record
{ isPartialOrder = isPartialOrder ER.isPartialOrder
} where module ER = Poset ER-poset
decPoset : DecPoset a e r → DecPoset _ _ _
decPoset ER-poset = record
{ isDecPartialOrder = isDecPartialOrder ER.isDecPartialOrder
} where module ER = DecPoset ER-poset
------------------------------------------------------------------------
-- Properties of disjoint sublists
module Disjointness {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
private
infix 4 _⊆_
_⊆_ = Sublist R
-- Forgetting the union
DisjointUnion→Disjoint : ∀ {xs ys zs us} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} {τ : us ⊆ zs} →
DisjointUnion τ₁ τ₂ τ → Disjoint τ₁ τ₂
DisjointUnion→Disjoint [] = []
DisjointUnion→Disjoint (y ∷ₙ u) = y ∷ₙ DisjointUnion→Disjoint u
DisjointUnion→Disjoint (x≈y ∷ₗ u) = x≈y ∷ₗ DisjointUnion→Disjoint u
DisjointUnion→Disjoint (x≈y ∷ᵣ u) = x≈y ∷ᵣ DisjointUnion→Disjoint u
-- Reconstructing the union
Disjoint→DisjointUnion : ∀ {xs ys zs} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} →
Disjoint τ₁ τ₂ → ∃₂ λ us (τ : us ⊆ zs) → DisjointUnion τ₁ τ₂ τ
Disjoint→DisjointUnion [] = _ , _ , []
Disjoint→DisjointUnion (y ∷ₙ u) = _ , _ , y ∷ₙ proj₂ (proj₂ (Disjoint→DisjointUnion u))
Disjoint→DisjointUnion (x≈y ∷ₗ u) = _ , _ , x≈y ∷ₗ proj₂ (proj₂ (Disjoint→DisjointUnion u))
Disjoint→DisjointUnion (x≈y ∷ᵣ u) = _ , _ , x≈y ∷ᵣ proj₂ (proj₂ (Disjoint→DisjointUnion u))
-- Disjoint is decidable
⊆-disjoint? : ∀ {xs ys zs} (τ₁ : xs ⊆ zs) (τ₂ : ys ⊆ zs) → Dec (Disjoint τ₁ τ₂)
⊆-disjoint? [] [] = yes []
-- Present in both sublists: not disjoint.
⊆-disjoint? (x≈z ∷ τ₁) (y≈z ∷ τ₂) = no λ()
-- Present in either sublist: ok.
⊆-disjoint? (y ∷ʳ τ₁) (x≈y ∷ τ₂) =
Dec.map′ (x≈y ∷ᵣ_) (λ{ (_ ∷ᵣ d) → d }) (⊆-disjoint? τ₁ τ₂)
⊆-disjoint? (x≈y ∷ τ₁) (y ∷ʳ τ₂) =
Dec.map′ (x≈y ∷ₗ_) (λ{ (_ ∷ₗ d) → d }) (⊆-disjoint? τ₁ τ₂)
-- Present in neither sublist: ok.
⊆-disjoint? (y ∷ʳ τ₁) (.y ∷ʳ τ₂) =
Dec.map′ (y ∷ₙ_) (λ{ (_ ∷ₙ d) → d }) (⊆-disjoint? τ₁ τ₂)
-- Disjoint is proof-irrelevant
Disjoint-irrelevant : ∀{xs ys zs} → Irrelevant (Disjoint {R = R} {xs} {ys} {zs})
Disjoint-irrelevant [] [] = P.refl
Disjoint-irrelevant (y ∷ₙ d₁) (.y ∷ₙ d₂) = P.cong (y ∷ₙ_) (Disjoint-irrelevant d₁ d₂)
Disjoint-irrelevant (x≈y ∷ₗ d₁) (.x≈y ∷ₗ d₂) = P.cong (x≈y ∷ₗ_) (Disjoint-irrelevant d₁ d₂)
Disjoint-irrelevant (x≈y ∷ᵣ d₁) (.x≈y ∷ᵣ d₂) = P.cong (x≈y ∷ᵣ_) (Disjoint-irrelevant d₁ d₂)
-- Note: DisjointUnion is not proof-irrelevant unless the underlying relation R is.
-- The proof is not entirely trivial, thus, we leave it for future work:
--
-- DisjointUnion-irrelevant : Irrelevant R →
-- ∀{xs ys us zs} {τ : us ⊆ zs} →
-- Irrelevant (λ (τ₁ : xs ⊆ zs) (τ₂ : ys ⊆ zs) → DisjointUnion τ₁ τ₂ τ)
-- Irreflexivity
Disjoint-irrefl′ : ∀{xs ys} {τ : xs ⊆ ys} → Disjoint τ τ → Null xs
Disjoint-irrefl′ [] = []
Disjoint-irrefl′ (y ∷ₙ d) = Disjoint-irrefl′ d
Disjoint-irrefl : ∀{x xs ys} → Irreflexive {A = x ∷ xs ⊆ ys } _≡_ Disjoint
Disjoint-irrefl P.refl x with Disjoint-irrefl′ x
... | () ∷ _
-- Symmetry
DisjointUnion-sym : ∀ {xs ys xys} {zs} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} {τ : xys ⊆ zs} →
DisjointUnion τ₁ τ₂ τ → DisjointUnion τ₂ τ₁ τ
DisjointUnion-sym [] = []
DisjointUnion-sym (y ∷ₙ d) = y ∷ₙ DisjointUnion-sym d
DisjointUnion-sym (x≈y ∷ₗ d) = x≈y ∷ᵣ DisjointUnion-sym d
DisjointUnion-sym (x≈y ∷ᵣ d) = x≈y ∷ₗ DisjointUnion-sym d
Disjoint-sym : ∀ {xs ys} {zs} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} →
Disjoint τ₁ τ₂ → Disjoint τ₂ τ₁
Disjoint-sym [] = []
Disjoint-sym (y ∷ₙ d) = y ∷ₙ Disjoint-sym d
Disjoint-sym (x≈y ∷ₗ d) = x≈y ∷ᵣ Disjoint-sym d
Disjoint-sym (x≈y ∷ᵣ d) = x≈y ∷ₗ Disjoint-sym d
-- Empty sublist
DisjointUnion-[]ˡ : ∀{xs ys} {ε : [] ⊆ ys} {τ : xs ⊆ ys} → DisjointUnion ε τ τ
DisjointUnion-[]ˡ {ε = []} {τ = []} = []
DisjointUnion-[]ˡ {ε = y ∷ʳ ε} {τ = y ∷ʳ τ} = y ∷ₙ DisjointUnion-[]ˡ
DisjointUnion-[]ˡ {ε = y ∷ʳ ε} {τ = x≈y ∷ τ} = x≈y ∷ᵣ DisjointUnion-[]ˡ
DisjointUnion-[]ʳ : ∀{xs ys} {ε : [] ⊆ ys} {τ : xs ⊆ ys} → DisjointUnion τ ε τ
DisjointUnion-[]ʳ {ε = []} {τ = []} = []
DisjointUnion-[]ʳ {ε = y ∷ʳ ε} {τ = y ∷ʳ τ} = y ∷ₙ DisjointUnion-[]ʳ
DisjointUnion-[]ʳ {ε = y ∷ʳ ε} {τ = x≈y ∷ τ} = x≈y ∷ₗ DisjointUnion-[]ʳ
-- A sublist τ : x∷xs ⊆ ys can be split into two disjoint sublists
-- [x] ⊆ ys (canonical choice) and (∷ˡ⁻ τ) : xs ⊆ ys.
DisjointUnion-fromAny∘toAny-∷ˡ⁻ : ∀ {x xs ys} (τ : (x ∷ xs) ⊆ ys) → DisjointUnion (fromAny (toAny τ)) (∷ˡ⁻ τ) τ
DisjointUnion-fromAny∘toAny-∷ˡ⁻ (y ∷ʳ τ) = y ∷ₙ DisjointUnion-fromAny∘toAny-∷ˡ⁻ τ
DisjointUnion-fromAny∘toAny-∷ˡ⁻ (xRy ∷ τ) = xRy ∷ₗ DisjointUnion-[]ˡ
-- Disjoint union of three mutually disjoint lists.
--
-- τᵢⱼ denotes the disjoint union of τᵢ and τⱼ: DisjointUnion τᵢ τⱼ τᵢⱼ
record DisjointUnion³
{xs ys zs ts} (τ₁ : xs ⊆ ts) (τ₂ : ys ⊆ ts) (τ₃ : zs ⊆ ts)
{xys xzs yzs} (τ₁₂ : xys ⊆ ts) (τ₁₃ : xzs ⊆ ts) (τ₂₃ : yzs ⊆ ts) : Set (a ⊔ b ⊔ r) where
field
{union³} : List A
sub³ : union³ ⊆ ts
join₁ : DisjointUnion τ₁ τ₂₃ sub³
join₂ : DisjointUnion τ₂ τ₁₃ sub³
join₃ : DisjointUnion τ₃ τ₁₂ sub³
infixr 5 _∷ʳ-DisjointUnion³_ _∷₁-DisjointUnion³_ _∷₂-DisjointUnion³_ _∷₃-DisjointUnion³_
-- Weakening the target list ts of a disjoint union.
_∷ʳ-DisjointUnion³_ :
∀ {xs ys zs ts} {τ₁ : xs ⊆ ts} {τ₂ : ys ⊆ ts} {τ₃ : zs ⊆ ts} →
∀ {xys xzs yzs} {τ₁₂ : xys ⊆ ts} {τ₁₃ : xzs ⊆ ts} {τ₂₃ : yzs ⊆ ts} →
∀ y →
DisjointUnion³ τ₁ τ₂ τ₃ τ₁₂ τ₁₃ τ₂₃ →
DisjointUnion³ (y ∷ʳ τ₁) (y ∷ʳ τ₂) (y ∷ʳ τ₃) (y ∷ʳ τ₁₂) (y ∷ʳ τ₁₃) (y ∷ʳ τ₂₃)
y ∷ʳ-DisjointUnion³ record{ sub³ = σ ; join₁ = d₁ ; join₂ = d₂ ; join₃ = d₃ } = record
{ sub³ = y ∷ʳ σ
; join₁ = y ∷ₙ d₁
; join₂ = y ∷ₙ d₂
; join₃ = y ∷ₙ d₃
}
-- Adding an element to the first list.
_∷₁-DisjointUnion³_ :
∀ {xs ys zs ts} {τ₁ : xs ⊆ ts} {τ₂ : ys ⊆ ts} {τ₃ : zs ⊆ ts} →
∀ {xys xzs yzs} {τ₁₂ : xys ⊆ ts} {τ₁₃ : xzs ⊆ ts} {τ₂₃ : yzs ⊆ ts} →
∀ {x y} (xRy : R x y) →
DisjointUnion³ τ₁ τ₂ τ₃ τ₁₂ τ₁₃ τ₂₃ →
DisjointUnion³ (xRy ∷ τ₁) (y ∷ʳ τ₂) (y ∷ʳ τ₃) (xRy ∷ τ₁₂) (xRy ∷ τ₁₃) (y ∷ʳ τ₂₃)
xRy ∷₁-DisjointUnion³ record{ sub³ = σ ; join₁ = d₁ ; join₂ = d₂ ; join₃ = d₃ } = record
{ sub³ = xRy ∷ σ
; join₁ = xRy ∷ₗ d₁
; join₂ = xRy ∷ᵣ d₂
; join₃ = xRy ∷ᵣ d₃
}
-- Adding an element to the second list.
_∷₂-DisjointUnion³_ :
∀ {xs ys zs ts} {τ₁ : xs ⊆ ts} {τ₂ : ys ⊆ ts} {τ₃ : zs ⊆ ts} →
∀ {xys xzs yzs} {τ₁₂ : xys ⊆ ts} {τ₁₃ : xzs ⊆ ts} {τ₂₃ : yzs ⊆ ts} →
∀ {x y} (xRy : R x y) →
DisjointUnion³ τ₁ τ₂ τ₃ τ₁₂ τ₁₃ τ₂₃ →
DisjointUnion³ (y ∷ʳ τ₁) (xRy ∷ τ₂) (y ∷ʳ τ₃) (xRy ∷ τ₁₂) (y ∷ʳ τ₁₃) (xRy ∷ τ₂₃)
xRy ∷₂-DisjointUnion³ record{ sub³ = σ ; join₁ = d₁ ; join₂ = d₂ ; join₃ = d₃ } = record
{ sub³ = xRy ∷ σ
; join₁ = xRy ∷ᵣ d₁
; join₂ = xRy ∷ₗ d₂
; join₃ = xRy ∷ᵣ d₃
}
-- Adding an element to the third list.
_∷₃-DisjointUnion³_ :
∀ {xs ys zs ts} {τ₁ : xs ⊆ ts} {τ₂ : ys ⊆ ts} {τ₃ : zs ⊆ ts} →
∀ {xys xzs yzs} {τ₁₂ : xys ⊆ ts} {τ₁₃ : xzs ⊆ ts} {τ₂₃ : yzs ⊆ ts} →
∀ {x y} (xRy : R x y) →
DisjointUnion³ τ₁ τ₂ τ₃ τ₁₂ τ₁₃ τ₂₃ →
DisjointUnion³ (y ∷ʳ τ₁) (y ∷ʳ τ₂) (xRy ∷ τ₃) (y ∷ʳ τ₁₂) (xRy ∷ τ₁₃) (xRy ∷ τ₂₃)
xRy ∷₃-DisjointUnion³ record{ sub³ = σ ; join₁ = d₁ ; join₂ = d₂ ; join₃ = d₃ } = record
{ sub³ = xRy ∷ σ
; join₁ = xRy ∷ᵣ d₁
; join₂ = xRy ∷ᵣ d₂
; join₃ = xRy ∷ₗ d₃
}
-- Computing the disjoint union of three disjoint lists.
disjointUnion³ : ∀{xs ys zs ts} {τ₁ : xs ⊆ ts} {τ₂ : ys ⊆ ts} {τ₃ : zs ⊆ ts}
{xys xzs yzs} {τ₁₂ : xys ⊆ ts} {τ₁₃ : xzs ⊆ ts} {τ₂₃ : yzs ⊆ ts} →
DisjointUnion τ₁ τ₂ τ₁₂ →
DisjointUnion τ₁ τ₃ τ₁₃ →
DisjointUnion τ₂ τ₃ τ₂₃ →
DisjointUnion³ τ₁ τ₂ τ₃ τ₁₂ τ₁₃ τ₂₃
disjointUnion³ [] [] [] = record { sub³ = [] ; join₁ = [] ; join₂ = [] ; join₃ = [] }
disjointUnion³ (y ∷ₙ d₁₂) (.y ∷ₙ d₁₃) (.y ∷ₙ d₂₃) = y ∷ʳ-DisjointUnion³ disjointUnion³ d₁₂ d₁₃ d₂₃
disjointUnion³ (y ∷ₙ d₁₂) (xRy ∷ᵣ d₁₃) (.xRy ∷ᵣ d₂₃) = xRy ∷₃-DisjointUnion³ disjointUnion³ d₁₂ d₁₃ d₂₃
disjointUnion³ (xRy ∷ᵣ d₁₂) (y ∷ₙ d₁₃) (.xRy ∷ₗ d₂₃) = xRy ∷₂-DisjointUnion³ disjointUnion³ d₁₂ d₁₃ d₂₃
disjointUnion³ (xRy ∷ₗ d₁₂) (.xRy ∷ₗ d₁₃) (y ∷ₙ d₂₃) = xRy ∷₁-DisjointUnion³ disjointUnion³ d₁₂ d₁₃ d₂₃
disjointUnion³ (xRy ∷ᵣ d₁₂) (xRy′ ∷ᵣ d₁₃) ()
-- If a sublist τ is disjoint to two lists σ₁ and σ₂,
-- then also to their disjoint union σ.
disjoint⇒disjoint-to-union : ∀{xs ys zs yzs ts}
{τ : xs ⊆ ts} {σ₁ : ys ⊆ ts} {σ₂ : zs ⊆ ts} {σ : yzs ⊆ ts} →
Disjoint τ σ₁ → Disjoint τ σ₂ → DisjointUnion σ₁ σ₂ σ → Disjoint τ σ
disjoint⇒disjoint-to-union d₁ d₂ u = let
_ , _ , u₁ = Disjoint→DisjointUnion d₁
_ , _ , u₂ = Disjoint→DisjointUnion d₂
in DisjointUnion→Disjoint (DisjointUnion³.join₁ (disjointUnion³ u₁ u₂ u))
open Disjointness public
-- Monotonicity of disjointness.
module DisjointnessMonotonicity
{a b c r s t} {A : Set a} {B : Set b} {C : Set c}
{R : REL A B r} {S : REL B C s} {T : REL A C t}
(rs⇒t : Trans R S T) where
-- We can enlarge and convert the target list of a disjoint union.
weakenDisjointUnion : ∀ {xs ys xys zs ws}
{τ₁ : Sublist R xs zs}
{τ₂ : Sublist R ys zs}
{τ : Sublist R xys zs} (σ : Sublist S zs ws) →
DisjointUnion τ₁ τ₂ τ →
DisjointUnion (trans rs⇒t τ₁ σ) (trans rs⇒t τ₂ σ) (trans rs⇒t τ σ)
weakenDisjointUnion [] [] = []
weakenDisjointUnion (w ∷ʳ σ) d = w ∷ₙ weakenDisjointUnion σ d
weakenDisjointUnion (_ ∷ σ) (y ∷ₙ d) = _ ∷ₙ weakenDisjointUnion σ d
weakenDisjointUnion (zSw ∷ σ) (xRz ∷ₗ d) = rs⇒t xRz zSw ∷ₗ weakenDisjointUnion σ d
weakenDisjointUnion (zSw ∷ σ) (yRz ∷ᵣ d) = rs⇒t yRz zSw ∷ᵣ weakenDisjointUnion σ d
weakenDisjoint : ∀ {xs ys zs ws}
{τ₁ : Sublist R xs zs}
{τ₂ : Sublist R ys zs} (σ : Sublist S zs ws) →
Disjoint τ₁ τ₂ →
Disjoint (trans rs⇒t τ₁ σ) (trans rs⇒t τ₂ σ)
weakenDisjoint [] [] = []
weakenDisjoint (w ∷ʳ σ) d = w ∷ₙ weakenDisjoint σ d
weakenDisjoint (_ ∷ σ) (y ∷ₙ d) = _ ∷ₙ weakenDisjoint σ d
weakenDisjoint (zSw ∷ σ) (xRz ∷ₗ d) = rs⇒t xRz zSw ∷ₗ weakenDisjoint σ d
weakenDisjoint (zSw ∷ σ) (yRz ∷ᵣ d) = rs⇒t yRz zSw ∷ᵣ weakenDisjoint σ d
-- Lists remain disjoint when elements are removed.
shrinkDisjoint : ∀ {us vs xs ys zs}
(σ₁ : Sublist R us xs) {τ₁ : Sublist S xs zs}
(σ₂ : Sublist R vs ys) {τ₂ : Sublist S ys zs} →
Disjoint τ₁ τ₂ →
Disjoint (trans rs⇒t σ₁ τ₁) (trans rs⇒t σ₂ τ₂)
shrinkDisjoint σ₁ σ₂ (y ∷ₙ d) = y ∷ₙ shrinkDisjoint σ₁ σ₂ d
shrinkDisjoint (x ∷ʳ σ₁) σ₂ (xSz ∷ₗ d) = _ ∷ₙ shrinkDisjoint σ₁ σ₂ d
shrinkDisjoint (uRx ∷ σ₁) σ₂ (xSz ∷ₗ d) = rs⇒t uRx xSz ∷ₗ shrinkDisjoint σ₁ σ₂ d
shrinkDisjoint σ₁ (y ∷ʳ σ₂) (ySz ∷ᵣ d) = _ ∷ₙ shrinkDisjoint σ₁ σ₂ d
shrinkDisjoint σ₁ (vRy ∷ σ₂) (ySz ∷ᵣ d) = rs⇒t vRy ySz ∷ᵣ shrinkDisjoint σ₁ σ₂ d
shrinkDisjoint [] [] [] = []
open DisjointnessMonotonicity public
|
{
"alphanum_fraction": 0.5376075493,
"avg_line_length": 40.3697478992,
"ext": "agda",
"hexsha": "3e5957a6e4efc7edcc6757e0f22b3de264b77fed",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Heterogeneous/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Heterogeneous/Properties.agda",
"max_line_length": 113,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Heterogeneous/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 12095,
"size": 28824
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.JoinComm
open import homotopy.JoinAssocCubical
module homotopy.JoinSusp where
module _ {i} {A : Type i} where
private
module Into = PushoutRec {d = *-span (Lift {j = i} Bool) A}
{D = Suspension A}
(λ {(lift true) → north _;
(lift false) → south _})
(λ _ → south _)
(λ {(lift true , a) → merid _ a;
(lift false , a) → idp})
into = Into.f
module Out = SuspensionRec A {C = Lift {j = i} Bool * A}
(left (lift true))
(left (lift false))
(λ a → glue (lift true , a) ∙ ! (glue (lift false , a)))
out = Out.f
into-out : ∀ σ → into (out σ) == σ
into-out = Suspension-elim _
idp
idp
(↓-∘=idf-from-square into out ∘ λ a → vert-degen-square $
ap (ap into) (Out.glue-β a)
∙ ap-∙ into (glue (lift true , a)) (! (glue (lift false , a)))
∙ (Into.glue-β (lift true , a)
∙2 (ap-! into (glue (lift false , a))
∙ ap ! (Into.glue-β (lift false , a))))
∙ ∙-unit-r _)
out-into : ∀ j → out (into j) == j
out-into = Pushout-elim
(λ {(lift true) → idp;
(lift false) → idp})
(λ a → glue (lift false , a))
(↓-∘=idf-from-square out into ∘
λ {(lift true , a) →
(ap (ap out) (Into.glue-β (lift true , a)) ∙ Out.glue-β a)
∙v⊡ (vid-square {p = glue (lift true , a)}
⊡h rt-square (glue (lift false , a)))
⊡v∙ ∙-unit-r _;
(lift false , a) →
ap (ap out) (Into.glue-β (lift false , a)) ∙v⊡ connection})
join-S⁰-equiv : Lift {j = i} Bool * A ≃ Suspension A
join-S⁰-equiv = equiv into out into-out out-into
join-S⁰-path = ua join-S⁰-equiv
module _ {i} (X : Ptd i) where
join-S⁰-⊙path : ⊙Sphere {i} 0 ⊙* X == ⊙Susp X
join-S⁰-⊙path = ⊙ua join-S⁰-equiv idp
module _ {i} {A B : Type i} where
join-susp-shift : Suspension A * B == Suspension (A * B)
join-susp-shift =
ap (λ C → C * B) (! join-S⁰-path)
∙ join-rearrange-path
∙ ua swap-equiv
∙ join-S⁰-path
∙ ap Suspension (ua swap-equiv)
module _ {i} (X Y : Ptd i) where
⊙join-susp-shift : ⊙Susp X ⊙* Y == ⊙Susp (X ⊙* Y)
⊙join-susp-shift =
ap (λ Z → Z ⊙* Y) (! (join-S⁰-⊙path X))
∙ join-rearrange-⊙path (⊙Sphere 0) X Y
∙ ⊙ua swap-equiv (! (glue _))
∙ join-S⁰-⊙path (Y ⊙* X)
∙ ap (λ A → (Suspension A , north _)) (ua swap-equiv)
module _ {i} (X : Ptd i) where
⊙join-sphere : (m : ℕ) → ⊙Sphere {i} m ⊙* X == ⊙Susp^ (S m) X
⊙join-sphere O = join-S⁰-⊙path X
⊙join-sphere (S m) = ⊙join-susp-shift (⊙Sphere m) X
∙ ap ⊙Susp (⊙join-sphere m)
|
{
"alphanum_fraction": 0.4969544966,
"avg_line_length": 30.0107526882,
"ext": "agda",
"hexsha": "9e8c82c73f6f9a3a3ee882052389dcc4234e4d82",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "homotopy/JoinSusp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danbornside/HoTT-Agda",
"max_issues_repo_path": "homotopy/JoinSusp.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "homotopy/JoinSusp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1025,
"size": 2791
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Simple implementation of sets of ℕ.
--
-- Since ℕ is represented as unary numbers, simply having an ordered list of
-- numbers to represent a set is quite inefficient. For instance, to see if
-- 6 is in the set {1, 3, 4}, we have to do a comparison with 1, then 3, and
-- then 4. But 4 is equal to suc 3, so we should be able to share the work
-- accross those two comparisons.
--
-- This module defines a type that represents {1, 3, 4} as:
--
-- 1 ∷ 1 ∷ 0 ∷ []
--
-- i.e. we only store the gaps. When checking if a number (the needle) is in the
-- set (the haystack), we subtract each successive member of the haystack from the
-- needle as we go. For example, to check if 6 is in the above set, we do the
-- following:
--
-- start: 6 ∈? (1 ∷ 1 ∷ 0 ∷ [])
-- test head: 6 ≟ 1
-- not equal, so continue: (6 - 1 - 1) ∈? (1 ∷ 0 ∷ [])
-- compute: 4 ∈? (1 ∷ 0 ∷ [])
-- test head: 4 ≟ 1
-- not equal, so continue: (4 - 1 - 1) ∈? (0 ∷ [])
-- compute: 2 ∈? (0 ∷ [])
-- test head: 2 ≟ 0
-- not equal, so continue: (2 - 1 - 1) ∈? []
-- empty list: false
--
-- In this way, we change the membership test from O(n²) to O(n).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Tactic.RingSolver.Core.NatSet where
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.List as List using (List; _∷_; [])
open import Data.Maybe.Base as Maybe using (Maybe; just; nothing)
open import Data.Bool as Bool using (Bool)
open import Function
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Helper methods
para : ∀ {a b} {A : Set a} {B : Set b} →
(A → List A → B → B) → B → List A → B
para f b [] = b
para f b (x ∷ xs) = f x xs (para f b xs)
------------------------------------------------------------------------
-- Definition
NatSet : Set
NatSet = List ℕ
------------------------------------------------------------------------
-- Functions
insert : ℕ → NatSet → NatSet
insert x xs = para f (_∷ []) xs x
where
f : ℕ → NatSet → (ℕ → NatSet) → ℕ → NatSet
f y ys c x with ℕ.compare x y
... | ℕ.less x k = x ∷ k ∷ ys
... | ℕ.equal x = x ∷ ys
... | ℕ.greater y k = y ∷ c k
delete : ℕ → NatSet → NatSet
delete x xs = para f (const []) xs x
where
f : ℕ → NatSet → (ℕ → NatSet) → ℕ → NatSet
f y ys c x with ℕ.compare x y
f y ys c x | ℕ.less x k = y ∷ ys
f y [] c x | ℕ.equal x = []
f y₁ (y₂ ∷ ys) c x | ℕ.equal x = suc x ℕ.+ y₂ ∷ ys
f y ys c x | ℕ.greater y k = y ∷ c k
-- Returns the position of the element, if it's present.
lookup : ℕ → NatSet → Maybe ℕ
lookup x xs = List.foldr f (const (const nothing)) xs x 0
where
f : ℕ → (ℕ → ℕ → Maybe ℕ) → ℕ → ℕ → Maybe ℕ
f y ys x i with ℕ.compare x y
... | ℕ.less x k = nothing
... | ℕ.equal y = just i
... | ℕ.greater y k = ys k (suc i)
member : ℕ → NatSet → Bool
member x = Maybe.is-just ∘ lookup x
fromList : List ℕ → NatSet
fromList = List.foldr insert []
toList : NatSet → List ℕ
toList = List.drop 1 ∘ List.map ℕ.pred ∘ List.scanl (λ x y → suc (y ℕ.+ x)) 0
------------------------------------------------------------------------
-- Tests
private
example₁ : fromList (4 ∷ 3 ∷ 1 ∷ 0 ∷ 2 ∷ []) ≡ (0 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ [])
example₁ = refl
example₂ : lookup 3 (fromList (4 ∷ 3 ∷ 1 ∷ 0 ∷ 2 ∷ [])) ≡ just 3
example₂ = refl
example₃ : toList (fromList (4 ∷ 3 ∷ 1 ∷ 0 ∷ 2 ∷ [])) ≡ (0 ∷ 1 ∷ 2 ∷ 3 ∷ 4 ∷ [])
example₃ = refl
example₄ : delete 3 (fromList (4 ∷ 3 ∷ 1 ∷ 2 ∷ [])) ≡ fromList (4 ∷ 1 ∷ 2 ∷ [])
example₄ = refl
example₅ : delete 3 (fromList (4 ∷ 1 ∷ 2 ∷ [])) ≡ fromList (4 ∷ 1 ∷ 2 ∷ [])
example₅ = refl
|
{
"alphanum_fraction": 0.489635996,
"avg_line_length": 32.9666666667,
"ext": "agda",
"hexsha": "d23c5e3d46bd6d7b014e30209566d311d652fc0b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/NatSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/NatSet.agda",
"max_line_length": 82,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/NatSet.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1319,
"size": 3956
}
|
module Numeral.Natural.Relation.DivisibilityWithRemainder where
import Lvl
open import Logic
open import Logic.Propositional
open import Numeral.Finite
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Type
-- Divisibility with a remainder.
-- `(y ∣ x)(r)` means that `y` is divisible by `x − r`.
-- Note: `(0 ∣ᵣₑₘ _)(_)` is impossible to construct (0 is never a divisor by this definition).
data _∣ᵣₑₘ_ : (y : ℕ) → ℕ → 𝕟(y) → Stmt{Lvl.𝟎} where
DivRem𝟎 : ∀{y : ℕ} {r : 𝕟(y)} → (y ∣ᵣₑₘ 𝕟-to-ℕ(r))(r)
DivRem𝐒 : ∀{y x : ℕ}{r : 𝕟(y)} → (y ∣ᵣₑₘ x)(r) → (y ∣ᵣₑₘ (x + y))(r)
_∣₊_ : ℕ → ℕ → Stmt
𝟎 ∣₊ x = ⊥
𝐒(y) ∣₊ x = (𝐒(y) ∣ᵣₑₘ x)(𝟎)
-- The quotient extracted from the proof of divisibility.
[∣ᵣₑₘ]-quotient : ∀{y x}{r} → (y ∣ᵣₑₘ x)(r) → ℕ
[∣ᵣₑₘ]-quotient DivRem𝟎 = 𝟎
[∣ᵣₑₘ]-quotient (DivRem𝐒 p) = 𝐒([∣ᵣₑₘ]-quotient p)
-- The remainder extracted from the proof of divisibility.
[∣ᵣₑₘ]-remainder : ∀{y x}{r} → (y ∣ᵣₑₘ x)(r) → 𝕟(y)
[∣ᵣₑₘ]-remainder{r = r} _ = r
data _∣ᵣₑₘ₀_ : (y : ℕ) → ℕ → ℕ → Stmt{Lvl.𝟎} where
base₀ : ∀{y} → (y ∣ᵣₑₘ₀ 𝟎)(𝟎)
base₊ : ∀{y r} → (y ∣ᵣₑₘ₀ r)(r) → (𝐒(y) ∣ᵣₑₘ₀ 𝐒(r))(𝐒(r))
step : ∀{y x r} → (y ∣ᵣₑₘ₀ x)(r) → (y ∣ᵣₑₘ₀ (x + y))(r)
|
{
"alphanum_fraction": 0.5825726141,
"avg_line_length": 34.4285714286,
"ext": "agda",
"hexsha": "54b193be0f6f479eb4eacb1c1fc2321b19a674b1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Relation/DivisibilityWithRemainder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Relation/DivisibilityWithRemainder.agda",
"max_line_length": 94,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Relation/DivisibilityWithRemainder.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 675,
"size": 1205
}
|
open import Type
open import Logic.Classical as Logic using (Classical)
open import Logic.Predicate as Logic using ()
module Formalization.ClassicalPropositionalLogic.NaturalDeduction.Tree ⦃ classical : ∀{ℓ} → Logic.∀ₗ(Classical{ℓ}) ⦄ where
import Lvl
open import Logic
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_)
private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level
open import Formalization.ClassicalPropositionalLogic.Syntax
module _ {ℓₚ} {P : Type{ℓₚ}} where
{-# NO_POSITIVITY_CHECK #-}
data Tree : Formula(P) → Stmt{Lvl.𝐒(ℓₚ)} where
[⊤]-intro : Tree(⊤)
[⊥]-intro : ∀{φ} → Tree(φ) → Tree(¬ φ) → Tree(⊥)
[⊥]-elim : ∀{φ} → Tree(⊥) → Tree(φ)
[¬]-intro : ∀{φ} → (Tree(φ) → Tree(⊥)) → Tree(¬ φ)
[¬]-elim : ∀{φ} → (Tree(¬ φ) → Tree(⊥)) → Tree(φ)
[∧]-intro : ∀{φ ψ} → Tree(φ) → Tree(ψ) → Tree(φ ∧ ψ)
[∧]-elimₗ : ∀{φ ψ} → Tree(φ ∧ ψ) → Tree(φ)
[∧]-elimᵣ : ∀{φ ψ} → Tree(φ ∧ ψ) → Tree(ψ)
[∨]-introₗ : ∀{φ ψ} → Tree(φ) → Tree(φ ∨ ψ)
[∨]-introᵣ : ∀{φ ψ} → Tree(ψ) → Tree(φ ∨ ψ)
[∨]-elim : ∀{φ ψ χ} → (Tree(φ) → Tree(χ)) → (Tree(ψ) → Tree(χ)) → Tree(φ ∨ ψ) → Tree(χ)
[⟶]-intro : ∀{φ ψ} → (Tree(φ) → Tree(ψ)) → Tree(φ ⟶ ψ)
[⟶]-elim : ∀{φ ψ} → Tree(φ) → Tree(φ ⟶ ψ) → Tree(ψ)
[⟷]-intro : ∀{φ ψ} → (Tree(ψ) → Tree(φ)) → (Tree(φ) → Tree(ψ)) → Tree(ψ ⟷ φ)
[⟷]-elimₗ : ∀{φ ψ} → Tree(φ) → Tree(ψ ⟷ φ) → Tree(ψ)
[⟷]-elimᵣ : ∀{φ ψ} → Tree(ψ) → Tree(ψ ⟷ φ) → Tree(φ)
open import Formalization.ClassicalPropositionalLogic.NaturalDeduction
module _ {ℓ} where
Tree-to-[⊢]-tautologies : ∀{φ} → Tree(φ) → (∅{ℓ} ⊢ φ)
Tree-to-[⊢]-tautologies {.⊤} [⊤]-intro = [⊤]-intro
Tree-to-[⊢]-tautologies {.⊥} ([⊥]-intro tφ tφ₁) =
([⊥]-intro
(Tree-to-[⊢]-tautologies tφ)
(Tree-to-[⊢]-tautologies tφ₁)
)
Tree-to-[⊢]-tautologies {φ} ([⊥]-elim tφ) =
([⊥]-elim
(Tree-to-[⊢]-tautologies tφ)
)
Tree-to-[⊢]-tautologies {.(¬ _)} ([¬]-intro x) = [¬]-intro {!!}
Tree-to-[⊢]-tautologies {φ} ([¬]-elim x) = {!!}
Tree-to-[⊢]-tautologies {.(_ ∧ _)} ([∧]-intro tφ tφ₁) =
([∧]-intro
(Tree-to-[⊢]-tautologies tφ)
(Tree-to-[⊢]-tautologies tφ₁)
)
Tree-to-[⊢]-tautologies {φ} ([∧]-elimₗ tφ) =
([∧]-elimₗ
(Tree-to-[⊢]-tautologies tφ)
)
Tree-to-[⊢]-tautologies {φ} ([∧]-elimᵣ tφ) =
([∧]-elimᵣ
(Tree-to-[⊢]-tautologies tφ)
)
Tree-to-[⊢]-tautologies {.(_ ∨ _)} ([∨]-introₗ tφ) =
([∨]-introₗ
(Tree-to-[⊢]-tautologies tφ)
)
Tree-to-[⊢]-tautologies {.(_ ∨ _)} ([∨]-introᵣ tφ) =
([∨]-introᵣ
(Tree-to-[⊢]-tautologies tφ)
)
Tree-to-[⊢]-tautologies {φ} ([∨]-elim x x₁ tφ) = {!!}
Tree-to-[⊢]-tautologies {.(_ ⟶ _)} ([⟶]-intro x) = {!!}
Tree-to-[⊢]-tautologies {φ} ([⟶]-elim tφ tφ₁) =
([⟶]-elim
(Tree-to-[⊢]-tautologies tφ)
(Tree-to-[⊢]-tautologies tφ₁)
)
Tree-to-[⊢]-tautologies {.(_ ⟷ _)} ([⟷]-intro x x₁) = {!!}
Tree-to-[⊢]-tautologies {φ} ([⟷]-elimₗ tφ tφ₁) =
([⟷]-elimₗ
(Tree-to-[⊢]-tautologies tφ)
(Tree-to-[⊢]-tautologies tφ₁)
)
Tree-to-[⊢]-tautologies {φ} ([⟷]-elimᵣ tφ tφ₁) =
([⟷]-elimᵣ
(Tree-to-[⊢]-tautologies tφ)
(Tree-to-[⊢]-tautologies tφ₁)
)
--Tree-to-[⊢] : ∀{P : Type{ℓₚ}}{Γ : Formulas(P)}{φ} → ((Γ ⊆ Tree) → Tree(φ)) → (Γ ⊢ φ)
--Tree-to-[⊢] {Γ} {φ} t = {!!}
|
{
"alphanum_fraction": 0.486632537,
"avg_line_length": 35.5151515152,
"ext": "agda",
"hexsha": "d88395adda86886969c9b94de15eb7727120214c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Tree.agda",
"max_line_length": 159,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Formalization/ClassicalPropositionalLogic/NaturalDeduction/Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1673,
"size": 3516
}
|
record R (A : Set) : Set where
field
f : A → A
open module R′ (@0 A : Set) (r : R A) = R {A = A} r
|
{
"alphanum_fraction": 0.4716981132,
"avg_line_length": 17.6666666667,
"ext": "agda",
"hexsha": "e68a900232f01d445c9104cae6e74c56d9507371",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/Issue4786c.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/Issue4786c.agda",
"max_line_length": 51,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/Issue4786c.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 46,
"size": 106
}
|
module Impure.LFRef.Properties.Confluence where
open import Prelude
open import Data.List
open import Extensions.List
open import Extensions.Nat
open import Impure.LFRef.Syntax
open import Impure.LFRef.Eval
private
val-lemma : ∀ {t} → (v v₁ : Val t) → v ≡ v₁
val-lemma loc loc = refl
val-lemma unit unit = refl
val-lemma con con = refl
-- A stronger property than Church-Rosser
deterministic : ∀ {𝕊 e e' e'' μ μ' μ''} →
𝕊 ⊢ e , μ ≻ e' , μ' → 𝕊 ⊢ e , μ ≻ e'' , μ'' →
---------------------------------------------
e' ≡ e'' × μ' ≡ μ''
deterministic (funapp-β x p₁) (funapp-β x' p) with []=-functional _ _ x x'
deterministic (funapp-β x refl) (funapp-β x' refl) | refl = refl , refl
deterministic {μ = μ} (ref-val p) (ref-val q) = refl , cong (λ v → μ ∷ʳ (, v)) (val-lemma p q)
deterministic (ref-val v) (ref-clos ())
deterministic (≔-val p v) (≔-val q w) with <-unique p q | val-lemma v w
... | refl | refl = refl , refl
deterministic (≔-val p v) (≔-clos₁ ())
deterministic (≔-val p v) (≔-clos₂ _ ())
deterministic {μ = μ} (!-val p) (!-val q) = (cong (λ v → tm (!load μ v)) (<-unique p q)) , refl
deterministic (!-val p) (!-clos ())
deterministic (ref-clos ()) (ref-val v)
deterministic (ref-clos p) (ref-clos q) with deterministic p q
... | refl , refl = refl , refl
deterministic (!-clos ()) (!-val p)
deterministic (!-clos p) (!-clos q) with deterministic p q
... | refl , refl = refl , refl
deterministic (≔-clos₁ ()) (≔-val p v)
deterministic (≔-clos₁ p) (≔-clos₁ q) with deterministic p q
... | refl , refl = refl , refl
deterministic (≔-clos₁ ()) (≔-clos₂ (tm x) q)
deterministic (≔-clos₂ (tm x) p) (≔-clos₁ ())
deterministic (≔-clos₂ _ ()) (≔-val p v)
deterministic (≔-clos₂ _ p) (≔-clos₂ _ q) with deterministic p q
... | refl , refl = refl , refl
deterministic-seq : ∀ {𝕊 e e' e'' μ μ' μ''} →
𝕊 ⊢ e , μ ≻ₛ e' , μ' →
𝕊 ⊢ e , μ ≻ₛ e'' , μ'' →
---------------------------------------------
e' ≡ e'' × μ' ≡ μ''
deterministic-seq lett-β lett-β = refl , refl
deterministic-seq lett-β (lett-clos ())
deterministic-seq (lett-clos ()) lett-β
deterministic-seq (lett-clos p) (lett-clos q) with deterministic p q
... | refl , refl = refl , refl
deterministic-seq (ret-clos x) (ret-clos x') with deterministic x x'
... | refl , refl = refl , refl
open import Data.Star
confluence : ∀ {𝕊 e e' e'' μ μ' μ''} →
𝕊 ⊢ e , μ ≻⋆ e' , μ' → 𝕊 ⊢ e , μ ≻⋆ e'' , μ'' →
SeqExpVal e' → SeqExpVal e'' →
-----------------------------------------------
e' ≡ e'' × μ' ≡ μ''
confluence ε ε z y = refl , refl
confluence ε (ret-clos () ◅ _) (ret-tm _) _
confluence (ret-clos () ◅ _) ε _ (ret-tm _)
confluence (lett-β ◅ _) ε _ ()
confluence (lett-clos _ ◅ _) ε _ ()
confluence (x ◅ p) (x' ◅ p') v w with deterministic-seq x x'
... | refl , refl with confluence p p' v w
... | refl , refl = refl , refl
|
{
"alphanum_fraction": 0.5431764307,
"avg_line_length": 39.9054054054,
"ext": "agda",
"hexsha": "5f3742c1a6aecdc458f0dfc22785c5e7d0a6f740",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Impure/LFRef/Properties/Confluence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Impure/LFRef/Properties/Confluence.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Impure/LFRef/Properties/Confluence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1084,
"size": 2953
}
|
{- Basic theory about transport:
- transport is invertible
- transport is an equivalence ([transportEquiv])
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Transport where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.GroupoidLaws
-- Direct definition of transport filler, note that we have to
-- explicitly tell Agda that the type is constant (like in CHM)
transpFill : ∀ {ℓ} {A : Type ℓ}
(φ : I)
(A : (i : I) → Type ℓ [ φ ↦ (λ _ → A) ])
(u0 : outS (A i0))
→ --------------------------------------
PathP (λ i → outS (A i)) u0 (transp (λ i → outS (A i)) φ u0)
transpFill φ A u0 i = transp (λ j → outS (A (i ∧ j))) (~ i ∨ φ) u0
transport⁻ : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → B → A
transport⁻ p = transport (λ i → p (~ i))
subst⁻ : ∀ {ℓ ℓ'} {A : Type ℓ} {x y : A} (B : A → Type ℓ') (p : x ≡ y) → B y → B x
subst⁻ B p pa = transport⁻ (λ i → B (p i)) pa
transport-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B)
→ PathP (λ i → A → p i) (λ x → x) (transport p)
transport-fillerExt p i x = transport-filler p x i
transport⁻-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B)
→ PathP (λ i → p i → A) (λ x → x) (transport⁻ p)
transport⁻-fillerExt p i x = transp (λ j → p (i ∧ ~ j)) (~ i) x
transport-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B)
→ PathP (λ i → p i → B) (transport p) (λ x → x)
transport-fillerExt⁻ p = symP (transport⁻-fillerExt (sym p))
transport⁻-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B)
→ PathP (λ i → B → p i) (transport⁻ p) (λ x → x)
transport⁻-fillerExt⁻ p = symP (transport-fillerExt (sym p))
transport⁻-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : B)
→ PathP (λ i → p (~ i)) x (transport⁻ p x)
transport⁻-filler p x = transport-filler (λ i → p (~ i)) x
transport⁻Transport : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (a : A) →
transport⁻ p (transport p a) ≡ a
transport⁻Transport p a j = transport⁻-fillerExt p (~ j) (transport-fillerExt p (~ j) a)
transportTransport⁻ : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (b : B) →
transport p (transport⁻ p b) ≡ b
transportTransport⁻ p b j = transport-fillerExt⁻ p j (transport⁻-fillerExt⁻ p j b)
-- Transport is an equivalence
isEquivTransport : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → isEquiv (transport p)
isEquivTransport {A = A} {B = B} p =
transport (λ i → isEquiv (transport-fillerExt p i)) (idIsEquiv A)
transportEquiv : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B
transportEquiv p = (transport p , isEquivTransport p)
substEquiv : ∀ {ℓ ℓ'} {A B : Type ℓ} (P : Type ℓ → Type ℓ') (p : A ≡ B) → P A ≃ P B
substEquiv P p = (subst P p , isEquivTransport (λ i → P (p i)))
liftEquiv : ∀ {ℓ ℓ'} {A B : Type ℓ} (P : Type ℓ → Type ℓ') (e : A ≃ B) → P A ≃ P B
liftEquiv P e = substEquiv P (ua e)
transpEquiv : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → ∀ i → p i ≃ B
transpEquiv P i .fst = transp (λ j → P (i ∨ j)) i
transpEquiv P i .snd
= transp (λ k → isEquiv (transp (λ j → P (i ∨ (j ∧ k))) (i ∨ ~ k)))
i (idIsEquiv (P i))
uaTransportη : ∀ {ℓ} {A B : Type ℓ} (P : A ≡ B) → ua (transportEquiv P) ≡ P
uaTransportη P i j
= Glue (P i1) λ where
(j = i0) → P i0 , transportEquiv P
(i = i1) → P j , transpEquiv P j
(j = i1) → P i1 , idEquiv (P i1)
pathToIso : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → Iso A B
pathToIso x = iso (transport x) (transport⁻ x) (transportTransport⁻ x) (transport⁻Transport x)
isInjectiveTransport : ∀ {ℓ : Level} {A B : Type ℓ} {p q : A ≡ B}
→ transport p ≡ transport q → p ≡ q
isInjectiveTransport {p = p} {q} α i =
hcomp
(λ j → λ
{ (i = i0) → secEq univalence p j
; (i = i1) → secEq univalence q j
})
(invEq univalence ((λ a → α i a) , t i))
where
t : PathP (λ i → isEquiv (λ a → α i a)) (pathToEquiv p .snd) (pathToEquiv q .snd)
t = isProp→PathP (λ i → isPropIsEquiv (λ a → α i a)) _ _
transportUaInv : ∀ {ℓ} {A B : Type ℓ} (e : A ≃ B) → transport (ua (invEquiv e)) ≡ transport (sym (ua e))
transportUaInv e = cong transport (uaInvEquiv e)
-- notice that transport (ua e) would reduce, thus an alternative definition using EquivJ can give
-- refl for the case of idEquiv:
-- transportUaInv e = EquivJ (λ _ e → transport (ua (invEquiv e)) ≡ transport (sym (ua e))) refl e
isSet-subst : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′}
→ (isSet-A : isSet A)
→ ∀ {a : A}
→ (p : a ≡ a) → (x : B a) → subst B p x ≡ x
isSet-subst {B = B} isSet-A p x = subst (λ p′ → subst B p′ x ≡ x) (isSet-A _ _ refl p) (substRefl {B = B} x)
-- substituting along a composite path is equivalent to substituting twice
substComposite : ∀ {ℓ ℓ′} {A : Type ℓ} → (B : A → Type ℓ′)
→ {x y z : A} (p : x ≡ y) (q : y ≡ z) (u : B x)
→ subst B (p ∙ q) u ≡ subst B q (subst B p u)
substComposite B p q Bx i =
transport (cong B (compPath-filler' p q (~ i))) (transport-fillerExt (cong B p) i Bx)
-- substitution commutes with morphisms in slices
substCommSlice : ∀ {ℓ ℓ′} {A : Type ℓ}
→ (B C : A → Type ℓ′)
→ (F : ∀ i → B i → C i)
→ {x y : A} (p : x ≡ y) (u : B x)
→ subst C p (F x u) ≡ F y (subst B p u)
substCommSlice B C F p Bx i =
transport-fillerExt⁻ (cong C p) i (F _ (transport-fillerExt (cong B p) i Bx))
-- transports between loop spaces preserve path composition
overPathFunct : ∀ {ℓ} {A : Type ℓ} {x y : A} (p q : x ≡ x) (P : x ≡ y)
→ transport (λ i → P i ≡ P i) (p ∙ q)
≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q
overPathFunct p q =
J (λ y P → transport (λ i → P i ≡ P i) (p ∙ q) ≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q)
(transportRefl (p ∙ q) ∙ cong₂ _∙_ (sym (transportRefl p)) (sym (transportRefl q)))
|
{
"alphanum_fraction": 0.5398874545,
"avg_line_length": 43.1571428571,
"ext": "agda",
"hexsha": "a75a4567cada5177657be9e518c89eaad25febdb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/Foundations/Transport.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/Foundations/Transport.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/Foundations/Transport.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2352,
"size": 6042
}
|
module TestVec where
open import PreludeNatType
open import PreludeShow
infixr 40 _::_
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
head : {A : Set}{n : Nat} -> Vec A (suc n) -> A
head (x :: _) = x -- no need for a [] case
length : {A : Set}{n : Nat} -> Vec A n -> Nat
length {A} {n} v = n
three : Vec Nat 3
three = 1 :: 2 :: 3 :: []
mainS = showNat (length three)
|
{
"alphanum_fraction": 0.5442176871,
"avg_line_length": 22.05,
"ext": "agda",
"hexsha": "aa159c7cfd74a63487046b0f8303921d129eb729",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/Alonzo/TestVec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/Alonzo/TestVec.agda",
"max_line_length": 53,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/TestVec.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 164,
"size": 441
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_; Setω)
open import Boolean.Definition
open import Setoids.Setoids
open import Setoids.Subset
open import Setoids.Functions.Definition
open import LogicalFormulae
open import Functions.Definition
open import Lists.Lists
module LectureNotes.MetAndTop.Chapter1 where
PowerSet : {a : _} (A : Set a) → {b : _} → Set (a ⊔ lsuc b)
PowerSet A {b} = A → Set b
equality : {a b c : _} (A : Set a) → PowerSet A {b} → PowerSet A {c} → Set (a ⊔ b ⊔ c)
equality A x y = (z : A) → (x z → y z) && (y z → x z)
trans : {a b c d : _} {A : Set a} → {x : PowerSet A {b}} {y : PowerSet A {c}} {z : PowerSet A {d}} → equality A x y → equality A y z → equality A x z
trans {x} {y} {z} x=y y=z i with x=y i
... | r ,, s with y=z i
... | t ,, u = (λ z → t (r z)) ,, λ z → s (r (_&&_.snd (x=y i) (u z)))
symm : {a b c : _} {A : Set a} → {x : PowerSet A {b}} {y : PowerSet A {c}} → equality A x y → equality A y x
symm x=y i with x=y i
... | r ,, s = s ,, r
reflex : {a b : _} {A : Set a} → (x : PowerSet A {b}) → equality A x x
reflex x i = (λ z → z) ,, λ z → z
mapPower : {a b c : _} {A : Set a} {B : Set b} (f : A → B) → PowerSet B {c} → PowerSet A {c}
mapPower f p a = p (f a)
mapF : {a b c : _} {A : Set a} {B : Set b} (f : A → B) → PowerSet A {c} → PowerSet B {_}
mapF {A = A} f p b = Sg A (λ a → (p a) && (f a ≡ b))
singleton : {a b : _} {A : Set a} → (decidableEquality : (x y : A) → (x ≡ y) || ((x ≡ y) → False)) → A → PowerSet A {b}
singleton decidable a n with decidable a n
singleton decidable a n | inl x = True'
singleton decidable a n | inr x = False'
intersection : {a b c : _} {A : Set a} {B : Set b} (sets : A → PowerSet B {c}) → PowerSet B {a ⊔ c}
intersection {A = A} sets x = (a : A) → (sets a) x
union : {a b c : _} {A : Set a} {B : Set b} (sets : A → PowerSet B {c}) → PowerSet B {a ⊔ c}
union {A = A} sets x = Sg A λ i → sets i x
complement : {a b : _} {A : Set a} → (x : PowerSet A {b}) → PowerSet A
complement x t = x t → False
emptySet : {a b : _} (A : Set a) → PowerSet A {b}
emptySet A x = False'
decideIt : {a b : _} {A : Set a} → {f : A → Set b} → ((x : A) → (f x) || ((f x) → False)) → A → Set _
decideIt decide a with decide a
decideIt decide a | inl x = True
decideIt decide a | inr x = False
fromExtension : {a : _} {A : Set a} → ((x y : A) → (x ≡ y) || ((x ≡ y) → False)) → List A → PowerSet A
fromExtension decideEquality l = decideIt {f = contains l} (containsDecidable decideEquality l)
private
data !1234 : Set where
!1 : !1234
!2 : !1234
!3 : !1234
!4 : !1234
decidable1234 : (x y : !1234) → (x ≡ y) || ((x ≡ y) → False)
decidable1234 !1 !1 = inl refl
decidable1234 !1 !2 = inr (λ ())
decidable1234 !1 !3 = inr (λ ())
decidable1234 !1 !4 = inr (λ ())
decidable1234 !2 !1 = inr (λ ())
decidable1234 !2 !2 = inl refl
decidable1234 !2 !3 = inr (λ ())
decidable1234 !2 !4 = inr (λ ())
decidable1234 !3 !1 = inr (λ ())
decidable1234 !3 !2 = inr (λ ())
decidable1234 !3 !3 = inl refl
decidable1234 !3 !4 = inr (λ ())
decidable1234 !4 !1 = inr (λ ())
decidable1234 !4 !2 = inr (λ ())
decidable1234 !4 !3 = inr (λ ())
decidable1234 !4 !4 = inl refl
f : !1234 → !1234
f !1 = !1
f !2 = !1
f !3 = !4
f !4 = !3
exercise1'1i1 : {b : _} → equality {b = b} !1234 (mapPower f (singleton decidable1234 !1)) (fromExtension decidable1234 (!1 :: !2 :: []))
exercise1'1i1 !1 = (λ x → record {}) ,, (λ x → record {})
exercise1'1i1 !2 = (λ x → record {}) ,, (λ x → record {})
exercise1'1i1 !3 = (λ ()) ,, (λ ())
exercise1'1i1 !4 = (λ ()) ,, λ ()
exercise1'1i2 : {b : _} → equality {b = b} !1234 (mapPower f (singleton decidable1234 !2)) (λ _ → False)
exercise1'1i2 !1 = (λ ()) ,, λ ()
exercise1'1i2 !2 = (λ ()) ,, (λ ())
exercise1'1i2 !3 = (λ ()) ,, (λ ())
exercise1'1i2 !4 = (λ ()) ,, (λ ())
exercise1'1i3 : equality !1234 (mapPower f (fromExtension decidable1234 (!3 :: !4 :: []))) (fromExtension decidable1234 (!3 :: !4 :: []))
exercise1'1i3 !1 = (λ x → x) ,, (λ x → x)
exercise1'1i3 !2 = (λ x → x) ,, (λ x → x)
exercise1'1i3 !3 = (λ x → record {}) ,, (λ x → record {})
exercise1'1i3 !4 = (λ x → record {}) ,, (λ x → record {})
exercise1'1ii1 : {a b c t : _} {A : Set a} {B : Set b} {T : Set t} → (f : A → B) → (sets : T → PowerSet B {c}) → equality A (mapPower f (union sets)) (union λ x → mapPower f (sets x))
exercise1'1ii1 f sets i = (λ x → x) ,, (λ x → x)
exercise1'1ii2 : {a b c t : _} {A : Set a} {B : Set b} {T : Set t} → (f : A → B) → (sets : T → PowerSet B {c}) → equality A (mapPower f (intersection sets)) (intersection λ x → mapPower f (sets x))
exercise1'1ii2 f sets i = (λ x → x) ,, (λ x → x)
exercise1'1ii3 : {a b : _} {A : Set a} {B : Set b} → (f : A → B) → equality A (mapPower f (λ i → True)) (λ i → True)
exercise1'1ii3 f = λ z → (λ x → record {}) ,, (λ x → record {})
exercise1'1ii4 : {a b c : _} {A : Set a} {B : Set b} → (f : A → B) → equality A (mapPower f (emptySet {b = c} B)) (emptySet A)
exercise1'1ii4 f = λ z → (λ x → x) ,, (λ x → x)
exercise1'1ii5 : {a b c : _} {A : Set a} {B : Set b} → (f : A → B) → (u : PowerSet B {c}) → equality A (mapPower f (complement u)) (complement (mapPower f u))
exercise1'1ii5 f u z = (λ x → x) ,, (λ x → x)
exercise1'1iii1 : {a b c t : _} {A : Set a} {B : Set b} {T : Set t} → (f : A → B) (sets : T → PowerSet A {c}) → equality B (mapF f (union sets)) (union λ t → mapF f (sets t))
exercise1'1iii1 {A = A} {T = T} f sets z = x ,, y
where
x : mapF f (union sets) z → union (λ t → mapF f (sets t)) z
x (a , ((t , isIn) ,, snd)) = t , (a , (isIn ,, snd))
y : union (λ t → mapF f (sets t)) z → mapF f (union sets) z
y (t , (r , s)) = r , ((t , _&&_.fst s) ,, _&&_.snd s)
exercise1'1iii2 : {a b c d : _} {A : Set a} {B : Set b} → (f : A → B) → equality B (mapF f (emptySet {b = c} A)) (emptySet {b = d} B)
exercise1'1iii2 {A = A} {B = B} f z = x ,, λ ()
where
x : mapF f (emptySet A) z → emptySet B z
x (a , ())
ex4F : !1234 → !1234
ex4F !1 = !1
ex4F !2 = !2
ex4F !3 = !1
ex4F !4 = !4
v1 : PowerSet !1234
v1 !1 = True
v1 !2 = True
v1 !3 = False
v1 !4 = False
v2 : PowerSet !1234
v2 !1 = False
v2 !2 = True
v2 !3 = True
v2 !4 = False
v1AndV2 : Bool → !1234 → Set
v1AndV2 BoolTrue = v1
v1AndV2 BoolFalse = v2
lhs : equality {c = lzero} !1234 (mapF ex4F (intersection v1AndV2)) (singleton decidable1234 !2)
lhs !1 = ans ,, λ ()
where
ans : mapF ex4F (intersection v1AndV2) !1 → False'
ans (!1 , (fst ,, refl)) with fst BoolFalse
ans (!1 , (fst ,, refl)) | ()
ans (!3 , (fst ,, refl)) with fst BoolTrue
ans (!3 , (fst ,, refl)) | ()
lhs !2 = (λ _ → record {}) ,, ans
where
u : intersection v1AndV2 !2
u BoolTrue = record {}
u BoolFalse = record {}
ans : singleton decidable1234 !2 !2 → mapF ex4F (intersection v1AndV2) !2
ans _ = !2 , (u ,, refl)
lhs !3 = ans ,, λ ()
where
ans : mapF ex4F (intersection v1AndV2) !3 → False'
ans (!3 , (fst ,, ()))
lhs !4 = ans ,, λ ()
where
ans : mapF ex4F (intersection v1AndV2) !4 → False'
ans (!4 , (fst ,, refl)) with fst BoolTrue
ans (!4 , (fst ,, refl)) | ()
fv1AndV2 : Bool → !1234 → Set
fv1AndV2 BoolTrue = mapF ex4F v1
fv1AndV2 BoolFalse = mapF ex4F v2
rhs : equality {c = lzero} !1234 (intersection fv1AndV2) (fromExtension decidable1234 (!2 :: !1 :: []))
rhs !1 = (λ _ → record {}) ,, λ _ → a
where
a : intersection fv1AndV2 !1
a BoolTrue = !1 , (record {} ,, refl)
a BoolFalse = !3 , (record {} ,, refl)
rhs !2 = (λ _ → record {}) ,, λ _ → a
where
a : intersection fv1AndV2 !2
a BoolTrue = !2 , (record {} ,, refl)
a BoolFalse = !2 , (record {} ,, refl)
rhs !3 = a ,, λ ()
where
a : intersection fv1AndV2 !3 → fromExtension decidable1234 (!2 :: !1 :: []) !4
a pr with pr BoolTrue
a pr | !1 , (fst ,, ())
a pr | !2 , (fst ,, ())
a pr | !3 , (fst ,, snd) = fst
a pr | !4 , (fst ,, snd) = fst
rhs !4 = a ,, λ ()
where
a : intersection fv1AndV2 !4 → fromExtension decidable1234 (!2 :: !1 :: []) !4
a pr with pr BoolTrue
a pr | !1 , (x ,, ())
a pr | !2 , (x ,, ())
a pr | !3 , (x ,, ())
a pr | !4 , (x ,, _) = x
exercise1'1iv1 : (equality !1234 (mapF ex4F (intersection v1AndV2)) (intersection fv1AndV2)) → False
exercise1'1iv1 pr = ohno
where
bad : equality !1234 (fromExtension decidable1234 (!2 :: !1 :: [])) (singleton decidable1234 !2)
bad = trans (symm rhs) (trans (symm pr) lhs)
ohno : False
ohno with bad !1
ohno | fst ,, snd with fst record {}
... | ()
exercise1'1iv2 : (equality !1234 (mapF ex4F (λ _ → True)) (λ _ → True)) → False
exercise1'1iv2 pr with pr !3
exercise1'1iv2 pr | fst ,, snd with snd _
exercise1'1iv2 pr | fst ,, snd | !1 , ()
exercise1'1iv2 pr | fst ,, snd | !2 , ()
exercise1'1iv2 pr | fst ,, snd | !3 , ()
exercise1'1iv2 pr | fst ,, snd | !4 , ()
exercise1'1iv3 : equality !1234 (mapF ex4F (complement v1)) (complement v1) → False
exercise1'1iv3 pr with pr !1
exercise1'1iv3 pr | fst ,, snd with fst (!3 , ((λ i → i) ,, refl)) (record {})
... | ()
|
{
"alphanum_fraction": 0.5299410819,
"avg_line_length": 38.4156378601,
"ext": "agda",
"hexsha": "d89d12ce260511a46268b77d9d2068e05362e794",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "LectureNotes/MetAndTop/Chapter1.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "LectureNotes/MetAndTop/Chapter1.agda",
"max_line_length": 199,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "LectureNotes/MetAndTop/Chapter1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 3734,
"size": 9335
}
|
------------------------------------------------------------------------
-- Truncated queues: any two queues representing the same sequence are
-- equal, and things are set up so that at compile-time (but not at
-- run-time) some queue operations compute in roughly the same way as
-- the corresponding list operations
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Queue.Truncated
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Erased.Cubical eq hiding (map)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import List equality-with-J as L hiding (map)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
import Queue equality-with-J as Q
open import Sum equality-with-J
open import Surjection equality-with-J using (_↠_)
private
variable
a b : Level
A B : Type a
p q x : A
f : A → B
xs : List A
s s₁ s₂ : Very-stableᴱ-≡ A
------------------------------------------------------------------------
-- Queues
-- The queue type family is parametrised.
module _
-- The underlying queue type family.
(Q : ∀ {ℓ} → Type ℓ → Type ℓ)
-- Note that the predicate is required to be trivial. Perhaps the
-- code could be made more general, but I have not found a use for
-- such generality.
⦃ is-queue : ∀ {ℓ} → Q.Is-queue (λ A → Q A) (λ _ → ↑ _ ⊤) ℓ ⦄
where
abstract
-- Queues indexed by corresponding lists, and truncated so that
-- any two queues that stand for the same list are seen as equal.
--
-- The type is abstract to ensure that a change to a different
-- underlying queue type family does not break code that uses this
-- module.
--
-- Ulf Norell suggested to me that I could use parametrisation
-- instead of abstract. (Because if the underlying queue type
-- family is a parameter, then the underlying queues do not
-- compute.) I decided to use both. (Because I want to have the
-- flexibility that comes with parametrisation, but I do not want
-- to force users to work in a parametrised setting.)
Queue_⟪_⟫ : {A : Type a} → @0 List A → Type a
Queue_⟪_⟫ {A = A} xs =
∥ (∃ λ (q : Q A) → Erased (Q.to-List _ q ≡ xs)) ∥
-- Queues.
Queue : Type a → Type a
Queue A = ∃ λ (xs : Erased (List A)) → Queue_⟪_⟫ (erased xs)
-- The remainder of the code uses an implicit underlying queue type
-- family parameter, and an extra instance argument.
module _
{Q : ∀ {ℓ} → Type ℓ → Type ℓ}
⦃ is-queue : ∀ {ℓ} → Q.Is-queue (λ A → Q A) (λ _ → ↑ _ ⊤) ℓ ⦄
⦃ is-queue-with-map :
∀ {ℓ₁ ℓ₂} → Q.Is-queue-with-map (λ A → Q A) ℓ₁ ℓ₂ ⦄
where
abstract
-- Queue Q ⟪ xs ⟫ is a proposition.
Queue-⟪⟫-propositional :
{@0 xs : List A} →
Is-proposition (Queue Q ⟪ xs ⟫)
Queue-⟪⟫-propositional = truncation-is-proposition
-- Returns the (erased) index.
@0 ⌊_⌋ : Queue Q A → List A
⌊_⌋ = erased ∘ proj₁
-- There is a bijection between equality of two values of type
-- Queue Q A and erased equality of the corresponding list indices.
≡-for-indices↔≡ :
{xs ys : Queue Q A} →
Erased (⌊ xs ⌋ ≡ ⌊ ys ⌋) ↔ xs ≡ ys
≡-for-indices↔≡ {xs = xs} {ys = ys} =
Erased (⌊ xs ⌋ ≡ ⌊ ys ⌋) ↝⟨ Erased-≡↔[]≡[] ⟩
proj₁ xs ≡ proj₁ ys ↝⟨ ignore-propositional-component Queue-⟪⟫-propositional ⟩□
xs ≡ ys □
-- If a queue equality holds under the (non-dependent) assumption
-- that equality is very stable for the carrier type, then it also
-- holds without this assumption.
--
-- For an example of a lemma which has this kind of assumption, see
-- Queue.from-List≡foldl-enqueue-empty.
strengthen-queue-equality :
{q₁ q₂ : Queue Q A} → (Very-stable-≡ A → q₁ ≡ q₂) → q₁ ≡ q₂
strengthen-queue-equality {q₁ = q₁} {q₂ = q₂} eq =
_↔_.to ≡-for-indices↔≡
[ ⌊ q₁ ⌋ ≡⟨ cong ⌊_⌋ (eq (Very-stable→Very-stable-≡ 0 (erased Erased-Very-stable))) ⟩∎
⌊ q₂ ⌋ ∎
]
------------------------------------------------------------------------
-- Conversion functions
mutual
abstract
-- The right-to-left direction of Queue-⟪⟫↔Σ-List (defined
-- below). Note that there is no assumption of stability.
Σ-List→Queue-⟪⟫ :
{@0 ys : List A} →
(∃ λ xs → Erased (xs ≡ ys)) → Queue Q ⟪ ys ⟫
Σ-List→Queue-⟪⟫ = _ -- Agda can infer the definition.
-- If ys : List A and equality is very stable (with erased proofs)
-- for A, then Queue Q ⟪ ys ⟫ is isomorphic to the type of lists
-- equal (with erased equality proofs) to ys.
--
-- Note that equality is very stable for A if A has decidable
-- equality.
Queue-⟪⟫↔Σ-List :
{@0 ys : List A} →
Very-stableᴱ-≡ A →
Queue Q ⟪ ys ⟫ ↔ ∃ λ xs → Erased (xs ≡ ys)
Queue-⟪⟫↔Σ-List {ys = ys} s = Bijection.with-other-inverse
Queue-⟪⟫↔Σ-List′
Σ-List→Queue-⟪⟫
(λ _ → from-Queue-⟪⟫↔Σ-List′)
where
abstract
Queue-⟪⟫↔Σ-List′ : Queue Q ⟪ ys ⟫ ↔ ∃ λ xs → Erased (xs ≡ ys)
Queue-⟪⟫↔Σ-List′ = ↠→↔Erased-singleton
(Q.Queue↠List _)
(Very-stableᴱ-≡-List 0 s)
from-Queue-⟪⟫↔Σ-List′ :
_≡_ {A = Queue Q ⟪ ys ⟫}
(_↔_.from Queue-⟪⟫↔Σ-List′ p)
(Σ-List→Queue-⟪⟫ p)
from-Queue-⟪⟫↔Σ-List′ = refl _
-- If equality is very stable (with erased proofs) for A, then
-- Queue Q A is isomorphic to List A.
Queue↔List : Very-stableᴱ-≡ A → Queue Q A ↔ List A
Queue↔List {A = A} s =
Queue Q A ↔⟨⟩
(∃ λ (xs : Erased (List A)) → Queue Q ⟪ erased xs ⟫) ↝⟨ (∃-cong λ _ → Queue-⟪⟫↔Σ-List s) ⟩
(∃ λ (xs : Erased (List A)) → ∃ λ ys → Erased (ys ≡ erased xs)) ↝⟨ Σ-Erased-Erased-singleton↔ ⟩□
List A □
mutual
-- The right-to-left direction of Queue↔List. (Note that equality
-- is not required to be very stable with erased proofs for the
-- carrier type.)
from-List : List A → Queue Q A
from-List = _ -- Agda can infer the definition.
_ : _↔_.from (Queue↔List s) ≡ from-List
_ = refl _
-- The forward direction of Queue↔List s.
to-List : Very-stableᴱ-≡ A → Queue Q A → List A
to-List s = _↔_.to (Queue↔List s)
abstract
-- The function to-List returns the index.
@0 ≡⌊⌋ : to-List s q ≡ ⌊ q ⌋
≡⌊⌋ {s = s} {q = q} =
to-Σ-Erased-∥-Σ-Erased-≡-∥↔≡
(Q.Queue↠List _) (Very-stableᴱ-≡-List 0 s) q
-- Queue Q A is isomorphic to List A in an erased context. The
-- forward direction of this isomorphism returns the index directly.
@0 Queue↔Listⁱ : Queue Q A ↔ List A
Queue↔Listⁱ {A = A} =
Queue Q A ↔⟨⟩
(∃ λ (xs : Erased (List A)) → Queue Q ⟪ erased xs ⟫) ↝⟨ drop-⊤-right (λ _ → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible Queue-⟪⟫-propositional $
_↔_.from (Queue-⟪⟫↔Σ-List (Very-stable→Very-stableᴱ 1 $
Very-stable→Very-stable-≡ 0 $
erased Erased-Very-stable))
(_ , [ refl _ ])) ⟩
Erased (List A) ↝⟨ Very-stable→Stable 0 $ erased Erased-Very-stable ⟩□
List A □
private
@0 to-Queue↔Listⁱ-, : _↔_.to Queue↔Listⁱ q ≡ ⌊ q ⌋
to-Queue↔Listⁱ-, = refl _
-- The forward directions of Queue↔List and Queue↔Listⁱ match.
@0 to-Queue↔List : _↔_.to (Queue↔List s) q ≡ _↔_.to Queue↔Listⁱ q
to-Queue↔List = ≡⌊⌋
-- Variants of Queue↔List and Queue↔Listⁱ.
Maybe[×Queue]↔List :
Very-stableᴱ-≡ A →
Maybe (A × Queue Q A) ↔ List A
Maybe[×Queue]↔List {A = A} s =
Maybe (A × Queue Q A) ↝⟨ F.id ⊎-cong F.id ×-cong Queue↔List s ⟩
Maybe (A × List A) ↝⟨ inverse List↔Maybe[×List] ⟩□
List A □
@0 Maybe[×Queue]↔Listⁱ :
Maybe (A × Queue Q A) ↔ List A
Maybe[×Queue]↔Listⁱ {A = A} =
Maybe (A × Queue Q A) ↝⟨ F.id ⊎-cong F.id ×-cong Queue↔Listⁱ ⟩
Maybe (A × List A) ↝⟨ inverse List↔Maybe[×List] ⟩□
List A □
@0 to-Maybe[×Queue]↔List :
∀ xs →
_↔_.to (Maybe[×Queue]↔List s) xs ≡
_↔_.to Maybe[×Queue]↔Listⁱ xs
to-Maybe[×Queue]↔List {s = s} xs =
_↔_.from List↔Maybe[×List]
(⊎-map id (Σ-map id (_↔_.to (Queue↔List s))) xs) ≡⟨ cong (λ f → _↔_.from List↔Maybe[×List] (⊎-map id (Σ-map id f) xs)) (⟨ext⟩ λ _ →
to-Queue↔List) ⟩∎
_↔_.from List↔Maybe[×List]
(⊎-map id (Σ-map id (_↔_.to Queue↔Listⁱ)) xs) ∎
-- A lemma that can be used to prove "to-List lemmas".
⌊⌋≡→to-List≡ :
Erased (⌊ q ⌋ ≡ xs) →
to-List s q ≡ xs
⌊⌋≡→to-List≡ {q = q} {xs = xs} {s = s} eq =
to-List s q ≡⟨ cong (to-List _) (_↔_.to ≡-for-indices↔≡ eq) ⟩
to-List s (from-List xs) ≡⟨ _↔_.right-inverse-of (Queue↔List _) _ ⟩∎
xs ∎
------------------------------------------------------------------------
-- Some queue operations, implemented for Queue ⟪_⟫
module Indexed where
abstract
private
-- A helper function that can be used to define unary
-- functions on queues.
unary :
{A : Type a} {B : Type b}
{@0 xs : List A} {@0 f : List A → List B}
(g : Q A → Q B) →
@0 (∀ {q} → Q.to-List _ (g q) ≡ f (Q.to-List _ q)) →
Queue Q ⟪ xs ⟫ → Queue Q ⟪ f xs ⟫
unary {xs = xs} {f = f} g hyp = Trunc.rec
truncation-is-proposition
(uncurry λ q p →
∣ g q
, [ Q.to-List _ (g q) ≡⟨ hyp ⟩
f (Q.to-List _ q) ≡⟨ cong f (erased p) ⟩∎
f xs ∎
]
∣)
-- Enqueues an element.
enqueue :
{@0 xs : List A}
(x : A) → Queue Q ⟪ xs ⟫ → Queue Q ⟪ xs ++ x ∷ [] ⟫
enqueue x = unary (Q.enqueue x) Q.to-List-enqueue
-- A map function.
map :
{@0 xs : List A} →
(f : A → B) → Queue Q ⟪ xs ⟫ → Queue Q ⟪ L.map f xs ⟫
map f = unary (Q.map f) Q.to-List-map
-- The result of trying to dequeue an element from an indexed
-- queue.
--
-- TODO: Perhaps it makes sense to make Q an explicit argument of
-- this definition.
Result-⟪_⟫ : {A : Type a} → @0 List A → Type a
Result-⟪_⟫ {A = A} xs =
∃ λ (q : Maybe (A × Queue Q A)) →
Erased (_↔_.to Maybe[×Queue]↔Listⁱ q ≡ xs)
-- If equality is very stable (with erased proofs) for A, then
-- Result-⟪ xs ⟫ is a proposition for lists xs of type List A.
Result-⟪⟫-propositional :
{@0 xs : List A} →
Very-stableᴱ-≡ A →
Is-proposition Result-⟪ xs ⟫
Result-⟪⟫-propositional {A = A} {xs = xs} s =
$⟨ erased-singleton-with-erased-center-propositional (Very-stableᴱ-≡-List 0 s) ⟩
Is-proposition (Erased-singleton xs) ↝⟨ H-level-cong _ 1 (inverse lemma) ⦂ (_ → _) ⟩□
Is-proposition Result-⟪ xs ⟫ □
where
lemma : _ ↔ _
lemma =
Result-⟪ xs ⟫ ↔⟨⟩
(∃ λ (ys : Maybe (A × Queue Q A)) →
Erased (_↔_.to Maybe[×Queue]↔Listⁱ ys ≡ xs)) ↝⟨ ∃-cong (λ ys → Erased-cong (≡⇒↝ _ $ cong (_≡ xs) $ sym $
to-Maybe[×Queue]↔List ys)) ⟩
(∃ λ (ys : Maybe (A × Queue Q A)) →
Erased (_↔_.to (Maybe[×Queue]↔List s) ys ≡ xs)) ↝⟨ Σ-cong (Maybe[×Queue]↔List s) (λ _ → F.id) ⟩
(∃ λ (ys : List A) → Erased (ys ≡ xs)) ↔⟨⟩
Erased-singleton xs □
abstract
-- Dequeuing.
dequeue :
{@0 xs : List A} →
Very-stableᴱ-≡ A →
Queue Q ⟪ xs ⟫ →
Result-⟪ xs ⟫
dequeue {xs = xs} s = Trunc.rec
(Result-⟪⟫-propositional s)
(λ (q , [ eq ]) →
⊎-map id (Σ-map id λ q → _ , ∣ q , [ refl _ ] ∣)
(Q.dequeue _ q)
, [ _↔_.to Maybe[×Queue]↔Listⁱ
(⊎-map id (Σ-map id (λ q → _ , ∣ q , [ refl _ ] ∣))
(Q.dequeue _ q)) ≡⟨⟩
_↔_.from List↔Maybe[×List]
(⊎-map id (Σ-map id (_↔_.to Queue↔Listⁱ))
(⊎-map id (Σ-map id (λ q → _ , ∣ q , [ refl _ ] ∣))
(Q.dequeue _ q))) ≡⟨ cong (_↔_.from List↔Maybe[×List]) $ sym $ ⊎-map-∘ (Q.dequeue _ q) ⟩
_↔_.from List↔Maybe[×List]
(⊎-map id (Σ-map id (Q.to-List _)) (Q.dequeue _ q)) ≡⟨ cong (_↔_.from List↔Maybe[×List]) $ Q.to-List-dequeue {q = q} ⟩
_↔_.from List↔Maybe[×List]
(_↔_.to List↔Maybe[×List] (Q.to-List _ q)) ≡⟨ _↔_.left-inverse-of List↔Maybe[×List] _ ⟩
Q.to-List _ q ≡⟨ eq ⟩∎
xs ∎
])
-- The inverse of the dequeue operation. This operation does not
-- depend on stability.
dequeue⁻¹ :
{@0 xs : List A} →
Result-⟪ xs ⟫ → Queue Q ⟪ xs ⟫
dequeue⁻¹ {xs = xs} (nothing , eq) =
∣ Q.empty
, [ Q.to-List _ (Q.empty ⦂ Q _) ≡⟨ Q.to-List-empty ⟩
[] ≡⟨ erased eq ⟩∎
xs ∎
]
∣
dequeue⁻¹ {xs = xs} (just (x , ys , q) , eq) =
∥∥-map (Σ-map (Q.cons x)
(λ {q′} → Erased-cong λ eq′ →
Q.to-List _ (Q.cons x q′) ≡⟨ Q.to-List-cons ⟩
x ∷ Q.to-List _ q′ ≡⟨ cong (x ∷_) eq′ ⟩
x ∷ erased ys ≡⟨ erased eq ⟩∎
xs ∎))
q
-- The dequeue and dequeue⁻¹ operations are inverses.
Queue-⟪⟫↔Result-⟪⟫ :
{@0 xs : List A} →
Very-stableᴱ-≡ A →
Queue Q ⟪ xs ⟫ ↔ Result-⟪ xs ⟫
Queue-⟪⟫↔Result-⟪⟫ s = record
{ surjection = record
{ logical-equivalence = record
{ to = dequeue s
; from = dequeue⁻¹
}
; right-inverse-of = λ _ → Result-⟪⟫-propositional s _ _
}
; left-inverse-of = λ _ → Queue-⟪⟫-propositional _ _
}
------------------------------------------------------------------------
-- Some queue operations, implemented for Queue
-- Note that none of these operations are abstract.
module Non-indexed where
-- Enqueues an element.
enqueue : A → Queue Q A → Queue Q A
enqueue x = Σ-map _ (Indexed.enqueue x)
to-List-enqueue : to-List s (enqueue x q) ≡ to-List s q ++ x ∷ []
to-List-enqueue {s = s} {x = x} {q = q} = ⌊⌋≡→to-List≡
[ ⌊ q ⌋ ++ x ∷ [] ≡⟨ cong (_++ _) $ sym ≡⌊⌋ ⟩∎
to-List s q ++ x ∷ [] ∎
]
-- A map function.
map : (A → B) → Queue Q A → Queue Q B
map f = Σ-map _ (Indexed.map f)
to-List-map : to-List s₁ (map f q) ≡ L.map f (to-List s₂ q)
to-List-map {f = f} {q = q} {s₂ = s₂} = ⌊⌋≡→to-List≡
[ L.map f ⌊ q ⌋ ≡⟨ cong (L.map f) $ sym ≡⌊⌋ ⟩∎
L.map f (to-List s₂ q) ∎
]
private
-- A variant of the result of the dequeue operation.
Result : Type a → Type a
Result A =
∃ λ (xs : Erased (List A)) → Indexed.Result-⟪ erased xs ⟫
-- Conversion lemmas for Result.
Result↠Maybe[×Queue] : Result A ↠ Maybe (A × Queue Q A)
Result↠Maybe[×Queue] = record
{ logical-equivalence = record
{ to = proj₁ ∘ proj₂
; from = λ q → _ , q , [ refl _ ]
}
; right-inverse-of = refl
}
Result↔Maybe[×Queue] :
Very-stableᴱ-≡ A →
Result A ↔ Maybe (A × Queue Q A)
Result↔Maybe[×Queue] s = record
{ surjection = Result↠Maybe[×Queue]
; left-inverse-of = λ r → $⟨ from∘to r ⟩
Erased (⌊ from (to r) ⌋ʳ ≡ ⌊ r ⌋ʳ) ↝⟨ Erased-≡↔[]≡[] ⟩
proj₁ (from (to r)) ≡ proj₁ r ↝⟨ ignore-propositional-component (Indexed.Result-⟪⟫-propositional s) ⟩□
from (to r) ≡ r □
}
where
open _↠_ Result↠Maybe[×Queue]
@0 ⌊_⌋ʳ : Result A → List A
⌊_⌋ʳ = erased ∘ proj₁
from∘to : ∀ r → Erased (⌊ from (to r) ⌋ʳ ≡ ⌊ r ⌋ʳ)
from∘to (_ , _ , eq) = eq
-- Queue Q A is isomorphic to Maybe (A × Queue Q A), assuming that
-- equality is very stable (with erased proofs) for A.
Queue↔Maybe[×Queue] :
Very-stableᴱ-≡ A →
Queue Q A ↔ Maybe (A × Queue Q A)
Queue↔Maybe[×Queue] {A = A} s =
Queue Q A ↝⟨ ∃-cong (λ _ → Indexed.Queue-⟪⟫↔Result-⟪⟫ s) ⟩
Result A ↝⟨ Result↔Maybe[×Queue] s ⟩□
Maybe (A × Queue Q A) □
mutual
-- The inverse of the dequeue operation. This operation does not
-- depend on stability.
dequeue⁻¹ : Maybe (A × Queue Q A) → Queue Q A
dequeue⁻¹ q = _ -- Agda can infer the definition.
_ : _↔_.from (Queue↔Maybe[×Queue] s) ≡ dequeue⁻¹
_ = refl _
to-List-dequeue⁻¹ :
to-List s (dequeue⁻¹ x) ≡
_↔_.from List↔Maybe[×List] (⊎-map id (Σ-map id (to-List s)) x)
to-List-dequeue⁻¹ {x = nothing} = ⌊⌋≡→to-List≡ [ refl _ ]
to-List-dequeue⁻¹ {s = s} {x = just (x , q)} = ⌊⌋≡→to-List≡
[ x ∷ ⌊ q ⌋ ≡⟨ cong (_ ∷_) $ sym ≡⌊⌋ ⟩∎
x ∷ to-List s q ∎
]
-- Dequeues an element, if possible.
dequeue : Very-stableᴱ-≡ A → Queue Q A → Maybe (A × Queue Q A)
dequeue s = _↔_.to (Queue↔Maybe[×Queue] s)
to-List-dequeue :
⊎-map id (Σ-map id (to-List s)) (dequeue s q) ≡
_↔_.to List↔Maybe[×List] (to-List s q)
to-List-dequeue {s = s} {q = q} =
⊎-map id (Σ-map id (to-List s)) (dequeue s q) ≡⟨ _↔_.to (from≡↔≡to (from-isomorphism List↔Maybe[×List])) $
sym to-List-dequeue⁻¹ ⟩
_↔_.to List↔Maybe[×List] (to-List s (dequeue⁻¹ (dequeue s q))) ≡⟨ cong (_↔_.to List↔Maybe[×List] ∘ to-List s) $
_↔_.left-inverse-of (Queue↔Maybe[×Queue] _) _ ⟩∎
_↔_.to List↔Maybe[×List] (to-List s q) ∎
|
{
"alphanum_fraction": 0.4804443054,
"avg_line_length": 35.4454713494,
"ext": "agda",
"hexsha": "1637032c5f3a63e2c48fe79a49efaa5dc7398561",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Queue/Truncated.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Queue/Truncated.agda",
"max_line_length": 143,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Queue/Truncated.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 6700,
"size": 19176
}
|
{-# OPTIONS --without-K #-}
{- INDEX: Some constructions with non-recursive HITs,
and related results.
This formalization covers the hardest results of my
paper titled "Constructions with non-recursive HITs".
To be precise: I have formalized the result that all
functions in the sequence of approximations (see Section 6)
are weakly constant, and that the colimit is thus
propositional. This requires a lot of lemmas. Some of
these lemmas are trivial on paper and only tedious in Agda,
but many lemmas are (at least for me) even on paper far
from trivial.
Formalized are Section 2, Section 3 (without the example
applications), especially the first main result; all of
Section 4 except Lemma 4.9, the definitions and principles
of Section 5, all of Section 6 expect the last corollaries.
The parts of the paper that are not formalized are
(A) the examples in Section 3
(B) the statements of remarks
(C) Lemma 4.9, 5.4, 5.5, and 5.6
(D) Theorem 5.7, Corollary 5.8, Theorem 6.2
(E) the discussions and results in the concluding Section 7
All of these are relatively easy compared with the results
that are formalized. The items in (C) could be implemented
easily, but are not very interesting on their own.
The same is true for the second and third item in (D),
which however depend on Theorem 5.7.
Theorem 5.7 itself could be interesting to formalize.
However, it relies on the main result of
Capriotti, Kraus, Vezzosi,
"Functions out of Higher Truncations".
This result is formalized, but unfortunately in another
library; thus, we omit Theorem 5.7 (for now) in the current
formalization. (E) would require (D) first.
This development type-checks with Agda 2.4.2.5 and similar
versions (I assume with 2.4.2.x in general; same as the
HoTT library).
-}
module nicolai.pseudotruncations.NONRECURSIVE-INDEX where
{- Some preliminary definitions/lemmas, and an explanation
why we need to work with the spheres defined by suspension-
iteration of the form
Σ¹⁺ⁿ :≡ Σⁿ ∘ Σ -}
open import nicolai.pseudotruncations.Preliminary-definitions
open import nicolai.pseudotruncations.Liblemmas
{- SECTION 2
The Sequential colimit. I am aware that there is some
overlap with lib/types/NatColim.agda -}
open import nicolai.pseudotruncations.SeqColim
{- Here is some prepartion for Section 3 -}
open import nicolai.pseudotruncations.wconst-preparation
{- The rather lengthy argument that some heptagon commutes;
very tedious; this is still preparation for Section 3 -}
open import nicolai.pseudotruncations.heptagon
{- SECTION 3 (without the sample applications)
One result of the paper: If we have a sequence of weakly
constant functions, then the colimit is propositional -}
open import nicolai.pseudotruncations.wconstSequence
{- SECTION 4
The correspondance between loops and maps from spheres:
a lot of tedious technical content. This was hard work for me!
The results are in two files; first, essentially the fact that
the 'pointed' 0-sphere [i.e. (bool, true)] is "as good as"
the unit type if we consider pointed maps out of it.
Second, the main lemmas. -}
open import nicolai.pseudotruncations.pointed-O-Sphere
open import nicolai.pseudotruncations.LoopsAndSpheres
{- SECTION 5 (mainly the definition and some auxiliary lemmas)
Definition of pseudo-truncations -}
open import nicolai.pseudotruncations.PseudoTruncs
{- SECTION 6
The sequence of approximations with increasing "connectedness-
level", and the proof that every map is weakly constant,
and the corollary that its colimit is propositional. -}
open import nicolai.pseudotruncations.PseudoTruncs-wconst-seq
|
{
"alphanum_fraction": 0.750798722,
"avg_line_length": 41.2747252747,
"ext": "agda",
"hexsha": "dcb57803e14ef537fa3506cb16d058334f9a353e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda",
"max_line_length": 65,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/pseudotruncations/NONRECURSIVE-INDEX.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1018,
"size": 3756
}
|
{-# OPTIONS --cubical --safe #-}
open import Prelude hiding (A; B)
open import Categories
module Categories.Pushout {ℓ₁ ℓ₂} (C : Category ℓ₁ ℓ₂) where
open Category C
private
variable
A B : Ob
h₁ h₂ j : A ⟶ B
record Pushout (f : X ⟶ Y) (g : X ⟶ Z) : Type (ℓ₁ ℓ⊔ ℓ₂) where
field
{Q} : Ob
i₁ : Y ⟶ Q
i₂ : Z ⟶ Q
commute : i₁ · f ≡ i₂ · g
universal : h₁ · f ≡ h₂ · g → Q ⟶ Codomain h₁
unique : ∀ {eq : h₁ · f ≡ h₂ · g} →
j · i₁ ≡ h₁ → j · i₂ ≡ h₂ →
j ≡ universal eq
universal·i₁≡h₁ : ∀ {eq : h₁ · f ≡ h₂ · g} →
universal eq · i₁ ≡ h₁
universal·i₂≡h₂ : ∀ {eq : h₁ · f ≡ h₂ · g} →
universal eq · i₂ ≡ h₂
HasPushouts : Type (ℓ₁ ℓ⊔ ℓ₂)
HasPushouts = ∀ {X Y Z} → (f : X ⟶ Y) → (g : X ⟶ Z) → Pushout f g
|
{
"alphanum_fraction": 0.4763061968,
"avg_line_length": 24.9393939394,
"ext": "agda",
"hexsha": "c5942ce6c1238af1d4aab88608cc8b5b07af1e27",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Categories/Pushout.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Categories/Pushout.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Categories/Pushout.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 351,
"size": 823
}
|
-- Andreas, 2016-02-02
module _ where
data Q : Set where
a : Q
data Overlap : Set where
a : Overlap
postulate helper : ∀ {T : Set} → (T → T) → Set
test₃ : Set
test₃ = helper λ { a → a }
-- Does not succeed, as the type of the extended lambda is ambiguous.
-- It should fail with an error or unsolved metas instead of
-- looping the type checker.
|
{
"alphanum_fraction": 0.6378378378,
"avg_line_length": 19.4736842105,
"ext": "agda",
"hexsha": "ce85f6a1e670d258f4ff436afebe647264d795fd",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue480.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue480.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue480.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 116,
"size": 370
}
|
module Issue756a where
data Nat : Set where
zero : Nat
suc : Nat → Nat
data T : Nat → Set where
[_] : ∀ n → T n
bad : ∀ n → T n → Nat
bad .zero [ zero ] = zero
bad .(suc (let x = n in x)) [ suc n ] = zero
|
{
"alphanum_fraction": 0.4978723404,
"avg_line_length": 16.7857142857,
"ext": "agda",
"hexsha": "8ebfa597b3086f551ff9dce042f48826478e4a34",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue756a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue756a.agda",
"max_line_length": 44,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue756a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 85,
"size": 235
}
|
{-# OPTIONS --without-K #-}
module Agda.Builtin.List where
infixr 5 _∷_
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
{-# HASKELL type AgdaList a b = [b] #-}
{-# COMPILED_DATA List MAlonzo.Code.Agda.Builtin.List.AgdaList [] (:) #-}
{-# COMPILED_DATA_UHC List __LIST__ __NIL__ __CONS__ #-}
{-# COMPILED_JS List function(x,v) {
if (x.length < 1) { return v["[]"](); } else { return v["_∷_"](x[0], x.slice(1)); }
} #-}
{-# COMPILED_JS [] Array() #-}
{-# COMPILED_JS _∷_ function (x) { return function(y) { return Array(x).concat(y); }; } #-}
|
{
"alphanum_fraction": 0.5729166667,
"avg_line_length": 29.2173913043,
"ext": "agda",
"hexsha": "d5d594628754488f7bf1b39212f7de92794a7156",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/List.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 234,
"size": 672
}
|
-- Andreas, 2015-07-07 continuation of issue 665
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.with.strip:60 -v tc.lhs:10 #-}
postulate
C : Set
anything : C
record I : Set where
constructor c
field
f : C
data Wrap : (j : I) → Set where
wrap : ∀ {j} → Wrap j
works1 : ∀ {j} → Wrap j → C
works1 {c ._} (wrap {c x}) with anything
... | z = z
works2 : ∀ {j} → Wrap j → C
works2 (wrap {_}) with anything
... | z = z
works3 : ∀ {j} → Wrap j → C
works3 wrap with anything
... | z = z
works : ∀ {j} → Wrap j → C
works {c _} (wrap {c ._}) with anything
works {c _} (wrap .{c _}) | z = z
-- The following should not pass, but issue 142 is hard to fix
-- with the current infrastructure for with-clauses.
-- Not many attempts have been made since 2009, and none succeeded.
issue142 : ∀ {j} → Wrap j → C
issue142 {c _} (wrap {c ._}) with anything
issue142 {c _} (wrap .{c anything}) | z = z
test : ∀ {j} → Wrap j → C
test {c _} (wrap {c ._}) with anything
test {c _} (wrap {c ._}) | z = z
test' : ∀ {j} → Wrap j → C
test' {c _} (wrap {c ._}) with anything
... | z = z
-- ERROR WAS::
-- Inaccessible (dotted) patterns from the parent clause must also be
-- inaccessible in the with clause, when checking the pattern {c ._},
-- when checking that the clause
-- test {c _} (wrap {c ._}) with anything
-- test {c _} (wrap {c ._}) | z = z
-- has type {j : I} → Wrap j → C
works1a : ∀ {j} → Wrap j → C
works1a {c ._} (wrap {c x}) with anything
works1a {c ._} (wrap {c x}) | z = z
works1b : ∀ {j} → Wrap j → C
works1b {c ._} (wrap {c x}) with anything
works1b .{c _} (wrap {c x}) | z = z
-- ERROR WAS:
-- With clause pattern .(c _) is not an instance of its parent pattern
-- (c .(Var 0 []) : {I})
-- when checking that the clause
-- works1b {c ._} (wrap {c _}) with anything
-- works1b {.(c _)} (wrap {c _}) | z = z
-- has type {j : I} → Wrap j → C
-- should pass
|
{
"alphanum_fraction": 0.5841741901,
"avg_line_length": 25.4459459459,
"ext": "agda",
"hexsha": "040932de07207c23764a135ee41ff80587a1da0f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/Issue1606.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/Issue1606.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue1606.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 671,
"size": 1883
}
|
open import Prelude hiding (begin_; step-≡; _∎)
module MJ.Classtable.Core (c : ℕ) where
open import Data.Product.Relation.Binary.Pointwise.NonDependent using (_×-≟_)
open import Data.List
open import Data.List.Membership.Propositional
open import Data.List.Relation.Binary.Pointwise using (decidable-≡)
open import Relation.Binary
open import Data.Vec
open import Data.Maybe
open import Data.String
open import Relation.Binary using (Decidable)
open import MJ.Types as Types
{-
To model that a class may define both field and methods in a uniform manner, we
choose to introduce two namespaces.
-}
data NS : Set where
METHOD : NS
FIELD : NS
typing : NS → Set
typing METHOD = Sig c
typing FIELD = Ty c
-- decidable equality on typings
_typing-≟_ : ∀ {ns} → Decidable (_≡_ {A = typing ns})
_typing-≟_ {METHOD} = (decidable-≡ Types._≟_) ×-≟ Types._≟_
_typing-≟_ {FIELD} = Types._≟_
{-
We choose to make parent declarations obligatory and have a distinguished class
identifier Object in which inheritance chains find their foundation.
The field constr of this record provides access to the constructor parameter types.
The field decls returns a list of named members for each namespace, where the
type of the member is namespace-dependent. The uniformity of member definitions
permits a notion of membership that works for both fields and methods:
-}
record Class : Set where
constructor class
field
parent : Cid c
constr : List (Ty c) -- argument types
decls : (ns : NS) → List (String × typing ns)
ObjectClass = class Object [] (λ _ → [])
{-
Conceptually a class table stores the types of all members of all classes.
It is modeled by a total function from class identifiers to instances of
a record Class.
-}
PreClasstable = Cid c → Class
{-
We can define inheritance as the transitive closure of a step relation
between class identifiers under a given classtable Σ:
-}
data _⊢_<:ₛ_ (Σ : PreClasstable) : Cid c → Cid c → Set where
super : ∀ {cid} → Σ ⊢ cls cid <:ₛ (Class.parent (Σ (cls cid)))
open import Data.Star
_⊢_<:_ : (Σ : PreClasstable)(cid : Cid c) → (pid : Cid c) → Set
_⊢_<:_ Σ = Star (_⊢_<:ₛ_ Σ)
{-
We'll restrict classtables to those that satisfy three properties:
- founded: says that Object is at the base of sub-typing
- rooted: says that every class inherits from Object
- Σ-object: gives meaning to the distinguished Object class identifier
-}
record Classtable : Set where
field
Σ : PreClasstable
founded : Class.parent (Σ Object) ≡ Object
rooted : ∀ C → Σ ⊢ C <: Object
Σ-Object : Σ Object ≡ ObjectClass
_<∶_ : ∀ (cid pid : Cid c) → Set
a <∶ b = Σ ⊢ a <: b
open import Relation.Binary
open import Data.Nat.Properties
{-
We can show that the subtyping relation is indeed reflexive and transitive
-}
<:-reflexive : Reflexive (_⊢_<:_ Σ)
<:-reflexive = ε
<:-transitive : Transitive (_⊢_<:_ Σ)
<:-transitive = _◅◅_
{-
From the axioms of the classtable we can derive the important properties
that cyclic inheritance is impossible and that consequently inheritance
proofs are unique.
The proof is slightly involved because we have to make sure that Agda
believes that it is total.
-}
private
len : ∀ {c p} → Σ ⊢ c <: p → ℕ
len ε = 0
len (x ◅ px) = suc $ len px
len-◅◅ : ∀ {c p p'}(s : Σ ⊢ c <: p)(s' : Σ ⊢ p <: p') → len (s ◅◅ s') ≡ len s + len s'
len-◅◅ ε _ = refl
len-◅◅ (x ◅ s) s' rewrite len-◅◅ s s' = refl
lem-len : ∀ {c p}(px : Σ ⊢ c <: p)(qx : Σ ⊢ c <: Object) → len px ≤ len qx
lem-len ε ε = z≤n
lem-len ε (x ◅ qx) = z≤n
lem-len (() ◅ px) ε
lem-len (super ◅ px) (super ◅ qx) = s≤s (lem-len px qx)
open ≤-Reasoning
-- generate an inheritance proof of arbitrary length,
-- given an inheritance proof from a parent to a child
lem-inf : ∀ c → Σ ⊢ Class.parent (Σ (cls c)) <: (cls c) → ∀ n → ∃ λ (px : Σ ⊢ (cls c) <: (cls c)) → len px > n
lem-inf c px n with helper px n
where
helper : (p : Σ ⊢ Class.parent (Σ (cls c)) <: (cls c)) → ∀ gap → ∃ λ (px : Σ ⊢ (cls c) <: (cls c)) → len px ≥ gap + len p
helper p zero = (super ◅ p) , ≤-step ≤-refl
helper p (suc gap) with gap ≤? len p
... | yes q = (super ◅ p ◅◅ (super ◅ p)) , s≤s (begin
(gap + len p)
≤⟨ +-mono-≤ q (≤-step ≤-refl) ⟩
len p + (suc (len p))
≡⟨ sym (len-◅◅ p (super ◅ p)) ⟩
len (p ◅◅ super ◅ p)
∎)
... | no ¬q with helper (p ◅◅ (super ◅ p)) gap
... | z , q = z , (begin
suc (gap + len p)
≡⟨ sym $ m+n+o≡n+m+o gap 1 (len p) ⟩
gap + (len (super ◅ p))
≤⟨ +-mono-≤ { gap } ≤-refl (≤-stepsˡ (len p) ≤-refl) ⟩
gap + (len p + len (super ◅ p))
≡⟨ cong (_+_ gap) (sym $ len-◅◅ p (super ◅ p)) ⟩
gap + (len (p ◅◅ (super ◅ p)))
≤⟨ q ⟩
len z ∎)
where open import Data.Nat.Properties.Extra
... | py , z = super ◅ px ◅◅ py , s≤s (subst (_≤_ n) (sym $ len-◅◅ px py) (≤-stepsˡ (len px) (m+n≤o⇒m≤o n z)))
-- Proves that a parent can't inherit from it's children,
Σ-acyclic : ∀ c → ¬ Σ ⊢ Class.parent (Σ (cls c)) <: (cls c)
Σ-acyclic c px with lem-inf c px (len $ rooted (cls c))
... | qx , impossible with lem-len qx (rooted (cls c))
... | z = ⊥-elim (<⇒≱ impossible z)
-- Trivially we have that Object cannot inherit from any class
¬Object<:x : ∀ {cid} → ¬ Σ ⊢ Object <: cls cid
¬Object<:x (() ◅ p)
-- Using acyclicity we can show that inheritance proofs are unique
<:-unique : ∀ {c p} → (l r : Σ ⊢ c <: p) → l ≡ r
<:-unique ε ε = refl
<:-unique ε ch@(super ◅ r) = ⊥-elim (Σ-acyclic _ r)
<:-unique ch@(super ◅ l) ε = ⊥-elim (Σ-acyclic _ l)
<:-unique (super ◅ l) (super ◅ r) with <:-unique l r
... | refl = refl
|
{
"alphanum_fraction": 0.5983915127,
"avg_line_length": 33.976744186,
"ext": "agda",
"hexsha": "f96b9b9f5cc35eddf991109634c6058b94f3d2c2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Classtable/Core.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Classtable/Core.agda",
"max_line_length": 129,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Classtable/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 2006,
"size": 5844
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Homogeneously-indexed binary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Indexed.Homogeneous where
------------------------------------------------------------------------
-- Publicly export core definitions
open import Relation.Binary.Indexed.Homogeneous.Core public
open import Relation.Binary.Indexed.Homogeneous.Definitions public
open import Relation.Binary.Indexed.Homogeneous.Structures public
open import Relation.Binary.Indexed.Homogeneous.Bundles public
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.17
REL = IREL
{-# WARNING_ON_USAGE REL
"Warning: REL was deprecated in v0.17.
Please use IREL instead."
#-}
Rel = IRel
{-# WARNING_ON_USAGE Rel
"Warning: Rel was deprecated in v0.17.
Please use IRel instead."
#-}
|
{
"alphanum_fraction": 0.5306298533,
"avg_line_length": 30.5,
"ext": "agda",
"hexsha": "b1bc8fcb06a4502b8596d2fd1f82717cb2bea6c8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 199,
"size": 1159
}
|
{-# OPTIONS --without-K #-}
open import HoTT
{- The pseudo-adjoint functors F,G : Ptd → Ptd
- It stops at composition and ignores
- all the higher associahedrons.
-}
module homotopy.PtdAdjoint where
record PtdFunctor i j : Type (lsucc (lmax i j)) where
field
obj : Ptd i → Ptd j
arr : {X Y : Ptd i} → fst (X ⊙→ Y) → fst (obj X ⊙→ obj Y)
id : (X : Ptd i) → arr (⊙idf X) == ⊙idf (obj X)
comp : {X Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))
→ arr (g ⊙∘ f) == arr g ⊙∘ arr f
{- counit-unit description of F ⊣ G -}
record CounitUnitAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i)
: Type (lsucc (lmax i j)) where
private
module F = PtdFunctor F
module G = PtdFunctor G
field
η : (X : Ptd i) → fst (X ⊙→ G.obj (F.obj X))
ε : (U : Ptd j) → fst (F.obj (G.obj U) ⊙→ U)
η-natural : {X Y : Ptd i} (h : fst (X ⊙→ Y))
→ η Y ⊙∘ h == G.arr (F.arr h) ⊙∘ η X
ε-natural : {U V : Ptd j} (k : fst (U ⊙→ V))
→ ε V ⊙∘ F.arr (G.arr k) == k ⊙∘ ε U
εF-Fη : (X : Ptd i) → ε (F.obj X) ⊙∘ F.arr (η X) == ⊙idf (F.obj X)
Gε-ηG : (U : Ptd j) → G.arr (ε U) ⊙∘ η (G.obj U) == ⊙idf (G.obj U)
{- hom-set isomorphism description of F ⊣ G -}
record HomAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i)
: Type (lsucc (lmax i j)) where
private
module F = PtdFunctor F
module G = PtdFunctor G
field
eq : (X : Ptd i) (U : Ptd j) → fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U)
nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)
(r : fst (F.obj Y ⊙→ U))
→ –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h)
nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))
(r : fst (F.obj X ⊙→ U))
→ G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r)
nat!-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)
(s : fst (Y ⊙→ G.obj U))
→ <– (eq Y U) s ⊙∘ F.arr h == <– (eq X U) (s ⊙∘ h)
nat!-dom {X} {Y} h U s =
! (<–-inv-l (eq X U) (<– (eq Y U) s ⊙∘ F.arr h))
∙ ap (<– (eq X U)) (! (nat-dom h U (<– (eq Y U) s)))
∙ ap (λ w → <– (eq X U) (w ⊙∘ h)) (<–-inv-r (eq Y U) s)
nat!-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))
(s : fst (X ⊙→ G.obj U))
→ k ⊙∘ <– (eq X U) s == <– (eq X V) (G.arr k ⊙∘ s)
nat!-cod X {U} {V} k s =
! (<–-inv-l (eq X V) (k ⊙∘ <– (eq X U) s))
∙ ap (<– (eq X V)) (! (nat-cod X k (<– (eq X U) s)))
∙ ap (λ w → <– (eq X V) (G.arr k ⊙∘ w)) (<–-inv-r (eq X U) s)
counit-unit-to-hom : ∀ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}
→ CounitUnitAdjoint F G → HomAdjoint F G
counit-unit-to-hom {i} {j} {F} {G} adj = record {
eq = eq;
nat-dom = nat-dom;
nat-cod = nat-cod}
where
module F = PtdFunctor F
module G = PtdFunctor G
open CounitUnitAdjoint adj
module _ (X : Ptd i) (U : Ptd j) where
into : fst (F.obj X ⊙→ U) → fst (X ⊙→ G.obj U)
into r = G.arr r ⊙∘ η X
out : fst (X ⊙→ G.obj U) → fst (F.obj X ⊙→ U)
out s = ε U ⊙∘ F.arr s
into-out : (s : fst (X ⊙→ G.obj U)) → into (out s) == s
into-out s =
G.arr (ε U ⊙∘ F.arr s) ⊙∘ η X
=⟨ G.comp (ε U) (F.arr s) |in-ctx (λ w → w ⊙∘ η X) ⟩
(G.arr (ε U) ⊙∘ G.arr (F.arr s)) ⊙∘ η X
=⟨ ⊙∘-assoc (G.arr (ε U)) (G.arr (F.arr s)) (η X) ⟩
G.arr (ε U) ⊙∘ G.arr (F.arr s) ⊙∘ η X
=⟨ ! (η-natural s) |in-ctx (λ w → G.arr (ε U) ⊙∘ w) ⟩
G.arr (ε U) ⊙∘ η (G.obj U) ⊙∘ s
=⟨ ! (⊙∘-assoc (G.arr (ε U)) (η (G.obj U)) s) ⟩
(G.arr (ε U) ⊙∘ η (G.obj U)) ⊙∘ s
=⟨ Gε-ηG U |in-ctx (λ w → w ⊙∘ s) ⟩
⊙idf (G.obj U) ⊙∘ s
=⟨ ⊙∘-unit-l s ⟩
s ∎
out-into : (r : fst (F.obj X ⊙→ U)) → out (into r) == r
out-into r =
ε U ⊙∘ F.arr (G.arr r ⊙∘ η X)
=⟨ F.comp (G.arr r) (η X) |in-ctx (λ w → ε U ⊙∘ w) ⟩
ε U ⊙∘ F.arr (G.arr r) ⊙∘ F.arr (η X)
=⟨ ! (⊙∘-assoc (ε U) (F.arr (G.arr r)) (F.arr (η X))) ⟩
(ε U ⊙∘ F.arr (G.arr r)) ⊙∘ F.arr (η X)
=⟨ ε-natural r |in-ctx (λ w → w ⊙∘ F.arr (η X)) ⟩
(r ⊙∘ ε (F.obj X)) ⊙∘ F.arr (η X)
=⟨ ⊙∘-assoc r (ε (F.obj X)) (F.arr (η X)) ⟩
r ⊙∘ ε (F.obj X) ⊙∘ F.arr (η X)
=⟨ εF-Fη X |in-ctx (λ w → r ⊙∘ w) ⟩
r ∎
eq : fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U)
eq = equiv into out into-out out-into
nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)
(r : fst (F.obj Y ⊙→ U))
→ –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h)
nat-dom {X} {Y} h U r =
(G.arr r ⊙∘ η Y) ⊙∘ h
=⟨ ⊙∘-assoc (G.arr r) (η Y) h ⟩
G.arr r ⊙∘ η Y ⊙∘ h
=⟨ η-natural h |in-ctx (λ w → G.arr r ⊙∘ w) ⟩
G.arr r ⊙∘ G.arr (F.arr h) ⊙∘ η X
=⟨ ! (⊙∘-assoc (G.arr r) (G.arr (F.arr h)) (η X)) ⟩
(G.arr r ⊙∘ G.arr (F.arr h)) ⊙∘ η X
=⟨ ! (G.comp r (F.arr h)) |in-ctx (λ w → w ⊙∘ η X) ⟩
G.arr (r ⊙∘ F.arr h) ⊙∘ η X ∎
nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))
(r : fst (F.obj X ⊙→ U))
→ G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r)
nat-cod X k r =
G.arr k ⊙∘ (G.arr r ⊙∘ η X)
=⟨ ! (⊙∘-assoc (G.arr k) (G.arr r) (η X)) ⟩
(G.arr k ⊙∘ G.arr r) ⊙∘ η X
=⟨ ! (G.comp k r) |in-ctx (λ w → w ⊙∘ η X) ⟩
G.arr (k ⊙∘ r) ⊙∘ η X ∎
{- a right adjoint preserves products -}
module RightAdjoint× {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}
(adj : HomAdjoint F G) (U V : Ptd j) where
private
module F = PtdFunctor F
module G = PtdFunctor G
module A = HomAdjoint adj
⊙into : fst (G.obj (U ⊙× V) ⊙→ G.obj U ⊙× G.obj V)
⊙into = ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)
⊙out : fst (G.obj U ⊙× G.obj V ⊙→ G.obj (U ⊙× V))
⊙out = –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst)
(<– (A.eq _ _) ⊙snd))
⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _
⊙into-out =
⊙×-in (G.arr ⊙fst) (G.arr ⊙snd) ⊙∘ ⊙out
=⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) ⊙out ⟩
⊙×-in (G.arr ⊙fst ⊙∘ ⊙out) (G.arr ⊙snd ⊙∘ ⊙out)
=⟨ ap2 ⊙×-in
(A.nat-cod _ ⊙fst (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))
∙ ap (–> (A.eq _ _))
(⊙fst-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))
∙ <–-inv-r (A.eq _ _) ⊙fst)
(A.nat-cod _ ⊙snd (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))
∙ ap (–> (A.eq _ _))
(⊙snd-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))
∙ <–-inv-r (A.eq _ _) ⊙snd) ⟩
⊙×-in ⊙fst ⊙snd ∎
⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _
⊙out-into =
–> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))
⊙∘ ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)
=⟨ A.nat-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _
(⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ⟩
–> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)
⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))
=⟨ ⊙×-in-pre∘ (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)
(F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))
|in-ctx –> (A.eq _ _) ⟩
–> (A.eq _ _) (⊙×-in
(<– (A.eq _ _) ⊙fst ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))
(<– (A.eq _ _) ⊙snd ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))))
=⟨ ap2 (λ f g → –> (A.eq _ _) (⊙×-in f g))
(A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙fst
∙ ap (<– (A.eq _ _)) (⊙fst-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))
∙ ! (A.nat!-cod _ ⊙fst (⊙idf _)))
(A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙snd
∙ ap (<– (A.eq _ _)) (⊙snd-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))
∙ ! (A.nat!-cod _ ⊙snd (⊙idf _))) ⟩
–> (A.eq _ _) (⊙×-in (⊙fst ⊙∘ <– (A.eq _ _) (⊙idf _))
(⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _)))
=⟨ ap (–> (A.eq _ _)) (! (⊙×-in-pre∘ ⊙fst ⊙snd (<– (A.eq _ _) (⊙idf _)))) ⟩
–> (A.eq _ _) (⊙×-in ⊙fst ⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _))
=⟨ ⊙∘-unit-l _ |in-ctx –> (A.eq _ _) ⟩
–> (A.eq _ _) (<– (A.eq _ _) (⊙idf _))
=⟨ <–-inv-r (A.eq _ _) (⊙idf _) ⟩
⊙idf _ ∎
⊙eq : G.obj (U ⊙× V) ⊙≃ G.obj U ⊙× G.obj V
⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out)
(app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into)))
(snd ⊙into)
⊙path = ⊙ua ⊙eq
{- Using the equivalence in RightAdjoint× we get a binary
- "G.arr2" : (X × Y → Z) → (G X × G Y → G Z)
- and there is some kind of naturality wrt the (FX→Y)≃(X→GY) equivalence
- (use case: from ⊙ap we get ⊙ap2) -}
module RightAdjointBinary {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}
(adj : HomAdjoint F G)
where
private
module F = PtdFunctor F
module G = PtdFunctor G
module A = HomAdjoint adj
module A× = RightAdjoint× adj
arr2 : {X Y Z : Ptd j}
→ fst (X ⊙× Y ⊙→ Z) → fst (G.obj X ⊙× G.obj Y ⊙→ G.obj Z)
arr2 {X} {Y} {Z} f = G.arr f ⊙∘ A×.⊙out X Y
nat-cod : {X : Ptd i} {Y Z W : Ptd j}
(r₁ : fst (F.obj X ⊙→ Y)) (r₂ : fst (F.obj X ⊙→ Z))
(o : fst (Y ⊙× Z ⊙→ W))
→ –> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂)
== arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂)
nat-cod {X} {Y} {Z} {W} r₁ r₂ o =
–> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂)
=⟨ ! (A.nat-cod X o (⊙×-in r₁ r₂)) ⟩
G.arr o ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)
=⟨ ! (A×.⊙out-into Y Z)
|in-ctx (λ w → (G.arr o ⊙∘ w) ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩
(G.arr o ⊙∘ (A×.⊙out Y Z ⊙∘ A×.⊙into Y Z))
⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)
=⟨ ⊙∘-assoc-lemma (G.arr o) (A×.⊙out Y Z) (A×.⊙into Y Z)
(–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩
arr2 o ⊙∘ A×.⊙into Y Z ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)
=⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) (–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))
|in-ctx (λ w → arr2 o ⊙∘ w) ⟩
arr2 o ⊙∘ ⊙×-in (G.arr ⊙fst ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))
(G.arr ⊙snd ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))
=⟨ ap2 (λ w₁ w₂ → arr2 o ⊙∘ ⊙×-in w₁ w₂)
(A.nat-cod X ⊙fst (⊙×-in r₁ r₂)
∙ ap (–> (A.eq X Y)) (⊙fst-⊙×-in r₁ r₂))
(A.nat-cod X ⊙snd (⊙×-in r₁ r₂)
∙ ap (–> (A.eq X Z)) (⊙snd-⊙×-in r₁ r₂)) ⟩
arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂) ∎
where
⊙∘-assoc-lemma : ∀ {i j k l m}
{X : Ptd i} {Y : Ptd j} {Z : Ptd k} {U : Ptd l} {V : Ptd m}
(k : fst (U ⊙→ V)) (h : fst (Z ⊙→ U))
(g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))
→ (k ⊙∘ (h ⊙∘ g)) ⊙∘ f == (k ⊙∘ h) ⊙∘ g ⊙∘ f
⊙∘-assoc-lemma (k , idp) (h , idp) (g , idp) (f , idp) = idp
{- a left adjoint preserves wedges -}
module LeftAdjoint∨ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}
(adj : HomAdjoint F G) (U V : Ptd i) where
private
module F = PtdFunctor F
module G = PtdFunctor G
module A = HomAdjoint adj
module Into = ⊙WedgeRec (F.arr ⊙winl) (F.arr ⊙winr)
⊙into : fst (F.obj U ⊙∨ F.obj V ⊙→ F.obj (U ⊙∨ V))
⊙into = Into.⊙f
module OutHelp = ⊙WedgeRec (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)
⊙out : fst (F.obj (U ⊙∨ V) ⊙→ F.obj U ⊙∨ F.obj V)
⊙out = <– (A.eq _ _) OutHelp.⊙f
⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _
⊙into-out =
⊙into ⊙∘ ⊙out
=⟨ A.nat!-cod _ ⊙into (⊙wedge-rec (–> (A.eq _ _) ⊙winl)
(–> (A.eq _ _) ⊙winr)) ⟩
<– (A.eq _ _) (G.arr ⊙into ⊙∘ ⊙wedge-rec (–> (A.eq _ _) ⊙winl)
(–> (A.eq _ _) ⊙winr))
=⟨ ap (<– (A.eq _ _)) (⊙wedge-rec-post∘ (G.arr ⊙into)
(–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)) ⟩
<– (A.eq _ _) (⊙wedge-rec (G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winl)
(G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winr))
=⟨ ap2 (λ w₁ w₂ → <– (A.eq _ _) (⊙wedge-rec w₁ w₂))
(A.nat-cod _ ⊙into ⊙winl
∙ ap (–> (A.eq _ _)) (Into.⊙winl-β ∙ ! (⊙∘-unit-l _))
∙ ! (A.nat-dom ⊙winl _ (⊙idf _)))
(A.nat-cod _ ⊙into ⊙winr
∙ ap (–> (A.eq _ _)) (Into.⊙winr-β ∙ ! (⊙∘-unit-l _))
∙ ! (A.nat-dom ⊙winr _ (⊙idf _))) ⟩
<– (A.eq _ _) (⊙wedge-rec (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winl)
(–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winr))
=⟨ ap (<– (A.eq _ _))
(! (⊙wedge-rec-post∘ (–> (A.eq _ _) (⊙idf _)) ⊙winl ⊙winr)) ⟩
<– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙wedge-rec ⊙winl ⊙winr)
=⟨ ap (λ w → <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ w))
⊙wedge-rec-η ⟩
<– (A.eq _ _) (–> (A.eq _ _) (⊙idf _))
=⟨ <–-inv-l (A.eq _ _) (⊙idf _) ⟩
⊙idf _ ∎
⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _
⊙out-into =
⊙out ⊙∘ ⊙wedge-rec (F.arr ⊙winl) (F.arr ⊙winr)
=⟨ ⊙wedge-rec-post∘ ⊙out (F.arr ⊙winl) (F.arr ⊙winr) ⟩
⊙wedge-rec (⊙out ⊙∘ F.arr ⊙winl) (⊙out ⊙∘ F.arr ⊙winr)
=⟨ ap2 ⊙wedge-rec
(A.nat!-dom ⊙winl _ (⊙wedge-rec _ _)
∙ ap (<– (A.eq _ _)) OutHelp.⊙winl-β
∙ <–-inv-l (A.eq _ _) ⊙winl)
(A.nat!-dom ⊙winr _ (⊙wedge-rec _ _)
∙ ap (<– (A.eq _ _)) OutHelp.⊙winr-β
∙ <–-inv-l (A.eq _ _) ⊙winr) ⟩
⊙wedge-rec ⊙winl ⊙winr
=⟨ ⊙wedge-rec-η ⟩
⊙idf _ ∎
⊙eq : F.obj U ⊙∨ F.obj V ⊙≃ F.obj (U ⊙∨ V)
⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out)
(app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into)))
(snd ⊙into)
⊙path = ⊙ua ⊙eq
|
{
"alphanum_fraction": 0.4090249675,
"avg_line_length": 38.2953216374,
"ext": "agda",
"hexsha": "41718b3fbf52c79534f4fcef2287040285ce0761",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/PtdAdjoint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/PtdAdjoint.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/PtdAdjoint.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6699,
"size": 13097
}
|
module test.IntegerLiteral where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
open import Agda.Builtin.Sigma
open import Data.Integer
open import Data.Nat
-- zerepoch/zerepoch-core/test/data/integerLiteral.plc
intLit : ∀{Γ} → Γ ⊢ con integer (size⋆ 100)
intLit = con (integer 100 (ℤ.pos 102341) (-≤+ Σ., +≤+ (gen _ _ _)))
|
{
"alphanum_fraction": 0.7420091324,
"avg_line_length": 27.375,
"ext": "agda",
"hexsha": "b24aa571b0c801ebc1452fc8bcbec84fe831dcb8",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-21T16:38:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-13T21:25:19.000Z",
"max_forks_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Quantum-One-DLT/zerepoch",
"max_forks_repo_path": "zerepoch-metatheory/test/IntegerLiteral.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Quantum-One-DLT/zerepoch",
"max_issues_repo_path": "zerepoch-metatheory/test/IntegerLiteral.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "Quantum-One-DLT/zerepoch",
"max_stars_repo_path": "zerepoch-metatheory/test/IntegerLiteral.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 149,
"size": 438
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function using (_on_)
open import Cubical.Foundations.HLevels
open import Cubical.Classes using (Cast; [_]) public
private
variable
a b ℓ : Level
A : Type a
B : Type b
RawREL : Type a → Type b → (ℓ : Level) → Type _
RawREL A B ℓ = A → B → Type ℓ
RawRel : Type a → (ℓ : Level) → Type _
RawRel A ℓ = RawREL A A ℓ
REL : Type a → Type b → (ℓ : Level) → Type _
REL A B ℓ = A → B → hProp ℓ
Rel : Type a → (ℓ : Level) → Type _
Rel A ℓ = REL A A ℓ
isPropValued : RawREL A B ℓ → Type _
isPropValued R = ∀ a b → isProp (R a b)
instance
RelCast : Cast (REL A B ℓ) (RawREL A B ℓ)
RelCast = record { cast = λ R a b → R a b .fst }
isProp[_] : (R : REL A B ℓ) → isPropValued [ R ]
isProp[ R ] a b = R a b .snd
fromRaw : (R : RawREL A B ℓ) → isPropValued R → REL A B ℓ
fromRaw R isPropR a b .fst = R a b
fromRaw R isPropR a b .snd = isPropR a b
|
{
"alphanum_fraction": 0.6387582314,
"avg_line_length": 23.1086956522,
"ext": "agda",
"hexsha": "130caa516b59267666f27e043625c5499b650efe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 386,
"size": 1063
}
|
------------------------------------------------------------------------
-- Some results/examples related to CCS, implemented using the
-- coinductive definition of bisimilarity
------------------------------------------------------------------------
-- Unless anything else is stated the results (or statements, in the
-- case of exercises) below are taken from "Enhancements of the
-- bisimulation proof method" by Pous and Sangiorgi.
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.CCS.Examples {ℓ} {Name : Type ℓ} where
open import Equality.Propositional
open import Prelude.Size
open import Bisimilarity.CCS
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
open import Labelled-transition-system.CCS Name
open import Bisimilarity CCS
------------------------------------------------------------------------
-- A result mentioned in "Enhancements of the bisimulation proof
-- method"
mutual
-- For a more general result, see 6-2-14 below.
!∙⊕∙∼!∙∣!∙ : ∀ {i a b} → [ i ] ! (a ∙ ⊕ b ∙) ∼ ! a ∙ ∣ ! b ∙
!∙⊕∙∼!∙∣!∙ {i} {a} {b} = ⟨ lr , rl ⟩
where
lemma =
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ ∣-right-identity ⟩
! (a ∙ ⊕ b ∙) ∼⟨ !∙⊕∙∼′!∙∣!∙ {i = i} ⟩■
! a ∙ ∣ ! b ∙
left-lemma =
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩
! a ∙ ∣ ! b ∙ ∼⟨ symmetric ∣-right-identity ∣-cong reflexive ⟩■
(! a ∙ ∣ ∅) ∣ ! b ∙
right-lemma =
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩
! a ∙ ∣ ! b ∙ ∼⟨ reflexive ∣-cong symmetric ∣-right-identity ⟩■
! a ∙ ∣ (! b ∙ ∣ ∅)
τ-lemma =
(! (a ∙ ⊕ b ∙) ∣ ∅) ∣ ∅ ∼⟨ ∣-right-identity ⟩
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ lemma ⟩
! a ∙ ∣ ! b ∙ ∼⟨ symmetric (∣-right-identity ∣-cong ∣-right-identity) ⟩■
(! a ∙ ∣ ∅) ∣ (! b ∙ ∣ ∅)
lr : ∀ {P μ} →
! (a ∙ ⊕ b ∙) [ μ ]⟶ P →
∃ λ Q → ! a ∙ ∣ ! b ∙ [ μ ]⟶ Q × [ i ] P ∼′ Q
lr {P} tr = case 6-1-3-2 tr of λ where
(inj₁ (.∅ , sum-left action , P∼![a⊕b]∣∅)) →
P ∼⟨ P∼![a⊕b]∣∅ ⟩
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ left-lemma ⟩■
(! a ∙ ∣ ∅) ∣ ! b ∙ [ name a ]⟵⟨ par-left (replication (par-right action)) ⟩
! a ∙ ∣ ! b ∙
(inj₁ (.∅ , sum-right action , P∼![a⊕b]∣∅)) →
P ∼⟨ P∼![a⊕b]∣∅ ⟩
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ right-lemma ⟩■
! a ∙ ∣ (! b ∙ ∣ ∅) [ name b ]⟵⟨ par-right (replication (par-right action)) ⟩
! a ∙ ∣ ! b ∙
(inj₂ (refl , P′ , P″ , c , a⊕b⟶P′ , a⊕b⟶P″ , P∼![a⊕b]∣P′∣P″)) →
let b≡co-a , P′≡∅ , P″≡∅ = Σ-map id [ id , id ]
(·⊕·-co a⊕b⟶P′ a⊕b⟶P″) in
P ∼⟨ P∼![a⊕b]∣P′∣P″ ⟩
(! (a ∙ ⊕ b ∙) ∣ P′) ∣ P″ ∼⟨ (reflexive ∣-cong ≡⇒∼ P′≡∅) ∣-cong ≡⇒∼ P″≡∅ ⟩
(! (a ∙ ⊕ b ∙) ∣ ∅) ∣ ∅ ∼⟨ τ-lemma ⟩■
(! a ∙ ∣ ∅) ∣ (! b ∙ ∣ ∅) [ τ ]⟵⟨ par-τ′ b≡co-a (replication (par-right action))
(replication (par-right action)) ⟩
! a ∙ ∣ ! b ∙
rl : ∀ {Q μ} →
! a ∙ ∣ ! b ∙ [ μ ]⟶ Q →
∃ λ P → ! (a ∙ ⊕ b ∙) [ μ ]⟶ P × [ i ] P ∼′ Q
rl (par-left {P′ = P′} tr) =
case 6-1-3-2 tr of λ where
(inj₁ (.∅ , action , P′∼!a∣∅)) →
! (a ∙ ⊕ b ∙) [ name a ]⟶⟨ replication (par-right (sum-left action)) ⟩ʳˡ
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ left-lemma ⟩
(! a ∙ ∣ ∅) ∣ ! b ∙ ∼⟨ symmetric P′∼!a∣∅ ∣-cong reflexive ⟩■
P′ ∣ ! b ∙
(inj₂ (refl , .∅ , P″ , .a , action , a⟶P″ , P′∼!a∣∅∣P″)) →
⊥-elim (names-are-not-inverted a⟶P″)
rl (par-right {Q′ = Q′} tr) =
case 6-1-3-2 tr of λ where
(inj₁ (.∅ , action , Q′∼!b∣∅)) →
! (a ∙ ⊕ b ∙) [ name b ]⟶⟨ replication (par-right (sum-right action)) ⟩ʳˡ
! (a ∙ ⊕ b ∙) ∣ ∅ ∼⟨ right-lemma ⟩
! a ∙ ∣ (! b ∙ ∣ ∅) ∼⟨ reflexive ∣-cong symmetric Q′∼!b∣∅ ⟩■
! a ∙ ∣ Q′
(inj₂ (refl , .∅ , Q″ , .b , action , b⟶Q″ , Q′∼!b∣∅∣Q″)) →
⊥-elim (names-are-not-inverted b⟶Q″)
rl (par-τ {P′ = P′} {Q′ = Q′} tr₁ tr₂) =
case 6-1-3-2 tr₁ ,′ 6-1-3-2 tr₂ of λ where
(inj₁ (.∅ , action , P′∼!a∣∅) ,
inj₁ (.∅ , action , Q′∼!co-a∣∅)) →
! (a ∙ ⊕ co a ∙) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left action)))
(sum-right action)) ⟩ʳˡ
(! (a ∙ ⊕ co a ∙) ∣ ∅) ∣ ∅ ∼⟨ τ-lemma ⟩
(! a ∙ ∣ ∅) ∣ (! co a ∙ ∣ ∅) ∼⟨ symmetric (P′∼!a∣∅ ∣-cong Q′∼!co-a∣∅) ⟩■
P′ ∣ Q′
(inj₁ _ , inj₂ (() , _))
(inj₂ (() , _) , _)
!∙⊕∙∼′!∙∣!∙ : ∀ {a b i} → [ i ] ! (a ∙ ⊕ b ∙) ∼′ ! a ∙ ∣ ! b ∙
force !∙⊕∙∼′!∙∣!∙ = !∙⊕∙∼!∙∣!∙
------------------------------------------------------------------------
-- Exercise 6.2.4
mutual
-- For a more general result, see 6-2-17-4 below.
6-2-4 : ∀ {a i} → [ i ] ! ! a ∙ ∼ ! a ∙
6-2-4 {a} {i} = ⟨ lr , rl ⟩
where
impossible : ∀ {μ P q} {Q : Type q} →
! ! a ∙ [ μ ]⟶ P → μ ≡ τ → Q
impossible {μ} !!a⟶P μ≡τ = ⊥-elim $ name≢τ
(name a ≡⟨ !-only (!-only ·-only) !!a⟶P ⟩
μ ≡⟨ μ≡τ ⟩∎
τ ∎)
lemma : ∀ {P} → P ∼ ! a ∙ ∣ ∅ → _
lemma {P} P∼!a∣∅ =
! ! a ∙ ∣ P ∼⟨ reflexive ∣-cong P∼!a∣∅ ⟩
! ! a ∙ ∣ (! a ∙ ∣ ∅) ∼⟨ reflexive ∣-cong ∣-right-identity ⟩
! ! a ∙ ∣ ! a ∙ ∼⟨ 6-1-2 ⟩
! ! a ∙ ∼⟨ 6-2-4′ {i = i} ⟩
! a ∙ ∼⟨ symmetric ∣-right-identity ⟩■
! a ∙ ∣ ∅
lr : ∀ {P μ} →
! ! a ∙ [ μ ]⟶ P →
∃ λ P′ → ! a ∙ [ μ ]⟶ P′ × [ i ] P ∼′ P′
lr {P = P} !!a⟶P = case 6-1-3-2 !!a⟶P of λ where
(inj₂ (μ≡τ , _)) → impossible !!a⟶P μ≡τ
(inj₁ (P′ , !a⟶P′ , P∼!!a∣P′)) → case 6-1-3-2 !a⟶P′ of λ where
(inj₂ (μ≡τ , _)) → impossible !!a⟶P μ≡τ
(inj₁ (.∅ , action , P′∼!a∣∅)) →
P ∼⟨ P∼!!a∣P′ ⟩
! ! a ∙ ∣ P′ ∼⟨ lemma P′∼!a∣∅ ⟩■
! a ∙ ∣ ∅ [ name a ]⟵⟨ replication (par-right action) ⟩
! a ∙
rl : ∀ {P μ} →
! a ∙ [ μ ]⟶ P →
∃ λ P′ → ! ! a ∙ [ μ ]⟶ P′ × [ i ] P′ ∼′ P
rl {P = P} !a⟶P = case 6-1-3-2 !a⟶P of λ where
(inj₂ (refl , .∅ , Q″ , .a , action , a⟶Q″ , _)) →
⊥-elim (names-are-not-inverted a⟶Q″)
(inj₁ (.∅ , action , P∼!a∣∅)) →
! ! a ∙ [ name a ]⟶⟨ replication (par-right !a⟶P) ⟩ʳˡ
! ! a ∙ ∣ P ∼⟨ lemma P∼!a∣∅ ⟩
! a ∙ ∣ ∅ ∼⟨ symmetric P∼!a∣∅ ⟩■
P
6-2-4′ : ∀ {a i} → [ i ] ! ! a ∙ ∼′ ! a ∙
force 6-2-4′ = 6-2-4
------------------------------------------------------------------------
-- A result mentioned in "Enhancements of the bisimulation proof
-- method"
∙∣∙∼∙∙ : ∀ {a} → a ∙ ∣ a ∙ ∼ name a ∙ (a ∙)
∙∣∙∼∙∙ {a} = ⟨ lr , rl ⟩
where
lr : ∀ {P μ} → a ∙ ∣ a ∙ [ μ ]⟶ P →
∃ λ P′ → name a ∙ (a ∙) [ μ ]⟶ P′ × P ∼′ P′
lr (par-left action) =
∅ ∣ a ∙ ∼⟨ ∣-left-identity ⟩■
a ∙ [ name a ]⟵⟨ action ⟩
name a ∙ (a ∙)
lr (par-right action) =
a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■
a ∙ [ name a ]⟵⟨ action ⟩
name a ∙ (a ∙)
lr (par-τ action tr) = ⊥-elim (names-are-not-inverted tr)
rl : ∀ {P μ} → name a ∙ (a ∙) [ μ ]⟶ P →
∃ λ P′ → a ∙ ∣ a ∙ [ μ ]⟶ P′ × P′ ∼′ P
rl action =
a ∙ ∣ a ∙ [ name a ]⟶⟨ par-right action ⟩ʳˡ
a ∙ ∣ ∅ ∼⟨ ∣-right-identity ⟩■
a ∙
------------------------------------------------------------------------
-- Lemma 6.2.14
mutual
-- A more general variant of !∙⊕∙∼!∙∣!∙. For an even more general
-- variant, see 6-2-17-2 below.
6-2-14 :
∀ {i a b P Q} →
[ i ] ! (name a ∙ P ⊕ name b ∙ Q) ∼ ! name a ∙ P ∣ ! name b ∙ Q
6-2-14 {i} {a} {b} {P} {Q} = ⟨ lr , rl ⟩
where
left-lemma =
! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ 6-2-14′ {i = i} ∣-cong′ reflexive ⟩
(! name a ∙ P ∣ ! name b ∙ Q) ∣ P ∼⟨ swap-rightmost ⟩■
(! name a ∙ P ∣ P) ∣ ! name b ∙ Q
right-lemma =
! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ 6-2-14′ {i = i} ∣-cong′ reflexive ⟩
(! name a ∙ P ∣ ! name b ∙ Q) ∣ Q ∼⟨ symmetric ∣-assoc ⟩■
! name a ∙ P ∣ (! name b ∙ Q ∣ Q)
τ-lemma =
(! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q ∼⟨ left-lemma ∣-cong′ reflexive ⟩
((! name a ∙ P ∣ P) ∣ ! name b ∙ Q) ∣ Q ∼⟨ symmetric ∣-assoc ⟩■
(! name a ∙ P ∣ P) ∣ (! name b ∙ Q ∣ Q)
lr : ∀ {R μ} →
! (name a ∙ P ⊕ name b ∙ Q) [ μ ]⟶ R →
∃ λ S → ! name a ∙ P ∣ ! name b ∙ Q [ μ ]⟶ S × [ i ] R ∼′ S
lr {R} tr = case 6-1-3-2 tr of λ where
(inj₁ (.P , sum-left action , R∼![aP⊕bQ]∣P)) →
R ∼⟨ R∼![aP⊕bQ]∣P ⟩
! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ left-lemma ⟩■
(! name a ∙ P ∣ P) ∣ ! name b ∙ Q [ name a ]⟵⟨ par-left (replication (par-right action)) ⟩
! name a ∙ P ∣ ! name b ∙ Q
(inj₁ (.Q , sum-right action , R∼![aP⊕bQ]∣Q)) →
R ∼⟨ R∼![aP⊕bQ]∣Q ⟩
! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ right-lemma ⟩■
! name a ∙ P ∣ (! name b ∙ Q ∣ Q) [ name b ]⟵⟨ par-right (replication (par-right action)) ⟩
! name a ∙ P ∣ ! name b ∙ Q
(inj₂ ( refl , R′ , R″ , c , aP⊕bQ⟶R′ , aP⊕bQ⟶R″
, R∼![aP⊕bQ]∣R′∣R″
)) →
let b≡co-a , R′≡,R″≡ = ·⊕·-co aP⊕bQ⟶R′ aP⊕bQ⟶R″
lemma : _ → [ _ ] _ ∼ _
lemma = λ where
(inj₁ (R′≡P , R″≡Q)) →
(! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ (reflexive ∣-cong ≡⇒∼ R′≡P) ∣-cong ≡⇒∼ R″≡Q ⟩■
(! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q
(inj₂ (R′≡Q , R″≡P)) →
(! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ (reflexive ∣-cong ≡⇒∼ R′≡Q) ∣-cong ≡⇒∼ R″≡P ⟩
(! (name a ∙ P ⊕ name b ∙ Q) ∣ Q) ∣ P ∼⟨ swap-rightmost ⟩■
(! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q
in
R ∼⟨ R∼![aP⊕bQ]∣R′∣R″ ⟩
(! (name a ∙ P ⊕ name b ∙ Q) ∣ R′) ∣ R″ ∼⟨ lemma R′≡,R″≡ ⟩
(! (name a ∙ P ⊕ name b ∙ Q) ∣ P) ∣ Q ∼⟨ τ-lemma ⟩■
(! name a ∙ P ∣ P) ∣ (! name b ∙ Q ∣ Q) [ τ ]⟵⟨ par-τ′ b≡co-a (replication (par-right action))
(replication (par-right action)) ⟩
! name a ∙ P ∣ ! name b ∙ Q
rl : ∀ {S μ} →
! name a ∙ P ∣ ! name b ∙ Q [ μ ]⟶ S →
∃ λ R → ! (name a ∙ P ⊕ name b ∙ Q) [ μ ]⟶ R × [ i ] R ∼′ S
rl (par-left {P′ = S} tr) =
case 6-1-3-2 tr of λ where
(inj₁ (.P , action , S∼!aP∣P)) →
! (name a ∙ P ⊕ name b ∙ Q) [ name a ]⟶⟨ replication (par-right (sum-left action)) ⟩ʳˡ
! (name a ∙ P ⊕ name b ∙ Q) ∣ P ∼⟨ left-lemma ⟩
(! name a ∙ P ∣ P) ∣ ! name b ∙ Q ∼⟨ symmetric S∼!aP∣P ∣-cong reflexive ⟩■
S ∣ ! name b ∙ Q
(inj₂ (refl , .P , S′ , .a , action , aP⟶S′ , S∼!aP∣P∣S′)) →
⊥-elim (names-are-not-inverted aP⟶S′)
rl (par-right {Q′ = S} tr) =
case 6-1-3-2 tr of λ where
(inj₁ (.Q , action , S∼!bQ∣Q)) →
! (name a ∙ P ⊕ name b ∙ Q) [ name b ]⟶⟨ replication (par-right (sum-right action)) ⟩ʳˡ
! (name a ∙ P ⊕ name b ∙ Q) ∣ Q ∼⟨ right-lemma ⟩
! name a ∙ P ∣ (! name b ∙ Q ∣ Q) ∼⟨ reflexive ∣-cong symmetric S∼!bQ∣Q ⟩■
! name a ∙ P ∣ S
(inj₂ (refl , .Q , S′ , .b , action , bQ⟶S′ , S∼!bQ∣Q∣S′)) →
⊥-elim (names-are-not-inverted bQ⟶S′)
rl (par-τ {P′ = S} {Q′ = S′} tr₁ tr₂) =
case 6-1-3-2 tr₁ ,′ 6-1-3-2 tr₂ of λ where
(inj₁ (.P , action , S∼!aP∣P) ,
inj₁ (.Q , action , S′∼!co-aQ∣Q)) →
! (name a ∙ P ⊕ name (co a) ∙ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left action)))
(sum-right action)) ⟩ʳˡ
(! (name a ∙ P ⊕ name (co a) ∙ Q) ∣ P) ∣ Q ∼⟨ τ-lemma ⟩
(! name a ∙ P ∣ P) ∣ (! name (co a) ∙ Q ∣ Q) ∼⟨ symmetric (S∼!aP∣P ∣-cong S′∼!co-aQ∣Q) ⟩■
S ∣ S′
(inj₁ _ , inj₂ (() , _))
(inj₂ (() , _) , _)
6-2-14′ :
∀ {i a b P Q} →
[ i ] ! (name a ∙ P ⊕ name b ∙ Q) ∼′ ! name a ∙ P ∣ ! name b ∙ Q
force 6-2-14′ = 6-2-14
------------------------------------------------------------------------
-- Lemma 6.2.17
-- Some results mentioned in the proof of 6.2.17 (1) in
-- "Enhancements of the bisimulation proof method".
6-2-17-1-lemma₁ : ∀ {P Q} → (! P ∣ ! Q) ∣ (P ∣ Q) ∼ ! P ∣ ! Q
6-2-17-1-lemma₁ {P} {Q} =
(! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ swap-in-the-middle ⟩
(! P ∣ P) ∣ (! Q ∣ Q) ∼⟨ 6-1-2 ∣-cong 6-1-2 ⟩■
! P ∣ ! Q
abstract
6-2-17-1-lemma₂ :
∀ {P Q R μ} →
! (P ∣ Q) [ μ ]⟶ R →
∃ λ S →
R ∼ ! (P ∣ Q) ∣ S ×
∃ λ T →
! P ∣ ! Q [ μ ]⟶ T ×
(! P ∣ ! Q) ∣ S ∼′ T
6-2-17-1-lemma₂ {P} {Q} {R} tr = case 6-1-3-2 tr of λ where
(inj₁ (R′ , P∣Q⟶R′ , R∼![P∣Q]∣R′)) →
let R″ , !P∣!Q⟶R″ , !P∣!Q∣R′∼R″ =
left-to-right
((! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ⟩■
! P ∣ ! Q)
((! P ∣ ! Q) ∣ (P ∣ Q) ⟶⟨ par-right P∣Q⟶R′ ⟩
(! P ∣ ! Q) ∣ R′)
in _ , R∼![P∣Q]∣R′ , _ , !P∣!Q⟶R″ , !P∣!Q∣R′∼R″
(inj₂ (refl , R′ , R″ , a , P∣Q⟶R′ , P∣Q⟶R″ , R∼![P∣Q]∣R′∣R″)) →
let T , !P∣!Q⟶T , !P∣!Q∣[R′∣R″]∼T =
left-to-right
((! P ∣ ! Q) ∣ ((P ∣ Q) ∣ (P ∣ Q)) ∼⟨ ∣-assoc ⟩
((! P ∣ ! Q) ∣ (P ∣ Q)) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ∣-cong reflexive ⟩
(! P ∣ ! Q) ∣ (P ∣ Q) ∼⟨ 6-2-17-1-lemma₁ ⟩■
! P ∣ ! Q)
((! P ∣ ! Q) ∣ ((P ∣ Q) ∣ (P ∣ Q)) ⟶⟨ par-right (par-τ P∣Q⟶R′ P∣Q⟶R″) ⟩
(! P ∣ ! Q) ∣ (R′ ∣ R″))
in
_
, (R ∼⟨ R∼![P∣Q]∣R′∣R″ ⟩
(! (P ∣ Q) ∣ R′) ∣ R″ ∼⟨ symmetric ∣-assoc ⟩■
! (P ∣ Q) ∣ (R′ ∣ R″))
, _
, !P∣!Q⟶T
, !P∣!Q∣[R′∣R″]∼T
mutual
6-2-17-1 : ∀ {i P Q} → [ i ] ! (P ∣ Q) ∼ ! P ∣ ! Q
6-2-17-1 {i} {P} {Q} = ⟨ lr , rl ⟩
where
lr : ∀ {R μ} →
! (P ∣ Q) [ μ ]⟶ R →
∃ λ S → ! P ∣ ! Q [ μ ]⟶ S × [ i ] R ∼′ S
lr {R} tr =
let S , R∼![P∣Q]∣S , T , !P∣!Q⟶T , !P∣!Q∣S∼T =
6-2-17-1-lemma₂ tr in
R ∼⟨ R∼![P∣Q]∣S ⟩
! (P ∣ Q) ∣ S ∼⟨ 6-2-17-1′ ∣-cong′ reflexive ⟩
(! P ∣ ! Q) ∣ S ∼⟨ !P∣!Q∣S∼T ⟩■
T ⟵⟨ !P∣!Q⟶T ⟩
! P ∣ ! Q
lemma = λ {R S : Proc ∞} →
! (P ∣ Q) ∣ (R ∣ S) ∼⟨ 6-2-17-1′ {i = i} ∣-cong′ reflexive ⟩
(! P ∣ ! Q) ∣ (R ∣ S) ∼⟨ swap-in-the-middle ⟩■
(! P ∣ R) ∣ (! Q ∣ S)
left-lemma = λ {R : Proc ∞} →
! (P ∣ Q) ∣ (R ∣ Q) ∼⟨ lemma ⟩
(! P ∣ R) ∣ (! Q ∣ Q) ∼⟨ reflexive ∣-cong 6-1-2 ⟩■
(! P ∣ R) ∣ ! Q
right-lemma = λ {R : Proc ∞} →
! (P ∣ Q) ∣ (P ∣ R) ∼⟨ lemma ⟩
(! P ∣ P) ∣ (! Q ∣ R) ∼⟨ 6-1-2 ∣-cong reflexive ⟩■
! P ∣ (! Q ∣ R)
rl : ∀ {S μ} →
! P ∣ ! Q [ μ ]⟶ S →
∃ λ R → ! (P ∣ Q) [ μ ]⟶ R × [ i ] R ∼′ S
rl (par-left {P′ = S} !P⟶S) =
case 6-1-3-2 !P⟶S
return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _)
of λ where
(inj₁ (P′ , P⟶P′ , S∼!P∣P′)) →
! (P ∣ Q) ⟶⟨ replication (par-right (par-left P⟶P′)) ⟩ʳˡ
! (P ∣ Q) ∣ (P′ ∣ Q) ∼⟨ left-lemma ⟩
(! P ∣ P′) ∣ ! Q ∼⟨ symmetric S∼!P∣P′ ∣-cong reflexive ⟩■
S ∣ ! Q
(inj₂ (refl , P′ , P″ , a , P⟶P′ , P⟶P″ , S∼!P∣P′∣P″)) →
! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-left P⟶P′)))
(par-left P⟶P″)) ⟩ʳˡ
(! (P ∣ Q) ∣ (P′ ∣ Q)) ∣ (P″ ∣ Q) ∼⟨ left-lemma ∣-cong′ reflexive ⟩
((! P ∣ P′) ∣ ! Q) ∣ (P″ ∣ Q) ∼⟨ swap-in-the-middle ⟩
((! P ∣ P′) ∣ P″) ∣ (! Q ∣ Q) ∼⟨ reflexive ∣-cong 6-1-2 ⟩
((! P ∣ P′) ∣ P″) ∣ ! Q ∼⟨ symmetric S∼!P∣P′∣P″ ∣-cong reflexive ⟩■
S ∣ ! Q
rl (par-right {Q′ = S} !Q⟶S) =
case 6-1-3-2 !Q⟶S
return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _)
of λ where
(inj₁ (Q′ , Q⟶Q′ , S∼!Q∣Q′)) →
! (P ∣ Q) ⟶⟨ replication (par-right (par-right Q⟶Q′)) ⟩ʳˡ
! (P ∣ Q) ∣ (P ∣ Q′) ∼⟨ right-lemma ⟩
! P ∣ (! Q ∣ Q′) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′ ⟩■
! P ∣ S
(inj₂ (refl , Q′ , Q″ , a , Q⟶Q′ , Q⟶Q″ , S∼!Q∣Q′∣Q″)) →
! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-right Q⟶Q′)))
(par-right Q⟶Q″)) ⟩ʳˡ
(! (P ∣ Q) ∣ (P ∣ Q′)) ∣ (P ∣ Q″) ∼⟨ right-lemma ∣-cong′ reflexive ⟩
(! P ∣ (! Q ∣ Q′)) ∣ (P ∣ Q″) ∼⟨ swap-in-the-middle ⟩
(! P ∣ P) ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ 6-1-2 ∣-cong reflexive ⟩
! P ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′∣Q″ ⟩■
! P ∣ S
rl (par-τ {P′ = S} {Q′ = S′} !P⟶S !Q⟶S′) =
case 6-1-3-2 !P⟶S ,′ 6-1-3-2 !Q⟶S′ of λ where
(inj₁ (P′ , P⟶P′ , S∼!P∣P′) ,
inj₁ (Q′ , Q⟶Q′ , S′∼!Q∣Q′)) →
! (P ∣ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (par-left P⟶P′)))
(par-right Q⟶Q′)) ⟩ʳˡ
(! (P ∣ Q) ∣ (P′ ∣ Q)) ∣ (P ∣ Q′) ∼⟨ left-lemma ∣-cong′ reflexive ⟩
((! P ∣ P′) ∣ ! Q) ∣ (P ∣ Q′) ∼⟨ swap-in-the-middle ⟩
((! P ∣ P′) ∣ P) ∣ (! Q ∣ Q′) ∼⟨ swap-rightmost ∣-cong reflexive ⟩
((! P ∣ P) ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ (6-1-2 ∣-cong reflexive) ∣-cong reflexive ⟩
(! P ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ symmetric (S∼!P∣P′ ∣-cong S′∼!Q∣Q′) ⟩■
S ∣ S′
(inj₁ _ , inj₂ (() , _))
(inj₂ (() , _) , _)
6-2-17-1′ : ∀ {i P Q} → [ i ] ! (P ∣ Q) ∼′ ! P ∣ ! Q
force 6-2-17-1′ = 6-2-17-1
mutual
6-2-17-2 : ∀ {i P Q} → [ i ] ! (P ⊕ Q) ∼ ! P ∣ ! Q
6-2-17-2 {i} {P} {Q} = ⟨ lr , rl ⟩
where
left-lemma = λ {R : Proc ∞} →
! (P ⊕ Q) ∣ R ∼⟨ 6-2-17-2′ {i = i} ∣-cong′ reflexive ⟩
(! P ∣ ! Q) ∣ R ∼⟨ swap-rightmost ⟩■
(! P ∣ R) ∣ ! Q
right-lemma = λ {R : Proc ∞} →
! (P ⊕ Q) ∣ R ∼⟨ 6-2-17-2′ {i = i} ∣-cong′ reflexive ⟩
(! P ∣ ! Q) ∣ R ∼⟨ symmetric ∣-assoc ⟩■
! P ∣ (! Q ∣ R)
τ-lemma₁ = λ {P′ P″ : Proc ∞} →
(! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ left-lemma ∣-cong′ reflexive ⟩
((! P ∣ P′) ∣ ! Q) ∣ P″ ∼⟨ swap-rightmost ⟩■
((! P ∣ P′) ∣ P″) ∣ ! Q
τ-lemma₂ = λ {P′ Q′ : Proc ∞} →
(! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ left-lemma ∣-cong′ reflexive ⟩
((! P ∣ P′) ∣ ! Q) ∣ Q′ ∼⟨ symmetric ∣-assoc ⟩■
(! P ∣ P′) ∣ (! Q ∣ Q′)
τ-lemma₃ = λ {Q′ Q″ : Proc ∞} →
(! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ right-lemma ∣-cong′ reflexive ⟩
(! P ∣ (! Q ∣ Q′)) ∣ Q″ ∼⟨ symmetric ∣-assoc ⟩■
! P ∣ ((! Q ∣ Q′) ∣ Q″)
lr : ∀ {R μ} →
! (P ⊕ Q) [ μ ]⟶ R →
∃ λ S → ! P ∣ ! Q [ μ ]⟶ S × [ i ] R ∼′ S
lr {R} tr =
case 6-1-3-2 tr
return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _)
of λ where
(inj₁ (P′ , sum-left P⟶P′ , R∼![P⊕Q]∣P′)) →
R ∼⟨ R∼![P⊕Q]∣P′ ⟩
! (P ⊕ Q) ∣ P′ ∼⟨ left-lemma ⟩■
(! P ∣ P′) ∣ ! Q ⟵⟨ par-left (replication (par-right P⟶P′)) ⟩
! P ∣ ! Q
(inj₁ (Q′ , sum-right Q⟶Q′ , R∼![P⊕Q]∣Q′)) →
R ∼⟨ R∼![P⊕Q]∣Q′ ⟩
! (P ⊕ Q) ∣ Q′ ∼⟨ right-lemma ⟩■
! P ∣ (! Q ∣ Q′) ⟵⟨ par-right (replication (par-right Q⟶Q′)) ⟩
! P ∣ ! Q
(inj₂ ( refl , P′ , P″ , c
, sum-left P⟶P′ , sum-left P⟶P″
, R∼![P⊕Q]∣P′∣P″
)) →
R ∼⟨ R∼![P⊕Q]∣P′∣P″ ⟩
(! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ τ-lemma₁ ⟩■
((! P ∣ P′) ∣ P″) ∣ ! Q [ τ ]⟵⟨ par-left (replication (par-τ (replication (par-right P⟶P′)) P⟶P″)) ⟩
! P ∣ ! Q
(inj₂ ( refl , P′ , Q′ , c
, sum-left P⟶P′ , sum-right Q⟶Q′
, R∼![P⊕Q]∣P′∣Q′
)) →
R ∼⟨ R∼![P⊕Q]∣P′∣Q′ ⟩
(! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ τ-lemma₂ ⟩■
(! P ∣ P′) ∣ (! Q ∣ Q′) [ τ ]⟵⟨ par-τ (replication (par-right P⟶P′))
(replication (par-right Q⟶Q′)) ⟩
! P ∣ ! Q
(inj₂ ( refl , Q′ , P′ , c
, sum-right Q⟶Q′ , sum-left P⟶P′
, R∼![P⊕Q]∣Q′∣P′
)) →
R ∼⟨ R∼![P⊕Q]∣Q′∣P′ ⟩
(! (P ⊕ Q) ∣ Q′) ∣ P′ ∼⟨ right-lemma ∣-cong′ reflexive ⟩
(! P ∣ (! Q ∣ Q′)) ∣ P′ ∼⟨ swap-rightmost ⟩■
(! P ∣ P′) ∣ (! Q ∣ Q′) [ τ ]⟵⟨ par-τ′ (sym $ co-involutive c)
(replication (par-right P⟶P′))
(replication (par-right Q⟶Q′)) ⟩
! P ∣ ! Q
(inj₂ ( refl , Q′ , Q″ , c
, sum-right Q⟶Q′ , sum-right Q⟶Q″
, R∼![P⊕Q]∣Q′∣Q″
)) →
R ∼⟨ R∼![P⊕Q]∣Q′∣Q″ ⟩
(! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ τ-lemma₃ ⟩■
! P ∣ ((! Q ∣ Q′) ∣ Q″) [ τ ]⟵⟨ par-right (replication (par-τ (replication (par-right Q⟶Q′)) Q⟶Q″)) ⟩
! P ∣ ! Q
rl : ∀ {S μ} →
! P ∣ ! Q [ μ ]⟶ S →
∃ λ R → ! (P ⊕ Q) [ μ ]⟶ R × [ i ] R ∼′ S
rl (par-left {P′ = S} !P⟶S) =
case 6-1-3-2 !P⟶S
return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _)
of λ where
(inj₁ (P′ , P⟶P′ , S∼!P∣P′)) →
! (P ⊕ Q) ⟶⟨ replication (par-right (sum-left P⟶P′)) ⟩ʳˡ
! (P ⊕ Q) ∣ P′ ∼⟨ left-lemma ⟩
(! P ∣ P′) ∣ ! Q ∼⟨ symmetric S∼!P∣P′ ∣-cong reflexive ⟩■
S ∣ ! Q
(inj₂ (refl , P′ , P″ , a , P⟶P′ , P⟶P″ , S∼!P∣P′∣P″)) →
! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left P⟶P′)))
(sum-left P⟶P″)) ⟩ʳˡ
(! (P ⊕ Q) ∣ P′) ∣ P″ ∼⟨ τ-lemma₁ ⟩
((! P ∣ P′) ∣ P″) ∣ ! Q ∼⟨ symmetric S∼!P∣P′∣P″ ∣-cong reflexive ⟩■
S ∣ ! Q
rl (par-right {Q′ = S} !Q⟶S) =
case 6-1-3-2 !Q⟶S
return (const $ ∃ λ _ → _ × [ i ] _ ∼′ _)
of λ where
(inj₁ (Q′ , Q⟶Q′ , S∼!Q∣Q′)) →
! (P ⊕ Q) ⟶⟨ replication (par-right (sum-right Q⟶Q′)) ⟩ʳˡ
! (P ⊕ Q) ∣ Q′ ∼⟨ right-lemma ⟩
! P ∣ (! Q ∣ Q′) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′ ⟩■
! P ∣ S
(inj₂ (refl , Q′ , Q″ , a , Q⟶Q′ , Q⟶Q″ , S∼!Q∣Q′∣Q″)) →
! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-right Q⟶Q′)))
(sum-right Q⟶Q″)) ⟩ʳˡ
(! (P ⊕ Q) ∣ Q′) ∣ Q″ ∼⟨ τ-lemma₃ ⟩
! P ∣ ((! Q ∣ Q′) ∣ Q″) ∼⟨ reflexive ∣-cong symmetric S∼!Q∣Q′∣Q″ ⟩■
! P ∣ S
rl (par-τ {P′ = S} {Q′ = S′} !P⟶S !Q⟶S′) =
case 6-1-3-2 !P⟶S ,′ 6-1-3-2 !Q⟶S′ of λ where
(inj₁ (P′ , P⟶P′ , S∼!P∣P′) ,
inj₁ (Q′ , Q⟶Q′ , S′∼!Q∣Q′)) →
! (P ⊕ Q) [ τ ]⟶⟨ replication (par-τ (replication (par-right (sum-left P⟶P′)))
(sum-right Q⟶Q′)) ⟩ʳˡ
(! (P ⊕ Q) ∣ P′) ∣ Q′ ∼⟨ τ-lemma₂ ⟩
(! P ∣ P′) ∣ (! Q ∣ Q′) ∼⟨ symmetric (S∼!P∣P′ ∣-cong S′∼!Q∣Q′) ⟩■
S ∣ S′
(inj₁ _ , inj₂ (() , _))
(inj₂ (() , _) , _)
6-2-17-2′ : ∀ {i P Q} → [ i ] ! (P ⊕ Q) ∼′ ! P ∣ ! Q
force 6-2-17-2′ = 6-2-17-2
6-2-17-3 : ∀ {P} → ! P ∣ ! P ∼ ! P
6-2-17-3 {P} =
! P ∣ ! P ∼⟨ symmetric 6-2-17-2 ⟩
! (P ⊕ P) ∼⟨ !-cong ⊕-idempotent ⟩■
! P
-- A result mentioned in the proof of 6.2.17 (4) in "Enhancements of
-- the bisimulation proof method".
6-2-17-4-lemma : ∀ {P Q μ} → ! P [ μ ]⟶ Q → Q ∼ ! P ∣ Q
6-2-17-4-lemma {P} {Q} !P⟶Q = case 6-1-3-2 !P⟶Q of λ where
(inj₁ (P′ , P⟶P′ , Q∼!P∣P′)) →
Q ∼⟨ Q∼!P∣P′ ⟩
! P ∣ P′ ∼⟨ symmetric 6-2-17-3 ∣-cong reflexive ⟩
(! P ∣ ! P) ∣ P′ ∼⟨ symmetric ∣-assoc ⟩
! P ∣ (! P ∣ P′) ∼⟨ reflexive ∣-cong symmetric Q∼!P∣P′ ⟩■
! P ∣ Q
(inj₂ (_ , P′ , P″ , _ , P⟶P′ , P⟶P″ , Q∼!P∣P′∣P″)) →
Q ∼⟨ Q∼!P∣P′∣P″ ⟩
(! P ∣ P′) ∣ P″ ∼⟨ symmetric ∣-assoc ⟩
! P ∣ (P′ ∣ P″) ∼⟨ symmetric 6-2-17-3 ∣-cong reflexive ⟩
(! P ∣ ! P) ∣ (P′ ∣ P″) ∼⟨ symmetric ∣-assoc ⟩
! P ∣ (! P ∣ (P′ ∣ P″)) ∼⟨ reflexive ∣-cong ∣-assoc ⟩
! P ∣ ((! P ∣ P′) ∣ P″) ∼⟨ reflexive ∣-cong symmetric Q∼!P∣P′∣P″ ⟩■
! P ∣ Q
mutual
6-2-17-4 : ∀ {P i} → [ i ] ! ! P ∼ ! P
6-2-17-4 {P} {i} = ⟨ lr , rl ⟩
where
lemma = λ {Q μ} (!P⟶Q : ! P [ μ ]⟶ Q) →
! ! P ∣ Q ∼⟨ 6-2-17-4′ {i = i} ∣-cong′ reflexive ⟩
! P ∣ Q ∼⟨ symmetric (6-2-17-4-lemma !P⟶Q) ⟩■
Q
lr : ∀ {Q μ} →
! ! P [ μ ]⟶ Q →
∃ λ Q′ → ! P [ μ ]⟶ Q′ × [ i ] Q ∼′ Q′
lr {Q} !!P⟶Q = case 6-1-3-2 !!P⟶Q of λ where
(inj₁ (Q′ , !P⟶Q′ , Q∼!!P∣Q′)) →
_
, !P⟶Q′
, (Q ∼⟨ Q∼!!P∣Q′ ⟩
! ! P ∣ Q′ ∼⟨ lemma !P⟶Q′ ⟩■
Q′)
(inj₂ (refl , Q′ , Q″ , a , !P⟶Q′ , !P⟶Q″ , Q∼!!P∣Q′∣Q″)) →
case 6-1-3-2 !P⟶Q″ of λ where
(inj₂ (() , _))
(inj₁ (Q‴ , P⟶Q‴ , Q″∼!P∣Q‴)) →
let !P⟶Q′∣Q″ =
! P [ τ ]⟶⟨ replication (par-τ !P⟶Q′ P⟶Q‴) ⟩
Q′ ∣ Q‴
in
Q ∼⟨ Q∼!!P∣Q′∣Q″ ⟩
(! ! P ∣ Q′) ∣ Q″ ∼⟨ reflexive ∣-cong Q″∼!P∣Q‴ ⟩
(! ! P ∣ Q′) ∣ (! P ∣ Q‴) ∼⟨ swap-in-the-middle ⟩
(! ! P ∣ ! P) ∣ (Q′ ∣ Q‴) ∼⟨ 6-1-2 ∣-cong reflexive ⟩
! ! P ∣ (Q′ ∣ Q‴) ∼⟨ lemma !P⟶Q′∣Q″ ⟩■
Q′ ∣ Q‴ [ τ ]⟵⟨ !P⟶Q′∣Q″ ⟩
! P
rl : ∀ {Q μ} →
! P [ μ ]⟶ Q →
∃ λ Q′ → ! ! P [ μ ]⟶ Q′ × [ i ] Q′ ∼′ Q
rl {Q} !P⟶Q =
! ! P ⟶⟨ replication (par-right !P⟶Q) ⟩ʳˡ
! ! P ∣ Q ∼⟨ lemma !P⟶Q ⟩■
Q
6-2-17-4′ : ∀ {P i} → [ i ] ! ! P ∼′ ! P
force 6-2-17-4′ = 6-2-17-4
------------------------------------------------------------------------
-- An example from "Coinduction All the Way Up" by Pous
module _ (a b : Name-with-kind) where
A B C D : ∀ {i} → Proc i
A = name a ∙ name b ∙ D
B = name a ∙ name b ∙ C
C = name (co a) · λ { .force → A ∣ C }
D = name (co a) · λ { .force → B ∣ D }
mutual
A∼B : ∀ {i} → [ i ] A ∼ B
A∼B = refl ∙-cong (refl ∙-cong symmetric C∼D)
C∼D : ∀ {i} → [ i ] C ∼ D
C∼D = refl ·-cong λ { .force → A∼B ∣-cong C∼D }
------------------------------------------------------------------------
-- Another example (not taken from Pous and Sangiorgi)
Restricted : Name → Proc ∞
Restricted a = ⟨ν a ⟩ (name (a , true) · λ { .force → ∅ })
Restricted∼∅ : ∀ {a} → Restricted a ∼ ∅
Restricted∼∅ =
⟨ (λ { (restriction x≢x action) → ⊥-elim (x≢x refl) })
, (λ ())
⟩
|
{
"alphanum_fraction": 0.3288268484,
"avg_line_length": 38.1734265734,
"ext": "agda",
"hexsha": "d59c19550eaecec3240b6196a3139f5759f81c46",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/CCS/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/CCS/Examples.agda",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/CCS/Examples.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13493,
"size": 27294
}
|
{-# OPTIONS --verbose tc.constr.findInScope:15 #-}
module InstanceArguments.03-classes where
open import Algebra
open import Algebra.Structures
open import Algebra.FunctionProperties
open import Data.Nat.Properties as NatProps
open import Data.Nat
open import Data.Bool.Properties using (isCommutativeSemiring-∧-∨)
open import Data.Product using (proj₁)
open import Relation.Binary.PropositionalEquality
open import Relation.Binary
open import Level renaming (zero to lzero; suc to lsuc)
open CommutativeSemiring NatProps.commutativeSemiring using (semiring)
open IsCommutativeSemiring isCommutativeSemiring using (isSemiring)
open IsCommutativeSemiring isCommutativeSemiring-∧-∨ using () renaming (isSemiring to Bool-isSemiring)
record S (A : Set) : Set₁ where
field
z : A
o : A
_≈_ : Rel A lzero
_⟨+⟩_ : Op₂ A
_⟨*⟩_ : Op₂ A
instance isSemiring' : IsSemiring _≈_ _⟨+⟩_ _⟨*⟩_ z o
instance
ℕ-S : S ℕ
ℕ-S = record { z = 0; o = 1;
_≈_ = _≡_; _⟨+⟩_ = _+_; _⟨*⟩_ = _*_;
isSemiring' = isSemiring }
zero' : {A : Set} → {{aRing : S A}} → A
zero' {{ARing}} = S.z ARing
zero-nat : ℕ
zero-nat = zero'
isZero : {A : Set} {{r : S A}} (let open S r) →
Zero _≈_ z _⟨*⟩_
isZero {{r}} = IsSemiring.zero (S.isSemiring' r)
useIsZero : 0 * 5 ≡ 0
useIsZero = proj₁ isZero 5
|
{
"alphanum_fraction": 0.6758982036,
"avg_line_length": 27.8333333333,
"ext": "agda",
"hexsha": "5a4095fd9bfa3676f3aff315e7f5104750b436bd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/LibSucceed/InstanceArguments/03-classes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/LibSucceed/InstanceArguments/03-classes.agda",
"max_line_length": 102,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/LibSucceed/InstanceArguments/03-classes.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 456,
"size": 1336
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Yoneda where
open import Level
open import Data.Product
open import Categories.Support.Equivalence
open import Categories.Support.EqReasoning
open import Categories.Category
import Categories.Functor as Cat
open import Categories.Functor using (Functor; module Functor)
open import Categories.Functor.Hom
import Categories.Morphisms as Mor
open import Categories.NaturalTransformation using (NaturalTransformation; module NaturalTransformation)
open import Categories.NaturalIsomorphism
open import Categories.Product
open import Categories.FunctorCategory
open import Categories.Presheaves
open import Categories.Agda
Embed : ∀ {o ℓ e} → (C : Category o ℓ e) → Functor C (Presheaves C)
Embed C = record
{ F₀ = λ x → Hom[ C ][-, x ]
; F₁ = λ f → record
{ η = λ X → record
{ _⟨$⟩_ = λ g → f ∘ g
; cong = λ x → ∘-resp-≡ʳ x
}
; commute = commute′ f
}
; identity = λ x≡y → trans identityˡ x≡y
; homomorphism = λ x≡y → trans (∘-resp-≡ʳ x≡y) assoc
; F-resp-≡ = λ f≡g h≡i → ∘-resp-≡ f≡g h≡i
}
where
open Category C
open Equiv
.commute′ : {A B X Y : Obj} (f : A ⇒ B) (g : Y ⇒ X) {x y : X ⇒ A} → x ≡ y → f ∘ id ∘ x ∘ g ≡ id ∘ (f ∘ y) ∘ g
commute′ f g {x} {y} x≡y =
begin
f ∘ id ∘ x ∘ g
↑⟨ assoc ⟩
(f ∘ id) ∘ x ∘ g
≈⟨ ∘-resp-≡ˡ id-comm ⟩
(id ∘ f) ∘ x ∘ g
≈⟨ ∘-resp-≡ʳ (∘-resp-≡ˡ x≡y) ⟩
(id ∘ f) ∘ y ∘ g
≈⟨ assoc ⟩
id ∘ f ∘ y ∘ g
↑⟨ ∘-resp-≡ʳ assoc ⟩
id ∘ (f ∘ y) ∘ g
∎
where open HomReasoning
module Embed {o ℓ e} C = Functor (Embed {o} {ℓ} {e} C)
Nat[Embed[_][c],F] : ∀ {o ℓ e} → (C : Category o ℓ e) -> Functor (Product (Presheaves C) (Category.op C)) (ISetoids _ _)
Nat[Embed[ C ][c],F] = Hom[ Presheaves C ][-,-] Cat.∘ ((Embed.op C Cat.∘ snd) ※ fst)
where
fst = πˡ {C = Presheaves C} {D = Category.op C}
snd = πʳ {C = Presheaves C} {D = Category.op C}
F[c∈_] : ∀ {o ℓ e} → (C : Category o ℓ e) -> Functor (Product (Presheaves C) (Category.op C)) (ISetoids _ _)
F[c∈_] {o} {ℓ} {e} C = Lift-IS (suc e ⊔ suc ℓ ⊔ o) (o ⊔ ℓ) Cat.∘ eval {C = Category.op C} {D = ISetoids ℓ e}
yoneda : ∀ {o ℓ e} → (C : Category o ℓ e) -> NaturalIsomorphism Nat[Embed[ C ][c],F] F[c∈ C ]
yoneda C = record { F⇒G = F⇒G; F⇐G = F⇐G; iso = iso }
where
open NaturalTransformation
open Categories.Functor.Functor
open import Categories.Support.SetoidFunctions
module C = Category C
open C.Equiv
module M = Mor (ISetoids _ _)
F⇒G : NaturalTransformation Nat[Embed[ C ][c],F] F[c∈ C ]
F⇒G = record {
η = λ {(F , c) →
record { _⟨$⟩_ = λ ε → lift (η ε c ⟨$⟩ C.id);
cong = λ x → lift (x refl) }};
commute = λ { {F , c₁} {G , c₂} (ε , f) {φ} {ψ} φ≡ψ → lift
(let module s = Setoid (F₀ G c₂)
module sr = SetoidReasoning (F₀ G c₂)
module t = Setoid (F₀ F c₂)
module tr = SetoidReasoning (F₀ F c₂)
in s.sym (sr.begin
F₁ G f ⟨$⟩ (η ε c₁ ⟨$⟩ (η ψ c₁ ⟨$⟩ C.id))
sr.↑⟨ commute ε f (Setoid.refl (F₀ F c₁)) ⟩
η ε c₂ ⟨$⟩ (F₁ F f ⟨$⟩ (η ψ c₁ ⟨$⟩ C.id))
sr.↓⟨ cong (η ε c₂) (tr.begin
F₁ F f ⟨$⟩ (η ψ c₁ ⟨$⟩ C.id)
tr.↑⟨ commute ψ f (refl {x = C.id}) ⟩
η ψ c₂ ⟨$⟩ C.id C.∘ C.id C.∘ f
tr.↑⟨ φ≡ψ (trans C.identityʳ (trans (sym C.identityˡ) (sym C.identityˡ))) ⟩
η φ c₂ ⟨$⟩ f C.∘ C.id
tr.∎) ⟩
η ε c₂ ⟨$⟩ (η φ c₂ ⟨$⟩ f C.∘ C.id) sr.∎ )) }}
F⇐G : NaturalTransformation F[c∈ C ] Nat[Embed[ C ][c],F]
F⇐G = record {
η = λ {(F , c) →
record { _⟨$⟩_ = λ Fc →
record { η = λ X →
record { _⟨$⟩_ = λ f → F₁ F f ⟨$⟩ lower Fc;
cong = λ eq → F-resp-≡ F eq (Setoid.refl (F₀ F c)) };
commute = λ {X} {Y} h {f} {g} f≡g →
let module s = Setoid (F₀ F Y)
module sr = SetoidReasoning (F₀ F Y)
in sr.begin
F₁ F (C.id C.∘ f C.∘ h) ⟨$⟩ lower Fc
sr.↓⟨ F-resp-≡ F (trans C.identityˡ (C.∘-resp-≡ˡ f≡g)) (Setoid.refl (F₀ F c)) ⟩
F₁ F (g C.∘ h) ⟨$⟩ lower Fc
sr.↓⟨ homomorphism F (Setoid.refl (F₀ F c)) ⟩
F₁ F h ⟨$⟩ (F₁ F g ⟨$⟩ lower Fc)
sr.∎ };
cong = λ i≡j {X} {f} {g} f≡g → F-resp-≡ F f≡g (lower i≡j) }};
commute = λ { {F , c₁} {G , c₂} (ε , e) {lift i} {lift j} i≡j {X} {f} {g} f≡g →
let module s = Setoid (F₀ G X)
module sr = SetoidReasoning (F₀ G X)
in sr.begin
F₁ G f ⟨$⟩ (F₁ G e ⟨$⟩ (η ε c₁ ⟨$⟩ i))
sr.↑⟨ homomorphism G {f = e} {g = f} (Setoid.refl (F₀ G c₁)) ⟩
F₁ G (e C.∘ f) ⟨$⟩ (η ε c₁ ⟨$⟩ i)
sr.↑⟨ commute ε (e C.∘ f) (Setoid.refl (F₀ F c₁)) ⟩
η ε X ⟨$⟩ (F₁ F (e C.∘ f) ⟨$⟩ i)
sr.↓⟨ cong (η ε X) (F-resp-≡ F (C.∘-resp-≡ʳ f≡g) (lower i≡j)) ⟩
η ε X ⟨$⟩ (F₁ F (e C.∘ g) ⟨$⟩ j)
sr.∎}}
module F⇐G = NaturalTransformation F⇐G
module F⇒G = NaturalTransformation F⇒G
iso : (X : Category.Obj (Product (Presheaves C) C.op)) → M.Iso (F⇒G.η X) (F⇐G.η X)
iso (F , c) = record {
isoˡ = λ { {ε₁} {ε₂} ε₁≡ε₂ {X} {f} {g} f≡g →
let module s = Setoid (F₀ F X)
open SetoidReasoning (F₀ F X)
in begin
F₁ F f ⟨$⟩ (η ε₁ c ⟨$⟩ C.id)
↑⟨ commute ε₁ f {C.id} {C.id} refl ⟩
η ε₁ X ⟨$⟩ C.id C.∘ C.id C.∘ f
↓⟨ ε₁≡ε₂ (trans C.identityˡ (trans C.identityˡ f≡g)) ⟩
η ε₂ X ⟨$⟩ g
∎ };
isoʳ = λ eq → lift (identity F (lower eq)) }
yoneda-iso : ∀ {o ℓ e} → (C : Category o ℓ e) (c d : Category.Obj C) ->
let open Mor (ISetoids _ _) in
Functor.F₀ Hom[ Presheaves C ][ Embed.F₀ C c ,-] (Embed.F₀ C d)
≅ Functor.F₀ (Lift-IS (suc e ⊔ suc ℓ ⊔ o) (o ⊔ ℓ)) (Functor.F₀ (Embed.F₀ C d) c)
yoneda-iso C c d = record { f = ⇒.η X; g = ⇐.η X;
iso = iso X }
where
open NaturalIsomorphism (yoneda C)
module iso F,c = Mor.Iso (iso F,c)
X = ((Embed.F₀ C d) , c)
yoneda-inj : ∀ {o ℓ e} → (C : Category o ℓ e) (c d : Category.Obj C) -> NaturalIsomorphism (Embed.F₀ C c) (Embed.F₀ C d)
-> Mor._≅_ C c d
yoneda-inj C c d ηiso = record { f = ⇒.η c ⟨$⟩ C.id; g = ⇐.η d ⟨$⟩ C.id;
iso = record { isoˡ = Lemma.lemma c d ηiso;
isoʳ = Lemma.lemma d c (IsEquivalence.sym Categories.NaturalIsomorphism.equiv ηiso)
} }
where
open import Categories.Support.SetoidFunctions
open import Relation.Binary
module C = Category C
open C.HomReasoning
module Lemma (c d : C.Obj) (ηiso : NaturalIsomorphism (Embed.F₀ C c) (Embed.F₀ C d)) where
open NaturalIsomorphism ηiso
module iso c = Mor.Iso (iso c)
.lemma : (⇐.η d ⟨$⟩ C.id) C.∘ (⇒.η c ⟨$⟩ C.id) C.≡ C.id
lemma = begin
(⇐.η d ⟨$⟩ C.id) C.∘ (⇒.η c ⟨$⟩ C.id)
↑⟨ C.identityˡ ⟩
C.id C.∘ (⇐.η d ⟨$⟩ C.id) C.∘ (⇒.η c ⟨$⟩ C.id)
↑⟨ ⇐.commute (⇒.η c ⟨$⟩ C.id) {C.id} C.Equiv.refl ⟩
⇐.η c ⟨$⟩ C.id C.∘ C.id C.∘ (⇒.η c ⟨$⟩ C.id)
↓⟨ cong (⇐.η c) (C.Equiv.trans C.identityˡ C.identityˡ) ⟩
⇐.η c ⟨$⟩ (⇒.η c ⟨$⟩ C.id)
↓⟨ iso.isoˡ c C.Equiv.refl ⟩
C.id
∎
open NaturalIsomorphism ηiso
|
{
"alphanum_fraction": 0.4745895231,
"avg_line_length": 40.6031746032,
"ext": "agda",
"hexsha": "cf44ad0f0f7e0399f0f7823cada4b33c9a3d2b21",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Yoneda.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Yoneda.agda",
"max_line_length": 120,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Yoneda.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 3104,
"size": 7674
}
|
module Common where
open import Data.String
using (String)
-- Basic sorts -----------------------------------------------------------------
Id : Set
Id = String
|
{
"alphanum_fraction": 0.4176470588,
"avg_line_length": 15.4545454545,
"ext": "agda",
"hexsha": "712407e24a6d8162f6bf50c8d9db1e05b609decd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "d-plaindoux/colca",
"max_forks_repo_path": "src/Common.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "d-plaindoux/colca",
"max_issues_repo_path": "src/Common.agda",
"max_line_length": 80,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "d-plaindoux/colca",
"max_stars_repo_path": "src/Common.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-04T09:35:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-03-12T18:31:14.000Z",
"num_tokens": 27,
"size": 170
}
|
{-# OPTIONS --cubical #-}
module Multidimensional.Data.DirNum where
open import Multidimensional.Data.DirNum.Base public
open import Multidimensional.Data.DirNum.Properties public
|
{
"alphanum_fraction": 0.8186813187,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "26fe6122e3e656b9188d00984cfc22601dcc0758",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_forks_repo_path": "Multidimensional/Data/DirNum.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_issues_repo_issues_event_max_datetime": "2019-07-02T16:24:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-19T20:40:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_issues_repo_path": "Multidimensional/Data/DirNum.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_stars_repo_path": "Multidimensional/Data/DirNum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 38,
"size": 182
}
|
module Data.List.Equiv.Id where
import Lvl
open import Functional
open import Function.Names as Names using (_⊜_)
import Function.Equals as Fn
open import Data.Boolean
open import Data.Option
open import Data.Option.Equiv.Id
open import Data.Option.Proofs using ()
open import Data.List
open import Data.List.Equiv
open import Data.List.Functions
open import Logic
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Relator.Equals
open import Structure.Function
open import Structure.Function.Domain
import Structure.Function.Names as Names
open import Structure.Operator.Properties
open import Structure.Operator
open import Structure.Relator.Properties
open import Structure.Setoid using (Equiv) renaming (_≡_ to _≡ₛ_)
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₑ ℓₑₗ ℓₑₒ ℓₑ₁ ℓₑ₂ ℓₑₗ₁ ℓₑₗ₂ : Lvl.Level
private variable T A B : Type{ℓ}
private variable n : ℕ
open import Relator.Equals
open import Relator.Equals.Proofs
private variable l l₁ l₂ : List(T)
private variable a b x : T
private variable f : A → B
private variable P : List(T) → Stmt{ℓ}
[⊰]-general-cancellation : ((a ⊰ l₁) ≡ (b ⊰ l₂)) → (a ≡ b) ∧ (l₁ ≡ l₂)
[⊰]-general-cancellation p = [∧]-intro (L p) (R p) where
R : ((a ⊰ l₁) ≡ (b ⊰ l₂)) → (l₁ ≡ l₂)
R p = congruence₁(tail) p
L : ((a ⊰ l₁) ≡ (b ⊰ l₂)) → (a ≡ b)
L {l₁ = ∅} {l₂ = ∅} [≡]-intro = [≡]-intro
L {l₁ = ∅} {l₂ = _ ⊰ _} p with () ← R p
L {l₁ = _ ⊰ _} {l₂ = _ ⊰ _} p = injective(Some) (congruence₁(first) p)
instance
List-Id-extensionality : Extensionality([≡]-equiv {T = List(T)})
Extensionality.generalized-cancellationᵣ List-Id-extensionality = [∧]-elimₗ ∘ [⊰]-general-cancellation
Extensionality.generalized-cancellationₗ List-Id-extensionality = [∧]-elimᵣ ∘ [⊰]-general-cancellation
Extensionality.case-unequality List-Id-extensionality ()
open import Data.List.Proofs
initial-0-length : (initial(0)(l) ≡ ∅)
initial-0-length {l = ∅} = reflexivity(_≡_)
initial-0-length {l = x ⊰ l} = reflexivity(_≡_)
{-# REWRITE initial-0-length #-}
multiply-singleton-repeat : (singleton(l) ++^ n ≡ repeat(l)(n))
multiply-singleton-repeat {l = l} {n = 𝟎} = reflexivity(_≡_)
multiply-singleton-repeat {l = l} {n = 𝐒 n} = congruence₁(l ⊰_) (multiply-singleton-repeat {l = l} {n = n})
module _ {f g : A → B} where
map-function-raw : (f ⊜ g) → (map f ⊜ map g)
map-function-raw p {∅} = reflexivity(_≡_)
map-function-raw p {x ⊰ l} rewrite p{x} = congruence₁(g(x) ⊰_) (map-function-raw p {l})
module _ {f g : A → List(B)} where
concatMap-function-raw : (f ⊜ g) → (concatMap f ⊜ concatMap g)
concatMap-function-raw p {∅} = reflexivity(_≡_)
concatMap-function-raw p {x ⊰ l} rewrite p{x} = congruence₁(g(x) ++_) (concatMap-function-raw p {l})
module _ {ℓ₁ ℓ₂ ℓ₃} {A : Type{ℓ₁}} {B : Type{ℓ₂}} {C : Type{ℓ₃}} {f : B → C}{g : A → B} where
map-preserves-[∘] : (map(f ∘ g) ⊜ (map f ∘ map g))
map-preserves-[∘] {x = ∅} = reflexivity(_≡_)
map-preserves-[∘] {x = x ⊰ l} = congruence₁(f(g(x)) ⊰_) (map-preserves-[∘] {x = l})
map-preserves-id : (map id ⊜ id{T = List(T)})
map-preserves-id {x = ∅} = reflexivity(_≡_)
map-preserves-id {x = x ⊰ l} = congruence₁(x ⊰_) (map-preserves-id {x = l})
{-# REWRITE map-preserves-id #-}
concatMap-[++] : (concatMap f (l₁ ++ l₂) ≡ (concatMap f l₁ ++ concatMap f l₂))
concatMap-[++] {f = f} {∅} {l₂} = reflexivity(_≡_)
concatMap-[++] {f = f} {x ⊰ l₁} {l₂} =
(f(x) ++ concatMap f (l₁ ++ l₂)) 🝖-[ congruence₁(f(x) ++_) (concatMap-[++] {f = f} {l₁} {l₂}) ]
(f(x) ++ (concatMap f l₁ ++ concatMap f l₂)) 🝖-[ associativity(_++_) {x = f(x)}{y = concatMap f l₁}{z = concatMap f l₂} ]-sym
(f(x) ++ concatMap f l₁ ++ concatMap f l₂) 🝖-end
module _ {ℓ₁ ℓ₂ ℓ₃} {A : Type{ℓ₁}} {B : Type{ℓ₂}} {C : Type{ℓ₃}} {f : B → List(C)}{g : A → List(B)} where
concatMap-[∘] : (concatMap(concatMap f ∘ g)) ⊜ (concatMap f ∘ concatMap g)
concatMap-[∘] {∅} = reflexivity(_≡_)
concatMap-[∘] {x ⊰ l} =
(concatMap(concatMap f ∘ g)) (x ⊰ l) 🝖[ _≡_ ]-[]
(concatMap f ∘ g) x ++ concatMap(concatMap f ∘ g) l 🝖-[ congruence₁((concatMap f ∘ g) x ++_) (concatMap-[∘] {l}) ]
(concatMap f ∘ g) x ++ (concatMap f ∘ concatMap g) l 🝖[ _≡_ ]-[]
(concatMap f (g(x))) ++ (concatMap f (concatMap g l)) 🝖-[ concatMap-[++] {f = f}{l₁ = g(x)}{l₂ = concatMap g l} ]-sym
concatMap f (g(x) ++ concatMap g l) 🝖[ _≡_ ]-[]
concatMap f (concatMap g (x ⊰ l)) 🝖[ _≡_ ]-[]
(concatMap f ∘ concatMap g) (x ⊰ l) 🝖-end
concatMap-singleton : (concatMap{A = T} singleton) ⊜ id
concatMap-singleton {x = ∅} = reflexivity(_≡_)
concatMap-singleton {x = x ⊰ l} = congruence₁(x ⊰_) (concatMap-singleton {x = l})
concatMap-concat-map : (concatMap f l ≡ concat(map f l))
concatMap-concat-map {l = ∅} = reflexivity(_≡_)
concatMap-concat-map {f = f}{l = x ⊰ l} =
concatMap f (x ⊰ l) 🝖[ _≡_ ]-[]
f(x) ++ concatMap f l 🝖[ _≡_ ]-[ congruence₂ᵣ(_++_)(f(x)) (concatMap-concat-map {l = l}) ]
f(x) ++ concat(map f l) 🝖[ _≡_ ]-[]
concat(f(x) ⊰ map f l) 🝖[ _≡_ ]-[]
concat(map f (x ⊰ l)) 🝖-end
foldₗ-lastElem-equivalence : (last{T = T} ⊜ foldₗ (const Option.Some) Option.None)
foldₗ-lastElem-equivalence {x = ∅} = reflexivity(_≡_)
foldₗ-lastElem-equivalence {x = x ⊰ ∅} = reflexivity(_≡_)
foldₗ-lastElem-equivalence {x = x ⊰ y ⊰ l} = foldₗ-lastElem-equivalence {x = y ⊰ l}
{-
foldₗ-reverse-equivalence : (reverse{T = T} ⊜ foldₗ (Functional.swap(_⊰_)) ∅)
foldₗ-reverse-equivalence {x = ∅} = reflexivity(_≡_)
foldₗ-reverse-equivalence {x = x ⊰ l} =
reverse (x ⊰ l) 🝖[ _≡_ ]-[]
(postpend x ∘ reverse) l 🝖[ _≡_ ]-[ congruence₁(postpend x) (foldₗ-reverse-equivalence {x = l}) ]
(postpend x ∘ foldₗ (Functional.swap(_⊰_)) ∅) l 🝖[ _≡_ ]-[ {!!} ]
foldₗ (Functional.swap(_⊰_)) (Functional.swap(_⊰_) ∅ x) l 🝖[ _≡_ ]-[]
foldₗ (Functional.swap(_⊰_)) (singleton(x)) l 🝖[ _≡_ ]-[]
foldₗ (Functional.swap(_⊰_)) ∅ (x ⊰ l) 🝖-end
-}
foldᵣ-function : ⦃ equiv : Equiv{ℓₑ}(B) ⦄ → ∀{_▫_ : A → B → B} ⦃ oper : BinaryOperator(_▫_) ⦄ → Function ⦃ equiv-B = equiv ⦄ (foldᵣ(_▫_) a)
foldᵣ-function {a = a} ⦃ equiv ⦄ {_▫_ = _▫_} ⦃ oper ⦄ = intro p where
p : Names.Congruence₁ ⦃ equiv-B = equiv ⦄ (foldᵣ(_▫_) a)
p {∅} {∅} xy = reflexivity(Equiv._≡_ equiv)
p {x₁ ⊰ l₁} {x₂ ⊰ l₂} xy =
foldᵣ(_▫_) a (x₁ ⊰ l₁) 🝖[ Equiv._≡_ equiv ]-[]
x₁ ▫ (foldᵣ(_▫_) a l₁) 🝖[ Equiv._≡_ equiv ]-[ congruence₂(_▫_) ⦃ oper ⦄ ([∧]-elimₗ([⊰]-general-cancellation xy)) (p {l₁} {l₂} ([∧]-elimᵣ([⊰]-general-cancellation xy))) ]
x₂ ▫ (foldᵣ(_▫_) a l₂) 🝖[ Equiv._≡_ equiv ]-[]
foldᵣ(_▫_) a (x₂ ⊰ l₂) 🝖-end
foldᵣ-function₊-raw : ∀{l₁ l₂ : List(A)} ⦃ equiv : Equiv{ℓₑ}(B) ⦄ {_▫₁_ _▫₂_ : A → B → B} ⦃ oper₁ : BinaryOperator(_▫₁_) ⦄ ⦃ oper₂ : BinaryOperator ⦃ [≡]-equiv ⦄ ⦃ equiv ⦄ ⦃ equiv ⦄ (_▫₂_) ⦄ {a₁ a₂ : B} → (∀{x y} → (_≡ₛ_ ⦃ equiv ⦄ (x ▫₁ y) (x ▫₂ y))) → (_≡ₛ_ ⦃ equiv ⦄ a₁ a₂) → (l₁ ≡ l₂) → (foldᵣ(_▫₁_) a₁ l₁ ≡ₛ foldᵣ(_▫₂_) a₂ l₂)
foldᵣ-function₊-raw {l₁ = ∅} {∅} ⦃ equiv ⦄ {_▫₁_} {_▫₂_} ⦃ oper₁ ⦄ ⦃ oper₂ ⦄ {a₁} {a₂} opeq aeq leq = aeq
foldᵣ-function₊-raw {l₁ = x₁ ⊰ l₁} {x₂ ⊰ l₂} ⦃ equiv ⦄ {_▫₁_} {_▫₂_} ⦃ oper₁ ⦄ ⦃ oper₂ ⦄ {a₁} {a₂} opeq aeq leq =
foldᵣ(_▫₁_) a₁ (x₁ ⊰ l₁) 🝖[ Equiv._≡_ equiv ]-[]
x₁ ▫₁ (foldᵣ(_▫₁_) a₁ l₁) 🝖[ Equiv._≡_ equiv ]-[ congruence₂(_▫₁_) ⦃ oper₁ ⦄ ([∧]-elimₗ([⊰]-general-cancellation leq)) (foldᵣ-function₊-raw {l₁ = l₁} {l₂} ⦃ equiv ⦄ {_▫₁_}{_▫₂_} ⦃ oper₁ ⦄ ⦃ oper₂ ⦄ {a₁}{a₂} opeq aeq ([∧]-elimᵣ([⊰]-general-cancellation leq))) ]
x₂ ▫₁ (foldᵣ(_▫₂_) a₂ l₂) 🝖[ Equiv._≡_ equiv ]-[ opeq{x₂}{foldᵣ(_▫₂_) a₂ l₂} ]
x₂ ▫₂ (foldᵣ(_▫₂_) a₂ l₂) 🝖[ Equiv._≡_ equiv ]-[]
foldᵣ(_▫₂_) a₂ (x₂ ⊰ l₂) 🝖[ Equiv._≡_ equiv ]-end
map-binaryOperator : BinaryOperator {A₁ = A → B} ⦃ equiv-A₁ = Fn.[⊜]-equiv ⦃ [≡]-equiv ⦄ ⦄ ⦃ equiv-A₂ = [≡]-equiv ⦄ (map)
map-binaryOperator = intro p where
p : Names.Congruence₂(map)
p {f} {g} {∅} {∅} fg xy = reflexivity(_≡_)
p {f} {g} {x₁ ⊰ l₁} {x₂ ⊰ l₂} fg xy = congruence₂(_⊰_) ba rec where
ba : f(x₁) ≡ g(x₂)
ba =
f(x₁) 🝖[ _≡_ ]-[ Fn._⊜_.proof fg {x₁} ]
g(x₁) 🝖[ _≡_ ]-[ congruence₁(g) ([∧]-elimₗ([⊰]-general-cancellation xy)) ]
g(x₂) 🝖-end
rec : map f(l₁) ≡ map g(l₂)
rec =
map f(l₁) 🝖[ _≡_ ]-[ p fg ([∧]-elimᵣ([⊰]-general-cancellation xy)) ]
map g(l₂) 🝖-end
count-of-[++] : ∀{P} → (count P (l₁ ++ l₂) ≡ count P l₁ + count P l₂)
count-of-[++] {l₁ = ∅} {l₂ = l₂} {P = P} = reflexivity(_≡_)
count-of-[++] {l₁ = x₁ ⊰ l₁} {l₂ = l₂} {P = P} with P(x₁) | count-of-[++] {l₁ = l₁} {l₂ = l₂} {P = P}
... | 𝑇 | p = congruence₁ 𝐒(p)
... | 𝐹 | p = p
-- TODO Is this true?: count-single-equality-equivalence : (∀{P} → count P l₁ ≡ count P l₂) ↔ (∀{x} → (count (x ≡?_) l₁ ≡ count (x ≡?_) l₂))
|
{
"alphanum_fraction": 0.5701499217,
"avg_line_length": 49.9329608939,
"ext": "agda",
"hexsha": "6ce2609cc44bc9cb556f200faa79674d7de78d57",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/List/Equiv/Id.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/List/Equiv/Id.agda",
"max_line_length": 330,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/List/Equiv/Id.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 3922,
"size": 8938
}
|
{-# OPTIONS --rewriting #-}
-- {-# OPTIONS -v rewriting:30 #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality renaming (_≡_ to _≡≡_)
record Eq (t : Set) : Set₁ where
field
_≡_ : t → t → Set
open Eq {{...}}
{-# BUILTIN REWRITE _≡_ #-}
instance
eqN : Eq Nat
eqN = record { _≡_ = _≡≡_ }
postulate
plus0p : ∀{x} → (x + zero) ≡ x
{-# REWRITE plus0p #-}
-- Error:
-- plus0p does not target rewrite relation
-- when checking the pragma REWRITE plus0p
-- The type of the postulate ends in _≡≡_ (after reduction)
-- but the rewrite relation is _≡_
|
{
"alphanum_fraction": 0.6252158895,
"avg_line_length": 18.6774193548,
"ext": "agda",
"hexsha": "182364c922291ffbc1dd6dea09c10dd0bb3e4932",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2451.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2451.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2451.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 199,
"size": 579
}
|
module MLib.Algebra.PropertyCode.RawStruct where
open import MLib.Prelude
open import MLib.Fin.Parts
open import MLib.Finite
open import Relation.Binary as B using (Setoid)
open import Data.List.Any using (Any; here; there)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Vec.N-ary
open import Data.Product.Relation.SigmaPropositional as OverΣ using (OverΣ)
open import Data.Bool using (T)
open import Category.Applicative
module _ {c ℓ} {A : Set c} (_≈_ : Rel A ℓ) where
open Algebra.FunctionProperties _≈_
Congruentₙ : ∀ {n} → (Vec A n → A) → Set (c ⊔ˡ ℓ)
Congruentₙ f = ∀ {xs ys} → Vec.Pointwise _≈_ xs ys → f xs ≈ f ys
fromRefl : Reflexive _≈_ → (f : Vec A 0 → A) → Congruentₙ f
fromRefl refl f [] = refl
fromCongruent₂ : (f : Vec A 2 → A) → Congruent₂ (curryⁿ f) → Congruentₙ f
fromCongruent₂ f cong₂ (x≈u ∷ y≈v ∷ []) = cong₂ x≈u y≈v
PointwiseFunc : ∀ {n} {a b ℓ r} {A : Set a} {B : Set b} (_∼_ : A → B → Set ℓ) (xs : Vec A n) (ys : Vec B n) (R : Set r) → Set (N-ary-level ℓ r n)
PointwiseFunc _∼_ [] [] R = R
PointwiseFunc _∼_ (x ∷ xs) (y ∷ ys) R = x ∼ y → PointwiseFunc _∼_ xs ys R
appPW : ∀ {n} {a b ℓ r} {A : Set a} {B : Set b} {_∼_ : A → B → Set ℓ} {xs : Vec A n} {ys : Vec B n} {R : Set r} → PointwiseFunc _∼_ xs ys R → Vec.Pointwise _∼_ xs ys → R
appPW f [] = f
appPW f (x∼y ∷ pw) = appPW (f x∼y) pw
curryPW : ∀ {n} {a b ℓ r} {A : Set a} {B : Set b} {_∼_ : A → B → Set ℓ} {xs : Vec A n} {ys : Vec B n} {R : Set r} → (Vec.Pointwise _∼_ xs ys → R) → PointwiseFunc _∼_ xs ys R
curryPW {xs = []} {[]} f = f []
curryPW {xs = x ∷ xs} {y ∷ ys} f x∼y = curryPW {xs = xs} {ys} λ pw → f (x∼y ∷ pw)
--------------------------------------------------------------------------------
-- Raw structures implementing a set of operators, i.e. interpretations of the
-- operators which are each congruent under an equivalence, but do not
-- necessarily have any other properties.
--------------------------------------------------------------------------------
record IsRawStruct {c ℓ} {A : Set c} (_≈_ : Rel A ℓ) {k} {K : ℕ → Set k} (appOp : ∀ {n} → K n → Vec A n → A) : Set (c ⊔ˡ ℓ ⊔ˡ k) where
open Algebra.FunctionProperties _≈_
field
isEquivalence : IsEquivalence _≈_
congⁿ : ∀ {n} (κ : K n) → Congruentₙ _≈_ (appOp κ)
cong : ∀ {n} (κ : K n) {xs ys} → PointwiseFunc _≈_ xs ys (appOp κ xs ≈ appOp κ ys)
cong κ {xs} = curryPW {xs = xs} (congⁿ κ)
setoid : Setoid _ _
setoid = record { isEquivalence = isEquivalence }
⟦_⟧ : ∀ {n} → K n → N-ary n A A
⟦ κ ⟧ = curryⁿ (appOp κ)
_⟨_⟩_ : A → K 2 → A → A
x ⟨ κ ⟩ y = ⟦ κ ⟧ x y
open IsEquivalence isEquivalence public
record RawStruct {k} (K : ℕ → Set k) c ℓ : Set (sucˡ (c ⊔ˡ ℓ ⊔ˡ k)) where
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
appOp : ∀ {n} → K n → Vec Carrier n → Carrier
isRawStruct : IsRawStruct _≈_ appOp
open IsRawStruct isRawStruct public
-- Form a structure over a new kind of operator by injecting from it.
subRawStruct : ∀ {k′} {K′ : ℕ → Set k′} → (∀ {n} → K′ n → K n) → RawStruct K′ c ℓ
subRawStruct liftK = record
{ Carrier = Carrier
; _≈_ = _≈_
; appOp = appOp ∘ liftK
; isRawStruct = record
{ isEquivalence = isEquivalence
; congⁿ = congⁿ ∘ liftK
}
}
|
{
"alphanum_fraction": 0.571211199,
"avg_line_length": 35.3333333333,
"ext": "agda",
"hexsha": "2d0abaae487f7fbdab111f2d801748defe4c7681",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Algebra/PropertyCode/RawStruct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Algebra/PropertyCode/RawStruct.agda",
"max_line_length": 173,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Algebra/PropertyCode/RawStruct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1284,
"size": 3286
}
|
{-# OPTIONS --universe-polymorphism #-}
module Issue293a where
open import Agda.Primitive
using (Level; _⊔_) renaming (lzero to zero; lsuc to suc)
------------------------------------------------------------------------
record RawMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Carrier → Carrier → Set ℓ
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
module M (rm : RawMonoid zero zero) where
open RawMonoid rm
thm : ∀ x → x ∙ ε ≈ x
thm = {!!}
-- Previous agda2-goal-and-context:
-- rm : RawMonoid zero zero
-- ------------------------
-- Goal: (x : RawMonoid.Carrier rm) →
-- RawMonoid._≈_ rm (RawMonoid._∙_ rm x (RawMonoid.ε rm)) x
-- Current agda2-goal-and-context:
-- rm : RawMonoid zero zero
-- ------------------------
-- Goal: (x : Carrier) → x ∙ ε ≈ x
------------------------------------------------------------------------
record RawMonoid′ : Set₁ where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set
_≈_ : Carrier → Carrier → Set
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
module M′ (rm : RawMonoid′) where
open RawMonoid′ rm
thm′ : ∀ x → x ∙ ε ≈ x
thm′ = {!!}
-- Previous and current agda2-goal-and-context:
-- rm : RawMonoid′
-- ---------------
-- Goal: (x : Carrier) → x ∙ ε ≈ x
------------------------------------------------------------------------
-- UP isn't relevant.
record RawMonoid″ (Carrier : Set) : Set₁ where
infixl 7 _∙_
infix 4 _≈_
field
_≈_ : Carrier → Carrier → Set
_∙_ : Carrier → Carrier → Carrier
ε : Carrier
data Bool : Set where
true false : Bool
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A)(xs : List A) → List A
module M″ (rm : RawMonoid″ (List Bool)) where
open RawMonoid″ rm
thm″ : ∀ x → x ∙ ε ≈ x
thm″ = {!!}
-- Previous agda2-goal-and-context:
-- rm : RawMonoid″ (List Bool)
-- ---------------------------
-- Goal: (x : List Bool) →
-- RawMonoid″._≈_ rm (RawMonoid″._∙_ rm x (RawMonoid″.ε rm)) x
-- Current agda2-goal-and-context:
-- rm : RawMonoid″ (List Bool)
-- ---------------------------
-- Goal: (x : List Bool) → x ∙ ε ≈ x
|
{
"alphanum_fraction": 0.472246696,
"avg_line_length": 22.2549019608,
"ext": "agda",
"hexsha": "f02756b86292d976cb2261ecefc08fa9e768e4e7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue293a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue293a.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue293a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 730,
"size": 2270
}
|
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist heap that proves to maintain priority --
-- invariant and uses a single-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module SinglePassMerge.PriorityProof where
open import Basics.Nat renaming (_≥_ to _≥ℕ_)
open import Basics
open import Sized
data Heap : {i : Size} → Priority → Set where
empty : {i : Size} {n : Priority} → Heap {↑ i} n
node : {i : Size} {n : Priority} → (p : Priority) → Rank → p ≥ n →
Heap {i} p → Heap {i} p → Heap {↑ i} n
rank : {b : Priority} → Heap b → Rank
rank empty = zero
rank (node _ r _ _ _) = r
-- This implementation is derived in the same way as merge in
-- SinglePassMerge.NoProofs: depending on the size of new children we
-- swap parameters passed to node. Nothing really interesting.
merge : {i j : Size} {p : Nat} → Heap {i} p → Heap {j} p → Heap p
merge empty h2 = h2
merge h1 empty = h1
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
with order p1 p2
| rank l1 ≥ℕ rank r1 + r-rank
| rank l2 ≥ℕ rank r2 + l-rank
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| le p1≤p2 | true | _
= node p1 (l-rank + r-rank) p1≥p l1 (merge {i} {↑ j} r1 (node p2 r-rank p1≤p2 l2 r2))
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| le p1≤p2 | false | _
= node p1 (l-rank + r-rank) p1≥p (merge {i} {↑ j} r1 (node p2 r-rank p1≤p2 l2 r2)) l1
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| ge p2≤p1 | _ | true
= node p2 ((l-rank + r-rank)) p2≥p l2 (merge {↑ i} {j} (node p1 l-rank p2≤p1 l1 r1) r2)
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| ge p2≤p1 | _ | false
= node p2 ((l-rank + r-rank)) p2≥p (merge {↑ i} {j} (node p1 l-rank p2≤p1 l1 r1) r2) l2
|
{
"alphanum_fraction": 0.51738584,
"avg_line_length": 40.4576271186,
"ext": "agda",
"hexsha": "8cc71f7589383c30fd595ad31128f6c6fa07ed8e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/SinglePassMerge/PriorityProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/SinglePassMerge/PriorityProof.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/SinglePassMerge/PriorityProof.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 889,
"size": 2387
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathGroupoid
module lib.PathFunctor where
{- Nondependent stuff -}
module _ {i j} {A : Type i} {B : Type j} (f : A → B) where
!-ap : {x y : A} (p : x == y)
→ ! (ap f p) == ap f (! p)
!-ap idp = idp
ap-! : {x y : A} (p : x == y)
→ ap f (! p) == ! (ap f p)
ap-! idp = idp
∙-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙ ap f q == ap f (p ∙ q)
∙-ap idp q = idp
ap-∙ : {x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∙ q) == ap f p ∙ ap f q
ap-∙ idp q = idp
!ap-∙=∙-ap : {x y z : A} (p : x == y) (q : y == z)
→ ! (ap-∙ p q) == ∙-ap p q
!ap-∙=∙-ap idp q = idp
∙∙-ap : {x y z w : A} (p : x == y) (q : y == z) (r : z == w)
→ ap f p ∙ ap f q ∙ ap f r == ap f (p ∙ q ∙ r)
∙∙-ap idp idp r = idp
ap-∙∙ : {x y z w : A} (p : x == y) (q : y == z) (r : z == w)
→ ap f (p ∙ q ∙ r) == ap f p ∙ ap f q ∙ ap f r
ap-∙∙ idp idp r = idp
ap-∙∙∙ : {x y z w t : A} (p : x == y) (q : y == z) (r : z == w) (s : w == t)
→ ap f (p ∙ q ∙ r ∙ s) == ap f p ∙ ap f q ∙ ap f r ∙ ap f s
ap-∙∙∙ idp idp idp s = idp
∙'-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙' ap f q == ap f (p ∙' q)
∙'-ap p idp = idp
-- note: ap-∙' is defined in PathGroupoid
{- Dependent stuff -}
module _ {i j} {A : Type i} {B : A → Type j} (f : Π A B) where
apd-∙ : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙ q) == apd f p ∙ᵈ apd f q
apd-∙ idp idp = idp
apd-∙' : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙' q) == apd f p ∙'ᵈ apd f q
apd-∙' idp idp = idp
apd-! : {x y : A} (p : x == y)
→ apd f (! p) == !ᵈ (apd f p)
apd-! idp = idp
{- Over stuff -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(f : {a : A} → B a → C a) where
ap↓-◃ : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : y == z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ ap↓ f (q ◃ r) == ap↓ f q ◃ ap↓ f r
ap↓-◃ {p = idp} {p' = idp} idp idp = idp
ap↓-▹! : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : z == y} (q : u == v [ B ↓ p ]) (r : w == v [ B ↓ p' ])
→ ap↓ f (q ▹! r) == ap↓ f q ▹! ap↓ f r
ap↓-▹! {p = idp} {p' = idp} idp idp = idp
{- Fuse and unfuse -}
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B) where
∘-ap : {x y : A} (p : x == y) → ap g (ap f p) == ap (g ∘ f) p
∘-ap idp = idp
ap-∘ : {x y : A} (p : x == y) → ap (g ∘ f) p == ap g (ap f p)
ap-∘ idp = idp
!ap-∘=∘-ap : {x y : A} (p : x == y) → ! (ap-∘ p) == ∘-ap p
!ap-∘=∘-ap idp = idp
ap-idf : ∀ {i} {A : Type i} {u v : A} (p : u == v) → ap (idf A) p == p
ap-idf idp = idp
{- Functoriality of [coe] -}
coe-∙ : ∀ {i} {A B C : Type i} (p : A == B) (q : B == C) (a : A)
→ coe (p ∙ q) a == coe q (coe p a)
coe-∙ idp q a = idp
coe-! : ∀ {i} {A B : Type i} (p : A == B) (b : B) → coe (! p) b == coe! p b
coe-! idp b = idp
coe!-inv-r : ∀ {i} {A B : Type i} (p : A == B) (b : B)
→ coe p (coe! p b) == b
coe!-inv-r idp b = idp
coe!-inv-l : ∀ {i} {A B : Type i} (p : A == B) (a : A)
→ coe! p (coe p a) == a
coe!-inv-l idp a = idp
coe-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (a : A) →
ap (coe p) (coe!-inv-l p a) == coe!-inv-r p (coe p a)
coe-inv-adj idp a = idp
coe!-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (b : B) →
ap (coe! p) (coe!-inv-r p b) == coe!-inv-l p (coe! p b)
coe!-inv-adj idp b = idp
coe-ap-! : ∀ {i j} {A : Type i} (P : A → Type j) {a b : A} (p : a == b)
(x : P b)
→ coe (ap P (! p)) x == coe! (ap P p) x
coe-ap-! P idp x = idp
{- Functoriality of transport -}
transp-∙ : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙ q) b == transport B q (transport B p b)
transp-∙ idp _ _ = idp
transp-∙' : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙' q) b == transport B q (transport B p b)
transp-∙' _ idp _ = idp
{- Naturality of transport -}
transp-naturality : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(u : {a : A} → B a → C a)
{a₀ a₁ : A} (p : a₀ == a₁)
→ u ∘ transport B p == transport C p ∘ u
transp-naturality f idp = idp
transp-idp : ∀ {i j} {A : Type i} {B : Type j}
(f : A → B) {x y : A} (p : x == y)
→ transport (λ a → f a == f a) p idp == idp
transp-idp f idp = idp
module _ {i j} {A : Type i} {B : Type j} where
ap-transp : (f g : A → B) {a₀ a₁ : A} (p : a₀ == a₁) (h : f a₀ == g a₀)
→ h ∙ ap g p == ap f p ∙ transport (λ a → f a == g a) p h
ap-transp f g p@idp h = ∙-unit-r h
ap-transp-idp : (f : A → B)
{a₀ a₁ : A} (p : a₀ == a₁)
→ ap-transp f f p idp ◃∙
ap (ap f p ∙_) (transp-idp f p) ◃∙
∙-unit-r (ap f p) ◃∎
=ₛ
[]
ap-transp-idp f p@idp = =ₛ-in idp
{- for functions with two arguments -}
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → B → C) where
ap2 : {x y : A} {w z : B}
→ (x == y) → (w == z) → f x w == f y z
ap2 idp idp = idp
ap2-out : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 p q ◃∎ =ₛ ap (λ u → f u w) p ◃∙ ap (λ v → f y v) q ◃∎
ap2-out idp idp = =ₛ-in idp
ap2-out' : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 p q ◃∎ =ₛ ap (λ u → f x u) q ◃∙ ap (λ v → f v z) p ◃∎
ap2-out' idp idp = =ₛ-in idp
ap2-idp-l : {x : A} {w z : B} (q : w == z)
→ ap2 (idp {a = x}) q == ap (f x) q
ap2-idp-l idp = idp
ap2-idp-r : {x y : A} {w : B} (p : x == y)
→ ap2 p (idp {a = w}) == ap (λ z → f z w) p
ap2-idp-r idp = idp
ap2-! : {a a' : A} {b b' : B} (p : a == a') (q : b == b')
→ ap2 (! p) (! q) == ! (ap2 p q)
ap2-! idp idp = idp
!-ap2 : {a a' : A} {b b' : B} (p : a == a') (q : b == b')
→ ! (ap2 p q) == ap2 (! p) (! q)
!-ap2 idp idp = idp
ap2-∙ : {a a' a'' : A} {b b' b'' : B}
(p : a == a') (p' : a' == a'')
(q : b == b') (q' : b' == b'')
→ ap2 (p ∙ p') (q ∙ q') == ap2 p q ∙ ap2 p' q'
ap2-∙ idp p' idp q' = idp
∙-ap2 : {a a' a'' : A} {b b' b'' : B}
(p : a == a') (p' : a' == a'')
(q : b == b') (q' : b' == b'')
→ ap2 p q ∙ ap2 p' q' == ap2 (p ∙ p') (q ∙ q')
∙-ap2 idp p' idp q' = idp
{- ap2 lemmas -}
module _ {i j} {A : Type i} {B : Type j} where
ap2-fst : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry fst) p q == p
ap2-fst idp idp = idp
ap2-snd : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry snd) p q == q
ap2-snd idp idp = idp
ap-ap2 : ∀ {k l} {C : Type k} {D : Type l}
(g : C → D) (f : A → B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap g (ap2 f p q) == ap2 (λ a b → g (f a b)) p q
ap-ap2 g f idp idp = idp
ap2-ap-l : ∀ {k l} {C : Type k} {D : Type l}
(g : B → C → D) (f : A → B) {x y : A} {w z : C}
(p : x == y) (q : w == z)
→ ap2 g (ap f p) q == ap2 (λ a c → g (f a) c) p q
ap2-ap-l g f idp idp = idp
ap2-ap-r : ∀ {k l} {C : Type k} {D : Type l}
(g : A → C → D) (f : B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap2 g p (ap f q) == ap2 (λ a b → g a (f b)) p q
ap2-ap-r g f idp idp = idp
ap2-ap-lr : ∀ {k l m} {C : Type k} {D : Type l} {E : Type m}
(g : C → D → E) (f : A → C) (h : B → D)
{x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap2 g (ap f p) (ap h q) == ap2 (λ a b → g (f a) (h b)) p q
ap2-ap-lr g f h idp idp = idp
ap2-diag : (f : A → A → B)
{x y : A} (p : x == y)
→ ap2 f p p == ap (λ x → f x x) p
ap2-diag f idp = idp
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B) where
module _ {a a' a'' : A} (p : a == a') (p' : a' == a'') where
ap-∘-∙-coh-seq₁ :
ap (g ∘ f) (p ∙ p') =-= ap g (ap f p) ∙ ap g (ap f p')
ap-∘-∙-coh-seq₁ =
ap (g ∘ f) (p ∙ p')
=⟪ ap-∙ (g ∘ f) p p' ⟫
ap (g ∘ f) p ∙ ap (g ∘ f) p'
=⟪ ap2 _∙_ (ap-∘ g f p) (ap-∘ g f p') ⟫
ap g (ap f p) ∙ ap g (ap f p') ∎∎
ap-∘-∙-coh-seq₂ :
ap (g ∘ f) (p ∙ p') =-= ap g (ap f p) ∙ ap g (ap f p')
ap-∘-∙-coh-seq₂ =
ap (g ∘ f) (p ∙ p')
=⟪ ap-∘ g f (p ∙ p') ⟫
ap g (ap f (p ∙ p'))
=⟪ ap (ap g) (ap-∙ f p p') ⟫
ap g (ap f p ∙ ap f p')
=⟪ ap-∙ g (ap f p) (ap f p') ⟫
ap g (ap f p) ∙ ap g (ap f p') ∎∎
ap-∘-∙-coh : {a a' a'' : A} (p : a == a') (p' : a' == a'')
→ ap-∘-∙-coh-seq₁ p p' =ₛ ap-∘-∙-coh-seq₂ p p'
ap-∘-∙-coh idp idp = =ₛ-in idp
module _ {i} {A : Type i} where
ap-null-homotopic : ∀ {k} {B : Type k} (f : A → B) {b : B}
(h : (x : A) → f x == b) {x y : A} (p : x == y)
→ ap f p == h x ∙ ! (h y)
ap-null-homotopic f h {x} p@idp = ! (!-inv-r (h x))
module _ {i j} {A : Type i} {B : Type j} (b : B) where
ap-cst : {x y : A} (p : x == y)
→ ap (cst b) p == idp
ap-cst = ap-null-homotopic (cst b) (cst idp)
ap-cst-coh : {x y z : A} (p : x == y) (q : y == z)
→ ap-cst (p ∙ q) ◃∎
=ₛ
ap-∙ (cst b) p q ◃∙
ap2 _∙_ (ap-cst p) (ap-cst q) ◃∎
ap-cst-coh idp idp = =ₛ-in idp
ap-∘-cst-coh : ∀ {i} {j} {k} {A : Type i} {B : Type j} {C : Type k}
(g : B → C) (b : B)
{x y : A} (p : x == y)
→ ∘-ap g (λ _ → b) p ◃∙
ap-cst (g b) p ◃∎
=ₛ
ap (ap g) (ap-cst b p) ◃∎
ap-∘-cst-coh g b p@idp = =ₛ-in idp
{- Naturality of homotopies -}
module _ {i} {A : Type i} where
homotopy-naturality : ∀ {k} {B : Type k} (f g : A → B)
(h : (x : A) → f x == g x) {x y : A} (p : x == y)
→ ap f p ◃∙ h y ◃∎ =ₛ h x ◃∙ ap g p ◃∎
homotopy-naturality f g h {x} idp =
=ₛ-in (! (∙-unit-r (h x)))
homotopy-naturality-to-idf : (f : A → A)
(h : (x : A) → f x == x) {x y : A} (p : x == y)
→ ap f p ◃∙ h y ◃∎ =ₛ h x ◃∙ p ◃∎
homotopy-naturality-to-idf f h {x} p = =ₛ-in $
=ₛ-out (homotopy-naturality f (λ a → a) h p) ∙ ap (λ w → h x ∙ w) (ap-idf p)
homotopy-naturality-from-idf : (g : A → A)
(h : (x : A) → x == g x) {x y : A} (p : x == y)
→ p ◃∙ h y ◃∎ =ₛ h x ◃∙ ap g p ◃∎
homotopy-naturality-from-idf g h {y = y} p = =ₛ-in $
ap (λ w → w ∙ h y) (! (ap-idf p)) ∙ =ₛ-out (homotopy-naturality (λ a → a) g h p)
homotopy-naturality-to-cst : ∀ {k} {B : Type k} (f : A → B) (b : B)
(h : (x : A) → f x == b) {x y : A} (p : x == y)
→ ap f p ◃∙ h y ◃∎ =ₛ h x ◃∎
homotopy-naturality-to-cst f b h p@idp = =ₛ-in idp
ap-null-homotopic-cst : ∀ {k} {B : Type k}
(b₀ b₁ : B) (h : A → b₀ == b₁) {x y : A} (p : x == y)
→ ap-null-homotopic (cst b₀) h p ◃∙
ap (λ v → h v ∙ ! (h y)) p ◃∙
!-inv-r (h y) ◃∎
=ₛ
ap-cst b₀ p ◃∎
ap-null-homotopic-cst b₀ b₁ h {x} p@idp =
=ₛ-in (!-inv-l (!-inv-r (h x)))
module _ {i j k} {A : Type i} {B : Type j} {C : Type k}
(f g : A → B → C) (h : ∀ a b → f a b == g a b) where
homotopy-naturality2 : {a₀ a₁ : A} {b₀ b₁ : B} (p : a₀ == a₁) (q : b₀ == b₁)
→ ap2 f p q ◃∙ h a₁ b₁ ◃∎ =ₛ h a₀ b₀ ◃∙ ap2 g p q ◃∎
homotopy-naturality2 {a₀ = a} {b₀ = b} idp idp =
=ₛ-in (! (∙-unit-r (h a b)))
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → B → C) where
ap-comm : {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
→ ap (λ a → f a b₀) p ∙ ap (λ z → f a₁ z) q ==
ap (λ z → f a₀ z) q ∙ ap (λ a → f a b₁) p
ap-comm p q = ! (=ₛ-out (ap2-out f p q)) ∙ =ₛ-out (ap2-out' f p q)
ap-comm-=ₛ : {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
→ ap (λ a → f a b₀) p ◃∙ ap (λ z → f a₁ z) q ◃∎ =ₛ
ap (λ z → f a₀ z) q ◃∙ ap (λ a → f a b₁) p ◃∎
ap-comm-=ₛ p q = =ₛ-in (ap-comm p q)
ap-comm' : {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
→ ap (λ a → f a b₀) p ∙' ap (λ z → f a₁ z) q ==
ap (λ z → f a₀ z) q ∙ ap (λ a → f a b₁) p
ap-comm' p idp = idp
ap-comm-cst-seq : {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
(c : C) (h₀ : ∀ b → f a₀ b == c)
→ ap (λ a → f a b₀) p ∙ ap (λ b → f a₁ b) q =-=
ap (λ z → f a₀ z) q ∙ ap (λ a → f a b₁) p
ap-comm-cst-seq {a₀} {a₁} p {b₀} {b₁} q c h₀ =
ap (λ a → f a b₀) p ∙ ap (λ b → f a₁ b) q
=⟪ ap (ap (λ a → f a b₀) p ∙_) $
ap-null-homotopic (λ b → f a₁ b) h₁ q ⟫
ap (λ a → f a b₀) p ∙ h₁ b₀ ∙ ! (h₁ b₁)
=⟪ ap (ap (λ a → f a b₀) p ∙_) $ ap (λ k → k h₀) $
transp-naturality {B = λ a → ∀ b → f a b == c} (λ h → h b₀ ∙ ! (h b₁)) p ⟫
ap (λ a → f a b₀) p ∙ transport (λ a → f a b₀ == f a b₁) p (h₀ b₀ ∙ ! (h₀ b₁))
=⟪ ! (ap-transp (λ a → f a b₀) (λ a → f a b₁) p (h₀ b₀ ∙ ! (h₀ b₁))) ⟫
(h₀ b₀ ∙ ! (h₀ b₁)) ∙ ap (λ a → f a b₁) p
=⟪ ! (ap (_∙ ap (λ a → f a b₁) p) $
(ap-null-homotopic (λ b → f a₀ b) h₀ q)) ⟫
ap (λ z → f a₀ z) q ∙ ap (λ a → f a b₁) p ∎∎
where
h₁ : ∀ b → f a₁ b == c
h₁ = transport (λ a → ∀ b → f a b == c) p h₀
ap-comm-cst-coh : {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
(c : C) (h₀ : ∀ b → f a₀ b == c)
→ ap-comm p q ◃∎ =ₛ
ap-comm-cst-seq p q c h₀
ap-comm-cst-coh p@idp {b₀} q@idp c h₀ = =ₛ-in $ ! $
ap (idp ∙_) (! (!-inv-r (h₀ b₀))) ∙
! (∙-unit-r (h₀ b₀ ∙ ! (h₀ b₀))) ∙
! (ap (_∙ idp) (! (!-inv-r (h₀ b₀))))
=⟨ ap (_∙ ! (∙-unit-r (h₀ b₀ ∙ ! (h₀ b₀))) ∙ ! (ap (_∙ idp) (! (!-inv-r (h₀ b₀)))))
(ap-idf (! (!-inv-r (h₀ b₀)))) ⟩
! (!-inv-r (h₀ b₀)) ∙
! (∙-unit-r (h₀ b₀ ∙ ! (h₀ b₀))) ∙
! (ap (_∙ idp) (! (!-inv-r (h₀ b₀))))
=⟨ ap (λ v → ! (!-inv-r (h₀ b₀)) ∙ ! (∙-unit-r (h₀ b₀ ∙ ! (h₀ b₀))) ∙ v)
(!-ap (_∙ idp) (! (!-inv-r (h₀ b₀)))) ⟩
! (!-inv-r (h₀ b₀)) ∙
! (∙-unit-r (h₀ b₀ ∙ ! (h₀ b₀))) ∙
ap (_∙ idp) (! (! (!-inv-r (h₀ b₀))))
=⟨ ap (! (!-inv-r (h₀ b₀)) ∙_) $ ! $ =ₛ-out $
homotopy-naturality-from-idf (_∙ idp)
(λ p → ! (∙-unit-r p))
(! (! (!-inv-r (h₀ b₀)))) ⟩
! (!-inv-r (h₀ b₀)) ∙ ! (! (!-inv-r (h₀ b₀))) ∙ idp
=⟨ ap (! (!-inv-r (h₀ b₀)) ∙_) (∙-unit-r (! (! (!-inv-r (h₀ b₀))))) ⟩
! (!-inv-r (h₀ b₀)) ∙ ! (! (!-inv-r (h₀ b₀)))
=⟨ !-inv-r (! (!-inv-r (h₀ b₀))) ⟩
idp =∎
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where
ap-comm-comm : (f : A → B → C) {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
→ ap-comm f p q == ! (ap-comm (λ x y → f y x) q p)
ap-comm-comm f p@idp q@idp = idp
module _ {i} {A : Type i} where
-- unsure where this belongs
transp-cst=idf : {a x y : A} (p : x == y) (q : a == x)
→ transport (λ x → a == x) p q == q ∙ p
transp-cst=idf idp q = ! (∙-unit-r q)
transp-cst=idf-pentagon : {a x y z : A}
(p : x == y) (q : y == z) (r : a == x)
→ transp-cst=idf (p ∙ q) r ◃∎ =ₛ
transp-∙ p q r ◃∙
ap (transport (λ x → a == x) q) (transp-cst=idf p r) ◃∙
transp-cst=idf q (r ∙ p) ◃∙
∙-assoc r p q ◃∎
transp-cst=idf-pentagon idp q idp =
=ₛ-in (! (∙-unit-r (transp-cst=idf q idp)))
{- for functions with more arguments -}
module _ {i₀ i₁ i₂ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂}
{B : Type j} (f : A₀ → A₁ → A₂ → B) where
ap3 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → f x₀ x₁ x₂ == f y₀ y₁ y₂
ap3 idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{B : Type j} (f : A₀ → A₁ → A₂ → A₃ → B) where
ap4 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → f x₀ x₁ x₂ x₃ == f y₀ y₁ y₂ y₃
ap4 idp idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ i₄ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{A₄ : Type i₄} {B : Type j} (f : A₀ → A₁ → A₂ → A₃ → A₄ → B) where
ap5 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃} {x₄ y₄ : A₄}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → (x₄ == y₄)
→ f x₀ x₁ x₂ x₃ x₄ == f y₀ y₁ y₂ y₃ y₄
ap5 idp idp idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ i₄ i₅ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{A₄ : Type i₄} {A₅ : Type i₅} {B : Type j} (f : A₀ → A₁ → A₂ → A₃ → A₄ → A₅ → B) where
ap6 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃} {x₄ y₄ : A₄} {x₅ y₅ : A₅}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → (x₄ == y₄) → (x₅ == y₅)
→ f x₀ x₁ x₂ x₃ x₄ x₅ == f y₀ y₁ y₂ y₃ y₄ y₅
ap6 idp idp idp idp idp idp = idp
|
{
"alphanum_fraction": 0.4021678538,
"avg_line_length": 34.9458874459,
"ext": "agda",
"hexsha": "da25a4496cd94bcc17a3b30a19da199d45d462a1",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/PathFunctor.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/PathFunctor.agda",
"max_line_length": 90,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/PathFunctor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 8557,
"size": 16145
}
|
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.constr.findInScope:10 #-} -- -v tc.conv.elim:25 #-}
-- Andreas, 2012-07-01
module Issue670a where
import Common.Level
open import Common.Equality
findRefl : {A : Set}(a : A){{p : a ≡ a}} → a ≡ a
findRefl a {{p}} = p
uip : {A : Set}{a : A} → findRefl a ≡ refl
uip = refl
-- this should work. Used to throw an internal error in Conversion,
-- because the solution for p was refl applied to parameters, instead of just refl.
|
{
"alphanum_fraction": 0.6534446764,
"avg_line_length": 29.9375,
"ext": "agda",
"hexsha": "5505e07cdda3de0dd1498e448c2d45056dffb599",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue670a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue670a.agda",
"max_line_length": 83,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue670a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 155,
"size": 479
}
|
module BasicIO where
open import Agda.Builtin.IO public
open import Data.Char
open import Data.List
{-# FOREIGN GHC import Control.Exception #-}
{-# FOREIGN GHC import System.Environment #-}
-- This is easier than using the IO functions in the standard library,
-- but it's technically not as type-safe. And it bypasses the
-- termination checker.
postulate
return : {A : Set} → A → IO A
_>>_ : {A B : Set} → IO A → IO B → IO B
_>>=_ : {A B : Set} → IO A → (A → IO B) → IO B
fail : {A : Set} → List Char → IO A
bracket : {A B C : Set} → IO A → (A → IO B) → (A → IO C) → IO C
getArgs : IO (List (List Char))
{-# COMPILE GHC return = \_ -> return #-}
{-# COMPILE GHC _>>_ = \_ _ -> (>>) #-}
{-# COMPILE GHC _>>=_ = \_ _ -> (>>=) #-}
{-# COMPILE GHC fail = \_ -> fail #-}
{-# COMPILE GHC bracket = \ _ _ _ -> bracket #-}
{-# COMPILE GHC getArgs = getArgs #-}
|
{
"alphanum_fraction": 0.5860091743,
"avg_line_length": 32.2962962963,
"ext": "agda",
"hexsha": "521b24b60368f68bea4ee11eb0926f0d8aa14d1a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda-editor",
"max_forks_repo_path": "src/BasicIO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda-editor",
"max_issues_repo_path": "src/BasicIO.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda-editor",
"max_stars_repo_path": "src/BasicIO.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 269,
"size": 872
}
|
-- Andreas, 2016-12-20, issue #2350
-- Agda ignores a wrong instance parameter to a constructor
data D {{a}} (A : Set a) : Set a where
c : A → D A
test : ∀ ℓ {ℓ'} (A : Set ℓ') {B : Set ℓ} (a : A) → D A
test ℓ A a = c {{ℓ}} a
-- Expected Error:
-- .ℓ' != ℓ of type .Agda.Primitive.Level
-- when checking that the expression a has type A
|
{
"alphanum_fraction": 0.5953079179,
"avg_line_length": 26.2307692308,
"ext": "agda",
"hexsha": "cd9e533fc4087f39920fe8868237bec492a7731c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue2350-constructor-parameter-ignored.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue2350-constructor-parameter-ignored.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue2350-constructor-parameter-ignored.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 129,
"size": 341
}
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.Free where
open import Categories.Category
open import Categories.Free.Core
open import Categories.Free.Functor
open import Categories.Graphs.Underlying
open import Categories.Functor
using (Functor)
open import Graphs.Graph
open import Graphs.GraphMorphism
using (GraphMorphism; module GraphMorphism)
open import Data.Star
-- Exports from other modules:
-- Free₀, Free₁ and Free
open Categories.Free.Core public
using (Free₀)
open Categories.Free.Functor public
using (Free)
-- TODO:
-- Prove Free⊣Underlying : Adjunction Free Underlying
-- Define Adjunction.left and Adjunction.right as conveniences
-- (or whatever other names make sense for the hom-set maps
-- C [ F _ , _ ] → D [ _ , G _ ] and inverse, respectively)
-- Let Cata = Adjunction.left Free⊣Underlying
Cata : ∀{o₁ ℓ₁ e₁}{G : Graph o₁ ℓ₁ e₁}
{o₂ ℓ₂ e₂}{C : Category o₂ ℓ₂ e₂}
→ (F : GraphMorphism G (Underlying₀ C))
→ Functor (Free₀ G) C
Cata {G = G} {C = C} F = record
{ F₀ = F₀
; F₁ = F₁*
; identity = refl
; homomorphism = λ{X}{Y}{Z}{f}{g} → homomorphism {X}{Y}{Z}{f}{g}
; F-resp-≡ = F₁*-resp-≡
}
where
open Category C
open GraphMorphism F
open Equiv
open HomReasoning
open PathEquality using (ε-cong; _◅-cong_)
F₁* : ∀ {A B} → Free₀ G [ A , B ] → C [ F₀ A , F₀ B ]
F₁* ε = id
F₁* (f ◅ fs) = F₁* fs ∘ F₁ f
.homomorphism : ∀ {X Y Z} {f : Free₀ G [ X , Y ]} {g : Free₀ G [ Y , Z ]}
→ C [ F₁* (Free₀ G [ g ∘ f ]) ≡ C [ F₁* g ∘ F₁* f ] ]
homomorphism {f = ε} = sym identityʳ
homomorphism {f = f ◅ fs}{gs} =
begin
F₁* (fs ◅◅ gs) ∘ F₁ f
↓⟨ homomorphism {f = fs}{gs} ⟩∘⟨ refl ⟩
(F₁* gs ∘ F₁* fs) ∘ F₁ f
↓⟨ assoc ⟩
F₁* gs ∘ F₁* fs ∘ F₁ f
∎
.F₁*-resp-≡ : ∀ {A B} {f g : Free₀ G [ A , B ]} → Free₀ G [ f ≡ g ] → C [ F₁* f ≡ F₁* g ]
F₁*-resp-≡ {f = ε}{.ε} ε-cong = refl
F₁*-resp-≡ {f = f ◅ fs}{g ◅ gs} (f≈g ◅-cong fs≈gs) =
begin
F₁* fs ∘ F₁ f
↓⟨ F₁*-resp-≡ fs≈gs ⟩∘⟨ F-resp-≈ f≈g ⟩
F₁* gs ∘ F₁ g
∎
F₁*-resp-≡ {f = f ◅ fs}{ε} ()
|
{
"alphanum_fraction": 0.5523809524,
"avg_line_length": 30.625,
"ext": "agda",
"hexsha": "acd1abd5288a6e060bb1dd458367fb0ca822a1ba",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Free.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Free.agda",
"max_line_length": 93,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Free.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 870,
"size": 2205
}
|
{-# OPTIONS --rewriting #-}
module DualContractive where
open import Data.Fin
open import Data.Maybe
open import Data.Nat hiding (_≤_ ; compare) renaming (_+_ to _+ℕ_)
open import Data.Nat.Properties
open import Data.Sum hiding (map)
open import Data.Product
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Function
open import Types.Direction
open import Auxiliary.Extensionality
open import Max hiding (n)
----------------------------------------------------------------------
-- see also https://github.com/zmthy/recursive-types/tree/ftfjp16
-- for encoding of recursive types
variable
m n : ℕ
i i' j : Fin n
----------------------------------------------------------------------
-- lemmas for rewriting
n+1=suc-n : n +ℕ 1 ≡ suc n
n+1=suc-n {zero} = refl
n+1=suc-n {suc n} = cong suc (n+1=suc-n {n})
n+0=n : n +ℕ 0 ≡ n
n+0=n {zero} = refl
n+0=n {suc n} = cong suc (n+0=n {n})
n+sucm=sucn+m : ∀ n m → n +ℕ suc m ≡ suc (n +ℕ m)
n+sucm=sucn+m zero m = refl
n+sucm=sucn+m (suc n) m = cong suc (n+sucm=sucn+m n m)
{-# REWRITE n+sucm=sucn+m #-}
open import Agda.Builtin.Equality.Rewrite
----------------------------------------------------------------------
-- auxiliaries for automatic rewriting
{- REWRITE n+1=suc-n #-}
{-# REWRITE n+0=n #-}
-- inject+0-x=x : {x : Fin m} → inject+ 0 x ≡ x
-- inject+0-x=x {x = zero} = refl
-- inject+0-x=x {x = suc x} = cong suc inject+0-x=x
{- REWRITE inject+0-x=x #-}
----------------------------------------------------------------------
-- types and session types
data TType (n : ℕ) : Set
data SType (n : ℕ) : Set
data TType n where
TInt : TType n
TChn : (S : SType n) → TType n
data SType n where
xmt : (d : Dir) (T : TType n) (S : SType n) → SType n
end : SType n
rec : (S : SType (suc n)) → SType n
var : (x : Fin n) → SType n
variable
t T : TType n
s s₀ S S₀ : SType n
----------------------------------------------------------------------
module Examples-Types where
sint : SType n → SType n
sint = xmt SND TInt
-- μ X. !Int. X
s1 : SType 0
s1 = rec (sint (var zero))
-- μ X. μ Y. !Int. Y
s2 : SType 0
s2 = rec (rec (sint (var zero)))
-- μ X. μ Y. !Int. X
s2a : SType 0
s2a = rec (rec (sint (var (suc zero))))
-- μ X. !Int. μ Y. X
s3 : SType 0
s3 = rec (sint (rec (var (suc zero))))
module Alternative-Substitution where
-- analogous to https://plfa.github.io/DeBruijn/
-- extending a map by an identity segment
extV : (Fin m → Fin n) → (Fin (suc m) → Fin (suc n))
extV ρ zero = zero
extV ρ (suc i) = suc (ρ i)
-- renaming / can be used for weakening one binding as @rename suc@
renameT : (Fin m → Fin n) → TType m → TType n
renameS : (Fin m → Fin n) → SType m → SType n
renameT ρ TInt = TInt
renameT ρ (TChn S) = TChn (renameS ρ S)
renameS ρ (xmt d T S) = xmt d (renameT ρ T) (renameS ρ S)
renameS ρ end = end
renameS ρ (rec S) = rec (renameS (extV ρ) S)
renameS ρ (var x) = var (ρ x)
-- extending a map from variables to terms
extS : (Fin m → SType n) → (Fin (suc m) → SType (suc n))
extS σ zero = var zero
extS σ (suc i) = renameS suc (σ i)
-- simultaneous substitution
substT : (Fin m → SType n) → TType m → TType n
substS : (Fin m → SType n) → SType m → SType n
substT σ TInt = TInt
substT σ (TChn S) = TChn (substS σ S)
substS σ (xmt d T S) = xmt d (substT σ T) (substS σ S)
substS σ end = end
substS σ (rec S) = rec (substS (extS σ) S)
substS σ (var x) = σ x
-- single substitution
mk-σ : SType n → Fin (suc n) → SType n
mk-σ S' zero = S'
mk-σ S' (suc x) = var x
substT1 : SType n → TType (suc n) → TType n
substT1 S' T = substT (mk-σ S') T
substS1 : SType n → SType (suc n) → SType n
substS1 S' S = substS (mk-σ S') S
----------------------------------------------------------------------
-- weakening
increase : ∀ m → (x : Fin n) → Fin (n +ℕ m)
increase zero x = x
increase (suc m) x = suc (increase m x)
increaseS : ∀ m → SType n → SType (n +ℕ m)
increaseT : ∀ m → TType n → TType (n +ℕ m)
increaseS m (xmt d t s) = xmt d (increaseT m t) (increaseS m s)
increaseS m (rec s) = rec (increaseS m s)
increaseS m (var x) = var (inject+ m x) -- should say increase here
increaseS m end = end
increaseT m TInt = TInt
increaseT m (TChn s) = TChn (increaseS m s)
-- weaken m is used to push a (closed) term under m new binders
weakenS : ∀ m → SType n → SType (n +ℕ m)
weakenT : ∀ m → TType n → TType (n +ℕ m)
weakenS m (xmt d t s) = xmt d (weakenT m t) (weakenS m s)
weakenS m (rec s) = rec (weakenS m s)
weakenS m (var x) = var (inject+ m x)
weakenS m end = end
weakenT m TInt = TInt
weakenT m (TChn s) = TChn (weakenS m s)
weaken1S : SType n → SType (suc n)
weaken1S s = weakenS 1 s
-- this one behaves correctly
weaken'S : ∀ m → Fin (suc n) → SType n → SType (n +ℕ m)
weaken'T : ∀ m → Fin (suc n) → TType n → TType (n +ℕ m)
weaken'S m i (xmt d T S) = xmt d (weaken'T m i T) (weaken'S m i S)
weaken'S m i end = end
weaken'S m i (rec S) = rec (weaken'S m (suc i) S)
weaken'S {suc n} m zero (var x) = var (increase m x)
weaken'S {suc n} m (suc i) (var x)
with compare i x
weaken'S {suc n} m (suc .(inject least)) (var x) | less .x least = var (increase m x)
weaken'S {suc n} m (suc i) (var .i) | equal .i = var (inject+ m i)
weaken'S {suc n} m (suc i) (var .(inject least)) | greater .i least = var (inject+ m (inject least))
weaken'T m i TInt = TInt
weaken'T m i (TChn S) = TChn (weaken'S m i S)
weaken'S0 : ∀ m → SType n → SType (n +ℕ m)
weaken'S0 m S = weaken'S m (fromℕ _) S
----------------------------------------------------------------------
-- examples
module Examples-Weakening where
sv0 sv1 : SType 1
sv0 = rec (var zero)
sv1 = rec (var (suc zero))
sv0-w : SType 2
sv0-w = weaken'S 1 zero sv0
step0 : weaken'S{2} 1 zero (var zero) ≡ var (suc zero)
× weaken'S{2} 1 zero (var (suc zero)) ≡ var (suc (suc zero))
step0 = refl , refl
step1 : weaken'S{2} 1 (suc zero) (var zero) ≡ var zero
× weaken'S{2} 1 (suc zero) (var (suc zero)) ≡ var (suc (suc zero))
step1 = refl , refl
stepr1 : weaken'S 1 zero sv0 ≡ rec (var zero)
× weaken'S 1 zero sv1 ≡ rec (var (suc (suc zero)))
stepr1 = refl , refl
stepr2 : weaken'S{3} 1 zero (rec (rec (var zero))) ≡ rec (rec (var zero))
× weaken'S{3} 1 zero (rec (rec (var (suc zero)))) ≡ rec (rec (var (suc zero)))
× weaken'S{3} 1 zero (rec (rec (var (suc (suc zero))))) ≡ rec (rec (var (suc (suc (suc zero)))))
stepr2 = refl , refl , refl
sx1 : SType 0
sx1 = rec (xmt SND TInt (var zero))
sx1-w : SType 1
sx1-w = rec (xmt SND TInt (var zero))
sx1=sx1-w : sx1-w ≡ weaken'S 1 zero sx1
sx1=sx1-w = refl
sx2 : SType 1
sx2 = xmt SND TInt (var zero)
sx2-w1 : SType 2
sx2-w1 = xmt SND TInt (var (suc zero))
sx2-w0 : SType 2
sx2-w0 = xmt SND TInt (var zero)
sx2=w : sx2-w1 ≡ weaken'S 1 zero sx2
× sx2-w0 ≡ weaken'S 1 (suc zero) sx2
sx2=w = refl , refl
open Alternative-Substitution
step0-r : renameS suc sv0 ≡ rec (var zero)
× renameS suc sv1 ≡ rec (var (suc (suc zero)))
step0-r = refl , refl
step1-r : renameS{1} suc (rec (rec (var zero))) ≡ (rec (rec (var zero)))
× renameS{1} suc (rec (rec (var (suc zero)))) ≡ (rec (rec (var (suc zero))))
× renameS{1} suc (rec (rec (var (suc (suc zero))))) ≡ (rec (rec (var (suc (suc (suc zero))))))
step1-r = refl , refl , refl
----------------------------------------------------------------------
-- contractivity
mutual
data ContractiveT {n} : TType n → Set where
con-int : ContractiveT TInt
con-chn : Contractive zero S → ContractiveT (TChn S)
data Contractive (i : Fin (suc n)) : SType n → Set where
con-xmt : ContractiveT t → Contractive zero s → Contractive i (xmt d t s)
con-end : Contractive i end
con-rec : Contractive (suc i) S → Contractive i (rec S)
con-var : i ≤ inject₁ j → Contractive i (var j)
----------------------------------------------------------------------
module Examples-Contractivity where
open Examples-Types
cn1 : ¬ Contractive {2} (suc zero) (var zero)
cn1 (con-var ())
cp1 : Contractive {2} zero (var (suc zero))
cp1 = con-var z≤n
cp0 : Contractive {2} zero (var zero)
cp0 = con-var z≤n
cs1 : Contractive zero s1
cs1 = con-rec (con-xmt con-int (con-var z≤n))
cs2 : Contractive zero s2
cs2 = con-rec (con-rec (con-xmt con-int (con-var z≤n)))
cs2a : Contractive zero s2a
cs2a = con-rec (con-rec (con-xmt con-int (con-var z≤n)))
sp2 : SType 0
sp2 = s3
cp2 : Contractive zero sp2
cp2 = con-rec (con-xmt con-int (con-rec (con-var (s≤s z≤n))))
sn2 : SType 0
sn2 = (rec (xmt SND TInt (rec (var zero))))
cn2 : ¬ Contractive zero sn2
cn2 (con-rec (con-xmt con-int (con-rec (con-var ()))))
module Alternative-Unfolding where
open Alternative-Substitution
-- one top-level unfolding if possible
unfold₁ : SType n → SType n
unfold₁ (rec S) = substS1 (rec S) S
unfold₁ S@(xmt d T x) = S
unfold₁ S@end = S
unfold₁ S@(var x) = S
-- unfold all the way
unfold : (S : SType n) (σ : SType n → SType m) → SType m
unfold S@(xmt d T S') σ = σ S
unfold end σ = end
unfold (rec S) σ = unfold S (σ ∘ substS1 (rec S))
unfold S@(var x) σ = σ S
unfold₀ : SType n → SType n
unfold₀ S = unfold S id
----------------------------------------------------------------------
-- substitution
ssubst : SType (suc n) → Fin (suc n) → SType 0 → SType n
tsubst : TType (suc n) → Fin (suc n) → SType 0 → TType n
ssubst (xmt d t s) i s0 = xmt d (tsubst t i s0) (ssubst s i s0)
ssubst (rec s) i s0 = rec (ssubst s (suc i) s0)
ssubst {n} (var zero) zero s0 = increaseS n s0
ssubst {suc n} (var zero) (suc i) s0 = var zero
ssubst (var (suc x)) zero s0 = var x
ssubst {suc n} (var (suc x)) (suc i) s0 = increaseS 1 (ssubst (var x) i s0)
ssubst end i s0 = end
tsubst TInt i s₀ = TInt
tsubst (TChn s) i s₀ = TChn (ssubst s i s₀)
----------------------------------------------------------------------
-- unfolding to first non-rec constructor
unfold : (s : SType n) (c : Contractive i s) (σ : SType n → SType 0) → SType 0
unfold (xmt d t s) (con-xmt ct c) σ = σ (xmt d t s)
unfold end con-end σ = end
unfold (rec s) (con-rec c) σ = unfold s c (σ ∘ λ sn' → ssubst sn' zero (σ (rec s)))
unfold {i = zero} (var x) (con-var z≤n) σ = σ (var x)
unfold {i = suc i} (var zero) (con-var ()) σ
unfold {i = suc i} (var (suc x)) (con-var (s≤s x₁)) σ = unfold (var x) (con-var x₁) (σ ∘ increaseS 1)
unfold₀ : (S : SType 0) (c : Contractive zero S) → SType 0
unfold₀ S c = unfold S c id
----------------------------------------------------------------------
module Examples-Unfold where
open Examples-Types
c1 : Contractive zero s1
c1 = con-rec (con-xmt con-int (con-var z≤n))
s11 : SType 0
s11 = xmt SND TInt s1
u-s1=s11 : unfold s1 c1 id ≡ s11
u-s1=s11 = refl
c2 : Contractive zero s2
c2 = con-rec (con-rec (con-xmt con-int (con-var z≤n)))
u-s2=s11 : unfold s2 c2 id ≡ s11
u-s2=s11 = cong (xmt SND TInt) (cong rec (cong (xmt SND TInt) refl))
----------------------------------------------------------------------
-- contractivity is decidable
infer-contractiveT : (t : TType n) → Dec (ContractiveT t)
infer-contractive : (s : SType n) (i : Fin (suc n)) → Dec (Contractive i s)
infer-contractiveT TInt = yes con-int
infer-contractiveT (TChn s)
with infer-contractive s zero
infer-contractiveT (TChn s) | yes p = yes (con-chn p)
infer-contractiveT (TChn s) | no ¬p = no (λ { (con-chn cs) → ¬p cs })
infer-contractive (xmt d t s) i
with infer-contractiveT t | infer-contractive s zero
infer-contractive (xmt d t s) i | yes p | yes p₁ = yes (con-xmt p p₁)
infer-contractive (xmt d t s) i | yes p | no ¬p = no (λ { (con-xmt ct cs) → ¬p cs })
infer-contractive (xmt d t s) i | no ¬p | yes p = no (λ { (con-xmt ct cs) → ¬p ct })
infer-contractive (xmt d t s) i | no ¬p | no ¬p₁ = no (λ { (con-xmt ct cs) → ¬p₁ cs})
infer-contractive end i = yes con-end
infer-contractive (rec s) i
with infer-contractive s (suc i)
infer-contractive (rec s) i | yes p = yes (con-rec p)
infer-contractive (rec s) i | no ¬p = no (λ { (con-rec c) → ¬p c })
infer-contractive (var x) zero = yes (con-var z≤n)
infer-contractive (var zero) (suc i) = no (λ { (con-var ()) })
infer-contractive (var (suc x)) (suc i)
with infer-contractive (var x) i
infer-contractive (var (suc x)) (suc i) | yes (con-var x₁) = yes (con-var (s≤s x₁))
infer-contractive (var (suc x)) (suc i) | no ¬p = no (λ { (con-var (s≤s y)) → ¬p (con-var y) })
----------------------------------------------------------------------
module Examples-Inference where
open Examples-Contractivity
infer-p2 : infer-contractive sp2 zero ≡ yes cp2
infer-p2 = refl
infer-n2 : infer-contractive sn2 zero ≡ no cn2
infer-n2 = cong no (ext (λ { (con-rec (con-xmt con-int (con-rec (con-var ())))) }))
----------------------------------------------------------------------
-- RT: if a type is contractive at level i, then it is also contractive at any smaller level
c-weakenS : {S : SType n} (i' : Fin′ i) → Contractive i S → Contractive (inject i') S
c-weakenS i' (con-rec cis) = con-rec (c-weakenS (suc i') cis)
c-weakenS i' (con-xmt x cis) = con-xmt x cis
c-weakenS i' con-end = con-end
c-weakenS {i = suc i} i' (con-var {zero} ())
c-weakenS {i = suc i} zero (con-var {suc n} (s≤s x)) = con-var z≤n
c-weakenS {i = suc i} (suc i') (con-var {suc n} (s≤s x)) = con-var (s≤s (trans-< x))
c-weakenS₁ : {S : SType n} → Contractive (suc i) S → Contractive (inject₁ i) S
c-weakenS₁ (con-rec cis) = con-rec (c-weakenS₁ cis)
c-weakenS₁ (con-xmt x cis) = con-xmt x cis
c-weakenS₁ con-end = con-end
c-weakenS₁ {zero} {()} (con-var x)
c-weakenS₁ {suc n} {zero} (con-var x) = con-var z≤n
c-weakenS₁ {suc n} {suc i} (con-var x) = con-var (pred-≤ x)
c-weakenS! : {S : SType n} → Contractive i S → Contractive zero S
c-weakenS! {i = zero} (con-rec cis) = con-rec cis
c-weakenS! {i = suc i} (con-rec cis) = con-rec (c-weakenS (suc zero) cis)
c-weakenS! {n} {i} (con-xmt x cis) = con-xmt x cis
c-weakenS! {n} {i} con-end = con-end
c-weakenS! {n} {i} (con-var x) = con-var z≤n
ct-weaken+ : {T : TType n} → ContractiveT T → ContractiveT (weaken'T 1 zero T)
c-weaken+ : {S : SType n} → Contractive i S → Contractive (suc i) (weaken'S 1 zero S)
ct-weaken+ con-int = con-int
ct-weaken+ (con-chn x) = con-chn (c-weakenS! (c-weaken+ x))
c-weaken+ (con-xmt x cis) = con-xmt (ct-weaken+ x) (c-weakenS! (c-weaken+ cis))
c-weaken+ con-end = con-end
c-weaken+ (con-rec cis) = con-rec {!!} -- gives a problem: (c-weaken+ {!cis!})
c-weaken+ {suc n} {i} {var j} (con-var i≤j) = con-var (s≤s i≤j)
module Alternative-Multiple-Substitution-Preserves where
open Alternative-Substitution
subst-contr-T :
{T : TType m}
(σ : Fin m → SType n)
(γ : (j : Fin m) → Contractive i (σ j))
(ct : ContractiveT T)
→ ContractiveT (substT σ T)
subst-contr-S : ∀ {k} →
(σ : Fin m → SType n)
(γ : (j : Fin m) → Contractive k (σ j))
(c : Contractive zero S)
→ Contractive k (substS σ S)
subst-contr-T σ γ con-int = con-int
subst-contr-T σ γ (con-chn cs) = con-chn (subst-contr-S σ (c-weakenS! ∘ γ) cs)
subst-contr-S σ γ (con-xmt ct cs) =
con-xmt (subst-contr-T σ γ ct) (subst-contr-S σ (c-weakenS! ∘ γ) cs)
subst-contr-S σ γ con-end = con-end
subst-contr-S σ γ (con-rec cs) = con-rec (subst-contr-S (extS σ) {!extS!} (c-weakenS₁ cs))
subst-contr-S σ γ (con-var{j} x) = γ j
module Alternative-Substitution-Preserves where
open Alternative-Substitution
subst-contr-T :
{S' : SType n} (c' : Contractive i S')
{T : TType (suc n)} (c : ContractiveT T)
→ ContractiveT (substT1 S' T)
subst-contr-S :
{S' : SType n} (c' : Contractive i S')
{S : SType (suc n)} (c : Contractive (inject₁ i) S)
→ Contractive i (substS1 S' S)
subst-contr-T c' con-int = con-int
subst-contr-T c' (con-chn x) = con-chn (subst-contr-S (c-weakenS! c') x)
subst-contr-S c' (con-xmt ct cs) =
con-xmt (subst-contr-T c' ct) (subst-contr-S (c-weakenS! c') cs)
subst-contr-S c' con-end = con-end
subst-contr-S c' (con-rec c) = con-rec {!!} -- (subst-contr-S {!!} {!c!})
subst-contr-S c' (con-var x) = {!!}
module Alternative-SingleSubstitution where
----------------------------------------------------------------------
-- single substitution of j ↦ Sj
subst1T : (T : TType (suc n)) (j : Fin (suc n)) (Sj : SType n) → TType n
subst1S : (S : SType (suc n)) (j : Fin (suc n)) (Sj : SType n) → SType n
subst1T TInt j Sj = TInt
subst1T (TChn S) j Sj = TChn (subst1S S j Sj)
subst1S (xmt d T S) j Sj = xmt d (subst1T T j Sj) (subst1S S j Sj)
subst1S end j Sj = end
subst1S (rec S) j Sj = rec (subst1S S (suc j) (weaken'S 1 zero Sj))
subst1S (var x) j Sj
with compare x j
subst1S (var .(inject least)) j Sj | less .j least = var (inject! least)
subst1S (var x) .x Sj | equal .x = Sj
subst1S (var (suc x)) .(inject least) Sj | greater .(suc x) least = var x
{- the termination checker doesnt like this:
subst1S (var zero) zero Sj = Sj
subst1S {suc n} (var zero) (suc j) Sj = var zero
subst1S (var (suc x)) zero Sj = var x
subst1S (var (suc x)) (suc j) Sj = subst1S (var (inject₁ x)) (inject₁ j) Sj
-}
unfold1S : (S : SType 0) → SType 0
unfold1S (xmt d T S) = xmt d T S
unfold1S end = end
unfold1S (rec S) = subst1S S zero (rec S)
unfoldSS : (S : SType n) → SType n
unfoldSS (xmt d T S) = xmt d T S
unfoldSS end = end
unfoldSS (rec S)
with unfoldSS S
... | ih = subst1S ih zero (rec ih)
unfoldSS (var x) = var x
----------------------------------------------------------------------
-- max index substitution
subst-maxT : (Sm : SType n) (T : TType (suc n)) → TType n
subst-maxS : (Sm : SType n) (S : SType (suc n)) → SType n
subst-maxT Sm TInt = TInt
subst-maxT Sm (TChn S) = TChn (subst-maxS Sm S)
subst-maxS Sm (xmt d T S) = xmt d (subst-maxT Sm T) (subst-maxS Sm S)
subst-maxS Sm end = end
subst-maxS Sm (rec S) = rec (subst-maxS (weaken'S 1 zero Sm) S)
subst-maxS Sm (var x)
with max? x
subst-maxS Sm (var x) | yes p = Sm
subst-maxS Sm (var x) | no ¬p = var (reduce ¬p)
unfoldmS : (S : SType n) → SType n
unfoldmS (xmt d T S) = xmt d T S
unfoldmS end = end
unfoldmS (rec S) = subst-maxS (rec S) S
unfoldmS {suc n} (var x) = var x
----------------------------------------------------------------------
-- max substitution preserves contractivity
subst-contr-mT :
{T : TType (suc n)} (c : ContractiveT T)
{S' : SType n} (c' : Contractive i S')
→ ContractiveT (subst-maxT S' T)
subst-contr-mS :
-- {i : Fin (suc (suc n))}
{S : SType (suc n)} (c : Contractive (inject₁ i) S)
{S' : SType n} (c' : Contractive i S')
→ Contractive i (subst-maxS S' S)
subst-contr-mT con-int csm = con-int
subst-contr-mT (con-chn x) csm = con-chn (c-weakenS! (subst-contr-mS x (c-weakenS! csm)))
subst-contr-mS (con-xmt x cs) csm = con-xmt (subst-contr-mT x csm) (subst-contr-mS cs (c-weakenS! csm))
subst-contr-mS con-end csm = con-end
subst-contr-mS (con-rec cs) csm = con-rec (subst-contr-mS cs (c-weaken+ csm))
subst-contr-mS {S = var j} (con-var x) csm
with max? j
subst-contr-mS {i = _} {var j} (con-var x) csm | yes p = csm
subst-contr-mS {i = _} {var j} (con-var x) csm | no ¬p = con-var (lemma-reduce x ¬p)
-- one step unfolding preserves contractivity
unfold-contr : Contractive i S → Contractive i (unfoldmS S)
unfold-contr (con-xmt x c) = con-xmt x c
unfold-contr con-end = con-end
unfold-contr (con-rec c) = subst-contr-mS (c-weakenS₁ c) (con-rec c)
unfold-contr (con-var x) = {!!}
-- multiple unfolding
-- terminates even for non-contractive types because it delays the substitution
unfold! : (S : SType n) (σ : SType n → SType 0) → SType 0
unfold! (xmt d T S) σ = σ (xmt d T S)
unfold! end σ = end
unfold! (rec S) σ = unfold! S (σ ∘ subst-maxS (rec S))
unfold! (var x) σ = σ (var x)
-- unclear how this could be completed
-- unfold!-contr : Contractive i S → Contractive i (unfold! S id)
-- unfold!-contr (con-xmt x cs) = con-xmt x cs
-- unfold!-contr con-end = con-end
-- unfold!-contr (con-rec cs) = {!!}
-- multiple unfolding preserves contractivity
TCType : (n : ℕ) → Set
TCType n = Σ (TType n) ContractiveT
SCType : (n : ℕ) → Fin (suc n) → Set
SCType n i = Σ (SType n) (Contractive i)
unfold!! : (SC : SCType n i) → (SCType n i → SCType 0 zero) → SCType 0 zero
unfold!! SC@(xmt d T S , con-xmt x cs) σ = σ SC
unfold!! (end , con-end) σ = end , con-end
unfold!! (rec S , con-rec cs) σ =
unfold!! (S , cs) (σ ∘ λ{ (S' , c') → (subst-maxS (rec S) S') , (subst-contr-mS (c-weakenS₁ c') (con-rec cs)) })
unfold!! SC@(var x , con-var x₁) σ = σ SC
{-# TERMINATING #-}
unfold!!! : ∀ {m n : ℕ} → SCType (n +ℕ m) zero → (SCType (n +ℕ m) zero → SCType m zero) → SCType m zero
unfold!!! SC@(xmt d T S , con-xmt x cs) σ = σ SC
unfold!!! (end , con-end) σ = end , con-end
unfold!!! (rec S , con-rec cs) σ =
unfold!!! (S , c-weakenS₁ cs) (σ ∘ λ SC → (subst-maxS (rec S) (proj₁ SC)) , (subst-contr-mS (proj₂ SC) (con-rec cs)))
unfold!!! SC@(var x , con-var x₁) σ = σ SC
----------------------------------------------------------------------
-- equivalence requires multiple unfolding
variable
T₁ T₂ : TCType n
S₁ S₂ : SCType n i
data EquivT (R : SCType n zero → SCType n zero → Set) : TCType n → TCType n → Set where
eq-int : EquivT R (TInt , con-int) (TInt , con-int)
eq-chn : R S₁ S₂ →
EquivT R (TChn (proj₁ S₁) , con-chn (proj₂ S₁))
(TChn (proj₁ S₂) , con-chn (proj₂ S₂))
data EquivS (R : SCType n zero → SCType n zero → Set) :
(S₁ S₂ : SCType n zero) → Set where
eq-end :
EquivS R (end , con-end) (end , con-end)
eq-xmt : (d : Dir) →
EquivT R T₁ T₂ →
R S₁ S₂ →
EquivS R (xmt d (proj₁ T₁) (proj₁ S₁) , con-xmt (proj₂ T₁) (proj₂ S₁))
(xmt d (proj₁ T₂) (proj₁ S₂) , con-xmt (proj₂ T₂) (proj₂ S₂))
eq-rec-l :
let S = proj₁ S₁ in
let cs = proj₂ S₁ in
EquivS R (subst-maxS (rec S) S , subst-contr-mS (c-weakenS₁ cs) (con-rec cs)) S₂ →
EquivS R (rec S , con-rec cs) S₂
eq-rec-r :
let S = proj₁ S₂ in
let cs = proj₂ S₂ in
EquivS R S₁ (subst-maxS (rec S) S , subst-contr-mS (c-weakenS₁ cs) (con-rec cs)) →
EquivS R S₁ (rec S , con-rec cs)
record Equiv (S₁ S₂ : SCType 0 zero) : Set where
coinductive
field force : EquivS Equiv (unfold!! S₁ id) (unfold!! S₂ id)
record Equiv' (S₁ S₂ : SCType n zero) : Set where
coinductive
field force : EquivS Equiv' (unfold!!!{n = 0} S₁ id) (unfold!!!{n = 0} S₂ id)
{-# TERMINATING #-}
equivt-refl : ∀ T → EquivT Equiv T T
equivs-refl : ∀ S → EquivS Equiv S S
equiv-refl : ∀ S → Equiv S S
equivt-refl (TInt , con-int) = eq-int
equivt-refl (TChn S , con-chn x) = eq-chn (equiv-refl (S , x))
equivs-refl (xmt d t s , con-xmt ct cs) = eq-xmt d (equivt-refl (t , ct)) (equiv-refl (s , cs))
equivs-refl (end , con-end) = eq-end
equivs-refl (rec s , con-rec cs) = eq-rec-l (eq-rec-r (equivs-refl ((subst-maxS (rec s) s) , (subst-contr-mS (c-weakenS₁ cs) (con-rec cs)))))
Equiv.force (equiv-refl S) = equivs-refl (unfold!! S id)
----------------------------------------------------------------------
-- prove equivalence of one-level unrolling
-- μX S ≈ S [μX S / X]
module μ-unrolling where
unfold-≡ : ∀ S cs →
unfold!! (S , cs) (λ { (S' , c') → (subst-maxS (rec S) S') , (subst-contr-mS (c-weakenS₁ c') (con-rec cs)) })
≡
(unfold!!
(subst-maxS (rec S) S ,
subst-contr-mS (c-weakenS₁ cs) (con-rec cs))
id)
unfold-≡ (xmt d T S) (con-xmt x cs) = refl
unfold-≡ end con-end = refl
unfold-≡ (rec S) (con-rec cs) = {!!}
unfold-≡ (var x) (con-var x₁)
with max? x
unfold-≡ (var x) (con-var x₁) | yes p = {!!}
unfold-≡ (var x) (con-var x₁) | no ¬p = refl
unroll : SCType n i → SCType n i
unroll SC@(xmt d T S , con-xmt x cs) = SC
unroll SC@(end , con-end) = SC
unroll (rec S , cs@(con-rec cs')) = (subst-maxS (rec S) S) , (subst-contr-mS (c-weakenS₁ cs') cs)
unroll SC@(var x , con-var x₁) = SC
unroll-equiv : (SC : SCType 0 zero) → Equiv SC (unroll SC)
Equiv.force (unroll-equiv SC@(xmt d T S , con-xmt x cs))
with unroll SC
... | SC' = equivs-refl SC'
Equiv.force (unroll-equiv (end , con-end)) = eq-end
Equiv.force (unroll-equiv (rec S , con-rec cs))
rewrite unfold-≡ S cs =
let S₁ = unfold!! (S , cs) (λ { (S' , c') → (subst-maxS (rec S) S') , (subst-contr-mS (c-weakenS₁ c') (con-rec cs)) }) in
let eqx = equivs-refl S₁ in
{!S₁!}
----------------------------------------------------------------------
-- prove the folk theorem
-- μX μY S = μY [Y/X]S
module μ-examples where
r1 : SType 0
r1 = rec (rec (xmt SND (TChn (var zero)) (var (suc zero))))
r2 : SType n
r2 = rec (xmt SND (TChn (var zero)) (var zero))
r2a : SType 0
r2a = rec r2
r2b : SType n
r2b = rec (rec (xmt SND (TChn (var zero)) (var (suc zero))))
r2-unfolded : SType 0
r2-unfolded = xmt SND (TChn r2) r2
r2-unf : SType 0
r2-unf = rec (xmt SND (TChn (var zero)) r2b)
rc2-unf : SCType 0 zero
rc2-unf = r2-unf , (con-rec (con-xmt (con-chn (con-var z≤n)) (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n))))))
rc1 : SCType 0 zero
rc1 = r1 , (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n))))
rc2 : SCType n zero
rc2 = r2 , (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))
rc2a : SCType 0 zero
rc2a = r2a , con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))
rc2b : SCType n zero
rc2b = r2b , con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))
rc2-unfolded : SCType 0 zero
rc2-unfolded = r2-unfolded , (con-xmt (con-chn (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))) (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n))))
rc2=rc2 : Equiv rc2 rc2
Equiv.force rc2=rc2 = eq-xmt SND (eq-chn rc2=rc2) rc2=rc2
rc2=rc2-unfolded : Equiv rc2 rc2-unfolded
Equiv.force rc2=rc2-unfolded = eq-xmt SND (eq-chn rc2=rc2) rc2=rc2
weak-r2 : SType 0
weak-r2 = rec (weaken'S 1 zero r2)
weak-rc2 : SCType 0 zero
weak-rc2 = weak-r2 , (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n))))
r2-weak : SType n
r2-weak = rec (xmt SND ((TChn (weaken'S 1 zero (rec (rec (xmt SND (TChn (var (suc zero))) (var (suc zero)))))))) ((weaken'S 1 zero (rec (rec (xmt SND (TChn (var (suc zero))) (var (suc zero))))))))
rc2-weak : SCType 0 zero
rc2-weak = r2-weak , con-rec (con-xmt (con-chn (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n))))) (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))))
rc2=rc2a : Equiv rc2 rc2a
Equiv.force rc2=rc2a = eq-xmt SND (eq-chn rc2=rc2a) rc2=rc2a
rc2=xxxrc2b : Equiv' rc2 rc2-unf
rc2=rc2b : Equiv' rc2 rc2b
Equiv'.force rc2=xxxrc2b = eq-xmt SND (eq-chn rc2=xxxrc2b) rc2=rc2b
Equiv'.force rc2=rc2b = eq-xmt SND (eq-chn rc2=rc2b) rc2=xxxrc2b
rc2=rc2-weak : Equiv' rc2 rc2-weak
Equiv'.force rc2=rc2-weak = eq-xmt SND (eq-chn {!rc2=rc2b!}) {!!}
rc2=weak-rc2 : Equiv rc2 weak-rc2
Equiv.force rc2=weak-rc2 = eq-xmt SND (eq-chn rc2=rc2a) rc2=rc2a
r3 : SType 0
r3 = rec (xmt SND (TChn (var zero)) (weaken'S 1 zero r1))
rc3 : SCType 0 zero
rc3 = r3 , con-rec (con-xmt (con-chn (con-var z≤n)) (con-rec (con-rec (con-xmt (con-chn (con-var z≤n)) (con-var z≤n)))))
rc1=rc2 : Equiv rc1 rc2
rc3=rc2 : Equiv rc3 rc2
Equiv.force rc1=rc2 = eq-xmt SND (eq-chn rc1=rc2) rc3=rc2
Equiv.force rc3=rc2 = eq-xmt SND (eq-chn rc3=rc2) rc1=rc2
-- end examples
----------------------------------------------------------------------
recrec : SType 2 → SType 0 × SType 0
recrec S = rec (rec S) , rec (subst-maxS (var zero) S)
recrec2 : SType 2 → SType 1
recrec2 S = rec S
conrr1 : {S : SType 2} → Contractive (suc (suc zero)) S → Contractive zero (rec (rec S))
conrr1 cs = con-rec (con-rec cs)
conrr2 : {S : SType 2} → Contractive (suc (suc zero)) S → Contractive (suc zero) (subst-maxS (var zero) S)
conrr2 cs = subst-contr-mS {!subst-contr-mS!} (con-var (s≤s z≤n))
sc-rec : SCType (suc n) (suc i) → SCType n i
sc-rec (S , cs) = (rec S , con-rec cs)
¬fromN≤x : (x : Fin n) → ¬ (fromℕ n ≤ inject₁ x)
¬fromN≤x {suc n} zero ()
¬fromN≤x {suc n} (suc x) (s≤s n≤x) = ¬fromN≤x x n≤x
μμ-lem-gen : {n : ℕ}
→ (S : SType (suc (suc n)))
→ Contractive (suc (suc (fromℕ n))) S
→ Contractive (suc (fromℕ n)) (subst-maxS (var (fromℕ n)) S)
μμ-lem-gen (xmt d T S) (con-xmt x cs) = con-xmt (subst-contr-mT x (con-var z≤n)) (subst-contr-mS cs (con-var z≤n))
μμ-lem-gen end con-end = con-end
μμ-lem-gen (rec S) (con-rec cs) = con-rec (μμ-lem-gen S cs)
μμ-lem-gen (var zero) (con-var ())
μμ-lem-gen (var (suc zero)) (con-var (s≤s ()))
μμ-lem-gen (var (suc (suc x))) (con-var (s≤s (s≤s x₁)))
with ¬fromN≤x x x₁
μμ-lem-gen (var (suc (suc x))) (con-var (s≤s (s≤s x₁))) | ()
μμ-lemma : (S : SType 2) → Contractive (suc (suc zero)) S → Contractive (suc zero) (subst-maxS (var zero) S)
μμ-lemma S cs = μμ-lem-gen S cs
μμ-gen : (S : SType (suc (suc n))) (cs : Contractive (suc (suc (fromℕ n))) S) →
Equiv' (sc-rec (sc-rec (S , {!!})))
(sc-rec ((subst-maxS (var zero) S) , {!!}))
μμ-gen S cs = {!!}
μμ1 : (S : SType 2) (cs : Contractive (suc (suc zero)) S) →
Equiv (sc-rec (sc-rec (S , cs)))
(sc-rec ((subst-maxS (var zero) S) , μμ-lemma S cs))
Equiv.force (μμ1 (xmt d T S) (con-xmt x cs)) = {!!}
Equiv.force (μμ1 end con-end) = eq-end
Equiv.force (μμ1 (rec S) (con-rec cs)) = {!!}
Equiv.force (μμ1 (var x) (con-var x₁)) = {!!}
-- or μX μY S = μX [X/Y]S
μμ2 : (S : SType 2) (cs : Contractive (suc (suc zero)) S) →
Equiv (sc-rec (sc-rec (S , cs)))
let xxx = subst-maxS {!sc-rec!} (rec S) in (sc-rec ((subst-maxS (var zero) S) , (subst-contr-mS (c-weakenS₁ cs) (con-var {!!}))))
μμ2 S cs = {!!}
|
{
"alphanum_fraction": 0.5745780343,
"avg_line_length": 33.2972067039,
"ext": "agda",
"hexsha": "1b396aefcda2e04fe6bbc5a71140cb3c753e1f6e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "peterthiemann/dual-session",
"max_forks_repo_path": "src/DualContractive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "peterthiemann/dual-session",
"max_issues_repo_path": "src/DualContractive.agda",
"max_line_length": 198,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "peterthiemann/dual-session",
"max_stars_repo_path": "src/DualContractive.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:43:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-13T05:43:25.000Z",
"num_tokens": 11502,
"size": 29801
}
|
{-
In this file we apply the cubical machinery to Martin Hötzel-Escardó's
structure identity principle:
https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.SIP where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence renaming (ua-pathToEquiv to ua-pathToEquiv')
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Foundations.Structure public
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Level
S : Type ℓ₁ → Type ℓ₂
-- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be
-- a proposition. Indeed this type should correspond to the ways s and t can be identified
-- as S-structures. This we call a standard notion of structure or SNS.
-- We will use a different definition, but the two definitions are interchangeable.
SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
SNS {ℓ₁} S ι = ∀ {X : Type ℓ₁} (s t : S X) → ι (X , s) (X , t) (idEquiv X) ≃ (s ≡ t)
-- We introduce the notation for structure preserving equivalences a
-- bit differently, but this definition doesn't actually change from
-- Escardó's notes.
_≃[_]_ : (A : TypeWithStr ℓ₁ S) (ι : StrEquiv S ℓ₂) (B : TypeWithStr ℓ₁ S) → Type (ℓ-max ℓ₁ ℓ₂)
A ≃[ ι ] B = Σ[ e ∈ typ A ≃ typ B ] (ι A B e)
-- The following PathP version of SNS is a bit easier to work with
-- for the proof of the SIP
UnivalentStr : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
UnivalentStr {ℓ₁} S ι =
{A B : TypeWithStr ℓ₁ S} (e : typ A ≃ typ B)
→ ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B)
-- A quick sanity-check that our definition is interchangeable with
-- Escardó's. The direction SNS→UnivalentStr corresponds more or less
-- to a dependent EquivJ formulation of Escardó's homomorphism-lemma.
UnivalentStr→SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃)
→ UnivalentStr S ι → SNS S ι
UnivalentStr→SNS S ι θ {X = X} s t =
ι (X , s) (X , t) (idEquiv X)
≃⟨ θ (idEquiv X) ⟩
PathP (λ i → S (ua (idEquiv X) i)) s t
≃⟨ transportEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = X} j i)) s t) ⟩
s ≡ t
■
SNS→UnivalentStr : (ι : StrEquiv S ℓ₃) → SNS S ι → UnivalentStr S ι
SNS→UnivalentStr {S = S} ι θ {A = A} {B = B} e = EquivJ P C e (str A) (str B)
where
Y = typ B
P : (X : Type _) → X ≃ Y → Type _
P X e' = (s : S X) (t : S Y) → ι (X , s) (Y , t) e' ≃ PathP (λ i → S (ua e' i)) s t
C : (s t : S Y) → ι (Y , s) (Y , t) (idEquiv Y) ≃ PathP (λ i → S (ua (idEquiv Y) i)) s t
C s t =
ι (Y , s) (Y , t) (idEquiv Y)
≃⟨ θ s t ⟩
s ≡ t
≃⟨ transportEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = Y} (~ j) i)) s t) ⟩
PathP (λ i → S (ua (idEquiv Y) i)) s t
■
TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S) → Type (ℓ-max (ℓ-suc ℓ) ℓ₁)
TransportStr {ℓ} {S = S} α =
{X Y : Type ℓ} (e : X ≃ Y) (s : S X) → equivFun (α e) s ≡ subst S (ua e) s
TransportStr→UnivalentStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ TransportStr α → UnivalentStr S (EquivAction→StrEquiv α)
TransportStr→UnivalentStr {S = S} α τ {X , s} {Y , t} e =
equivFun (α e) s ≡ t
≃⟨ pathToEquiv (cong (_≡ t) (τ e s)) ⟩
subst S (ua e) s ≡ t
≃⟨ invEquiv (PathP≃Path _ _ _) ⟩
PathP (λ i → S (ua e i)) s t
■
UnivalentStr→TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ UnivalentStr S (EquivAction→StrEquiv α) → TransportStr α
UnivalentStr→TransportStr {S = S} α θ e s =
invEq (θ e) (transport-filler (cong S (ua e)) s)
invTransportStr : {S : Type ℓ → Type ℓ₂} (α : EquivAction S) (τ : TransportStr α)
{X Y : Type ℓ} (e : X ≃ Y) (t : S Y) → invEq (α e) t ≡ subst⁻ S (ua e) t
invTransportStr {S = S} α τ e t =
sym (transport⁻Transport (cong S (ua e)) (invEq (α e) t))
∙∙ sym (cong (subst⁻ S (ua e)) (τ e (invEq (α e) t)))
∙∙ cong (subst⁻ S (ua e)) (retEq (α e) t)
--- We can now define an invertible function
---
--- sip : A ≃[ ι ] B → A ≡ B
module _ {S : Type ℓ₁ → Type ℓ₂} {ι : StrEquiv S ℓ₃}
(θ : UnivalentStr S ι) (A B : TypeWithStr ℓ₁ S)
where
sip : A ≃[ ι ] B → A ≡ B
sip (e , p) i = ua e i , θ e .fst p i
SIP : A ≃[ ι ] B ≃ (A ≡ B)
SIP =
sip , isoToIsEquiv (compIso (Σ-cong-iso (invIso univalenceIso) (equivToIso ∘ θ)) ΣPathIsoPathΣ)
sip⁻ : A ≡ B → A ≃[ ι ] B
sip⁻ = invEq SIP
|
{
"alphanum_fraction": 0.6117877338,
"avg_line_length": 36.784,
"ext": "agda",
"hexsha": "15c2c1a1df74806c8440118003bd69a720287005",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Foundations/SIP.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Foundations/SIP.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Foundations/SIP.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1935,
"size": 4598
}
|
-- Andreas, 2016-07-25, issue #2108
-- test case and report by Jesper
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.pos.occ:70 #-}
open import Agda.Primitive
open import Agda.Builtin.Equality
lone = lsuc lzero
record Level-zero-or-one : Set where
field
level : Level
is-lower : (level ⊔ lone) ≡ lone
open Level-zero-or-one public
Coerce : ∀ {a} → a ≡ lone → Set₁
Coerce refl = Set
data Test : Set₁ where
test : Coerce (is-lower _) → Test
-- WAS:
-- Meta variable here triggers internal error.
-- Should succeed with unsolved metas.
|
{
"alphanum_fraction": 0.6725352113,
"avg_line_length": 18.9333333333,
"ext": "agda",
"hexsha": "2f54d639d4022c03d839e9ed5213420afa2c3ac9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2108.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2108.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2108.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 173,
"size": 568
}
|
module Base.Prelude where
open import Base.Prelude.Bool public
open import Base.Prelude.Integer public
open import Base.Prelude.List public
open import Base.Prelude.Pair public
open import Base.Prelude.Unit public
|
{
"alphanum_fraction": 0.7929515419,
"avg_line_length": 28.375,
"ext": "agda",
"hexsha": "43677e8ab235078ba00a19e0c73da0c203bb01a7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z",
"max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "FreeProving/free-compiler",
"max_forks_repo_path": "base/agda/Base/Prelude.agda",
"max_issues_count": 120,
"max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "FreeProving/free-compiler",
"max_issues_repo_path": "base/agda/Base/Prelude.agda",
"max_line_length": 39,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "FreeProving/free-compiler",
"max_stars_repo_path": "base/agda/Base/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z",
"num_tokens": 51,
"size": 227
}
|
module Holes.Test.Limited where
open import Holes.Prelude hiding (_⊛_)
open import Holes.Util
open import Holes.Term
open import Holes.Cong.Limited
open import Agda.Builtin.Equality using (_≡_; refl)
module Contrived where
infixl 5 _⊕_
infixl 6 _⊛_
infix 4 _≈_
-- A type of expression trees for natural number calculations
data Expr : Set where
zero : Expr
succ : Expr → Expr
_⊕_ _⊛_ : Expr → Expr → Expr
-- An unsophisticated 'equality' relation on the expression trees. Doesn't try
-- to make the operations associative.
data _≈_ : Expr → Expr → Set where
zero-cong : zero ≈ zero
succ-cong : ∀ {m n} → m ≈ n → succ m ≈ succ n
⊕-cong : ∀ {a a′ b b′} → a ≈ a′ → b ≈ b′ → a ⊕ b ≈ a′ ⊕ b′
⊛-cong : ∀ {a a′ b b′} → a ≈ a′ → b ≈ b′ → a ⊛ b ≈ a′ ⊛ b′
⊕-comm : ∀ a b → a ⊕ b ≈ b ⊕ a
-- Some lemmas that are necessary to proceed
≈-refl : ∀ {n} → n ≈ n
≈-refl {zero} = zero-cong
≈-refl {succ n} = succ-cong ≈-refl
≈-refl {m ⊕ n} = ⊕-cong ≈-refl ≈-refl
≈-refl {m ⊛ n} = ⊛-cong ≈-refl ≈-refl
{-
Each congruence in the database must have a type with the same shape as the
below, following these rules:
- A congruence `c` is for a single _top-level_ function `f`
- `c` may only be a congruence for _one_ of `f`'s arguments
- Each explicit argument to `f` must be an explicit argument to `c`
- The 'rewritten' version of the changing argument must follow as an implicit
argument to `c`
- The equation to do the local rewriting must be the next explicit argument
-}
open CongSplit _≈_ ≈-refl
⊕-cong₁ = two→one₁ ⊕-cong
⊕-cong₂ = two→one₂ ⊕-cong
⊛-cong₁ = two→one₁ ⊛-cong
⊛-cong₂ = two→one₂ ⊛-cong
succ-cong′ : ∀ n {n′} → n ≈ n′ → succ n ≈ succ n′
succ-cong′ _ = succ-cong
{-
Create the database of congruences.
- This is a list of (Name × ArgPlace × Congruence) triples.
- The `Name` is the (reflected) name of the function to which the congruence
applies.
- The `ArgPlace` is the index of the argument place that the congruence can
rewrite at. Make sure you take into account implicit and instance arguments
as well!
- The `Congruence` is a reflected copy of the congruence function, of type `Term`
-}
database
= (quote _⊕_ , 0 , quote ⊕-cong₁)
∷ (quote _⊕_ , 1 , quote ⊕-cong₂)
∷ (quote _⊛_ , 0 , quote ⊛-cong₁)
∷ (quote _⊛_ , 1 , quote ⊛-cong₂)
∷ (quote succ , 0 , quote succ-cong′)
∷ []
open AutoCong database
test1 : ∀ a b → succ ⌞ a ⊕ b ⌟ ≈ succ (b ⊕ a)
test1 a b = cong! (⊕-comm a b)
test2 : ∀ a b c → succ (⌞ a ⊕ b ⌟ ⊕ c) ≈ succ (b ⊕ a ⊕ c)
test2 a b c = cong! (⊕-comm a b)
test3 : ∀ a b c → succ (a ⊕ ⌞ b ⊕ c ⌟) ≈ succ (a ⊕ (c ⊕ b))
test3 a b c = cong! (⊕-comm b c)
-- We can use a proof obtained by pattern matching for `cong!`
test5 : ∀ a b c → a ≈ b ⊕ c × b ≈ succ c → succ (⌞ b ⌟ ⊕ c ⊛ a) ≈ succ (succ c ⊕ c ⊛ a)
test5 a b c (eq1 , eq2) = cong! eq2
record ∃ {a p} {A : Set a} (P : A → Set p) : Set (a ⊔ p) where
constructor _,_
field
evidence : A
proof : P evidence
-- We can use `cong!` to prove some part of the result even when it depends on
-- other parts of the result
test6 : ∀ a b c → b ⊕ c ≈ a × b ≈ succ c → ∃ λ x → succ (⌞ b ⊕ x ⌟ ⊕ a) ≈ succ (a ⊕ a)
test6 a b c (eq1 , eq2) = c , cong! eq1
-- Deep nesting
test7 : ∀ a b c
→ succ (a ⊕ succ (b ⊕ succ (c ⊕ succ (succ ⌞ b ⊕ c ⌟ ⊕ (a ⊕ b)))))
≈ succ (a ⊕ succ (b ⊕ succ (c ⊕ succ (succ ⌞ c ⊕ b ⌟ ⊕ (a ⊕ b)))))
test7 _ b c = cong! (⊕-comm b c)
module Propositional (+-comm : ∀ a b → a + b ≡ b + a) where
+-cong₁ : ∀ a b {a′} → a ≡ a′ → a + b ≡ a′ + b
+-cong₁ _ _ refl = refl
+-cong₂ : ∀ a b {b′} → b ≡ b′ → a + b ≡ a + b′
+-cong₂ _ _ refl = refl
suc-cong : ∀ n {n′} → n ≡ n′ → suc n ≡ suc n′
suc-cong _ refl = refl
database
= (quote _+_ , 0 , quote +-cong₁)
∷ (quote _+_ , 1 , quote +-cong₂)
∷ (quote suc , 0 , quote suc-cong)
∷ []
open AutoCong database
test1 : ∀ a b → suc ⌞ a + b ⌟ ≡ suc (b + a)
test1 a b = cong! (+-comm a b)
test2 : ∀ a b c → suc (⌞ a + b ⌟ + c) ≡ suc (b + a + c)
test2 a b c = cong! (+-comm a b)
test3 : ∀ a b c → suc (a + ⌞ b + c ⌟) ≡ suc (a + (c + b))
test3 a b c = cong! (+-comm b c)
test4 : ∀ a b c a′ → a ≡ a′ → suc (⌞ a ⌟ + b + c) ≡ suc (a′ + b + c)
test4 _ _ _ _ eq = cong! eq
|
{
"alphanum_fraction": 0.5548668503,
"avg_line_length": 30.25,
"ext": "agda",
"hexsha": "5d01eb8162a9d91eb91ed619e860054f6bc0225e",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-02T18:57:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-01-27T14:57:39.000Z",
"max_forks_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-holes",
"max_forks_repo_path": "src/Holes/Test/Limited.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_issues_repo_issues_event_max_datetime": "2020-08-31T20:58:33.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-16T10:47:58.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-holes",
"max_issues_repo_path": "src/Holes/Test/Limited.agda",
"max_line_length": 89,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-holes",
"max_stars_repo_path": "src/Holes/Test/Limited.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-03T15:02:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-01-28T10:56:46.000Z",
"num_tokens": 1837,
"size": 4356
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.