Search is not available for this dataset
text
string
meta
dict
module Properties where import Properties.Dec
{ "alphanum_fraction": 0.8510638298, "avg_line_length": 11.75, "ext": "agda", "hexsha": "a3c685d14e4bf15f70478c41eeec063755535eea", "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": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "FreakingBarbarians/luau", "max_forks_repo_path": "prototyping/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "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": "FreakingBarbarians/luau", "max_issues_repo_path": "prototyping/Properties.agda", "max_line_length": 23, "max_stars_count": 1, "max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FreakingBarbarians/luau", "max_stars_repo_path": "prototyping/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z", "num_tokens": 8, "size": 47 }
------------------------------------------------------------------------------ -- The alternating bit protocol (ABP) ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- This module define the ABP following the presentation in Dybjer and -- Sander (1989). module FOTC.Program.ABP.ABP where open import FOTC.Base open import FOTC.Base.Loop open import FOTC.Base.List open import FOTC.Data.Bool open import FOTC.Data.Stream.Type open import FOTC.Program.ABP.Fair.Type open import FOTC.Program.ABP.Terms ------------------------------------------------------------------------------ -- ABP equations postulate send ack out corrupt : D → D await : D → D → D → D → D postulate send-eq : ∀ b i is ds → send b · (i ∷ is) · ds ≡ < i , b > ∷ await b i is ds {-# ATP axioms send-eq #-} postulate await-ok≡ : ∀ b b' i is ds → b ≡ b' → await b i is (ok b' ∷ ds) ≡ send (not b) · is · ds await-ok≢ : ∀ b b' i is ds → b ≢ b' → await b i is (ok b' ∷ ds) ≡ < i , b > ∷ await b i is ds await-error : ∀ b i is ds → await b i is (error ∷ ds) ≡ < i , b > ∷ await b i is ds {-# ATP axioms await-ok≡ await-ok≢ await-error #-} postulate ack-ok≡ : ∀ b b' i bs → b ≡ b' → ack b · (ok < i , b' > ∷ bs) ≡ b ∷ ack (not b) · bs ack-ok≢ : ∀ b b' i bs → b ≢ b' → ack b · (ok < i , b' > ∷ bs) ≡ not b ∷ ack b · bs ack-error : ∀ b bs → ack b · (error ∷ bs) ≡ not b ∷ ack b · bs {-# ATP axioms ack-ok≡ ack-ok≢ ack-error #-} postulate out-ok≡ : ∀ b b' i bs → b ≡ b' → out b · (ok < i , b' > ∷ bs) ≡ i ∷ out (not b) · bs out-ok≢ : ∀ b b' i bs → b ≢ b' → out b · (ok < i , b' > ∷ bs) ≡ out b · bs out-error : ∀ b bs → out b · (error ∷ bs) ≡ out b · bs {-# ATP axioms out-ok≡ out-ok≢ out-error #-} postulate corrupt-T : ∀ os x xs → corrupt (T ∷ os) · (x ∷ xs) ≡ ok x ∷ corrupt os · xs corrupt-F : ∀ os x xs → corrupt (F ∷ os) · (x ∷ xs) ≡ error ∷ corrupt os · xs {-# ATP axioms corrupt-T corrupt-F #-} postulate has hbs hcs hds : D → D → D → D → D → D → D postulate has-eq : ∀ f₁ f₂ f₃ g₁ g₂ is → has f₁ f₂ f₃ g₁ g₂ is ≡ f₁ · is · (hds f₁ f₂ f₃ g₁ g₂ is) {-# ATP axioms has-eq #-} postulate hbs-eq : ∀ f₁ f₂ f₃ g₁ g₂ is → hbs f₁ f₂ f₃ g₁ g₂ is ≡ g₁ · (has f₁ f₂ f₃ g₁ g₂ is) {-# ATP axioms hbs-eq #-} postulate hcs-eq : ∀ f₁ f₂ f₃ g₁ g₂ is → hcs f₁ f₂ f₃ g₁ g₂ is ≡ f₂ · (hbs f₁ f₂ f₃ g₁ g₂ is) {-# ATP axioms hcs-eq #-} postulate hds-eq : ∀ f₁ f₂ f₃ g₁ g₂ is → hds f₁ f₂ f₃ g₁ g₂ is ≡ g₂ · (hcs f₁ f₂ f₃ g₁ g₂ is) {-# ATP axioms hds-eq #-} postulate transfer : D → D → D → D → D → D → D transfer-eq : ∀ f₁ f₂ f₃ g₁ g₂ is → transfer f₁ f₂ f₃ g₁ g₂ is ≡ f₃ · (hbs f₁ f₂ f₃ g₁ g₂ is) {-# ATP axioms transfer-eq #-} postulate abpTransfer : D → D → D → D → D abpTransfer-eq : ∀ b os₁ os₂ is → abpTransfer b os₁ os₂ is ≡ transfer (send b) (ack b) (out b) (corrupt os₁) (corrupt os₂) is {-# ATP axiom abpTransfer-eq #-} ------------------------------------------------------------------------------ -- ABP relations -- Start state for the ABP. S : D → D → D → D → D → D → D → D → D → Set S b is os₁ os₂ as bs cs ds js = as ≡ send b · is · ds ∧ bs ≡ corrupt os₁ · as ∧ cs ≡ ack b · bs ∧ ds ≡ corrupt os₂ · cs ∧ js ≡ out b · bs {-# ATP definition S #-} -- Auxiliary state for the ABP. S' : D → D → D → D → D → D → D → D → D → D → Set S' b i' is' os₁' os₂' as' bs' cs' ds' js' = as' ≡ await b i' is' ds' -- Typo in ds'. ∧ bs' ≡ corrupt os₁' · as' ∧ cs' ≡ ack (not b) · bs' ∧ ds' ≡ corrupt os₂' · (b ∷ cs') ∧ js' ≡ out (not b) · bs' {-# ATP definition S' #-} -- Auxiliary bisimulation. B : D → D → Set B is js = ∃[ b ] ∃[ os₁ ] ∃[ os₂ ] ∃[ as ] ∃[ bs ] ∃[ cs ] ∃[ ds ] Stream is ∧ Bit b ∧ Fair os₁ ∧ Fair os₂ ∧ S b is os₁ os₂ as bs cs ds js {-# ATP definition B #-} ------------------------------------------------------------------------------ -- References -- -- Dybjer, Peter and Sander, Herbert P. (1989). A Functional -- Programming Approach to the Specification and Verification of -- Concurrent Systems. Formal Aspects of Computing 1, pp. 303–319.
{ "alphanum_fraction": 0.4614882507, "avg_line_length": 30.8456375839, "ext": "agda", "hexsha": "2da1b956fd09c20f584ee220aae1c32660a67a5c", "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": "src/fot/FOTC/Program/ABP/ABP.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": "src/fot/FOTC/Program/ABP/ABP.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": "src/fot/FOTC/Program/ABP/ABP.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": 1606, "size": 4596 }
module HasDecidableSatisfaction where open import OscarPrelude open import 𝓐ssertion open import HasSatisfaction open import Interpretation record HasDecidableSatisfaction (A : Set) ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ : Set₁ where field _⊨?_ : (I : Interpretation) → (x : A) → Dec (I ⊨ x) open HasDecidableSatisfaction ⦃ … ⦄ public {-# DISPLAY HasDecidableSatisfaction._⊨?_ _ = _⊨?_ #-}
{ "alphanum_fraction": 0.7212713936, "avg_line_length": 24.0588235294, "ext": "agda", "hexsha": "1f50baa4b84cc7fb74dded1dc69c0813780f3f4d", "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-1/HasDecidableSatisfaction.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-1/HasDecidableSatisfaction.agda", "max_line_length": 94, "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-1/HasDecidableSatisfaction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 147, "size": 409 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Lifting of two predicates ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product.Relation.Unary.All where open import Level open import Data.Product open import Function.Base open import Relation.Unary private variable a b p q : Level A : Set a B : Set b All : (A → Set p) → (B → Set q) → (A × B → Set (p ⊔ q)) All P Q (a , b) = P a × Q b
{ "alphanum_fraction": 0.4582560297, "avg_line_length": 22.4583333333, "ext": "agda", "hexsha": "7432b06e756f7fdfc0e0f214cfefc9242f1ad35a", "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/Product/Relation/Unary/All.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/Product/Relation/Unary/All.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/Data/Product/Relation/Unary/All.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": 125, "size": 539 }
{-# OPTIONS --without-K --safe #-} module Categories.Adjoint.TwoSided where -- A "two sided" adjoint is an adjoint of two functors L and R where the -- unit and counit are natural isomorphisms. -- A two sided adjoint is the underlying data to an Adjoint Equivalence open import Level open import Categories.Adjoint open import Categories.Category.Core using (Category) open import Categories.Functor renaming (id to idF) open import Categories.Functor.Properties open import Categories.NaturalTransformation using (ntHelper) open import Categories.NaturalTransformation.NaturalIsomorphism as ≃ using (_≃_; NaturalIsomorphism) open import Categories.NaturalTransformation.NaturalIsomorphism.Properties import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level o′ ℓ′ e′ : Level C D : Category o ℓ e infix 5 _⊣⊢_ record _⊣⊢_ (L : Functor C D) (R : Functor D C) : Set (levelOfTerm L ⊔ levelOfTerm R) where field unit : idF ≃ (R ∘F L) counit : (L ∘F R) ≃ idF module unit = NaturalIsomorphism unit module counit = NaturalIsomorphism counit private module C = Category C using (Obj; id; _∘_; _≈_; module HomReasoning) module D = Category D using (Obj; id; _∘_; _≈_; module HomReasoning) module L = Functor L using (₀; ₁; op; identity) module R = Functor R using (₀; ₁; op; identity) field zig : ∀ {A : C.Obj} → counit.⇒.η (L.₀ A) D.∘ L.₁ (unit.⇒.η A) D.≈ D.id zag : ∀ {B : D.Obj} → R.₁ (counit.⇒.η B) C.∘ unit.⇒.η (R.₀ B) C.≈ C.id op₁ : R.op ⊣⊢ L.op op₁ = record { unit = counit.op ; counit = unit.op ; zig = zag ; zag = zig } zag⁻¹ : {B : D.Obj} → unit.⇐.η (R.₀ B) C.∘ R.₁ (counit.⇐.η B) C.≈ C.id zag⁻¹ {B} = begin unit.⇐.η (R.₀ B) C.∘ R.₁ (counit.⇐.η B) ≈˘⟨ flip-fromʳ unit.FX≅GX zag ⟩∘⟨refl ⟩ R.₁ (counit.⇒.η B) C.∘ R.₁ (counit.⇐.η B) ≈⟨ [ R ]-resp-∘ (counit.iso.isoʳ B) ⟩ R.₁ D.id ≈⟨ R.identity ⟩ C.id ∎ where open C.HomReasoning open MR C zig⁻¹ : {A : C.Obj} → L.₁ (unit.⇐.η A) D.∘ counit.⇐.η (L.₀ A) D.≈ D.id zig⁻¹ {A} = begin L.₁ (unit.⇐.η A) D.∘ counit.⇐.η (L.₀ A) ≈˘⟨ refl⟩∘⟨ flip-fromˡ counit.FX≅GX zig ⟩ L.₁ (unit.⇐.η A) D.∘ L.₁ (unit.⇒.η A) ≈⟨ [ L ]-resp-∘ (unit.iso.isoˡ A) ⟩ L.₁ C.id ≈⟨ L.identity ⟩ D.id ∎ where open D.HomReasoning open MR D op₂ : R ⊣⊢ L op₂ = record { unit = ≃.sym counit ; counit = ≃.sym unit ; zig = zag⁻¹ ; zag = zig⁻¹ } L⊣R : L ⊣ R L⊣R = record { unit = unit.F⇒G ; counit = counit.F⇒G ; zig = zig ; zag = zag } module L⊣R = Adjoint L⊣R open L⊣R hiding (unit; counit; zig; zag; op) public R⊣L : R ⊣ L R⊣L = record { unit = counit.F⇐G ; counit = unit.F⇐G ; zig = zag⁻¹ ; zag = zig⁻¹ } module R⊣L = Adjoint R⊣L private record WithZig (L : Functor C D) (R : Functor D C) : Set (levelOfTerm L ⊔ levelOfTerm R) where field unit : idF ≃ (R ∘F L) counit : (L ∘F R) ≃ idF private module unit = NaturalIsomorphism unit module counit = NaturalIsomorphism counit module C = Category C using (Obj; id; _∘_; _≈_; module HomReasoning) module D = Category D using (Obj; id; _∘_; _≈_; module HomReasoning) module L = Functor L using (₀; ₁; op; identity) module R = Functor R using (₀; ₁; op; identity; F-resp-≈) field zig : ∀ {A : C.Obj} → counit.⇒.η (L.₀ A) D.∘ L.₁ (unit.⇒.η A) D.≈ D.id zag : ∀ {B : D.Obj} → R.₁ (counit.⇒.η B) C.∘ unit.⇒.η (R.₀ B) C.≈ C.id zag {B} = F≃id⇒id (≃.sym unit) helper where open C open HomReasoning helper : R.₁ (L.₁ (R.₁ (counit.⇒.η B) ∘ unit.⇒.η (R.₀ B))) ≈ id helper = begin R.₁ (L.₁ (R.₁ (counit.⇒.η B) ∘ unit.⇒.η (R.₀ B))) ≈⟨ Functor.homomorphism (R ∘F L) ⟩ R.₁ (L.₁ (R.₁ (counit.⇒.η B))) ∘ R.₁ (L.₁ (unit.⇒.η (R.₀ B))) ≈˘⟨ R.F-resp-≈ (F≃id-comm₁ counit) ⟩∘⟨refl ⟩ R.₁ (counit.⇒.η (L.₀ (R.₀ B))) ∘ R.₁ (L.₁ (unit.⇒.η (R.₀ B))) ≈⟨ [ R ]-resp-∘ zig ⟩ R.₁ D.id ≈⟨ R.identity ⟩ id ∎ record WithZag (L : Functor C D) (R : Functor D C) : Set (levelOfTerm L ⊔ levelOfTerm R) where field unit : idF ≃ (R ∘F L) counit : (L ∘F R) ≃ idF private module unit = NaturalIsomorphism unit module counit = NaturalIsomorphism counit module C = Category C using (Obj; id; _∘_; _≈_; module HomReasoning) module D = Category D using (Obj; id; _∘_; _≈_; module HomReasoning) module L = Functor L using (₀; ₁; op; identity; F-resp-≈) module R = Functor R using (₀; ₁; op; identity) field zag : ∀ {B : D.Obj} → R.₁ (counit.⇒.η B) C.∘ unit.⇒.η (R.₀ B) C.≈ C.id zig : ∀ {A : C.Obj} → counit.⇒.η (L.₀ A) D.∘ L.₁ (unit.⇒.η A) D.≈ D.id zig {A} = F≃id⇒id counit helper where open D open HomReasoning helper : L.₁ (R.₁ (counit.⇒.η (L.₀ A) ∘ L.₁ (unit.⇒.η A))) ≈ id helper = begin L.₁ (R.₁ (counit.⇒.η (L.₀ A) ∘ L.₁ (unit.⇒.η A))) ≈⟨ Functor.homomorphism (L ∘F R) ⟩ (L.₁ (R.₁ (counit.⇒.η (L.₀ A))) ∘ L.₁ (R.₁ (L.₁ (unit.⇒.η A)))) ≈˘⟨ refl⟩∘⟨ L.F-resp-≈ (F≃id-comm₂ (≃.sym unit)) ⟩ L.₁ (R.₁ (counit.⇒.η (L.₀ A))) ∘ L.₁ (unit.⇒.η (R.₀ (L.₀ A))) ≈⟨ [ L ]-resp-∘ zag ⟩ L.₁ C.id ≈⟨ L.identity ⟩ id ∎ module _ {L : Functor C D} {R : Functor D C} where withZig : WithZig L R → L ⊣⊢ R withZig LR = record { unit = unit ; counit = counit ; zig = zig ; zag = zag } where open WithZig LR withZag : WithZag L R → L ⊣⊢ R withZag LR = record { unit = unit ; counit = counit ; zig = zig ; zag = zag } where open WithZag LR id⊣⊢id : idF {C = C} ⊣⊢ idF id⊣⊢id {C = C} = record { unit = ≃.sym ≃.unitor² ; counit = ≃.unitor² ; zig = identity² ; zag = identity² } where open Category C
{ "alphanum_fraction": 0.5060335371, "avg_line_length": 34.1229946524, "ext": "agda", "hexsha": "d1312dcecbb841265e486013ddd0f09af08453b1", "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/Adjoint/TwoSided.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/Adjoint/TwoSided.agda", "max_line_length": 128, "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/Adjoint/TwoSided.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": 2670, "size": 6381 }
{- 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.ImplShared.Consensus.Types module LibraBFT.Impl.Crypto.Crypto.Hash where postulate -- TODO-1: valueZero valueZero : HashValue
{ "alphanum_fraction": 0.7791878173, "avg_line_length": 30.3076923077, "ext": "agda", "hexsha": "d8fcadebe71c4698bcf4a539716f92af04b8b09f", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z", "max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z", "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/Crypto/Crypto/Hash.agda", "max_issues_count": 72, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z", "max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z", "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/Crypto/Crypto/Hash.agda", "max_line_length": 111, "max_stars_count": 4, "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/Crypto/Crypto/Hash.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z", "num_tokens": 106, "size": 394 }
-- Andreas, 2014-09-01 restored this test case module ClashingImport where postulate A : Set import Imports.A open Imports.A public -- only a public import creates a clash -- since an ambiguous identifier would be exported
{ "alphanum_fraction": 0.7719298246, "avg_line_length": 17.5384615385, "ext": "agda", "hexsha": "d796dfeeed67339df43366b26e865a89516a8b87", "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/ClashingImport.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/ClashingImport.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/Fail/ClashingImport.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": 54, "size": 228 }
module Types.IND1 where open import Data.Nat open import Data.Fin hiding (_+_) open import Data.Product open import Function open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Types.Direction open import Auxiliary.Extensionality open import Auxiliary.RewriteLemmas private variable m n : ℕ ---------------------------------------------------------------------- -- session type inductively with explicit rec -- without polarized variables mutual data Type n : Set where TUnit TInt : Type n TPair : (T₁ : Type n) (T₂ : Type n) → Type n TChan : (S : SType n) → Type n data SType n : Set where gdd : (G : GType n) → SType n rec : (G : GType (suc n) ) → SType n var : (x : Fin n) → SType n data GType n : Set where transmit : (d : Dir) (T : Type n) (S : SType n) → GType n choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n end : GType n TType = Type -- weakening weakenS : (n : ℕ) → SType m → SType (m + n) weakenG : (n : ℕ) → GType m → GType (m + n) weakenT : (n : ℕ) → TType m → TType (m + n) weakenS n (gdd gst) = gdd (weakenG n gst) weakenS n (rec gst) = rec (weakenG n gst) weakenS n (var x) = var (inject+ n x) weakenG n (transmit d t s) = transmit d (weakenT n t) (weakenS n s) weakenG n (choice d m alt) = choice d m (weakenS n ∘ alt) weakenG n end = end weakenT n TUnit = TUnit weakenT n TInt = TInt weakenT n (TPair ty ty₁) = TPair (weakenT n ty) (weakenT n ty₁) weakenT n (TChan x) = TChan (weakenS n x) weaken1 : SType m → SType (suc m) weaken1{m} stm with weakenS 1 stm ... | r rewrite n+1=suc-n {m} = r module CheckWeaken where s0 : SType 0 s0 = rec (transmit SND TUnit (var zero)) s1 : SType 1 s1 = rec (transmit SND TUnit (var zero)) s2 : SType 2 s2 = rec (transmit SND TUnit (var zero)) check-weakenS1 : weakenS 1 s0 ≡ s1 check-weakenS1 = cong rec (cong (transmit SND TUnit) refl) check-weakenS2 : weakenS 2 s0 ≡ s2 check-weakenS2 = cong rec (cong (transmit SND TUnit) refl) weaken1'N : Fin (suc n) → Fin n → Fin (suc n) weaken1'N zero x = suc x weaken1'N (suc i) zero = zero weaken1'N (suc i) (suc x) = suc (weaken1'N i x) weaken1'S : Fin (suc n) → SType n → SType (suc n) weaken1'G : Fin (suc n) → GType n → GType (suc n) weaken1'T : Fin (suc n) → TType n → TType (suc n) weaken1'S i (gdd gst) = gdd (weaken1'G i gst) weaken1'S i (rec gst) = rec (weaken1'G (suc i) gst) weaken1'S i (var x) = var (weaken1'N i x) weaken1'G i (transmit d t s) = transmit d (weaken1'T i t) (weaken1'S i s) weaken1'G i (choice d m alt) = choice d m (weaken1'S i ∘ alt) weaken1'G i end = end weaken1'T i TUnit = TUnit weaken1'T i TInt = TInt weaken1'T i (TPair t₁ t₂) = TPair (weaken1'T i t₁) (weaken1'T i t₂) weaken1'T i (TChan x) = TChan (weaken1'S i x) weaken1S : SType n → SType (suc n) weaken1G : GType n → GType (suc n) weaken1T : Type n → Type (suc n) weaken1S = weaken1'S zero weaken1G = weaken1'G zero weaken1T = weaken1'T zero module CheckWeaken1' where sxy : ∀ n → Fin (suc n) → SType n sxy n x = rec (transmit SND TUnit (var x)) s00 : SType 0 s00 = sxy 0 zero s10 : SType 1 s10 = sxy 1 zero s11 : SType 1 s11 = sxy 1 (suc zero) s22 : SType 2 s22 = sxy 2 (suc (suc zero)) check-weaken-s01 : weaken1'S zero s00 ≡ s10 check-weaken-s01 = refl check-weaken-s1-s2 : weaken1'S zero s11 ≡ s22 check-weaken-s1-s2 = refl check-weaken-s21 : weaken1'S (suc zero) (sxy 2 (suc zero)) ≡ sxy 3 (suc zero) check-weaken-s21 = refl -------------------------------------------------------------------- weak-weakN : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (x : Fin n) → weaken1'N (suc i) (weaken1'N j x) ≡ weaken1'N (inject₁ j) (weaken1'N i x) weak-weakG : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (g : GType n) → weaken1'G (suc i) (weaken1'G j g) ≡ weaken1'G (inject₁ j) (weaken1'G i g) weak-weakS : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s : SType n) → weaken1'S (suc i) (weaken1'S j s) ≡ weaken1'S (inject₁ j) (weaken1'S i s) weak-weakT : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (t : Type n) → weaken1'T (suc i) (weaken1'T j t) ≡ weaken1'T (inject₁ j) (weaken1'T i t) weak-weakN zero zero le x = refl weak-weakN (suc i) zero le x = refl weak-weakN (suc i) (suc j) (s≤s le) zero = refl weak-weakN{suc n} (suc i) (suc j) (s≤s le) (suc x) = cong suc (weak-weakN i j le x) weak-weakG i j le (transmit d t s) = cong₂ (transmit d) (weak-weakT i j le t) (weak-weakS i j le s) weak-weakG i j le (choice d m alt) = cong (choice d m) (ext (weak-weakS i j le ∘ alt)) weak-weakG i j le end = refl weak-weakS i j le (gdd gst) = cong gdd (weak-weakG i j le gst) weak-weakS i j le (rec gst) = cong rec (weak-weakG (suc i) (suc j) (s≤s le) gst) weak-weakS i j le (var x) = cong (var) (weak-weakN i j le x) weak-weakT i j le TUnit = refl weak-weakT i j le TInt = refl weak-weakT i j le (TPair t t₁) = cong₂ TPair (weak-weakT i j le t) (weak-weakT i j le t₁) weak-weakT i j le (TChan s) = cong TChan (weak-weakS i j le s) weaken1-weakenN : (m : ℕ) (j : Fin (suc n)) (x : Fin n) → inject+ m (weaken1'N j x) ≡ weaken1'N (inject+ m j) (inject+ m x) weaken1-weakenN m zero zero = refl weaken1-weakenN m zero (suc x) = refl weaken1-weakenN m (suc j) zero = refl weaken1-weakenN m (suc j) (suc x) = cong suc (weaken1-weakenN m j x) weaken1-weakenS : (m : ℕ) (j : Fin (suc n)) (s : SType n) → weakenS m (weaken1'S j s) ≡ weaken1'S (inject+ m j) (weakenS m s) weaken1-weakenG : (m : ℕ) (j : Fin (suc n)) (g : GType n) → weakenG m (weaken1'G j g) ≡ weaken1'G (inject+ m j) (weakenG m g) weaken1-weakenT : (m : ℕ) (j : Fin (suc n)) (t : Type n) → weakenT m (weaken1'T j t) ≡ weaken1'T (inject+ m j) (weakenT m t) weaken1-weakenS m j (gdd gst) = cong gdd (weaken1-weakenG m j gst) weaken1-weakenS m j (rec gst) = cong rec (weaken1-weakenG m (suc j) gst) weaken1-weakenS m zero (var zero) = refl weaken1-weakenS m zero (var (suc x)) = refl weaken1-weakenS {suc n} m (suc j) (var zero) = refl weaken1-weakenS {suc n} m (suc j) (var (suc x)) = cong (var) (cong suc (weaken1-weakenN m j x)) weaken1-weakenG m j (transmit d t s) = cong₂ (transmit d) (weaken1-weakenT m j t) (weaken1-weakenS m j s) weaken1-weakenG m j (choice d m₁ alt) = cong (choice d m₁) (ext (weaken1-weakenS m j ∘ alt)) weaken1-weakenG m j end = refl weaken1-weakenT m j TUnit = refl weaken1-weakenT m j TInt = refl weaken1-weakenT m j (TPair t t₁) = cong₂ TPair (weaken1-weakenT m j t) (weaken1-weakenT m j t₁) weaken1-weakenT m j (TChan x) = cong TChan (weaken1-weakenS m j x) -------------------------------------------------------------------- -- substitution st-substS : SType (suc n) → Fin (suc n) → SType 0 → SType n st-substG : GType (suc n) → Fin (suc n) → SType 0 → GType n st-substT : Type (suc n) → Fin (suc n) → SType 0 → Type n st-substS (gdd gst) i st0 = gdd (st-substG gst i st0) st-substS (rec gst) i st0 = rec (st-substG gst (suc i) st0) st-substS {n} (var zero) zero st0 = weakenS n st0 st-substS {suc n} (var zero) (suc i) st0 = var zero st-substS {suc n} (var (suc x)) zero st0 = var x st-substS {suc n} (var (suc x)) (suc i) st0 = weaken1S (st-substS (var x) i st0) st-substG (transmit d t s) i st0 = transmit d (st-substT t i st0) (st-substS s i st0) st-substG (choice d m alt) i st0 = choice d m (λ j → st-substS (alt j) i st0) st-substG end i st0 = end st-substT TUnit i st0 = TUnit st-substT TInt i st0 = TInt st-substT (TPair ty ty₁) i st0 = TPair (st-substT ty i st0) (st-substT ty₁ i st0) st-substT (TChan st) i st0 = TChan (st-substS st i st0) -------------------------------------------------------------------- trivial-subst-var : (x : Fin n) (ist₁ ist₂ : SType 0) → st-substS (var (suc x)) zero ist₁ ≡ st-substS (var (suc x)) zero ist₂ trivial-subst-var zero ist1 ist2 = refl trivial-subst-var (suc x) ist1 ist2 = refl trivial-subst-var' : (i : Fin n) (ist₁ ist₂ : SType 0) → st-substS (var zero) (suc i) ist₁ ≡ st-substS (var zero) (suc i) ist₂ trivial-subst-var' zero ist1 ist2 = refl trivial-subst-var' (suc x) ist1 ist2 = refl -------------------------------------------------------------------- -- equivalence variable t t₁ t₂ t₁' t₂' : Type n s s₁ s₂ : SType n g g₁ g₂ : GType n unfold : SType 0 → GType 0 unfold (gdd gst) = gst unfold (rec gst) = st-substG gst zero (rec gst) -- type equivalence data EquivT (R : SType n → SType n → Set) : Type n → Type n → Set where eq-unit : EquivT R TUnit TUnit eq-int : EquivT R TInt TInt eq-pair : EquivT R t₁ t₁' → EquivT R t₂ t₂' → EquivT R (TPair t₁ t₂) (TPair t₁' t₂') eq-chan : R s₁ s₂ → EquivT R (TChan s₁) (TChan s₂) -- session type equivalence data EquivG (R : SType n → SType n → Set) : GType n → GType n → Set where eq-transmit : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivG R (transmit d t₁ s₁) (transmit d t₂ s₂) eq-choice : ∀ {alt alt'} → (d : Dir) → ((i : Fin m) → R (alt i) (alt' i)) → EquivG R (choice d m alt) (choice d m alt') eq-end : EquivG R end end record Equiv (s₁ s₂ : SType 0) : Set where coinductive field force : EquivG Equiv (unfold s₁) (unfold s₂) open Equiv _≈_ = Equiv _≈'_ = EquivG Equiv _≈ᵗ_ = EquivT Equiv -- reflexive ≈-refl : s ≈ s ≈'-refl : g ≈' g ≈ᵗ-refl : t ≈ᵗ t force (≈-refl {s}) = ≈'-refl ≈'-refl {transmit d t s} = eq-transmit d ≈ᵗ-refl ≈-refl ≈'-refl {choice d m alt} = eq-choice d (λ i → ≈-refl) ≈'-refl {end} = eq-end ≈ᵗ-refl {TUnit} = eq-unit ≈ᵗ-refl {TInt} = eq-int ≈ᵗ-refl {TPair t t₁} = eq-pair ≈ᵗ-refl ≈ᵗ-refl ≈ᵗ-refl {TChan x} = eq-chan ≈-refl -- symmetric ≈-symm : s₁ ≈ s₂ → s₂ ≈ s₁ ≈'-symm : g₁ ≈' g₂ → g₂ ≈' g₁ ≈ᵗ-symm : t₁ ≈ᵗ t₂ → t₂ ≈ᵗ t₁ force (≈-symm s₁≈s₂) = ≈'-symm (force s₁≈s₂) ≈'-symm (eq-transmit d x x₁) = eq-transmit d (≈ᵗ-symm x) (≈-symm x₁) ≈'-symm (eq-choice d x) = eq-choice d (≈-symm ∘ x) ≈'-symm eq-end = eq-end ≈ᵗ-symm eq-unit = eq-unit ≈ᵗ-symm eq-int = eq-int ≈ᵗ-symm (eq-pair t₁≈ᵗt₂ t₁≈ᵗt₃) = eq-pair (≈ᵗ-symm t₁≈ᵗt₂) (≈ᵗ-symm t₁≈ᵗt₃) ≈ᵗ-symm (eq-chan x) = eq-chan (≈-symm x)
{ "alphanum_fraction": 0.6027059056, "avg_line_length": 34.6780821918, "ext": "agda", "hexsha": "d5c6e97464ed73af4da66bb1fd7d43c2dab2bc2c", "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/Types/IND1.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/Types/IND1.agda", "max_line_length": 121, "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/Types/IND1.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": 4284, "size": 10126 }
open import Oscar.Prelude open import Oscar.Data.¶ open import Oscar.Data.Fin open import Oscar.Data.Substitunction open import Oscar.Data.Term open import Oscar.Data.Maybe open import Oscar.Data.Proposequality open import Oscar.Data.Vec open import Oscar.Class.Congruity open import Oscar.Class.Thickandthin open import Oscar.Class.Injectivity open import Oscar.Class.Smap open import Oscar.Class.Pure open import Oscar.Class.Apply import Oscar.Property.Monad.Maybe import Oscar.Property.Thickandthin.FinFinProposequalityMaybeProposequality import Oscar.Class.Surjection.⋆ import Oscar.Class.Congruity.Proposequality import Oscar.Class.Injectivity.Vec import Oscar.Class.Smap.ExtensionFinExtensionTerm module Oscar.Property.Thickandthin.FinTermProposequalityMaybeProposequality where module _ {𝔭} {𝔓 : Ø 𝔭} where open Substitunction 𝔓 open Term 𝔓 instance [𝓣hick]FinTerm : [𝓣hick] Fin Term [𝓣hick]FinTerm = ∁ 𝓣hickFinTerm : 𝓣hick Fin Term 𝓣hickFinTerm .𝓣hick.thick x t = thick x ◃ t [𝓣hick]FinTerms : ∀ {N} → [𝓣hick] Fin (Terms N) [𝓣hick]FinTerms = ∁ 𝓣hickFinTerms : ∀ {N} → 𝓣hick Fin (Terms N) 𝓣hickFinTerms .𝓣hick.thick x t = thick x ◃ t [𝓣hin]FinTerm : [𝓣hin] Fin Term [𝓣hin]FinTerm = ∁ 𝓣hinFinTerm : 𝓣hin Fin Term 𝓣hinFinTerm .𝓣hin.thin = smap ∘ thin [𝓣hin]FinTerms : ∀ {N} → [𝓣hin] Fin (Terms N) [𝓣hin]FinTerms = ∁ 𝓣hinFinTerms : ∀ {N} → 𝓣hin Fin (Terms N) 𝓣hinFinTerms .𝓣hin.thin = smap ∘ thin [𝓘njectivity₂,₁]FinTerm : ∀ {m} → [𝓘njectivity₂,₁] (𝔱hin Fin Term m) Proposequality Proposequality [𝓘njectivity₂,₁]FinTerm = ∁ 𝓘njection₂FinTerm : ∀ {m} → 𝓘njection₂ (λ (_ : ¶⟨< ↑ m ⟩) (_ : Term m) → Term (↑ m)) 𝓘njection₂FinTerm {m} .𝓘njection₂.injection₂ = thin [𝓘njectivity₂,₁]FinTerms : ∀ {N m} → [𝓘njectivity₂,₁] (𝔱hin Fin (Terms N) m) Proposequality Proposequality [𝓘njectivity₂,₁]FinTerms = ∁ 𝓘njection₂FinTerms : ∀ {N m} → 𝓘njection₂ (λ (_ : ¶⟨< ↑ m ⟩) (_ : Terms N m) → Terms N (↑ m)) 𝓘njection₂FinTerms {m} .𝓘njection₂.injection₂ = thin 𝓘njection₁-TermI : ∀ {n} → 𝓘njection₁ (λ (_ : ¶⟨< n ⟩) → Term n) 𝓘njection₁-TermI .𝓘njection₁.injection₁ = i [𝓘njectivity₁]TermI : ∀ {n} → [𝓘njectivity₁] (λ (_ : ¶⟨< n ⟩) → Term n) Proposequality Proposequality [𝓘njectivity₁]TermI = ∁ 𝓘njectivity₁TermI : ∀ {n} → 𝓘njectivity₁ (λ (_ : ¶⟨< n ⟩) → Term n) Proposequality Proposequality 𝓘njectivity₁TermI {n} .𝓘njectivity₁.injectivity₁ ∅ = ∅ 𝓘njection₂-TermFork : ∀ {n} → 𝓘njection₂ (λ (_ : Term n) (_ : Term n) → Term n) 𝓘njection₂-TermFork .𝓘njection₂.injection₂ = _fork_ [𝓘njection₂,₀,₁]-TermFork : ∀ {n} → [𝓘njectivity₂,₀,₁] (λ (_ : Term n) (_ : Term n) → Term n) Proposequality Proposequality [𝓘njection₂,₀,₁]-TermFork = ∁ 𝓘njection₂,₀,₁-TermFork : ∀ {n} → 𝓘njectivity₂,₀,₁ (λ (_ : Term n) (_ : Term n) → Term n) Proposequality Proposequality 𝓘njection₂,₀,₁-TermFork .𝓘njectivity₂,₀,₁.injectivity₂,₀,₁ ∅ = ∅ [𝓘njection₂,₀,₂]-TermFork : ∀ {n} → [𝓘njectivity₂,₀,₂] (λ (_ : Term n) (_ : Term n) → Term n) Proposequality Proposequality [𝓘njection₂,₀,₂]-TermFork = ∁ 𝓘njection₂,₀,₂-TermFork : ∀ {n} → 𝓘njectivity₂,₀,₂ (λ (_ : Term n) (_ : Term n) → Term n) Proposequality Proposequality 𝓘njection₂,₀,₂-TermFork .𝓘njectivity₂,₀,₂.injectivity₂,₀,₂ ∅ = ∅ 𝓘njection₃TermFunction : ∀ {n} → 𝓘njection₃ (λ (_ : 𝔓) (N : ¶) (_ : Terms N n) → Term n) 𝓘njection₃TermFunction {n} .𝓘njection₃.injection₃ p N ts = function p ts [𝓘njectivity₃,₀,₁]TermFunction : ∀ {n} → [𝓘njectivity₃,₀,₁] (λ (_ : 𝔓) (N : ¶) (_ : Terms N n) → Term n) Proposequality Proposequality [𝓘njectivity₃,₀,₁]TermFunction = ∁ 𝓘njectivity₃,₀,₁TermFunction : ∀ {n} → 𝓘njectivity₃,₀,₁ (λ (_ : 𝔓) (N : ¶) (_ : Terms N n) → Term n) Proposequality Proposequality 𝓘njectivity₃,₀,₁TermFunction .𝓘njectivity₃,₀,₁.injectivity₃,₀,₁ ∅ = ∅ [𝓘njectivity₃,₀,₂]TermFunction : ∀ {n} → [𝓘njectivity₃,₀,₂] (λ (_ : 𝔓) (N : ¶) (_ : Terms N n) → Term n) Proposequality Proposequality [𝓘njectivity₃,₀,₂]TermFunction = ∁ 𝓘njectivity₃,₀,₂TermFunction : ∀ {n} → 𝓘njectivity₃,₀,₂ (λ (_ : 𝔓) (N : ¶) (_ : Terms N n) → Term n) Proposequality Proposequality 𝓘njectivity₃,₀,₂TermFunction .𝓘njectivity₃,₀,₂.injectivity₃,₀,₂ ∅ = ∅ 𝓘njection₂TermFunction : ∀ {N n} → 𝓘njection₂ (λ (_ : 𝔓) (_ : Terms N n) → Term n) 𝓘njection₂TermFunction {N} {n} .𝓘njection₂.injection₂ p ts = function p ts [𝓘njectivity₂,₀,₂]TermFunction : ∀ {N n} → [𝓘njectivity₂,₀,₂] (λ (_ : 𝔓) (_ : Terms N n) → Term n) Proposequality Proposequality [𝓘njectivity₂,₀,₂]TermFunction = ∁ 𝓘njectivity₂,₀,₂TermFunction : ∀ {N n} → 𝓘njectivity₂,₀,₂ (λ (_ : 𝔓) (_ : Terms N n) → Term n) Proposequality Proposequality 𝓘njectivity₂,₀,₂TermFunction .𝓘njectivity₂,₀,₂.injectivity₂,₀,₂ ∅ = ∅ mutual instance 𝓘njectivity₂,₁FinTerm : ∀ {m} → 𝓘njectivity₂,₁ (𝔱hin Fin Term m) Proposequality Proposequality 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ x {i _} {i _} eq = congruity i (injectivity₂,₁ x (injectivity₁[ Proposequality ] eq)) 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {i _} {leaf} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {i _} {_ fork _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {i _} {function _ _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {leaf} {i _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {leaf} {leaf} _ = ∅ 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {leaf} {_ fork _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {leaf} {function _ _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {_ fork _} {i _} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {_ fork _} {leaf} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ x {y₁ fork y₂} {y₃ fork y₄} eq rewrite injectivity₂,₁ {_∼₂_ = Proposequality} x {y₁ = y₁} (injectivity₂,₀,₁[ Proposequality ] eq) | injectivity₂,₁ {_∼₂_ = Proposequality} x {y₁ = y₂} (injectivity₂,₀,₂[ Proposequality ] eq) = ∅ 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {y₁ fork y₂} {function x₁ x₂} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {function _ _} {i x₃} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {function _ _} {leaf} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ _ {function _ _} {y₂ fork y₃} () 𝓘njectivity₂,₁FinTerm .𝓘njectivity₂,₁.injectivity₂,₁ x {function p1 {N1} ts1} {function p2 {N2} ts2} t₁≡t₂ rewrite injectivity₃,₀,₁[ Proposequality ] {x₂ = p2} t₁≡t₂ with injectivity₃,₀,₂[ Proposequality ] {y₂ = N2} t₁≡t₂ … | ∅ with injectivity₂,₀,₂[ Proposequality ] {y₂ = thin x ts2} t₁≡t₂ … | ts₁≡ts₂ = congruity (function p2) (injectivity₂,₁ x ts₁≡ts₂) 𝓘njectivity₂,₁FinTerms : ∀ {N m} → 𝓘njectivity₂,₁ (𝔱hin Fin (Terms N) m) Proposequality Proposequality 𝓘njectivity₂,₁FinTerms .𝓘njectivity₂,₁.injectivity₂,₁ x {∅} {∅} x₁ = ∅ 𝓘njectivity₂,₁FinTerms .𝓘njectivity₂,₁.injectivity₂,₁ x {_ , _} {t₂ , ts₂} eq rewrite injectivity₂,₁ {_∼₂_ = Proposequality} x {y₂ = t₂} (injectivity₂,₀,₁[ Proposequality ] eq) | injectivity₂,₁ {_∼₂_ = Proposequality} x {y₂ = ts₂} (injectivity₂,₀,₂[ Proposequality ] eq) = ∅ instance [𝓒heck]FinTermMaybe : [𝓒heck] Fin Term Maybe [𝓒heck]FinTermMaybe = ∁ [𝓒heck]FinTermsMaybe : ∀ {N} → [𝓒heck] Fin (Terms N) Maybe [𝓒heck]FinTermsMaybe = ∁ open import Oscar.Class.Smap open import Oscar.Class.Fmap mutual instance 𝓒heckFinTermMaybe : 𝓒heck Fin Term Maybe 𝓒heckFinTermMaybe .𝓒heck.check x (i y) = ⦇ i (check x y) ⦈ 𝓒heckFinTermMaybe .𝓒heck.check x leaf = ⦇ leaf ⦈ 𝓒heckFinTermMaybe .𝓒heck.check x (y₁ fork y₂) = ⦇ _fork_ (check x y₁) (check x y₂) ⦈ 𝓒heckFinTermMaybe .𝓒heck.check x (function p ts) = ⦇ (function p) (check x ts) ⦈ 𝓒heckFinTermsMaybe : ∀ {N} → 𝓒heck Fin (Terms N) Maybe 𝓒heckFinTermsMaybe .𝓒heck.check _ ∅ = ⦇ ∅ ⦈ 𝓒heckFinTermsMaybe .𝓒heck.check x (t , ts) = ⦇ check x t , check x ts ⦈ instance [𝓣hick/thin=1]FinTermProposequality : [𝓣hick/thin=1] Fin Term Proposequality [𝓣hick/thin=1]FinTermProposequality = ∁ [𝓣hick/thin=1]FinTermsProposequality : ∀ {N} → [𝓣hick/thin=1] Fin (Terms N) Proposequality [𝓣hick/thin=1]FinTermsProposequality = ∁ mutual instance 𝓣hick/thin=1FinTermProposequality : 𝓣hick/thin=1 Fin Term Proposequality 𝓣hick/thin=1FinTermProposequality .𝓣hick/thin=1.thick/thin=1 x (i y) rewrite thick/thin=1 {_≈_ = Proposequality} x y = ∅ -- congruity i $ thick/thin=1 x y 𝓣hick/thin=1FinTermProposequality .𝓣hick/thin=1.thick/thin=1 x leaf = ∅ 𝓣hick/thin=1FinTermProposequality .𝓣hick/thin=1.thick/thin=1 x (y₁ fork y₂) = congruity₂ _fork_ (thick/thin=1 x y₁) (thick/thin=1 x y₂) 𝓣hick/thin=1FinTermProposequality .𝓣hick/thin=1.thick/thin=1 x (function p ts) = congruity (function p) (thick/thin=1 x ts) 𝓣hick/thin=1FinTermsProposequality : ∀ {N} → 𝓣hick/thin=1 Fin (Terms N) Proposequality 𝓣hick/thin=1FinTermsProposequality .𝓣hick/thin=1.thick/thin=1 x ∅ = ∅ 𝓣hick/thin=1FinTermsProposequality .𝓣hick/thin=1.thick/thin=1 x (t , ts) = congruity₂ _,_ (thick/thin=1 x t) (thick/thin=1 x ts) instance [𝓒heck/thin=1]FinTermMaybe : [𝓒heck/thin=1] Fin Term Maybe Proposequality [𝓒heck/thin=1]FinTermMaybe = ∁ [𝓒heck/thin=1]FinTermsMaybe : ∀ {N} → [𝓒heck/thin=1] Fin (Terms N) Maybe Proposequality [𝓒heck/thin=1]FinTermsMaybe = ∁ mutual instance 𝓒heck/thin=1FinTermMaybe : 𝓒heck/thin=1 Fin Term Maybe Proposequality 𝓒heck/thin=1FinTermMaybe .𝓒heck/thin=1.check/thin=1 x (i y) rewrite check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x y = ∅ 𝓒heck/thin=1FinTermMaybe .𝓒heck/thin=1.check/thin=1 x leaf = ∅ 𝓒heck/thin=1FinTermMaybe .𝓒heck/thin=1.check/thin=1 x (y₁ fork y₂) rewrite check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x y₁ | check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x y₂ = ∅ 𝓒heck/thin=1FinTermMaybe .𝓒heck/thin=1.check/thin=1 x (function p ys) rewrite check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x ys = ∅ 𝓒heck/thin=1FinTermsMaybe : ∀ {N} → 𝓒heck/thin=1 Fin (Terms N) Maybe Proposequality 𝓒heck/thin=1FinTermsMaybe .𝓒heck/thin=1.check/thin=1 x ∅ = ∅ 𝓒heck/thin=1FinTermsMaybe .𝓒heck/thin=1.check/thin=1 x (y , ys) rewrite check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x y | check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x ys = ∅ instance IsThickandthinFinTerm : IsThickandthin Fin Term Proposequality Maybe Proposequality IsThickandthinFinTerm = ∁ IsThickandthinFinTerms : ∀ {N} → IsThickandthin Fin (Terms N) Proposequality Maybe Proposequality IsThickandthinFinTerms = ∁ module _ {𝔭} (𝔓 : Ø 𝔭) where open Substitunction 𝔓 open Term 𝔓 ThickandthinFinTerm : Thickandthin _ _ _ _ _ _ ThickandthinFinTerm = ∁ Fin Term Proposequality Maybe Proposequality ThickandthinFinTerms : ∀ N → Thickandthin _ _ _ _ _ _ ThickandthinFinTerms N = ∁ Fin (Terms N) Proposequality Maybe Proposequality
{ "alphanum_fraction": 0.674842823, "avg_line_length": 45.3534136546, "ext": "agda", "hexsha": "5c7dd013dbcab808b49779c5f75c3f181aff5818", "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/Property/Thickandthin/FinTermProposequalityMaybeProposequality.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/Property/Thickandthin/FinTermProposequalityMaybeProposequality.agda", "max_line_length": 160, "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/Property/Thickandthin/FinTermProposequalityMaybeProposequality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4773, "size": 11293 }
------------------------------------------------------------------------------ -- Proving properties without using pattern matching on refl ------------------------------------------------------------------------------ {-# OPTIONS --no-pattern-matching #-} {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} module FOT.PA.Inductive2Standard.NoPatternMatchingOnRefl where open import PA.Inductive.Base ------------------------------------------------------------------------------ -- From PA.Inductive2Standard -- 20 May 2013. Requires the predecessor function. -- PA₂ : ∀ {m n} → succ m ≡ succ n → m ≡ n
{ "alphanum_fraction": 0.4349710983, "avg_line_length": 36.4210526316, "ext": "agda", "hexsha": "640d5b89bf458f4428c983657e9e0e0f4d2d3ef4", "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/PA/Inductive2Standard/NoPatternMatchingOnRefl.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/PA/Inductive2Standard/NoPatternMatchingOnRefl.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/PA/Inductive2Standard/NoPatternMatchingOnRefl.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": 121, "size": 692 }
module Syntax where import Level open import Data.Empty open import Data.Unit as Unit open import Data.Nat open import Data.List as List renaming ([] to Ø; [_] to [_]L) open import NonEmptyList as NList open import Data.Vec as Vec hiding ([_]; _++_) open import Data.Product as Prod open import Function open import Relation.Binary.PropositionalEquality as PE hiding ([_]) open import Relation.Binary using (module IsEquivalence; Setoid; module Setoid) open ≡-Reasoning open import Common.Context as Context open import Algebra open Monoid {{ ... }} hiding (refl) open import SyntaxRaw infixr 5 _§ₒ_ _§ₘ_ ----------------------------------------- --- Separate types and terms ----------------------------------------- mutual data DecentType : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ Γ₂ → Set where DT-⊤ : (Θ : TyCtx) (Γ : RawCtx) → DecentType (⊤-Raw Θ Γ) DT-tyVar : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → (X : TyVar Θ Γ₂) → DecentType (tyVarRaw Γ₁ X) DT-inst : ∀{Θ Γ₁ Γ₂ A} → (B : Raw Θ Γ₁ (Γ₂ ↑ A)) → (t : Raw Ø Γ₁ Ø) → DecentType B → DecentTerm t → DecentType (instRaw {Γ₂ = Γ₂} B t) DT-paramAbstr : ∀{Θ Γ₂} {B : U} (Γ₁ : RawCtx) → {A : Raw Θ (B ∷ Γ₁) Γ₂} → DecentType A → DecentType (paramAbstrRaw Γ₁ A) DT-fp : ∀{Θ Γ₂} (Γ₁ : RawCtx) → (ρ : FP) → (D : FpData Raw Θ Γ₂) → DecentFpData D → DecentType (fpRaw Γ₁ ρ D) data DecentTerm : {Γ₁ Γ₂ : RawCtx} → Raw Ø Γ₁ Γ₂ → Set where DO-unit : (Γ : RawCtx) → DecentTerm (unitRaw Γ) DO-objVar : {Γ : RawCtx} {A : U} → (x : RawVar Γ A) → DecentTerm (objVarRaw x) DO-inst : {Γ₁ Γ₂ : RawCtx} {A : U} → (t : Raw Ø Γ₁ (Γ₂ ↑ A)) → (s : Raw Ø Γ₁ Ø) → DecentTerm t → DecentTerm s → DecentTerm (instRaw {Γ₂ = Γ₂} t s) DO-dialg : (Δ : RawCtx) (Γ : RawCtx) (A : U) → (ρ : FP) (k : ℕ) → DecentTerm (dialgRaw Δ Γ A ρ k) DO-mapping : (Γ : RawCtx) (Δ : RawCtx) → (gs : FpMapData Raw Γ) → (ρ : FP) → DecentFpMapData gs → DecentTerm (recRaw Γ Δ gs ρ) DecentFpMapData : {Γ : RawCtx} → FpMapData Raw Γ → Set DecentFpMapData [ (Γ' , A , f , t) ] = DecentType A × DecentCtxMor f × DecentTerm t DecentFpMapData ((Γ' , A , f , t) ∷ ts) = DecentType A × DecentCtxMor f × DecentTerm t × DecentFpMapData ts DecentCtxMor : {Γ₁ Γ₂ : RawCtx} → CtxMor Raw Γ₁ Γ₂ → Set DecentCtxMor {Γ₂ = Ø} [] = ⊤ DecentCtxMor {Γ₂ = x ∷ Γ₂} (t ∷ f) = DecentTerm t × DecentCtxMor f DecentFpData : ∀{Θ Γ₂} → FpData Raw Θ Γ₂ → Set DecentFpData [ Γ , f , A ] = DecentCtxMor f × DecentType A DecentFpData ((Γ , f , A) ∷ D) = (DecentCtxMor f × DecentType A) × DecentFpData D {- DT-syntax : (Θ : TyCtx) (Γ₁ Γ₂ : RawCtx) → Raw Θ Γ₁ Γ₂ → Set DT-syntax _ _ _ A = DecentType A syntax DT-syntax Θ Γ₁ Γ₁ A = Θ ∥ Γ₁ ⊨ A ε Γ₂ ━ DO-syntax : (Γ₁ Γ₂ : RawCtx) → Raw Ø Γ₁ Γ₂ → Set DO-syntax _ _ t = DecentTerm t syntax DO-syntax Γ₁ Γ₂ t = Γ₁ ⊢ t ∈ Γ₂ ⊸? -} ------------------------------------- ------- Pre-types and terms ------------------------------------- PreType : (Θ : TyCtx) (Γ₁ Γ₂ : RawCtx) → Set PreType Θ Γ₁ Γ₂ = Σ (Raw Θ Γ₁ Γ₂) λ A → DecentType A _∣_/_⊸Ty = PreType mkPreType : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} → DecentType A → PreType Θ Γ₁ Γ₂ mkPreType {A = A} p = (A , p) PreTerm : (Γ₁ Γ₂ : RawCtx) → Set PreTerm Γ₁ Γ₂ = Σ (Raw Ø Γ₁ Γ₂) λ t → DecentTerm t mkPreTerm : ∀ {Γ₁ Γ₂} {t : Raw Ø Γ₁ Γ₂} → DecentTerm t → PreTerm Γ₁ Γ₂ mkPreTerm {t = t} p = (t , p) CtxMorP = CtxMor (λ _ → PreTerm) mkCtxMorP : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → DecentCtxMor f → CtxMorP Γ₁ Γ₂ mkCtxMorP {Γ₂ = Ø} p = [] mkCtxMorP {Γ₂ = x ∷ Γ₂} {t ∷ f} (p , ps) = (t , p) ∷ (mkCtxMorP ps) TyCtxMorP : TyCtx → TyCtx → Set TyCtxMorP Θ₁ Ø = ⊤ TyCtxMorP Θ₁ (Γ ∷ Θ₂) = PreType Θ₁ Ø Γ × TyCtxMorP Θ₁ Θ₂ FpDataP : TyCtx → RawCtx → Set FpDataP Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMorP Γ' Γ × PreType (Γ ∷ Θ) Γ' Ø)) mkFpDataP : ∀ {Θ Γ} {D : FpData Raw Θ Γ} → DecentFpData D → FpDataP Θ Γ mkFpDataP {D = [ Γ , f , A ]} (p , q) = [ Γ , (mkCtxMorP p) , mkPreType q ] mkFpDataP {D = (Γ , f , A) ∷ D} ((p , q) , r) = (Γ , mkCtxMorP p , mkPreType q) ∷ mkFpDataP {D = D} r -- | List of types, context morphisms and terms (Aₖ, fₖ, gₖ) such that -- Γₖ, x : Aₖ[C/X] ⊢ gₖ : C fₖ or -- Γₖ, x : C fₖ ⊢ gₖ : Aₖ[C/X], -- which are the premisses of the rule for recursion and corecursion, -- respectively. FpMapDataP : RawCtx → Set FpMapDataP Γ = NList (Σ RawCtx λ Γ' → PreType [ Γ ]L Γ' Ø × CtxMorP Γ' Γ × PreTerm (∗ ∷ Γ') Ø) mkFpMapDataP : ∀{Γ} {gs : FpMapData Raw Γ} → DecentFpMapData gs → FpMapDataP Γ mkFpMapDataP {Γ} {[ Γ' , A , f , t ]} (A-decent , f-decent , t-decent) = [ Γ' , mkPreType A-decent , mkCtxMorP f-decent , mkPreTerm t-decent ] mkFpMapDataP {Γ} {(Γ' , A , f , t) ∷ gs} (A-decent , f-decent , t-decent , r) = (Γ' , mkPreType A-decent , mkCtxMorP f-decent , mkPreTerm t-decent) ∷ mkFpMapDataP {Γ} {gs} r getFpData : ∀{Γ} → FpMapDataP Γ → FpDataP Ø Γ getFpData [ Γ' , A , f , _ ] = [ Γ' , f , A ] getFpData ((Γ' , A , f , _) ∷ d) = (Γ' , f , A) ∷ getFpData d projCtxMor₁ : {Γ₁ Γ₂ : RawCtx} → CtxMorP Γ₂ Γ₁ → CtxMor Raw Γ₂ Γ₁ projCtxMor₁ = Vec.map proj₁ projCtxMor₂ : {Γ₁ Γ₂ : RawCtx} → (f : CtxMorP Γ₂ Γ₁) → DecentCtxMor (projCtxMor₁ f) projCtxMor₂ {Ø} [] = tt projCtxMor₂ {x ∷ Γ₁} ((t , p) ∷ f) = (p , projCtxMor₂ f) projPTList₁ : ∀{Γ} → FpMapDataP Γ → FpMapData Raw Γ projPTList₁ = NList.map (Prod.map id (Prod.map proj₁ (Prod.map projCtxMor₁ proj₁))) projPTList₂ : ∀{Γ} → (gs : FpMapDataP Γ) → DecentFpMapData (projPTList₁ gs) projPTList₂ [ (Γ' , A , f , t) ] = (proj₂ A , projCtxMor₂ f , proj₂ t) projPTList₂ ((Γ' , A , f , t) ∷ gs) = (proj₂ A , projCtxMor₂ f , proj₂ t , projPTList₂ gs) projFpData₁ : ∀ {Θ Γ} → FpDataP Θ Γ → FpData Raw Θ Γ projFpData₁ = NList.map (Prod.map id (Prod.map projCtxMor₁ proj₁)) projFpData₂ : ∀ {Θ Γ} → (D : FpDataP Θ Γ) → DecentFpData (projFpData₁ D) projFpData₂ [ (Γ , f , A) ] = (projCtxMor₂ f , proj₂ A) projFpData₂ ((Γ , f , A) ∷ D) = ((projCtxMor₂ f , proj₂ A) , projFpData₂ D) ----------------------------------------- ----- Constructors for pre terms ----------------------------------------- ⊤-PT : (Θ : TyCtx) (Γ : RawCtx) → PreType Θ Γ Ø ⊤-PT Θ Γ = mkPreType (DT-⊤ Θ Γ) instPT : ∀ {Θ Γ₁ Γ₂ A} → PreType Θ Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → PreType Θ Γ₁ Γ₂ instPT (B , p) (t , q) = mkPreType (DT-inst _ _ p q) _⊙_ = instPT tyVarPT : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → TyVar Θ Γ₂ → PreType Θ Γ₁ Γ₂ tyVarPT Γ₁ X = mkPreType (DT-tyVar _ X) paramAbstrPT : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) {A : U} → PreType Θ (A ∷ Γ₁) Γ₂ → PreType Θ Γ₁ (Γ₂ ↑ A) paramAbstrPT Γ₁ (A , p) = mkPreType (DT-paramAbstr Γ₁ p) fpPT : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) → FP → FpDataP Θ Γ₂ → PreType Θ Γ₁ Γ₂ fpPT Γ₁ ρ D = mkPreType (DT-fp Γ₁ ρ (projFpData₁ D) (projFpData₂ D)) unitPO : (Γ : RawCtx) → PreTerm Γ Ø unitPO Γ = mkPreTerm (DO-unit _) varPO : {Γ : RawCtx} {A : U} → RawVar Γ A → PreTerm Γ Ø varPO x = mkPreTerm (DO-objVar x) instPO : ∀ {Γ₁ Γ₂ A} → PreTerm Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → PreTerm Γ₁ Γ₂ instPO (t , p) (s , q) = mkPreTerm (DO-inst _ _ p q) _§ₒ_ = instPO dialgPO : (Δ : RawCtx) (Γ : RawCtx) (A : U) → FP → ℕ → PreTerm Δ (A ∷ Γ) dialgPO Δ Γ A ρ k = mkPreTerm (DO-dialg _ Γ A ρ k) α : (Δ : RawCtx) (Γ : RawCtx) (A : U) → ℕ → PreTerm Δ (A ∷ Γ) α Δ Γ A k = dialgPO Δ Γ A μ k ξ : (Δ : RawCtx) (Γ : RawCtx) (A : U) → ℕ → PreTerm Δ (A ∷ Γ) ξ Δ Γ A k = dialgPO Δ Γ A ν k -- | Generalised recursion, does recursion or corecursion, depending on ρ grec : (Γ : RawCtx) (Δ : RawCtx) → FpMapDataP Γ → FP → PreTerm Δ (∗ ∷ Γ) grec Γ Δ gs ρ = mkPreTerm (DO-mapping Γ Δ (projPTList₁ gs) ρ (projPTList₂ gs)) -- | Recursion for inductive types rec : (Γ : RawCtx) (Δ : RawCtx) → FpMapDataP Γ → PreTerm Δ (∗ ∷ Γ) rec Γ Δ gs = grec Γ Δ gs μ -- Corecursion corec : (Γ : RawCtx) (Δ : RawCtx) → FpMapDataP Γ → PreTerm Δ (∗ ∷ Γ) corec Γ Δ gs = grec Γ Δ gs ν instWCtxMorP : {Γ₁ Γ₂ Γ₃ : RawCtx} → PreTerm Γ₁ (Γ₃ ++ Γ₂) → CtxMorP Γ₁ Γ₂ → PreTerm Γ₁ Γ₃ instWCtxMorP {Γ₁} {Ø} {Γ₃} t [] = subst (PreTerm Γ₁) (proj₂ identity Γ₃) t instWCtxMorP {Γ₁} {x ∷ Γ₂} {Γ₃} t (s ∷ f) = instPO (instWCtxMorP {Γ₂ = Γ₂} {Γ₃ = Γ₃ ↑ x} (subst (PreTerm Γ₁) (mvVar _ Γ₃ x) t) f) s _§ₘ'_ = instWCtxMorP _§ₘ_ : {Γ₁ Γ₂ : RawCtx} → PreTerm Γ₁ Γ₂ → CtxMorP Γ₁ Γ₂ → PreTerm Γ₁ Ø t §ₘ f = instWCtxMorP {Γ₃ = Ø} t f instTyWCtxMorP : ∀ {Θ Γ₁ Γ₂ Γ₃} → PreType Θ Γ₁ (Γ₃ ++ Γ₂) → CtxMorP Γ₁ Γ₂ → PreType Θ Γ₁ Γ₃ instTyWCtxMorP {Θ} {Γ₁} {Ø} {Γ₃} A [] = subst (PreType Θ Γ₁) (proj₂ identity Γ₃) A instTyWCtxMorP {Θ} {Γ₁} {x ∷ Γ₂} {Γ₃} A (s ∷ f) = (instTyWCtxMorP (subst (PreType Θ Γ₁) (mvVar _ Γ₃ x) A) f) ⊙ s _§ₜ_ : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → CtxMorP Γ₁ Γ₂ → PreType Θ Γ₁ Ø A §ₜ f = instTyWCtxMorP {Γ₃ = Ø} A f --------------------------------------------------------- --------- Recursion for pre-types --------------------------------------------------------- FpDataP' : (TyCtx → RawCtx → RawCtx → Set) → TyCtx → RawCtx → Set FpDataP' V Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMorP Γ' Γ × V (Γ ∷ Θ) Γ' Ø)) {-# NON_TERMINATING #-} mapPT : {V : TyCtx → RawCtx → RawCtx → Set} → ((Θ : TyCtx) (Γ₁ : RawCtx) → V Θ Γ₁ Ø) → (∀{Θ Γ₁ Γ₂} → TyVar Θ Γ₂ → V Θ Γ₁ Γ₂) → (∀{Θ Γ₁ Γ₂ A} → V Θ Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → V Θ Γ₁ Γ₂) → (∀{Θ Γ₁ Γ₂ A} → V Θ (A ∷ Γ₁) Γ₂ → V Θ Γ₁ (Γ₂ ↑ A)) → (∀{Θ Γ₁ Γ₂} → FP → FpDataP' V Θ Γ₂ → V Θ Γ₁ Γ₂) → ∀{Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → V Θ Γ₁ Γ₂ mapPT ⊤-x _ _ _ _ (._ , DT-⊤ Θ Γ) = ⊤-x Θ Γ mapPT _ var-x _ _ _ (._ , DT-tyVar Γ₁ X) = var-x X mapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-inst B t B-dec t-dec) = let r = mapPT ⊤-x var-x inst-x abstr-x fp-x (B , B-dec) in inst-x r (t , t-dec) mapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-paramAbstr Γ₁ {A} A-dec) = let r = mapPT ⊤-x var-x inst-x abstr-x fp-x (A , A-dec) in abstr-x r mapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-fp Γ₁ ρ D D-dec) = let D' = NList.map (Prod.map id (Prod.map id (mapPT ⊤-x var-x inst-x abstr-x fp-x))) (mkFpDataP {D = D} D-dec) in fp-x ρ D' ---------------------------------------------------------- --------- Meta theory for decent type predicate --------------------------------------------------------- weakenDO : (Γ₁ : RawCtx) → {Γ₂ Γ₃ : RawCtx} {t : Raw Ø (Γ₁ ++ Γ₂) Γ₃} → (A : U) → DecentTerm t → DecentTerm (weaken Γ₁ A t) weakenDO Γ₁ B (DO-unit ._) = DO-unit _ weakenDO Γ₁ B (DO-objVar x) = DO-objVar (weakenObjVar Γ₁ B x) weakenDO Γ₁ B (DO-inst t s p q) = DO-inst _ _ (weakenDO Γ₁ B p) (weakenDO Γ₁ B q) weakenDO Γ₁ B (DO-dialg ._ Γ A ρ k) = DO-dialg _ _ A ρ k weakenDO Γ₁ B (DO-mapping Γ ._ gs ρ p) = DO-mapping Γ _ gs ρ p weakenDT : ∀ {Θ} → (Γ₁ : RawCtx) → {Γ₂ Γ₃ : RawCtx} {A : Raw Θ (Γ₁ ++ Γ₂) Γ₃} → (B : U) → DecentType A → DecentType (weaken Γ₁ B A) weakenDT Γ₁ B (DT-⊤ Θ ._) = DT-⊤ Θ _ weakenDT Γ₁ B (DT-tyVar _ X) = DT-tyVar _ X weakenDT Γ₁ B (DT-inst A t p q) = DT-inst _ _ (weakenDT Γ₁ B p) (weakenDO Γ₁ B q) weakenDT Γ₁ B (DT-paramAbstr _ p) = DT-paramAbstr _ (weakenDT _ B p) weakenDT Γ₁ B (DT-fp _ ρ D p) = DT-fp _ ρ D p weakenDO₁ : ∀ {Γ₁ Γ₂} {t : Raw Ø Γ₁ Γ₂} → (A : U) → DecentTerm t → DecentTerm (weaken₁ A t) weakenDO₁ = weakenDO Ø weakenDT₁ : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} → (B : U) → DecentType A → DecentType (weaken₁ B A) weakenDT₁ = weakenDT Ø weakenDecentCtxMor : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → (A : U) → DecentCtxMor f → DecentCtxMor (Vec.map (weaken₁ A) f) weakenDecentCtxMor {Γ₂ = Ø} {[]} A p = tt weakenDecentCtxMor {Γ₂ = x ∷ Γ₂} {t ∷ f} A (p , ps) = (weakenDO₁ A p , weakenDecentCtxMor A ps) weakenCtxMorP : {Γ₁ Γ₂ : RawCtx} → CtxMorP Γ₁ Γ₂ → CtxMorP (∗ ∷ Γ₁) Γ₂ weakenCtxMorP f = mkCtxMorP (weakenDecentCtxMor ∗ (projCtxMor₂ f)) ----------------------------------------------------- ------ Meta operations on pre-terms and pre-types ----------------------------------------------------- weakenPT : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ Γ₃ : RawCtx} → (A : U) → PreType Θ (Γ₁ ++ Γ₂) Γ₃ → PreType Θ (Γ₁ ++ A ∷ Γ₂) Γ₃ weakenPT Γ₁ A (B , p) = (_ , weakenDT Γ₁ A p) weakenPT₁ : ∀ {Θ Γ₁ Γ₂} → (A : U) → PreType Θ Γ₁ Γ₂ → PreType Θ (A ∷ Γ₁) Γ₂ weakenPT₁ = weakenPT Ø weakenPO : (Γ₁ : RawCtx) {Γ₂ Γ₃ : RawCtx} → (A : U) → PreTerm (Γ₁ ++ Γ₂) Γ₃ → PreTerm (Γ₁ ++ A ∷ Γ₂) Γ₃ weakenPO Γ₁ A (t , p) = (_ , weakenDO Γ₁ A p) weakenPO₁ : {Γ₁ Γ₂ : RawCtx} → (A : U) → PreTerm Γ₁ Γ₂ → PreTerm (A ∷ Γ₁) Γ₂ weakenPO₁ = weakenPO Ø get' : {Γ₁ Γ₂ : RawCtx} {A : U} → (f : CtxMor (λ _ → PreTerm) Γ₂ Γ₁) → (x : RawVar Γ₁ A) → DecentTerm (get {Raw} (projCtxMor₁ f) x) get' (t ∷ f) zero = proj₂ t get' (t ∷ f) (succ {b = _} _ x) = get' f x -- | Lift substitutions to DecentTerm predicate substDO : {Γ₁ Γ Γ₂ : RawCtx} {t : Raw Ø Γ₁ Γ} → (f : CtxMorP Γ₂ Γ₁) → DecentTerm t → DecentTerm (substRaw t (projCtxMor₁ f)) substDO f (DO-unit Γ₁) = DO-unit _ substDO f (DO-objVar x) = get' f x substDO f (DO-inst t s p q) = DO-inst _ _ (substDO f p) (substDO f q) substDO f (DO-dialg Γ₁ Γ A ρ k) = DO-dialg _ _ A ρ k substDO f (DO-mapping Γ Γ₁ gs ρ p) = DO-mapping Γ _ _ _ p -- | Lift substRaw to pre terms substP : {Γ₁ Γ Γ₂ : RawCtx} → PreTerm Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreTerm Γ₂ Γ substP (t , p) f = (substRaw t (projCtxMor₁ f) , substDO f p) _↓[_] = substP -- | Context identity is a decent context morphism ctxidDO : (Γ : RawCtx) → DecentCtxMor (ctxid Γ) ctxidDO Ø = tt ctxidDO (x ∷ Γ) = (DO-objVar zero , weakenDecentCtxMor _ (ctxidDO Γ)) mkCtxMorP₁ : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → (p : DecentCtxMor f) → projCtxMor₁ (mkCtxMorP p) ≡ f mkCtxMorP₁ {Γ₂ = Ø} {[]} p = refl mkCtxMorP₁ {Γ₂ = A ∷ Γ₂} {t ∷ f} (p , ps) = begin projCtxMor₁ {A ∷ Γ₂} ((t , p) ∷ mkCtxMorP ps) ≡⟨ refl ⟩ t ∷ projCtxMor₁ (mkCtxMorP ps) ≡⟨ cong (λ u → t ∷ u) (mkCtxMorP₁ ps) ⟩ t ∷ f ∎ ctxidP : (Γ : RawCtx) → CtxMorP Γ Γ ctxidP Γ = mkCtxMorP (ctxidDO Γ) _↓[_/0] : {Γ₁ Γ Γ₂ : RawCtx} → PreTerm (∗ ∷ Γ₁) Γ → PreTerm Γ₁ Ø → PreTerm Γ₁ Γ _↓[_/0] t s = t ↓[ s ∷ ctxidP _ ] _•_ : {Γ₁ Γ₂ Γ₃ : RawCtx} → CtxMorP Γ₂ Γ₃ → CtxMorP Γ₁ Γ₂ → CtxMorP Γ₁ Γ₃ _•_ {Γ₃ = Ø} [] f = [] _•_ {Γ₃ = A ∷ Γ₃} (t ∷ g) f = substP t f ∷ (g • f) -- | Context projection is a decent context morphism ctxProjDO : (Γ₁ Γ₂ : RawCtx) → DecentCtxMor (ctxProjRaw Γ₁ Γ₂) ctxProjDO Γ₁ Ø = ctxidDO Γ₁ ctxProjDO Γ₁ (x ∷ Γ₂) = weakenDecentCtxMor _ (ctxProjDO Γ₁ Γ₂) ctxProjP : (Γ₁ Γ₂ : RawCtx) → CtxMorP (Γ₂ ++ Γ₁) Γ₁ ctxProjP Γ₁ Γ₂ = mkCtxMorP (ctxProjDO Γ₁ Γ₂) ctxProjP' : (Γ₁ Γ₂ Γ₃ : RawCtx) → CtxMorP (Γ₁ ++ Γ₂ ++ Γ₃) Γ₂ ctxProjP' Γ₁ Γ₂ Ø = subst (λ Γ → CtxMorP (Γ₁ ++ Γ) Γ₂) (PE.sym (proj₂ identity Γ₂)) (ctxProjP Γ₂ Γ₁) ctxProjP' Γ₁ Γ₂ (A ∷ Γ₃) = let f = ctxProjP' Γ₁ Γ₂ Γ₃ in subst (λ Γ → Vec (PreTerm Γ Ø) (length' Γ₂)) (assoc Γ₁ Γ₂ (A ∷ Γ₃)) (Vec.map (weakenPO (Γ₁ ++ Γ₂) A) (subst (λ Γ → Vec (PreTerm Γ Ø) (length' Γ₂)) (PE.sym (assoc Γ₁ Γ₂ Γ₃)) f ) ) weakenDO' : {Γ₁ Γ₃ : RawCtx} {t : Raw Ø Γ₁ Γ₃} → (Γ₂ : RawCtx) → DecentTerm t → DecentTerm (weaken' Γ₂ t) weakenDO' {Γ₁} {t = t} Γ₂ p = subst DecentTerm (cong (substRaw t) (mkCtxMorP₁ (ctxProjDO Γ₁ Γ₂))) (substDO (ctxProjP Γ₁ Γ₂) p) weakenPO' : {Γ₁ Γ₃ : RawCtx} → (Γ₂ : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂ ++ Γ₁) Γ₃ weakenPO' Γ₂ (t , p) = (weaken' Γ₂ t , weakenDO' Γ₂ p) -- | Lift extension of context morphism to decent terms extendP : {Γ₁ Γ₂ : RawCtx} → (A : U) → (f : CtxMorP Γ₂ Γ₁) → CtxMorP (A ∷ Γ₂) (A ∷ Γ₁) extendP {Γ₁} {Γ₂} A f = varPO zero ∷ Vec.map (weakenPO₁ A) f getPO : {Γ₁ Γ₂ : RawCtx} {A : U} → CtxMorP Γ₂ Γ₁ → RawVar Γ₁ A → PreTerm Γ₂ Ø getPO f x = (get {Raw} (projCtxMor₁ f) x , get' f x) substPO : ∀ {Γ₁ Γ Γ₂} → PreTerm Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreTerm Γ₂ Γ substPO (._ , DO-unit Γ₁) f = unitPO _ substPO (._ , DO-objVar x) f = getPO f x substPO (._ , DO-inst t s p q) f = instPO (substPO (t , p) f) (substPO (s , q) f) substPO (._ , DO-dialg Γ₁ Γ A ρ k) f = dialgPO _ Γ A ρ k substPO (._ , DO-mapping Γ Γ₁ gs ρ p) f = grec Γ _ (mkFpMapDataP {Γ} {gs} p) ρ weakenPO'' : {Γ₁ Γ₃ : RawCtx} → (Γ₂ Γ₂' : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂' ++ Γ₁ ++ Γ₂) Γ₃ weakenPO'' Γ₂ Γ₂' t = substPO t (ctxProjP' Γ₂' _ Γ₂) -- | Lift substitution to pretypes substPT : ∀ {Θ Γ₁ Γ Γ₂} → PreType Θ Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreType Θ Γ₂ Γ substPT (._ , DT-⊤ Θ Γ) f = ⊤-PT _ _ substPT (._ , DT-tyVar Γ₁ X) f = tyVarPT _ X substPT (._ , DT-inst B t p q) f = (substPT (B , p) f) ⊙ (substPO (t , q) f) substPT (._ , DT-paramAbstr Γ₁ {A} p) f = paramAbstrPT _ (substPT (A , p) (extendP _ f)) substPT (._ , DT-fp Γ₁ ρ D q) f = fpPT _ ρ (mkFpDataP {D = D} q) weakenPT' : ∀ {Θ Γ₁ Γ₂} (Γ : RawCtx) → PreType Θ Γ₁ Γ₂ → PreType Θ (Γ ++ Γ₁) Γ₂ weakenPT' {Γ₁ = Γ₁} Γ A = substPT A (ctxProjP Γ₁ Γ) weakenPT'' : ∀ {Θ Γ₁} (Γ : RawCtx) → PreType Θ Ø Γ₁ → PreType Θ Γ Γ₁ weakenPT'' Γ A = subst (λ u → PreType _ u _) (proj₂ identity Γ) (weakenPT' Γ A) -- | Project a specific variable out projVar : (Γ₁ Γ₂ : RawCtx) (A : U) → PreTerm (Γ₂ ++ A ∷ Γ₁) Ø projVar Γ₁ Ø A = varPO zero projVar Γ₁ (∗ ∷ Γ₂) A = weakenPO₁ _ (projVar Γ₁ Γ₂ A) extendProj : {Γ₁ Γ₂ : RawCtx} → (Γ₃ Γ₄ : RawCtx) → CtxMorP (Γ₄ ++ Γ₃ ++ Γ₂) Γ₁ → CtxMorP (Γ₄ ++ Γ₃ ++ Γ₂) (Γ₃ ++ Γ₁) extendProj Ø Γ₄ f = f extendProj {Γ₁} {Γ₂ = Γ₂} (A ∷ Γ₃) Γ₄ f = let p = (assoc Γ₄ (A ∷ Ø) (Γ₃ ++ Γ₂)) f' = subst (λ u → CtxMorP u Γ₁) (PE.sym p) f g = extendProj {Γ₁} {Γ₂} Γ₃ (Γ₄ ↑ A) f' g' = subst (λ u → CtxMorP u (Γ₃ ++ Γ₁)) p g in projVar (Γ₃ ++ Γ₂) Γ₄ A ∷ g' weakenTyVar₁ : ∀{Θ₂ Γ₁} (Θ₁ : TyCtx) (Γ : RawCtx) → TyVar (Θ₁ ++ Θ₂) Γ₁ → TyVar (Θ₁ ++ Γ ∷ Θ₂) Γ₁ weakenTyVar₁ Ø Γ X = succ _ X weakenTyVar₁ (Γ₁ ∷ Θ₁) Γ zero = zero weakenTyVar₁ (Γ₂ ∷ Θ₁) Γ (succ Γ₁ X) = succ Γ₁ (weakenTyVar₁ Θ₁ Γ X) weakenTyFpData'₁ : ∀ {Θ₂ Γ₁} (Θ₁ : TyCtx) → {D : FpData Raw (Θ₁ ++ Θ₂) Γ₁} → (Γ : RawCtx) → DecentFpData D → Σ (FpData Raw (Θ₁ ++ Γ ∷ Θ₂) Γ₁) DecentFpData -- | Auxiliary definition to allow Agda to see that it is provided with -- a well-defined reursion. weakenTy'₁ : ∀ {Θ₂ Γ₁ Γ₂} (Θ₁ : TyCtx) (Γ : RawCtx) → (A : Raw (Θ₁ ++ Θ₂) Γ₁ Γ₂) → DecentType A → PreType (Θ₁ ++ Γ ∷ Θ₂) Γ₁ Γ₂ weakenTy'₁ Θ₁ Γ ._ (DT-⊤ ._ Γ₁) = ⊤-PT _ _ weakenTy'₁ Θ₁ Γ .(tyVarRaw Γ₁ X) (DT-tyVar Γ₁ X) = tyVarPT Γ₁ (weakenTyVar₁ Θ₁ Γ X) weakenTy'₁ Θ₁ Γ .(instRaw B t) (DT-inst B t p q) = (weakenTy'₁ Θ₁ Γ B p) ⊙ (t , q) weakenTy'₁ Θ₁ Γ .(paramAbstrRaw Γ₁ A) (DT-paramAbstr Γ₁ {A} p) = paramAbstrPT Γ₁ (weakenTy'₁ Θ₁ Γ A p) weakenTy'₁ Θ₁ Γ .(fpRaw Γ₁ ρ D) (DT-fp Γ₁ ρ D p) = let (D' , p') = weakenTyFpData'₁ Θ₁ {D} Γ p in fpPT Γ₁ ρ (mkFpDataP {D = D'} p') weakenTyFpData'₁ {Γ₁ = Γ₁} Θ₁ {[ Γ₂ , f , A ]} Γ (p , q) = let (A' , q') = weakenTy'₁ (Γ₁ ∷ Θ₁) Γ A q in ([ Γ₂ , f , A' ] , p , q') weakenTyFpData'₁ {Γ₁ = Γ₁} Θ₁ {(Γ₂ , f , A) ∷ D} Γ ((p , q) , r) = let (A' , q') = weakenTy'₁ (Γ₁ ∷ Θ₁) Γ A q (D' , r') = weakenTyFpData'₁ Θ₁ {D} Γ r in ((Γ₂ , f , A') ∷ D' , (p , q') , r') weakenTy₁ : ∀ {Θ₂ Γ₁ Γ₂} (Θ₁ : TyCtx) (Γ : RawCtx) → PreType (Θ₁ ++ Θ₂) Γ₁ Γ₂ → PreType (Θ₁ ++ Γ ∷ Θ₂) Γ₁ Γ₂ weakenTy₁ Θ₁ Γ (A , p) = weakenTy'₁ Θ₁ Γ A p weakenTyCtxMor₁ : ∀ {Θ₁ Θ₂} → (Γ : RawCtx) → TyCtxMorP Θ₂ Θ₁ → TyCtxMorP (Γ ∷ Θ₂) Θ₁ weakenTyCtxMor₁ {Ø} Γ tt = tt weakenTyCtxMor₁ {Γ₁ ∷ Θ₁} Γ (A , f) = (weakenTy₁ Ø Γ A , weakenTyCtxMor₁ Γ f) getTy : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} → TyCtxMorP Θ₁ Θ₂ → TyVar Θ₂ Γ₂ → PreType Θ₁ Γ₁ Γ₂ getTy {Θ₂ = Ø} tt () getTy {Θ₁} {Θ₂ = Γ ∷ Θ₂} {Γ₁} (B , f) zero = subst (λ Γ' → PreType Θ₁ Γ' Γ) (proj₂ identity Γ₁) (weakenPT' Γ₁ B) getTy {Θ₂ = Γ ∷ Θ₂} (B , f) (succ Γ₂ X) = getTy f X extendTy : ∀ {Θ₁ Θ₂} → TyCtxMorP Θ₁ Θ₂ → (Γ : RawCtx) → TyCtxMorP (Γ ∷ Θ₁) (Γ ∷ Θ₂) extendTy f Γ = (tyVarPT Ø zero , weakenTyCtxMor₁ Γ f) substTyFpData' : ∀ {Θ₁ Θ₂ Γ} → (D : FpData Raw Θ₂ Γ) → DecentFpData D → TyCtxMorP Θ₁ Θ₂ → FpDataP Θ₁ Γ -- | Substitution for type variables, auxilary version to have a clearly -- terminating definition. substTy' : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} → (A : Raw Θ₂ Γ₁ Γ₂) → DecentType A → TyCtxMorP Θ₁ Θ₂ → PreType Θ₁ Γ₁ Γ₂ substTy' {Θ₁} ._ (DT-⊤ Θ Γ) f = ⊤-PT Θ₁ _ substTy' {Θ₁} ._ (DT-tyVar Γ₁ X) f = getTy f X substTy' {Θ₁} ._ (DT-inst B t p q) f = (substTy' B p f) ⊙ (t , q) substTy' {Θ₁} ._ (DT-paramAbstr Γ₁ {A} p) f = paramAbstrPT Γ₁ (substTy' A p f) substTy' {Θ₁} ._ (DT-fp Γ₁ ρ D p) f = fpPT Γ₁ ρ (substTyFpData' D p f) substTyFpData' {Γ = Γ} [ Γ₁ , g , A ] (p , q) f = [ Γ₁ , mkCtxMorP p , substTy' A q (extendTy f Γ) ] substTyFpData' {Γ = Γ} ((Γ₁ , g , A) ∷ D) ((p , q) , r) f = (Γ₁ , mkCtxMorP p , substTy' A q (extendTy f Γ)) ∷ substTyFpData' D r f -- | Substitution for type variables substTy : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} → PreType Θ₂ Γ₁ Γ₂ → TyCtxMorP Θ₁ Θ₂ → PreType Θ₁ Γ₁ Γ₂ substTy (A , p) = substTy' A p {- weakenTy : {Θ₁ : TyCtx} {Γ₁ Γ₂ : RawCtx} (Θ₂ : TyCtx) → Raw Θ₁ Γ₁ Γ₂ → Raw (Θ₂ ++ Θ₁) Γ₁ Γ₂ weakenTy = {!!} -} ----------------------------------------------- --- Other operations ---------------------------------------------- Λ : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → PreType Θ Ø (Γ₂ ++ Γ₁) Λ {Γ₁ = Ø} A = subst (λ Γ → PreType _ Ø Γ) (PE.sym (proj₂ identity _)) A Λ {Γ₁ = B ∷ Γ₁} {Γ₂} A = let A' = Λ (paramAbstrPT Γ₁ A) in subst (λ Γ → PreType _ Ø Γ) (assoc Γ₂ (B ∷ Ø) Γ₁) A' -------------------------------------------------- -- Examples -------------------------------------------------- -- We could prove the following -- DT-Prod : (Γ : RawCtx) → DecentType (ProdRaw Γ) -- However, it is easier to construct the product directly as pretype. Prod : (Γ : RawCtx) → PreType (Γ ︵ Γ) Ø Γ Prod Γ = fpPT Ø ν D where Δ = Γ ︵ Γ A : TyVar (Γ ∷ Δ) Γ A = succ Γ zero B : TyVar (Γ ∷ Δ) Γ B = succ Γ (succ Γ zero) D₁ = (Γ , ctxidP Γ , instTyWCtxMorP (tyVarPT Γ A) (ctxidP Γ)) D₂ = (Γ , ctxidP Γ , instTyWCtxMorP (tyVarPT Γ B) (ctxidP Γ)) D : FpDataP Δ Γ D = D₁ ∷ [ D₂ ]
{ "alphanum_fraction": 0.5346849793, "avg_line_length": 37.1717990276, "ext": "agda", "hexsha": "44f920dff546eabc67194b2663c7898203239bc5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z", "max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z", "max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "StillerHarpo/CoindDepTypes", "max_forks_repo_path": "Syntax/Syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z", "max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "StillerHarpo/CoindDepTypes", "max_issues_repo_path": "Syntax/Syntax.agda", "max_line_length": 80, "max_stars_count": 2, "max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "StillerHarpo/CoindDepTypes", "max_stars_repo_path": "Syntax/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z", "max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z", "num_tokens": 10208, "size": 22935 }
module Structure.Operator.Vector.FiniteDimensional.LinearMaps.ChangeOfBasis where open import Functional import Lvl open import Numeral.CoordinateVector as Vec using () renaming (Vector to Vec) open import Numeral.Finite open import Numeral.Natural open import Structure.Function.Multi open import Structure.Operator.Properties open import Structure.Operator.Vector.FiniteDimensional open import Structure.Operator.Vector.LinearCombination open import Structure.Operator.Vector.LinearMap open import Structure.Operator.Vector.Proofs open import Structure.Operator.Vector open import Structure.Relator.Properties open import Structure.Setoid open import Syntax.Transitivity open import Type private variable ℓ ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ : Lvl.Level private variable V Vₗ Vᵣ S : Type{ℓ} private variable _+ᵥ_ : V → V → V private variable _⋅ₛᵥ_ : S → V → V private variable _+ₛ_ _⋅ₛ_ : S → S → S private variable n : ℕ private variable i j k : 𝕟(n) private variable vf : Vec(n)(V) module _ ⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄ ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ (vectorSpace : VectorSpace{V = V}{S = S}(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_)) where open VectorSpace(vectorSpace) -- changeBasis : LinearOperator(vectorSpace)(linearCombination )
{ "alphanum_fraction": 0.7737704918, "avg_line_length": 32.1052631579, "ext": "agda", "hexsha": "8e8095dc7afa5b919083323733dd2a2cdca464e7", "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/FiniteDimensional/LinearMaps/ChangeOfBasis.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/FiniteDimensional/LinearMaps/ChangeOfBasis.agda", "max_line_length": 81, "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/FiniteDimensional/LinearMaps/ChangeOfBasis.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": 380, "size": 1220 }
open import Common.Prelude hiding (tt) instance tt : ⊤ tt = record{} _<_ : Nat → Nat → Set m < zero = ⊥ zero < suc n = ⊤ suc m < suc n = m < n instance <-suc : ∀ {m n} {{_ : m < n}} → m < suc n <-suc {zero} = tt <-suc {suc m} {zero} {{}} <-suc {suc m} {suc n} = <-suc {m} {n}
{ "alphanum_fraction": 0.4794520548, "avg_line_length": 16.2222222222, "ext": "agda", "hexsha": "dd2d27ad3c494ae4eaf33be20321425bdf0a5fa8", "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/NonUniqueInstance2.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/NonUniqueInstance2.agda", "max_line_length": 43, "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/NonUniqueInstance2.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": 130, "size": 292 }
S : Set S = S
{ "alphanum_fraction": 0.4285714286, "avg_line_length": 4.6666666667, "ext": "agda", "hexsha": "9c8045dfe512169f456e607dc517ed8dd7501599", "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/Fail/Issue623/B.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/Issue623/B.agda", "max_line_length": 7, "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/Issue623/B.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 8, "size": 14 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommMonoid where open import Cubical.Algebra.CommMonoid.Base public open import Cubical.Algebra.CommMonoid.Properties public
{ "alphanum_fraction": 0.8139534884, "avg_line_length": 28.6666666667, "ext": "agda", "hexsha": "651f1e3ccac150daf8b0ccafa30c3b03137a0dcc", "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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/Algebra/CommMonoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/Algebra/CommMonoid.agda", "max_line_length": 56, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/Algebra/CommMonoid.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 39, "size": 172 }
{-# OPTIONS --without-K #-} open import HoTT.Base open import HoTT.Identity open import HoTT.Equivalence open import HoTT.Equivalence.Sigma open import HoTT.Identity.Sigma open import HoTT.Identity.Pi open import HoTT.Transport.Identity open import HoTT.HLevel open import HoTT.Exercises.Chapter2.Exercise11 using (module Square ; pullback) module HoTT.Exercises.Chapter2.Exercise12 {i} {A B C D E F : 𝒰 i} {ac : A → C} {ab : A → B} {cd : C → D} {bd : B → D} {ce : C → E} {ef : E → F} {df : D → F} where module Squareₗ = Square ac ab cd bd module Squareᵣ = Square ce cd ef df module Squareₒ = Square (ce ∘ ac) ab ef (df ∘ bd) module _ {commₗ : Squareₗ.IsCommutative} {commᵣ : Squareᵣ.IsCommutative} {pullbackᵣ : Squareᵣ.IsPullback commᵣ {i}} where commₒ : Squareₒ.IsCommutative commₒ = commᵣ ∘ ac ∙ₕ ap df ∘ commₗ open Squareₗ.Commutative commₗ using () renaming (inducedMap to fₗ) open Squareᵣ.Commutative commᵣ using () renaming (inducedMap to fᵣ) open Squareₒ.Commutative commₒ using () renaming (inducedMap to fₒ) -- Solution based on https://pcapriotti.github.io/hott-exercises/chapter2.ex12.core.html equiv : (X : 𝒰 i) → pullback (X → C) (X → B) (cd ∘_) (bd ∘_) ≃ pullback (X → E) (X → B) (ef ∘_) ((df ∘ bd) ∘_) equiv X = -- Use pullbackᵣ to expand X → C to pullback (X → E) (X → D) (ef ∘_) (df ∘_) pullback (X → C) (X → B) (cd ∘_) (bd ∘_) ≃⟨ Σ-equiv₁ (fᵣ , pullbackᵣ X) ⟩ -- Reassociate pairs Σ[ (_ , xd , _) ∶ pullback (X → E) (X → D) (ef ∘_) (df ∘_) ] Σ[ xb ∶ (X → B) ] (xd == bd ∘ xb) ≃⟨ (λ{((xe , xd , pᵣ) , xb , pₗ) → xe , xb , xd , pₗ , pᵣ}) , qinv→isequiv ( (λ{(xe , xb , xd , pₗ , pᵣ) → (xe , xd , pᵣ) , xb , pₗ}) , (λ{((xe , xd , pᵣ) , xb , refl) → refl}) , (λ{(xe , xb , xd , pₗ , pᵣ) → refl}) ) ⟩ Σ[ xe ∶ (X → E) ] Σ[ xb ∶ (X → B) ] Σ[ xd ∶ (X → D) ] (xd == bd ∘ xb) × (ef ∘ xe == df ∘ xd) ≃⟨ Σ-equiv₂ (λ xe → Σ-equiv₂ λ xb → -- Use pₗ to rewrite ef ∘ xe == df ∘ xd as df ∘ bd ∘ xb, -- removing the dependency on xd Σ[ xd ∶ (X → D) ] (xd == bd ∘ xb) × (ef ∘ xe == df ∘ xd) ≃⟨ Σ-equiv₂ (λ xd → Σ-equiv₂ (idtoeqv ∘ ap (λ xf → ef ∘ xe == df ∘ xf))) ⟩ -- Associate pₗ with xd Σ[ xd ∶ (X → D) ] (xd == bd ∘ xb) × (ef ∘ xe == df ∘ bd ∘ xb) ≃⟨ Σ-assoc ⟩ -- Use Lemmas 3.11.8 and 3.11.9 (ii) to contract xd to bd ∘ xb (Σ[ xd ∶ (X → D) ] (xd == bd ∘ xb)) × (ef ∘ xe == df ∘ bd ∘ xb) ≃⟨ Σ-contr₁ ⦃ =-contrᵣ (bd ∘ xb) ⦄ ⟩ ef ∘ xe == df ∘ bd ∘ xb ∎) ⟩ pullback (X → E) (X → B) (ef ∘_) ((df ∘ bd) ∘_) ∎ where open ≃-Reasoning -- Proves that we compose the above equivalence with fₗ, we get out fₒ equiv-fₗ→fₒ : {X : 𝒰 i} (xa : X → A) → pr₁ (equiv X) (fₗ xa) == fₒ xa equiv-fₗ→fₒ {X = X} xa = pair⁼ (refl , pair⁼ (refl , p)) where xe = ce ∘ ac ∘ xa q : (cd ∘ ac ∘ xa , _) == (bd ∘ ab ∘ xa , _) q = pair⁼ (funext (commₗ ∘ xa) ⁻¹ , _) ⁻¹ p : pr₂ (pr₂ (pr₁ (equiv X) (fₗ xa))) == funext (commᵣ ∘ ac ∘ xa ∙ₕ ap df ∘ commₗ ∘ xa) p = -- Simplify the constant transport transport _ q _ =⟨ transportconst q _ ⟩ -- Move the ap function into the transport transport id (ap (λ xd → ef ∘ xe == df ∘ xd) (funext (commₗ ∘ xa))) (funext (commᵣ ∘ ac ∘ xa)) =⟨ transport-ap id (λ xd → ef ∘ xe == df ∘ xd) (funext (commₗ ∘ xa)) (funext (commᵣ ∘ ac ∘ xa)) ⟩ -- Apply Theorem 2.11.3 to eliminate the transport transport (λ xf → ef ∘ xe == df ∘ xf) (funext (commₗ ∘ xa)) (funext (commᵣ ∘ ac ∘ xa)) =⟨ transport=-constₗ (ef ∘ xe) (df ∘_) (funext (commₗ ∘ xa)) (funext (commᵣ ∘ ac ∘ xa)) ⟩ -- Combine the ap df into the funext on the right funext (commᵣ ∘ ac ∘ xa) ∙ ap (df ∘_) (funext (commₗ ∘ xa)) =⟨ _ ∙ₗ funext-ap df (commₗ ∘ xa) ⁻¹ ⟩ -- Combine the two funext funext (commᵣ ∘ ac ∘ xa) ∙ funext (ap df ∘ commₗ ∘ xa) =⟨ funext-∙ₕ (commᵣ ∘ ac ∘ xa) (ap df ∘ commₗ ∘ xa) ⁻¹ ⟩ funext (commᵣ ∘ ac ∘ xa ∙ₕ ap df ∘ commₗ ∘ xa) ∎ where open =-Reasoning prop₁ : Squareₗ.IsPullback commₗ → Squareₒ.IsPullback commₒ prop₁ pullbackₗ X = transport isequiv (funext equiv-fₗ→fₒ) (pr₂ ((fₗ , pullbackₗ X) ∙ₑ equiv X)) equiv-fₒ→fₗ : {X : 𝒰 i} (xa : X → A) → pr₁ (equiv X ⁻¹ₑ) (fₒ xa) == fₗ xa equiv-fₒ→fₗ {X = X} xa = ap g (equiv-fₗ→fₒ xa ⁻¹) ∙ η (fₗ xa) where open qinv (isequiv→qinv (pr₂ (equiv X))) prop₂ : Squareₒ.IsPullback commₒ {i} → Squareₗ.IsPullback commₗ {i} prop₂ pullbackₒ X = transport isequiv (funext equiv-fₒ→fₗ) (pr₂ ((fₒ , pullbackₒ X) ∙ₑ equiv X ⁻¹ₑ)) -- I tried quite hard to come up with the equivalences directly, -- but was only able to find one of the four necessary homotopies. -- The other three quickly spiraled out of control. =pullback-intro : {A B C : 𝒰 i} {ac : A → C} {bc : B → C} {x@(a₁ , b₁ , p) y@(a₂ , b₂ , q) : pullback A B ac bc} → Σ[ p₁ ∶ a₁ == a₂ ] Σ[ p₂ ∶ b₁ == b₂ ] (p ∙ ap bc p₂ == ap ac p₁ ∙ q) → x == y =pullback-intro {x = _ , _ , _} {y = _ , _ , _} (refl , refl , p) rewrite unitᵣ ∙ p ∙ unitₗ ⁻¹ = refl =pullback-elim : {A B C : 𝒰 i} {ac : A → C} {bc : B → C} {x@(a₁ , b₁ , p) y@(a₂ , b₂ , q) : pullback A B ac bc} → x == y → Σ[ p₁ ∶ a₁ == a₂ ] Σ[ p₂ ∶ b₁ == b₂ ] (p ∙ ap bc p₂ == ap ac p₁ ∙ q) =pullback-elim {x = _ , _ , _} {y = _ , _ , _} refl = refl , refl , unitᵣ ⁻¹ ∙ unitₗ prop₁' : Squareₗ.IsPullback commₗ → Squareₒ.IsPullback commₒ prop₁' pullbackₗ X with isequiv→qinv (pullbackᵣ X) | isequiv→qinv (pullbackₗ X) ... | (gᵣ , ηᵣ , εᵣ) | (gₗ , ηₗ , εₗ) = qinv→isequiv (gₒ , ηₒ , εₒ) where gₒ : pullback (X → E) (X → B) (ef ∘_) ((df ∘ bd) ∘_) → (X → A) gₒ (xe , xb , p) = gₗ (gᵣ xc' , xb , ap (pr₁ ∘ pr₂) (εᵣ xc')) where xc' = (xe , bd ∘ xb , p) ηₒ : gₒ ∘ fₒ ~ id ηₒ xa = ap gₗ (=pullback-intro (p-xc , refl , p-pₗ)) ∙ ηₗ xa where pᵣ = funext (commᵣ ∘ ac ∘ xa ∙ₕ ap df ∘ commₗ ∘ xa) xc' = ce ∘ ac ∘ xa , bd ∘ ab ∘ xa , pᵣ p-xd = funext (commₗ ∘ xa) ⁻¹ p-pᵣ : pᵣ ∙ ap (df ∘_) p-xd == refl ∙ funext (commᵣ ∘ ac ∘ xa) p-pᵣ = pᵣ ∙ ap (df ∘_) p-xd =⟨ _ ∙ₗ ap-inv (df ∘_) (funext (commₗ ∘ xa)) ⟩ _ ∙ p ⁻¹ =⟨ funext-∙ₕ (commᵣ ∘ ac ∘ xa) (ap df ∘ commₗ ∘ xa) ∙ᵣ _ ⟩ _ ∙ funext (ap df ∘ commₗ ∘ xa) ∙ _ =⟨ _ ∙ₗ funext-ap df (commₗ ∘ xa) ∙ᵣ _ ⟩ funext (commᵣ ∘ ac ∘ xa) ∙ p ∙ p ⁻¹ =⟨ assoc ⁻¹ ⟩ funext (commᵣ ∘ ac ∘ xa) ∙ (p ∙ p ⁻¹) =⟨ _ ∙ₗ invᵣ ⟩ funext (commᵣ ∘ ac ∘ xa) ∙ refl =⟨ unitᵣ ⁻¹ ⟩ funext (commᵣ ∘ ac ∘ xa) =⟨ unitₗ ⟩ refl ∙ funext (commᵣ ∘ ac ∘ xa) ∎ where open =-Reasoning p = ap (df ∘_) (funext (commₗ ∘ xa)) p-xc : gᵣ xc' == ac ∘ xa p-xc = ap gᵣ (=pullback-intro (refl , p-xd , p-pᵣ)) ∙ ηᵣ (ac ∘ xa) -- TODO postulate p-pₗ : ap (pr₁ ∘ pr₂) (εᵣ xc') ∙ refl == ap (cd ∘_) p-xc ∙ funext (commₗ ∘ xa) -- TODO postulate εₒ : fₒ ∘ gₒ ~ id prop₂' : Squareₒ.IsPullback commₒ → Squareₗ.IsPullback commₗ prop₂' sₒ-pullback X = qinv→isequiv (gₗ , ηₗ , εₗ) where open qinv (isequiv→qinv (sₒ-pullback X)) renaming (g to gₒ ; η to ηₒ ; ε to εₒ) open qinv (isequiv→qinv (pullbackᵣ X)) renaming (g to gᵣ ; η to ηᵣ ; ε to εᵣ) gₗ : pullback (X → C) (X → B) (cd ∘_) (bd ∘_) → (X → A) gₗ (xc , xb , pₗ) = gₒ (ce ∘ xc , xb , funext (commᵣ ∘ xc) ∙ ap (df ∘_) pₗ) ηₗ : gₗ ∘ fₗ ~ id ηₗ xa = ap gₒ (pair⁼ (refl , pair⁼ (refl , _ ∙ₗ funext-ap df (commₗ ∘ xa) ⁻¹ ∙ funext-∙ₕ (commᵣ ∘ ac ∘ xa) (ap df ∘ commₗ ∘ xa) ⁻¹))) ∙ ηₒ xa εₗ : fₗ ∘ gₗ ~ id εₗ (xc , xb , pₗ) = =pullback-intro (p-xc , p-xb , p-pₗ) where xa = gₗ (xc , xb , pₗ) xa' = ce ∘ xc , xb , funext (commᵣ ∘ xc) ∙ ap (df ∘_) pₗ p-xa' = =pullback-elim (εₒ xa') p-xe = pr₁ p-xa' p-xb = pr₁ (pr₂ p-xa') p-pₒ = pr₂ (pr₂ p-xa') p-xd = funext (commₗ ∘ xa) ∙ ap (bd ∘_) p-xb ∙ pₗ ⁻¹ -- TODO postulate p-pᵣ : funext (commᵣ ∘ ac ∘ xa) ∙ ap (df ∘_) p-xd == ap (ef ∘_) p-xe ∙ funext (commᵣ ∘ xc) p-xc : ac ∘ xa == xc p-xc = ηᵣ (ac ∘ xa) ⁻¹ ∙ ap gᵣ (=pullback-intro (p-xe , p-xd , p-pᵣ)) ∙ ηᵣ xc -- TODO postulate p-pₗ : funext (commₗ ∘ xa) ∙ ap (bd ∘_) p-xb == ap (cd ∘_) p-xc ∙ pₗ
{ "alphanum_fraction": 0.5046486995, "avg_line_length": 45.1968085106, "ext": "agda", "hexsha": "cec52c5c29dd28d514452b234ba0f308f1435fc5", "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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "michaelforney/hott", "max_forks_repo_path": "HoTT/Exercises/Chapter2/Exercise12.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "michaelforney/hott", "max_issues_repo_path": "HoTT/Exercises/Chapter2/Exercise12.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "michaelforney/hott", "max_stars_repo_path": "HoTT/Exercises/Chapter2/Exercise12.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4002, "size": 8497 }
-- {-# OPTIONS -v tc.constr.findInScope:15 -v tc.meta.new:50 #-} -- Andreas, 2012-10-20 issue raised by d.starosud -- solved by dropping UnBlock constraints during trial candidate assignment module Fail.Issue723 where import Common.Level open import Common.Prelude using (Bool; false; zero) renaming (Nat to ℕ) record Default {ℓ} (A : Set ℓ) : Set ℓ where constructor create field default : A open Default {{...}} using (default) instance defBool : Default Bool defBool = create false defSet : Default Set defSet = create Bool defNat : Default ℕ defNat = create zero defDef : Default (Default ℕ) defDef = create defNat defFunc : ∀ {ℓ} {A : Set ℓ} → Default (A → A) defFunc = create (λ x → x) -- these lines are compiled successfully id : ∀ {a} (A : Set a) → A → A id A x = x syntax id A x = x ∶ A n₁ = default ∶ ℕ f₁ = default ∶ (ℕ → ℕ) -- WAS: but this one hangs on "Checking" n₂ = default (5 ∶ ℕ) ∶ ℕ -- n₂ = id ℕ (default (id ℕ 5)) n : ℕ n = default 5 -- now we get unsolved metas -- that's kind of ok n₃ = (default ∶ (_ → _)) 5 -- this one works again (before: also unsolved metas (worked before switching of the occurs-error (Issue 795)))
{ "alphanum_fraction": 0.6582278481, "avg_line_length": 22.7884615385, "ext": "agda", "hexsha": "05d744a779d2b1af838f9a2dec7c264950fb8ecc", "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/Issue723.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/Issue723.agda", "max_line_length": 111, "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/Issue723.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": 383, "size": 1185 }
------------------------------------------------------------------------------ -- Testing the translation of function, predicates and variables names ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- From the technical manual of TPTP -- (http://www.cs.miami.edu/~tptp/TPTP/TR/TPTPTR.shtml) -- ... variables start with upper case letters, ... predicates and -- functors either start with lower case and contain alphanumerics and -- underscore ... module Names where infix 4 _≡_ ------------------------------------------------------------------------------ -- Testing funny names postulate D : Set _≡_ : D → D → Set FUN! : D → D -- A funny function name. PRED! : D → Set -- A funny predicate name. -- Using a funny function and variable name. postulate funnyFV : (nx∎ : D) → FUN! nx∎ ≡ nx∎ {-# ATP axiom funnyFV #-} -- Using a funny predicate name. postulate funnyP : (n : D) → PRED! n {-# ATP axiom funnyP #-} -- We need to have at least one conjecture to generate a TPTP file. postulate refl : ∀ d → d ≡ d {-# ATP prove refl #-}
{ "alphanum_fraction": 0.5103011094, "avg_line_length": 30.7804878049, "ext": "agda", "hexsha": "0cadabd2b304c2a939e9ea051bcb75100e994030", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/Names.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/Names.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/Names.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 288, "size": 1262 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Paths open import lib.types.TwoSemiCategory module lib.two-semi-categories.Functor where record TwoSemiFunctor {i₁ j₁ i₂ j₂} (C : TwoSemiCategory i₁ j₁) (D : TwoSemiCategory i₂ j₂) : Type (lmax (lmax i₁ j₁) (lmax i₂ j₂)) where private module C = TwoSemiCategory C module D = TwoSemiCategory D field F₀ : C.El → D.El F₁ : {x y : C.El} → C.Arr x y → D.Arr (F₀ x) (F₀ y) pres-comp : {x y z : C.El} (f : C.Arr x y) (g : C.Arr y z) → F₁ (C.comp f g) == D.comp (F₁ f) (F₁ g) pres-comp-coh-seq₁ : {w x y z : C.El} (f : C.Arr w x) (g : C.Arr x y) (h : C.Arr y z) → F₁ (C.comp (C.comp f g) h) =-= D.comp (F₁ f) (D.comp (F₁ g) (F₁ h)) pres-comp-coh-seq₁ f g h = F₁ (C.comp (C.comp f g) h) =⟪ pres-comp (C.comp f g) h ⟫ D.comp (F₁ (C.comp f g)) (F₁ h) =⟪ ap (λ s → D.comp s (F₁ h)) (pres-comp f g) ⟫ D.comp (D.comp (F₁ f) (F₁ g)) (F₁ h) =⟪ D.assoc (F₁ f) (F₁ g) (F₁ h) ⟫ D.comp (F₁ f) (D.comp (F₁ g) (F₁ h)) ∎∎ pres-comp-coh-seq₂ : {w x y z : C.El} (f : C.Arr w x) (g : C.Arr x y) (h : C.Arr y z) → F₁ (C.comp (C.comp f g) h) =-= D.comp (F₁ f) (D.comp (F₁ g) (F₁ h)) pres-comp-coh-seq₂ f g h = F₁ (C.comp (C.comp f g) h) =⟪ ap F₁ (C.assoc f g h) ⟫ F₁ (C.comp f (C.comp g h)) =⟪ pres-comp f (C.comp g h) ⟫ D.comp (F₁ f) (F₁ (C.comp g h)) =⟪ ap (D.comp (F₁ f)) (pres-comp g h) ⟫ D.comp (F₁ f) (D.comp (F₁ g) (F₁ h)) ∎∎ field pres-comp-coh : {w x y z : C.El} (f : C.Arr w x) (g : C.Arr x y) (h : C.Arr y z) → pres-comp-coh-seq₁ f g h =ₛ pres-comp-coh-seq₂ f g h module FunctorComposition {i₁ j₁ i₂ j₂ i₃ j₃} {C : TwoSemiCategory i₁ j₁} {D : TwoSemiCategory i₂ j₂} {E : TwoSemiCategory i₃ j₃} (F : TwoSemiFunctor C D) (G : TwoSemiFunctor D E) where private module C = TwoSemiCategory C module D = TwoSemiCategory D module E = TwoSemiCategory E module F = TwoSemiFunctor F module G = TwoSemiFunctor G F₀ : C.El → E.El F₀ = G.F₀ ∘ F.F₀ F₁ : {x y : C.El} → C.Arr x y → E.Arr (F₀ x) (F₀ y) F₁ f = G.F₁ (F.F₁ f) pres-comp-seq : {x y z : C.El} (f : C.Arr x y) (g : C.Arr y z) → G.F₁ (F.F₁ (C.comp f g)) =-= E.comp (G.F₁ (F.F₁ f)) (G.F₁ (F.F₁ g)) pres-comp-seq f g = G.F₁ (F.F₁ (C.comp f g)) =⟪ ap G.F₁ (F.pres-comp f g) ⟫ G.F₁ (D.comp (F.F₁ f) (F.F₁ g)) =⟪ G.pres-comp (F.F₁ f) (F.F₁ g) ⟫ E.comp (G.F₁ (F.F₁ f)) (G.F₁ (F.F₁ g)) ∎∎ abstract pres-comp : {x y z : C.El} (f : C.Arr x y) (g : C.Arr y z) → G.F₁ (F.F₁ (C.comp f g)) == E.comp (G.F₁ (F.F₁ f)) (G.F₁ (F.F₁ g)) pres-comp f g = ↯ (pres-comp-seq f g) pres-comp-β : {x y z : C.El} (f : C.Arr x y) (g : C.Arr y z) → pres-comp f g ◃∎ =ₛ pres-comp-seq f g pres-comp-β f g = =ₛ-in idp private abstract pres-comp-coh : {w x y z : C.El} (f : C.Arr w x) (g : C.Arr x y) (h : C.Arr y z) → pres-comp (C.comp f g) h ◃∙ ap (λ s → E.comp s (F₁ h)) (pres-comp f g) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ ap F₁ (C.assoc f g h) ◃∙ pres-comp f (C.comp g h) ◃∙ ap (E.comp (F₁ f)) (pres-comp g h) ◃∎ pres-comp-coh f g h = pres-comp (C.comp f g) h ◃∙ ap (λ s → E.comp s (F₁ h)) (pres-comp f g) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ⟨ 0 & 1 & expand (pres-comp-seq (C.comp f g) h) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ G.pres-comp (F.F₁ (C.comp f g)) (F.F₁ h) ◃∙ ap (λ s → E.comp s (F₁ h)) (pres-comp f g) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ⟨ 2 & 1 & ap-seq-∙ (λ s → E.comp s (F₁ h)) (pres-comp-seq f g) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ G.pres-comp (F.F₁ (C.comp f g)) (F.F₁ h) ◃∙ ap (λ s → E.comp s (F₁ h)) (ap G.F₁ (F.pres-comp f g)) ◃∙ ap (λ s → E.comp s (F₁ h)) (G.pres-comp (F.F₁ f) (F.F₁ g)) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ₁⟨ 2 & 1 & ∘-ap (λ s → E.comp s (F₁ h)) G.F₁ (F.pres-comp f g) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ G.pres-comp (F.F₁ (C.comp f g)) (F.F₁ h) ◃∙ ap (λ s → E.comp (G.F₁ s) (F₁ h)) (F.pres-comp f g) ◃∙ ap (λ s → E.comp s (F₁ h)) (G.pres-comp (F.F₁ f) (F.F₁ g)) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ⟨ 1 & 2 & !ₛ $ homotopy-naturality (λ s → G.F₁ (D.comp s (F.F₁ h))) (λ s → E.comp (G.F₁ s) (F₁ h)) (λ s → G.pres-comp s (F.F₁ h)) (F.pres-comp f g) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ ap (λ s → G.F₁ (D.comp s (F.F₁ h))) (F.pres-comp f g) ◃∙ G.pres-comp (D.comp (F.F₁ f) (F.F₁ g)) (F.F₁ h) ◃∙ ap (λ s → E.comp s (F₁ h)) (G.pres-comp (F.F₁ f) (F.F₁ g)) ◃∙ E.assoc (F₁ f) (F₁ g) (F₁ h) ◃∎ =ₛ⟨ 2 & 3 & G.pres-comp-coh (F.F₁ f) (F.F₁ g) (F.F₁ h) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ ap (λ s → G.F₁ (D.comp s (F.F₁ h))) (F.pres-comp f g) ◃∙ ap G.F₁ (D.assoc (F.F₁ f) (F.F₁ g) (F.F₁ h)) ◃∙ G.pres-comp (F.F₁ f) (D.comp (F.F₁ g) (F.F₁ h)) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ₁⟨ 1 & 1 & ap-∘ G.F₁ (λ s → D.comp s (F.F₁ h)) (F.pres-comp f g) ⟩ ap G.F₁ (F.pres-comp (C.comp f g) h) ◃∙ ap G.F₁ (ap (λ s → D.comp s (F.F₁ h)) (F.pres-comp f g)) ◃∙ ap G.F₁ (D.assoc (F.F₁ f) (F.F₁ g) (F.F₁ h)) ◃∙ G.pres-comp (F.F₁ f) (D.comp (F.F₁ g) (F.F₁ h)) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ⟨ 0 & 3 & ap-seq-=ₛ G.F₁ (F.pres-comp-coh f g h) ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ ap G.F₁ (F.pres-comp f (C.comp g h)) ◃∙ ap G.F₁ (ap (D.comp (F.F₁ f)) (F.pres-comp g h)) ◃∙ G.pres-comp (F.F₁ f) (D.comp (F.F₁ g) (F.F₁ h)) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ₁⟨ 2 & 1 & ∘-ap G.F₁ (D.comp (F.F₁ f)) (F.pres-comp g h) ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ ap G.F₁ (F.pres-comp f (C.comp g h)) ◃∙ ap (G.F₁ ∘ D.comp (F.F₁ f)) (F.pres-comp g h) ◃∙ G.pres-comp (F.F₁ f) (D.comp (F.F₁ g) (F.F₁ h)) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ⟨ 2 & 2 & homotopy-naturality (G.F₁ ∘ D.comp (F.F₁ f)) (E.comp (F₁ f) ∘ G.F₁) (G.pres-comp (F.F₁ f)) (F.pres-comp g h) ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ ap G.F₁ (F.pres-comp f (C.comp g h)) ◃∙ G.pres-comp (F.F₁ f) (F.F₁ (C.comp g h)) ◃∙ ap (λ s → E.comp (F₁ f) (G.F₁ s)) (F.pres-comp g h) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ⟨ 1 & 2 & contract ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ pres-comp f (C.comp g h) ◃∙ ap (λ s → E.comp (F₁ f) (G.F₁ s)) (F.pres-comp g h) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ₁⟨ 2 & 1 & ap-∘ (E.comp (F₁ f)) G.F₁ (F.pres-comp g h) ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ pres-comp f (C.comp g h) ◃∙ ap (E.comp (F₁ f)) (ap G.F₁ (F.pres-comp g h)) ◃∙ ap (E.comp (F₁ f)) (G.pres-comp (F.F₁ g) (F.F₁ h)) ◃∎ =ₛ⟨ 2 & 2 & ∙-ap-seq (E.comp (F₁ f)) (pres-comp-seq g h) ⟩ ap G.F₁ (ap F.F₁ (C.assoc f g h)) ◃∙ pres-comp f (C.comp g h) ◃∙ ap (E.comp (F₁ f)) (pres-comp g h) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap G.F₁ F.F₁ (C.assoc f g h) ⟩ ap F₁ (C.assoc f g h) ◃∙ pres-comp f (C.comp g h) ◃∙ ap (E.comp (F₁ f)) (pres-comp g h) ◃∎ ∎ₛ composition : TwoSemiFunctor C E composition = record { F₀ = F₀ ; F₁ = F₁ ; pres-comp = pres-comp ; pres-comp-coh = pres-comp-coh } open FunctorComposition renaming ( composition to comp-functors ; pres-comp-seq to comp-functors-pres-comp-seq ; pres-comp to comp-functors-pres-comp ; pres-comp-β to comp-functors-pres-comp-β ) public infixr 80 _–F→_ _–F→_ = comp-functors
{ "alphanum_fraction": 0.4655660958, "avg_line_length": 42.9470899471, "ext": "agda", "hexsha": "815e5c974cf841fd48d26e45f5927341be7f35d4", "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/two-semi-categories/Functor.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/two-semi-categories/Functor.agda", "max_line_length": 115, "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/two-semi-categories/Functor.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": 3730, "size": 8117 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Groups.Definition open import Numbers.Naturals.Definition open import Setoids.Setoids open import Sets.EquivalenceRelations open import Rings.Definition open import Rings.EuclideanDomains.Definition open import Fields.Fields open import Fields.Lemmas module Rings.EuclideanDomains.Examples where polynomialField : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) → (Setoid._∼_ S (Ring.1R R) (Ring.0R R) → False) → EuclideanDomain R EuclideanDomain.isIntegralDomain (polynomialField F 1!=0) = fieldIsIntDom F EuclideanDomain.norm (polynomialField F _) a!=0 = zero EuclideanDomain.normSize (polynomialField F _) a!=0 b!=0 c b=ac = inr refl DivisionAlgorithmResult.quotient (EuclideanDomain.divisionAlg (polynomialField {_*_ = _*_} F _) {a = a} {b} a!=0 b!=0) with Field.allInvertible F b b!=0 ... | bInv , prB = a * bInv DivisionAlgorithmResult.rem (EuclideanDomain.divisionAlg (polynomialField F _) a!=0 b!=0) = Field.0F F DivisionAlgorithmResult.remSmall (EuclideanDomain.divisionAlg (polynomialField {S = S} F _) a!=0 b!=0) = inl (Equivalence.reflexive (Setoid.eq S)) DivisionAlgorithmResult.divAlg (EuclideanDomain.divisionAlg (polynomialField {S = S} {R = R} F _) {a = a} {b = b} a!=0 b!=0) with Field.allInvertible F b b!=0 ... | bInv , prB = transitive (transitive (transitive (symmetric identIsIdent) (transitive *Commutative (*WellDefined reflexive (symmetric prB)))) *Associative) (symmetric identRight) where open Setoid S open Equivalence eq open Ring R open Group additiveGroup
{ "alphanum_fraction": 0.735347432, "avg_line_length": 53.3870967742, "ext": "agda", "hexsha": "fc02ac5f011209026b3fb5e15b3ca2ec4a528efe", "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": "Rings/EuclideanDomains/Examples.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": "Rings/EuclideanDomains/Examples.agda", "max_line_length": 188, "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": "Rings/EuclideanDomains/Examples.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": 515, "size": 1655 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Setoids.Setoids open import Rings.Definition open import Groups.Definition open import Fields.Fields open import Sets.EquivalenceRelations open import LogicalFormulae open import Rings.IntegralDomains.Definition open import Rings.IntegralDomains.Lemmas open import Setoids.Subset module Fields.Lemmas {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) where open Setoid S open Field F open Ring R open Group additiveGroup open Equivalence eq open import Rings.Lemmas R halve : (charNot2 : ((1R + 1R) ∼ 0R) → False) → (a : A) → Sg A (λ i → i + i ∼ a) halve charNot2 a with allInvertible (1R + 1R) charNot2 ... | 1/2 , pr1/2 = (a * 1/2) , transitive (+WellDefined *Commutative *Commutative) (transitive (symmetric (*DistributesOver+ {1/2} {a} {a})) (transitive (*WellDefined (reflexive) r) (transitive (*Associative) (transitive (*WellDefined pr1/2 (reflexive)) identIsIdent)))) where r : a + a ∼ (1R + 1R) * a r = symmetric (transitive *Commutative (transitive *DistributesOver+ (+WellDefined (transitive *Commutative identIsIdent) (transitive *Commutative identIsIdent)))) abstract halfHalves : {x : A} (1/2 : A) (pr : 1/2 + 1/2 ∼ 1R) → (x + x) * 1/2 ∼ x halfHalves {x} 1/2 pr = transitive (transitive (transitive *Commutative (transitive (transitive *DistributesOver+ (transitive (+WellDefined *Commutative *Commutative) (symmetric *DistributesOver+))) *Commutative)) (*WellDefined pr (reflexive))) identIsIdent fieldIsIntDom : IntegralDomain R IntegralDomain.intDom fieldIsIntDom {a} {b} ab=0 a!=0 with Field.allInvertible F a a!=0 IntegralDomain.intDom fieldIsIntDom {a} {b} ab=0 a!=0 | 1/a , prA = transitive (symmetric identIsIdent) (transitive (*WellDefined (symmetric prA) reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive ab=0) (Ring.timesZero R)))) IntegralDomain.nontrivial fieldIsIntDom 1=0 = Field.nontrivial F (symmetric 1=0) allInvertibleWellDefined : {a b : A} {a!=0 : (a ∼ 0F) → False} {b!=0 : (b ∼ 0F) → False} → (a ∼ b) → underlying (allInvertible a a!=0) ∼ underlying (allInvertible b b!=0) allInvertibleWellDefined {a} {b} {a!=0} {b!=0} a=b with allInvertible a a!=0 ... | x , prX with allInvertible b b!=0 ... | y , prY with transitive (transitive prX (symmetric prY)) (*WellDefined reflexive (symmetric a=b)) ... | xa=ya = cancelIntDom fieldIsIntDom (transitive *Commutative (transitive xa=ya *Commutative)) a!=0 private mulNonzeros : Sg A (λ m → (Setoid._∼_ S m (Ring.0R R)) → False) → Sg A (λ m → (Setoid._∼_ S m (Ring.0R R)) → False) → Sg A (λ m → (Setoid._∼_ S m (Ring.0R R)) → False) mulNonzeros (a , a!=0) (b , b!=0) = (a * b) , λ ab=0 → b!=0 (IntegralDomain.intDom (fieldIsIntDom) ab=0 a!=0) fieldMultiplicativeGroup : Group (subsetSetoid S {pred = λ m → ((Setoid._∼_ S m (Ring.0R R)) → False)}(λ {x} {y} x=y x!=0 → λ y=0 → x!=0 (Equivalence.transitive (Setoid.eq S) x=y y=0))) (mulNonzeros) Group.+WellDefined (fieldMultiplicativeGroup) {x , prX} {y , prY} {z , prZ} {w , prW} = Ring.*WellDefined R Group.0G (fieldMultiplicativeGroup) = Ring.1R R , λ 1=0 → Field.nontrivial F (Equivalence.symmetric (Setoid.eq S) 1=0) Group.inverse (fieldMultiplicativeGroup) (x , pr) with Field.allInvertible F x pr ... | 1/x , pr1/x = 1/x , λ 1/x=0 → Field.nontrivial F (Equivalence.transitive (Setoid.eq S) (Equivalence.symmetric (Setoid.eq S) (Equivalence.transitive (Setoid.eq S) (Ring.*WellDefined R 1/x=0 (Equivalence.reflexive (Setoid.eq S))) (Ring.timesZero' R))) pr1/x) Group.+Associative (fieldMultiplicativeGroup) {x , prX} {y , prY} {z , prZ} = Ring.*Associative R Group.identRight (fieldMultiplicativeGroup) {x , prX} = Ring.identIsIdent' R Group.identLeft (fieldMultiplicativeGroup) {x , prX} = Ring.identIsIdent R Group.invLeft (fieldMultiplicativeGroup) {x , prX} with Field.allInvertible F x prX ... | 1/x , pr1/x = pr1/x Group.invRight (fieldMultiplicativeGroup) {x , prX} with Field.allInvertible F x prX ... | 1/x , pr1/x = Equivalence.transitive (Setoid.eq S) (Ring.*Commutative R) pr1/x
{ "alphanum_fraction": 0.6960855823, "avg_line_length": 67.4262295082, "ext": "agda", "hexsha": "f3ea3daeee51246a97ac06eac6c71d480f49d4e5", "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": "Fields/Lemmas.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": "Fields/Lemmas.agda", "max_line_length": 271, "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": "Fields/Lemmas.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": 1475, "size": 4113 }
{- Product of structures S and T: X ↦ S X × T X -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Structures.Product where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.Path open import Cubical.Foundations.SIP open import Cubical.Data.Sigma private variable ℓ ℓ₁ ℓ₁' ℓ₂ ℓ₂' : Level ProductStructure : (S₁ : Type ℓ → Type ℓ₁) (S₂ : Type ℓ → Type ℓ₂) → Type ℓ → Type (ℓ-max ℓ₁ ℓ₂) ProductStructure S₁ S₂ X = S₁ X × S₂ X ProductEquivStr : {S₁ : Type ℓ → Type ℓ₁} (ι₁ : StrEquiv S₁ ℓ₁') {S₂ : Type ℓ → Type ℓ₂} (ι₂ : StrEquiv S₂ ℓ₂') → StrEquiv (ProductStructure S₁ S₂) (ℓ-max ℓ₁' ℓ₂') ProductEquivStr ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) f = (ι₁ (X , s₁) (Y , t₁) f) × (ι₂ (X , s₂) (Y , t₂) f) ProductUnivalentStr : {S₁ : Type ℓ → Type ℓ₁} (ι₁ : StrEquiv S₁ ℓ₁') (θ₁ : UnivalentStr S₁ ι₁) {S₂ : Type ℓ → Type ℓ₂} (ι₂ : StrEquiv S₂ ℓ₂') (θ₂ : UnivalentStr S₂ ι₂) → UnivalentStr (ProductStructure S₁ S₂) (ProductEquivStr ι₁ ι₂) ProductUnivalentStr {S₁ = S₁} ι₁ θ₁ {S₂} ι₂ θ₂ {X , s₁ , s₂} {Y , t₁ , t₂} e = isoToEquiv (iso φ ψ η ε) where φ : ProductEquivStr ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) e → PathP (λ i → ProductStructure S₁ S₂ (ua e i)) (s₁ , s₂) (t₁ , t₂) φ (p , q) i = (θ₁ e .fst p i) , (θ₂ e .fst q i) ψ : PathP (λ i → ProductStructure S₁ S₂ (ua e i)) (s₁ , s₂) (t₁ , t₂) → ProductEquivStr ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) e ψ p = invEq (θ₁ e) (λ i → p i .fst) , invEq (θ₂ e) (λ i → p i .snd) η : section φ ψ η p i j = retEq (θ₁ e) (λ k → p k .fst) i j , retEq (θ₂ e) (λ k → p k .snd) i j ε : retract φ ψ ε (p , q) i = secEq (θ₁ e) p i , secEq (θ₂ e) q i
{ "alphanum_fraction": 0.5996827076, "avg_line_length": 36.3653846154, "ext": "agda", "hexsha": "5ff6623aacf1420089481a0aad67aa1711d920fe", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "RobertHarper/cubical", "max_forks_repo_path": "Cubical/Structures/Product.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "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": "RobertHarper/cubical", "max_issues_repo_path": "Cubical/Structures/Product.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "RobertHarper/cubical", "max_stars_repo_path": "Cubical/Structures/Product.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 818, "size": 1891 }
-- Andreas, 2017-01-12, issue #2386 -- Relaxing the constraints of BUILTIN EQUALITY open import Agda.Primitive postulate ℓ : Level A : Set ℓ a b : A P : A → Set -- Level-polymorphic equality, living in the first universe data _≡_ {a} {A : Set a} (x : A) : A → Set where instance refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} -- The type of primTrustMe has to match the flavor of EQUALITY primitive primTrustMe : ∀ {a}{A : Set a} {x y : A} → x ≡ y testTM : primTrustMe {x = a} {y = a} ≡ refl testTM = refl -- Testing rewrite subst : a ≡ b → P a → P b subst eq p rewrite eq = p
{ "alphanum_fraction": 0.6317567568, "avg_line_length": 19.7333333333, "ext": "agda", "hexsha": "e57b83032e0664044f08cb039fb1970715d92c3e", "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/Succeed/Issue2386BuiltinEqualityPolySet.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/Succeed/Issue2386BuiltinEqualityPolySet.agda", "max_line_length": 62, "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/Succeed/Issue2386BuiltinEqualityPolySet.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": 212, "size": 592 }
{-# OPTIONS --enable-prop #-} open import Agda.Builtin.Nat -- You can define datatypes in Prop, even with multiple constructors. -- However, all constructors are considered (definitionally) equal. data TestProp : Prop where p₁ p₂ : TestProp -- Pattern matching on a datatype in Prop is disallowed unless the -- target type is a Prop: test-case : {P : Prop} (x₁ x₂ : P) → TestProp → P test-case x₁ x₂ p₁ = x₁ test-case x₁ x₂ p₂ = x₂ -- All elements of a Prop are definitionally equal: data _≡Prop_ {A : Prop} (x : A) : A → Set where refl : x ≡Prop x p₁≡p₂ : p₁ ≡Prop p₂ p₁≡p₂ = refl -- A special case are empty types in Prop: these can be eliminated to -- any other type. data ⊥ : Prop where absurd : {A : Set} → ⊥ → A absurd () -- We can also define record types in Prop, such as the unit: record ⊤ : Prop where constructor tt -- We have Prop : Set₀, so we can store predicates in a small datatype: data NatProp : Set₁ where c : (Nat → Prop) → NatProp -- To define more interesting predicates, we need to define them by pattern matching: _≤_ : Nat → Nat → Prop zero ≤ y = ⊤ suc x ≤ suc y = x ≤ y _ ≤ _ = ⊥ -- We can also define the induction principle for predicates defined in this way, -- using the fact that we can eliminate absurd propositions with a () pattern. ≤-ind : (P : (m n : Nat) → Set) → (pzy : (y : Nat) → P zero y) → (pss : (x y : Nat) → P x y → P (suc x) (suc y)) → (m n : Nat) → m ≤ n → P m n ≤-ind P pzy pss zero y pf = pzy y ≤-ind P pzy pss (suc x) (suc y) pf = pss x y (≤-ind P pzy pss x y pf) ≤-ind P pzy pss (suc _) zero () -- We can define equality as a Prop, but (currently) we cannot define -- the corresponding eliminator, so the equality is only useful for -- refuting impossible equations. data _≡P_ {A : Set} (x : A) : A → Prop where refl : x ≡P x 0≢1 : 0 ≡P 1 → ⊥ 0≢1 ()
{ "alphanum_fraction": 0.6400862069, "avg_line_length": 29.935483871, "ext": "agda", "hexsha": "a1ef269f8f45ff1b14b12150b9f58b50950223a0", "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": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/eagda", "max_forks_repo_path": "test/Succeed/PropTests.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "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": "asr/eagda", "max_issues_repo_path": "test/Succeed/PropTests.agda", "max_line_length": 85, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/eagda", "max_stars_repo_path": "test/Succeed/PropTests.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 625, "size": 1856 }
module bool where ------------------------ -- Datatypes ------------------------ data 𝔹 : Set where true : 𝔹 false : 𝔹 ---------------------- -- AND ---------------------- infixr 6 _∧_ _∧_ : 𝔹 → 𝔹 → 𝔹 true ∧ b = b false ∧ b = false --------------------- -- OR --------------------- infixr 5 _∨_ _∨_ : 𝔹 → 𝔹 → 𝔹 true ∨ b = true false ∨ b = b -------------------- -- NEFATION -------------------- infixr 7 ¬_ ¬_ : 𝔹 → 𝔹 ¬ true = false ¬ false = true
{ "alphanum_fraction": 0.3275488069, "avg_line_length": 13.9696969697, "ext": "agda", "hexsha": "5ed0c3335476cde35966ce46f6535bc2419b636f", "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": "2c92eb9520dc83f0258e43b4227ce281dfadaffe", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mrLSD/agda-emacs", "max_forks_repo_path": "bool.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2c92eb9520dc83f0258e43b4227ce281dfadaffe", "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": "mrLSD/agda-emacs", "max_issues_repo_path": "bool.agda", "max_line_length": 24, "max_stars_count": null, "max_stars_repo_head_hexsha": "2c92eb9520dc83f0258e43b4227ce281dfadaffe", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mrLSD/agda-emacs", "max_stars_repo_path": "bool.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 168, "size": 461 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT module homotopy.EilenbergMacLane1 {i} (G : Group i) where private module G = Group G comp-equiv : ∀ g → G.El ≃ G.El comp-equiv g = equiv (λ x → G.comp x g) (λ x → G.comp x (G.inv g)) (λ x → G.assoc x (G.inv g) g ∙ ap (G.comp x) (G.inv-l g) ∙ G.unit-r x) (λ x → G.assoc x g (G.inv g) ∙ ap (G.comp x) (G.inv-r g) ∙ G.unit-r x) comp-equiv-id : comp-equiv G.ident == ide G.El comp-equiv-id = pair= (λ= G.unit-r) (prop-has-all-paths-↓ {B = is-equiv}) comp-equiv-comp : (g₁ g₂ : G.El) → comp-equiv (G.comp g₁ g₂) == (comp-equiv g₂ ∘e comp-equiv g₁) comp-equiv-comp g₁ g₂ = pair= (λ= (λ x → ! (G.assoc x g₁ g₂))) (prop-has-all-paths-↓ {B = is-equiv}) Ω-group : Group (lsucc i) Ω-group = Ω^S-group 0 ⊙[ (0 -Type i) , (G.El , G.El-level) ] Codes-hom : G →ᴳ Ω-group Codes-hom = group-hom (nType=-out ∘ ua ∘ comp-equiv) pres-comp where abstract pres-comp : ∀ g₁ g₂ → nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv (G.comp g₁ g₂))) == nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₁)) ∙ nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₂)) pres-comp g₁ g₂ = nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv (G.comp g₁ g₂))) =⟨ comp-equiv-comp g₁ g₂ |in-ctx nType=-out ∘ ua ⟩ nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₂ ∘e comp-equiv g₁)) =⟨ ua-∘e (comp-equiv g₁) (comp-equiv g₂) |in-ctx nType=-out ⟩ nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₁) ∙ ua (comp-equiv g₂)) =⟨ ! $ nType-∙ {A = G.El , G.El-level} {B = G.El , G.El-level} {C = G.El , G.El-level} (ua (comp-equiv g₁)) (ua (comp-equiv g₂)) ⟩ nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₁)) ∙ nType=-out {A = G.El , G.El-level} {B = G.El , G.El-level} (ua (comp-equiv g₂)) =∎ Codes : EM₁ G → 0 -Type i Codes = EM₁-rec {G = G} {C = 0 -Type i} (G.El , G.El-level) Codes-hom abstract ↓-Codes-loop : ∀ g g' → g' == G.comp g' g [ fst ∘ Codes ↓ emloop g ] ↓-Codes-loop g g' = ↓-ap-out fst Codes (emloop g) $ ↓-ap-out (idf _) fst (ap Codes (emloop g)) $ transport (λ w → g' == G.comp g' g [ idf _ ↓ ap fst w ]) (! (EM₁Rec.emloop-β (G.El , G.El-level) Codes-hom g)) $ transport (λ w → g' == G.comp g' g [ idf _ ↓ w ]) (! (fst=-β (ua $ comp-equiv g) _)) $ ↓-idf-ua-in (comp-equiv g) idp encode : {x : EM₁ G} → embase == x → fst (Codes x) encode α = transport (fst ∘ Codes) α G.ident encode-emloop : ∀ g → encode (emloop g) == g encode-emloop g = to-transp $ transport (λ x → G.ident == x [ fst ∘ Codes ↓ emloop g ]) (G.unit-l g) (↓-Codes-loop g G.ident) decode : {x : EM₁ G} → fst (Codes x) → embase == x decode {x} = EM₁-elim {P = λ x' → fst (Codes x') → embase == x'} emloop loop' (λ _ _ → prop-has-all-paths-↓ {{↓-level ⟨⟩}}) x where loop' : (g : G.El) → emloop == emloop [ (λ x' → fst (Codes x') → embase == x') ↓ emloop g ] loop' g = ↓-→-from-transp $ λ= $ λ y → transport (λ z → embase == z) (emloop g) (emloop y) =⟨ transp-cst=idf (emloop g) (emloop y) ⟩ emloop y ∙ emloop g =⟨ ! (emloop-comp y g) ⟩ emloop (G.comp y g) =⟨ ap emloop (! (to-transp (↓-Codes-loop g y))) ⟩ emloop (transport (λ z → fst (Codes z)) (emloop g) y) =∎ decode-encode : ∀ {x} (α : embase' G == x) → decode (encode α) == α decode-encode idp = emloop-ident {G = G} emloop-equiv : G.El ≃ (embase' G == embase) emloop-equiv = equiv emloop encode decode-encode encode-emloop Ω¹-EM₁ : Ω^S-group 0 (⊙EM₁ G) ≃ᴳ G Ω¹-EM₁ = ≃-to-≃ᴳ (emloop-equiv ⁻¹) (λ l₁ l₂ → <– (ap-equiv emloop-equiv _ _) $ emloop (encode (l₁ ∙ l₂)) =⟨ decode-encode (l₁ ∙ l₂) ⟩ l₁ ∙ l₂ =⟨ ! $ ap2 _∙_ (decode-encode l₁) (decode-encode l₂) ⟩ emloop (encode l₁) ∙ emloop (encode l₂) =⟨ ! $ emloop-comp (encode l₁) (encode l₂) ⟩ emloop (G.comp (encode l₁) (encode l₂)) =∎) π₁-EM₁ : πS 0 (⊙EM₁ G) ≃ᴳ G π₁-EM₁ = Ω¹-EM₁ ∘eᴳ unTrunc-iso (Ω^S-group-structure 0 (⊙EM₁ G))
{ "alphanum_fraction": 0.492211164, "avg_line_length": 40.5438596491, "ext": "agda", "hexsha": "d16d57eea1074f5d7c33e9193a7427a058f5e55c", "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": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/homotopy/EilenbergMacLane1.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/homotopy/EilenbergMacLane1.agda", "max_line_length": 110, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/homotopy/EilenbergMacLane1.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1748, "size": 4622 }
import Level as L open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Data.Product open import Data.Empty open import Data.Nat open import Data.Nat.Properties open import RevMachine module RevNoRepeat {ℓ} (M : RevMachine {ℓ}) where infix 99 _ᵣₑᵥ infixr 10 _∷_ infixr 10 _++↦_ open RevMachine.RevMachine M is-stuck : State → Set _ is-stuck st = ∄[ st' ] (st ↦ st') is-initial : State → Set _ is-initial st = ∄[ st' ] (st' ↦ st) data _↦ᵣₑᵥ_ : State → State → Set (L.suc ℓ) where _ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ st₂ → st₂ ↦ᵣₑᵥ st₁ data _↦*_ : State → State → Set (L.suc ℓ) where ◾ : {st : State} → st ↦* st _∷_ : {st₁ st₂ st₃ : State} → st₁ ↦ st₂ → st₂ ↦* st₃ → st₁ ↦* st₃ _++↦_ : {st₁ st₂ st₃ : State} → st₁ ↦* st₂ → st₂ ↦* st₃ → st₁ ↦* st₃ ◾ ++↦ st₁↦*st₂ = st₁↦*st₂ (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ st₂'↦*st₃) len↦ : ∀ {st st'} → st ↦* st' → ℕ len↦ ◾ = 0 len↦ (_ ∷ r) = 1 + len↦ r data _↦ᵣₑᵥ*_ : State → State → Set (L.suc ℓ) where ◾ : ∀ {st} → st ↦ᵣₑᵥ* st _∷_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃ _++↦ᵣₑᵥ_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃ ◾ ++↦ᵣₑᵥ st₁↦ᵣₑᵥ*st₂ = st₁↦ᵣₑᵥ*st₂ (st₁↦ᵣₑᵥst₁' ∷ st₁'↦ᵣₑᵥ*st₂) ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃ = st₁↦ᵣₑᵥst₁' ∷ (st₁'↦ᵣₑᵥ*st₂ ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃) Rev↦ : ∀ {st₁ st₂} → st₁ ↦* st₂ → st₂ ↦ᵣₑᵥ* st₁ Rev↦ ◾ = ◾ Rev↦ (r ∷ rs) = Rev↦ rs ++↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ ◾) Rev↦ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦* st₁ Rev↦ᵣₑᵥ ◾ = ◾ Rev↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ rs) = Rev↦ᵣₑᵥ rs ++↦ (r ∷ ◾) deterministic* : ∀ {st st₁ st₂} → st ↦* st₁ → st ↦* st₂ → is-stuck st₁ → is-stuck st₂ → st₁ ≡ st₂ deterministic* ◾ ◾ stuck₁ stuck₂ = refl deterministic* ◾ (r ∷ ↦*₂) stuck₁ stuck₂ = ⊥-elim (stuck₁ (_ , r)) deterministic* (r ∷ ↦*₁) ◾ stuck₁ stuck₂ = ⊥-elim (stuck₂ (_ , r)) deterministic* (r₁ ∷ ↦*₁) (r₂ ∷ ↦*₂) stuck₁ stuck₂ with deterministic r₁ r₂ ... | refl = deterministic* ↦*₁ ↦*₂ stuck₁ stuck₂ deterministic*' : ∀ {st st₁ st'} → (rs₁ : st ↦* st₁) → (rs : st ↦* st') → is-stuck st' → Σ[ rs' ∈ st₁ ↦* st' ] (len↦ rs ≡ len↦ rs₁ + len↦ rs') deterministic*' ◾ rs stuck = rs , refl deterministic*' (r ∷ rs₁) ◾ stuck = ⊥-elim (stuck (_ , r)) deterministic*' (r ∷ rs₁) (r' ∷ rs) stuck with deterministic r r' ... | refl with deterministic*' rs₁ rs stuck ... | (rs' , eq) = rs' , cong suc eq deterministicᵣₑᵥ* : ∀ {st st₁ st₂} → st ↦ᵣₑᵥ* st₁ → st ↦ᵣₑᵥ* st₂ → is-initial st₁ → is-initial st₂ → st₁ ≡ st₂ deterministicᵣₑᵥ* ◾ ◾ initial₁ initial₂ = refl deterministicᵣₑᵥ* ◾ (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ = ⊥-elim (initial₁ (_ , r)) deterministicᵣₑᵥ* (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) ◾ initial₁ initial₂ = ⊥-elim (initial₂ (_ , r)) deterministicᵣₑᵥ* (r₁ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) (r₂ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ with deterministicᵣₑᵥ r₁ r₂ ... | refl = deterministicᵣₑᵥ* ↦ᵣₑᵥ*₁ ↦ᵣₑᵥ*₂ initial₁ initial₂ data _↦[_]_ : State → ℕ → State → Set (L.suc ℓ) where ◾ : ∀ {st} → st ↦[ 0 ] st _∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ st₂ → st₂ ↦[ n ] st₃ → st₁ ↦[ suc n ] st₃ _++↦ⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦[ n ] st₂ → st₂ ↦[ m ] st₃ → st₁ ↦[ n + m ] st₃ ◾ ++↦ⁿ st₁↦*st₂ = st₁↦*st₂ (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ⁿ st₂'↦*st₃) data _↦ᵣₑᵥ[_]_ : State → ℕ → State → Set (L.suc ℓ) where ◾ : ∀ {st} → st ↦ᵣₑᵥ[ 0 ] st _∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ[ n ] st₃ → st₁ ↦ᵣₑᵥ[ suc n ] st₃ _++↦ᵣₑᵥⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦ᵣₑᵥ[ n ] st₂ → st₂ ↦ᵣₑᵥ[ m ] st₃ → st₁ ↦ᵣₑᵥ[ n + m ] st₃ ◾ ++↦ᵣₑᵥⁿ st₁↦*st₂ = st₁↦*st₂ (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ᵣₑᵥⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ᵣₑᵥⁿ st₂'↦*st₃) deterministicⁿ : ∀ {st st₁ st₂ n} → st ↦[ n ] st₁ → st ↦[ n ] st₂ → st₁ ≡ st₂ deterministicⁿ ◾ ◾ = refl deterministicⁿ (r₁ ∷ rs₁) (r₂ ∷ rs₂) with deterministic r₁ r₂ ... | refl = deterministicⁿ rs₁ rs₂ deterministicᵣₑᵥⁿ : ∀ {st st₁ st₂ n} → st ↦ᵣₑᵥ[ n ] st₁ → st ↦ᵣₑᵥ[ n ] st₂ → st₁ ≡ st₂ deterministicᵣₑᵥⁿ ◾ ◾ = refl deterministicᵣₑᵥⁿ (r₁ ᵣₑᵥ ∷ rs₁) (r₂ ᵣₑᵥ ∷ rs₂) with deterministicᵣₑᵥ r₁ r₂ ... | refl = deterministicᵣₑᵥⁿ rs₁ rs₂ private split↦ⁿ : ∀ {st st'' n m} → st ↦ᵣₑᵥ[ n + m ] st'' → ∃[ st' ] (st ↦ᵣₑᵥ[ n ] st' × st' ↦ᵣₑᵥ[ m ] st'') split↦ⁿ {n = 0} {m} rs = _ , ◾ , rs split↦ⁿ {n = suc n} {m} (r ∷ rs) with split↦ⁿ {n = n} {m} rs ... | st' , st↦ⁿst' , st'↦ᵐst'' = st' , (r ∷ st↦ⁿst') , st'↦ᵐst'' diff : ∀ {n m} → n < m → ∃[ k ] (0 < k × n + k ≡ m) diff {0} {(suc m)} (s≤s z≤n) = suc m , s≤s z≤n , refl diff {(suc n)} {(suc (suc m))} (s≤s (s≤s n≤m)) with diff {n} {suc m} (s≤s n≤m) ... | k , 0<k , eq = k , 0<k , cong suc eq Revⁿ : ∀ {st st' n} → st ↦[ n ] st' → st' ↦ᵣₑᵥ[ n ] st Revⁿ {n = 0} ◾ = ◾ Revⁿ {n = suc n} (r ∷ rs) rewrite +-comm 1 n = Revⁿ rs ++↦ᵣₑᵥⁿ (r ᵣₑᵥ ∷ ◾) NoRepeat : ∀ {st₀ stₙ stₘ n m} → is-initial st₀ → n < m → st₀ ↦[ n ] stₙ → st₀ ↦[ m ] stₘ → stₙ ≢ stₘ NoRepeat {stₙ = st} {_} {m} st₀-is-init n<m st₀↦ᵐst st₀↦ᵐ⁺ᵏ⁺¹st refl with diff n<m ... | suc k , 0<k , refl with (Revⁿ st₀↦ᵐst , Revⁿ st₀↦ᵐ⁺ᵏ⁺¹st) ... | st'↦ᵐst₀' , st'↦ᵐ⁺ᵏ⁺¹st₀' with split↦ⁿ {n = m} {suc k} st'↦ᵐ⁺ᵏ⁺¹st₀' ... | st′ , st'↦ᵐst′ , st′↦ᵏ⁺¹st₀' with deterministicᵣₑᵥⁿ st'↦ᵐst₀' st'↦ᵐst′ ... | refl with st′↦ᵏ⁺¹st₀' ... | r ᵣₑᵥ ∷ rs = ⊥-elim (st₀-is-init (_ , r))
{ "alphanum_fraction": 0.5174850516, "avg_line_length": 40.2846715328, "ext": "agda", "hexsha": "433b401bf47f86ccaba69c64dd0df87b177299bf", "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": "RevNoRepeat.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": "RevNoRepeat.agda", "max_line_length": 101, "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": "RevNoRepeat.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": 3339, "size": 5519 }
------------------------------------------------------------------------------ -- Distributive laws on a binary operation: Lemma 6 ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module DistributiveLaws.Lemma6-ATP where open import DistributiveLaws.Base ------------------------------------------------------------------------------ postulate lemma₆ : ∀ u x y z → (((x · y) · (z · u)) · ((x · y) · (z · u))) ≡ (x · y) · (z · u) {-# ATP prove lemma₆ #-}
{ "alphanum_fraction": 0.3427299703, "avg_line_length": 33.7, "ext": "agda", "hexsha": "240d04d1aad6efd93942096b75df24bdb250a81f", "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": "src/fot/DistributiveLaws/Lemma6-ATP.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": "src/fot/DistributiveLaws/Lemma6-ATP.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": "src/fot/DistributiveLaws/Lemma6-ATP.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": 131, "size": 674 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Properties.Setoids.LCCC where open import Level open import Data.Product using (Σ; _,_) open import Function.Equality as Func using (Π; _⟶_) open import Relation.Binary using (Setoid) import Relation.Binary.PropositionalEquality as ≡ open import Categories.Category open import Categories.Category.Slice open import Categories.Category.Slice.Properties open import Categories.Category.CartesianClosed open import Categories.Category.CartesianClosed.Canonical using (module Equivalence) renaming (CartesianClosed to Canonical) open import Categories.Category.CartesianClosed.Locally using (Locally) open import Categories.Category.Cartesian open import Categories.Category.Instance.Span open import Categories.Category.Instance.Setoids open import Categories.Category.Instance.Properties.Setoids.Complete open import Categories.Category.Monoidal.Instance.Setoids open import Categories.Functor open import Categories.Object.Terminal open import Categories.Diagram.Pullback open import Categories.Diagram.Pullback.Limit import Categories.Object.Product as Prod open Π using (_⟨$⟩_) module _ {o ℓ} where module _ {A X : Setoid o ℓ} where private module A = Setoid A module X = Setoid X record InverseImage (a : Setoid.Carrier A) (f : X ⟶ A) : Set (o ⊔ ℓ) where constructor pack field x : X.Carrier fx≈a : f ⟨$⟩ x A.≈ a inverseImage-transport : ∀ {a a′} {f : X ⟶ A} → a A.≈ a′ → InverseImage a f → InverseImage a′ f inverseImage-transport eq img = pack x (A.trans fx≈a eq) where open InverseImage img module _ {A X Y : Setoid o ℓ} where private module A = Setoid A module X = Setoid X module Y = Setoid Y -- the inverse image part of an exponential object the slice category of Setoids -- it's a morphism from f to g, which in set theory is -- f⁻¹(a) ⟶ g⁻¹(a) -- here, we need to take care of some coherence condition. record InverseImageMap (a : Setoid.Carrier A) (f : X ⟶ A) (g : Y ⟶ A) : Set (o ⊔ ℓ) where field f⇒g : InverseImage a f → InverseImage a g cong : ∀ (x x′ : InverseImage a f) → InverseImage.x x X.≈ InverseImage.x x′ → InverseImage.x (f⇒g x) Y.≈ InverseImage.x (f⇒g x′) inverseImageMap-transport : ∀ {a a′} {f : X ⟶ A} {g : Y ⟶ A} → a A.≈ a′ → InverseImageMap a f g → InverseImageMap a′ f g inverseImageMap-transport eq h = record { f⇒g = λ img → inverseImage-transport eq (f⇒g (inverseImage-transport (A.sym eq) img)) ; cong = λ x x′ eq′ → cong (inverseImage-transport (A.sym eq) x) (inverseImage-transport (A.sym eq) x′) eq′ } where open InverseImageMap h record SlExp (f : X ⟶ A) (g : Y ⟶ A) : Set (o ⊔ ℓ) where field idx : A.Carrier map : InverseImageMap idx f g open InverseImageMap map public record SlExp≈ {f : X ⟶ A} {g : Y ⟶ A} (h i : SlExp f g) : Set (o ⊔ ℓ) where private module h = SlExp h module i = SlExp i field idx≈ : h.idx A.≈ i.idx map≈ : ∀ (img : InverseImage h.idx f) → InverseImage.x (h.f⇒g img) Y.≈ InverseImage.x (i.f⇒g (inverseImage-transport idx≈ img)) -- map≈′ : ∀ (img : InverseImage i.idx f) → InverseImage.x (i.f⇒g img) Y.≈ InverseImage.x (h.f⇒g (inverseImage-transport idx≈ img)) SlExp-Setoid : ∀ {A X Y : Setoid o ℓ} (f : X ⟶ A) (g : Y ⟶ A) → Setoid (o ⊔ ℓ) (o ⊔ ℓ) SlExp-Setoid {A} {X} {Y} f g = record { Carrier = SlExp f g ; _≈_ = SlExp≈ ; isEquivalence = record { refl = λ {h} → record { idx≈ = A.refl ; map≈ = λ img → SlExp.cong h img (inverseImage-transport A.refl img) X.refl } ; sym = λ {h i} eq → let open SlExp≈ eq in record { idx≈ = A.sym idx≈ ; map≈ = λ img → Y.trans (SlExp.cong i img (inverseImage-transport idx≈ (inverseImage-transport (A.sym idx≈) img)) X.refl) (Y.sym (map≈ (inverseImage-transport (A.sym idx≈) img))) } ; trans = λ {h i j} eq eq′ → let module eq = SlExp≈ eq module eq′ = SlExp≈ eq′ in record { idx≈ = A.trans eq.idx≈ eq′.idx≈ ; map≈ = λ img → Y.trans (eq.map≈ img) (Y.trans (eq′.map≈ (inverseImage-transport eq.idx≈ img)) (SlExp.cong j (inverseImage-transport eq′.idx≈ (inverseImage-transport eq.idx≈ img)) (inverseImage-transport (A.trans eq.idx≈ eq′.idx≈) img) X.refl)) } } } where module A = Setoid A module X = Setoid X module Y = Setoid Y module _ {o} where private S : Category (suc o) o o S = Setoids o o module S = Category S module _ (A : S.Obj) where private Sl = Slice S A module Sl = Category Sl open Setoid A open Prod (Slice S A) slice-terminal : Terminal Sl slice-terminal = record { ⊤ = sliceobj {Y = A} record { _⟨$⟩_ = λ x → x ; cong = λ eq → eq } ; ⊤-is-terminal = record { ! = λ { {sliceobj f} → slicearr {h = f} (Π.cong f) } ; !-unique = λ { {X} (slicearr △) eq → let module X = SliceObj X in sym (△ (Setoid.sym X.Y eq)) } } } F₀ : Sl.Obj → Sl.Obj → SpanObj → Setoid o o F₀ X Y center = A F₀ X Y left = SliceObj.Y X F₀ X Y right = SliceObj.Y Y slice-product : (X Y : Sl.Obj) → Product X Y slice-product X Y = pullback⇒product S XY-pullback where module X = SliceObj X module Y = SliceObj Y F : Functor (Category.op Span) (Setoids o o) F = record { F₀ = F₀ X Y ; F₁ = λ { span-id → Func.id ; span-arrˡ → X.arr ; span-arrʳ → Y.arr } ; identity = λ {Z} → S.Equiv.refl {F₀ X Y Z} {F₀ X Y Z} {Func.id} ; homomorphism = λ { {_} {_} {_} {span-id} {span-id} eq → eq ; {_} {_} {_} {span-id} {span-arrˡ} → Π.cong X.arr ; {_} {_} {_} {span-id} {span-arrʳ} → Π.cong Y.arr ; {_} {_} {_} {span-arrˡ} {span-id} → Π.cong X.arr ; {_} {_} {_} {span-arrʳ} {span-id} → Π.cong Y.arr } ; F-resp-≈ = λ { {_} {_} {span-id} ≡.refl eq → eq ; {_} {_} {span-arrˡ} ≡.refl → Π.cong X.arr ; {_} {_} {span-arrʳ} ≡.refl → Π.cong Y.arr } } XY-pullback : Pullback S X.arr Y.arr XY-pullback = limit⇒pullback S {F = F} (Setoids-Complete 0ℓ 0ℓ 0ℓ o o F) module slice-terminal = Terminal slice-terminal module slice-product X Y = Product (slice-product X Y) cartesian : Cartesian Sl cartesian = record { terminal = slice-terminal ; products = record { product = slice-product _ _ } } module cartesian = Cartesian cartesian _^_ : Sl.Obj → Sl.Obj → Sl.Obj f ^ g = sliceobj {Y = SlExp-Setoid g.arr f.arr} record { _⟨$⟩_ = SlExp.idx ; cong = SlExp≈.idx≈ } where module f = SliceObj f module g = SliceObj g prod = slice-product.A×B eval : {f g : Sl.Obj} → prod (f ^ g) g Sl.⇒ f eval {f} {g} = slicearr {h = h} λ { {J₁ , arr₁} {J₂ , arr₂} eq → let open SlExp (J₁ left) in trans (InverseImage.fx≈a (f⇒g (pack (J₁ right) _))) (trans (arr₁ span-arrˡ) (trans (eq center) (sym (arr₂ span-arrʳ)))) } where module f = SliceObj f module g = SliceObj g module fY = Setoid f.Y h : SliceObj.Y (prod (f ^ g) g) S.⇒ f.Y h = record { _⟨$⟩_ = λ { (J , arr) → let module exp = SlExp (J left) in InverseImage.x (exp.f⇒g (pack (J right) (trans (arr span-arrʳ) (sym (arr span-arrˡ))))) } ; cong = λ { {J₁ , arr₁} {J₂ , arr₂} eq → let open SlExp≈ (eq left) open SlExp (J₂ left) in fY.trans (map≈ _) (cong _ _ (eq right)) } } module _ {f g : Sl.Obj} where private module f = SliceObj f module g = SliceObj g module fY = Setoid f.Y module gY = Setoid g.Y Jpb : ∀ x → InverseImage (f.arr ⟨$⟩ x) g.arr → ∀ j → Setoid.Carrier (F₀ f g j) Jpb x img center = f.arr ⟨$⟩ x Jpb x img left = x Jpb x img right = InverseImage.x img xypb : ∀ x → InverseImage (f.arr ⟨$⟩ x) g.arr → Setoid.Carrier (SliceObj.Y (prod f g)) xypb x img = Jpb x img , λ { {center} span-id → refl ; {left} span-id → fY.refl ; {right} span-id → gY.refl ; span-arrˡ → refl ; span-arrʳ → fx≈a } where open InverseImage img renaming (x to y) module _ {h : Sl.Obj} (α : prod f g Sl.⇒ h) where private module α = Slice⇒ α module h = SliceObj h module hY = Setoid h.Y βmap : fY.Carrier → SlExp g.arr h.arr βmap x = record { idx = f.arr ⟨$⟩ x ; map = record { f⇒g = λ img → let open InverseImage img renaming (x to y) in pack (α.h ⟨$⟩ xypb x img) (trans (α.△ {xypb x img} {xypb x img} (Setoid.refl (SliceObj.Y (prod f g)) {xypb x img})) fx≈a) ; cong = λ img img′ eq → let module img = InverseImage img module img′ = InverseImage img′ in Π.cong α.h λ { center → refl ; left → fY.refl ; right → eq } } } βcong : {i j : fY.Carrier} → i fY.≈ j → SlExp≈ (βmap i) (βmap j) βcong {i} {j} eq = record { idx≈ = Π.cong f.arr eq ; map≈ = λ img → let open InverseImage img in Π.cong α.h λ { center → Π.cong f.arr eq ; left → eq ; right → gY.refl } } β : f.Y S.⇒ SliceObj.Y (h ^ g) β = record { _⟨$⟩_ = βmap ; cong = βcong } curry : f Sl.⇒ (h ^ g) curry = slicearr {h = β} (Π.cong f.arr) module _ {f g h : Sl.Obj} {α β : prod f g Sl.⇒ h} where private module f = SliceObj f module g = SliceObj g module gY = Setoid g.Y curry-resp-≈ : α Sl.≈ β → curry α Sl.≈ curry β curry-resp-≈ eq eq′ = record { idx≈ = Π.cong f.arr eq′ ; map≈ = λ img → let open InverseImage img in eq λ { center → Π.cong f.arr eq′ ; left → eq′ ; right → gY.refl } } module _ {f g h : Sl.Obj} {α : f Sl.⇒ (g ^ h)} {β : prod f h Sl.⇒ g} where private module f = SliceObj f module g = SliceObj g module h = SliceObj h module α = Slice⇒ α module β = Slice⇒ β module fY = Setoid f.Y module gY = Setoid g.Y module hY = Setoid h.Y curry-unique : eval Sl.∘ (α cartesian.⁂ Sl.id) Sl.≈ β → α Sl.≈ curry β curry-unique eq {z} {w} eq′ = record { idx≈ = α.△ eq′ ; map≈ = λ img → let open InverseImage img in gY.trans (InverseImageMap.cong (SlExp.map (α.h ⟨$⟩ z)) img _ hY.refl) (eq {xypb z (inverseImage-transport (trans (α.△ eq′) (Π.cong f.arr (fY.sym eq′))) img)} {xypb w (inverseImage-transport (α.△ eq′) img)} λ { center → Π.cong f.arr eq′ ; left → eq′ ; right → hY.refl }) } slice-canonical : Canonical Sl slice-canonical = record { ⊤ = slice-terminal.⊤ ; _×_ = slice-product.A×B ; ! = slice-terminal.! ; π₁ = slice-product.π₁ _ _ ; π₂ = slice-product.π₂ _ _ ; ⟨_,_⟩ = slice-product.⟨_,_⟩ _ _ ; !-unique = slice-terminal.!-unique ; π₁-comp = λ {_ _ f _ g} → slice-product.project₁ _ _ {_} {f} {g} ; π₂-comp = λ {_ _ f _ g} → slice-product.project₂ _ _ {_} {f} {g} ; ⟨,⟩-unique = λ {_ _ _ f g h} → slice-product.unique _ _ {_} {h} {f} {g} ; _^_ = _^_ ; eval = eval ; curry = curry ; eval-comp = λ { {_} {_} {_} {α} {J , arr₁} eq → let module α = Slice⇒ α in Π.cong α.h λ { center → trans (arr₁ span-arrˡ) (eq center) ; left → eq left ; right → eq right } } ; curry-resp-≈ = λ {_ _ _} {α β} → curry-resp-≈ {_} {_} {_} {α} {β} ; curry-unique = λ {_ _ _} {α β} → curry-unique {_} {_} {_} {α} {β} } Setoids-sliceCCC : CartesianClosed (Slice S A) Setoids-sliceCCC = Equivalence.fromCanonical (Slice S A) slice-canonical Setoids-LCCC : Locally S Setoids-LCCC = record { sliceCCC = Setoids-sliceCCC }
{ "alphanum_fraction": 0.4709895211, "avg_line_length": 37.9173333333, "ext": "agda", "hexsha": "0758a223e0a246e3db07293222b787e6d74c0a6e", "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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Category/Instance/Properties/Setoids/LCCC.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "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": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Category/Instance/Properties/Setoids/LCCC.agda", "max_line_length": 139, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Category/Instance/Properties/Setoids/LCCC.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": 4337, "size": 14219 }
{- 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.Abstract.Types.EpochConfig open WithAbsVote -- This module defines and abstract view if a system, encompassing only a predicate for Records, -- another for Votes and a proof that, if a Vote is included in a QC in the system, then and -- equivalent Vote is also in the system. It further defines a notion "Complete", which states that -- if an honest vote is included in a QC in the system, then there is a RecordChain up to the block -- that the QC extends, such that all Records in the RecordChain are also in the system. The latter -- property is used to extend correctness conditions on RecordChains to correctness conditions that -- require only a short suffix of a RecordChain. module LibraBFT.Abstract.System (UID : Set) (_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁)) (NodeId : Set) (𝓔 : EpochConfig UID NodeId) (𝓥 : VoteEvidence UID NodeId 𝓔) where open import LibraBFT.Abstract.Types UID NodeId 𝓔 open import LibraBFT.Abstract.Records UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.Records.Extends UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.RecordChain UID _≟UID_ NodeId 𝓔 𝓥 module All-InSys-props {ℓ}(InSys : Record → Set ℓ) where All-InSys : ∀ {o r} → RecordChainFrom o r → Set ℓ All-InSys rc = {r' : Record} → r' ∈RC-simple rc → InSys r' All-InSys⇒last-InSys : ∀ {r} → {rc : RecordChain r} → All-InSys rc → InSys r All-InSys⇒last-InSys {rc = empty} a∈s = a∈s here All-InSys⇒last-InSys {r = r'} {step {r' = .r'} rc ext} a∈s = a∈s here All-InSys-unstep : ∀ {o r r' rc ext } → All-InSys (step {o} {r} {r'} rc ext) → All-InSys rc All-InSys-unstep {ext = ext} a∈s r'∈RC = a∈s (there ext r'∈RC) All-InSys-step : ∀ {r r' }{rc : RecordChain r} → All-InSys rc → (ext : r ← r') → InSys r' → All-InSys (step rc ext) All-InSys-step hyp ext r here = r All-InSys-step hyp ext r (there .ext r∈rc) = hyp r∈rc -- We say an InSys predicate is /Complete/ when we can construct a record chain -- from any vote by an honest participant. This essentially says that whenever -- an honest participant casts a vote, they have checked that the voted-for -- block is in a RecordChain whose records are all in the system. This notion -- is used to extend correctness conditions on RecordChains to correctness conditions that -- require only a short suffix of a RecordChain. Complete : ∀{ℓ} → (Record → Set ℓ) → Set ℓ Complete ∈sys = ∀{α q} → Meta-Honest-Member α → α ∈QC q → ∈sys (Q q) → ∃[ b ] ( Σ (RecordChain (B b)) All-InSys × B b ← Q q) where open All-InSys-props ∈sys
{ "alphanum_fraction": 0.6559814937, "avg_line_length": 48.0317460317, "ext": "agda", "hexsha": "e11c60df83834ace8a65593e9ab66f2a998dca93", "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/System.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/System.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/System.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 927, "size": 3026 }
-- {-# OPTIONS --verbose tc.constr.findInScope:15 #-} module 01-arguments where data T : Set where tt : T data A : Set where mkA : A mkA2 : T → A giveA : ⦃ a : A ⦄ → A giveA {{a}} = a test : A → T test a = tt test2 : T test2 = test giveA id : {A : Set} → A → A id v = v test5 : T → T test5 = id ⋯ : {A : Set} → {{a : A}} → A ⋯ {{a}} = a --giveA' : {{a : A}} → A --giveA' = ⋯
{ "alphanum_fraction": 0.4897959184, "avg_line_length": 11.8787878788, "ext": "agda", "hexsha": "e074e4468e810ce74f5df9cc26b08347bcb61693", "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": "examples/instance-arguments/01-arguments.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/instance-arguments/01-arguments.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/instance-arguments/01-arguments.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": 178, "size": 392 }
{-# OPTIONS --safe --without-K #-} module Generics.Desc where open import Data.String using (String) open import Generics.Prelude hiding (lookup) open import Generics.Telescope private variable P : Telescope ⊤ V I : ExTele P p : ⟦ P ⟧tel tt ℓ : Level n : ℕ data ConDesc (P : Telescope ⊤) (V I : ExTele P) : Setω where var : (((p , v) : ⟦ P , V ⟧xtel) → ⟦ I ⟧tel p) → ConDesc P V I π : (ai : String × ArgInfo) (S : ⟦ P , V ⟧xtel → Set ℓ) (C : ConDesc P (V ⊢< ai > S) I) → ConDesc P V I _⊗_ : (A B : ConDesc P V I) → ConDesc P V I data DataDesc P (I : ExTele P) : ℕ → Setω where [] : DataDesc P I 0 _∷_ : ∀ {n} (C : ConDesc P ε I) (D : DataDesc P I n) → DataDesc P I (suc n) lookupCon : DataDesc P I n → Fin n → ConDesc P ε I lookupCon (C ∷ D) (zero ) = C lookupCon (C ∷ D) (suc k) = lookupCon D k levelIndArg : ConDesc P V I → Level → Level levelIndArg (var _) c = c levelIndArg (π {ℓ} _ _ C) c = ℓ ⊔ levelIndArg C c levelIndArg (A ⊗ B) c = levelIndArg A c ⊔ levelIndArg B c ⟦_⟧IndArg : (C : ConDesc P V I) → (⟦ P , I ⟧xtel → Set ℓ) → (⟦ P , V ⟧xtel → Set (levelIndArg C ℓ)) ⟦ var f ⟧IndArg X (p , v) = X (p , f (p , v)) ⟦ π ai S C ⟧IndArg X (p , v) = Π< ai > (S (p , v)) (λ s → ⟦ C ⟧IndArg X (p , v , s)) ⟦ A ⊗ B ⟧IndArg X pv = ⟦ A ⟧IndArg X pv × ⟦ B ⟧IndArg X pv levelCon : ConDesc P V I → Level → Level levelCon {I = I} (var _) c = levelOfTel I levelCon (π {ℓ} _ _ C) c = ℓ ⊔ levelCon C c levelCon (A ⊗ B) c = levelIndArg A c ⊔ levelCon B c ⟦_⟧Con : (C : ConDesc P V I) → (⟦ P , I ⟧xtel → Set ℓ) → (⟦ P , V & I ⟧xtel → Set (levelCon C ℓ)) ⟦ var f ⟧Con X (p , v , i) = i ≡ f (p , v) ⟦ π (n , ai) S C ⟧Con X (p , v , i) = Σ[ s ∈ < relevance ai > S (p , v) ] ⟦ C ⟧Con X (p , ((v , s) , i)) ⟦ A ⊗ B ⟧Con X pvi@(p , v , i) = ⟦ A ⟧IndArg X (p , v) × ⟦ B ⟧Con X pvi record Σℓω {a} (A : Set a) {ℓB : A → Level} (B : ∀ x → Set (ℓB x)) : Setω where constructor _,_ field proj₁ : A proj₂ : B proj₁ ⟦_⟧Data : DataDesc P I n → (⟦ P , I ⟧xtel → Set ℓ) → ⟦ P , I ⟧xtel → Setω ⟦_⟧Data {n = n} D X (p , i) = Σℓω (Fin n) (λ k → ⟦ lookupCon D k ⟧Con X (p , tt , i))
{ "alphanum_fraction": 0.5122838944, "avg_line_length": 31.4, "ext": "agda", "hexsha": "f82251521bb334c867c7d9e160c63d67d0a2a9a9", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "src/Generics/Desc.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "src/Generics/Desc.agda", "max_line_length": 104, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "src/Generics/Desc.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 992, "size": 2198 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Floats: basic types and operations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Float.Base where open import Relation.Binary.Core using (Rel) import Data.Word.Base as Word open import Function using (_on_) open import Agda.Builtin.Equality ------------------------------------------------------------------------ -- Re-export built-ins publically open import Agda.Builtin.Float public using (Float) renaming -- Relations ( primFloatEquality to _≡ᵇ_ ; primFloatLess to _≤ᵇ_ ; primFloatNumericalEquality to _≈ᵇ_ ; primFloatNumericalLess to _≲ᵇ_ -- Conversions ; primShowFloat to show ; primFloatToWord64 to toWord ; primNatToFloat to fromℕ -- Operations ; primFloatPlus to _+_ ; primFloatMinus to _-_ ; primFloatTimes to _*_ ; primFloatNegate to -_ ; primFloatDiv to _÷_ ; primFloatSqrt to sqrt ; primRound to round ; primFloor to ⌊_⌋ ; primCeiling to ⌈_⌉ ; primExp to e^_ ; primLog to log ; primSin to sin ; primCos to cos ; primTan to tan ; primASin to asin ; primACos to acos ; primATan to atan ) _≈_ : Rel Float _ _≈_ = Word._≈_ on toWord _<_ : Rel Float _ _<_ = Word._<_ on toWord
{ "alphanum_fraction": 0.5381968341, "avg_line_length": 25.9464285714, "ext": "agda", "hexsha": "e5dd7c5e037f0b74bb270eab794c9cf10ec9d1a0", "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/Float/Base.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/Float/Base.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/Data/Float/Base.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": 404, "size": 1453 }
-- Andreas, 2016-02-04 -- Printing of overapplied operator patterns -- Expected results see comments. _fun : (A : Set) → Set _fun = {!!} -- C-c C-c RET gives -- -- A fun = ? _nofun : (A : Set₁) (B : Set₁) → Set₁ _nofun = {!!} -- C-c C-c RET gives -- -- (A nofun) B = ? module Works where record Safe : Set₁ where field <_>safe : Set open Safe mixfix : Safe mixfix = {!!} -- C-c C-c RET gives -- -- < mixfix >safe record Safe : Set₁ where field <_>safe : Set → Set open Safe mixfix : Safe mixfix = {! !} -- C-c C-c RET gives -- -- < mixfix >safe x _+_ : (A B C : Set) → Set _+_ = {!!} -- C-c C-c RET gives -- -- (A + B) C = ? -_ : (A B : Set) → Set -_ = {!!} -- C-c C-c RET gives -- -- (- A) B = ? data D : Set where _*_ : (x y z : D) → D splitP : D → D splitP d = {! d!} -- C-c C-c [d RET] gives -- -- splitP ((d * d₁) d₂) = ?
{ "alphanum_fraction": 0.5063001145, "avg_line_length": 14.3114754098, "ext": "agda", "hexsha": "d4d9c302f5b9e85c8ac7289f568337369140152c", "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/interaction/Issue1792.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/interaction/Issue1792.agda", "max_line_length": 44, "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/interaction/Issue1792.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 336, "size": 873 }
module bohm-out where open import lib open import general-util open import cedille-types open import syntax-util {- Implementation of the Böhm-Out Algorithm -} private nfoldr : ℕ → ∀ {ℓ} {X : Set ℓ} → X → (ℕ → X → X) → X nfoldr zero z s = z nfoldr (suc n) z s = s n (nfoldr n z s) nfoldl : ℕ → ∀ {ℓ} {X : Set ℓ} → X → (ℕ → X → X) → X nfoldl zero z s = z nfoldl (suc n) z s = nfoldl n (s n z) s set-nth : ∀ {ℓ} {X : Set ℓ} → ℕ → X → 𝕃 X → 𝕃 X set-nth n x [] = [] set-nth zero x (x' :: xs) = x :: xs set-nth (suc n) x (x' :: xs) = x' :: set-nth n x xs -- Böhm Tree data BT : Set where Node : (n i : ℕ) → 𝕃 BT → BT -- n: number of lambdas currently bound -- i: head variable -- 𝕃 BT: list of arguments -- Path to difference data path : Set where hd : path -- Difference in heads as : path -- Difference in number of arguments ps : (n : ℕ) → path → path -- Difference in nth subtrees (recursive) -- η functions η-expand'' : ℕ → 𝕃 BT → 𝕃 BT η-expand'' g [] = [] η-expand'' g (Node n i b :: bs) = Node (suc n) (if i ≥ g then suc i else i) (η-expand'' g b) :: η-expand'' g bs η-expand' : ℕ → BT → BT η-expand' g (Node n i b) = Node (suc n) (if i ≥ g then suc i else i) (η-expand'' g b) η-expand : BT → BT η-expand t @ (Node n _ _) with η-expand' (suc n) t ...| Node n' i' b' = Node n' i' (b' ++ [ Node n' n' [] ]) bt-n : BT → ℕ bt-n (Node n i b) = n η-equate : BT → BT → BT × BT η-equate t₁ t₂ = nfoldr (bt-n t₂ ∸ bt-n t₁) t₁ (λ _ → η-expand) , nfoldr (bt-n t₁ ∸ bt-n t₂) t₂ (λ _ → η-expand) -- η-equates all nodes along path to difference η-equate-path : BT → BT → path → BT × BT η-equate-path (Node n₁ i₁ b₁) (Node n₂ i₂ b₂) (ps d p) = let b-b = h d b₁ b₂ in η-equate (Node n₁ i₁ (fst b-b)) (Node n₂ i₂ (snd b-b)) where h : ℕ → 𝕃 BT → 𝕃 BT → 𝕃 BT × 𝕃 BT h zero (b₁ :: bs₁) (b₂ :: bs₂) with η-equate-path b₁ b₂ p ...| b₁' , b₂' = b₁' :: bs₁ , b₂' :: bs₂ h (suc d) (b₁ :: bs₁) (b₂ :: bs₂) with h d bs₁ bs₂ ...| bs₁' , bs₂' = b₁ :: bs₁' , b₂ :: bs₂' h d b₁ b₂ = b₁ , b₂ η-equate-path t₁ t₂ p = η-equate t₁ t₂ -- Rotation functions rotate : (k : ℕ) → BT rotate k = Node (suc k) (suc k) (nfoldl k [] (λ k' → Node (suc k) (suc k') [] ::_)) rotate-BT' : ℕ → 𝕃 BT → 𝕃 BT rotate-BT' k [] = [] rotate-BT' k (Node n i b :: bs) with i =ℕ k ...| ff = Node n i (rotate-BT' k b) :: rotate-BT' k bs ...| tt = Node (suc n) (suc n) (η-expand'' (suc n) (rotate-BT' k b)) :: rotate-BT' k bs rotate-BT : ℕ → BT → BT rotate-BT k (Node n i b) with i =ℕ k ...| ff = Node n i (rotate-BT' k b) ...| tt = Node (suc n) (suc n) (η-expand'' (suc n) (rotate-BT' k b)) -- Returns the greatest number of arguments k ever has at each node it where it is the head greatest-apps' : ℕ → 𝕃 BT → ℕ greatest-apps' k [] = zero greatest-apps' k (Node n k' bs' :: bs) with k =ℕ k' ...| ff = max (greatest-apps' k bs') (greatest-apps' k bs) ...| tt = max (length bs') (max (greatest-apps' k bs') (greatest-apps' k bs)) greatest-apps : ℕ → BT → ℕ greatest-apps k (Node n i b) with k =ℕ i ...| ff = greatest-apps' k b ...| tt = max (length b) (greatest-apps' k b) greatest-η' : ℕ → ℕ → 𝕃 BT → 𝕃 BT greatest-η' k m [] = [] greatest-η' k m (Node n i bs :: bs') with k =ℕ i ...| ff = Node n i (greatest-η' k m bs) :: greatest-η' k m bs' ...| tt = nfoldr (m ∸ length bs) (Node n i (greatest-η' k m bs)) (λ _ → η-expand) :: greatest-η' k m bs' greatest-η : ℕ → ℕ → BT → BT greatest-η k m (Node n i b) with k =ℕ i ...| ff = Node n i (greatest-η' k m b) ...| tt = nfoldr (m ∸ length b) (Node n i (greatest-η' k m b)) (λ _ → η-expand) -- Returns tt if k ever is at the head of a node along the path to the difference occurs-in-path : ℕ → BT → path → 𝔹 occurs-in-path k (Node n i b) (ps d p) = k =ℕ i || maybe-else ff (λ t → occurs-in-path k t p) (nth d b) occurs-in-path k (Node n i b) p = k =ℕ i adjust-path : ℕ → BT → path → path adjust-path k (Node n i b) (ps d p) = maybe-else' (nth d b) (ps d p) λ n → ps d (adjust-path k n p) adjust-path k (Node n i b) as with k =ℕ i ...| tt = hd ...| ff = as adjust-path k (Node n i b) hd = hd -- Δ functions construct-BT : term → maybe BT construct-BT = h zero empty-trie Node where h : ℕ → trie ℕ → ((n i : ℕ) → 𝕃 BT → BT) → term → maybe BT h n vm f (Var _ x) = just (f n (trie-lookup-else zero vm x) []) h n vm f (App t NotErased t') = h n vm Node t' ≫=maybe λ t' → h n vm (λ n i b → f n i (b ++ [ t' ])) t h n vm f (Lam _ NotErased _ x NoClass t) = h (suc n) (trie-insert vm x (suc n)) f t h n vm f t = nothing {-# TERMINATING #-} construct-path' : BT → BT → maybe (path × BT × BT) construct-path : BT → BT → maybe (path × BT × BT) construct-path (Node _ zero _) _ = nothing construct-path _ (Node _ zero _) = nothing construct-path t₁ t₂ = uncurry construct-path' (η-equate t₁ t₂) construct-path' t₁ @ (Node n₁ i₁ b₁) t₂ @ (Node n₂ i₂ b₂) = if ~ i₁ =ℕ i₂ then just (hd , t₁ , t₂) else if length b₁ =ℕ length b₂ then maybe-map (λ {(p , b₁ , b₂) → p , Node n₁ i₁ b₁ , Node n₂ i₂ b₂}) (h zero b₁ b₂) else just (as , t₁ , t₂) where h : ℕ → 𝕃 BT → 𝕃 BT → maybe (path × 𝕃 BT × 𝕃 BT) h n (b₁ :: bs₁) (b₂ :: bs₂) = maybe-else (maybe-map (λ {(p , bs₁ , bs₂) → p , b₁ :: bs₁ , b₂ :: bs₂}) (h (suc n) bs₁ bs₂)) (λ {(p , b₁ , b₂) → just (ps n p , b₁ :: bs₁ , b₂ :: bs₂)}) (construct-path b₁ b₂) h _ _ _ = nothing {-# TERMINATING #-} construct-Δ : BT → BT → path → 𝕃 BT construct-Δ (Node n₁ i₁ b₁) (Node n₂ i₂ b₂) hd = nfoldl n₁ [] λ m → _::_ (if suc m =ℕ i₁ then Node (2 + length b₁) (1 + length b₁) [] else if suc m =ℕ i₂ then Node (2 + length b₂) (2 + length b₂) [] else Node 1 1 []) construct-Δ (Node n₁ i₁ b₁) (Node n₂ i₂ b₂) as = let l₁ = length b₁ l₂ = length b₂ d = l₁ > l₂ lM = if d then l₁ else l₂ lm = if d then l₂ else l₁ l = lM ∸ lm in nfoldl n₁ (nfoldr l [ Node (2 + l) ((if d then 1 else 2) + l) [] ] λ l' → _++ [ if suc l' =ℕ l then Node 2 (if d then 2 else 1) [] else Node 1 1 [] ]) (λ n' → _::_ (if suc n' =ℕ i₁ then Node (suc lM) (suc lM) [] else Node 1 1 [])) construct-Δ t₁ @ (Node n₁ i₁ b₁) t₂ @ (Node n₂ i₂ b₂) (ps d p) with nth d b₁ ≫=maybe λ b₁ → nth d b₂ ≫=maybe λ b₂ → just (b₁ , b₂) ...| nothing = [] -- Shouldn't happen ...| just (t₁' @ (Node n₁' i₁' b₁') , t₂' @ (Node n₂' i₂' b₂')) with occurs-in-path i₁ t₁' p || occurs-in-path i₂ t₂' p ...| ff = set-nth (pred i₁) (Node (length b₁) (suc d) []) (construct-Δ t₁' t₂' p) ...| tt with max (greatest-apps i₁ t₁) (greatest-apps i₂ t₂) ...| kₘ with η-equate-path (rotate-BT i₁ (greatest-η i₁ kₘ t₁)) (rotate-BT i₂ (greatest-η i₂ kₘ t₂)) (ps d p) ...| t₁'' , t₂'' = set-nth (pred i₁) (rotate kₘ) (construct-Δ t₁'' t₂'' (ps d $ adjust-path i₁ t₁' p)) reconstruct : BT → term reconstruct = h zero where mkvar : ℕ → var mkvar n = "x" ^ ℕ-to-string n h : ℕ → BT → term a : ℕ → term → 𝕃 BT → term a n t [] = t a n t (b :: bs) = a n (mapp t (h n b)) bs h m (Node n i b) = nfoldl (n ∸ m) (a n (mvar (mkvar i)) b) (λ nm → mlam (mkvar (suc (m + nm)))) -- Returns a term f such that f t₁ ≃ λ t. λ f. t and f t₂ ≃ λ t. λ f. f, assuming two things: -- 1. t₁ ≄ t₂ -- 2. The head of each node along the path to the difference between t₁ and t₂ is bound -- withing the terms (so λ x. λ y. y y (x y) and λ x. λ y. y y (x x) works, but not -- λ x. λ y. y y (f y), where f is already declared/defined) make-contradiction : (t₁ t₂ : term) → maybe term make-contradiction t₁ t₂ = construct-BT t₁ ≫=maybe λ t₁ → construct-BT t₂ ≫=maybe λ t₂ → construct-path t₁ t₂ ≫=maybe λ {(p , t₁ , t₂) → just (reconstruct (Node (suc zero) (suc zero) (map (η-expand' zero) (construct-Δ t₁ t₂ p))))} -- Returns tt if the two terms are provably not equal is-contradiction : term → term → 𝔹 is-contradiction t₁ t₂ = isJust (make-contradiction t₁ t₂)
{ "alphanum_fraction": 0.5289246279, "avg_line_length": 37.1964285714, "ext": "agda", "hexsha": "f883d2eb4a49ccf9274dee89b61dd8fa8a08160f", "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": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CarlOlson/cedille", "max_forks_repo_path": "src/bohm-out.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "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": "CarlOlson/cedille", "max_issues_repo_path": "src/bohm-out.agda", "max_line_length": 106, "max_stars_count": null, "max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CarlOlson/cedille", "max_stars_repo_path": "src/bohm-out.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3406, "size": 8332 }
-- Copyright: (c) 2016 Ertugrul Söylemez -- License: BSD3 -- Maintainer: Ertugrul Söylemez <[email protected]> module Data.Fin.Core where open import Core open import Data.Nat import Data.Nat.Core as Nat data Fin : ℕ → Set where fzero : {n : ℕ} → Fin (suc n) fsuc : {n : ℕ} → Fin n → Fin (suc n) instance Fin-Number : {n : ℕ} → Number (Fin (suc n)) Fin-Number {n} = record { Constraint = λ x → x ℕ,≤.≤ n; fromNat = f n } where f : ∀ n x {{_ : x ℕ,≤.≤ n}} → Fin (suc n) f n .0 {{Nat.0≤s}} = fzero f (suc n) (suc x) {{Nat.s≤s p}} = fsuc (f n x {{p}}) Fin,≡ : ∀ {n} → Equiv (Fin n) Fin,≡ = PropEq _ fsuc-inj : ∀ {n} {x y : Fin (suc n)} → fsuc x ≡ fsuc y → x ≡ y fsuc-inj ≡-refl = ≡-refl fromℕ : ∀ {n} (x : ℕ) → x Nat.≤ n → Fin (suc n) fromℕ zero p = fzero fromℕ (suc x) (Nat.s≤s p) = fsuc (fromℕ x p) toℕ : ∀ {n} → Fin (suc n) → ∃ (λ x → x Nat.≤ n) toℕ fzero = zero , Nat.0≤s toℕ {zero} (fsuc ()) toℕ {suc n} (fsuc x) with toℕ x toℕ {suc n} (fsuc x) | x' , p = suc x' , Nat.s≤s p embed : ∀ {n} → Fin n → Fin (suc n) embed fzero = fzero embed (fsuc x) = fsuc (embed x) _≤_ : ∀ {n} (x y : Fin (suc n)) → Set _ x ≤ y = fst (toℕ x) Nat.≤ fst (toℕ y) infix 1 _≤_ _≤?_ : ∀ {n} (x y : Fin (suc n)) → Decision (x ≤ y) x ≤? y = fst (toℕ x) Nat.≤? fst (toℕ y) -- Fin,≤ : ∀ {n} → TotalOrder (Fin (suc n)) -- Fin,≤ {n} = -- record { -- partialOrder = record { -- Eq = Fin,≡; -- _≤_ = _≤_; -- antisym = antisym; -- refl' = refl'; -- trans = λ {x} {y} {z} → trans {x} {y} {z} -- }; -- total = total -- } -- where -- not-s≤0 : ∀ {n} {x : Fin (suc n)} → not (fsuc x ≤ fzero) -- not-s≤0 () -- antisym : ∀ {x y} → x ≤ y → y ≤ x → x ≡ y -- antisym {fzero} {fzero} p q = ≡-refl -- antisym {fzero} {fsuc y} p q with not-s≤0 {!!} -- antisym {fzero} {fsuc y} p q | () -- antisym {fsuc x} p q = {!!} -- refl' : ∀ {x y} → x ≡ y → x ≤ y -- refl' = {!!} -- trans : ∀ {x y z} → x ≤ y → y ≤ z → x ≤ z -- trans = {!!} -- total : ∀ x y → Either (x ≤ y) (y ≤ x) -- total = {!!}
{ "alphanum_fraction": 0.4679732314, "avg_line_length": 22.2553191489, "ext": "agda", "hexsha": "da45c906c26b183b78408a5acf0285dd84d2effe", "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": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "esoeylemez/agda-simple", "max_forks_repo_path": "Data/Fin/Core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": "esoeylemez/agda-simple", "max_issues_repo_path": "Data/Fin/Core.agda", "max_line_length": 62, "max_stars_count": 1, "max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "esoeylemez/agda-simple", "max_stars_repo_path": "Data/Fin/Core.agda", "max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z", "num_tokens": 966, "size": 2092 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.FiniteMultiset.CountExtensionality where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Sum open import Cubical.Relation.Nullary open import Cubical.HITs.FiniteMultiset.Base open import Cubical.HITs.FiniteMultiset.Properties as FMS open import Cubical.Structures.MultiSet open import Cubical.Relation.Nullary.DecidableEq private variable ℓ : Level -- We define a partial order on FMSet A and use it to proof -- a strong induction principle for finite multi-sets. -- Finally, we use this stronger elimination principle to show -- that any two FMSets can be identified, if they have the same count for every a : A module _{A : Type ℓ} (discA : Discrete A) where _≼_ : FMSet A → FMSet A → Type ℓ xs ≼ ys = ∀ a → FMScount discA a xs ≤ FMScount discA a ys ≼-refl : ∀ xs → xs ≼ xs ≼-refl xs a = ≤-refl ≼-trans : ∀ xs ys zs → xs ≼ ys → ys ≼ zs → xs ≼ zs ≼-trans xs ys zs xs≼ys ys≼zs a = ≤-trans (xs≼ys a) (ys≼zs a) ≼[]→≡[] : ∀ xs → xs ≼ [] → xs ≡ [] ≼[]→≡[] xs xs≼[] = FMScount-0-lemma discA xs λ a → ≤0→≡0 (xs≼[] a) ≼-remove1 : ∀ a xs → remove1 discA a xs ≼ xs ≼-remove1 a xs b with discA a b ... | yes a≡b = subst (λ n → n ≤ FMScount discA b xs) (sym path) (≤-predℕ) where path : FMScount discA b (remove1 discA a xs) ≡ predℕ (FMScount discA b xs) path = cong (λ c → FMScount discA b (remove1 discA c xs)) a≡b ∙ remove1-predℕ-lemma discA b xs ... | no a≢b = subst (λ n → n ≤ FMScount discA b xs) (sym (FMScount-remove1-≢-lemma discA xs λ b≡a → a≢b (sym b≡a))) ≤-refl ≼-remove1-lemma : ∀ x xs ys → ys ≼ (x ∷ xs) → (remove1 discA x ys) ≼ xs ≼-remove1-lemma x xs ys ys≼x∷xs a with discA a x ... | yes a≡x = ≤-trans (≤-trans (0 , p₁) (predℕ-≤-predℕ (ys≼x∷xs a))) (0 , cong predℕ (FMScount-≡-lemma discA xs a≡x)) where p₁ : FMScount discA a (remove1 discA x ys) ≡ predℕ (FMScount discA a ys) p₁ = subst (λ b → FMScount discA a (remove1 discA b ys) ≡ predℕ (FMScount discA a ys)) a≡x (remove1-predℕ-lemma discA a ys) ... | no a≢x = ≤-trans (≤-trans (0 , FMScount-remove1-≢-lemma discA ys a≢x) (ys≼x∷xs a)) (0 , FMScount-≢-lemma discA xs a≢x) ≼-Dichotomy : ∀ x xs ys → ys ≼ (x ∷ xs) → (ys ≼ xs) ⊎ (ys ≡ x ∷ (remove1 discA x ys)) ≼-Dichotomy x xs ys ys≼x∷xs with (FMScount discA x ys) ≟ suc (FMScount discA x xs) ... | lt <suc = inl ys≼xs where ys≼xs : ys ≼ xs ys≼xs a with discA a x ... | yes a≡x = pred-≤-pred (subst (λ b → (FMScount discA b ys) < suc (FMScount discA b xs)) (sym a≡x) <suc) ... | no a≢x = ≤-trans (ys≼x∷xs a) (subst (λ n → FMScount discA a (x ∷ xs) ≤ n) (FMScount-≢-lemma discA xs a≢x) ≤-refl) ... | eq ≡suc = inr (remove1-suc-lemma discA x (FMScount discA x xs) ys ≡suc) ... | gt >suc = ⊥.rec (¬m<m strict-ineq) where strict-ineq : suc (FMScount discA x xs) < suc (FMScount discA x xs) strict-ineq = <≤-trans (<≤-trans >suc (ys≼x∷xs x)) (0 , FMScount-≡-lemma-refl discA xs) -- proving a strong elimination principle for finite multisets module ≼-ElimProp {ℓ'} {B : FMSet A → Type ℓ'} (BisProp : ∀ {xs} → isProp (B xs)) (b₀ : B []) (B-≼-hyp : ∀ x xs → (∀ ys → ys ≼ xs → B ys) → B (x ∷ xs)) where C : FMSet A → Type (ℓ-max ℓ ℓ') C xs = ∀ ys → ys ≼ xs → B ys g : ∀ xs → C xs g = ElimProp.f (isPropΠ2 (λ _ _ → BisProp)) c₀ θ where c₀ : C [] c₀ ys ys≼[] = subst B (sym (≼[]→≡[] ys ys≼[])) b₀ θ : ∀ x {xs} → C xs → C (x ∷ xs) θ x {xs} hyp ys ys≼x∷xs with ≼-Dichotomy x xs ys ys≼x∷xs ... | inl ys≼xs = hyp ys ys≼xs ... | inr ys≡x∷zs = subst B (sym ys≡x∷zs) (B-≼-hyp x zs χ) where zs = remove1 discA x ys χ : ∀ vs → vs ≼ zs → B vs χ vs vs≼zs = hyp vs (≼-trans vs zs xs vs≼zs (≼-remove1-lemma x xs ys ys≼x∷xs)) f : ∀ xs → B xs f = C→B g where C→B : (∀ xs → C xs) → (∀ xs → B xs) C→B C-hyp xs = C-hyp xs xs (≼-refl xs) ≼-ElimPropBin : ∀ {ℓ'} {B : FMSet A → FMSet A → Type ℓ'} → (∀ {xs} {ys} → isProp (B xs ys)) → (B [] []) → (∀ x xs ys → (∀ vs ws → vs ≼ xs → ws ≼ ys → B vs ws) → B (x ∷ xs) ys) → (∀ x xs ys → (∀ vs ws → vs ≼ xs → ws ≼ ys → B vs ws) → B xs (x ∷ ys)) ------------------------------------------------------------------------------- → (∀ xs ys → B xs ys) ≼-ElimPropBin {B = B} BisProp b₀₀ left-hyp right-hyp = ≼-ElimProp.f (isPropΠ (λ _ → BisProp)) θ χ where θ : ∀ ys → B [] ys θ = ≼-ElimProp.f BisProp b₀₀ h₁ where h₁ : ∀ x ys → (∀ ws → ws ≼ ys → B [] ws) → B [] (x ∷ ys) h₁ x ys mini-h = right-hyp x [] ys h₂ where h₂ : ∀ vs ws → vs ≼ [] → ws ≼ ys → B vs ws h₂ vs ws vs≼[] ws≼ys = subst (λ zs → B zs ws) (sym (≼[]→≡[] vs vs≼[])) (mini-h ws ws≼ys) χ : ∀ x xs → (∀ zs → zs ≼ xs → (∀ ys → B zs ys)) → ∀ ys → B (x ∷ xs) ys χ x xs h ys = left-hyp x xs ys λ vs ws vs≼xs _ → h vs vs≼xs ws ≼-ElimPropBinSym : ∀ {ℓ'} {B : FMSet A → FMSet A → Type ℓ'} → (∀ {xs} {ys} → isProp (B xs ys)) → (∀ {xs} {ys} → B xs ys → B ys xs) → (B [] []) → (∀ x xs ys → (∀ vs ws → vs ≼ xs → ws ≼ ys → B vs ws) → B (x ∷ xs) ys) ---------------------------------------------------------------------------- → (∀ xs ys → B xs ys) ≼-ElimPropBinSym {B = B} BisProp BisSym b₀₀ left-hyp = ≼-ElimPropBin BisProp b₀₀ left-hyp right-hyp where right-hyp : ∀ x xs ys → (∀ vs ws → vs ≼ xs → ws ≼ ys → B vs ws) → B xs (x ∷ ys) right-hyp x xs ys h₁ = BisSym (left-hyp x ys xs (λ vs ws vs≼ys ws≼xs → BisSym (h₁ ws vs ws≼xs vs≼ys))) -- The main result module FMScountExt where B : FMSet A → FMSet A → Type ℓ B xs ys = (∀ a → FMScount discA a xs ≡ FMScount discA a ys) → xs ≡ ys BisProp : ∀ {xs} {ys} → isProp (B xs ys) BisProp = isPropΠ λ _ → trunc _ _ BisSym : ∀ {xs} {ys} → B xs ys → B ys xs BisSym {xs} {ys} b h = sym (b (λ a → sym (h a))) b₀₀ : B [] [] b₀₀ _ = refl left-hyp : ∀ x xs ys → (∀ vs ws → vs ≼ xs → ws ≼ ys → B vs ws) → B (x ∷ xs) ys left-hyp x xs ys hyp h₁ = (λ i → x ∷ (hyp-path i)) ∙ sym path where eq₁ : FMScount discA x ys ≡ suc (FMScount discA x xs) eq₁ = sym (h₁ x) ∙ FMScount-≡-lemma-refl discA xs path : ys ≡ x ∷ (remove1 discA x ys) path = remove1-suc-lemma discA x (FMScount discA x xs) ys eq₁ hyp-path : xs ≡ remove1 discA x ys hyp-path = hyp xs (remove1 discA x ys) (≼-refl xs) (≼-remove1 x ys) θ where θ : ∀ a → FMScount discA a xs ≡ FMScount discA a (remove1 discA x ys) θ a with discA a x ... | yes a≡x = subst (λ b → FMScount discA b xs ≡ FMScount discA b (remove1 discA x ys)) (sym a≡x) eq₂ where eq₂ : FMScount discA x xs ≡ FMScount discA x (remove1 discA x ys) eq₂ = FMScount discA x xs ≡⟨ cong predℕ (sym (FMScount-≡-lemma-refl discA xs)) ⟩ predℕ (FMScount discA x (x ∷ xs)) ≡⟨ cong predℕ (h₁ x) ⟩ predℕ (FMScount discA x ys) ≡⟨ sym (remove1-predℕ-lemma discA x ys) ⟩ FMScount discA x (remove1 discA x ys) ∎ ... | no a≢x = FMScount discA a xs ≡⟨ sym (FMScount-≢-lemma discA xs a≢x) ⟩ FMScount discA a (x ∷ xs) ≡⟨ h₁ a ⟩ FMScount discA a ys ≡⟨ cong (FMScount discA a) path ⟩ FMScount discA a (x ∷ (remove1 discA x ys)) ≡⟨ FMScount-≢-lemma discA (remove1 discA x ys) a≢x ⟩ FMScount discA a (remove1 discA x ys) ∎ Thm : ∀ xs ys → (∀ a → FMScount discA a xs ≡ FMScount discA a ys) → xs ≡ ys Thm = ≼-ElimPropBinSym BisProp BisSym b₀₀ left-hyp
{ "alphanum_fraction": 0.5098540146, "avg_line_length": 42.8125, "ext": "agda", "hexsha": "298d64711ed604760b2432dc45e60487d1b4978b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "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/FiniteMultiset/CountExtensionality.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/HITs/FiniteMultiset/CountExtensionality.agda", "max_line_length": 126, "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/FiniteMultiset/CountExtensionality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3225, "size": 8220 }
module SameName where data Stuff : Set where mkStuff : Stuff stuffFunc : Stuff -> (Stuff : Set) -> Stuff stuffFunc = {! !}
{ "alphanum_fraction": 0.6461538462, "avg_line_length": 14.4444444444, "ext": "agda", "hexsha": "4c6cc431e54a0b92ba3a2d8a9903428691a9fe9e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "omega12345/RefactorAgda", "max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/input/SameName.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "omega12345/RefactorAgda", "max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/input/SameName.agda", "max_line_length": 43, "max_stars_count": 5, "max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "omega12345/RefactorAgda", "max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/input/SameName.agda", "max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z", "num_tokens": 37, "size": 130 }
{-# OPTIONS --without-K #-} module FunExt where open import Base module _ {i j} {A : Type i} {B : A → Type j} where happly : (f g : (x : A) → B x) → (f == g) → ((x : A) → f x == g x) happly f g = ind== D d where D : (f g : (x : A) → B x) → f == g → Type _ D f g _ = (x : A) → f x == g x d : (f : (x : A) → B x) → D f f idp d f = λ x → idp postulate fun-ext : (f g : (x : A) → B x) → is-equiv (happly f g)
{ "alphanum_fraction": 0.4328018223, "avg_line_length": 23.1052631579, "ext": "agda", "hexsha": "b67749fef5c5c69039ff382d5e2385c2aa72a659", "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": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "aerskine/hott-ex", "max_forks_repo_path": "FunExt.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "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": "aerskine/hott-ex", "max_issues_repo_path": "FunExt.agda", "max_line_length": 68, "max_stars_count": null, "max_stars_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "aerskine/hott-ex", "max_stars_repo_path": "FunExt.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 188, "size": 439 }
{-# OPTIONS --rewriting --without-K #-} -- -- Prelude.agda - Some base definitions -- module Prelude where open import Agda.Primitive public record ⊤ : Set where constructor tt {-# BUILTIN UNIT ⊤ #-} record Σ {i j} (A : Set i) (B : A → Set j) : Set (i ⊔ j) where constructor _,_ field fst : A snd : B fst open Σ public _×_ : ∀ {i j} (A : Set i) (B : Set j) → Set (i ⊔ j) A × B = Σ A (λ a → B) id : ∀ {i} {A : Set i} → A → A id x = x uncurry : ∀ {i j k} {A : Set i} {B : A → Set j} {C : Set k} → (φ : (a : A) → (b : B a) → C) → Σ A B → C uncurry φ (a , b) = φ a b curry : ∀ {i j k} {A : Set i} {B : A → Set j} {C : Set k} → (ψ : Σ A B → C) → (a : A) → (b : B a) → C curry ψ a b = ψ (a , b) {- Equality -} infix 30 _==_ data _==_ {i} {A : Set i} (a : A) : A → Set i where idp : a == a {-# BUILTIN EQUALITY _==_ #-} {-# BUILTIN REWRITE _==_ #-} infixl 20 _>>_ _>>_ : ∀ {i} {A : Set i} {a b c : A} → a == b → b == c → a == c idp >> idp = idp _^ : ∀ {i} {A : Set i} {a b : A} → a == b → b == a _^ idp = idp coe : ∀ {a} {A B : Set a} → A == B → A → B coe idp x = x coe^ : ∀ {a} {A B : Set a} (p : A == B) {a : A} {b : B} → a == (coe (p ^) b) → (coe p a) == b coe^ idp q = q coe= : ∀ {a} {A B : Set a} (p : A == B) {a b : A} → a == b → coe p a == coe p b coe= p idp = idp ap : ∀ {i j} {A : Set i} {C : Set j} {M N : A} (f : A → C) → M == N → (f M) == (f N) ap f idp = idp ap² : ∀ {i j k} {A : Set i} {B : Set k} {C : Set j} {a a' : A} {b b' : B} (f : A → B → C) → a == a' → b == b' → (f a b) == (f a' b') ap² f idp idp = idp ap³ : ∀ {i j k l} {A : Set i} {B : Set k} {C : Set j} {D : Set l} {a a' : A} {b b' : B} {c c' : C} (f : A → B → C → D) → a == a' → b == b' → c == c' → (f a b c) == (f a' b' c') ap³ f idp idp idp = idp ap⁴ : ∀ {i j k l m} {A : Set i} {B : Set k} {C : Set j} {D : Set l} {E : Set m} {a a' : A} {b b' : B} {c c' : C} {d d' : D} (f : A → B → C → D → E) → a == a' → b == b' → c == c' → d == d' → (f a b c d) == (f a' b' c' d') ap⁴ f idp idp idp idp = idp ap⁵ : ∀ {i j k l m n} {A : Set i} {B : Set k} {C : Set j} {D : Set l} {E : Set m} {F : Set n} {a a' : A} {b b' : B} {c c' : C} {d d' : D} {e e' : E} (f : A → B → C → D → E → F) → a == a' → b == b' → c == c' → d == d' → e == e' → (f a b c d e) == (f a' b' c' d' e') ap⁵ f idp idp idp idp idp = idp ap⁶ : ∀ {i j k l m n o} {A : Set i} {B : Set k} {C : Set j} {D : Set l} {E : Set m} {F : Set n} {G : Set o} {a a' : A} {b b' : B} {c c' : C} {d d' : D} {e e' : E} {f f' : F} (α : A → B → C → D → E → F → G) → a == a' → b == b' → c == c' → d == d' → e == e' → f == f' → (α a b c d e f) == (α a' b' c' d' e' f') ap⁶ f idp idp idp idp idp idp = idp ap⁷ : ∀ {i j k l m n o p} {A : Set i} {B : Set k} {C : Set j} {D : Set l} {E : Set m} {F : Set n} {G : Set o} {H : Set p} {a a' : A} {b b' : B} {c c' : C} {d d' : D} {e e' : E} {f f' : F} {g g' : G} (α : A → B → C → D → E → F → G → H) → a == a' → b == b' → c == c' → d == d' → e == e' → f == f' → g == g' → (α a b c d e f g) == (α a' b' c' d' e' f' g') ap⁷ f idp idp idp idp idp idp idp = idp transport : ∀ {i j} {A : Set i} {B : A → Set j} {a a' : A} (pₐ : a == a') → B a → B a' transport pₐ b = coe (ap _ pₐ) b transport₂ : ∀ {i j k} {A : Set i} {B : Set j} {C : A → B → Set k} {a a' : A} {b b' : B} (pₐ : a == a') (q : b == b') → C a b → C a' b' transport₂ pₐ q c = coe (ap² _ pₐ q) c hfiber : ∀ {i} {A B : Set i} (f : A → B) (b : B) → Set i hfiber {A = A} f b = Σ A (λ a → f a == b) PathOver : ∀ {i j} {A : Set i} (B : A → Set j) {a₀ a₁ : A} (p : a₀ == a₁) (b₉ : B a₀) (b₁ : B a₁) → Set j PathOver B idp b₀ b₁ = b₀ == b₁ infix 30 PathOver syntax PathOver B p u v = u == v [ B ↓ p ] ×= : ∀{i j} {A : Set i} {B : Set j} {a a' : A} {b b' : B} → a == a' → b == b' → (a , b) == (a' , b') ×= idp idp = idp Σ= : ∀ {i j} {A : Set i} {B : A → Set j} {a a' : A} {b : B a} {b' : B a'} → (pₐ : a == a') → transport pₐ b == b' → (a , b) == (a' , b') Σ= idp idp = idp ,= : ∀ {i j} {A : Set i} {B : Set j} {a a' : A} {b b' : B} → a == a' → b == b' → (a , b) == (a' , b') ,= idp idp = idp Σ-r : ∀ {i j k} {A : Set i} {B : A → Set j} (C : Σ A B → Set k) → A → Set (j ⊔ k) Σ-r {A = A} {B = B} C a = Σ (B a) (λ b → C (a , b)) Σ-in : ∀ {i j k} {A : Set i} {B : A → Set j} (C : (a : A) → B a → Set k) → A → Set (j ⊔ k) Σ-in {A = A} {B = B} C a = Σ (B a) (λ b → C a b) =, : ∀ {i j} {A : Set i} {B : Set j} {a a' : A} {b b' : B} → (a , b) == (a' , b') → (a == a') × (b == b') =, idp = idp , idp fst-is-inj : ∀ {i j} {A : Set i} {B : A → Set j} {x y : Σ A B} → x == y → fst x == fst y fst-is-inj idp = idp {- False and negation -} data ⊥ {i} : Set i where ⊥-elim : ∀ {i j} {A : Set i} → ⊥ {j} → A ⊥-elim () ¬_ : ∀ {i} → Set i → Set i ¬ A = A → ⊥ {lzero} _≠_ : ∀{i} {A : Set i} (a b : A) → Set i a ≠ b = ¬ (a == b) data _+_ {i j} (A : Set i) (B : Set j) : Set (i ⊔ j) where inl : A → A + B inr : B → A + B inl= : ∀ {i j} {A : Set i} {B : Set j} {a b : A} → a == b → _==_ {i ⊔ j} {A + B} (inl a) (inl b) inl= idp = idp inr= : ∀ {i j} {A : Set i} {B : Set j} {a b : B} → a == b → _==_ {i ⊔ j} {A + B} (inr a) (inr b) inr= idp = idp {- Booleans -} data Bool : Set where true : Bool false : Bool {- Decidability -} dec : ∀ {i} → Set i → Set i dec A = A + (¬ A) eqdec : ∀ {i} → Set i → Set i eqdec A = ∀ (a b : A) → dec (a == b) {- Natural numbers -} data ℕ : Set where O : ℕ S : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} S= : ∀{n m} → n == m → S n == S m S= idp = idp pred : ℕ → ℕ pred O = O pred (S n) = n S-is-inj : ∀ n m → (S n == S m) → n == m S-is-inj n m p = ap pred p S-≠ : ∀ {n m : ℕ} (p : n ≠ m) → S n ≠ S m S-≠ {n} {m} n≠m p = n≠m (S-is-inj n m p) private S≠O-type : ℕ → Set S≠O-type O = ⊥ S≠O-type (S n) = ⊤ S≠O : (n : ℕ) → S n ≠ O S≠O n p = coe (ap S≠O-type p) tt O≠S : (n : ℕ) → (O ≠ S n) O≠S n p = S≠O n (p ^) n≠Sn : (n : ℕ) → (n ≠ S n) n≠Sn O () n≠Sn (S n) n=Sn = n≠Sn n (S-is-inj _ _ n=Sn) Sn≠n : (n : ℕ) → (S n ≠ n) Sn≠n O () Sn≠n (S n) Sn=n = Sn≠n n (S-is-inj _ _ Sn=n) eqdecℕ : eqdec ℕ eqdecℕ O O = inl idp eqdecℕ O (S b) = inr (O≠S b) eqdecℕ (S a) O = inr (S≠O a) eqdecℕ (S a) (S b) with (eqdecℕ a b) ... | inl idp = inl idp ... | inr a≠b = inr (S-≠ a≠b) {- Order on ℕ -} data _≤_ : ℕ → ℕ → Set where 0≤ : ∀ n → O ≤ n S≤ : ∀ {n m} → n ≤ m → S n ≤ S m n≤n : ∀ (n : ℕ) → n ≤ n n≤n O = 0≤ O n≤n (S n) = S≤ (n≤n n) ≤-antisymetry : ∀ {n m} → n ≤ m → m ≤ n → n == m ≤-antisymetry (0≤ _) (0≤ _) = idp ≤-antisymetry (S≤ n≤m) (S≤ m≤n) = ap S (≤-antisymetry n≤m m≤n) n≤Sn : ∀ (n : ℕ) → n ≤ S n n≤Sn O = 0≤ _ n≤Sn (S n) = S≤ (n≤Sn _) S≤S : ∀ {n m} → S n ≤ S m → n ≤ m S≤S (S≤ n≤m) = n≤m Sn≰n : ∀ (n : ℕ) → ¬ (S n ≤ n) Sn≰n .(S _) (S≤ Sn≤n) = Sn≰n _ Sn≤n Sn≰n-t : ∀ {n m} → n == m → ¬ (S n ≤ m) Sn≰n-t idp Sn≤n = Sn≰n _ Sn≤n Sn≰0 : ∀ (n : ℕ) → ¬ (S n ≤ O) Sn≰0 n () n≤m→n≤Sm : ∀ {n m : ℕ} → n ≤ m → n ≤ S m n≤m→n≤Sm (0≤ n) = 0≤ (S n) n≤m→n≤Sm (S≤ n≤m) = S≤ (n≤m→n≤Sm n≤m) Sn≤m→n≤m : ∀ {n m : ℕ} → S n ≤ m → n ≤ m Sn≤m→n≤m (S≤ n≤m) = n≤m→n≤Sm n≤m dec-≤ : ∀ n m → dec (n ≤ m) dec-≤ O m = inl (0≤ m) dec-≤ (S n) O = inr λ () dec-≤ (S n) (S m) with (dec-≤ n m) ... | inl n≤m = inl (S≤ n≤m) ... | inr n≰m = inr λ {(S≤ n≤m) → n≰m n≤m} ≤S : ∀ (n m : ℕ) → n ≤ S m → (n ≤ m) + (n == S m) ≤S .0 m (0≤ .(S m)) = inl (0≤ _) ≤S .1 O (S≤ (0≤ .0)) = inr idp ≤S .(S _) (S m) (S≤ n≤Sm) with ≤S _ _ n≤Sm ... | inl n≤m = inl (S≤ n≤m) ... | inr n=Sm = inr (ap S n=Sm) ≤-= : ∀ {n m k} → n ≤ m → m == k → n ≤ k ≤-= n≤m idp = n≤m =-≤ : ∀ {n m k} → n == m → m ≤ k → n ≤ k =-≤ idp m≤k = m≤k =-≤-= : ∀ {n m k l} → n == m → m ≤ k → k == l → n ≤ l =-≤-= idp m≤k idp = m≤k ≤T : ∀ {n m k} → n ≤ m → m ≤ k → n ≤ k ≤T (0≤ _) _ = 0≤ _ ≤T (S≤ n≤m) (S≤ m≤k) = S≤ (≤T n≤m m≤k) {- Strict order on ℕ -} _<_ : ℕ → ℕ → Set n < m = S n ≤ m ≤×≠→< : ∀ {n m} → n ≤ m → n ≠ m → n < m ≤×≠→< {.0} {.0} (0≤ O) n≠m = ⊥-elim (n≠m idp) ≤×≠→< {.0} {.(S m)} (0≤ (S m)) n≠m = S≤ (0≤ _) ≤×≠→< (S≤ n≤m) Sn≠Sm = S≤ (≤×≠→< n≤m λ n=m → Sn≠Sm (ap S n=m)) ≰ : ∀ {n m } → ¬ (n ≤ m) → m < n ≰ {O} {m} n≰m = ⊥-elim (n≰m (0≤ _)) ≰ {S n} {O} n≰m = S≤ (0≤ _) ≰ {S n} {S m} n≰m = S≤ (≰ λ n≤m → n≰m (S≤ n≤m)) ℕ-trichotomy : ∀ n m → ((n < m) + (m < n)) + (n == m) ℕ-trichotomy n m with dec-≤ n m ... | inr n≰m = inl (inr (≰ n≰m)) ... | inl n≤m with eqdecℕ n m ... | inl n=m = inr n=m ... | inr n≠m = inl (inl (≤×≠→< n≤m n≠m)) {- Minimum and maximum -} max : ℕ → ℕ → ℕ max n m with dec-≤ n m ... | inl _ = m ... | inr _ = n n≤max : ∀ n m → n ≤ max n m n≤max n m with dec-≤ n m ... | inl n≤m = n≤m ... | inr m≤n = n≤n _ m≤max : ∀ n m → m ≤ max n m m≤max n m with dec-≤ n m ... | inl n≤m = n≤n _ ... | inr n≰m = Sn≤m→n≤m (≰ n≰m) up-max : ∀ {n m k} → n ≤ k → m ≤ k → max n m ≤ k up-max {n} {m} {k} n≤k m≤k with dec-≤ n m ... | inl n≤m = m≤k ... | inr n≰m = n≤k up-maxS : ∀ {n m k} → S n ≤ k → S m ≤ k → S (max n m) ≤ k up-maxS {n} {m} {k} n≤k m≤k with dec-≤ n m ... | inl n≤m = m≤k ... | inr n≰m = n≤k simplify-max-l : ∀ {n m} → m ≤ n → max n m == n simplify-max-l {n} {m} m≤n with dec-≤ n m ... | inl n≤m = ≤-antisymetry m≤n n≤m ... | inr _ = idp simplify-max-r : ∀ {n m} → n ≤ m → max n m == m simplify-max-r {n} {m} n≤m with dec-≤ n m ... | inl _ = idp ... | inr n≰m = ⊥-elim (n≰m n≤m) min : ℕ → ℕ → ℕ min n m with dec-≤ n m ... | inl _ = n ... | inr _ = m min≤m : ∀ n m → min n m ≤ m min≤m n m with dec-≤ n m ... | inl n≤m = n≤m ... | inr n≰m = n≤n _ simplify-min-l : ∀ {n m} → n ≤ m → min n m == n simplify-min-l {n} {m} n≤m with dec-≤ n m ... | inl _ = idp ... | inr n≰m = ⊥-elim (n≰m n≤m) simplify-min-r : ∀ {n m} → m ≤ n → min n m == m simplify-min-r {n} {m} n≤m with dec-≤ n m ... | inl m≤n = ≤-antisymetry m≤n n≤m ... | inr _ = idp min<l : ∀ {n m} → min n m < n → m ≤ n min<l {n} {m} min<n with dec-≤ n m ... | inl _ = ⊥-elim (Sn≰n _ min<n) ... | inr _ = Sn≤m→n≤m min<n greater-than-min-r : ∀ {n m k} → k < n → min n m ≤ k → m ≤ k greater-than-min-r {n} {m} {k} k<n min≤k with dec-≤ n m ... | inl _ = ⊥-elim (Sn≰n _ (≤T (S≤ min≤k) k<n)) ... | inr _ = min≤k {- Conditional branchings -} ifdec_>_then_else_ : ∀ {i j} {A : Set i} (B : Set j) → (dec B) → A → A → A ifdec b > inl x then A else B = A ifdec b > inr x then A else B = B iftrue : ∀ {i j}{A : Set i} {B : Set j} → (H : dec B) → (a : A) {a' : A} → B → (ifdec B > H then a else a') == a iftrue (inl _) a b = idp iftrue (inr ¬B) a b = ⊥-elim (¬B b) iffalse : ∀ {i j}{A : Set i} {B : Set j} → (H : dec B) → {a : A} (a' : A) → ¬ B → (ifdec B > H then a else a') == a' iffalse (inl b) a' ¬B = ⊥-elim (¬B b) iffalse (inr ¬B) a' b = idp if_≡_then_else_ : ∀ {i} {A : Set i} → ℕ → ℕ → A → A → A if v ≡ w then A else B = ifdec (v == w) > (eqdecℕ v w) then A else B if= : ∀ {i} {A : Set i} {n m : ℕ} (p : n == m) (a : A) {a' : A} → (if n ≡ m then a else a') == a if= p a = iftrue (eqdecℕ _ _) a p if≠ : ∀ {i} {A : Set i} {n m : ℕ} (p : n ≠ m) {a : A} (a' : A) → (if n ≡ m then a else a') == a' if≠ p a' = iffalse (eqdecℕ _ _) a' p simplify-if : ∀ {i} {A : Set i} {n} {a b : A} → 0 < n → (if n ≡ 0 then a else b) == b simplify-if {n = n} {b = b} 0<n with eqdecℕ n 0 ... | inl idp = ⊥-elim (Sn≰0 _ 0<n) ... | inr _ = idp -- logical equivalence _↔_ : ∀{i j} (A : Set i) (B : Set j) → Set (i ⊔ j) A ↔ B = (A → B) × (B → A) {- Lists -} data list {i} : Set i → Set (lsuc i) where nil : ∀{A} → list A _::_ : ∀ {A} → list A → (a : A) → list A ::= : ∀ {i} {A : Set i} {l l' : list A} {a a' : A} → l == l' → a == a' → (l :: a) == (l' :: a') ::= idp idp = idp =:: : ∀ {i} {A : Set i} {a b : A} {l k} → (l :: a) == (k :: b) → (l == k) × (a == b) =:: idp = idp , idp cons≠nil : ∀ {i} {A : Set i} {l : list A} {a : A} → (l :: a) ≠ nil cons≠nil () length : ∀ {i} {A : Set i} → list A → ℕ length nil = 0 length (l :: _) = S (length l) _++_ : ∀ {i} {A : Set i} → list A → list A → list A l ++ nil = l l ++ (l' :: a) = (l ++ l') :: a _∈-list_ : ∀ {i} {A : Set i} → A → list A → Set i x ∈-list nil = ⊥ x ∈-list (l :: a) = (x ∈-list l) + (x == a) dec-∈-list : ∀ {i} {A : Set i} → eqdec A → ∀ (a : A) (l : list A) → dec (a ∈-list l) dec-∈-list eqdecA a nil = inr λ{()} dec-∈-list eqdecA a (l :: b) with eqdecA a b ... | inl idp = inl (inr idp) ... | inr a≠b with dec-∈-list eqdecA a l ... | inl a∈l = inl (inl a∈l) ... | inr a∉l = inr λ{(inl a∈l) → a∉l a∈l; (inr a=b) → a≠b a=b} {- Univalence and known consequences -} record is-equiv {i j} {A : Set i} {B : Set j} (f : A → B) : Set (i ⊔ j) where field g : B → A f-g : (b : B) → f (g b) == b g-f : (a : A) → g (f a) == a adj : (a : A) → ap f (g-f a) == f-g (f a) _≃_ : ∀ {i j} → (A : Set i) (B : Set j) → Set (i ⊔ j) A ≃ B = Σ (A → B) λ f → is-equiv f postulate univalence : ∀ {i} {A B : Set i} → (A == B) ≃ (A ≃ B) funext : ∀ {i} {A B : Set i} (f g : A → B) → (∀ x → f x == g x) → f == g funext-dep : ∀ {i} {A : Set i} {B : A → Set i} (f g : ∀ a → B a) → (∀ a → f a == g a) → f == g {- Definition of the first H-levels -} is-contr : ∀ {i} → Set i → Set i is-contr A = Σ A (λ x → ((y : A) → x == y)) is-prop : ∀ {i} → Set i → Set i is-prop A = ∀ (x y : A) → is-contr (x == y) is-set : ∀{i} → Set i → Set i is-set A = ∀ (x y : A) → is-prop (x == y) has-all-paths : ∀ {i} → Set i → Set i has-all-paths A = ∀ (a b : A) → a == b {- Known properties of H-levels -} postulate has-all-paths-idp : ∀ {i} (A : Set i) (pathsA : has-all-paths A) (a : A) → pathsA a a == idp has-all-paths-is-prop : ∀ {i} → {A : Set i} → has-all-paths A → is-prop A is-prop-has-all-paths : ∀ {i} → {A : Set i} → is-prop A → has-all-paths A eqdec-is-set : ∀ {i} {A : Set i} → eqdec A → is-set A is-setℕ : is-set ℕ is-setℕ = eqdec-is-set eqdecℕ
{ "alphanum_fraction": 0.3875963609, "avg_line_length": 30.5063559322, "ext": "agda", "hexsha": "97882d114f2f0deb7027520c5604071f1cd1e21a", "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": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_path": "Prelude.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "thibautbenjamin/catt-formalization", "max_issues_repo_path": "Prelude.agda", "max_line_length": 355, "max_stars_count": null, "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_path": "Prelude.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7546, "size": 14399 }
------------------------------------------------------------------------ -- Pullbacks ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module is partly based on code written by Guillame Brunerie in -- a fork of the Coq HoTT library -- (https://github.com/guillaumebrunerie/HoTT/), and partly based on -- the Wikipedia page about pullbacks -- (https://en.wikipedia.org/wiki/Pullback_(category_theory)). open import Equality module Pullback {e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection eq as Bijection using (_↔_) open import Equivalence eq as Eq using (_≃_; Is-equivalence) open import Function-universe eq as F hiding (_∘_) open import H-level.Closure eq private variable a a₁ a₂ b b₁ b₂ l m r : Level A A₁ A₂ B : Type a C : A k : Kind -- Cospans. record Cospan l r m : Type (lsuc (l ⊔ r ⊔ m)) where field {Left} : Type l {Right} : Type r {Middle} : Type m left : Left → Middle right : Right → Middle -- Cones over cospans. The "corner opposite to" the Middle type is a -- parameter, not a field, so a more accurate name might be something -- like Cone-over-cospan-with-given-opposite-corner. record Cone (A : Type a) (C : Cospan l r m) : Type (a ⊔ l ⊔ r ⊔ m) where field left : A → Cospan.Left C right : A → Cospan.Right C commutes : ∀ x → Cospan.left C (left x) ≡ Cospan.right C (right x) -- The type of cones can also be written using Σ-types. Cone↔Σ : Cone A C ↔ ∃ λ ((f , g) : (A → Cospan.Left C) × (A → Cospan.Right C)) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x) Cone↔Σ = record { surjection = record { logical-equivalence = record { to = λ f → (Cone.left f , Cone.right f) , Cone.commutes f ; from = λ ((l , r) , c) → record { left = l; right = r; commutes = c } } ; right-inverse-of = refl } ; left-inverse-of = refl } -- Equality between cones is isomorphic to certain kinds of triples. Cone-≡-↔-Σ : {C : Cospan l m r} {c d : Cone A C} → c ≡ d ↔ (∃ λ (p : Cone.left c ≡ Cone.left d) → ∃ λ (q : Cone.right c ≡ Cone.right d) → subst (λ (f , g) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) (cong₂ _,_ p q) (Cone.commutes c) ≡ Cone.commutes d) Cone-≡-↔-Σ {C = C} {c = c} {d = d} = c ≡ d ↔⟨ inverse $ Eq.≃-≡ (Eq.↔⇒≃ Cone↔Σ) ⟩ ((Cone.left c , Cone.right c) , Cone.commutes c) ≡ ((Cone.left d , Cone.right d) , Cone.commutes d) ↝⟨ inverse $ Bijection.Σ-≡,≡↔≡ ⟩ (∃ λ (p : (Cone.left c , Cone.right c) ≡ (Cone.left d , Cone.right d)) → subst (λ (f , g) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) p (Cone.commutes c) ≡ Cone.commutes d) ↝⟨ (Σ-cong-contra ≡×≡↔≡ λ _ → F.id) ⟩ (∃ λ (p : Cone.left c ≡ Cone.left d × Cone.right c ≡ Cone.right d) → subst (λ (f , g) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) (uncurry (cong₂ _,_) p) (Cone.commutes c) ≡ Cone.commutes d) ↝⟨ inverse Σ-assoc ⟩□ (∃ λ (p : Cone.left c ≡ Cone.left d) → ∃ λ (q : Cone.right c ≡ Cone.right d) → subst (λ (f , g) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) (cong₂ _,_ p q) (Cone.commutes c) ≡ Cone.commutes d) □ -- A composition operation for cones. composition : Cone B C → (A → B) → Cone A C composition c f .Cone.left = c .Cone.left ∘ f composition c f .Cone.right = c .Cone.right ∘ f composition c f .Cone.commutes = c .Cone.commutes ∘ f -- The pullback for a given cospan. Pullback : Cospan l r m → Type (l ⊔ r ⊔ m) Pullback C = ∃ λ x → ∃ λ y → Cospan.left C x ≡ Cospan.right C y -- The cone with the pullback as the "opposite corner". pullback-cone : Cone (Pullback C) C pullback-cone .Cone.left = proj₁ pullback-cone .Cone.right = proj₁ ∘ proj₂ pullback-cone .Cone.commutes = proj₂ ∘ proj₂ -- The property of being a homotopy pullback. Is-homotopy-pullback : {A : Type a} {C : Cospan l r m} → Cone A C → ∀ b → Type (a ⊔ lsuc b ⊔ l ⊔ r ⊔ m) Is-homotopy-pullback c b = (B : Type b) → Is-equivalence (composition {A = B} c) -- The pullback is a homotopy pullback for pullback-cone. is-homotopy-pullback : Is-homotopy-pullback (pullback-cone {C = C}) b is-homotopy-pullback {C = C} B = _≃_.is-equivalence ( (B → Pullback C) ↔⟨⟩ (B → ∃ λ x → ∃ λ y → Cospan.left C x ≡ Cospan.right C y) ↔⟨ ΠΣ-comm ⟩ (∃ λ f → ∀ x → ∃ λ y → Cospan.left C (f x) ≡ Cospan.right C y) ↔⟨ (∃-cong λ _ → ΠΣ-comm) ⟩ (∃ λ f → ∃ λ g → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) ↔⟨ Σ-assoc ⟩ (∃ λ (f , g) → ∀ x → Cospan.left C (f x) ≡ Cospan.right C (g x)) ↔⟨ inverse Cone↔Σ ⟩□ Cone B C □) -- A universal property for pullbacks. universal-property : (A → Pullback C) ≃ Cone A C universal-property = Eq.⟨ _ , is-homotopy-pullback _ ⟩ -- A variant of the universal property. universal-property′ : {C : Cospan l r m} (c : Cone A C) → Contractible (∃ λ (f : A → Pullback C) → composition pullback-cone f ≡ c) universal-property′ {A = A} {C = C} c = _⇔_.from contractible⇔↔⊤ ( (∃ λ (f : A → Pullback C) → composition pullback-cone f ≡ c) ↝⟨ (Σ-cong universal-property λ _ → F.id) ⟩ (∃ λ (d : Cone A C) → d ≡ c) ↝⟨ _⇔_.to contractible⇔↔⊤ (singleton-contractible _) ⟩□ ⊤ □) -- A preservation lemma for Cone. Cone-cong : {A₁ : Type a₁} {A₂ : Type a₂} {C : Cospan l r m} → Extensionality? k (a₁ ⊔ a₂) (l ⊔ r ⊔ m) → A₁ ≃ A₂ → Cone A₁ C ↝[ k ] Cone A₂ C Cone-cong {A₁ = A₁} {A₂ = A₂} {C = C} ext A₁≃A₂ = Cone A₁ C ↔⟨ inverse universal-property ⟩ (A₁ → Pullback C) ↝⟨ →-cong₁ ext A₁≃A₂ ⟩ (A₂ → Pullback C) ↔⟨ universal-property ⟩□ Cone A₂ C □ private -- A special case of Cone-cong that does not require extensionality. Cone-↑⊤↔Cone-↑⊤ : Cone (↑ a₁ ⊤) C ↔ Cone (↑ a₂ ⊤) C Cone-↑⊤↔Cone-↑⊤ {C = C} = Cone (↑ _ ⊤) C ↔⟨ inverse universal-property ⟩ (↑ _ ⊤ → Pullback C) ↝⟨ Π-left-identity-↑ ⟩ Pullback C ↝⟨ inverse Π-left-identity-↑ ⟩ (↑ _ ⊤ → Pullback C) ↔⟨ universal-property ⟩□ Cone (↑ _ ⊤) C □ -- The "opposite corners" of homotopy pullbacks for a fixed cospan are -- equivalent. homotopy-pullbacks-equivalent : (c₁ : Cone A₁ C) (c₂ : Cone A₂ C) → Is-homotopy-pullback c₁ b₁ → Is-homotopy-pullback c₂ b₂ → A₁ ≃ A₂ homotopy-pullbacks-equivalent {A₁ = A₁} {C = C} {A₂ = A₂} _ _ p₁ p₂ = A₁ ↔⟨ inverse Π-left-identity-↑ ⟩ (↑ _ ⊤ → A₁) ↝⟨ Eq.⟨ _ , p₁ (↑ _ ⊤) ⟩ ⟩ Cone (↑ _ ⊤) C ↔⟨ Cone-↑⊤↔Cone-↑⊤ ⟩ Cone (↑ _ ⊤) C ↝⟨ inverse Eq.⟨ _ , p₂ (↑ _ ⊤) ⟩ ⟩ (↑ _ ⊤ → A₂) ↔⟨ Π-left-identity-↑ ⟩□ A₂ □
{ "alphanum_fraction": 0.5180345719, "avg_line_length": 33.8571428571, "ext": "agda", "hexsha": "a3ca2c77b53a05fb83c890acd2d2622af1f79f9f", "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/Pullback.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/Pullback.agda", "max_line_length": 119, "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/Pullback.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": 2700, "size": 7347 }
open import Oscar.Class.Congruity open import Oscar.Data.Proposequality module Oscar.Class.Congruity.Proposextensequality where instance 𝓒̇ongruityProposextensequality : ∀ {a b} → 𝓒̇ongruity a b Proposextensequality 𝓒̇ongruity.ċongruity 𝓒̇ongruityProposextensequality _ f≡̇g x rewrite f≡̇g x = ∅
{ "alphanum_fraction": 0.7967213115, "avg_line_length": 27.7272727273, "ext": "agda", "hexsha": "2883f69bf9260a2355d2653c2d410259026abbbe", "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/Congruity/Proposextensequality.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/Congruity/Proposextensequality.agda", "max_line_length": 82, "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/Congruity/Proposextensequality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 119, "size": 305 }
-- Andreas, 2017-01-01, issue #2377 -- Warn about useless `public` in `open` statements. -- {-# OPTIONS -v scope.decl:70 #-} -- Warning #1 open import Agda.Builtin.Nat public import Agda.Builtin.Bool as B -- Warning #2 open B public module _ where open import Agda.Builtin.Equality public -- no warning -- Warning #3 test-let : Set₁ test-let = let open B public in Set -- Warning #4 test-letm : Set₁ test-letm = let open module C = B public in Set
{ "alphanum_fraction": 0.6951754386, "avg_line_length": 18.24, "ext": "agda", "hexsha": "f98ced2033a84cfc3c44ae04bc0bed66ea0260c0", "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/Issue2377.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/Issue2377.agda", "max_line_length": 54, "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/Issue2377.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": 142, "size": 456 }
-- Minimal implicational logic, de Bruijn approach, final encoding module Bf.ArrMp where open import Lib using (List; _,_; LMem; lzero; lsuc) -- Types infixr 0 _=>_ data Ty : Set where UNIT : Ty _=>_ : Ty -> Ty -> Ty -- Context and truth judgement Cx : Set Cx = List Ty isTrue : Ty -> Cx -> Set isTrue a tc = LMem a tc -- Terms TmRepr : Set1 TmRepr = Cx -> Ty -> Set module ArrMp where record Tm (tr : TmRepr) : Set1 where infixl 1 _$_ infixr 0 lam=>_ field var : forall {tc a} -> isTrue a tc -> tr tc a lam=>_ : forall {tc a b} -> tr (tc , a) b -> tr tc (a => b) _$_ : forall {tc a b} -> tr tc (a => b) -> tr tc a -> tr tc b v0 : forall {tc a} -> tr (tc , a) a v0 = var lzero v1 : forall {tc a b} -> tr (tc , a , b) a v1 = var (lsuc lzero) v2 : forall {tc a b c} -> tr (tc , a , b , c) a v2 = var (lsuc (lsuc lzero)) open Tm {{...}} public Thm : Ty -> Set1 Thm a = forall {tr tc} {{_ : Tm tr}} -> tr tc a open ArrMp public -- Example theorems aI : forall {a} -> Thm (a => a) aI = lam=> v0 aK : forall {a b} -> Thm (a => b => a) aK = lam=> lam=> v1 aS : forall {a b c} -> Thm ((a => b => c) => (a => b) => a => c) aS = lam=> lam=> lam=> v2 $ v0 $ (v1 $ v0) tSKK : forall {a} -> Thm (a => a) tSKK {a = a} = aS {b = a => a} $ aK $ aK
{ "alphanum_fraction": 0.4996342356, "avg_line_length": 18.472972973, "ext": "agda", "hexsha": "5356301331aa523980e0be87ef0ded463f398ff1", "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": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/formal-logic", "max_forks_repo_path": "src/Bf/ArrMp.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/formal-logic", "max_issues_repo_path": "src/Bf/ArrMp.agda", "max_line_length": 70, "max_stars_count": 26, "max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/formal-logic", "max_stars_repo_path": "src/Bf/ArrMp.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z", "num_tokens": 552, "size": 1367 }
{-# OPTIONS --universe-polymorphism --allow-unsolved-metas #-} module Issue209 where postulate Level : Set zero : Level suc : Level → Level _⊔_ : Level -> Level -> Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} {-# BUILTIN LEVELMAX _⊔_ #-} data _≡_ {a} {A : Set a} (x : A) : A → Set where refl : x ≡ x data _≅_ {a} {A : Set a} (x : A) : ∀ {b} {B : Set b} → B → Set where refl : x ≅ x subst : ∀ {a p} {A : Set a} (P : A → Set p) {x y} → x ≡ y → P x → P y subst P refl p = p lemma : ∀ {A} (P : A → Set) {x y} (eq : x ≡ y) z → subst P eq z ≅ z lemma P refl z = refl -- An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/Telescope.hs:51 -- The problematic call to reorderTel is -- reorderTel tel3 -- in Agda.TypeChecking.Rules.LHS.Instantiate.
{ "alphanum_fraction": 0.5871766029, "avg_line_length": 26.1470588235, "ext": "agda", "hexsha": "bff931cd27d9941f9b80f3673dec9534c5aa50bf", "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/Issue209.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/Issue209.agda", "max_line_length": 69, "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/Issue209.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": 320, "size": 889 }
-- Andreas, 2016-02-11, bug reported by sanzhiyan module Issue610-module where import Common.Level open import Common.Equality data ⊥ : Set where record ⊤ : Set where data A : Set₁ where set : .Set → A module M .(x : Set) where .out : Set out = x .ack : A → Set ack (set x) = M.out x hah : set ⊤ ≡ set ⊥ hah = refl -- SHOULD FAIL .moo' : ⊥ moo' = subst (λ x → x) (cong ack hah) _ -- SHOULD FAIL .moo : ⊥ moo with cong ack hah moo | q = subst (λ x → x) q _ baa : .⊥ → ⊥ baa () yoink : ⊥ yoink = baa moo
{ "alphanum_fraction": 0.6, "avg_line_length": 13.3333333333, "ext": "agda", "hexsha": "12e684f3fff7f439754eb17c8abe02355c5b65d7", "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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Fail/Issue610-module.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/Issue610-module.agda", "max_line_length": 49, "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/Issue610-module.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": 208, "size": 520 }
module _ where open import Agda.Builtin.String _&_ = primStringAppend record Show (A : Set) : Set where field show : A → String open Show {{...}} public data Bin : Set where [] : Bin 0:_ : Bin → Bin 1:_ : Bin → Bin five : Bin five = 1: 0: 1: [] instance ShowBin : Show Bin show {{ShowBin}} [] = "" show {{ShowBin}} (0: b) = "0" & show b show {{ShowBin}} (1: b) = "1" & show b hole : Bin → Bin hole x = {!!}
{ "alphanum_fraction": 0.5560640732, "avg_line_length": 14.5666666667, "ext": "agda", "hexsha": "42a8232194ca933e004893adf5d1f9e174d5c79c", "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/interaction/ComputeUsingShowInstance.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/interaction/ComputeUsingShowInstance.agda", "max_line_length": 40, "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/interaction/ComputeUsingShowInstance.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": 161, "size": 437 }
{-# OPTIONS --cubical --safe #-} module Data.List.Sort where open import Data.List.Sort.InsertionSort using (insert-sort; sort-sorts; sort-perm; perm-invar) open import Data.List.Sort.MergeSort using (merge-sort; merge≡insert-sort)
{ "alphanum_fraction": 0.7531914894, "avg_line_length": 29.375, "ext": "agda", "hexsha": "67abc23734adeff3c2d1163f2f905750752198df", "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/Sort.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/Sort.agda", "max_line_length": 95, "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/Sort.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": 58, "size": 235 }
------------------------------------------------------------------------ -- Queue instances for the queues in Queue.Quotiented ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} import Equality.Path as P open import Prelude import Queue module Queue.Quotiented.Instances {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) (open P.Derived-definitions-and-properties eq) {Q : ∀ {ℓ} → Type ℓ → Type ℓ} ⦃ is-queue : ∀ {ℓ} → Queue.Is-queue equality-with-J Q (λ _ → ↑ _ ⊤) ℓ ⦄ ⦃ is-queue-with-map : ∀ {ℓ₁ ℓ₂} → Queue.Is-queue-with-map equality-with-J Q ℓ₁ ℓ₂ ⦄ where open Queue equality-with-J open import Queue.Quotiented eq as Q using (Queue) open import Bijection equality-with-J using (_↔_) open import H-level.Closure equality-with-J open import List equality-with-J as L hiding (map) open import Maybe equality-with-J open import Monad equality-with-J hiding (map) private variable a ℓ ℓ₁ ℓ₂ : Level A : Type a xs : List A instance -- Instances. Queue-is-queue : Is-queue (Queue Q) Is-set ℓ Queue-is-queue .Is-queue.to-List = Q.to-List Queue-is-queue .Is-queue.from-List = Q.from-List Queue-is-queue .Is-queue.to-List-from-List = Q.to-List-from-List Queue-is-queue .Is-queue.enqueue = Q.enqueue Queue-is-queue .Is-queue.to-List-enqueue = Q.to-List-enqueue Queue-is-queue .Is-queue.dequeue = Q.dequeue Queue-is-queue .Is-queue.to-List-dequeue = Q.to-List-dequeue Queue-is-queue .Is-queue.dequeue⁻¹ = Q.dequeue⁻¹ Queue-is-queue .Is-queue.to-List-dequeue⁻¹ = Q.to-List-dequeue⁻¹ Queue-is-queue-with-map : Is-queue-with-map (Queue Q) ℓ₁ ℓ₂ Queue-is-queue-with-map .Is-queue-with-map.map = Q.map Queue-is-queue-with-map .Is-queue-with-map.to-List-map = Q.to-List-map Queue-is-queue-with-unique-representations : Is-queue-with-unique-representations (Queue Q) ℓ Queue-is-queue-with-unique-representations .Is-queue-with-unique-representations.from-List-to-List = Q.from-List-to-List _ ------------------------------------------------------------------------ -- Some examples private ⌊_⌋ = to-List (λ {_ _} → ℕ-set) dequeue′ = dequeue (λ {_ _} → ℕ-set) empty′ = empty ⦂ Queue Q ℕ example₁ : map suc (enqueue 3 empty) ≡ enqueue 4 empty′ example₁ = _↔_.to ≡-for-lists↔≡ ( ⌊ map suc (enqueue 3 empty) ⌋ ≡⟨ to-List-map ⟩ L.map suc ⌊ enqueue 3 empty ⌋ ≡⟨ cong (L.map suc) $ to-List-foldl-enqueue-empty (_ ∷ []) ⟩ L.map suc (3 ∷ []) ≡⟨⟩ 4 ∷ [] ≡⟨ sym $ to-List-foldl-enqueue-empty (_ ∷ []) ⟩∎ ⌊ enqueue 4 empty ⌋ ∎) example₂ : dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) ≡ just (10 , enqueue 6 empty) example₂ = dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) ≡⟨ cong dequeue′ lemma ⟩ dequeue′ (cons 10 (enqueue 6 empty)) ≡⟨ _↔_.right-inverse-of (Queue↔Maybe[×Queue] _) _ ⟩∎ just (10 , enqueue 6 empty) ∎ where lemma = _↔_.to ≡-for-lists↔≡ ( ⌊ map (_* 2) (enqueue 3 (enqueue 5 empty)) ⌋ ≡⟨ to-List-map ⟩ L.map (_* 2) ⌊ enqueue 3 (enqueue 5 empty) ⌋ ≡⟨ cong (L.map (_* 2)) $ to-List-foldl-enqueue-empty (_ ∷ _ ∷ []) ⟩ L.map (_* 2) (5 ∷ 3 ∷ []) ≡⟨⟩ 10 ∷ 6 ∷ [] ≡⟨ cong (10 ∷_) $ sym $ to-List-foldl-enqueue-empty (_ ∷ []) ⟩ 10 ∷ ⌊ enqueue 6 empty ⌋ ≡⟨ sym $ to-List-cons ⟩∎ ⌊ cons 10 (enqueue 6 empty) ⌋ ∎) example₃ : (do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) return (enqueue (3 * x) q)) ≡ just (enqueue 30 (enqueue 6 empty)) example₃ = (do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) return (enqueue (3 * x) q)) ≡⟨ cong (_>>= λ _ → return (enqueue _ _)) example₂ ⟩ (do x , q ← just (10 , enqueue 6 empty) return (enqueue (3 * x) (q ⦂ Queue Q ℕ))) ≡⟨⟩ just (enqueue 30 (enqueue 6 empty)) ∎ example₄ : (do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) let q = enqueue (3 * x) q return ⌊ q ⌋) ≡ just (6 ∷ 30 ∷ []) example₄ = (do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) let q = enqueue (3 * x) q return ⌊ q ⌋) ≡⟨ cong (_>>= λ _ → return ⌊ enqueue _ _ ⌋) example₂ ⟩ (do x , q ← just (10 , enqueue 6 empty) let q = enqueue (3 * x) (q ⦂ Queue Q ℕ) return ⌊ q ⌋) ≡⟨⟩ just ⌊ enqueue 30 (enqueue 6 empty) ⌋ ≡⟨ cong just $ to-List-foldl-enqueue-empty (_ ∷ _ ∷ []) ⟩∎ just (6 ∷ 30 ∷ []) ∎ example₅ : ∀ {xs} → dequeue′ (from-List (1 ∷ 2 ∷ 3 ∷ xs)) ≡ just (1 , from-List (2 ∷ 3 ∷ xs)) example₅ {xs = xs} = dequeue′ (from-List (1 ∷ 2 ∷ 3 ∷ xs)) ≡⟨ cong dequeue′ lemma ⟩ dequeue′ (cons 1 (from-List (2 ∷ 3 ∷ xs))) ≡⟨ _↔_.right-inverse-of (Queue↔Maybe[×Queue] _) _ ⟩∎ just (1 , from-List (2 ∷ 3 ∷ xs)) ∎ where lemma = _↔_.to ≡-for-lists↔≡ ( ⌊ from-List (1 ∷ 2 ∷ 3 ∷ xs) ⌋ ≡⟨ _↔_.right-inverse-of (Queue↔List _) _ ⟩ 1 ∷ 2 ∷ 3 ∷ xs ≡⟨ cong (1 ∷_) $ sym $ _↔_.right-inverse-of (Queue↔List _) _ ⟩ 1 ∷ ⌊ from-List (2 ∷ 3 ∷ xs) ⌋ ≡⟨ sym to-List-cons ⟩∎ ⌊ cons 1 (from-List (2 ∷ 3 ∷ xs)) ⌋ ∎) example₆ : foldr enqueue empty′ (3 ∷ 2 ∷ 1 ∷ []) ≡ from-List (1 ∷ 2 ∷ 3 ∷ []) example₆ = sym $ from-List≡foldl-enqueue-empty (λ {_ _} → ℕ-set)
{ "alphanum_fraction": 0.5024088094, "avg_line_length": 39.8082191781, "ext": "agda", "hexsha": "771e8388d5ebb55a00ce469a0847bca91e647b9f", "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/Quotiented/Instances.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/Quotiented/Instances.agda", "max_line_length": 127, "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/Quotiented/Instances.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": 2075, "size": 5812 }
postulate __ : Set
{ "alphanum_fraction": 0.6666666667, "avg_line_length": 7, "ext": "agda", "hexsha": "b79485f782f515789789a1da8a0fda1f8469ff04", "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/Consecutive-underscores.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/Consecutive-underscores.agda", "max_line_length": 10, "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/Consecutive-underscores.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": 8, "size": 21 }
{-# OPTIONS --cubical #-} module Multidimensional.Data.NNat.Properties where open import Cubical.Core.Glue open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Foundations.Isomorphism open import Cubical.Data.Nat open import Cubical.Data.Prod open import Cubical.Data.Empty open import Cubical.Relation.Nullary open import Multidimensional.Data.Extra.Nat open import Multidimensional.Data.Dir open import Multidimensional.Data.DirNum open import Multidimensional.Data.NNat.Base -- N→ℕsucN : (r : ℕ) (x : N r) → N→ℕ r (sucN x) ≡ suc (N→ℕ r x) -- N→ℕsucN zero (bn tt) = refl -- N→ℕsucN zero (xr tt x) = -- suc (N→ℕ zero (sucN x)) -- ≡⟨ cong suc (N→ℕsucN zero x) ⟩ -- suc (suc (N→ℕ zero x)) -- ∎ -- N→ℕsucN (suc r) (bn (↓ , d)) = refl -- N→ℕsucN (suc r) (bn (↑ , d)) with max? d -- ... | no d≠max = -- doubleℕ (DirNum→ℕ (next d)) -- ≡⟨ cong doubleℕ (next≡suc r d d≠max) ⟩ -- doubleℕ (suc (DirNum→ℕ d)) -- ∎ -- ... | yes d≡max = -- this can probably be shortened by not reducing down to zero -- sucn (doubleℕ (DirNum→ℕ (zero-n r))) -- (doublesℕ r (suc (suc (doubleℕ (doubleℕ (DirNum→ℕ (zero-n r))))))) -- ≡⟨ cong (λ x → sucn (doubleℕ x) (doublesℕ r (suc (suc (doubleℕ (doubleℕ x)))))) (zero-n→0 {r}) ⟩ -- sucn (doubleℕ zero) (doublesℕ r (suc (suc (doubleℕ (doubleℕ zero))))) -- ≡⟨ refl ⟩ -- doublesℕ (suc r) (suc zero) -- 2^(r+1) -- ≡⟨ sym (doubleDoubles r 1) ⟩ -- doubleℕ (doublesℕ r (suc zero)) --2*2^r -- ≡⟨ sym (sucPred (doubleℕ (doublesℕ r (suc zero))) (doubleDoublesOne≠0 r)) ⟩ -- suc (predℕ (doubleℕ (doublesℕ r (suc zero)))) -- ≡⟨ cong suc (sym (sucPred (predℕ (doubleℕ (doublesℕ r (suc zero)))) (predDoubleDoublesOne≠0 r))) ⟩ -- suc (suc (predℕ (predℕ (doubleℕ (doublesℕ r (suc zero)))))) -- ≡⟨ cong (λ x → suc (suc x)) (sym (doublePred (doublesℕ r (suc zero)))) ⟩ -- suc (suc (doubleℕ (predℕ (doublesℕ r (suc zero))))) -- ≡⟨ cong (λ x → suc (suc (doubleℕ x))) (sym (maxr≡pred2ʳ r d d≡max)) ⟩ -- suc (suc (doubleℕ (DirNum→ℕ d))) -- 2*(2^r - 1) + 2 = 2^(r+1) - 2 + 2 = 2^(r+1) -- ∎ -- N→ℕsucN (suc r) (xr (↓ , d) x) = refl -- N→ℕsucN (suc r) (xr (↑ , d) x) with max? d -- ... | no d≠max = -- sucn (doubleℕ (DirNum→ℕ (next d))) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))) -- ≡⟨ cong (λ y → sucn (doubleℕ y) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))) (next≡suc r d d≠max) ⟩ -- sucn (doubleℕ (suc (DirNum→ℕ d))) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))) -- ≡⟨ refl ⟩ -- suc -- (suc -- (iter (doubleℕ (DirNum→ℕ d)) suc -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ∎ -- ... | yes d≡max = -- sucn (doubleℕ (DirNum→ℕ (zero-n r))) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x)))) -- ≡⟨ cong (λ z → sucn (doubleℕ z) (doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x))))) (zero-n≡0 {r}) ⟩ -- sucn (doubleℕ zero) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x)))) -- ≡⟨ refl ⟩ -- doublesℕ r (doubleℕ (N→ℕ (suc r) (sucN x))) -- ≡⟨ cong (λ x → doublesℕ r (doubleℕ x)) (N→ℕsucN (suc r) x) ⟩ -- doublesℕ r (doubleℕ (suc (N→ℕ (suc r) x))) -- ≡⟨ refl ⟩ -- doublesℕ r (suc (suc (doubleℕ (N→ℕ (suc r) x)))) -- 2^r * (2x + 2) = 2^(r+1)x + 2^(r+1) -- ≡⟨ doublesSucSuc r (doubleℕ (N→ℕ (suc r) x)) ⟩ -- sucn (doublesℕ (suc r) 1) -- _ + 2^(r+1) -- (doublesℕ (suc r) (N→ℕ (suc r) x)) -- 2^(r+1)x + 2^(r+1) -- ≡⟨ H r (doublesℕ (suc r) (N→ℕ (suc r) x)) ⟩ -- suc -- (suc -- (sucn (doubleℕ (predℕ (doublesℕ r 1))) -- _ + 2(2^r - 1) + 2 -- (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ≡⟨ refl ⟩ -- suc -- (suc -- (sucn (doubleℕ (predℕ (doublesℕ r 1))) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ≡⟨ cong (λ z → suc (suc (sucn (doubleℕ z) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))) (sym (max→ℕ r)) ⟩ -- suc -- (suc -- (sucn (doubleℕ (DirNum→ℕ (max-n r))) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ≡⟨ cong (λ z → suc (suc (sucn (doubleℕ (DirNum→ℕ z)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))))) (sym (d≡max)) ⟩ -- suc -- (suc -- (sucn (doubleℕ (DirNum→ℕ d)) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- (2^r*2x + (2*(2^r - 1))) + 2 = 2^(r+1)x + 2^(r+1) -- ∎ -- where -- H : (n m : ℕ) → sucn (doublesℕ (suc n) 1) m ≡ suc (suc (sucn (doubleℕ (predℕ (doublesℕ n 1))) m)) -- H zero m = refl -- H (suc n) m = -- sucn (doublesℕ n 4) m -- ≡⟨ cong (λ z → sucn z m) (doublesSucSuc n 2) ⟩ -- sucn (sucn (doublesℕ (suc n) 1) (doublesℕ n 2)) m -- ≡⟨ refl ⟩ -- sucn (sucn (doublesℕ n 2) (doublesℕ n 2)) m -- ≡⟨ {!!} ⟩ -- sucn (doubleℕ (doublesℕ n 2)) m -- ≡⟨ {!!} ⟩ {!!} -- ℕ→Nsuc : (r : ℕ) (n : ℕ) → ℕ→N r (suc n) ≡ sucN (ℕ→N r n) -- ℕ→Nsuc r n = {!!} -- ℕ→Nsucn : (r : ℕ) (n m : ℕ) → ℕ→N r (sucn n m) ≡ sucnN n (ℕ→N r m) -- ℕ→Nsucn r n m = {!!} -- NℕNlemma : (r : ℕ) (d : DirNum r) → ℕ→N r (DirNum→ℕ d) ≡ bn d -- NℕNlemma zero tt = refl -- NℕNlemma (suc r) (↓ , ds) = -- ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds)) -- ≡⟨ {!!} ⟩ {!!} -- NℕNlemma (suc r) (↑ , ds) = {!!} -- N→ℕ→N : (r : ℕ) → (x : N r) → ℕ→N r (N→ℕ r x) ≡ x -- N→ℕ→N zero (bn tt) = refl -- N→ℕ→N zero (xr tt x) = cong (xr tt) (N→ℕ→N zero x) -- N→ℕ→N (suc r) (bn (↓ , ds)) = -- ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds)) -- ≡⟨ cong (λ x → ℕ→N (suc r) x) (double-lemma ds) ⟩ -- ℕ→N (suc r) (DirNum→ℕ {suc r} (↓ , ds)) -- ≡⟨ NℕNlemma (suc r) (↓ , ds) ⟩ -- bn (↓ , ds) -- ∎ -- N→ℕ→N (suc r) (bn (↑ , ds)) = -- sucN (ℕ→N (suc r) (doubleℕ (DirNum→ℕ ds))) -- ≡⟨ cong (λ x → sucN (ℕ→N (suc r) x)) (double-lemma ds) ⟩ -- sucN (ℕ→N (suc r) (DirNum→ℕ {suc r} (↓ , ds))) -- ≡⟨ cong sucN (NℕNlemma (suc r) (↓ , ds)) ⟩ -- sucN (bn (↓ , ds)) -- ≡⟨ refl ⟩ -- bn (↑ , ds) -- ∎ -- N→ℕ→N (suc r) (xr (↓ , ds) x) = -- ℕ→N (suc r) -- (sucn (doubleℕ (DirNum→ℕ ds)) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))) -- ≡⟨ cong (λ z → ℕ→N (suc r) (sucn z (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) (double-lemma ds) ⟩ -- ℕ→N (suc r) -- (sucn (DirNum→ℕ {suc r} (↓ , ds)) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x)))) -- ≡⟨ refl ⟩ -- ℕ→N (suc r) -- (sucn (DirNum→ℕ {suc r} (↓ , ds)) -- (doublesℕ (suc r) (N→ℕ (suc r) x))) -- ≡⟨ ℕ→Nsucn (suc r) (DirNum→ℕ {suc r} (↓ , ds)) (doublesℕ (suc r) (N→ℕ (suc r) x)) ⟩ -- sucnN (DirNum→ℕ {suc r} (↓ , ds)) -- (ℕ→N (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x))) -- ≡⟨ cong (λ z → sucnN (DirNum→ℕ {suc r} (↓ , ds)) z) (H (suc r) (suc r) (N→ℕ (suc r) x)) ⟩ -- sucnN (DirNum→ℕ {suc r} (↓ , ds)) -- (doublesN (suc r) (suc r) (ℕ→N (suc r) (N→ℕ (suc r) x))) -- ≡⟨ cong (λ z → sucnN (DirNum→ℕ {suc r} (↓ , ds)) (doublesN (suc r) (suc r) z)) (N→ℕ→N (suc r) x) ⟩ -- sucnN (DirNum→ℕ {suc r} (↓ , ds)) -- (doublesN (suc r) (suc r) x) -- ≡⟨ G (suc r) (↓ , ds) x snotz ⟩ -- xr (↓ , ds) x ∎ -- where -- H : (r m n : ℕ) → ℕ→N r (doublesℕ m n) ≡ doublesN r m (ℕ→N r n) -- H r m n = {!!} -- G : (r : ℕ) (d : DirNum r) (x : N r) → ¬ (r ≡ 0) → sucnN (DirNum→ℕ {r} d) (doublesN r r x) ≡ xr d x -- G zero d x 0≠0 = ⊥-elim (0≠0 refl) -- G (suc r) d (bn x) r≠0 = {!!} -- G (suc r) d (xr x x₁) r≠0 = {!!} -- N→ℕ→N (suc r) (xr (↑ , ds) x) with max? ds -- ... | no ds≠max = -- sucN -- (ℕ→N (suc r) -- (sucn (doubleℕ (DirNum→ℕ ds)) -- (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ≡⟨ sym (ℕ→Nsuc (suc r) -- (sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ⟩ -- ℕ→N (suc r) -- (suc (sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ r (doubleℕ (N→ℕ (suc r) x))))) -- ≡⟨ refl ⟩ -- ℕ→N (suc r) -- (suc (sucn (doubleℕ (DirNum→ℕ ds)) (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ≡⟨ cong (λ z → ℕ→N (suc r) z) -- (sym (sucnsuc (doubleℕ (DirNum→ℕ ds)) (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ⟩ -- ℕ→N (suc r) -- (sucn (doubleℕ (DirNum→ℕ ds)) (suc (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ≡⟨ ℕ→Nsucn (suc r) (doubleℕ (DirNum→ℕ ds)) (suc (doublesℕ (suc r) (N→ℕ (suc r) x))) ⟩ -- sucnN (doubleℕ (DirNum→ℕ ds)) (ℕ→N (suc r) (suc (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ≡⟨ cong (λ z → sucnN (doubleℕ (DirNum→ℕ ds)) z) -- (ℕ→Nsuc (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x))) -- ⟩ -- -- (2^(r+1)*x + 1) + 2*ds -- -- = 2*(2^r*x + ds) + 1 -- -- = 2*( -- sucnN (doubleℕ (DirNum→ℕ ds)) (sucN (ℕ→N (suc r) (doublesℕ (suc r) (N→ℕ (suc r) x)))) -- ≡⟨ {!!} ⟩ {!!} -- ... | yes ds≡max = {!!} -- ℕ→N→ℕ : (r : ℕ) → (n : ℕ) → N→ℕ r (ℕ→N r n) ≡ n -- ℕ→N→ℕ zero zero = refl -- ℕ→N→ℕ (suc r) zero = -- doubleℕ (DirNum→ℕ (zero-n r)) -- ≡⟨ cong doubleℕ (zero-n≡0 {r}) ⟩ -- doubleℕ zero -- ≡⟨ refl ⟩ -- zero -- ∎ -- ℕ→N→ℕ zero (suc n) = cong suc (ℕ→N→ℕ zero n) -- ℕ→N→ℕ (suc r) (suc n) = -- N→ℕ (suc r) (sucN (ℕ→N (suc r) n)) -- ≡⟨ N→ℕsucN (suc r) (ℕ→N (suc r) n) ⟩ -- suc (N→ℕ (suc r) (ℕ→N (suc r) n)) -- ≡⟨ cong suc (ℕ→N→ℕ (suc r) n) ⟩ -- suc n -- ∎ -- N≃ℕ : (r : ℕ) → N r ≃ ℕ -- N≃ℕ r = isoToEquiv (iso (N→ℕ r) (ℕ→N r) (ℕ→N→ℕ r) (N→ℕ→N r)) -- N≡ℕ : (r : ℕ) → N r ≡ ℕ -- N≡ℕ r = ua (N≃ℕ r)
{ "alphanum_fraction": 0.4475773616, "avg_line_length": 41.9829059829, "ext": "agda", "hexsha": "dcf41a7e31422eb16415bbf9054dd3e418092921", "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/NNat/Properties.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/NNat/Properties.agda", "max_line_length": 119, "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/NNat/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4802, "size": 9824 }
open import Data.Empty using (⊥-elim) open import Data.Fin using (Fin; _≟_) open import Data.Nat using (ℕ) open import Data.Vec using (lookup; _[_]≔_) open import Data.Vec.Properties using (lookup∘update; lookup∘update′; []≔-commutes; []≔-idempotent; []≔-lookup) open import Relation.Nullary using (yes; no; ¬_) open import Relation.Binary.PropositionalEquality using (sym; trans; _≡_; refl; cong; _≢_; module ≡-Reasoning) open import Data.Product using (∃-syntax; _,_; proj₁; proj₂; _×_) open ≡-Reasoning open import Common open import Global open import Local open import Projection soundness : ∀ { n : ℕ } { act : Action n } { c g g′ } -> g ↔ c -> g - act →g g′ -> ∃[ c′ ] c - act →c c′ × g′ ↔ c′ soundness {n = n} {act = act@(action .p .q p≢q .l)} {c = c} {g = g@(msgSingle p q p≢q-gt l g′)} {g′ = .g′} assoc →g-prefix = c′ , (→c-comm c p≢q refl refl refl lpReduce lqReduce , g′↔c′) where config-without-prefix = config-gt-remove-prefix g c assoc refl c′ = proj₁ config-without-prefix g′↔c′ : g′ ↔ c′ g′↔c′ = proj₂ (proj₂ config-without-prefix) lpReduce : (p , lookup c p) - act →l (p , project g′ p) lpReduce rewrite _↔_.isProj assoc p = →l-send p (proj-prefix-send p q g′ p≢q-gt) p≢q lqReduce : (q , lookup c q) - act →l (q , project g′ q) lqReduce rewrite _↔_.isProj assoc q = →l-recv q (proj-prefix-recv p q g′ p≢q-gt) p≢q soundness {n = n} {act = act@(.action p q p≢q l)} {c = c} {g = g@(msgSingle r s r≢s l′ gSub)} {g′ = g′@(.msgSingle r s r≢s l′ gSub′)} assoc (→g-cont gReduce p≢r q≢r p≢s q≢s) = c′ , cReduce , assoc′ where config-without-prefix = config-gt-remove-prefix g c assoc refl cSub = proj₁ config-without-prefix gSub↔cSub : gSub ↔ cSub gSub↔cSub = proj₂ (proj₂ config-without-prefix) soundness-gSub : ∃[ cSub′ ] cSub - act →c cSub′ × gSub′ ↔ cSub′ soundness-gSub = soundness gSub↔cSub gReduce c′ : Configuration n c′ with soundness-gSub ... | cSub′ , _ , _ = (cSub′ [ r ]≔ lr′) [ s ]≔ ls′ where lr′ : Local n lr′ with soundness-gSub ... | cSub′ , _ , _ = sendSingle s l′ (lookup cSub′ r) ls′ : Local n ls′ with soundness-gSub ... | cSub′ , _ , _ = recvSingle r l′ (lookup cSub′ s) isProj-g′ : ∀(t : Fin n) -> lookup c′ t ≡ project g′ t isProj-g′ t with soundness-gSub ... | cSub′ , _ , gSub′↔cSub′ with r ≟ t | s ≟ t ... | yes r≡t | no _ rewrite sym r≡t rewrite lookup∘update′ r≢s (cSub′ [ r ]≔ sendSingle s l′ (lookup cSub′ r)) (recvSingle r l′ (lookup cSub′ s)) rewrite lookup∘update r cSub′ (sendSingle s l′ (lookup cSub′ r)) rewrite _↔_.isProj gSub′↔cSub′ r = refl ... | no _ | yes s≡t rewrite sym s≡t rewrite lookup∘update s (cSub′ [ r ]≔ sendSingle s l′ (lookup cSub′ r)) (recvSingle r l′ (lookup cSub′ s)) rewrite _↔_.isProj gSub′↔cSub′ s = refl ... | no r≢t | no s≢t rewrite lookup∘update′ (¬≡-flip s≢t) (cSub′ [ r ]≔ sendSingle s l′ (lookup cSub′ r)) (recvSingle r l′ (lookup cSub′ s)) rewrite lookup∘update′ (¬≡-flip r≢t) cSub′ (sendSingle s l′ (lookup cSub′ r)) rewrite _↔_.isProj gSub′↔cSub′ t = refl ... | yes refl | yes refl = ⊥-elim (r≢s refl) assoc′ : g′ ↔ c′ assoc′ = record { isProj = isProj-g′ } cReduce : c - act →c c′ cReduce with soundness-gSub ... | cSub′ , →c-comm {lp = lp} {lp′ = lp′} {lq = lq} {lq′ = lq′} .cSub .p≢q refl refl refl lpReduce lqReduce , gSub′↔cSub′ = →c-comm c p≢q lp≡c[p] lq≡c[q] c→c′ lpReduce lqReduce where lr′ = sendSingle s l′ (lookup cSub′ r) ls′ = recvSingle r l′ (lookup cSub′ s) lp≡c[p] : lp ≡ lookup c p lp≡c[p] rewrite lookup∘update′ p≢s (c [ r ]≔ project gSub r) (project gSub s) rewrite lookup∘update′ p≢r c (project gSub r) = refl lq≡c[q] : lq ≡ lookup c q lq≡c[q] rewrite lookup∘update′ q≢s (c [ r ]≔ project gSub r) (project gSub s) rewrite lookup∘update′ q≢r c (project gSub r) = refl lr′≡c[r] : lr′ ≡ lookup c r lr′≡c[r] rewrite lookup∘update′ (¬≡-flip q≢r) (cSub [ p ]≔ lp′) lq′ rewrite lookup∘update′ (¬≡-flip p≢r) cSub lp′ rewrite _↔_.isProj assoc r rewrite proj-prefix-send {l = l′} r s gSub r≢s rewrite lookup∘update′ r≢s (c [ r ]≔ project gSub r) (project gSub s) rewrite lookup∘update r c (project gSub r) = refl ls′≡c[s] : ls′ ≡ lookup c s ls′≡c[s] rewrite lookup∘update′ (¬≡-flip q≢s) (cSub [ p ]≔ lp′) lq′ rewrite lookup∘update′ (¬≡-flip p≢s) cSub lp′ rewrite _↔_.isProj assoc s rewrite proj-prefix-recv {l = l′} r s gSub r≢s rewrite lookup∘update s (c [ r ]≔ project gSub r) (project gSub s) = refl c→c′ : (cSub′ [ r ]≔ lr′) [ s ]≔ ls′ ≡ (c [ p ]≔ lp′) [ q ]≔ lq′ c→c′ rewrite []≔-commutes ((((c [ r ]≔ project gSub r) [ s ]≔ project gSub s) [ p ]≔ lp′) [ q ]≔ lq′) r s {lr′} {ls′} r≢s rewrite []≔-commutes (((c [ r ]≔ project gSub r) [ s ]≔ project gSub s) [ p ]≔ lp′) q s {lq′} {ls′} q≢s rewrite []≔-commutes ((c [ r ]≔ project gSub r) [ s ]≔ project gSub s) p s {lp′} {ls′} p≢s rewrite []≔-idempotent (c [ r ]≔ project gSub r) s {project gSub s} {ls′} rewrite []≔-commutes (((c [ r ]≔ project gSub r) [ s ]≔ ls′) [ p ]≔ lp′) q r {lq′} {lr′} q≢r rewrite []≔-commutes ((c [ r ]≔ project gSub r) [ s ]≔ ls′) p r {lp′} {lr′} p≢r rewrite []≔-commutes (c [ r ]≔ project gSub r) s r {ls′} {lr′} (¬≡-flip r≢s) rewrite []≔-idempotent c r {project gSub r} {lr′} rewrite lr′≡c[r] rewrite ls′≡c[s] rewrite []≔-lookup c r rewrite []≔-lookup c s = refl
{ "alphanum_fraction": 0.5396501953, "avg_line_length": 43.947761194, "ext": "agda", "hexsha": "88b6dd92ce66171c270a3f269aef3f3da2ffdc34", "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": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "fangyi-zhou/mpst-in-agda", "max_forks_repo_path": "Soundness.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_issues_repo_issues_event_max_datetime": "2021-11-24T11:30:17.000Z", "max_issues_repo_issues_event_min_datetime": "2021-08-31T10:15:38.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "fangyi-zhou/mpst-in-agda", "max_issues_repo_path": "Soundness.agda", "max_line_length": 129, "max_stars_count": 1, "max_stars_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "fangyi-zhou/mpst-in-agda", "max_stars_repo_path": "Soundness.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-14T17:36:53.000Z", "max_stars_repo_stars_event_min_datetime": "2021-08-14T17:36:53.000Z", "num_tokens": 2356, "size": 5889 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Indexed AVL trees ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (StrictTotalOrder) module Data.AVL.Indexed {a ℓ₁ ℓ₂} (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂) where open import Level using (_⊔_) open import Data.Nat.Base using (ℕ; zero; suc; _+_) open import Data.Product hiding (map) open import Data.Maybe hiding (map) open import Data.DifferenceList using (DiffList; []; _∷_; _++_) open import Function as F hiding (const) open import Relation.Unary open import Relation.Binary using (_Respects_; Tri; tri<; tri≈; tri>) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open StrictTotalOrder strictTotalOrder renaming (Carrier to Key) ------------------------------------------------------------------------ -- Re-export core definitions publicly open import Data.AVL.Key strictTotalOrder public open import Data.AVL.Value Eq.setoid public open import Data.AVL.Height public ------------------------------------------------------------------------ -- Definitions of the tree K&_ : ∀ {v} (V : Value v) → Set (a ⊔ v) K& V = Σ Key (Value.family V) -- The trees have three parameters/indices: a lower bound on the -- keys, an upper bound, and a height. -- -- (The bal argument is the balance factor.) data Tree {v} (V : Value v) (l u : Key⁺) : ℕ → Set (a ⊔ v ⊔ ℓ₂) where leaf : (l<u : l <⁺ u) → Tree V l u 0 node : ∀ {hˡ hʳ h} (k : K& V) (lk : Tree V l [ proj₁ k ] hˡ) (ku : Tree V [ proj₁ k ] u hʳ) (bal : hˡ ∼ hʳ ⊔ h) → Tree V l u (suc h) module _ {v} {V : Value v} where private Val = Value.family V V≈ = Value.respects V leaf-injective : ∀ {l u} {p q : l <⁺ u} → (Tree V l u 0 ∋ leaf p) ≡ leaf q → p ≡ q leaf-injective refl = refl node-injective-key : ∀ {hˡ₁ hˡ₂ hʳ₁ hʳ₂ h l u k₁ k₂} {lk₁ : Tree V l [ proj₁ k₁ ] hˡ₁} {lk₂ : Tree V l [ proj₁ k₂ ] hˡ₂} {ku₁ : Tree V [ proj₁ k₁ ] u hʳ₁} {ku₂ : Tree V [ proj₁ k₂ ] u hʳ₂} {bal₁ : hˡ₁ ∼ hʳ₁ ⊔ h} {bal₂ : hˡ₂ ∼ hʳ₂ ⊔ h} → node k₁ lk₁ ku₁ bal₁ ≡ node k₂ lk₂ ku₂ bal₂ → k₁ ≡ k₂ node-injective-key refl = refl -- See also node-injectiveˡ, node-injectiveʳ, and node-injective-bal -- in Data.AVL.Indexed.WithK. -- Cast operations. Logarithmic in the size of the tree, if we don't -- count the time needed to construct the new proofs in the leaf -- cases. (The same kind of caveat applies to other operations -- below.) -- -- Perhaps it would be worthwhile changing the data structure so -- that the casts could be implemented in constant time (excluding -- proof manipulation). However, note that this would not change the -- worst-case time complexity of the operations below (up to Θ). castˡ : ∀ {l m u h} → l <⁺ m → Tree V m u h → Tree V l u h castˡ {l} l<m (leaf m<u) = leaf (trans⁺ l l<m m<u) castˡ l<m (node k mk ku bal) = node k (castˡ l<m mk) ku bal castʳ : ∀ {l m u h} → Tree V l m h → m <⁺ u → Tree V l u h castʳ {l} (leaf l<m) m<u = leaf (trans⁺ l l<m m<u) castʳ (node k lk km bal) m<u = node k lk (castʳ km m<u) bal -- Various constant-time functions which construct trees out of -- smaller pieces, sometimes using rotation. joinˡ⁺ : ∀ {l u hˡ hʳ h} → (k : K& V) → (∃ λ i → Tree V l [ proj₁ k ] (i ⊕ hˡ)) → Tree V [ proj₁ k ] u hʳ → (bal : hˡ ∼ hʳ ⊔ h) → ∃ λ i → Tree V l u (i ⊕ (1 + h)) joinˡ⁺ k₆ (1# , node k₂ t₁ (node k₄ t₃ t₅ bal) ∼+) t₇ ∼- = (0# , node k₄ (node k₂ t₁ t₃ (max∼ bal)) (node k₆ t₅ t₇ (∼max bal)) ∼0) joinˡ⁺ k₄ (1# , node k₂ t₁ t₃ ∼-) t₅ ∼- = (0# , node k₂ t₁ (node k₄ t₃ t₅ ∼0) ∼0) joinˡ⁺ k₄ (1# , node k₂ t₁ t₃ ∼0) t₅ ∼- = (1# , node k₂ t₁ (node k₄ t₃ t₅ ∼-) ∼+) joinˡ⁺ k₂ (1# , t₁) t₃ ∼0 = (1# , node k₂ t₁ t₃ ∼-) joinˡ⁺ k₂ (1# , t₁) t₃ ∼+ = (0# , node k₂ t₁ t₃ ∼0) joinˡ⁺ k₂ (0# , t₁) t₃ bal = (0# , node k₂ t₁ t₃ bal) joinˡ⁺ k₂ (## , t₁) t₃ bal joinʳ⁺ : ∀ {l u hˡ hʳ h} → (k : K& V) → Tree V l [ proj₁ k ] hˡ → (∃ λ i → Tree V [ proj₁ k ] u (i ⊕ hʳ)) → (bal : hˡ ∼ hʳ ⊔ h) → ∃ λ i → Tree V l u (i ⊕ (1 + h)) joinʳ⁺ k₂ t₁ (1# , node k₆ (node k₄ t₃ t₅ bal) t₇ ∼-) ∼+ = (0# , node k₄ (node k₂ t₁ t₃ (max∼ bal)) (node k₆ t₅ t₇ (∼max bal)) ∼0) joinʳ⁺ k₂ t₁ (1# , node k₄ t₃ t₅ ∼+) ∼+ = (0# , node k₄ (node k₂ t₁ t₃ ∼0) t₅ ∼0) joinʳ⁺ k₂ t₁ (1# , node k₄ t₃ t₅ ∼0) ∼+ = (1# , node k₄ (node k₂ t₁ t₃ ∼+) t₅ ∼-) joinʳ⁺ k₂ t₁ (1# , t₃) ∼0 = (1# , node k₂ t₁ t₃ ∼+) joinʳ⁺ k₂ t₁ (1# , t₃) ∼- = (0# , node k₂ t₁ t₃ ∼0) joinʳ⁺ k₂ t₁ (0# , t₃) bal = (0# , node k₂ t₁ t₃ bal) joinʳ⁺ k₂ t₁ (## , t₃) bal joinˡ⁻ : ∀ {l u} hˡ {hʳ h} → (k : K& V) → (∃ λ i → Tree V l [ proj₁ k ] pred[ i ⊕ hˡ ]) → Tree V [ proj₁ k ] u hʳ → (bal : hˡ ∼ hʳ ⊔ h) → ∃ λ i → Tree V l u (i ⊕ h) joinˡ⁻ zero k₂ (0# , t₁) t₃ bal = (1# , node k₂ t₁ t₃ bal) joinˡ⁻ zero k₂ (1# , t₁) t₃ bal = (1# , node k₂ t₁ t₃ bal) joinˡ⁻ (suc _) k₂ (0# , t₁) t₃ ∼+ = joinʳ⁺ k₂ t₁ (1# , t₃) ∼+ joinˡ⁻ (suc _) k₂ (0# , t₁) t₃ ∼0 = (1# , node k₂ t₁ t₃ ∼+) joinˡ⁻ (suc _) k₂ (0# , t₁) t₃ ∼- = (0# , node k₂ t₁ t₃ ∼0) joinˡ⁻ (suc _) k₂ (1# , t₁) t₃ bal = (1# , node k₂ t₁ t₃ bal) joinˡ⁻ n k₂ (## , t₁) t₃ bal joinʳ⁻ : ∀ {l u hˡ} hʳ {h} → (k : K& V) → Tree V l [ proj₁ k ] hˡ → (∃ λ i → Tree V [ proj₁ k ] u pred[ i ⊕ hʳ ]) → (bal : hˡ ∼ hʳ ⊔ h) → ∃ λ i → Tree V l u (i ⊕ h) joinʳ⁻ zero k₂ t₁ (0# , t₃) bal = (1# , node k₂ t₁ t₃ bal) joinʳ⁻ zero k₂ t₁ (1# , t₃) bal = (1# , node k₂ t₁ t₃ bal) joinʳ⁻ (suc _) k₂ t₁ (0# , t₃) ∼- = joinˡ⁺ k₂ (1# , t₁) t₃ ∼- joinʳ⁻ (suc _) k₂ t₁ (0# , t₃) ∼0 = (1# , node k₂ t₁ t₃ ∼-) joinʳ⁻ (suc _) k₂ t₁ (0# , t₃) ∼+ = (0# , node k₂ t₁ t₃ ∼0) joinʳ⁻ (suc _) k₂ t₁ (1# , t₃) bal = (1# , node k₂ t₁ t₃ bal) joinʳ⁻ n k₂ t₁ (## , t₃) bal -- Extracts the smallest element from the tree, plus the rest. -- Logarithmic in the size of the tree. headTail : ∀ {l u h} → Tree V l u (1 + h) → ∃ λ (k : K& V) → l <⁺ [ proj₁ k ] × ∃ λ i → Tree V [ proj₁ k ] u (i ⊕ h) headTail (node k₁ (leaf l<k₁) t₂ ∼+) = (k₁ , l<k₁ , 0# , t₂) headTail (node k₁ (leaf l<k₁) t₂ ∼0) = (k₁ , l<k₁ , 0# , t₂) headTail (node {hˡ = suc _} k₃ t₁₂ t₄ bal) with headTail t₁₂ ... | (k₁ , l<k₁ , t₂) = (k₁ , l<k₁ , joinˡ⁻ _ k₃ t₂ t₄ bal) -- Extracts the largest element from the tree, plus the rest. -- Logarithmic in the size of the tree. initLast : ∀ {l u h} → Tree V l u (1 + h) → ∃ λ (k : K& V) → [ proj₁ k ] <⁺ u × ∃ λ i → Tree V l [ proj₁ k ] (i ⊕ h) initLast (node k₂ t₁ (leaf k₂<u) ∼-) = (k₂ , k₂<u , (0# , t₁)) initLast (node k₂ t₁ (leaf k₂<u) ∼0) = (k₂ , k₂<u , (0# , t₁)) initLast (node {hʳ = suc _} k₂ t₁ t₃₄ bal) with initLast t₃₄ ... | (k₄ , k₄<u , t₃) = (k₄ , k₄<u , joinʳ⁻ _ k₂ t₁ t₃ bal) -- Another joining function. Logarithmic in the size of either of -- the input trees (which need to have almost equal heights). join : ∀ {l m u hˡ hʳ h} → Tree V l m hˡ → Tree V m u hʳ → (bal : hˡ ∼ hʳ ⊔ h) → ∃ λ i → Tree V l u (i ⊕ h) join t₁ (leaf m<u) ∼0 = (0# , castʳ t₁ m<u) join t₁ (leaf m<u) ∼- = (0# , castʳ t₁ m<u) join {hʳ = suc _} t₁ t₂₃ bal with headTail t₂₃ ... | (k₂ , m<k₂ , t₃) = joinʳ⁻ _ k₂ (castʳ t₁ m<k₂) t₃ bal -- An empty tree. empty : ∀ {l u} → l <⁺ u → Tree V l u 0 empty = leaf -- A singleton tree. singleton : ∀ {l u} (k : Key) → Val k → l < k < u → Tree V l u 1 singleton k v (l<k , k<u) = node (k , v) (leaf l<k) (leaf k<u) ∼0 -- Inserts a key into the tree, using a function to combine any -- existing value with the new value. Logarithmic in the size of the -- tree (assuming constant-time comparisons and a constant-time -- combining function). insertWith : ∀ {l u h} (k : Key) → (Maybe (Val k) → Val k) → -- Maybe old → result. Tree V l u h → l < k < u → ∃ λ i → Tree V l u (i ⊕ h) insertWith k f (leaf l<u) l<k<u = (1# , singleton k (f nothing) l<k<u) insertWith k f (node (k′ , v′) lp pu bal) (l<k , k<u) with compare k k′ ... | tri< k<k′ _ _ = joinˡ⁺ (k′ , v′) (insertWith k f lp (l<k , [ k<k′ ]ᴿ)) pu bal ... | tri> _ _ k′<k = joinʳ⁺ (k′ , v′) lp (insertWith k f pu ([ k′<k ]ᴿ , k<u)) bal ... | tri≈ _ k≈k′ _ = (0# , node (k′ , V≈ k≈k′ (f (just (V≈ (Eq.sym k≈k′) v′)))) lp pu bal) -- Inserts a key into the tree. If the key already exists, then it -- is replaced. Logarithmic in the size of the tree (assuming -- constant-time comparisons). insert : ∀ {l u h} → (k : Key) → Val k → Tree V l u h → l < k < u → ∃ λ i → Tree V l u (i ⊕ h) insert k v = insertWith k (F.const v) -- Deletes the key/value pair containing the given key, if any. -- Logarithmic in the size of the tree (assuming constant-time -- comparisons). delete : ∀ {l u h} (k : Key) → Tree V l u h → l < k < u → ∃ λ i → Tree V l u pred[ i ⊕ h ] delete k (leaf l<u) l<k<u = (0# , leaf l<u) delete k (node p@(k′ , v) lp pu bal) (l<k , k<u) with compare k′ k ... | tri< k′<k _ _ = joinʳ⁻ _ p lp (delete k pu ([ k′<k ]ᴿ , k<u)) bal ... | tri> _ _ k′>k = joinˡ⁻ _ p (delete k lp (l<k , [ k′>k ]ᴿ)) pu bal ... | tri≈ _ k′≡k _ = join lp pu bal -- Looks up a key. Logarithmic in the size of the tree (assuming -- constant-time comparisons). lookup : ∀ {l u h} (k : Key) → Tree V l u h → l < k < u → Maybe (Val k) lookup k (leaf _) l<k<u = nothing lookup k (node (k′ , v) lk′ k′u _) (l<k , k<u) with compare k′ k ... | tri< k′<k _ _ = lookup k k′u ([ k′<k ]ᴿ , k<u) ... | tri> _ _ k′>k = lookup k lk′ (l<k , [ k′>k ]ᴿ) ... | tri≈ _ k′≡k _ = just (V≈ k′≡k v) -- Converts the tree to an ordered list. Linear in the size of the -- tree. toDiffList : ∀ {l u h} → Tree V l u h → DiffList (K& V) toDiffList (leaf _) = [] toDiffList (node k l r _) = toDiffList l ++ k ∷ toDiffList r module _ {v w} {V : Value v} {W : Value w} where private Val = Value.family V Wal = Value.family W -- Maps a function over all values in the tree. map : ∀[ Val ⇒ Wal ] → ∀ {l u h} → Tree V l u h → Tree W l u h map f (leaf l<u) = leaf l<u map f (node (k , v) l r bal) = node (k , f v) (map f l) (map f r) bal
{ "alphanum_fraction": 0.4912706983, "avg_line_length": 41.9320754717, "ext": "agda", "hexsha": "e5d75409b7baa08ba11f5eebc724d5ab9a1054b3", "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/AVL/Indexed.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/AVL/Indexed.agda", "max_line_length": 93, "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/AVL/Indexed.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4528, "size": 11112 }
module Function.Domains where import Lvl open import Structure.Setoid open import Type private variable ℓₒ₁ ℓₒ₂ ℓₑ₁ ℓₑ₂ : Lvl.Level module _ {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where -- The partial domain of a function -- Note: This is the same as the domain because all functions are total (or at least supposed to be) ⊷ : (X → Y) → Type{ℓₒ₁} ⊷ _ = X module _ {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where -- ∃(Unapply f(y)) is also called "the fiber of the element y under the map f". -- Unapply(f) is similar to the inverse image or the preimage of f when their argument is a singleton set. Fiber : ⦃ equiv-Y : Equiv{ℓₑ₂}(Y) ⦄ → (X → Y) → Y → X → Type Fiber f(y) x = (f(x) ≡ y)
{ "alphanum_fraction": 0.6541786744, "avg_line_length": 34.7, "ext": "agda", "hexsha": "e0d1be0c095054e80d49d58e25df2173a765491c", "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/Domains.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/Domains.agda", "max_line_length": 108, "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/Domains.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": 260, "size": 694 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by preorders ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Properties.Preorder {p₁ p₂ p₃} (P : Preorder p₁ p₂ p₃) where open import Function open import Data.Product as Prod open Relation.Binary.Preorder P ------------------------------------------------------------------------ -- For every preorder there is an induced equivalence InducedEquivalence : Setoid _ _ InducedEquivalence = record { _≈_ = λ x y → x ∼ y × y ∼ x ; isEquivalence = record { refl = (refl , refl) ; sym = swap ; trans = Prod.zip trans (flip trans) } }
{ "alphanum_fraction": 0.4827586207, "avg_line_length": 27, "ext": "agda", "hexsha": "716300e30c5b2ef926c563d1f0d8953e81a5a784", "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/Relation/Binary/Properties/Preorder.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/Relation/Binary/Properties/Preorder.agda", "max_line_length": 72, "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/Relation/Binary/Properties/Preorder.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": 165, "size": 783 }
{-# OPTIONS --without-K #-} module algebra.semigroup where open import algebra.semigroup.core public open import algebra.semigroup.morphism public
{ "alphanum_fraction": 0.7919463087, "avg_line_length": 24.8333333333, "ext": "agda", "hexsha": "c2a7cc2bb77d0d5f5d4408b20f0859b5a42d9993", "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/algebra/semigroup.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/algebra/semigroup.agda", "max_line_length": 45, "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/algebra/semigroup.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": 30, "size": 149 }
{-# OPTIONS --without-K --safe #-} module Data.Binary.Proofs.Unary where open import Relation.Binary.PropositionalEquality open import Data.Binary.Operations.Unary open import Data.Binary.Definitions open import Data.Binary.Operations.Semantics open import Data.Nat as ℕ using (ℕ; suc; zero) open import Relation.Binary.PropositionalEquality.FasterReasoning import Data.Nat.Properties as ℕ open import Function inc⁺⁺-homo : ∀ xs → ⟦ inc⁺⁺ xs ⇓⟧⁺ ≡ suc ⟦ xs ⇓⟧⁺ inc⁺⁺-homo 1ᵇ = refl inc⁺⁺-homo (O ∷ xs) = refl inc⁺⁺-homo (I ∷ xs) = begin 2* ⟦ inc⁺⁺ xs ⇓⟧⁺ ≡⟨ cong 2* (inc⁺⁺-homo xs) ⟩ 2* (suc ⟦ xs ⇓⟧⁺) ≡⟨⟩ (suc ⟦ xs ⇓⟧⁺) ℕ.+ suc ⟦ xs ⇓⟧⁺ ≡⟨ ℕ.+-suc (suc ⟦ xs ⇓⟧⁺) ⟦ xs ⇓⟧⁺ ⟩ suc (suc (2* ⟦ xs ⇓⟧⁺)) ∎ inc-homo : ∀ x → ⟦ inc x ⇓⟧ ≡ suc ⟦ x ⇓⟧ inc-homo 0ᵇ = refl inc-homo (0< xs) = inc⁺⁺-homo xs open import Data.Product ⟦x⇓⟧⁺≡suc : ∀ x → ∃[ n ] (⟦ x ⇓⟧⁺ ≡ suc n) ⟦x⇓⟧⁺≡suc 1ᵇ = 0 , refl ⟦x⇓⟧⁺≡suc (I ∷ x) = 2* ⟦ x ⇓⟧⁺ , refl ⟦x⇓⟧⁺≡suc (O ∷ x) with ⟦x⇓⟧⁺≡suc x ⟦x⇓⟧⁺≡suc (O ∷ x) | fst , snd = suc (2* fst) , (cong 2* snd ⟨ trans ⟩ (ℕ.+-suc (suc fst) _)) ⟦x⇓⟧⁺≢0 : ∀ x → ⟦ x ⇓⟧⁺ ≢ 0 ⟦x⇓⟧⁺≢0 x x≡0 with ⟦x⇓⟧⁺≡suc x ⟦x⇓⟧⁺≢0 x x≡0 | _ , prf with sym x≡0 ⟨ trans ⟩ prf ⟦x⇓⟧⁺≢0 x x≡0 | _ , prf | () open import Data.Empty inc-dec⁺⁺ : ∀ x xs → inc⁺⁺ (dec⁺⁺ x xs) ≡ x ∷ xs inc-dec⁺⁺ I xs = refl inc-dec⁺⁺ O 1ᵇ = refl inc-dec⁺⁺ O (x ∷ xs) = cong (O ∷_) (inc-dec⁺⁺ x xs) inc-dec : ∀ xs → inc⁺ (dec⁺ xs) ≡ xs inc-dec 1ᵇ = refl inc-dec (x ∷ xs) = inc-dec⁺⁺ x xs data IncView : 𝔹 → ℕ → Set where Izero : IncView 0ᵇ 0 Isuc : ∀ {n xs ys} → inc xs ≡ ys → IncView xs n → IncView ys (suc n) inc-view : ∀ xs → IncView xs ⟦ xs ⇓⟧ inc-view xs = go _ xs refl where go : ∀ n xs → ⟦ xs ⇓⟧ ≡ n → IncView xs n go .0 0ᵇ refl = Izero go zero (0< xs) eq = ⊥-elim (⟦x⇓⟧⁺≢0 xs eq) go (suc n) (0< xs) eq = Isuc (cong 0<_ (inc-dec xs)) (go n (dec⁺ xs) (ℕ.suc-injective (sym (inc-homo (dec⁺ xs)) ⟨ trans ⟩ cong ⟦_⇓⟧⁺ (inc-dec xs) ⟨ trans ⟩ eq)))
{ "alphanum_fraction": 0.5381909548, "avg_line_length": 28.0281690141, "ext": "agda", "hexsha": "6cd1482169e295c9c84b3ccfc7d9a4d44aa4cdfc", "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": "92af4d620febd47a9791d466d747278dc4a417aa", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-binary", "max_forks_repo_path": "Data/Binary/Proofs/Unary.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa", "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-binary", "max_issues_repo_path": "Data/Binary/Proofs/Unary.agda", "max_line_length": 104, "max_stars_count": 1, "max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-binary", "max_stars_repo_path": "Data/Binary/Proofs/Unary.agda", "max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z", "max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z", "num_tokens": 1106, "size": 1990 }
{- 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.Consensus.BlockStorage.BlockTree as BlockTree import LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock as ExecutedBlock import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote import LibraBFT.Impl.Consensus.PersistentLivenessStorage as PersistentLivenessStorage import LibraBFT.Impl.Consensus.StateComputerByteString as SCBS open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Util.Crypto open import LibraBFT.ImplShared.Util.Dijkstra.All open import Optics.All open import Util.ByteString open import Util.Hash open import Util.KVMap as Map open import Util.PKCS open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String as String using (String) module LibraBFT.Impl.Consensus.BlockStorage.BlockStore where ------------------------------------------------------------------------------ build : RootInfo → RootMetadata → List Block → List QuorumCert → Maybe TimeoutCertificate → StateComputer → PersistentLivenessStorage → Usize → Either ErrLog BlockStore executeAndInsertBlockE : BlockStore → Block → Either ErrLog (BlockStore × ExecutedBlock) executeBlockE : BlockStore → Block → Either ErrLog ExecutedBlock executeBlockE₀ : BlockStore → Block → EitherD ErrLog ExecutedBlock getBlock : HashValue → BlockStore → Maybe ExecutedBlock insertSingleQuorumCertE : BlockStore → QuorumCert → Either ErrLog (BlockStore × List InfoLog) pathFromRoot : HashValue → BlockStore → Either ErrLog (List ExecutedBlock) pathFromRootM : HashValue → LBFT (Either ErrLog (List ExecutedBlock)) ------------------------------------------------------------------------------ new : PersistentLivenessStorage → RecoveryData → StateComputer → Usize → Either ErrLog BlockStore new storage initialData stateComputer maxPrunedBlocksInMem = build (initialData ^∙ rdRoot) (initialData ^∙ rdRootMetadata) (initialData ^∙ rdBlocks) (initialData ^∙ rdQuorumCerts) (initialData ^∙ rdHighestTimeoutCertificate) stateComputer storage maxPrunedBlocksInMem abstract -- TODO: convert new to EitherD new-ed-abs : PersistentLivenessStorage → RecoveryData → StateComputer → Usize → EitherD ErrLog BlockStore new-ed-abs storage initialData stateComputer maxPrunedBlocksInMem = fromEither $ new storage initialData stateComputer maxPrunedBlocksInMem new-e-abs : PersistentLivenessStorage → RecoveryData → StateComputer → Usize → Either ErrLog BlockStore new-e-abs = new new-e-abs-≡ : new-e-abs ≡ new new-e-abs-≡ = refl build root _rootRootMetadata blocks quorumCerts highestTimeoutCert stateComputer storage maxPrunedBlocksInMem = do let (RootInfo∙new rootBlock rootQc rootLi) = root {- LBFT-OBM-DIFF : OBM does not implement RootMetadata assert_eq!( root_qc.certified_block().version(), root_metadata.version()) assert_eq!( root_qc.certified_block().executed_state_id(), root_metadata.accu_hash) -} executedRootBlock = ExecutedBlock∙new rootBlock (StateComputeResult∙new (stateComputer ^∙ scObmVersion) nothing) tree ← BlockTree.new executedRootBlock rootQc rootLi maxPrunedBlocksInMem highestTimeoutCert bs1 ← (foldM) (λ bs b → fst <$> executeAndInsertBlockE bs b) (BlockStore∙new tree stateComputer storage) blocks (foldM) go bs1 quorumCerts where go : BlockStore → QuorumCert → Either ErrLog BlockStore go bs qc = case insertSingleQuorumCertE bs qc of λ where (Left e) → Left e (Right (bs' , _info)) → Right bs' ------------------------------------------------------------------------------ commitM : LedgerInfoWithSignatures → LBFT (Either ErrLog Unit) commitM finalityProof = do bs ← use lBlockStore maybeSD (bs ^∙ bsRoot) (bail fakeErr) $ λ bsr → do let blockIdToCommit = finalityProof ^∙ liwsLedgerInfo ∙ liConsensusBlockId case getBlock blockIdToCommit bs of λ where nothing → bail (ErrCBlockNotFound blockIdToCommit) (just blockToCommit) → ifD‖ blockToCommit ^∙ ebRound ≤?ℕ bsr ^∙ ebRound ≔ bail fakeErr -- "commit block round lower than root" ‖ otherwise≔ (pathFromRootM blockIdToCommit >>= λ where (Left e) → bail e (Right r) → continue blockToCommit r) where continue : ExecutedBlock → List ExecutedBlock → LBFT (Either ErrLog Unit) continue blockToCommit blocksToCommit = do -- NOTE: Haskell tells the "StateComputer" to commit 'blocksToCommit'. -- TODO-1: The StateComputer might indicate an epoch change. -- NO NEED FOR PRUNING: pruneTreeM blockToCommit -- -- THIS IS WHERE COMMIT IS COMPLETED. -- To connect to the proof's correctness condition, it will be necessary to -- send a CommitMsg, which will carry evidence of the CommitRule -- needed to invoke correctness conditions like ConcCommitsDoNotConflict*. -- The details of this connection yet have not been settled yet. -- TODO-1: Once the details are determined, then make the connection. ok unit ------------------------------------------------------------------------------ rebuildM : RootInfo → RootMetadata → List Block → List QuorumCert → LBFT (Either ErrLog Unit) rebuildM root rootMetadata blocks quorumCerts = do -- logEE lEC (here []) $ do self0 ← use lBlockStore case build root rootMetadata blocks quorumCerts (self0 ^∙ bsHighestTimeoutCert) (self0 ^∙ bsStateComputer) (self0 ^∙ bsStorage) (self0 ^∙ bsInner ∙ btMaxPrunedBlocksInMem) of λ where (Left e) → bail e (Right (BlockStore∙new inner _ _)) → do toRemove ← BlockTree.getAllBlockIdM PersistentLivenessStorage.pruneTreeM toRemove ∙?∙ λ _ → do lRoundManager ∙ rmBlockStore ∙ bsInner ∙= inner self1 ← use lBlockStore maybeS (self1 ^∙ bsRoot) (bail fakeErr {-bsRootErrL here-}) $ λ bsr → do ifD self1 ^∙ bsHighestCommitCert ∙ qcCommitInfo ∙ biRound >? bsr ^∙ ebRound then (commitM (self1 ^∙ bsHighestCommitCert ∙ qcLedgerInfo) ∙^∙ withErrCtx (here' ("commitM failed" ∷ [])) ∙?∙ λ _ → ok unit) else ok unit where here' : List String.String → List String.String here' t = "BlockStore" ∷ "rebuildM" ∷ t -- lsRI root : lsRMD rootMetadata : lsBs blocks : lsQCs quorumCerts : t ------------------------------------------------------------------------------ executeAndInsertBlockM : Block → LBFT (Either ErrLog ExecutedBlock) executeAndInsertBlockM b = do bs ← use lBlockStore case⊎D executeAndInsertBlockE bs b of λ where (Left e) → bail e (Right (bs' , eb)) → do lBlockStore ∙= bs' ok eb module executeAndInsertBlockE (bs0 : BlockStore) (block : Block) where VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL VariantFor EL = EL ErrLog (BlockStore × ExecutedBlock) continue step₁ : VariantFor EitherD continue = step₁ step₂ : ExecutedBlock → VariantFor EitherD step₃ : ExecutedBlock → VariantFor EitherD step₄ : ExecutedBlock → VariantFor EitherD step₀ = -- NOTE: if the hash is already in our blockstore, then HASH-COLLISION -- because we have already confirmed the new block is for the expected round -- and if there is already a block for that round then our expected round -- should be higher. maybeSD (getBlock (block ^∙ bId) bs0) continue (pure ∘ (bs0 ,_)) here' : List String.String → List String.String here' t = "BlockStore" ∷ "executeAndInsertBlockE" {-∷ lsB block-} ∷ t step₁ = maybeSD (bs0 ^∙ bsRoot) (LeftD fakeErr) λ bsr → let btRound = bsr ^∙ ebRound in ifD btRound ≥?ℕ block ^∙ bRound then LeftD fakeErr -- block with old round else step₂ bsr step₂ _ = do eb ← case⊎D executeBlockE bs0 block of λ where (Right res) → RightD res -- OBM-LBFT-DIFF : This is never thrown in OBM. -- It is thrown by StateComputer in Rust (but not in OBM). (Left (ErrECCBlockNotFound parentBlockId)) → do eitherSD (pathFromRoot parentBlockId bs0) LeftD λ blocksToReexecute → -- OBM-LBFT-DIFF : OBM StateComputer does NOT have state. -- If it ever does have state then the following 'forM' will -- need to change to some sort of 'fold' because 'executeBlockE' -- would change the state, so the state passed to 'executeBlockE' -- would no longer be 'bs0'. case⊎D (forM) blocksToReexecute (executeBlockE bs0 ∘ (_^∙ ebBlock)) of λ where (Left e) → LeftD e (Right _) → executeBlockE₀ bs0 block (Left err) → LeftD err step₃ eb step₃ eb = do bs1 ← withErrCtxD' (here' []) -- TODO-1 : use inspect qualified so Agda List singleton can be in scope. (PersistentLivenessStorage.saveTreeE bs0 (eb ^∙ ebBlock ∷ []) []) step₄ eb step₄ eb = do (bt' , eb') ← BlockTree.insertBlockE eb (bs0 ^∙ bsInner) pure ((bs0 & bsInner ∙~ bt') , eb') E : VariantFor Either E = toEither step₀ D : VariantFor EitherD D = fromEither E executeAndInsertBlockE = executeAndInsertBlockE.E module executeBlockE (bs : BlockStore) (block : Block) where step₀ = do case SCBS.compute (bs ^∙ bsStateComputer) block (block ^∙ bParentId) of λ where (Left e) → Left fakeErr -- (here' e) (Right stateComputeResult) → pure (ExecutedBlock∙new block stateComputeResult) where here' : List String → List String here' t = "BlockStore" ∷ "executeBlockE" {-∷ lsB block-} ∷ t abstract executeBlockE = executeBlockE.step₀ executeBlockE₀ bs block = fromEither $ executeBlockE bs block executeBlockE≡ : ∀ {bs block r} → executeBlockE bs block ≡ r → executeBlockE₀ bs block ≡ fromEither r executeBlockE≡ refl = refl ------------------------------------------------------------------------------ insertSingleQuorumCertM : QuorumCert → LBFT (Either ErrLog Unit) insertSingleQuorumCertM qc = do bs ← use lBlockStore case insertSingleQuorumCertE bs qc of λ where (Left e) → bail e (Right (bs' , info)) → do forM_ info logInfo lBlockStore ∙= bs' ok unit insertSingleQuorumCertE bs qc = maybeS (getBlock (qc ^∙ qcCertifiedBlock ∙ biId) bs) (Left (ErrCBlockNotFound -- (here ["insert QC without having the block in store first"]) (qc ^∙ qcCertifiedBlock ∙ biId))) (λ executedBlock → if ExecutedBlock.blockInfo executedBlock /= qc ^∙ qcCertifiedBlock then Left fakeErr -- (ErrL (here [ "QC for block has different BlockInfo than EB" -- , "QC certified BI", show (qc ^∙ qcCertifiedBlock) -- , "EB BI", show (ExecutedBlock.blockInfo executedBlock) -- , "EB", show executedBlock ])) else (do bs' ← withErrCtx' (here' []) (PersistentLivenessStorage.saveTreeE bs [] (qc ∷ [])) (bt , output) ← BlockTree.insertQuorumCertE qc (bs' ^∙ bsInner) pure ((bs' & bsInner ∙~ bt) , output))) where here' : List String.String → List String.String here' t = "BlockStore" ∷ "insertSingleQuorumCertE" ∷ t ------------------------------------------------------------------------------ insertTimeoutCertificateM : TimeoutCertificate → LBFT (Either ErrLog Unit) insertTimeoutCertificateM tc = do curTcRound ← maybe {-(Round-} 0 {-)-} (_^∙ tcRound) <$> use (lBlockStore ∙ bsHighestTimeoutCert) ifD tc ^∙ tcRound ≤?ℕ curTcRound then ok unit else PersistentLivenessStorage.saveHighestTimeoutCertM tc ∙^∙ withErrCtx ("" ∷ []) ∙?∙ λ _ → do BlockTree.replaceTimeoutCertM tc ok unit ------------------------------------------------------------------------------ blockExists : HashValue → BlockStore → Bool blockExists hv bs = Map.kvm-member hv (bs ^∙ bsInner ∙ btIdToBlock) getBlock hv bs = btGetBlock hv (bs ^∙ bsInner) getQuorumCertForBlock : HashValue → BlockStore → Maybe QuorumCert getQuorumCertForBlock hv bs = Map.lookup hv (bs ^∙ bsInner ∙ btIdToQuorumCert) pathFromRootM hv = pathFromRoot hv <$> use lBlockStore pathFromRoot hv bs = BlockTree.pathFromRoot hv (bs ^∙ bsInner) ------------------------------------------------------------------------------ syncInfoM : LBFT SyncInfo syncInfoM = SyncInfo∙new <$> use (lBlockStore ∙ bsHighestQuorumCert) <*> use (lBlockStore ∙ bsHighestCommitCert) <*> use (lBlockStore ∙ bsHighestTimeoutCert) abstract syncInfoM-abs = syncInfoM syncInfoM-abs-≡ : syncInfoM-abs ≡ syncInfoM syncInfoM-abs-≡ = refl
{ "alphanum_fraction": 0.620990186, "avg_line_length": 39.5768115942, "ext": "agda", "hexsha": "ba35db4bb11d9a8d6a8644caa0bdeffa7902df59", "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/Consensus/BlockStorage/BlockStore.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/Consensus/BlockStorage/BlockStore.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/Consensus/BlockStorage/BlockStore.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3641, "size": 13654 }
module Data.Num.Standard where open import Data.Nat using (ℕ; suc; zero; _≤?_) open import Data.Fin using (Fin; fromℕ; #_) open import Level using () renaming (suc to lsuc) -- renaming (zero to Fzero; suc to Fsuc; toℕ to F→N; fromℕ≤ to N→F) open import Relation.Nullary.Decidable infixr 2 [_]_ -- invariant: base ≥ 1 data Num : ℕ → Set where ∙ : ∀ {b} → Num (suc b) [_]_ : ∀ {b} → (n : ℕ) → {in-bound : True (n ≤? b)} → Num (suc b) → Num (suc b) null : Num 2 null = [ 0 ] ∙ eins : Num 2 eins = [ 1 ] ∙ zwei : Num 3 zwei = [ 1 ] [ 2 ] ∙ carry : ∀ {b} → Num b → Num b carry {zero} () carry {suc b} ∙ = [ {! !} ] ∙ carry {suc b} ([ n ] xs) = {! !} _+_ : ∀ {b} → Num b → Num b → Num b ∙ + ys = ys xs + ∙ = xs ([ x ] xs) + ([ y ] ys) = {! !}
{ "alphanum_fraction": 0.5183246073, "avg_line_length": 21.8285714286, "ext": "agda", "hexsha": "78d5883c91ae4f16ceff266b06da8354491829ad", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_path": "Data/Num/Sandbox/Standard.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "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": "banacorn/numeral", "max_issues_repo_path": "Data/Num/Sandbox/Standard.agda", "max_line_length": 83, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_path": "Data/Num/Sandbox/Standard.agda", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "num_tokens": 325, "size": 764 }
open import Prelude open import Nat open import core open import contexts open import lemmas-disjointness module lemmas-freshness where -- if x is fresh in an hexp, it's fresh in its expansion mutual fresh-elab-synth1 : ∀{x e τ d Γ Δ} → x # Γ → freshh x e → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → fresh x d fresh-elab-synth1 _ FRHConst ESConst = FConst fresh-elab-synth1 apt (FRHAsc frsh) (ESAsc x₁) = FCast (fresh-elab-ana1 apt frsh x₁) fresh-elab-synth1 _ (FRHVar x₂) (ESVar x₃) = FVar x₂ fresh-elab-synth1 {Γ = Γ} apt (FRHLam2 x₂ frsh) (ESLam x₃ exp) = FLam x₂ (fresh-elab-synth1 (apart-extend1 Γ x₂ apt) frsh exp) fresh-elab-synth1 apt FRHEHole ESEHole = FHole (EFId apt) fresh-elab-synth1 apt (FRHNEHole frsh) (ESNEHole x₁ exp) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh exp) fresh-elab-synth1 apt (FRHAp frsh frsh₁) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) = FAp (FCast (fresh-elab-ana1 apt frsh x₅)) (FCast (fresh-elab-ana1 apt frsh₁ x₆)) fresh-elab-ana1 : ∀{ x e τ d τ' Γ Δ} → x # Γ → freshh x e → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ → fresh x d fresh-elab-ana1 {Γ = Γ} apt (FRHLam1 x₁ frsh) (EALam x₂ x₃ exp) = FLam x₁ (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh exp ) fresh-elab-ana1 apt frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth1 apt frsh x₃ fresh-elab-ana1 apt FRHEHole EAEHole = FHole (EFId apt) fresh-elab-ana1 apt (FRHNEHole frsh) (EANEHole x₁ x₂) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh x₂) -- if x is fresh in the expansion of an hexp, it's fresh in that hexp mutual fresh-elab-synth2 : ∀{x e τ d Γ Δ} → fresh x d → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → freshh x e fresh-elab-synth2 FConst ESConst = FRHConst fresh-elab-synth2 (FVar x₂) (ESVar x₃) = FRHVar x₂ fresh-elab-synth2 (FLam x₂ frsh) (ESLam x₃ exp) = FRHLam2 x₂ (fresh-elab-synth2 frsh exp) fresh-elab-synth2 (FHole x₁) ESEHole = FRHEHole fresh-elab-synth2 (FNEHole x₁ frsh) (ESNEHole x₂ exp) = FRHNEHole (fresh-elab-synth2 frsh exp) fresh-elab-synth2 (FAp (FCast frsh) (FCast frsh₁)) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) = FRHAp (fresh-elab-ana2 frsh x₅) (fresh-elab-ana2 frsh₁ x₆) fresh-elab-synth2 (FCast frsh) (ESAsc x₁) = FRHAsc (fresh-elab-ana2 frsh x₁) fresh-elab-ana2 : ∀{ x e τ d τ' Γ Δ} → fresh x d → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ → freshh x e fresh-elab-ana2 (FLam x₁ frsh) (EALam x₂ x₃ exp) = FRHLam1 x₁ (fresh-elab-ana2 frsh exp) fresh-elab-ana2 frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth2 frsh x₃ fresh-elab-ana2 (FHole x₁) EAEHole = FRHEHole fresh-elab-ana2 (FNEHole x₁ frsh) (EANEHole x₂ x₃) = FRHNEHole (fresh-elab-synth2 frsh x₃)
{ "alphanum_fraction": 0.5713815789, "avg_line_length": 51.5254237288, "ext": "agda", "hexsha": "a237c7f460be642fbc7a598b43d643dc0376a57f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "lemmas-freshness.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "lemmas-freshness.agda", "max_line_length": 131, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "lemmas-freshness.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 1165, "size": 3040 }
infix -3.14 _+_ postulate _+_ : Set → Set → Set
{ "alphanum_fraction": 0.5882352941, "avg_line_length": 10.2, "ext": "agda", "hexsha": "063e88b955cf19b29101d024475a8e7bc2a7dd70", "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/Issue3991FractionalPrecedence.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/Issue3991FractionalPrecedence.agda", "max_line_length": 23, "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/Issue3991FractionalPrecedence.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": 22, "size": 51 }
-- Andreas, 2017-07-25, issue #2649, reported by gallais -- Serialization killed range needed for error message. -- {-# OPTIONS -v scope.clash:60 #-} module Issue2649 where open import Issue2649-1 open import Issue2649-2 id : (A : Set) → A → A id A x = M.foo where module M = MyModule A x -- Expected: -- Duplicate definition of module M. Previous definition of module M -- at .../Issue2649-2.agda:5,13-14
{ "alphanum_fraction": 0.6939759036, "avg_line_length": 21.8421052632, "ext": "agda", "hexsha": "f7e0b4e59f64abfdee112e03f5f0b19bdf26140a", "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/customised/Issue2649.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/customised/Issue2649.agda", "max_line_length": 68, "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/customised/Issue2649.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": 129, "size": 415 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Unsigned divisibility ------------------------------------------------------------------------ -- For signed divisibility see `Data.Integer.Divisibility.Signed` {-# OPTIONS --without-K --safe #-} module Data.Integer.Divisibility where open import Function open import Data.Integer open import Data.Integer.Properties import Data.Nat as ℕ import Data.Nat.Properties as ℕᵖ import Data.Nat.Divisibility as ℕᵈ import Data.Nat.Coprimality as ℕᶜ open import Level open import Relation.Binary open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Divisibility infix 4 _∣_ _∣_ : Rel ℤ 0ℓ _∣_ = ℕᵈ._∣_ on ∣_∣ open ℕᵈ public using (divides) ------------------------------------------------------------------------ -- Properties of divisibility *-monoʳ-∣ : ∀ k → (k *_) Preserves _∣_ ⟶ _∣_ *-monoʳ-∣ k {i} {j} i∣j = begin ∣ k * i ∣ ≡⟨ abs-*-commute k i ⟩ ∣ k ∣ ℕ.* ∣ i ∣ ∣⟨ ℕᵈ.*-cong ∣ k ∣ i∣j ⟩ ∣ k ∣ ℕ.* ∣ j ∣ ≡⟨ sym (abs-*-commute k j) ⟩ ∣ k * j ∣ ∎ where open ℕᵈ.∣-Reasoning *-monoˡ-∣ : ∀ k → (_* k) Preserves _∣_ ⟶ _∣_ *-monoˡ-∣ k {i} {j} rewrite *-comm i k | *-comm j k = *-monoʳ-∣ k *-cancelˡ-∣ : ∀ k {i j} → k ≢ + 0 → k * i ∣ k * j → i ∣ j *-cancelˡ-∣ k {i} {j} k≢0 k*i∣k*j = ℕᵈ./-cong (ℕ.pred ∣ k ∣) $ begin let ∣k∣-is-suc = ℕᵖ.m≢0⇒suc[pred[m]]≡m (k≢0 ∘ ∣n∣≡0⇒n≡0) in ℕ.suc (ℕ.pred ∣ k ∣) ℕ.* ∣ i ∣ ≡⟨ cong (ℕ._* ∣ i ∣) (∣k∣-is-suc) ⟩ ∣ k ∣ ℕ.* ∣ i ∣ ≡⟨ sym (abs-*-commute k i) ⟩ ∣ k * i ∣ ∣⟨ k*i∣k*j ⟩ ∣ k * j ∣ ≡⟨ abs-*-commute k j ⟩ ∣ k ∣ ℕ.* ∣ j ∣ ≡⟨ cong (ℕ._* ∣ j ∣) (sym ∣k∣-is-suc) ⟩ ℕ.suc (ℕ.pred ∣ k ∣) ℕ.* ∣ j ∣ ∎ where open ℕᵈ.∣-Reasoning *-cancelʳ-∣ : ∀ k {i j} → k ≢ + 0 → i * k ∣ j * k → i ∣ j *-cancelʳ-∣ k {i} {j} ≢0 = *-cancelˡ-∣ k ≢0 ∘ subst₂ _∣_ (*-comm i k) (*-comm j k)
{ "alphanum_fraction": 0.4453280318, "avg_line_length": 31.4375, "ext": "agda", "hexsha": "fb67676470b975d43a67986969d3261961c4361a", "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/Integer/Divisibility.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/Integer/Divisibility.agda", "max_line_length": 72, "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/Integer/Divisibility.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 858, "size": 2012 }
-- Binary products {-# OPTIONS --safe #-} module Cubical.Categories.Limits.BinProduct where open import Cubical.Categories.Category.Base open import Cubical.Data.Sigma.Base open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.HITs.PropositionalTruncation.Base private variable ℓ ℓ' : Level module _ (C : Category ℓ ℓ') where open Category C module _ {x y x×y : ob} (π₁ : Hom[ x×y , x ]) (π₂ : Hom[ x×y , y ]) where isBinProduct : Type (ℓ-max ℓ ℓ') isBinProduct = ∀ {z : ob} (f₁ : Hom[ z , x ]) (f₂ : Hom[ z , y ]) → ∃![ f ∈ Hom[ z , x×y ] ] (f ⋆ π₁ ≡ f₁) × (f ⋆ π₂ ≡ f₂) isPropIsBinProduct : isProp (isBinProduct) isPropIsBinProduct = isPropImplicitΠ (λ _ → isPropΠ2 (λ _ _ → isPropIsContr)) record BinProduct (x y : ob) : Type (ℓ-max ℓ ℓ') where field binProdOb : ob binProdPr₁ : Hom[ binProdOb , x ] binProdPr₂ : Hom[ binProdOb , y ] univProp : isBinProduct binProdPr₁ binProdPr₂ BinProducts : Type (ℓ-max ℓ ℓ') BinProducts = (x y : ob) → BinProduct x y hasBinProducts : Type (ℓ-max ℓ ℓ') hasBinProducts = ∥ BinProducts ∥₁
{ "alphanum_fraction": 0.6332767402, "avg_line_length": 26.7727272727, "ext": "agda", "hexsha": "b76f8b5d89b07aeefabfa65f3e1eb854e0a25787", "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/Categories/Limits/BinProduct.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/Categories/Limits/BinProduct.agda", "max_line_length": 81, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Categories/Limits/BinProduct.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 413, "size": 1178 }
module _ where open import Agda.Builtin.Cubical.Glue hiding (primGlue) primitive primGlue : _
{ "alphanum_fraction": 0.7755102041, "avg_line_length": 14, "ext": "agda", "hexsha": "a1f9004cfcbb9c8e569aadf52935f6f0fc870dda", "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": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "caryoscelus/agda", "max_forks_repo_path": "test/Fail/Issue2788b.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "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": "caryoscelus/agda", "max_issues_repo_path": "test/Fail/Issue2788b.agda", "max_line_length": 55, "max_stars_count": null, "max_stars_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "caryoscelus/agda", "max_stars_repo_path": "test/Fail/Issue2788b.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 30, "size": 98 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Printing Strings During Evaluation ------------------------------------------------------------------------ {-# OPTIONS --without-K --rewriting #-} -- see README.Debug.Trace for a use-case module Debug.Trace where open import Agda.Builtin.String open import Agda.Builtin.Equality -- Postulating the `trace` function and explaining how to compile it postulate trace : ∀ {a} {A : Set a} → String → A → A {-# FOREIGN GHC import qualified Debug.Trace as Debug #-} {-# FOREIGN GHC import qualified Data.Text as Text #-} {-# COMPILE GHC trace = const (const (Debug.trace . Text.unpack)) #-} -- Because expressions involving postulates get stuck during evaluation, -- we also postulate an equality characterising `trace`'s behaviour. By -- declaring it as a rewrite rule we internalise that evaluation rule. postulate trace-eq : ∀ {a} {A : Set a} (a : A) str → trace str a ≡ a {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE trace-eq #-} -- Specialised version of `trace` returning the traced message. traceId : String → String traceId str = trace str str
{ "alphanum_fraction": 0.6197424893, "avg_line_length": 29.8717948718, "ext": "agda", "hexsha": "d1c18552d98ed4f91d8bcb14983165a76b6ca8f7", "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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Debug/Trace.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/Debug/Trace.agda", "max_line_length": 72, "max_stars_count": 5, "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/Debug/Trace.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": 254, "size": 1165 }
------------------------------------------------------------------------------ -- Common stuff used by the gcd example ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.GCD.Partial.Definitions where open import FOTC.Base open import FOTC.Data.Nat.Divisibility.NotBy0 open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Type ------------------------------------------------------------------------------ -- Common divisor. CD : D → D → D → Set CD m n cd = cd ∣ m ∧ cd ∣ n {-# ATP definition CD #-} -- Divisible for any common divisor. Divisible : D → D → D → Set Divisible m n gcd = ∀ cd → N cd → CD m n cd → cd ∣ gcd {-# ATP definition Divisible #-} -- Greatest that any common divisor. GACD : D → D → D → Set GACD m n gcd = ∀ cd → N cd → CD m n cd → cd ≤ gcd {-# ATP definition GACD #-} -- Greatest common divisor specification gcdSpec : D → D → D → Set gcdSpec m n gcd = CD m n gcd ∧ GACD m n gcd {-# ATP definition gcdSpec #-} x≢0≢y : D → D → Set x≢0≢y m n = ¬ (m ≡ zero ∧ n ≡ zero) {-# ATP definition x≢0≢y #-}
{ "alphanum_fraction": 0.4972155927, "avg_line_length": 30.6585365854, "ext": "agda", "hexsha": "bf777eabc4beb1dd02627605bc13601b4bfecf2b", "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": "src/fot/FOTC/Program/GCD/Partial/Definitions.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": "src/fot/FOTC/Program/GCD/Partial/Definitions.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": "src/fot/FOTC/Program/GCD/Partial/Definitions.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": 322, "size": 1257 }
-- Andreas, 2013-10-21 reported by Christian Sattler {-# OPTIONS --allow-unsolved-metas #-} module Issue922 where import Common.Level f : Set → Set → Set f x _ = x -- Note: second argument is unused module _ (_ : f ? ?) where g = f -- Here an instance search for the unused argument (2nd ?) -- is triggered. -- Problem WAS: instance search was started in wrong context.
{ "alphanum_fraction": 0.6806282723, "avg_line_length": 23.875, "ext": "agda", "hexsha": "baf05ada96b85c0870edb941251d9b83f66c6016", "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/Issue922.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/Issue922.agda", "max_line_length": 61, "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/Issue922.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": 105, "size": 382 }
-- Andreas, 2018-10-27, issue #3323, reported by Guillaume Brunerie -- -- Mismatches between original and repeated parameter list -- should not lead to internal errors. open import Agda.Builtin.Bool open import Agda.Builtin.Equality data T .(b : Bool) : Set data T b where -- Omission of relevance info allowed c : Bool → T b test : ∀{b b'} → T b ≡ T b' test = refl -- Should succeed. record R (@0 b : Bool) : Set record R b where field foo : Bool -- Should succeed.
{ "alphanum_fraction": 0.6882845188, "avg_line_length": 20.7826086957, "ext": "agda", "hexsha": "78423fec9683b9dea0e78d1dea92cac90b46c370", "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/Issue3323.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/Issue3323.agda", "max_line_length": 67, "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/Issue3323.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": 478 }
{-# OPTIONS --rewriting #-} {- Lower can be a record if using type-in-type or allowing large eliminations: {-# OPTIONS --type-in-type #-} record Lower (A : Set₁) : Set where constructor lower field raise : A open Lower -} postulate _≡_ : ∀ {A : Set₁} → A → A → Set Lower : (A : Set₁) → Set lower : ∀ {A} → A → Lower A raise : ∀ {A} → Lower A → A beta : ∀ {A} {a : A} → raise (lower a) ≡ a {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE beta #-} data ⊥ : Set where ℘ : ∀ {ℓ} → Set ℓ → Set _ ℘ {ℓ} S = S → Set U : Set U = Lower (∀ (X : Set) → (℘ (℘ X) → X) → ℘ (℘ X)) τ : ℘ (℘ U) → U τ t = lower (λ X f p → t (λ x → p (f (raise x X f)))) σ : U → ℘ (℘ U) σ s = raise s U τ Δ : ℘ U Δ y = Lower (∀ p → σ y p → p (τ (σ y))) → ⊥ Ω : U Ω = τ (λ p → (∀ x → σ x p → p x)) R : ∀ p → (∀ x → σ x p → p x) → p Ω R _ 𝟙 = 𝟙 Ω (λ x → 𝟙 (τ (σ x))) M : ∀ x → σ x Δ → Δ x M _ 𝟚 𝟛 = let 𝟛 = raise 𝟛 in 𝟛 Δ 𝟚 (lower (λ p → 𝟛 (λ y → p (τ (σ y))))) L : (∀ p → (∀ x → σ x p → p x) → p Ω) → ⊥ L 𝟘 = 𝟘 Δ M (lower (λ p → 𝟘 (λ y → p (τ (σ y))))) false : ⊥ false = L R
{ "alphanum_fraction": 0.4464285714, "avg_line_length": 20.0754716981, "ext": "agda", "hexsha": "8a6efa0404648455d98e938d34d6bf89a8277e72", "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": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ionathanch/ionathanch.github.io", "max_forks_repo_path": "_assets/agda/GirardLower.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b", "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": "ionathanch/ionathanch.github.io", "max_issues_repo_path": "_assets/agda/GirardLower.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ionathanch/ionathanch.github.io", "max_stars_repo_path": "_assets/agda/GirardLower.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 519, "size": 1064 }
module bstd.bash where
{ "alphanum_fraction": 0.8260869565, "avg_line_length": 11.5, "ext": "agda", "hexsha": "36f51438b9fb0465105b3715bf0aadb841a967fb", "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": "fe95ba440099f9cf086096469133576a9652c122", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "semenov-vladyslav/bstd", "max_forks_repo_path": "src/bstd/bash.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fe95ba440099f9cf086096469133576a9652c122", "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": "semenov-vladyslav/bstd", "max_issues_repo_path": "src/bstd/bash.agda", "max_line_length": 22, "max_stars_count": 1, "max_stars_repo_head_hexsha": "fe95ba440099f9cf086096469133576a9652c122", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "semenov-vladyslav/bstd", "max_stars_repo_path": "src/bstd/bash.agda", "max_stars_repo_stars_event_max_datetime": "2019-06-29T10:40:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-29T10:40:15.000Z", "num_tokens": 7, "size": 23 }
module Cats.Category.Constructions.Product where open import Relation.Binary.PropositionalEquality as PropEq using (_≡_ ; refl) open import Data.Bool using (Bool ; true ; false ; not; if_then_else_) open import Relation.Binary.Core using (IsEquivalence) open import Level open import Cats.Category.Base open import Cats.Category.Constructions.Terminal as Terminal using (HasTerminal) open import Cats.Functor using (Functor) open import Cats.Util.Conv open import Cats.Util.Logic.Constructive import Cats.Category.Constructions.Iso as Iso import Cats.Category.Constructions.Unique as Unique Bool-elim : ∀ {a} {A : Bool → Set a} → A true → A false → (i : Bool) → A i Bool-elim x y true = x Bool-elim x y false = y module Build {lo la l≈} (Cat : Category lo la l≈) where private open module Cat = Category Cat open Cat.≈-Reasoning open Iso.Build Cat open Unique.Build Cat open Terminal.Build Cat IsProduct : ∀ {li} {I : Set li} (O : I → Obj) P → (∀ i → P ⇒ O i) → Set (lo ⊔ la ⊔ l≈ ⊔ li) IsProduct O P proj = ∀ {X} (x : ∀ i → X ⇒ O i) → ∃![ u ] (∀ i → x i ≈ proj i ∘ u) -- TODO The types of the equalities in IsBinaryProducts are backwards, since -- we want the RHS to be simpler than the LHS. So, projl ∘ u ≈ xl instead -- of xl ≈ projl ∘ u. IsBinaryProduct : ∀ {A B} P → (P ⇒ A) → (P ⇒ B) → Set (lo ⊔ la ⊔ l≈) IsBinaryProduct {A} {B} P projl projr = ∀ {X} (xl : X ⇒ A) (xr : X ⇒ B) → ∃![ u ] (xl ≈ projl ∘ u ∧ xr ≈ projr ∘ u) -- BinProduct→id-unique : ∀ {A B P} → {projl : P ⇒ A} → {projr : P ⇒ B} -- → (y : IsBinaryProduct P projl projr) -- → id ≈ (Unique.Build.∃!′.arr y) -- BinProduct→id-unique = ? -- ≈.trans (≈.sym (unique ((≈.sym id-r) , (≈.sym id-r)) )) {!arr!} IsBinaryProduct→IsProduct : ∀ {A B P} {pl : P ⇒ A} {pr : P ⇒ B} → IsBinaryProduct P pl pr → IsProduct (Bool-elim A B) P (Bool-elim pl pr) IsBinaryProduct→IsProduct isBinProd x = record { arr = f ⃗ ; prop = Bool-elim (∧-eliml (∃!′.prop f)) (∧-elimr (∃!′.prop f)) ; unique = λ eq → ∃!′.unique f (eq true , eq false) } where f = isBinProd (x true) (x false) record Product {li} {I : Set li} (O : I → Obj) : Set (lo ⊔ la ⊔ l≈ ⊔ li) where field prod : Obj proj : ∀ i → prod ⇒ O i isProduct : IsProduct O prod proj open Product using (proj ; isProduct ; prod) instance HasObj-Product : ∀ {li} {I : Set li} {O : I → Obj} → HasObj (Product O) lo la l≈ HasObj-Product = record { Cat = Cat ; _ᴼ = Product.prod } BinaryProduct : Obj → Obj → Set (lo ⊔ la ⊔ l≈) BinaryProduct A B = Product (Bool-elim A B) mkBinaryProduct : ∀ {A B P} (pl : P ⇒ A) (pr : P ⇒ B) → IsBinaryProduct P pl pr → BinaryProduct A B mkBinaryProduct {P = P} pl pr isBinProd = record { isProduct = IsBinaryProduct→IsProduct isBinProd } nullaryProduct-Terminal : (P : Product {I = ⊥} (λ())) → IsTerminal (P ᴼ) nullaryProduct-Terminal P X with isProduct P {X = X} λ() ... | ∃!-intro arr _ unique = ∃!-intro arr _ (λ _ → unique λ()) module _ {li} {I : Set li} {O : I → Obj} (P : Product O) where factorizer : ∀ {X} → (∀ i → X ⇒ O i) → X ⇒ P ᴼ factorizer proj = isProduct P proj ⃗ factorizer-proj : ∀ {X} {x : ∀ i → X ⇒ O i} {i} → proj P i ∘ factorizer x ≈ x i factorizer-proj {x = x} {i} = ≈.sym (∃!′.prop (isProduct P x) i) factorizer-resp : ∀ {X} {x y : ∀ i → X ⇒ O i} → (∀ i → x i ≈ y i) → factorizer x ≈ factorizer y factorizer-resp {x = x} {y} eq = ∃!′.unique (isProduct P x) (λ i → ≈.trans (eq i) (≈.sym factorizer-proj)) factorizer-∘ : ∀ {X} {x : ∀ i → X ⇒ O i} {Z} {f : Z ⇒ X} → factorizer x ∘ f ≈ factorizer (λ i → x i ∘ f) factorizer-∘ {x = x} {f = f} = ≈.sym ( ∃!′.unique (isProduct P (λ i → x i ∘ f)) (λ i → ≈.sym (≈.trans unassoc (∘-resp-l factorizer-proj))) ) module _ {li} {I : Set li} {O : I → Obj} (P : Product O) {O′ : I → Obj} (P′ : Product O′) where times : (∀ i → O i ⇒ O′ i) → P ᴼ ⇒ P′ ᴼ times x = factorizer P′ (λ i → x i ∘ proj P i) times-proj : ∀ {x : ∀ i → O i ⇒ O′ i} {i} → proj P′ i ∘ times x ≈ x i ∘ proj P i times-proj = factorizer-proj P′ times-resp : {x y : ∀ i → O i ⇒ O′ i} → (∀ i → x i ≈ y i) → times x ≈ times y times-resp {x} {y} eq = factorizer-resp P′ (λ i → ∘-resp-l (eq i)) times-∘ : ∀ {li} {I : Set li} → {O O′ O″ : I → Obj} → (P : Product O) (P′ : Product O′) (P″ : Product O″) → {x : ∀ i → O i ⇒ O′ i} {y : ∀ i → O′ i ⇒ O″ i} → times P′ P″ y ∘ times P P′ x ≈ times P P″ (λ i → y i ∘ x i) times-∘ P P′ P″ {x} {y} = begin times P′ P″ y ∘ times P P′ x ≈⟨ factorizer-∘ P″ ⟩ factorizer P″ (λ i → (y i ∘ proj P′ i) ∘ times P P′ x) ≈⟨ factorizer-resp P″ (λ i → assoc) ⟩ factorizer P″ (λ i → y i ∘ proj P′ i ∘ times P P′ x) ≈⟨ factorizer-resp P″ (λ i → ∘-resp-r (times-proj P P′)) ⟩ factorizer P″ (λ i → y i ∘ x i ∘ proj P i) ≈⟨ factorizer-resp P″ (λ i → unassoc) ⟩ times P P″ (λ i → y i ∘ x i) ∎ tim-fac : ∀ {li} {X} {I : Set li} → {O O′ : I → Obj} → (P : Product O) (P′ : Product O′) → {x : ∀ i → X ⇒ O i} {y : ∀ i → O i ⇒ O′ i} → times P P′ y ∘ factorizer P x ≈ factorizer P′ (λ i → y i ∘ x i) tim-fac P P′ {x} {y} = begin times P P′ y ∘ factorizer P x ≈⟨ factorizer-∘ P′ ⟩ factorizer P′ (λ i → (y i ∘ proj P i) ∘ factorizer P x) ≈⟨ factorizer-resp P′ (λ i → assoc) ⟩ factorizer P′ (λ i → y i ∘ proj P i ∘ factorizer P x) ≈⟨ factorizer-resp P′ (λ i → (∘-resp-r (factorizer-proj P))) ⟩ factorizer P′ (λ i → y i ∘ x i) ∎ proj-cancel : ∀ {li} {I : Set li} {O : I → Obj} {P proj} → IsProduct O P proj → ∀ {X} {f g : X ⇒ P} → (∀ i → proj i ∘ f ≈ proj i ∘ g) → f ≈ g proj-cancel {proj = proj} prod {f = f} {g} eq with prod (λ i → proj i ∘ g) ... | ∃!-intro u _ u-uniq = begin f ≈⟨ ≈.sym (u-uniq (λ i → ≈.sym (eq i))) ⟩ u ≈⟨ u-uniq (λ i → ≈.refl) ⟩ g ∎ record HasProducts {lo la l≈} li (C : Category lo la l≈) : Set (suc li ⊔ lo ⊔ la ⊔ l≈ ) where private open module Bld = Build C using (Product) open Category C field Π′ : {I : Set li} (O : I → Obj) → Product O module _ {I : Set li} where Π : ∀ (O : I → Obj) → Obj Π O = Π′ O ᴼ syntax Π (λ i → O) = Π[ i ] O proj : ∀ {O : I → Obj} i → Π O ⇒ O i proj {O} = Bld.Product.proj (Π′ O) factorizer : ∀ {O : I → Obj} {X} → (∀ i → X ⇒ O i) → X ⇒ Π O factorizer {O} = Bld.factorizer (Π′ O) times : ∀ {O O′ : I → Obj} → (∀ i → O i ⇒ O′ i) → Π O ⇒ Π O′ times {O} {O′} = Bld.times (Π′ O) (Π′ O′) factorizer-proj : ∀ {O : I → Obj} {X} {x : ∀ i → X ⇒ O i} {i} → proj i ∘ factorizer x ≈ x i factorizer-proj {O} = Bld.factorizer-proj (Π′ O) factorizer-resp : ∀ {O : I → Obj} {X} {x y : ∀ i → X ⇒ O i} → (∀ i → x i ≈ y i) → factorizer x ≈ factorizer y factorizer-resp {O} = Bld.factorizer-resp (Π′ O) factorizer-∘ : ∀ {O : I → Obj} {X} {x : ∀ i → X ⇒ O i} {Z} {f : Z ⇒ X} → factorizer x ∘ f ≈ factorizer (λ i → x i ∘ f) factorizer-∘ {O} = Bld.factorizer-∘ (Π′ O) times-proj : ∀ {O O′ : I → Obj} {x : ∀ i → O i ⇒ O′ i} {i} → proj i ∘ times x ≈ x i ∘ proj i times-proj {O} {O′} = Bld.times-proj (Π′ O) (Π′ O′) times-resp : ∀ {O O′ : I → Obj} {x y : ∀ i → O i ⇒ O′ i} → (∀ i → x i ≈ y i) → times x ≈ times y times-resp {O} {O′} = Bld.times-resp (Π′ O) (Π′ O′) times-∘ : ∀ {O O′ O″ : I → Obj} {x : ∀ i → O i ⇒ O′ i} {y : ∀ i → O′ i ⇒ O″ i} → times y ∘ times x ≈ times (λ i → y i ∘ x i) times-∘ {O} {O′} {O″} = Bld.times-∘ (Π′ O) (Π′ O′) (Π′ O″) HasProducts→HasTerminal : ∀ {lo la l≈} {C : Category lo la l≈} → HasProducts zero C → HasTerminal C HasProducts→HasTerminal {C = C} record { Π′ = Π } = let P = Π {I = ⊥} λ() in record { One = P ᴼ ; isTerminal = Build.nullaryProduct-Terminal C P } record HasBinaryProducts {lo la l≈} (C : Category lo la l≈) : Set (lo ⊔ la ⊔ l≈) where private open module Bld = Build C using (BinaryProduct ; Product) open Category C open ≈-Reasoning infixr 2 _×_ _×′_ ⟨_×_⟩ ⟨_,_⟩ field _×′_ : ∀ A B → BinaryProduct A B _×_ : Obj → Obj → Obj A × B = (A ×′ B) ᴼ projl : ∀ {A B} → A × B ⇒ A projl {A} {B} = Product.proj (A ×′ B) true projr : ∀ {A B} → A × B ⇒ B projr {A} {B} = Product.proj (A ×′ B) false ⟨_,_⟩ : ∀ {A B Z} → Z ⇒ A → Z ⇒ B → Z ⇒ A × B ⟨_,_⟩ {A} {B} f g = Bld.factorizer (A ×′ B) (Bool-elim f g) ⟨_×_⟩ : ∀ {A B A′ B′} → A ⇒ A′ → B ⇒ B′ → A × B ⇒ A′ × B′ ⟨_×_⟩ {A} {B} {A′} {B′} f g = Bld.times (A ×′ B) (A′ ×′ B′) (Bool-elim f g) first : ∀ {A A′ B} → A ⇒ A′ → A × B ⇒ A′ × B first f = ⟨ f × id ⟩ second : ∀ {A B B′} → B ⇒ B′ → A × B ⇒ A × B′ second f = ⟨ id × f ⟩ swap : ∀ {A B} → A × B ⇒ B × A swap = ⟨ projr , projl ⟩ ⟨,⟩-resp : ∀ {A B Z} {f f′ : Z ⇒ A} {g g′ : Z ⇒ B} → f ≈ f′ → g ≈ g′ → ⟨ f , g ⟩ ≈ ⟨ f′ , g′ ⟩ ⟨,⟩-resp {A} {B} f≈f′ g≈g′ = Bld.factorizer-resp (A ×′ B) (Bool-elim f≈f′ g≈g′) ⟨,⟩-projl : ∀ {A B Z} {f : Z ⇒ A} {g : Z ⇒ B} → projl ∘ ⟨ f , g ⟩ ≈ f ⟨,⟩-projl {A} {B} = Bld.factorizer-proj (A ×′ B) ⟨,⟩-projr : ∀ {A B Z} {f : Z ⇒ A} {g : Z ⇒ B} → projr ∘ ⟨ f , g ⟩ ≈ g ⟨,⟩-projr {A} {B} = Bld.factorizer-proj (A ×′ B) data Singleton {a} {A : Set a} (x : A) : Set a where _with≡_ : (y : A) → x ≡ y → Singleton x inspect : ∀ {a} {A : Set a} (x : A) → Singleton x inspect x = x with≡ refl ⟨projr,projl⟩-id : {A B : Obj} → ⟨ projl , projr ⟩ ≈ id {A × B} ⟨projr,projl⟩-id {A} {B} with inspect (A ×′ B) ... | record { prod = .(Product.prod (A ×′ B)) ; proj = proj ; isProduct = isProduct } with≡ refl with (isProduct proj) ... | Unique.Build.∃!-intro arr prop unique = ≈.trans (≈.sym (unique (Bool-elim (≈.sym ⟨,⟩-projl) (≈.sym ⟨,⟩-projr))) ) (unique λ i → ≈.sym id-r) --... | p (record { prod = prod' ; proj = proj ; isProduct = isProduct }) with (isProduct proj) -- ... | Unique.Build.∃!-intro arr prop unique = ≈.trans (≈.sym (unique (Bool-elim {!⟨,⟩-projl {A} {B} {f = projl} {g = projr}!} {!!})) ) (unique λ i → ≈.sym id-r) ⟨,⟩-∘ : ∀ {A B Y Z} {f : Y ⇒ Z} {g : Z ⇒ A} {h : Z ⇒ B} → ⟨ g , h ⟩ ∘ f ≈ ⟨ g ∘ f , h ∘ f ⟩ ⟨,⟩-∘ {A} {B} {Y} {Z} {f} {g} {h} = begin ⟨ g , h ⟩ ∘ f ≈⟨ Bld.factorizer-∘ (A ×′ B) ⟩ Bld.factorizer (A ×′ B) (λ i → Bool-elim {A = λ i → Z ⇒ Bool-elim A B i} g h i ∘ f) ≈⟨ Bld.factorizer-resp (A ×′ B) (Bool-elim ≈.refl ≈.refl) ⟩ ⟨ g ∘ f , h ∘ f ⟩ ∎ ⟨×⟩-resp : ∀ {A A′ B B′} {f f′ : A ⇒ A′} {g g′ : B ⇒ B′} → f ≈ f′ → g ≈ g′ → ⟨ f × g ⟩ ≈ ⟨ f′ × g′ ⟩ ⟨×⟩-resp {A} {A′} {B} {B′} f≈f′ g≈g′ = Bld.times-resp (A ×′ B) (A′ ×′ B′) (Bool-elim f≈f′ g≈g′) ⟨×⟩-projl : ∀ {A A′ B B′} {f : A ⇒ A′} {g : B ⇒ B′} → projl ∘ ⟨ f × g ⟩ ≈ f ∘ projl ⟨×⟩-projl {A} {A′} {B} {B′} = Bld.times-proj (A ×′ B) (A′ ×′ B′) ⟨×⟩-projr : ∀ {A A′ B B′} {f : A ⇒ A′} {g : B ⇒ B′} → projr ∘ ⟨ f × g ⟩ ≈ g ∘ projr ⟨×⟩-projr {A} {A′} {B} {B′} = Bld.times-proj (A ×′ B) (A′ ×′ B′) ⟨×⟩-∘ : ∀ {A A′ A″ B B′ B″} → {f : A′ ⇒ A″} {f′ : A ⇒ A′} {g : B′ ⇒ B″} {g′ : B ⇒ B′} → ⟨ f × g ⟩ ∘ ⟨ f′ × g′ ⟩ ≈ ⟨ f ∘ f′ × g ∘ g′ ⟩ ⟨×⟩-∘ {A} {A′} {A″} {B} {B′} {B″} {f} {f′} {g} {g′} = begin ⟨ f × g ⟩ ∘ ⟨ f′ × g′ ⟩ ≈⟨ Bld.times-∘ (A ×′ B) (A′ ×′ B′) (A″ ×′ B″) ⟩ Bld.times (A ×′ B) (A″ ×′ B″) (λ i → Bool-elim {A = λ i → Bool-elim A′ B′ i ⇒ Bool-elim A″ B″ i} f g i ∘ Bool-elim {A = λ i → Bool-elim A B i ⇒ Bool-elim A′ B′ i} f′ g′ i) ≈⟨ Bld.times-resp (A ×′ B) (A″ ×′ B″) (Bool-elim ≈.refl ≈.refl) ⟩ ⟨ f ∘ f′ × g ∘ g′ ⟩ ∎ ⟨×⟩-∘-⟨,⟩ : ∀ {X A A′ B B′} → {u : X ⇒ A}{v : X ⇒ A′}{f : A ⇒ B}{g : A′ ⇒ B′} → ⟨ f × g ⟩ ∘ ⟨ u , v ⟩ ≈ ⟨ f ∘ u , g ∘ v ⟩ ⟨×⟩-∘-⟨,⟩ {X} {A} {A′} {B} {B′} {u} {v} {f} {g} = begin ⟨ f × g ⟩ ∘ ⟨ u , v ⟩ ≈⟨ Bld.tim-fac (A ×′ A′) (B ×′ B′) ⟩ Bld.factorizer (B ×′ B′) ( λ i → Bool-elim {A = λ i → Bool-elim A A′ i ⇒ Bool-elim B B′ i} f g i ∘ Bool-elim {A = λ i → X ⇒ Bool-elim A A′ i} u v i) -- {A = λ i → X ⇒ Bool-elim B B′ i} (f ∘ u) (g ∘ v) i) ≈⟨ Bld.factorizer-resp (B ×′ B′) (Bool-elim ≈.refl ≈.refl) ⟩ ⟨ f ∘ u , g ∘ v ⟩ ∎ -- The following is conceptually trivial, but we have to dig quite deep to -- avoid level-related nonsense. HasProducts→HasBinaryProducts : ∀ {lp lo la l≈} {C : Category lo la l≈} → HasProducts lp C → HasBinaryProducts C HasProducts→HasBinaryProducts {lp} {C = C} record { Π′ = Π } = record { _×′_ = _×_ } where open Category C open Unique.Build C open Build C open Product using (proj ; isProduct) open ∃!′ using (arr ; prop ; unique) _×_ : ∀ A B → Build.BinaryProduct C A B A × B = record { prod = prod′ ; proj = proj′ ; isProduct = isProduct′ } where O : Lift lp Bool → _ O (lift true) = A O (lift false) = B prod′ = Π O ᴼ proj′ = Bool-elim (proj (Π O) (lift true)) (proj (Π O) (lift false)) isProduct′ : IsProduct (Bool-elim A B) prod′ proj′ isProduct′ {X} x = record { arr = arr′ ⃗ ; prop = Bool-elim (prop arr′ (lift true)) (prop arr′ (lift false)) ; unique = λ eq → unique arr′ (λ { (lift true) → eq true ; (lift false) → eq false}) } where arr′ = isProduct (Π O) λ { (lift true) → x true ; (lift false) → x false} record HasFiniteProducts {lo la l≈} (Cat : Category lo la l≈) : Set (lo ⊔ la ⊔ l≈) where field {{hasTerminal}} : HasTerminal Cat {{hasBinaryProducts}} : HasBinaryProducts Cat open HasTerminal hasTerminal public open HasBinaryProducts hasBinaryProducts public module _ {lo la l≈ lo′ la′ l≈′} {C : Category lo la l≈} {D : Category lo′ la′ l≈′} where open Category C open Build using (IsProduct ; IsBinaryProduct) open Functor PreservesBinaryProducts : (F : Functor C D) → Set _ PreservesBinaryProducts F = ∀ {A B A×B} {projl : A×B ⇒ A} {projr : A×B ⇒ B} → IsBinaryProduct C A×B projl projr → IsBinaryProduct D (fobj F A×B) (fmap F projl) (fmap F projr) PreservesProducts : ∀ {i} (I : Set i) (F : Functor C D) → Set _ PreservesProducts I F = ∀ {O : I → Obj} {P} {proj : ∀ i → P ⇒ O i} → IsProduct C O P proj → IsProduct D (λ i → fobj F (O i)) (fobj F P) (λ i → fmap F (proj i))
{ "alphanum_fraction": 0.4747570194, "avg_line_length": 30.2985685072, "ext": "agda", "hexsha": "7299679a440a2855d0591f80335a70cb0573fd6e", "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": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_path": "Cats/Category/Constructions/Product.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "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": "alessio-b-zak/cats", "max_issues_repo_path": "Cats/Category/Constructions/Product.agda", "max_line_length": 166, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_path": "Cats/Category/Constructions/Product.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6312, "size": 14816 }
{-# OPTIONS --without-K --safe #-} module Experiment.Applicative where open import Function.Base open import Relation.Binary.PropositionalEquality record Functor (F : Set → Set) : Set₁ where field fmap : ∀ {A B} → (A → B) → F A → F B field fmap-id : ∀ {A} (x : F A) → fmap id x ≡ x fmap-∘ : ∀ {A B C} (f : B → C) (g : A → B) (x : F A) → fmap f (fmap g x) ≡ fmap (f ∘′ g) x fmap-cong : ∀ {A B} {f g : A → B} {x : F A} → (∀ v → f v ≡ g v) → fmap f x ≡ fmap g x record Applicative (F : Set → Set) : Set₁ where infixl 5 _<*>_ field pure : ∀ {A} → A → F A _<*>_ : ∀ {A B} → F (A → B) → F A → F B field identity : ∀ {A} (v : F A) → pure id <*> v ≡ v composition : ∀ {A B C} (u : F (A → C)) (v : F (B → A)) (w : F B) → pure _∘′_ <*> u <*> v <*> w ≡ u <*> (v <*> w) homomorphism : ∀ {A B} (f : A → B) (x : A) → pure f <*> pure x ≡ pure (f x) interchange : ∀ {A B} (u : F (A → B)) (y : A) → u <*> pure y ≡ pure (_$ y) <*> u -- <*>-cong : (∀ x → ff <*> pure x ≡ fg <*> pure x) → ff <*> fx ≡ fg <*> fx homomorphism₂ : ∀ {A B C} (f : A → B → C) (x : A) (y : B) → pure f <*> pure x <*> pure y ≡ pure (f x y) homomorphism₂ f x y = begin pure f <*> pure x <*> pure y ≡⟨ cong (_<*> pure y) $ homomorphism f x ⟩ pure (f x) <*> pure y ≡⟨ homomorphism (f x) y ⟩ pure (f x y) ∎ where open ≡-Reasoning functor : Functor F functor = record { fmap = λ f fx → pure f <*> fx ; fmap-id = identity ; fmap-∘ = λ f g x → begin pure f <*> (pure g <*> x) ≡⟨ sym $ composition (pure f) (pure g) x ⟩ pure _∘′_ <*> pure f <*> pure g <*> x ≡⟨ cong (λ v → v <*> x) $ homomorphism₂ _∘′_ f g ⟩ pure (f ∘′ g) <*> x ∎ ; fmap-cong = λ {A} {B} {f = f} {g = g} {x = x} f≡g → {! !} } where open ≡-Reasoning liftA2 : ∀ {A B C} → (A → B → C) → F A → F B → F C liftA2 f fx fy = pure f <*> fx <*> fy {- forall x y. p (q x y) = f x . g y it follows from the above that liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v -} record ApplicativeViaZip (F : Set → Set) : Set₁ where field pair : F A → F B → F (A × B) pair fx fy = ? record Monad (F : Set → Set) : Set₁ where infixl 5 _>>=_ field return : ∀ {A} → A → F A _>>=_ : ∀ {A B} → F A → (A → F B) → F B field identityˡ : ∀ {A B} (a : A) (k : A → F B) → return a >>= k ≡ k a identityʳ : ∀ {A} (m : F A) → m >>= return ≡ m assoc : ∀ {A B C} (m : F A) (k : A → F B) (h : B → F C) → m >>= (λ x → k x >>= h) ≡ (m >>= k) >>= h join : ∀ {A} → F (F A) → F A join x = x >>= id -- pure f <*> x ≡ pure g <*> x m >>= k = join (fmap k m) (∀ x → k x ≡ l x) join (fmap k m) join (fmap l m liftM1 : ∀ {A B} → (A → B) → F A → F B liftM1 f mx = mx >>= (λ x → return (f x)) functor : Functor F functor = record { fmap = liftM1 ; fmap-id = λ fx → identityʳ fx ; fmap-∘ = λ f g x → begin liftM1 f (liftM1 g x) ≡⟨ refl ⟩ liftM1 g x >>= (λ y → return (f y)) ≡⟨ refl ⟩ (x >>= (λ y → return (g y))) >>= (λ y → return (f y)) ≡⟨ sym $ assoc x (λ y → return (g y)) (λ y → return (f y)) ⟩ x >>= (λ y → return (g y) >>= (return ∘ f) ) ≡⟨ cong (λ v → x >>= v) $ {! !} ⟩ x >>= (λ y → return (f (g y))) ≡⟨ refl ⟩ liftM1 (f ∘′ g) x ∎ } where open ≡-Reasoning applicative : Applicative F applicative = record { pure = return ; _<*>_ = λ fab fa → fab >>= λ ab → fa >>= λ a → return (ab a) ; identity = λ v → begin return id >>= (λ ab → v >>= λ a → return (ab a)) ≡⟨ identityˡ id _ ⟩ v >>= return ≡⟨ identityʳ v ⟩ v ∎ ; composition = λ u v w → begin return _∘′_ >>= (λ f → u >>= (return ∘ f)) >>= (λ f → v >>= (return ∘ f)) >>= (λ f → w >>= (return ∘ f)) ≡⟨ {! !} ⟩ u >>= (λ f → v >>= (λ g → w >>= (return ∘ g)) >>= (return ∘ f)) ∎ ; homomorphism = {! !} ; interchange = {! !} } where open ≡-Reasoning {- return _∘′_ >>= (λ f → u >>= (λ a → return (f a))) >>= (λ f → v >>= (λ a → return (f a))) >>= (λ f → w >>= (λ a → return (f a))) ≡ u >>= (λ f → v >>= (λ g → w >>= (λ a → return (g a))) >>= (λ a → return (f a))) -} -- Traversable
{ "alphanum_fraction": 0.4191919192, "avg_line_length": 33.2519083969, "ext": "agda", "hexsha": "e96db527584c1bc9a34671e6aa8cd00d3964741b", "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": "Experiment/ApplicativeOld.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": "Experiment/ApplicativeOld.agda", "max_line_length": 79, "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": "Experiment/ApplicativeOld.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": 1786, "size": 4356 }
{-# OPTIONS --prop #-} open import Agda.Builtin.Equality postulate A : Set P : Prop p : P f : P → A mutual X : A X = _ test₁ : (x : P) → X ≡ f x test₁ x = refl test₂ : X ≡ f p test₂ = refl
{ "alphanum_fraction": 0.5140186916, "avg_line_length": 10.7, "ext": "agda", "hexsha": "97e6ee6e42921326aac921bf6670e60b8d692f8e", "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/Issue4152.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/Issue4152.agda", "max_line_length": 33, "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/Issue4152.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": 90, "size": 214 }
-- Andreas, 2016-12-15, issue #2341 -- `with` needs to abstract also in sort of target type. -- {-# OPTIONS -v tc.with:100 #-} open import Agda.Primitive data _≡_ {a}{A : Set a} (x : A) : A → Set a where refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} postulate equalLevel : (x y : Level) → x ≡ y id : ∀ {a} {A : Set a} → A → A id x = x Works : ∀ β α → Set α → Set β Works β α with equalLevel α β Works β .β | refl = id Coerce : ∀ β α → Set α → Set β Coerce β α rewrite equalLevel α β = id -- Should succeed {- Set α →{1+β⊔α} Set β added with function .Issue2341.rewrite-42 of type (β α w : Level) → w ≡ β → Set w → Set β (β α : Level) → (w : Level) →{1+β⊔α} w ≡ β →{1+β⊔α} Set w →{1+β⊔α} Set β raw with func. type = El {_getSort = Inf, unEl = Pi ru(El {_getSort = Type (Max []), unEl = Def Agda.Primitive.Level []}) (Abs "\946" El {_getSort = Inf, unEl = Pi ru(El {_getSort = Type (Max []), unEl = Def Agda.Primitive.Level []}) (Abs "\945" El {_getSort = Type (Max [Plus 1 (UnreducedLevel (Var 0 [])),Plus 1 (UnreducedLevel (Var 1 []))]), unEl = Pi ru(El {_getSort = Type (Max []), unEl = Def Agda.Primitive.Level []}) (Abs "w" El {_getSort = Type (Max [Plus 1 (UnreducedLevel (Var 1 [])),Plus 1 (UnreducedLevel (Var 2 []))]), unEl = Pi ru(El {_getSort = Type (Max []), unEl = Def Issue2341._≡_ [Apply ru{Level (Max [])},Apply ru{Def Agda.Primitive.Level []},Apply ru(Var 0 []),Apply ru(Var 2 [])]}) (NoAbs "w" El {_getSort = Type (Max [Plus 1 (UnreducedLevel (Var 1 [])),Plus 1 (UnreducedLevel (Var 2 []))]), unEl = Pi ru(El {_getSort = Type (Max [Plus 1 (UnreducedLevel (Var 0 []))]), unEl = Sort (Type (Max [Plus 0 (UnreducedLevel (Var 0 []))]))}) (NoAbs "_" El {_getSort = Type (Max [Plus 1 (UnreducedLevel (Var 2 []))]), unEl = Sort (Type (Max [Plus 0 (UnreducedLevel (Var 2 []))]))})})})})})} -}
{ "alphanum_fraction": 0.5938697318, "avg_line_length": 38.8723404255, "ext": "agda", "hexsha": "0177f340255da9d603919f60ffc4f98c6b60f97c", "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/Issue2341.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/Issue2341.agda", "max_line_length": 176, "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/Issue2341.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": 714, "size": 1827 }
module Thesis.SIRelBigStep.DSyntax where open import Thesis.SIRelBigStep.Syntax public -- data DType : Set where -- _⇒_ : (σ τ : DType) → DType -- int : DType DType = Type import Base.Syntax.Context module DC = Base.Syntax.Context DType Δτ : Type → DType Δτ (σ ⇒ τ) = σ ⇒ Δτ σ ⇒ Δτ τ Δτ (pair τ1 τ2) = pair (Δτ τ1) (Δτ τ2) Δτ nat = nat ΔΔ : Context → DC.Context ΔΔ ∅ = ∅ ΔΔ (τ • Γ) = Δτ τ • ΔΔ Γ --ΔΔ Γ = Γ -- A DTerm evaluates in normal context Δ, change context (ΔΔ Δ), and produces -- a result of type (Δt τ). data DTerm (Δ : Context) (τ : DType) : Set data DSVal (Δ : Context) : (τ : DType) → Set where dvar : ∀ {τ} → (x : Var Δ τ) → DSVal Δ τ dabs : ∀ {σ τ} (dt : DTerm (σ • Δ) τ) → DSVal Δ (σ ⇒ τ) dcons : ∀ {τ1 τ2} (dsv1 : DSVal Δ τ1) (dsv2 : DSVal Δ τ2) → DSVal Δ (pair τ1 τ2) dconst : ∀ {τ} → (dc : Const (Δτ τ)) → DSVal Δ τ data DTerm (Δ : Context) (τ : DType) where dval : DSVal Δ τ → DTerm Δ τ dprimapp : ∀ {σ} (p : Primitive (σ ⇒ τ)) → (sv : SVal Δ σ) → (dsv : DSVal Δ σ) → DTerm Δ τ dapp : ∀ {σ} (dvs : DSVal Δ (σ ⇒ τ)) → (vt : SVal Δ σ) → (dvt : DSVal Δ σ) → DTerm Δ τ dlett : ∀ {σ} (s : Term Δ σ) → (ds : DTerm Δ σ) → (dt : DTerm (σ • Δ) τ) → DTerm Δ τ
{ "alphanum_fraction": 0.53046875, "avg_line_length": 22.0689655172, "ext": "agda", "hexsha": "f0b6325974f967db3334f80a8ea8e9542ab09252", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/SIRelBigStep/DSyntax.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/SIRelBigStep/DSyntax.agda", "max_line_length": 77, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/SIRelBigStep/DSyntax.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 573, "size": 1280 }
module AbsurdPatternRequiresNoRHS where data False : Set where record True : Set where f : False -> True f () = _
{ "alphanum_fraction": 0.7, "avg_line_length": 13.3333333333, "ext": "agda", "hexsha": "f23f0a4e3e26a82cc0a25cb215333adcf2e1f281", "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/AbsurdPatternRequiresNoRHS.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/AbsurdPatternRequiresNoRHS.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/Succeed/AbsurdPatternRequiresNoRHS.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": 34, "size": 120 }
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures (A B) : Set1 A B = Set
{ "alphanum_fraction": 0.6979166667, "avg_line_length": 19.2, "ext": "agda", "hexsha": "5fb69dbe0d6760b10d01c50786ea0b62dd62bf90", "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/Issue1609f.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/Issue1609f.agda", "max_line_length": 71, "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/Issue1609f.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": 31, "size": 96 }
module Properties.Step where open import Agda.Builtin.Equality using (_≡_; refl) open import Agda.Builtin.Float using (primFloatPlus; primFloatMinus; primFloatTimes; primFloatDiv) open import FFI.Data.Maybe using (just; nothing) open import Luau.Heap using (Heap; _[_]; alloc; ok; function_is_end) open import Luau.Syntax using (Block; Expr; nil; var; addr; function_is_end; block_is_end; _$_; local_←_; return; done; _∙_; name; fun; arg; number; binexp; +) open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; app₁ ; app₂ ; beta; function; block; return; done; local; subst; binOpEval; evalBinOp; binOp₁; binOp₂) open import Luau.RuntimeError using (RuntimeErrorᴱ; RuntimeErrorᴮ; TypeMismatch; UnboundVariable; SEGV; app₁; app₂; block; local; return; bin₁; bin₂) open import Luau.RuntimeType using (function; number) open import Luau.Substitution using (_[_/_]ᴮ) open import Luau.Value using (nil; addr; val; number) open import Properties.Remember using (remember; _,_) data StepResultᴮ {a} (H : Heap a) (B : Block a) : Set data StepResultᴱ {a} (H : Heap a) (M : Expr a) : Set data StepResultᴮ H B where step : ∀ H′ B′ → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → StepResultᴮ H B return : ∀ V {B′} → (B ≡ (return (val V) ∙ B′)) → StepResultᴮ H B done : (B ≡ done) → StepResultᴮ H B error : (RuntimeErrorᴮ H B) → StepResultᴮ H B data StepResultᴱ H M where step : ∀ H′ M′ → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → StepResultᴱ H M value : ∀ V → (M ≡ val V) → StepResultᴱ H M error : (RuntimeErrorᴱ H M) → StepResultᴱ H M stepᴱ : ∀ {a} H M → StepResultᴱ {a} H M stepᴮ : ∀ {a} H B → StepResultᴮ {a} H B stepᴱ H nil = value nil refl stepᴱ H (var x) = error (UnboundVariable x) stepᴱ H (addr a) = value (addr a) refl stepᴱ H (number x) = value (number x) refl stepᴱ H (M $ N) with stepᴱ H M stepᴱ H (M $ N) | step H′ M′ D = step H′ (M′ $ N) (app₁ D) stepᴱ H (_ $ N) | value V refl with stepᴱ H N stepᴱ H (_ $ N) | value V refl | step H′ N′ s = step H′ (val V $ N′) (app₂ s) stepᴱ H (_ $ _) | value nil refl | value W refl = error (app₁ (TypeMismatch function nil λ())) stepᴱ H (_ $ _) | value (number n) refl | value W refl = error (app₁ (TypeMismatch function (number n) λ())) stepᴱ H (_ $ _) | value (addr a) refl | value W refl with remember (H [ a ]) stepᴱ H (_ $ _) | value (addr a) refl | value W refl | (nothing , p) = error (app₁ (SEGV a p)) stepᴱ H (_ $ _) | value (addr a) refl | value W refl | (just(function F is B end) , p) = step H (block fun F is B [ W / name (arg F) ]ᴮ end) (beta p) stepᴱ H (M $ N) | value V p | error E = error (app₂ E) stepᴱ H (M $ N) | error E = error (app₁ E) stepᴱ H (block b is B end) with stepᴮ H B stepᴱ H (block b is B end) | step H′ B′ D = step H′ (block b is B′ end) (block D) stepᴱ H (block b is (return _ ∙ B′) end) | return V refl = step H (val V) return stepᴱ H (block b is done end) | done refl = step H nil done stepᴱ H (block b is B end) | error E = error (block b E) stepᴱ H (function F is C end) with alloc H (function F is C end) stepᴱ H function F is C end | ok a H′ p = step H′ (addr a) (function p) stepᴱ H (binexp x op y) with stepᴱ H x stepᴱ H (binexp x op y) | value x′ refl with stepᴱ H y stepᴱ H (binexp x op y) | value (number x′) refl | value (number y′) refl = step H (number (evalBinOp x′ op y′)) binOpEval stepᴱ H (binexp x op y) | value (number x′) refl | step H′ y′ s = step H′ (binexp (number x′) op y′) (binOp₂ s) stepᴱ H (binexp x op y) | value (number x′) refl | error E = error (bin₂ E) stepᴱ H (binexp x op y) | value nil refl | _ = error (bin₁ (TypeMismatch number nil λ())) stepᴱ H (binexp x op y) | _ | value nil refl = error (bin₂ (TypeMismatch number nil λ())) stepᴱ H (binexp x op y) | value (addr a) refl | _ = error (bin₁ (TypeMismatch number (addr a) λ())) stepᴱ H (binexp x op y) | _ | value (addr a) refl = error (bin₂ (TypeMismatch number (addr a) λ())) stepᴱ H (binexp x op y) | step H′ x′ s = step H′ (binexp x′ op y) (binOp₁ s) stepᴱ H (binexp x op y) | error E = error (bin₁ E) stepᴮ H (function F is C end ∙ B) with alloc H (function F is C end) stepᴮ H (function F is C end ∙ B) | ok a H′ p = step H′ (B [ addr a / fun F ]ᴮ) (function p) stepᴮ H (local x ← M ∙ B) with stepᴱ H M stepᴮ H (local x ← M ∙ B) | step H′ M′ D = step H′ (local x ← M′ ∙ B) (local D) stepᴮ H (local x ← _ ∙ B) | value V refl = step H (B [ V / name x ]ᴮ) subst stepᴮ H (local x ← M ∙ B) | error E = error (local x E) stepᴮ H (return M ∙ B) with stepᴱ H M stepᴮ H (return M ∙ B) | step H′ M′ D = step H′ (return M′ ∙ B) (return D) stepᴮ H (return _ ∙ B) | value V refl = return V refl stepᴮ H (return M ∙ B) | error E = error (return E) stepᴮ H done = done refl
{ "alphanum_fraction": 0.6419726265, "avg_line_length": 59.7792207792, "ext": "agda", "hexsha": "2a0978ff63c5f366c67679a81da55e5241504d16", "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": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_path": "prototyping/Properties/Step.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "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": "Tr4shh/Roblox-Luau", "max_issues_repo_path": "prototyping/Properties/Step.agda", "max_line_length": 159, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_path": "prototyping/Properties/Step.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1838, "size": 4603 }
------------------------------------------------------------------------ -- Higher lenses ------------------------------------------------------------------------ {-# OPTIONS --cubical #-} import Equality.Path as P module Lens.Non-dependent.Higher {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 (_↔_) import Bool equality-with-J as Bool open import Circle eq as Circle using (𝕊¹) open import Coherently-constant eq as C using (Coherently-constant) open import Equality.Decidable-UIP equality-with-J open import Equality.Decision-procedures equality-with-J open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) import Equivalence.Half-adjoint equality-with-J as HA open import Function-universe equality-with-J as F hiding (id; _∘_) 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 Trunc hiding (Coherently-constant) import Nat equality-with-J as Nat open import Preimage equality-with-J as Preimage using (_⁻¹_) open import Quotient eq open import Surjection equality-with-J using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq as Non-dependent hiding (no-first-projection-lens; no-singleton-projection-lens) import Lens.Non-dependent.Traditional eq as Traditional private variable a b c ℓ p r : Level A A₁ A₂ B B₁ B₂ : Type a P : A → Type p ------------------------------------------------------------------------ -- Higher lenses -- Higher lenses. -- -- A little history: The "lenses" in Lens.Non-dependent.Bijection are -- not very well-behaved. I had previously considered some other -- variants, when Andrea Vezzosi suggested that I should look at Paolo -- Capriotti's higher lenses, and that I could perhaps use R → ∥ B ∥. -- This worked out nicely. -- -- For performance reasons η-equality is turned off for this record -- type. One can match on the constructor to block evaluation. record Lens (A : Type a) (B : Type b) : Type (lsuc (a ⊔ b)) where constructor ⟨_,_,_⟩ pattern no-eta-equality field -- Remainder type. R : Type (a ⊔ b) -- Equivalence. equiv : A ≃ (R × B) -- The proof of (mere) inhabitance. inhabited : R → ∥ B ∥ -- Remainder. remainder : A → R remainder a = proj₁ (_≃_.to equiv a) -- Getter. get : A → B get a = proj₂ (_≃_.to equiv a) -- Setter. set : A → B → A set a b = _≃_.from equiv (remainder a , b) -- A combination of get and set. modify : (B → B) → A → A modify f x = set x (f (get x)) -- The setter leaves the remainder unchanged. remainder-set : ∀ a b → remainder (set a b) ≡ remainder a remainder-set a b = proj₁ (_≃_.to equiv (_≃_.from equiv (remainder a , b))) ≡⟨ cong proj₁ (_≃_.right-inverse-of equiv (remainder a , b)) ⟩∎ remainder a ∎ -- Lens laws. get-set : ∀ a b → get (set a b) ≡ b get-set a b = proj₂ (_≃_.to equiv (_≃_.from equiv (remainder a , b))) ≡⟨ cong proj₂ (_≃_.right-inverse-of equiv (remainder a , b)) ⟩∎ proj₂ (remainder a , b) ∎ set-get : ∀ a → set a (get a) ≡ a set-get a = _≃_.from equiv (_≃_.to equiv a) ≡⟨ _≃_.left-inverse-of equiv a ⟩∎ a ∎ set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ set-set a b₁ b₂ = _≃_.from equiv (remainder (set a b₁) , b₂) ≡⟨ cong (λ r → _≃_.from equiv (r , b₂)) (remainder-set a b₁) ⟩∎ _≃_.from equiv (remainder a , b₂) ∎ -- The remainder function is surjective. remainder-surjective : Surjective remainder remainder-surjective r = ∥∥-map (λ b → _≃_.from equiv (r , b) , (remainder (_≃_.from equiv (r , b)) ≡⟨⟩ proj₁ (_≃_.to equiv (_≃_.from equiv (r , b))) ≡⟨ cong proj₁ (_≃_.right-inverse-of equiv (r , b)) ⟩∎ r ∎)) (inhabited r) -- Traditional lens. traditional-lens : Traditional.Lens A B traditional-lens = record { get = get ; set = set ; get-set = get-set ; set-get = set-get ; set-set = set-set } -- The following two coherence laws, which do not necessarily hold -- for traditional lenses (see -- Traditional.getter-equivalence-but-not-coherent), hold -- unconditionally for higher lenses. get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a) get-set-get a = cong get (set-get a) ≡⟨⟩ cong (proj₂ ∘ _≃_.to equiv) (_≃_.left-inverse-of equiv a) ≡⟨ sym $ cong-∘ _ _ (_≃_.left-inverse-of equiv _) ⟩ cong proj₂ (cong (_≃_.to equiv) (_≃_.left-inverse-of equiv a)) ≡⟨ cong (cong proj₂) $ _≃_.left-right-lemma equiv _ ⟩ cong proj₂ (_≃_.right-inverse-of equiv (_≃_.to equiv a)) ≡⟨⟩ get-set a (get a) ∎ get-set-set : ∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂)) get-set-set a b₁ b₂ = cong get (set-set a b₁ b₂) ≡⟨⟩ cong get (cong (λ r → _≃_.from equiv (r , b₂)) (remainder-set a b₁)) ≡⟨ elim₁ (λ {r} eq → cong get (cong (λ r → _≃_.from equiv (r , b₂)) eq) ≡ trans (cong proj₂ (_≃_.right-inverse-of equiv (r , b₂))) (sym (get-set a b₂))) ( cong get (cong (λ r → _≃_.from equiv (r , b₂)) (refl (remainder a))) ≡⟨ trans (cong (cong get) $ cong-refl _) $ cong-refl _ ⟩ refl (get (set a b₂)) ≡⟨ sym $ trans-symʳ _ ⟩ trans (get-set a b₂) (sym (get-set a b₂)) ≡⟨⟩ trans (cong proj₂ (_≃_.right-inverse-of equiv (remainder a , b₂))) (sym (get-set a b₂)) ∎) (remainder-set a b₁) ⟩ trans (cong proj₂ (_≃_.right-inverse-of equiv (remainder (set a b₁) , b₂))) (sym (get-set a b₂)) ≡⟨⟩ trans (get-set (set a b₁) b₂) (sym (get-set a b₂)) ∎ -- A somewhat coherent lens. coherent-lens : Traditional.Coherent-lens A B coherent-lens = record { lens = traditional-lens ; get-set-get = get-set-get ; get-set-set = get-set-set } instance -- Higher lenses 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 } ------------------------------------------------------------------------ -- Simple definitions related to lenses -- An η-law for lenses. η : (l : Lens A B) → ⟨ Lens.R l , Lens.equiv l , Lens.inhabited l ⟩ ≡ l η ⟨ _ , _ , _ ⟩ = refl _ -- Lens can be expressed as a nested Σ-type. Lens-as-Σ : {A : Type a} {B : Type b} → Lens A B ≃ ∃ λ (R : Type (a ⊔ b)) → (A ≃ (R × B)) × (R → ∥ B ∥) Lens-as-Σ = Eq.↔→≃ (λ l → R l , equiv l , inhabited l) (λ (R , equiv , inhabited) → record { R = R ; equiv = equiv ; inhabited = inhabited }) refl η where open Lens -- An equality rearrangement lemma. left-inverse-of-Lens-as-Σ : (l : Lens A B) → _≃_.left-inverse-of Lens-as-Σ l ≡ η l left-inverse-of-Lens-as-Σ l@(⟨ _ , _ , _ ⟩) = _≃_.left-inverse-of Lens-as-Σ l ≡⟨⟩ _≃_.left-inverse-of Lens-as-Σ (_≃_.from Lens-as-Σ (_≃_.to Lens-as-Σ l)) ≡⟨ sym $ _≃_.right-left-lemma Lens-as-Σ _ ⟩ cong (_≃_.from Lens-as-Σ) (_≃_.right-inverse-of Lens-as-Σ (_≃_.to Lens-as-Σ l)) ≡⟨⟩ cong (_≃_.from Lens-as-Σ) (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ -- Isomorphisms can be converted into lenses. isomorphism-to-lens : {A : Type a} {B : Type b} {R : Type (a ⊔ b)} → A ↔ R × B → Lens A B isomorphism-to-lens {A = A} {B = B} {R = R} iso = record { R = R × ∥ B ∥ ; equiv = A ↔⟨ iso ⟩ R × B ↔⟨ F.id ×-cong inverse ∥∥×↔ ⟩ R × ∥ B ∥ × B ↔⟨ ×-assoc ⟩□ (R × ∥ B ∥) × B □ ; inhabited = proj₂ } -- Converts equivalences to lenses. ≃→lens : {A : Type a} {B : Type b} → A ≃ B → Lens A B ≃→lens {a = a} {A = A} {B = B} A≃B = record { R = ∥ ↑ a B ∥ ; equiv = A ↝⟨ A≃B ⟩ B ↝⟨ inverse ∥∥×≃ ⟩ ∥ B ∥ × B ↔⟨ ∥∥-cong (inverse Bij.↑↔) ×-cong F.id ⟩□ ∥ ↑ a B ∥ × B □ ; inhabited = ∥∥-map lower } -- Converts equivalences between types with the same universe level to -- lenses. ≃→lens′ : {A B : Type a} → A ≃ B → Lens A B ≃→lens′ {a = a} {A = A} {B = B} A≃B = record { R = ∥ B ∥ ; equiv = A ↝⟨ A≃B ⟩ B ↝⟨ inverse ∥∥×≃ ⟩□ ∥ B ∥ × B □ ; inhabited = id } ------------------------------------------------------------------------ -- An example -- A lens from a type in a smaller universe to a type in a (possibly) -- larger universe. ↑-lens : Lens A (↑ ℓ A) ↑-lens = ≃→lens (Eq.↔⇒≃ $ inverse Bij.↑↔) ------------------------------------------------------------------------ -- Some results related to the remainder type -- The inhabited field is equivalent to stating that the remainder -- function is surjective. inhabited≃remainder-surjective : {A : Type a} {B : Type b} {R : Type (a ⊔ b)} (equiv : A ≃ (R × B)) → let remainder : A → R remainder a = proj₁ (_≃_.to equiv a) in (R → ∥ B ∥) ≃ Surjective remainder inhabited≃remainder-surjective eq = ∀-cong ext λ r → ∥∥-cong-⇔ (record { to = λ b → _≃_.from eq (r , b) , (proj₁ (_≃_.to eq (_≃_.from eq (r , b))) ≡⟨ cong proj₁ $ _≃_.right-inverse-of eq _ ⟩∎ r ∎) ; from = proj₂ ∘ _≃_.to eq ∘ proj₁ }) -- The remainder type of a lens l : Lens A B is, for every b : B, -- equivalent to the preimage of the getter with respect to b. -- -- This result was pointed out to me by Andrea Vezzosi. remainder≃get⁻¹ : (l : Lens A B) (b : B) → Lens.R l ≃ Lens.get l ⁻¹ b remainder≃get⁻¹ l b = Eq.↔→≃ (λ r → _≃_.from equiv (r , b) , (get (_≃_.from equiv (r , b)) ≡⟨⟩ proj₂ (_≃_.to equiv (_≃_.from equiv (r , b))) ≡⟨ cong proj₂ $ _≃_.right-inverse-of equiv _ ⟩∎ b ∎)) (λ (a , _) → remainder a) (λ (a , get-a≡b) → let lemma = cong get (trans (cong (set a) (sym get-a≡b)) (_≃_.left-inverse-of equiv _)) ≡⟨ cong-trans _ _ (_≃_.left-inverse-of equiv _) ⟩ trans (cong get (cong (set a) (sym get-a≡b))) (cong get (_≃_.left-inverse-of equiv _)) ≡⟨ cong₂ trans (cong-∘ _ _ (sym get-a≡b)) (sym $ cong-∘ _ _ (_≃_.left-inverse-of equiv _)) ⟩ trans (cong (get ∘ set a) (sym get-a≡b)) (cong proj₂ (cong (_≃_.to equiv) (_≃_.left-inverse-of equiv _))) ≡⟨ cong₂ (λ p q → trans p (cong proj₂ q)) (cong-sym _ get-a≡b) (_≃_.left-right-lemma equiv _) ⟩ trans (sym (cong (get ∘ set a) get-a≡b)) (cong proj₂ (_≃_.right-inverse-of equiv _)) ≡⟨ sym $ sym-sym _ ⟩ sym (sym (trans (sym (cong (get ∘ set a) get-a≡b)) (cong proj₂ (_≃_.right-inverse-of equiv _)))) ≡⟨ cong sym $ sym-trans _ (cong proj₂ (_≃_.right-inverse-of equiv _)) ⟩ sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (sym (sym (cong (get ∘ set a) get-a≡b)))) ≡⟨ cong (λ eq → sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) eq)) $ sym-sym (cong (get ∘ set a) get-a≡b) ⟩∎ sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong (get ∘ set a) get-a≡b)) ∎ in Σ-≡,≡→≡ (_≃_.from equiv (remainder a , b) ≡⟨⟩ set a b ≡⟨ cong (set a) (sym get-a≡b) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎) (subst (λ a → get a ≡ b) (trans (cong (set a) (sym get-a≡b)) (set-get a)) (cong proj₂ $ _≃_.right-inverse-of equiv (remainder a , b)) ≡⟨⟩ subst (λ a → get a ≡ b) (trans (cong (set a) (sym get-a≡b)) (_≃_.left-inverse-of equiv _)) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ subst-∘ _ _ (trans _ (_≃_.left-inverse-of equiv _)) ⟩ subst (_≡ b) (cong get (trans (cong (set a) (sym get-a≡b)) (_≃_.left-inverse-of equiv _))) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (λ eq → subst (_≡ b) eq (cong proj₂ $ _≃_.right-inverse-of equiv _)) lemma ⟩ subst (_≡ b) (sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong (get ∘ set a) get-a≡b))) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ subst-trans (trans _ (cong (get ∘ set a) get-a≡b)) ⟩ trans (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong (get ∘ set a) get-a≡b)) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ elim¹ (λ eq → trans (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong (get ∘ set a) eq)) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡ eq) ( trans (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong (get ∘ set a) (refl _))) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (λ eq → trans (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) eq) (cong proj₂ $ _≃_.right-inverse-of equiv _)) $ cong-refl _ ⟩ trans (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (refl _)) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩ trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _))) (cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ trans-symˡ (cong proj₂ (_≃_.right-inverse-of equiv _)) ⟩∎ refl _ ∎) get-a≡b ⟩∎ get-a≡b ∎)) (λ r → remainder (_≃_.from equiv (r , b)) ≡⟨⟩ proj₁ (_≃_.to equiv (_≃_.from equiv (r , b))) ≡⟨ cong proj₁ $ _≃_.right-inverse-of equiv _ ⟩∎ r ∎) where open Lens l -- A corollary: Lens.get l ⁻¹_ is constant (up to equivalence). -- -- Paolo Capriotti discusses this kind of property -- (http://homotopytypetheory.org/2014/04/29/higher-lenses/). get⁻¹-constant : (l : Lens A B) (b₁ b₂ : B) → Lens.get l ⁻¹ b₁ ≃ Lens.get l ⁻¹ b₂ get⁻¹-constant l b₁ b₂ = Lens.get l ⁻¹ b₁ ↝⟨ inverse $ remainder≃get⁻¹ l b₁ ⟩ Lens.R l ↝⟨ remainder≃get⁻¹ l b₂ ⟩□ Lens.get l ⁻¹ b₂ □ -- The two directions of get⁻¹-constant. get⁻¹-const : (l : Lens A B) (b₁ b₂ : B) → Lens.get l ⁻¹ b₁ → Lens.get l ⁻¹ b₂ get⁻¹-const l b₁ b₂ = _≃_.to (get⁻¹-constant l b₁ b₂) get⁻¹-const⁻¹ : (l : Lens A B) (b₁ b₂ : B) → Lens.get l ⁻¹ b₂ → Lens.get l ⁻¹ b₁ get⁻¹-const⁻¹ l b₁ b₂ = _≃_.from (get⁻¹-constant l b₁ b₂) -- The set function can be expressed using get⁻¹-const and get. -- -- Paolo Capriotti defines set in a similar way -- (http://homotopytypetheory.org/2014/04/29/higher-lenses/). set-in-terms-of-get⁻¹-const : (l : Lens A B) → Lens.set l ≡ λ a b → proj₁ (get⁻¹-const l (Lens.get l a) b (a , refl _)) set-in-terms-of-get⁻¹-const l = refl _ -- The remainder function can be expressed using remainder≃get⁻¹ and -- get. remainder-in-terms-of-remainder≃get⁻¹ : (l : Lens A B) → Lens.remainder l ≡ λ a → _≃_.from (remainder≃get⁻¹ l (Lens.get l a)) (a , refl _) remainder-in-terms-of-remainder≃get⁻¹ l = refl _ -- The functions get⁻¹-const and get⁻¹-const⁻¹ satisfy some coherence -- properties. -- -- The first and third properties are discussed by Paolo Capriotti -- (http://homotopytypetheory.org/2014/04/29/higher-lenses/). get⁻¹-const-∘ : (l : Lens A B) (b₁ b₂ b₃ : B) (p : Lens.get l ⁻¹ b₁) → get⁻¹-const l b₂ b₃ (get⁻¹-const l b₁ b₂ p) ≡ get⁻¹-const l b₁ b₃ p get⁻¹-const-∘ l _ b₂ b₃ p = from (r₂ , b₃) , cong proj₂ (right-inverse-of (r₂ , b₃)) ≡⟨ cong (λ r → from (r , b₃) , cong proj₂ (right-inverse-of (r , b₃))) $ cong proj₁ $ right-inverse-of _ ⟩∎ from (r₁ , b₃) , cong proj₂ (right-inverse-of (r₁ , b₃)) ∎ where open Lens l open _≃_ equiv r₁ r₂ : R r₁ = proj₁ (to (proj₁ p)) r₂ = proj₁ (to (from (r₁ , b₂))) get⁻¹-const-inverse : (l : Lens A B) (b₁ b₂ : B) (p : Lens.get l ⁻¹ b₁) → get⁻¹-const l b₁ b₂ p ≡ get⁻¹-const⁻¹ l b₂ b₁ p get⁻¹-const-inverse _ _ _ _ = refl _ get⁻¹-const-id : (l : Lens A B) (b : B) (p : Lens.get l ⁻¹ b) → get⁻¹-const l b b p ≡ p get⁻¹-const-id l b p = get⁻¹-const l b b p ≡⟨ sym $ get⁻¹-const-∘ l b _ _ p ⟩ get⁻¹-const l b b (get⁻¹-const l b b p) ≡⟨⟩ get⁻¹-const⁻¹ l b b (get⁻¹-const l b b p) ≡⟨ _≃_.left-inverse-of (get⁻¹-constant l b b) _ ⟩∎ p ∎ -- Another kind of coherence property does not hold for get⁻¹-const. -- -- This kind of property came up in a discussion with Andrea Vezzosi. get⁻¹-const-not-coherent : ¬ ({A B : Type} (l : Lens A B) (b₁ b₂ : B) (f : ∀ b → Lens.get l ⁻¹ b) → get⁻¹-const l b₁ b₂ (f b₁) ≡ f b₂) get⁻¹-const-not-coherent = ({A B : Type} (l : Lens A B) (b₁ b₂ : B) (f : ∀ b → Lens.get l ⁻¹ b) → get⁻¹-const l b₁ b₂ (f b₁) ≡ f b₂) ↝⟨ (λ hyp → hyp l true false f) ⟩ get⁻¹-const l true false (f true) ≡ f false ↝⟨ cong (proj₁ ∘ proj₁) ⟩ true ≡ false ↝⟨ Bool.true≢false ⟩□ ⊥ □ where l : Lens (Bool × Bool) Bool l = record { R = Bool ; equiv = F.id ; inhabited = ∣_∣ } f : ∀ b → Lens.get l ⁻¹ b f b = (b , b) , refl _ -- If B is inhabited whenever it is merely inhabited, then the -- remainder type of a lens of type Lens A B can be expressed in terms -- of preimages of the lens's getter. remainder≃∃get⁻¹ : (l : Lens A B) (∥B∥→B : ∥ B ∥ → B) → Lens.R l ≃ ∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b) remainder≃∃get⁻¹ {B = B} l ∥B∥→B = R ↔⟨ (inverse $ drop-⊤-left-× λ r → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible truncation-is-proposition (inhabited r)) ⟩ ∥ B ∥ × R ↝⟨ (∃-cong λ _ → remainder≃get⁻¹ l _) ⟩□ (∃ λ (b : ∥ B ∥) → get ⁻¹ (∥B∥→B b)) □ where open Lens l ------------------------------------------------------------------------ -- Equality characterisations for lenses -- An equality characterisation lemma. equality-characterisation₀ : let open Lens in {l₁ l₂ : Lens A B} → Block "equality-characterisation" → l₁ ≡ l₂ ↔ ∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂ equality-characterisation₀ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} ⊠ = l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens-as-Σ ⟩ l₁′ ≡ l₂′ ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩ (∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B) × (R → ∥ B ∥)) p (proj₂ l₁′) ≡ proj₂ l₂′) ↝⟨ (∃-cong λ _ → inverse $ ignore-propositional-component (Π-closure ext 1 λ _ → truncation-is-proposition)) ⟩ (∃ λ (p : R l₁ ≡ R l₂) → proj₁ (subst (λ R → A ≃ (R × B) × (R → ∥ B ∥)) p (proj₂ l₁′)) ≡ equiv l₂) ↔⟨ (∃-cong λ _ → ≡⇒≃ $ cong (λ (eq , _) → eq ≡ _) $ push-subst-, _ _) ⟩□ (∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) □ where open Lens l₁′ = _≃_.to Lens-as-Σ l₁ l₂′ = _≃_.to Lens-as-Σ l₂ -- A "computation" rule. from-equality-characterisation₀ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} (b : Block "equality-characterisation") → {p : R l₁ ≡ R l₂} {q : subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂} → _↔_.from (equality-characterisation₀ {l₁ = l₁} {l₂ = l₂} b) (p , q) ≡ trans (sym (η l₁)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) (η l₂)) from-equality-characterisation₀ ⊠ {p = p} {q = q} = trans (sym (_≃_.left-inverse-of Lens-as-Σ _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (_↔_.to (ignore-propositional-component (Π-closure ext 1 λ _ → truncation-is-proposition)) (_≃_.from (≡⇒≃ (cong (λ (eq , _) → eq ≡ _) (push-subst-, _ _))) q)))) (_≃_.left-inverse-of Lens-as-Σ _)) ≡⟨ cong (λ eq → trans (sym (_≃_.left-inverse-of Lens-as-Σ _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (_↔_.to (ignore-propositional-component (Π-closure ext 1 λ _ → truncation-is-proposition)) (_≃_.to eq q)))) (_≃_.left-inverse-of Lens-as-Σ _))) $ trans (sym $ ≡⇒≃-sym ext _) $ cong ≡⇒≃ $ sym $ cong-sym _ _ ⟩ trans (sym (_≃_.left-inverse-of Lens-as-Σ _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (_↔_.to (ignore-propositional-component (Π-closure ext 1 λ _ → truncation-is-proposition)) (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q)))) (_≃_.left-inverse-of Lens-as-Σ _)) ≡⟨⟩ trans (sym (_≃_.left-inverse-of Lens-as-Σ _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) (_≃_.left-inverse-of Lens-as-Σ _)) ≡⟨ cong₂ (λ eq₁ eq₂ → trans (sym eq₁) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) eq₂)) (left-inverse-of-Lens-as-Σ _) (left-inverse-of-Lens-as-Σ _) ⟩ trans (sym (η _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ p (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) (η _)) ∎ -- A variant of the computation rule above. cong-set-from-equality-characterisation₀ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} (b : Block "equality-characterisation") → {p : R l₁ ≡ R l₂} {q : subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂} → cong set (_↔_.from (equality-characterisation₀ {l₁ = l₁} {l₂ = l₂} b) (p , q)) ≡ cong (λ (_ , equiv) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (Σ-≡,≡→≡ p q) cong-set-from-equality-characterisation₀ {B = B} {l₁ = l₁@(⟨ _ , _ , _ ⟩)} {l₂ = l₂@(⟨ _ , _ , _ ⟩)} b {p = p} {q = q} = elim₁ (λ {R₁} p → ∀ equiv₁ inhabited₁ q → cong set (_↔_.from (equality-characterisation₀ {l₁ = ⟨ R₁ , equiv₁ , inhabited₁ ⟩} {l₂ = l₂} b) (p , q)) ≡ cong (λ (_ , equiv) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (Σ-≡,≡→≡ p q)) (λ equiv₁ inhabited₁ q → cong set (_↔_.from (equality-characterisation₀ b) (refl _ , q)) ≡⟨ cong (cong set) $ from-equality-characterisation₀ b ⟩ cong set (trans (sym (refl _)) (trans (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ (refl _) (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) (refl _))) ≡⟨ trans (cong₂ (λ eq₁ eq₂ → cong set (trans eq₁ eq₂)) sym-refl (trans-reflʳ _)) $ cong (cong set) $ trans-reflˡ _ ⟩ cong set (cong (_≃_.from Lens-as-Σ) (Σ-≡,≡→≡ (refl _) (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) ≡⟨ cong-∘ _ _ _ ⟩ cong (λ (_ , equiv , _) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (Σ-≡,≡→≡ (refl _) (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition))))) ≡⟨ cong (cong _) $ Σ-≡,≡→≡-reflˡ _ ⟩ cong (λ (_ , equiv , _) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (cong (_ ,_) (trans (sym $ subst-refl _ _) (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) ≡⟨ cong-∘ _ _ _ ⟩ cong (λ (equiv , _) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (trans (sym $ subst-refl _ _) (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition))))) ≡⟨ trans (sym $ cong-∘ _ _ _) $ cong (cong _) $ cong-trans _ _ _ ⟩ cong (λ equiv a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (trans (cong proj₁ (sym $ subst-refl _ _)) (cong proj₁ (Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) (proj₁ (+⇒≡ (Π-closure ext 1 λ _ → truncation-is-proposition)))))) ≡⟨ cong (λ eq → cong _ (trans (cong proj₁ (sym $ subst-refl _ _)) eq)) $ proj₁-Σ-≡,≡→≡ (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ (λ R → R → ∥ B ∥)))) q) _ ⟩ cong (λ equiv a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (trans (cong proj₁ (sym $ subst-refl _ _)) (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q)) ≡⟨ cong (cong _) $ elim¹ (λ q → trans (cong proj₁ (sym $ subst-refl _ _)) (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) q) ≡ trans (sym $ subst-refl _ _) q) ( trans (cong proj₁ $ sym $ subst-refl _ _) (≡⇒→ (cong (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _))) (refl _)) ≡⟨ cong (trans _) $ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩ trans (cong proj₁ $ sym $ subst-refl _ _) (subst (λ (eq , _) → eq ≡ _) (sym (push-subst-, _ _)) (refl _)) ≡⟨ cong (trans _) $ subst-∘ _ _ _ ⟩ trans (cong proj₁ $ sym $ subst-refl _ _) (subst (_≡ _) (cong proj₁ $ sym $ push-subst-, _ _) (refl _)) ≡⟨ cong (trans _) $ trans subst-trans-sym $ trans (trans-reflʳ _) $ trans (sym (cong-sym _ _)) $ cong (cong _) $ sym-sym _ ⟩ trans (cong proj₁ $ sym $ subst-refl _ _) (cong proj₁ $ push-subst-, {y≡z = refl _} _ _) ≡⟨ cong₂ trans (cong-sym _ _) (proj₁-push-subst-,-refl _ _) ⟩ trans (sym $ cong proj₁ $ subst-refl _ _) (trans (cong proj₁ (subst-refl _ _)) (sym $ subst-refl _ _)) ≡⟨ trans-sym-[trans] _ _ ⟩ sym (subst-refl _ _) ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (sym $ subst-refl _ _) (refl _) ∎) q ⟩ cong (λ equiv a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (trans (sym $ subst-refl _ _) q) ≡⟨ sym $ cong-∘ _ _ _ ⟩ cong (λ (_ , equiv) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (cong (_ ,_) (trans (sym $ subst-refl _ _) q)) ≡⟨ cong (cong _) $ sym $ Σ-≡,≡→≡-reflˡ _ ⟩∎ cong (λ (_ , equiv) a b → _≃_.from equiv (proj₁ (_≃_.to equiv a) , b)) (Σ-≡,≡→≡ (refl _) q) ∎) _ _ _ _ where open Lens -- An equality characterisation lemma. equality-characterisation₀₁ : let open Lens in {l₁ l₂ : Lens A B} → Block "equality-characterisation" → (l₁ ≡ l₂) ≃ ∃ λ (p : R l₁ ≡ R l₂) → ∀ a → (subst id p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a equality-characterisation₀₁ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} ⊠ = l₁ ≡ l₂ ↔⟨ equality-characterisation₀ ⊠ ⟩ (∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) ↝⟨ (∃-cong λ _ → inverse $ ≃-to-≡≃≡ ext ext) ⟩ (∃ λ (p : R l₁ ≡ R l₂) → ∀ a → _≃_.to (subst (λ R → A ≃ (R × B)) p (equiv l₁)) a ≡ _≃_.to (equiv l₂) a) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ≡⇒≃ $ cong (_≡ _) $ trans (cong (_$ _) $ Eq.to-subst) $ trans (sym $ push-subst-application _ _) $ trans (push-subst-, _ _) $ cong (subst id _ _ ,_) $ subst-const _) ⟩□ (∃ λ (p : R l₁ ≡ R l₂) → ∀ a → (subst id p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) □ where open Lens private -- An equality characterisation lemma with a "computation" rule. equality-characterisation₁′ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} (bl : Block "equality-characterisation₀") → Block "equality-characterisation₁" → (univ : Univalence (a ⊔ b)) → ∃ λ (eq : l₁ ≡ l₂ ↔ ∃ λ (p : R l₁ ≃ R l₂) → ∀ a → (_≃_.to p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) → (p : R l₁ ≃ R l₂) (q : ∀ a → (_≃_.to p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) → _↔_.from eq (p , q) ≡ _↔_.from (equality-characterisation₀ bl) ( ≃⇒≡ univ p , Eq.lift-equality ext (trans (≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) (trans (cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) (≃⇒≡-id univ)) (cong _≃_.to $ subst-refl _ _)) p) (⟨ext⟩ q)) ) equality-characterisation₁′ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} b ⊠ univ = (l₁ ≡ l₂ ↝⟨ equality-characterisation₀ b ⟩ (∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) ↝⟨ inverse $ Σ-cong (inverse $ ≡≃≃ univ) (λ _ → F.id) ⟩ (∃ λ (p : R l₁ ≃ R l₂) → subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁) ≡ equiv l₂) ↔⟨ (∃-cong λ _ → inverse $ ≃-to-≡≃≡ ext bad-ext) ⟩ (∃ λ (p : R l₁ ≃ R l₂) → ∀ a → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) a ≡ _≃_.to (equiv l₂) a) ↔⟨ (∃-cong λ p → ∀-cong ext λ a → inverse $ ≡⇒≃ $ cong (_≡ _) $ sym $ cong (_$ a) $ ≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) ( _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ Eq.id) (equiv l₁)) ≡⟨ cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) $ ≃⇒≡-id univ ⟩ _≃_.to (subst (λ R → A ≃ (R × B)) (refl _) (equiv l₁)) ≡⟨ cong _≃_.to $ subst-refl _ _ ⟩∎ _≃_.to (equiv l₁) ∎) p) ⟩□ (∃ λ (p : R l₁ ≃ R l₂) → ∀ a → (_≃_.to p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) □) , λ p q → _↔_.from (equality-characterisation₀ b) ( ≃⇒≡ univ p , Eq.lift-equality ext (⟨ext⟩ λ a → ≡⇒→ (cong (_≡ _) $ sym $ cong (_$ a) $ ≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) (trans (cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) (≃⇒≡-id univ)) (cong _≃_.to $ subst-refl _ _)) p) (q a)) ) ≡⟨ (cong (λ eq → _↔_.from (equality-characterisation₀ b) (≃⇒≡ univ p , Eq.lift-equality ext (⟨ext⟩ eq))) $ ⟨ext⟩ λ a → trans (sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _) $ subst-trans _) ⟩ _↔_.from (equality-characterisation₀ b) ( ≃⇒≡ univ p , Eq.lift-equality ext (⟨ext⟩ λ a → trans (cong (_$ a) $ ≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) (trans (cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) (≃⇒≡-id univ)) (cong _≃_.to $ subst-refl _ _)) p) (q a)) ) ≡⟨ cong (λ eq → _↔_.from (equality-characterisation₀ b) (≃⇒≡ univ p , Eq.lift-equality ext eq)) $ trans (ext-trans _ _) $ cong (flip trans _) $ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩ _↔_.from (equality-characterisation₀ b) ( ≃⇒≡ univ p , Eq.lift-equality ext (trans (≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) (trans (cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) (≃⇒≡-id univ)) (cong _≃_.to $ subst-refl _ _)) p) (⟨ext⟩ q)) ) ∎ where open Lens -- An equality characterisation lemma. equality-characterisation₁ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → Block "equality-characterisation" → Univalence (a ⊔ b) → l₁ ≡ l₂ ↔ ∃ λ (p : R l₁ ≃ R l₂) → ∀ a → (_≃_.to p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a equality-characterisation₁ b univ = proj₁ (equality-characterisation₁′ b b univ) -- A "computation" rule. from-equality-characterisation₁ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} (bl : Block "equality-characterisation") → (univ : Univalence (a ⊔ b)) (p : R l₁ ≃ R l₂) (q : ∀ a → (_≃_.to p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) → _↔_.from (equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} bl univ) (p , q) ≡ _↔_.from (equality-characterisation₀ bl) ( ≃⇒≡ univ p , Eq.lift-equality ext (trans (≃-elim¹ univ (λ {R} p → _≃_.to (subst (λ R → A ≃ (R × B)) (≃⇒≡ univ p) (equiv l₁)) ≡ (λ a → _≃_.to p (remainder l₁ a) , get l₁ a)) (trans (cong (λ eq → _≃_.to (subst (λ R → A ≃ (R × B)) eq (equiv l₁))) (≃⇒≡-id univ)) (cong _≃_.to $ subst-refl _ _)) p) (⟨ext⟩ q)) ) from-equality-characterisation₁ b univ _ _ = proj₂ (equality-characterisation₁′ b b univ) _ _ -- An equality characterisation lemma. equality-characterisation₀₂ : let open Lens in {l₁ l₂ : Lens A B} → Block "equality-characterisation" → (l₁ ≡ l₂) ≃ ∃ λ (p : R l₁ ≡ R l₂) → (∀ a → subst id p (remainder l₁ a) ≡ remainder l₂ a) × (∀ a → get l₁ a ≡ get l₂ a) equality-characterisation₀₂ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} ⊠ = l₁ ≡ l₂ ↝⟨ equality-characterisation₀₁ ⊠ ⟩ (∃ λ (p : R l₁ ≡ R l₂) → ∀ a → (subst id p (remainder l₁ a) , get l₁ a) ≡ _≃_.to (equiv l₂) a) ↔⟨⟩ (∃ λ (p : R l₁ ≡ R l₂) → ∀ a → (subst id p (remainder l₁ a) , get l₁ a) ≡ (remainder l₂ a , get l₂ a)) ↔⟨ (∃-cong λ _ → ∀-cong ext λ _ → inverse ≡×≡↔≡) ⟩ (∃ λ (p : R l₁ ≡ R l₂) → ∀ a → subst id p (remainder l₁ a) ≡ remainder l₂ a × get l₁ a ≡ get l₂ a) ↔⟨ (∃-cong λ _ → ΠΣ-comm) ⟩□ (∃ λ (p : R l₁ ≡ R l₂) → (∀ a → subst id p (remainder l₁ a) ≡ remainder l₂ a) × (∀ a → get l₁ a ≡ get l₂ a)) □ where open Lens private -- An equality characterisation lemma with a "computation" rule. equality-characterisation₂′ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → let open Lens in (bl : Block "equality-characterisation₁") → Block "equality-characterisation₂" → (univ : Univalence (a ⊔ b)) → ∃ λ (eq : l₁ ≡ l₂ ↔ ∃ λ (r : R l₁ ≃ R l₂) → (∀ x → _≃_.to r (remainder l₁ x) ≡ remainder l₂ x) × (∀ x → get l₁ x ≡ get l₂ x)) → (r₁ : R l₁ ≃ R l₂) (r₂ : ∀ x → _≃_.to r₁ (remainder l₁ x) ≡ remainder l₂ x) (g : ∀ x → get l₁ x ≡ get l₂ x) → _↔_.from eq (r₁ , r₂ , g) ≡ _↔_.from (equality-characterisation₁ bl univ) (r₁ , λ a → cong₂ _,_ (r₂ a) (g a)) equality-characterisation₂′ {l₁ = l₁} {l₂ = l₂} bl ⊠ univ = (l₁ ≡ l₂ ↝⟨ equality-characterisation₁ bl univ ⟩ (∃ λ (eq : R l₁ ≃ R l₂) → ∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡ _≃_.to (equiv l₂) x) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → inverse ≡×≡↔≡) ⟩ (∃ λ (eq : R l₁ ≃ R l₂) → ∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x × get l₁ x ≡ get l₂ x) ↝⟨ (∃-cong λ _ → ΠΣ-comm) ⟩□ (∃ λ (eq : R l₁ ≃ R l₂) → (∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x) × (∀ x → get l₁ x ≡ get l₂ x)) □) , λ _ _ _ → refl _ where open Lens -- An equality characterisation lemma. equality-characterisation₂ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → let open Lens in Block "equality-characterisation" → Univalence (a ⊔ b) → l₁ ≡ l₂ ↔ ∃ λ (eq : R l₁ ≃ R l₂) → (∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x) × (∀ x → get l₁ x ≡ get l₂ x) equality-characterisation₂ bl univ = proj₁ (equality-characterisation₂′ bl bl univ) -- A "computation" rule. from-equality-characterisation₂ : let open Lens in {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} (bl : Block "equality-characterisation") → (univ : Univalence (a ⊔ b)) (r₁ : R l₁ ≃ R l₂) (r₂ : ∀ x → _≃_.to r₁ (remainder l₁ x) ≡ remainder l₂ x) (g : ∀ x → get l₁ x ≡ get l₂ x) → _↔_.from (equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} bl univ) (r₁ , r₂ , g) ≡ _↔_.from (equality-characterisation₁ bl univ) (r₁ , λ a → cong₂ _,_ (r₂ a) (g a)) from-equality-characterisation₂ bl univ = proj₂ (equality-characterisation₂′ bl bl univ) -- An equality characterisation lemma. equality-characterisation₃ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → let open Lens in Univalence (a ⊔ b) → l₁ ≡ l₂ ↔ ∃ λ (eq : R l₁ ≃ R l₂) → ∀ p → _≃_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡ _≃_.from (equiv l₂) p equality-characterisation₃ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} univ = l₁ ≡ l₂ ↝⟨ equality-characterisation₀ ⊠ ⟩ (∃ λ (p : R l₁ ≡ R l₂) → subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) ↝⟨ inverse $ Σ-cong (inverse $ ≡≃≃ univ) (λ _ → F.id) ⟩ (∃ λ (eq : R l₁ ≃ R l₂) → subst (λ R → A ≃ (R × B)) (≃⇒≡ univ eq) (equiv l₁) ≡ equiv l₂) ↔⟨ (∃-cong λ _ → inverse $ ≡⇒≃ $ cong (_≡ _) $ transport-theorem (λ R → A ≃ (R × B)) (λ X≃Y → (X≃Y ×-cong F.id) F.∘_) (λ _ → Eq.lift-equality ext (refl _)) univ _ _) ⟩ (∃ λ (eq : R l₁ ≃ R l₂) → (eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂) ↝⟨ (∃-cong λ _ → inverse $ ≃-from-≡↔≡ ext) ⟩□ (∃ λ (eq : R l₁ ≃ R l₂) → ∀ p → _≃_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡ _≃_.from (equiv l₂) p) □ where open Lens -- An equality characterisation lemma for lenses for which the view -- type is inhabited. equality-characterisation₄ : {A : Type a} {B : Type b} {l₁ l₂ : Lens A B} → let open Lens in Block "equality-characterisation" → Univalence (a ⊔ b) → (b : B) → (l₁ ≡ l₂) ≃ (∃ λ (eq : get l₁ ⁻¹ b ≃ get l₂ ⁻¹ b) → (∀ a → _≃_.to eq (set l₁ a b , get-set l₁ a b) ≡ (set l₂ a b , get-set l₂ a b)) × (∀ a → get l₁ a ≡ get l₂ a)) equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} bl univ b = l₁ ≡ l₂ ↔⟨ equality-characterisation₂ bl univ ⟩ (∃ λ (eq : R l₁ ≃ R l₂) → (∀ a → _≃_.to eq (remainder l₁ a) ≡ remainder l₂ a) × (∀ a → get l₁ a ≡ get l₂ a)) ↝⟨ inverse $ Σ-cong (inverse $ Eq.≃-preserves ext (remainder≃get⁻¹ l₁ b) (remainder≃get⁻¹ l₂ b)) (λ _ → F.id) ⟩ (∃ λ (eq : get l₁ ⁻¹ b ≃ get l₂ ⁻¹ b) → (∀ a → remainder l₂ (proj₁ (_≃_.to eq (set l₁ a b , get-set l₁ a b))) ≡ remainder l₂ a) × (∀ a → get l₁ a ≡ get l₂ a)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ → ∀-cong ext λ a → ≡⇒≃ $ cong (remainder l₂ _ ≡_) $ sym $ remainder-set l₂ _ _) ⟩ (∃ λ (eq : get l₁ ⁻¹ b ≃ get l₂ ⁻¹ b) → (∀ a → remainder l₂ (proj₁ (_≃_.to eq (set l₁ a b , get-set l₁ a b))) ≡ remainder l₂ (set l₂ a b)) × (∀ a → get l₁ a ≡ get l₂ a)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ _ → ∀-cong ext λ a → Eq.≃-≡ (inverse $ remainder≃get⁻¹ l₂ b)) ⟩□ (∃ λ (eq : get l₁ ⁻¹ b ≃ get l₂ ⁻¹ b) → (∀ a → _≃_.to eq (set l₁ a b , get-set l₁ a b) ≡ (set l₂ a b , get-set l₂ a b)) × (∀ a → get l₁ a ≡ get l₂ a)) □ where open Lens ------------------------------------------------------------------------ -- More lens equalities -- If the forward direction of an equivalence is Lens.get l, then the -- setter of l can be expressed using the other direction of the -- equivalence. from≡set : ∀ (l : Lens A B) is-equiv → let open Lens A≃B = Eq.⟨ get l , is-equiv ⟩ in ∀ a b → _≃_.from A≃B b ≡ set l a b from≡set l is-equiv a b = _≃_.to-from Eq.⟨ get , is-equiv ⟩ ( get (set a b) ≡⟨ get-set _ _ ⟩∎ b ∎) where open Lens l -- If two lenses have equal setters, then they also have equal -- getters. getters-equal-if-setters-equal : let open Lens in (l₁ l₂ : Lens A B) → set l₁ ≡ set l₂ → get l₁ ≡ get l₂ getters-equal-if-setters-equal l₁ l₂ setters-equal = ⟨ext⟩ λ a → get l₁ a ≡⟨ cong (get l₁) $ sym $ set-get l₂ _ ⟩ get l₁ (set l₂ a (get l₂ a)) ≡⟨ cong (λ f → get l₁ (f a (get l₂ a))) $ sym setters-equal ⟩ get l₁ (set l₁ a (get l₂ a)) ≡⟨ get-set l₁ _ _ ⟩∎ get l₂ a ∎ where open Lens -- Two lenses of type Lens A B are equal if B is inhabited and the -- lenses' setters are equal (assuming univalence). -- -- Some results below are more general than this one, but this proof, -- which uses remainder≃get⁻¹, is rather easy. lenses-with-inhabited-codomains-equal-if-setters-equal : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (l₁ l₂ : Lens A B) → B → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-with-inhabited-codomains-equal-if-setters-equal {B = B} univ l₁ l₂ b setters-equal = _↔_.from (equality-characterisation₂ ⊠ univ) ( R≃R , (λ a → remainder l₂ (set l₁ a b) ≡⟨ cong (λ f → remainder l₂ (f a b)) setters-equal ⟩ remainder l₂ (set l₂ a b) ≡⟨ remainder-set l₂ _ _ ⟩∎ remainder l₂ a ∎) , getters-equal ) where open Lens getters-equal = ext⁻¹ $ getters-equal-if-setters-equal l₁ l₂ setters-equal R≃R : R l₁ ≃ R l₂ R≃R = R l₁ ↝⟨ remainder≃get⁻¹ l₁ b ⟩ get l₁ ⁻¹ b ↔⟨ Preimage.respects-extensional-equality getters-equal ⟩ get l₂ ⁻¹ b ↝⟨ inverse $ remainder≃get⁻¹ l₂ b ⟩□ R l₂ □ -- A generalisation of lenses-equal-if-setters-equal (which is defined -- below). lenses-equal-if-setters-equal′ : let open Lens in {A : Type a} {B : Type b} (univ : Univalence (a ⊔ b)) (l₁ l₂ : Lens A B) (f : R l₁ → R l₂) → (B → ∀ r → ∃ λ b′ → remainder l₂ (_≃_.from (equiv l₁) (r , b′)) ≡ f r) → (∀ a → f (remainder l₁ a) ≡ remainder l₂ a) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-equal-if-setters-equal′ {A = A} {B = B} univ l₁ l₂ f ∃≡f f-remainder≡remainder setters-equal = _↔_.from (equality-characterisation₂ ⊠ univ) ( R≃R , f-remainder≡remainder , ext⁻¹ (getters-equal-if-setters-equal l₁ l₂ setters-equal) ) where open Lens open _≃_ BR≃BR = B × R l₁ ↔⟨ ×-comm ⟩ R l₁ × B ↝⟨ inverse (equiv l₁) ⟩ A ↝⟨ equiv l₂ ⟩ R l₂ × B ↔⟨ ×-comm ⟩□ B × R l₂ □ to-BR≃BR : ∀ b b′ r → to BR≃BR (b , r) ≡ (b , remainder l₂ (from (equiv l₁) (r , b′))) to-BR≃BR b b′ r = swap (to (equiv l₂) (from (equiv l₁) (swap (b , r)))) ≡⟨ cong swap lemma ⟩ swap (swap (b , remainder l₂ (from (equiv l₁) (r , b′)))) ≡⟨⟩ b , remainder l₂ (from (equiv l₁) (r , b′)) ∎ where lemma = to (equiv l₂) (from (equiv l₁) (swap (b , r))) ≡⟨⟩ to (equiv l₂) (from (equiv l₁) (r , b)) ≡⟨ cong (λ r → to (equiv l₂) (from (equiv l₁) (proj₁ r , b))) $ sym $ right-inverse-of (equiv l₁) _ ⟩ to (equiv l₂) (from (equiv l₁) (proj₁ (to (equiv l₁) (from (equiv l₁) (r , b′))) , b)) ≡⟨⟩ to (equiv l₂) (set l₁ (from (equiv l₁) (r , b′)) b) ≡⟨ cong (to (equiv l₂)) $ ext⁻¹ (ext⁻¹ setters-equal _) _ ⟩ to (equiv l₂) (set l₂ (from (equiv l₁) (r , b′)) b) ≡⟨⟩ to (equiv l₂) (from (equiv l₂) (remainder l₂ (from (equiv l₁) (r , b′)) , b)) ≡⟨ right-inverse-of (equiv l₂) _ ⟩ remainder l₂ (from (equiv l₁) (r , b′)) , b ≡⟨⟩ swap (b , remainder l₂ (from (equiv l₁) (r , b′))) ∎ id-f≃ : Eq.Is-equivalence (Σ-map id f) id-f≃ = Eq.respects-extensional-equality (λ (b , r) → let b′ , ≡fr = ∃≡f b r in to BR≃BR (b , r) ≡⟨ to-BR≃BR _ _ _ ⟩ b , remainder l₂ (from (equiv l₁) (r , b′)) ≡⟨ cong (b ,_) ≡fr ⟩ b , f r ≡⟨⟩ Σ-map id f (b , r) ∎) (is-equivalence BR≃BR) f≃ : Eq.Is-equivalence f f≃ = HA.[inhabited→Is-equivalence]→Is-equivalence λ r → Trunc.rec (Eq.propositional ext _) (Eq.drop-Σ-map-id _ id-f≃) (inhabited l₂ r) R≃R : R l₁ ≃ R l₂ R≃R = Eq.⟨ f , f≃ ⟩ -- If the codomain of a lens is inhabited when it is merely inhabited -- and the remainder type is inhabited, then this lens is equal to -- another lens if their setters are equal (assuming univalence). lenses-equal-if-setters-equal : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (l₁ l₂ : Lens A B) → (Lens.R l₁ → ∥ B ∥ → B) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-equal-if-setters-equal {B = B} univ l₁ l₂ inh′ setters-equal = lenses-equal-if-setters-equal′ univ l₁ l₂ f (λ _ r → inh r , (remainder l₂ (_≃_.from (equiv l₁) (r , inh r)) ≡⟨⟩ f r ∎)) (λ a → f (remainder l₁ a) ≡⟨⟩ remainder l₂ (set l₁ a (inh (remainder l₁ a))) ≡⟨ cong (remainder l₂) $ ext⁻¹ (ext⁻¹ setters-equal _) _ ⟩ remainder l₂ (set l₂ a (inh (remainder l₁ a))) ≡⟨ remainder-set l₂ _ _ ⟩∎ remainder l₂ a ∎) setters-equal where open Lens inh : Lens.R l₁ → B inh r = inh′ r (inhabited l₁ r) f : R l₁ → R l₂ f r = remainder l₂ (_≃_.from (equiv l₁) (r , inh r)) -- If a lens has a propositional remainder type, then this lens is -- equal to another lens if their setters are equal (assuming -- univalence). lenses-equal-if-setters-equal-and-remainder-propositional : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (l₁ l₂ : Lens A B) → Is-proposition (Lens.R l₂) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-equal-if-setters-equal-and-remainder-propositional univ l₁ l₂ R₂-prop = lenses-equal-if-setters-equal′ univ l₁ l₂ f (λ b r → b , (remainder l₂ (_≃_.from (equiv l₁) (r , b)) ≡⟨ R₂-prop _ _ ⟩∎ f r ∎)) (λ a → f (remainder l₁ a) ≡⟨ R₂-prop _ _ ⟩∎ remainder l₂ a ∎) where open Lens f : R l₁ → R l₂ f r = Trunc.rec R₂-prop (λ b → remainder l₂ (_≃_.from (equiv l₁) (r , b))) (inhabited l₁ r) -- A generalisation of the previous result: If a lens has a remainder -- type that is a set, then this lens is equal to another lens if -- their setters are equal (assuming univalence). -- -- This result is due to Andrea Vezzosi. lenses-equal-if-setters-equal-and-remainder-set : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (l₁ l₂ : Lens A B) → Is-set (Lens.R l₂) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-equal-if-setters-equal-and-remainder-set {B = B} univ l₁ l₂ R₂-set setters-equal = lenses-equal-if-setters-equal′ univ l₁ l₂ f (λ b r → b , (remainder l₂ (_≃_.from (equiv l₁) (r , b)) ≡⟨ cong (f₂ r) $ truncation-is-proposition ∣ _ ∣ (inhabited l₁ r) ⟩∎ f r ∎)) (λ a → f (remainder l₁ a) ≡⟨⟩ f₂ (remainder l₁ a) (inhabited l₁ (remainder l₁ a)) ≡⟨ cong (f₂ (remainder l₁ a)) $ truncation-is-proposition (inhabited l₁ (remainder l₁ a)) ∣ _ ∣ ⟩ f₁ (remainder l₁ a) (get l₁ a) ≡⟨ sym $ f₁-remainder _ _ ⟩∎ remainder l₂ a ∎) setters-equal where open Lens f₁ : R l₁ → B → R l₂ f₁ r b = remainder l₂ (_≃_.from (equiv l₁) (r , b)) f₁-remainder : ∀ a b → remainder l₂ a ≡ f₁ (remainder l₁ a) b f₁-remainder a b = remainder l₂ a ≡⟨ sym $ remainder-set l₂ a b ⟩ remainder l₂ (set l₂ a b) ≡⟨ cong (λ f → remainder l₂ (f a b)) $ sym setters-equal ⟩∎ remainder l₂ (set l₁ a b) ∎ f₂ : R l₁ → ∥ B ∥ → R l₂ f₂ r = _↔_.to (constant-function↔∥inhabited∥⇒inhabited R₂-set) ( f₁ r , λ b₁ b₂ → let a = _≃_.from (equiv l₁) (r , b₁) in remainder l₂ a ≡⟨ f₁-remainder _ _ ⟩ f₁ (remainder l₁ a) b₂ ≡⟨⟩ remainder l₂ (_≃_.from (equiv l₁) (remainder l₁ a , b₂)) ≡⟨ cong (λ p → f₁ (proj₁ p) b₂) $ _≃_.right-inverse-of (equiv l₁) _ ⟩∎ remainder l₂ (_≃_.from (equiv l₁) (r , b₂)) ∎ ) f : R l₁ → R l₂ f r = f₂ r (inhabited l₁ r) -- If lenses from A × C to C (where the universe of A is at least as -- large as the universe of C) with equal setters are equal, then -- weakly constant functions from C to equivalences between A and B -- (where B lives in the same universe as A) are coherently constant. -- -- This result is due to Andrea Vezzosi. lenses-equal-if-setters-equal→constant→coherently-constant : ∀ ℓ {A B : Type (c ⊔ ℓ)} {C : Type c} → ((l₁ l₂ : Lens (A × C) C) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂) → (A≃B : C → A ≃ B) → Constant A≃B → Coherently-constant A≃B lenses-equal-if-setters-equal→constant→coherently-constant _ {A = A} {B = B} {C = C} lenses-equal-if-setters-equal A≃B c = A≃B′ , A≃B≡ where open Lens module _ (∥c∥ : ∥ C ∥) where l₁ l₂ : Lens (A × C) C l₁ = record { R = A ; equiv = F.id ; inhabited = λ _ → ∥c∥ } l₂ = record { R = B ; equiv = A × C ↔⟨ ×-comm ⟩ C × A ↝⟨ ∃-cong A≃B ⟩ C × B ↔⟨ ×-comm ⟩□ B × C □ ; inhabited = λ _ → ∥c∥ } setters-equal : ∀ p c → set l₁ p c ≡ set l₂ p c setters-equal (a , c₁) c₂ = cong (_, c₂) $ sym $ (_≃_.from (A≃B c₂) (_≃_.to (A≃B c₁) a) ≡⟨ cong (λ eq → _≃_.from (A≃B c₂) (_≃_.to eq a)) $ c c₁ c₂ ⟩ _≃_.from (A≃B c₂) (_≃_.to (A≃B c₂) a) ≡⟨ _≃_.left-inverse-of (A≃B c₂) a ⟩∎ a ∎) l₁≡l₂ : l₁ ≡ l₂ l₁≡l₂ = lenses-equal-if-setters-equal l₁ l₂ (⟨ext⟩ λ p → ⟨ext⟩ λ c → setters-equal p c) l₁≡l₂′ = _≃_.to (equality-characterisation₀₂ ⊠) l₁≡l₂ A≃B′ : A ≃ B A≃B′ = ≡⇒≃ $ proj₁ l₁≡l₂′ A≃B≡ : A≃B ≡ A≃B′ ∘ ∣_∣ A≃B≡ = ⟨ext⟩ λ c → Eq.lift-equality ext $ ⟨ext⟩ λ a → _≃_.to (A≃B c) a ≡⟨⟩ remainder (l₂ ∣ c ∣) (a , c) ≡⟨ sym $ proj₁ (proj₂ (l₁≡l₂′ ∣ c ∣)) _ ⟩ subst id (proj₁ (l₁≡l₂′ ∣ c ∣)) (remainder (l₁ ∣ c ∣) (a , c)) ≡⟨ subst-id-in-terms-of-≡⇒↝ equivalence ⟩ ≡⇒→ (proj₁ (l₁≡l₂′ ∣ c ∣)) (remainder (l₁ ∣ c ∣) (a , c)) ≡⟨⟩ _≃_.to (A≃B′ ∣ c ∣) a ∎ -- It is not the case that, for all types A and B in Type a and all -- lenses l₁ and l₂ from A to B, that l₁ is equal to l₂ if the lenses -- have equal setters (assuming univalence). ¬-lenses-equal-if-setters-equal : Univalence lzero → ¬ ((A B : Type a) (l₁ l₂ : Lens A B) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂) ¬-lenses-equal-if-setters-equal {a = a} univ = ((A B : Type a) (l₁ l₂ : Lens A B) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂) ↝⟨ (λ hyp A B _ f c → lenses-equal-if-setters-equal→constant→coherently-constant lzero (hyp (B × A) A) f c) ⟩ ((A B : Type a) → ∥ A ∥ → (f : A → B ≃ B) → Constant f → Coherently-constant f) ↝⟨ C.¬-Constant→Coherently-constant univ ⟩□ ⊥ □ -- The functions ≃→lens and ≃→lens′ are pointwise equal (when -- applicable, assuming univalence). ≃→lens≡≃→lens′ : {A B : Type a} → Univalence a → (A≃B : A ≃ B) → ≃→lens A≃B ≡ ≃→lens′ A≃B ≃→lens≡≃→lens′ {B = B} univ A≃B = _↔_.from (equality-characterisation₂ ⊠ univ) ( (∥ ↑ _ B ∥ ↔⟨ ∥∥-cong Bij.↑↔ ⟩□ ∥ B ∥ □) , (λ _ → refl _) , (λ _ → refl _) ) -- If the getter of a lens is an equivalence, then the lens formed -- using the equivalence (using ≃→lens) is equal to the lens (assuming -- univalence). get-equivalence→≡≃→lens : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (l : Lens A B) → (eq : Is-equivalence (Lens.get l)) → l ≡ ≃→lens Eq.⟨ Lens.get l , eq ⟩ get-equivalence→≡≃→lens {A = A} {B = B} univ l eq = lenses-equal-if-setters-equal-and-remainder-propositional univ l (≃→lens Eq.⟨ Lens.get l , eq ⟩) truncation-is-proposition (⟨ext⟩ λ a → ⟨ext⟩ λ b → set l a b ≡⟨ sym $ from≡set l eq a b ⟩ _≃_.from A≃B b ≡⟨⟩ set (≃→lens A≃B) a b ∎) where open Lens A≃B : A ≃ B A≃B = Eq.⟨ _ , eq ⟩ -- A variant of get-equivalence→≡≃→lens. get-equivalence→≡≃→lens′ : {A B : Type a} → Univalence a → (l : Lens A B) → (eq : Is-equivalence (Lens.get l)) → l ≡ ≃→lens′ Eq.⟨ Lens.get l , eq ⟩ get-equivalence→≡≃→lens′ {A = A} {B = B} univ l eq = l ≡⟨ get-equivalence→≡≃→lens univ _ _ ⟩ ≃→lens A≃B ≡⟨ ≃→lens≡≃→lens′ univ _ ⟩∎ ≃→lens′ A≃B ∎ where A≃B = Eq.⟨ Lens.get l , eq ⟩ ------------------------------------------------------------------------ -- Some equivalences -- "The getter is an equivalence" is equivalent to "the remainder type -- is equivalent to the propositional truncation of the codomain". get-equivalence≃inhabited-equivalence : (l : Lens A B) → Is-equivalence (Lens.get l) ≃ Is-equivalence (Lens.inhabited l) get-equivalence≃inhabited-equivalence {A = A} {B = B} l = Is-equivalence (get l) ↝⟨ Eq.⇔→≃ (Eq.propositional ext _) (Eq.propositional ext _) (flip (Eq.Two-out-of-three.g∘f-f (Eq.two-out-of-three _ _)) (_≃_.is-equivalence (equiv l))) (Eq.Two-out-of-three.f-g (Eq.two-out-of-three _ _) (_≃_.is-equivalence (equiv l))) ⟩ Is-equivalence (proj₂ ⦂ (R l × B → B)) ↝⟨ inverse $ equivalence-to-∥∥≃proj₂-equivalence _ ⟩□ Is-equivalence (inhabited l) □ where open Lens -- "The getter is an equivalence" is equivalent to "the remainder type -- is equivalent to the propositional truncation of the codomain". get-equivalence≃remainder≃∥codomain∥ : (l : Lens A B) → Is-equivalence (Lens.get l) ≃ (Lens.R l ≃ ∥ B ∥) get-equivalence≃remainder≃∥codomain∥ {A = A} {B = B} l = Is-equivalence (get l) ↝⟨ get-equivalence≃inhabited-equivalence l ⟩ Is-equivalence (inhabited l) ↔⟨ inverse $ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure ext 1 λ _ → truncation-is-proposition) (inhabited l) ⟩ (∃ λ (inh : R l → ∥ B ∥) → Is-equivalence inh) ↔⟨ inverse Eq.≃-as-Σ ⟩□ R l ≃ ∥ B ∥ □ where open Lens ------------------------------------------------------------------------ -- Some lens isomorphisms -- A generalised variant of Lens preserves bijections. Lens-cong′ : A₁ ↔ A₂ → B₁ ↔ B₂ → (∃ λ (R : Type r) → A₁ ≃ (R × B₁) × (R → ∥ B₁ ∥)) ↔ (∃ λ (R : Type r) → A₂ ≃ (R × B₂) × (R → ∥ B₂ ∥)) Lens-cong′ A₁↔A₂ B₁↔B₂ = ∃-cong λ _ → Eq.≃-preserves-bijections ext A₁↔A₂ (F.id ×-cong B₁↔B₂) ×-cong →-cong ext F.id (∥∥-cong B₁↔B₂) -- Lens preserves level-preserving bijections. Lens-cong : {A₁ A₂ : Type a} {B₁ B₂ : Type b} → A₁ ↔ A₂ → B₁ ↔ B₂ → Lens A₁ B₁ ↔ Lens A₂ B₂ Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁↔A₂ B₁↔B₂ = Lens A₁ B₁ ↔⟨ Lens-as-Σ ⟩ (∃ λ R → A₁ ≃ (R × B₁) × (R → ∥ B₁ ∥)) ↝⟨ Lens-cong′ A₁↔A₂ B₁↔B₂ ⟩ (∃ λ R → A₂ ≃ (R × B₂) × (R → ∥ B₂ ∥)) ↔⟨ inverse Lens-as-Σ ⟩□ Lens A₂ B₂ □ -- If B is a proposition, then Lens A B is isomorphic to A → B -- (assuming univalence). lens-to-proposition↔get : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-proposition B → Lens A B ↔ (A → B) lens-to-proposition↔get {b = b} {A = A} {B = B} univ B-prop = Lens A B ↔⟨ Lens-as-Σ ⟩ (∃ λ R → A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∥∥↔ B-prop) ⟩ (∃ λ R → A ≃ (R × B) × (R → B)) ↝⟨ (∃-cong λ _ → ×-cong₁ λ R→B → Eq.≃-preserves-bijections ext F.id $ drop-⊤-right λ r → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible B-prop (R→B r)) ⟩ (∃ λ R → A ≃ R × (R → B)) ↔⟨ (∃-cong λ _ → ∃-cong λ A≃R → →-cong {k = equivalence} ext (inverse A≃R) F.id) ⟩ (∃ λ R → A ≃ R × (A → B)) ↝⟨ Σ-assoc ⟩ (∃ λ R → A ≃ R) × (A → B) ↝⟨ (drop-⊤-left-× λ _ → other-singleton-with-≃-↔-⊤ {b = b} ext univ) ⟩□ (A → B) □ _ : {A : Type a} {B : Type b} (univ : Univalence (a ⊔ b)) (prop : Is-proposition B) (l : Lens A B) → _↔_.to (lens-to-proposition↔get univ prop) l ≡ Trunc.rec prop id ∘ Lens.inhabited l ∘ Lens.remainder l _ = λ _ _ _ → refl _ -- A variant of the previous result. lens-to-proposition≃get : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-proposition B → Lens A B ≃ (A → B) lens-to-proposition≃get {b = b} {A = A} {B = B} univ prop = Eq.↔→≃ get from refl (λ l → let lemma = ↑ b A ↔⟨ Bij.↑↔ ⟩ A ↝⟨ equiv l ⟩ R l × B ↔⟨ (drop-⊤-right λ r → _⇔_.to contractible⇔↔⊤ $ Trunc.rec (Contractible-propositional ext) (propositional⇒inhabited⇒contractible prop) (inhabited l r)) ⟩□ R l □ in _↔_.from (equality-characterisation₁ ⊠ univ) (lemma , λ _ → refl _)) where open Lens from = λ get → record { R = ↑ b A ; equiv = A ↔⟨ inverse Bij.↑↔ ⟩ ↑ b A ↔⟨ (inverse $ drop-⊤-right {k = bijection} λ (lift a) → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible prop (get a)) ⟩□ ↑ b A × B □ ; inhabited = ∣_∣ ∘ get ∘ lower } _ : {A : Type a} {B : Type b} (univ : Univalence (a ⊔ b)) (prop : Is-proposition B) (l : Lens A B) → _≃_.to (lens-to-proposition≃get univ prop) l ≡ Lens.get l _ = λ _ _ _ → refl _ -- If B is contractible, then Lens A B is isomorphic to ⊤ (assuming -- univalence). lens-to-contractible↔⊤ : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Contractible B → Lens A B ↔ ⊤ lens-to-contractible↔⊤ {A = A} {B} univ cB = Lens A B ↝⟨ lens-to-proposition↔get univ (mono₁ 0 cB) ⟩ (A → B) ↝⟨ →-cong ext F.id $ _⇔_.to contractible⇔↔⊤ cB ⟩ (A → ⊤) ↝⟨ →-right-zero ⟩□ ⊤ □ -- Lens A ⊥ is isomorphic to ¬ A (assuming univalence). lens-to-⊥↔¬ : {A : Type a} → Univalence (a ⊔ b) → Lens A (⊥ {ℓ = b}) ↔ ¬ A lens-to-⊥↔¬ {A = A} univ = Lens A ⊥ ↝⟨ lens-to-proposition↔get univ ⊥-propositional ⟩ (A → ⊥) ↝⟨ inverse $ ¬↔→⊥ ext ⟩□ ¬ A □ -- If A is contractible, then Lens A B is isomorphic to Contractible B -- (assuming univalence). lens-from-contractible↔codomain-contractible : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Contractible A → Lens A B ↔ Contractible B lens-from-contractible↔codomain-contractible {A = A} {B} univ cA = Lens A B ↔⟨ Lens-as-Σ ⟩ (∃ λ R → A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → Eq.≃-preserves-bijections ext (_⇔_.to contractible⇔↔⊤ cA) F.id ×-cong F.id) ⟩ (∃ λ R → ⊤ ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → Eq.inverse-isomorphism ext ×-cong F.id) ⟩ (∃ λ R → (R × B) ≃ ⊤ × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → inverse (contractible↔≃⊤ ext) ×-cong F.id) ⟩ (∃ λ R → Contractible (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → Contractible-commutes-with-× ext ×-cong F.id) ⟩ (∃ λ R → (Contractible R × Contractible B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → inverse ×-assoc) ⟩ (∃ λ R → Contractible R × Contractible B × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → ∃-cong λ cR → F.id ×-cong →-cong ext (_⇔_.to contractible⇔↔⊤ cR) F.id) ⟩ (∃ λ R → Contractible R × Contractible B × (⊤ → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → F.id ×-cong F.id ×-cong Π-left-identity) ⟩ (∃ λ R → Contractible R × Contractible B × ∥ B ∥) ↝⟨ ∃-cong (λ _ → ×-comm) ⟩ (∃ λ R → (Contractible B × ∥ B ∥) × Contractible R) ↝⟨ ∃-comm ⟩ (Contractible B × ∥ B ∥) × (∃ λ R → Contractible R) ↝⟨ drop-⊤-right (λ _ → ∃Contractible↔⊤ ext univ) ⟩ Contractible B × ∥ B ∥ ↝⟨ drop-⊤-right (λ cB → inhabited⇒∥∥↔⊤ ∣ proj₁ cB ∣) ⟩□ Contractible B □ -- Lens ⊥ B is isomorphic to the unit type (assuming univalence). lens-from-⊥↔⊤ : {B : Type b} → Univalence (a ⊔ b) → Lens (⊥ {ℓ = a}) B ↔ ⊤ lens-from-⊥↔⊤ {B = B} univ = _⇔_.to contractible⇔↔⊤ $ isomorphism-to-lens (⊥ ↝⟨ inverse ×-left-zero ⟩□ ⊥ × B □) , λ l → _↔_.from (equality-characterisation₁ ⊠ univ) ( (⊥ × ∥ B ∥ ↔⟨ ×-left-zero ⟩ ⊥₀ ↔⟨ lemma l ⟩□ R l □) , λ x → ⊥-elim x ) where open Lens lemma : (l : Lens ⊥ B) → ⊥₀ ↔ R l lemma l = record { surjection = record { logical-equivalence = record { to = ⊥-elim ; from = whatever } ; right-inverse-of = whatever } ; left-inverse-of = λ x → ⊥-elim x } where whatever : ∀ {ℓ} {Whatever : R l → Type ℓ} → (r : R l) → Whatever r whatever r = ⊥-elim {ℓ = lzero} $ Trunc.rec ⊥-propositional (λ b → ⊥-elim (_≃_.from (equiv l) (r , b))) (inhabited l r) -- There is an equivalence between A ≃ B and -- ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l) (assuming -- univalence). -- -- See also ≃≃≊ below. ≃-≃-Σ-Lens-Is-equivalence-get : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → (A ≃ B) ≃ (∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) ≃-≃-Σ-Lens-Is-equivalence-get {a = a} {A = A} {B = B} univ = A ≃ B ↝⟨ Eq.≃-preserves ext F.id (inverse ∥∥×≃) ⟩ A ≃ (∥ B ∥ × B) ↝⟨ inverse $ Eq.↔⇒≃ Σ-left-identity F.∘ Σ-cong (singleton-with-≃-↔-⊤ {a = a} ext univ) (λ (C , C≃∥B∥) → Eq.≃-preserves ext F.id (×-cong₁ λ _ → C≃∥B∥)) ⟩ (∃ λ ((R , _) : ∃ λ R → R ≃ ∥ B ∥) → A ≃ (R × B)) ↔⟨ inverse $ (Σ-cong (∃-cong λ _ → inverse Eq.≃-as-Σ) λ _ → F.id) F.∘ Σ-assoc F.∘ (∃-cong λ _ → inverse (Σ-assoc F.∘ ×-comm)) F.∘ inverse Σ-assoc F.∘ Σ-cong Lens-as-Σ (λ _ → F.id) ⟩ (∃ λ (l : Lens A B) → Is-equivalence (inhabited l)) ↝⟨ inverse $ ∃-cong get-equivalence≃inhabited-equivalence ⟩□ (∃ λ (l : Lens A B) → Is-equivalence (get l)) □ where open Lens -- The right-to-left direction of ≃-≃-Σ-Lens-Is-equivalence-get -- returns the lens's getter (and some proof). to-from-≃-≃-Σ-Lens-Is-equivalence-get≡get : {A : Type a} {B : Type b} → (univ : Univalence (a ⊔ b)) (p@(l , _) : ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) → _≃_.to (_≃_.from (≃-≃-Σ-Lens-Is-equivalence-get univ) p) ≡ Lens.get l to-from-≃-≃-Σ-Lens-Is-equivalence-get≡get _ _ = refl _ ------------------------------------------------------------------------ -- Results relating different kinds of lenses -- In general there is no split surjection from Lens A B to -- Traditional.Lens A B (assuming univalence). ¬Lens↠Traditional-lens : Univalence lzero → ¬ (Lens 𝕊¹ ⊤ ↠ Traditional.Lens 𝕊¹ ⊤) ¬Lens↠Traditional-lens univ = Lens 𝕊¹ ⊤ ↠ Traditional.Lens 𝕊¹ ⊤ ↝⟨ flip H-level.respects-surjection 1 ⟩ (Is-proposition (Lens 𝕊¹ ⊤) → Is-proposition (Traditional.Lens 𝕊¹ ⊤)) ↝⟨ _$ mono₁ 0 (_⇔_.from contractible⇔↔⊤ $ lens-to-contractible↔⊤ univ ⊤-contractible) ⟩ Is-proposition (Traditional.Lens 𝕊¹ ⊤) ↝⟨ Traditional.¬-lens-to-⊤-propositional univ ⟩□ ⊥ □ -- Some lemmas used in Lens↠Traditional-lens and Lens↔Traditional-lens -- below. private module Lens↔Traditional-lens {A : Type a} {B : Type b} (A-set : Is-set A) where from : Block "conversion" → Traditional.Lens A B → Lens A B from ⊠ l = isomorphism-to-lens (A ↔⟨ Traditional.≃Σ∥set⁻¹∥× A-set l ⟩□ (∃ λ (f : B → A) → ∥ set ⁻¹ f ∥) × B □) where open Traditional.Lens l to∘from : ∀ bc l → Lens.traditional-lens (from bc l) ≡ l to∘from ⊠ l = Traditional.equal-laws→≡ (λ a _ → B-set a _ _) (λ _ → A-set _ _) (λ _ _ _ → A-set _ _) where open Traditional.Lens l B-set : A → Is-set B B-set a = Traditional.h-level-respects-lens-from-inhabited 2 l a A-set from∘to : Univalence (a ⊔ b) → ∀ bc l → from bc (Lens.traditional-lens l) ≡ l from∘to univ ⊠ l′ = _↔_.from (equality-characterisation₁ ⊠ univ) ( ((∃ λ (f : B → A) → ∥ set ⁻¹ f ∥) × ∥ B ∥ ↝⟨ (×-cong₁ lemma₃) ⟩ (∥ B ∥ → R) × ∥ B ∥ ↝⟨ lemma₂ ⟩□ R □) , λ p → ( proj₁ (_≃_.to l (_≃_.from l (_≃_.to l p))) , proj₂ (_≃_.to l p) ) ≡⟨ cong (_, proj₂ (_≃_.to l p)) $ cong proj₁ $ _≃_.right-inverse-of l _ ⟩∎ _≃_.to l p ∎ ) where open Lens l′ renaming (equiv to l) B-set : A → Is-set B B-set a = Traditional.h-level-respects-lens-from-inhabited 2 (Lens.traditional-lens l′) a A-set R-set : Is-set R R-set = [inhabited⇒+]⇒+ 1 λ r → Trunc.rec (H-level-propositional ext 2) (λ b → proj₁-closure (const b) 2 $ H-level.respects-surjection (_≃_.surjection l) 2 A-set) (inhabited r) lemma₁ : ∥ B ∥ → (f : B → A) → ∥ set ⁻¹ f ∥ ≃ (∀ b b′ → set (f b) b′ ≡ f b′) lemma₁ ∥b∥ f = Eq.⇔→≃ truncation-is-proposition prop (Trunc.rec prop λ (a , set-a≡f) b b′ → set (f b) b′ ≡⟨ cong (λ f → set (f b) b′) $ sym set-a≡f ⟩ set (set a b) b′ ≡⟨ set-set _ _ _ ⟩ set a b′ ≡⟨ cong (_$ b′) set-a≡f ⟩∎ f b′ ∎) (λ hyp → flip ∥∥-map ∥b∥ λ b → f b , ⟨ext⟩ (hyp b)) where prop = Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set lemma₂ : ((∥ B ∥ → R) × ∥ B ∥) ≃ R lemma₂ = Eq.↔→≃ (λ (f , ∥b∥) → f ∥b∥) (λ r → (λ _ → r) , inhabited r) refl (λ (f , ∥b∥) → cong₂ _,_ (⟨ext⟩ λ ∥b∥′ → f ∥b∥ ≡⟨ cong f (truncation-is-proposition _ _) ⟩∎ f ∥b∥′ ∎) (truncation-is-proposition _ _)) lemma₃ = λ ∥b∥ → (∃ λ (f : B → A) → ∥ set ⁻¹ f ∥) ↝⟨ ∃-cong (lemma₁ ∥b∥) ⟩ (∃ λ (f : B → A) → ∀ b b′ → set (f b) b′ ≡ f b′) ↝⟨ (Σ-cong (→-cong ext F.id l) λ f → ∀-cong ext λ b → ∀-cong ext λ b′ → ≡⇒↝ _ $ cong (_≃_.from l (proj₁ (_≃_.to l (f b)) , b′) ≡_) $ sym $ _≃_.left-inverse-of l _) ⟩ (∃ λ (f : B → R × B) → ∀ b b′ → _≃_.from l (proj₁ (f b) , b′) ≡ _≃_.from l (f b′)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → Eq.≃-≡ (inverse l)) ⟩ (∃ λ (f : B → R × B) → ∀ b b′ → (proj₁ (f b) , b′) ≡ f b′) ↔⟨ (Σ-cong ΠΣ-comm λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → inverse $ ≡×≡↔≡) ⟩ (∃ λ ((f , g) : (B → R) × (B → B)) → ∀ b b′ → f b ≡ f b′ × b′ ≡ g b′) ↔⟨ (Σ-assoc F.∘ (∃-cong λ _ → ∃-comm F.∘ ∃-cong λ _ → ΠΣ-comm F.∘ ∀-cong ext λ _ → ΠΣ-comm) F.∘ inverse Σ-assoc) ⟩ ((∃ λ (f : B → R) → Constant f) × (∃ λ (g : B → B) → B → ∀ b → b ≡ g b)) ↔⟨ (∃-cong $ uncurry λ f _ → ∃-cong λ _ → inverse $ →-intro ext (λ b → B-set (_≃_.from l (f b , b)))) ⟩ ((∃ λ (f : B → R) → Constant f) × (∃ λ (g : B → B) → ∀ b → b ≡ g b)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Eq.extensionality-isomorphism ext) ⟩ ((∃ λ (f : B → R) → Constant f) × (∃ λ (g : B → B) → id ≡ g)) ↔⟨ (drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ other-singleton-contractible _) ⟩ (∃ λ (f : B → R) → Constant f) ↝⟨ constant-function≃∥inhabited∥⇒inhabited R-set ⟩□ (∥ B ∥ → R) □ iso : Block "conversion" → Univalence (a ⊔ b) → Lens A B ↔ Traditional.Lens A B iso bc univ = record { surjection = record { logical-equivalence = record { from = from bc } ; right-inverse-of = to∘from bc } ; left-inverse-of = from∘to univ bc } -- If the domain A is a set, then there is a split surjection from -- Lens A B to Traditional.Lens A B. Lens↠Traditional-lens : Block "conversion" → Is-set A → Lens A B ↠ Traditional.Lens A B Lens↠Traditional-lens {A = A} {B = B} bc A-set = record { logical-equivalence = record { to = Lens.traditional-lens ; from = Lens↔Traditional-lens.from A-set bc } ; right-inverse-of = Lens↔Traditional-lens.to∘from A-set bc } -- The split surjection above preserves getters and setters. Lens↠Traditional-lens-preserves-getters-and-setters : {A : Type a} (b : Block "conversion") (s : Is-set A) → Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence (Lens↠Traditional-lens b s)) Lens↠Traditional-lens-preserves-getters-and-setters ⊠ _ = (λ _ → refl _ , refl _) , (λ _ → refl _ , refl _) -- If the domain A is a set, then Traditional.Lens A B and Lens A B -- are isomorphic (assuming univalence). Lens↔Traditional-lens : {A : Type a} {B : Type b} → Block "conversion" → Univalence (a ⊔ b) → Is-set A → Lens A B ↔ Traditional.Lens A B Lens↔Traditional-lens bc univ A-set = Lens↔Traditional-lens.iso A-set bc univ -- The isomorphism preserves getters and setters. Lens↔Traditional-lens-preserves-getters-and-setters : {A : Type a} {B : Type b} (bc : Block "conversion") (univ : Univalence (a ⊔ b)) (s : Is-set A) → Preserves-getters-and-setters-⇔ A B (_↔_.logical-equivalence (Lens↔Traditional-lens bc univ s)) Lens↔Traditional-lens-preserves-getters-and-setters bc _ = Lens↠Traditional-lens-preserves-getters-and-setters bc -- If the codomain B is an inhabited set, then Lens A B and -- Traditional.Lens A B are logically equivalent. -- -- This definition is inspired by the statement of Corollary 13 from -- "Algebras and Update Strategies" by Johnson, Rosebrugh and Wood. -- -- See also Lens.Non-dependent.Equivalent-preimages.coherent↠higher. Lens⇔Traditional-lens : Is-set B → B → Lens A B ⇔ Traditional.Lens A B Lens⇔Traditional-lens {B = B} {A = A} B-set b₀ = record { to = Lens.traditional-lens ; from = from } where from : Traditional.Lens A B → Lens A B from l = isomorphism-to-lens (A ↔⟨ Traditional.≃get⁻¹× B-set b₀ l ⟩□ (∃ λ (a : A) → get a ≡ b₀) × B □) where open Traditional.Lens l -- The logical equivalence preserves getters and setters. Lens⇔Traditional-lens-preserves-getters-and-setters : {B : Type b} (s : Is-set B) (b₀ : B) → Preserves-getters-and-setters-⇔ A B (Lens⇔Traditional-lens s b₀) Lens⇔Traditional-lens-preserves-getters-and-setters _ b₀ = (λ _ → refl _ , refl _) , (λ l → refl _ , ⟨ext⟩ λ a → ⟨ext⟩ λ b → set l (set l a b₀) b ≡⟨ set-set l _ _ _ ⟩∎ set l a b ∎) where open Traditional.Lens ------------------------------------------------------------------------ -- Some results related to h-levels -- If the domain of a lens is inhabited and has h-level n, then the -- codomain also has h-level n. h-level-respects-lens-from-inhabited : ∀ n → Lens A B → A → H-level n A → H-level n B h-level-respects-lens-from-inhabited n = Traditional.h-level-respects-lens-from-inhabited n ∘ Lens.traditional-lens -- This is not necessarily true for arbitrary domains (assuming -- univalence). ¬-h-level-respects-lens : Univalence lzero → ¬ (∀ n → Lens ⊥₀ Bool → H-level n ⊥₀ → H-level n Bool) ¬-h-level-respects-lens univ resp = $⟨ ⊥-propositional ⟩ Is-proposition ⊥ ↝⟨ resp 1 (_↔_.from (lens-from-⊥↔⊤ univ) _) ⟩ Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□ ⊥ □ -- In fact, there is a lens with a proposition as its domain and a -- non-set as its codomain (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by Circle.¬-𝕊¹-set.) lens-from-proposition-to-non-set : Univalence (# 0) → ∃ λ (A : Type a) → ∃ λ (B : Type b) → Lens A B × Is-proposition A × ¬ Is-set B lens-from-proposition-to-non-set {b = b} _ = ⊥ , ↑ b 𝕊¹ , record { R = ⊥ ; equiv = ⊥ ↔⟨ inverse ×-left-zero ⟩□ ⊥ × ↑ _ 𝕊¹ □ ; inhabited = ⊥-elim } , ⊥-propositional , Circle.¬-𝕊¹-set ∘ H-level.respects-surjection (_↔_.surjection Bij.↑↔) 2 -- Lenses with contractible domains have contractible codomains. contractible-to-contractible : Lens A B → Contractible A → Contractible B contractible-to-contractible l c = h-level-respects-lens-from-inhabited _ l (proj₁ c) c -- If the domain type of a lens has h-level n, then the remainder type -- also has h-level n. remainder-has-same-h-level-as-domain : (l : Lens A B) → ∀ n → H-level n A → H-level n (Lens.R l) remainder-has-same-h-level-as-domain {A = A} {B = B} l n = H-level n A ↝⟨ H-level.respects-surjection (_≃_.surjection equiv) n ⟩ H-level n (R × B) ↝⟨ H-level-×₁ inhabited n ⟩□ H-level n R □ where open Lens l -- If the getter function is an equivalence, then the remainder type -- is propositional. get-equivalence→remainder-propositional : (l : Lens A B) → Is-equivalence (Lens.get l) → Is-proposition (Lens.R l) get-equivalence→remainder-propositional {B = B} l = Is-equivalence (get l) ↔⟨ get-equivalence≃remainder≃∥codomain∥ l ⟩ R l ≃ ∥ B ∥ ↝⟨ ≃∥∥→Is-proposition ⟩□ Is-proposition (R l) □ where open Lens -- If the getter function is pointwise equal to the identity -- function, then the remainder type is propositional. get≡id→remainder-propositional : (l : Lens A A) → (∀ a → Lens.get l a ≡ a) → Is-proposition (Lens.R l) get≡id→remainder-propositional l = (∀ a → Lens.get l a ≡ a) ↝⟨ (λ hyp → Eq.respects-extensional-equality (sym ∘ hyp) (_≃_.is-equivalence F.id)) ⟩ Is-equivalence (Lens.get l) ↝⟨ get-equivalence→remainder-propositional l ⟩□ Is-proposition (Lens.R l) □ -- It is not necessarily the case that contractibility of A implies -- contractibility of Lens A B (assuming univalence). ¬-Contractible-closed-domain : ∀ {a b} → Univalence (a ⊔ b) → ¬ ({A : Type a} {B : Type b} → Contractible A → Contractible (Lens A B)) ¬-Contractible-closed-domain univ closure = $⟨ ↑⊤-contractible ⟩ Contractible (↑ _ ⊤) ↝⟨ closure ⟩ Contractible (Lens (↑ _ ⊤) ⊥) ↝⟨ H-level.respects-surjection (_↔_.surjection $ lens-from-contractible↔codomain-contractible univ ↑⊤-contractible) 0 ⟩ Contractible (Contractible ⊥) ↝⟨ proj₁ ⟩ Contractible ⊥ ↝⟨ proj₁ ⟩ ⊥ ↝⟨ ⊥-elim ⟩□ ⊥₀ □ where ↑⊤-contractible = ↑-closure 0 ⊤-contractible -- Contractible is closed under Lens A (assuming univalence). Contractible-closed-codomain : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Contractible B → Contractible (Lens A B) Contractible-closed-codomain {A = A} {B} univ cB = $⟨ lens-to-contractible↔⊤ univ cB ⟩ Lens A B ↔ ⊤ ↝⟨ _⇔_.from contractible⇔↔⊤ ⟩□ Contractible (Lens A B) □ -- If B is a proposition, then Lens A B is also a proposition -- (assuming univalence). Is-proposition-closed-codomain : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-proposition B → Is-proposition (Lens A B) Is-proposition-closed-codomain {A = A} {B} univ B-prop = $⟨ Π-closure ext 1 (λ _ → B-prop) ⟩ Is-proposition (A → B) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse $ lens-to-proposition↔get univ B-prop) 1 ⟩□ Is-proposition (Lens A B) □ private -- If A has h-level 1 + n and equivalence between certain remainder -- types has h-level n, then Lens A B has h-level 1 + n (assuming -- univalence). domain-1+-remainder-equivalence-0+⇒lens-1+ : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → ∀ n → H-level (1 + n) A → ((l₁ l₂ : Lens A B) → H-level n (Lens.R l₁ ≃ Lens.R l₂)) → H-level (1 + n) (Lens A B) domain-1+-remainder-equivalence-0+⇒lens-1+ {A = A} univ n hA hR = ≡↔+ _ _ λ l₁ l₂ → $⟨ Σ-closure n (hR l₁ l₂) (λ _ → Π-closure ext n λ _ → +⇒≡ hA) ⟩ H-level n (∃ λ (eq : R l₁ ≃ R l₂) → ∀ p → _≡_ {A = A} _ _) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse $ equality-characterisation₃ univ) n ⟩□ H-level n (l₁ ≡ l₂) □ where open Lens -- If A is a proposition, then Lens A B is also a proposition -- (assuming univalence). Is-proposition-closed-domain : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-proposition A → Is-proposition (Lens A B) Is-proposition-closed-domain {b = b} {A = A} {B = B} univ A-prop = $⟨ R₁≃R₂ ⟩ (∀ l₁ l₂ → R l₁ ≃ R l₂) ↝⟨ (λ hyp l₁ l₂ → propositional⇒inhabited⇒contractible (Eq.left-closure ext 0 (R-prop l₁)) (hyp l₁ l₂)) ⟩ (∀ l₁ l₂ → Contractible (R l₁ ≃ R l₂)) ↝⟨ domain-1+-remainder-equivalence-0+⇒lens-1+ univ 0 A-prop ⟩□ Is-proposition (Lens A B) □ where open Lens R-prop : (l : Lens A B) → Is-proposition (R l) R-prop l = remainder-has-same-h-level-as-domain l 1 A-prop remainder⁻¹ : (l : Lens A B) → R l → A remainder⁻¹ l r = Trunc.rec A-prop (λ b → _≃_.from (equiv l) (r , b)) (inhabited l r) R-to-R : (l₁ l₂ : Lens A B) → R l₁ → R l₂ R-to-R l₁ l₂ = remainder l₂ ∘ remainder⁻¹ l₁ involutive : (l : Lens A B) {f : R l → R l} → ∀ r → f r ≡ r involutive l _ = R-prop l _ _ R₁≃R₂ : (l₁ l₂ : Lens A B) → R l₁ ≃ R l₂ R₁≃R₂ l₁ l₂ = Eq.↔⇒≃ $ Bij.bijection-from-involutive-family R-to-R (λ l _ → involutive l) l₁ l₂ -- An alternative proof. Is-proposition-closed-domain′ : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-proposition A → Is-proposition (Lens A B) Is-proposition-closed-domain′ {A = A} {B} univ A-prop = $⟨ Traditional.lens-preserves-h-level-of-domain 0 A-prop ⟩ Is-proposition (Traditional.Lens A B) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse $ Lens↔Traditional-lens ⊠ univ (mono₁ 1 A-prop)) 1 ⟩□ Is-proposition (Lens A B) □ -- If A is a set, then Lens A B is also a set (assuming univalence). -- -- TODO: Can one prove that the corresponding result does not hold for -- codomains? Are there types A and B such that B is a set, but -- Lens A B is not? Is-set-closed-domain : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → Is-set A → Is-set (Lens A B) Is-set-closed-domain {A = A} {B} univ A-set = $⟨ (λ {_ _} → Traditional.lens-preserves-h-level-of-domain 1 A-set) ⟩ Is-set (Traditional.Lens A B) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse $ Lens↔Traditional-lens ⊠ univ A-set) 2 ⟩□ Is-set (Lens A B) □ -- If A has h-level n, then Lens A B has h-level 1 + n (assuming -- univalence). -- -- See also -- Lens.Non-dependent.Higher.Coinductive.Small.lens-preserves-h-level-of-domain. domain-0+⇒lens-1+ : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → ∀ n → H-level n A → H-level (1 + n) (Lens A B) domain-0+⇒lens-1+ {A = A} {B} univ n hA = $⟨ (λ l₁ l₂ → Eq.h-level-closure ext n (hR l₁) (hR l₂)) ⟩ ((l₁ l₂ : Lens A B) → H-level n (R l₁ ≃ R l₂)) ↝⟨ domain-1+-remainder-equivalence-0+⇒lens-1+ univ n (mono₁ n hA) ⟩□ H-level (1 + n) (Lens A B) □ where open Lens hR : ∀ l → H-level n (R l) hR l = remainder-has-same-h-level-as-domain l n hA -- An alternative proof. domain-0+⇒lens-1+′ : {A : Type a} {B : Type b} → Univalence (a ⊔ b) → ∀ n → H-level n A → H-level (1 + n) (Lens A B) domain-0+⇒lens-1+′ {A = A} {B} univ n hA = $⟨ Σ-closure (1 + n) (∃-H-level-H-level-1+ ext univ n) (λ _ → ×-closure (1 + n) (Eq.left-closure ext n (mono₁ n hA)) (Π-closure ext (1 + n) λ _ → mono (Nat.suc≤suc (Nat.zero≤ n)) $ truncation-is-proposition)) ⟩ H-level (1 + n) (∃ λ (p : ∃ (H-level n)) → A ≃ (proj₁ p × B) × (proj₁ p → ∥ B ∥)) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse iso) (1 + n) ⟩□ H-level (1 + n) (Lens A B) □ where open Lens iso = Lens A B ↝⟨ inverse $ drop-⊤-right (λ l → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (H-level-propositional ext n) (remainder-has-same-h-level-as-domain l n hA)) ⟩ (∃ λ (l : Lens A B) → H-level n (R l)) ↝⟨ inverse Σ-assoc F.∘ Σ-cong Lens-as-Σ (λ _ → F.id) ⟩ (∃ λ R → (A ≃ (R × B) × (R → ∥ B ∥)) × H-level n R) ↝⟨ (∃-cong λ _ → ×-comm) ⟩ (∃ λ R → H-level n R × A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ Σ-assoc ⟩□ (∃ λ (p : ∃ (H-level n)) → A ≃ (proj₁ p × B) × (proj₁ p → ∥ B ∥)) □ ------------------------------------------------------------------------ -- Some existence results -- There is, in general, no lens for the first projection from a -- Σ-type. no-first-projection-lens : ¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool no-first-projection-lens = Non-dependent.no-first-projection-lens Lens contractible-to-contractible -- 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. no-singleton-projection-lens : ∥ A ∥ → (bool : A → Bool) → (∀ x → bool x ≡ true) → ¬ ∃ λ (l : Lens A Bool) → ∀ x → Lens.get l x ≡ bool x no-singleton-projection-lens = Non-dependent.no-singleton-projection-lens _ _ Lens.get-set ------------------------------------------------------------------------ -- Equal lenses can be "observably different" -- An example based on one presented in "Shattered lens" by Oleg -- Grenrus. -- -- Grenrus states that there are two lenses with equal getters and -- setters that are "observably different". -- A lemma used to construct the two lenses of the example. grenrus-example : (Bool → Bool ↔ Bool) → Lens (Bool × Bool) Bool grenrus-example eq = record { R = Bool ; inhabited = ∣_∣ ; equiv = Bool × Bool ↔⟨ ×-cong₁ eq ⟩□ Bool × Bool □ } -- The two lenses. grenrus-example₁ = grenrus-example (if_then F.id else Bool.swap) grenrus-example₂ = grenrus-example (if_then Bool.swap else F.id) -- The two lenses have equal setters. set-grenrus-example₁≡set-grenrus-example₂ : Lens.set grenrus-example₁ ≡ Lens.set grenrus-example₂ set-grenrus-example₁≡set-grenrus-example₂ = ⟨ext⟩ (⟨ext⟩ ∘ lemma) where lemma : ∀ _ _ → _ lemma (true , true) true = refl _ lemma (true , true) false = refl _ lemma (true , false) true = refl _ lemma (true , false) false = refl _ lemma (false , true) true = refl _ lemma (false , true) false = refl _ lemma (false , false) true = refl _ lemma (false , false) false = refl _ -- Thus the lenses are equal (assuming univalence). grenrus-example₁≡grenrus-example₂ : Univalence lzero → grenrus-example₁ ≡ grenrus-example₂ grenrus-example₁≡grenrus-example₂ univ = lenses-with-inhabited-codomains-equal-if-setters-equal univ _ _ true set-grenrus-example₁≡set-grenrus-example₂ -- However, in a certain sense the lenses are "observably different". grenrus-example₁-true : Lens.remainder grenrus-example₁ (true , true) ≡ true grenrus-example₁-true = refl _ grenrus-example₂-false : Lens.remainder grenrus-example₂ (true , true) ≡ false grenrus-example₂-false = refl _
{ "alphanum_fraction": 0.4186222269, "avg_line_length": 41.2676667983, "ext": "agda", "hexsha": "0a22c3763d41c30fe371d708b55b7c04184dcd22", "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.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.agda", "max_line_length": 148, "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.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": 33717, "size": 104531 }
open import Prelude open import Nat open import contexts open import dom-eq open import dynamics-core open import lemmas-disjointness open import statics-core module disjointness where -- if a hole name is new in a term, then the resultant context is -- disjoint from any singleton context with that hole name mutual elab-new-disjoint-synth : ∀ {e u τ d Δ Γ Γ' τ'} → hole-name-new e u → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → Δ ## (■ (u , Γ' , τ')) elab-new-disjoint-synth HNNum ESNum = empty-disj _ elab-new-disjoint-synth (HNPlus hn hn₁) (ESPlus apt x x₁ x₂) = disjoint-parts (elab-new-disjoint-ana hn x₁) (elab-new-disjoint-ana hn₁ x₂) elab-new-disjoint-synth (HNAsc hn) (ESAsc x) = elab-new-disjoint-ana hn x elab-new-disjoint-synth HNVar (ESVar x₁) = empty-disj (■ (_ , _ , _)) elab-new-disjoint-synth (HNLam2 hn) (ESLam x₁ exp) = elab-new-disjoint-synth hn exp elab-new-disjoint-synth (HNHole x) ESEHole = disjoint-singles x elab-new-disjoint-synth (HNNEHole x hn) (ESNEHole x₁ exp) = disjoint-parts (disjoint-singles x) (elab-new-disjoint-synth hn exp) elab-new-disjoint-synth (HNAp hn hn₁) (ESAp x x₁ x₂ x₃ x₄ x₅) = disjoint-parts (elab-new-disjoint-ana hn x₄) (elab-new-disjoint-ana hn₁ x₅) elab-new-disjoint-synth (HNPair hn hn₁) (ESPair x x₁ exp exp₁) = disjoint-parts (elab-new-disjoint-synth hn exp) (elab-new-disjoint-synth hn₁ exp₁) elab-new-disjoint-synth (HNLam1 hn) () elab-new-disjoint-synth (HNInl hn) () elab-new-disjoint-synth (HNInr hn) () elab-new-disjoint-synth (HNCase hn hn₁ hn₂) () elab-new-disjoint-synth (HNFst hn) (ESFst x x₁ x₂) = elab-new-disjoint-ana hn x₂ elab-new-disjoint-synth (HNSnd hn) (ESSnd x x₁ x₂) = elab-new-disjoint-ana hn x₂ elab-new-disjoint-ana : ∀{e u τ d Δ Γ Γ' τ' τ2} → hole-name-new e u → Γ ⊢ e ⇐ τ ~> d :: τ2 ⊣ Δ → Δ ## (■ (u , Γ' , τ')) elab-new-disjoint-ana hn (EASubsume x x₁ x₂ x₃) = elab-new-disjoint-synth hn x₂ elab-new-disjoint-ana (HNLam1 hn) (EALam x₁ x₂ ex) = elab-new-disjoint-ana hn ex elab-new-disjoint-ana (HNHole x) EAEHole = disjoint-singles x elab-new-disjoint-ana (HNNEHole x hn) (EANEHole x₁ x₂) = disjoint-parts (disjoint-singles x) (elab-new-disjoint-synth hn x₂) elab-new-disjoint-ana (HNInl hn) (EAInl x x₁) = elab-new-disjoint-ana hn x₁ elab-new-disjoint-ana (HNInr hn) (EAInr x x₁) = elab-new-disjoint-ana hn x₁ elab-new-disjoint-ana (HNCase hn hn₁ hn₂) (EACase x x₁ x₂ x₃ x₄ x₅ _ _ x₆ x₇ x₈ x₉) = disjoint-parts (elab-new-disjoint-synth hn x₆) (disjoint-parts (elab-new-disjoint-ana hn₁ x₈) (elab-new-disjoint-ana hn₂ x₉)) -- dual of the above: if elaborating a term produces a context that's -- disjoint with a singleton context, it must be that the index is a new -- hole name in the original term mutual elab-disjoint-new-synth : ∀{e τ d Δ u Γ Γ' τ'} → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → Δ ## (■ (u , Γ' , τ')) → hole-name-new e u elab-disjoint-new-synth ESNum disj = HNNum elab-disjoint-new-synth (ESPlus {Δ1 = Δ1} apt x x₁ x₂) disj with elab-disjoint-new-ana x₁ (disjoint-union1 disj) | elab-disjoint-new-ana x₂ (disjoint-union2 {Γ1 = Δ1} disj) ... | ih1 | ih2 = HNPlus ih1 ih2 elab-disjoint-new-synth (ESVar x₁) disj = HNVar elab-disjoint-new-synth (ESLam x₁ ex) disj = HNLam2 (elab-disjoint-new-synth ex disj) elab-disjoint-new-synth (ESAp {Δ1 = Δ1} x x₁ x₂ x₃ x₄ x₅) disj with elab-disjoint-new-ana x₄ (disjoint-union1 disj) | elab-disjoint-new-ana x₅ (disjoint-union2 {Γ1 = Δ1} disj) ... | ih1 | ih2 = HNAp ih1 ih2 elab-disjoint-new-synth {Γ = Γ} ESEHole disj = HNHole (singles-notequal disj) elab-disjoint-new-synth {Γ = Γ} (ESNEHole {u = u} {Δ = Δ} x ex) disj = HNNEHole (singles-notequal (disjoint-union1 {Γ2 = Δ} disj)) (elab-disjoint-new-synth ex (disjoint-union2 {Γ1 = ■ (u , Γ , ⦇-⦈)} {Γ2 = Δ} disj)) elab-disjoint-new-synth (ESAsc x) disj = HNAsc (elab-disjoint-new-ana x disj) elab-disjoint-new-synth (ESPair {Δ1 = Δ1} {Δ2 = Δ2} x x₁ x₂ x₃) disj = HNPair (elab-disjoint-new-synth x₂ (disjoint-union1 {Γ1 = Δ1} {Γ2 = Δ2} disj)) (elab-disjoint-new-synth x₃ (disjoint-union2 {Γ1 = Δ1} {Γ2 = Δ2} disj)) elab-disjoint-new-synth (ESFst x x₁ x₂) disj = HNFst (elab-disjoint-new-ana x₂ disj) elab-disjoint-new-synth (ESSnd x x₁ x₂) disj = HNSnd (elab-disjoint-new-ana x₂ disj) elab-disjoint-new-ana : ∀{e τ d Δ u Γ Γ' τ2 τ'} → Γ ⊢ e ⇐ τ ~> d :: τ2 ⊣ Δ → Δ ## (■ (u , Γ' , τ')) → hole-name-new e u elab-disjoint-new-ana (EALam x₁ x₂ ex) disj = HNLam1 (elab-disjoint-new-ana ex disj) elab-disjoint-new-ana (EASubsume x x₁ x₂ x₃) disj = elab-disjoint-new-synth x₂ disj elab-disjoint-new-ana EAEHole disj = HNHole (singles-notequal disj) elab-disjoint-new-ana {Γ = Γ} (EANEHole {u = u} {τ = τ} {Δ = Δ} x x₁) disj = HNNEHole (singles-notequal (disjoint-union1 {Γ2 = Δ} disj)) (elab-disjoint-new-synth x₁ (disjoint-union2 {Γ1 = ■ (u , Γ , τ)} {Γ2 = Δ} disj)) elab-disjoint-new-ana (EAInl x x₁) disj = HNInl (elab-disjoint-new-ana x₁ disj) elab-disjoint-new-ana (EAInr x x₁) disj = HNInr (elab-disjoint-new-ana x₁ disj) elab-disjoint-new-ana {Γ = Γ} (EACase {Δ = Δ} {Δ1 = Δ1} {Δ2 = Δ2} x x₁ x₂ x₃ x₄ x₅ _ _ x₆ x₇ x₈ x₉) disj = HNCase (elab-disjoint-new-synth x₆ (disjoint-union1 disj)) (elab-disjoint-new-ana x₈ (disjoint-union1 {Γ2 = Δ2} (disjoint-union2 {Γ1 = Δ} disj))) (elab-disjoint-new-ana x₉ (disjoint-union2 {Γ1 = Δ1} (disjoint-union2 {Γ1 = Δ} disj))) -- collect up the hole names of a term as the indices of a trivial context data holes : (e : hexp) (H : ⊤ ctx) → Set where HNum : ∀{n} → holes (N n) ∅ HPlus : ∀{e1 e2 H1 H2} → holes e1 H1 → holes e2 H2 → holes (e1 ·+ e2) (H1 ∪ H2) HAsc : ∀{e τ H} → holes e H → holes (e ·: τ) H HVar : ∀{x} → holes (X x) ∅ HLam1 : ∀{x e H} → holes e H → holes (·λ x e) H HLam2 : ∀{x e τ H} → holes e H → holes (·λ x ·[ τ ] e) H HAp : ∀{e1 e2 H1 H2} → holes e1 H1 → holes e2 H2 → holes (e1 ∘ e2) (H1 ∪ H2) HInl : ∀{e H} → holes e H → holes (inl e) H HInr : ∀{e H} → holes e H → holes (inr e) H HCase : ∀{e x e1 y e2 H H1 H2} → holes e H → holes e1 H1 → holes e2 H2 → holes (case e x e1 y e2) (H ∪ (H1 ∪ H2)) HPair : ∀{e1 e2 H1 H2} → holes e1 H1 → holes e2 H2 → holes ⟨ e1 , e2 ⟩ (H1 ∪ H2) HFst : ∀{e H} → holes e H → holes (fst e) H HSnd : ∀{e H} → holes e H → holes (snd e) H HEHole : ∀{u} → holes (⦇-⦈[ u ]) (■ (u , <>)) HNEHole : ∀{e u H} → holes e H → holes (⦇⌜ e ⌟⦈[ u ]) (H ,, (u , <>)) -- the above judgement has mode (∀,∃). this doesn't prove uniqueness; any -- context that extends the one computed here will be indistinguishable -- but we'll treat this one as canonical find-holes : (e : hexp) → Σ[ H ∈ ⊤ ctx ](holes e H) find-holes (N n) = ∅ , HNum find-holes (e1 ·+ e2) with find-holes e1 | find-holes e2 ... | (h1 , d1) | (h2 , d2) = (h1 ∪ h2 ) , (HPlus d1 d2) find-holes (e ·: x) with find-holes e ... | (h , d) = h , (HAsc d) find-holes (X x) = ∅ , HVar find-holes (·λ x e) with find-holes e ... | (h , d) = h , HLam1 d find-holes (·λ x ·[ x₁ ] e) with find-holes e ... | (h , d) = h , HLam2 d find-holes (e1 ∘ e2) with find-holes e1 | find-holes e2 ... | (h1 , d1) | (h2 , d2) = (h1 ∪ h2 ) , (HAp d1 d2) find-holes ⦇-⦈[ x ] = (■ (x , <>)) , HEHole find-holes ⦇⌜ e ⌟⦈[ x ] with find-holes e ... | (h , d) = h ,, (x , <>) , HNEHole d find-holes (inl e) with find-holes e ... | (h , d) = h , HInl d find-holes (inr e) with find-holes e ... | (h , d) = h , HInr d find-holes (case e x e₁ x₁ e₂) with find-holes e | find-holes e₁ | find-holes e₂ ... | (h , d) | (h1 , d1) | (h2 , d2) = (h ∪ (h1 ∪ h2)) , HCase d d1 d2 find-holes ⟨ e , e₁ ⟩ with find-holes e | find-holes e₁ ... | (h , d) | (h1 , d1) = h ∪ h1 , HPair d d1 find-holes (fst e) with find-holes e ... | (h , d) = h , HFst d find-holes (snd e) with find-holes e ... | (h , d) = h , HSnd d -- if a hole name is new then it's apart from the collection of hole -- names lem-apart-new : ∀{e H u} → holes e H → hole-name-new e u → u # H lem-apart-new HNum x = refl lem-apart-new (HPlus {H1 = H1} {H2 = H2} h h₁) (HNPlus hn hn₁) = apart-parts H1 H2 _ (lem-apart-new h hn) (lem-apart-new h₁ hn₁) lem-apart-new (HAsc h) (HNAsc hn) = lem-apart-new h hn lem-apart-new HVar HNVar = refl lem-apart-new (HLam1 h) (HNLam1 hn) = lem-apart-new h hn lem-apart-new (HLam2 h) (HNLam2 hn) = lem-apart-new h hn lem-apart-new (HAp {H1 = H1} {H2 = H2} h h₁) (HNAp hn hn₁) = apart-parts H1 H2 _ (lem-apart-new h hn) (lem-apart-new h₁ hn₁) lem-apart-new HEHole (HNHole x) = apart-singleton (flip x) lem-apart-new (HNEHole {u = u'} {H = H} h) (HNNEHole {u = u} x hn) = apart-parts (■ (u' , <>)) H u (apart-singleton (flip x)) (lem-apart-new h hn) lem-apart-new (HInl h) (HNInl hn) = lem-apart-new h hn lem-apart-new (HInr h) (HNInr hn) = lem-apart-new h hn lem-apart-new (HCase {H = H} {H1 = H1} {H2 = H2} h h₁ h₂) (HNCase {u = u'} hn hn₁ hn₂) = apart-parts H (H1 ∪ H2) u' (lem-apart-new h hn) (apart-parts H1 H2 u' (lem-apart-new h₁ hn₁) (lem-apart-new h₂ hn₂)) lem-apart-new (HPair {H1 = H1} {H2 = H2} h h₁) (HNPair {u = u} hn hn₁) = apart-parts H1 H2 u (lem-apart-new h hn) (lem-apart-new h₁ hn₁) lem-apart-new (HFst h) (HNFst hn) = lem-apart-new h hn lem-apart-new (HSnd h) (HNSnd hn) = lem-apart-new h hn -- if the holes of two expressions are disjoint, so are their collections -- of hole names holes-disjoint-disjoint : ∀{e1 e2 H1 H2} → holes e1 H1 → holes e2 H2 → holes-disjoint e1 e2 → H1 ## H2 holes-disjoint-disjoint HNum he2 HDNum = empty-disj _ holes-disjoint-disjoint (HPlus he1 he2) he3 (HDPlus hd hd₁) = disjoint-parts (holes-disjoint-disjoint he1 he3 hd) (holes-disjoint-disjoint he2 he3 hd₁) holes-disjoint-disjoint (HAsc he1) he2 (HDAsc hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint HVar he2 HDVar = empty-disj _ holes-disjoint-disjoint (HLam1 he1) he2 (HDLam1 hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint (HLam2 he1) he2 (HDLam2 hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint (HAp he1 he2) he3 (HDAp hd hd₁) = disjoint-parts (holes-disjoint-disjoint he1 he3 hd) (holes-disjoint-disjoint he2 he3 hd₁) holes-disjoint-disjoint HEHole he2 (HDHole x) = lem-apart-sing-disj (lem-apart-new he2 x) holes-disjoint-disjoint (HNEHole he1) he2 (HDNEHole x hd) = disjoint-parts (lem-apart-sing-disj (lem-apart-new he2 x)) (holes-disjoint-disjoint he1 he2 hd) holes-disjoint-disjoint (HInl he1) he2 (HDInl hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint (HInr he1) he2 (HDInr hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint (HCase he1 he3 he4) he2 (HDCase hd hd₁ hd₂) = disjoint-parts (holes-disjoint-disjoint he1 he2 hd) (disjoint-parts (holes-disjoint-disjoint he3 he2 hd₁) (holes-disjoint-disjoint he4 he2 hd₂)) holes-disjoint-disjoint (HPair he1 he3) he2 (HDPair hd hd₁) = disjoint-parts (holes-disjoint-disjoint he1 he2 hd) (holes-disjoint-disjoint he3 he2 hd₁) holes-disjoint-disjoint (HFst he1) he2 (HDFst hd) = holes-disjoint-disjoint he1 he2 hd holes-disjoint-disjoint (HSnd he1) he2 (HDSnd hd) = holes-disjoint-disjoint he1 he2 hd -- the holes of an expression have the same domain as the context -- produced during expansion; that is, we don't add anything we don't -- find in the term during expansion. mutual holes-delta-ana : ∀{Γ H e τ d τ' Δ} → holes e H → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ → dom-eq Δ H holes-delta-ana (HLam1 h) (EALam x₁ x₂ exp) = holes-delta-ana h exp holes-delta-ana h (EASubsume x x₁ x₂ x₃) = holes-delta-synth h x₂ holes-delta-ana (HEHole {u = u}) EAEHole = dom-single u holes-delta-ana (HNEHole {u = u} h) (EANEHole x x₁) = dom-union (lem-apart-sing-disj (lem-apart-new h (elab-disjoint-new-synth x₁ x))) (dom-single u) (holes-delta-synth h x₁) holes-delta-ana (HInl h) (EAInl x x₁) = holes-delta-ana h x₁ holes-delta-ana (HInr h) (EAInr x x₁) = holes-delta-ana h x₁ holes-delta-ana (HCase h h₁ h₂) (EACase {Δ = Δ} x x₁ x₂ x₃ x₄ x₅ _ _ x₆ x₇ x₈ x₉) = dom-union (##-comm (disjoint-parts (##-comm (holes-disjoint-disjoint h h₁ x)) (##-comm (holes-disjoint-disjoint h h₂ x₁)))) (holes-delta-synth h x₆) (dom-union (holes-disjoint-disjoint h₁ h₂ x₂) (holes-delta-ana h₁ x₈) (holes-delta-ana h₂ x₉)) holes-delta-synth : ∀{Γ H e τ d Δ} → holes e H → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → dom-eq Δ H holes-delta-synth HNum ESNum = dom-∅ holes-delta-synth (HPlus h h₁) (ESPlus x apt x₁ x₂) = dom-union (holes-disjoint-disjoint h h₁ x) (holes-delta-ana h x₁) (holes-delta-ana h₁ x₂) holes-delta-synth (HAsc h) (ESAsc x) = holes-delta-ana h x holes-delta-synth HVar (ESVar x₁) = dom-∅ holes-delta-synth (HLam2 h) (ESLam x₁ exp) = holes-delta-synth h exp holes-delta-synth (HAp h h₁) (ESAp x x₁ x₂ x₃ x₄ x₅) = dom-union (holes-disjoint-disjoint h h₁ x) (holes-delta-ana h x₄) (holes-delta-ana h₁ x₅) holes-delta-synth (HEHole {u = u}) ESEHole = dom-single u holes-delta-synth (HNEHole {u = u} h) (ESNEHole x exp) = dom-union (lem-apart-sing-disj (lem-apart-new h (elab-disjoint-new-synth exp x))) (dom-single u) (holes-delta-synth h exp) holes-delta-synth (HPair h h₁) (ESPair x x₁ exp exp₁) = dom-union (holes-disjoint-disjoint h h₁ x) (holes-delta-synth h exp) (holes-delta-synth h₁ exp₁) holes-delta-synth (HLam1 hn) () holes-delta-synth (HInl hn) () holes-delta-synth (HInr hn) () holes-delta-synth (HCase hn hn₁ hn₂) () holes-delta-synth (HFst hn) (ESFst x x₁ x₂) = holes-delta-ana hn x₂ holes-delta-synth (HSnd hn) (ESSnd x x₁ x₂) = holes-delta-ana hn x₂ -- this is one of the main results of this file: -- -- if you elaborate two hole-disjoint expressions analytically, the Δs -- produced are disjoint. -- -- the proof technique here is explcitly *not* structurally inductive on the -- expansion judgement, because that approach relies on weakening of -- expansion, which is false because of the substitution contexts. giving -- expansion weakning would take away unicity, so we avoid the whole -- question. elab-ana-disjoint : ∀{e1 e2 τ1 τ2 e1' e2' τ1' τ2' Γ1 Γ2 Δ1 Δ2} → holes-disjoint e1 e2 → Γ1 ⊢ e1 ⇐ τ1 ~> e1' :: τ1' ⊣ Δ1 → Γ2 ⊢ e2 ⇐ τ2 ~> e2' :: τ2' ⊣ Δ2 → Δ1 ## Δ2 elab-ana-disjoint {e1} {e2} hd ana1 ana2 with find-holes e1 | find-holes e2 ... | (_ , he1) | (_ , he2) = dom-eq-disj (holes-disjoint-disjoint he1 he2 hd) (holes-delta-ana he1 ana1) (holes-delta-ana he2 ana2) elab-synth-disjoint : ∀{e1 e2 τ1 τ2 e1' e2' Γ1 Γ2 Δ1 Δ2} → holes-disjoint e1 e2 → Γ1 ⊢ e1 ⇒ τ1 ~> e1' ⊣ Δ1 → Γ2 ⊢ e2 ⇒ τ2 ~> e2' ⊣ Δ2 → Δ1 ## Δ2 elab-synth-disjoint {e1} {e2} hd synth1 synth2 with find-holes e1 | find-holes e2 ... | (_ , he1) | (_ , he2) = dom-eq-disj (holes-disjoint-disjoint he1 he2 hd) (holes-delta-synth he1 synth1) (holes-delta-synth he2 synth2) elab-synth-ana-disjoint : ∀{e1 e2 τ1 τ2 e1' e2' τ2' Γ1 Γ2 Δ1 Δ2} → holes-disjoint e1 e2 → Γ1 ⊢ e1 ⇒ τ1 ~> e1' ⊣ Δ1 → Γ2 ⊢ e2 ⇐ τ2 ~> e2' :: τ2' ⊣ Δ2 → Δ1 ## Δ2 elab-synth-ana-disjoint {e1} {e2} hd synth ana with find-holes e1 | find-holes e2 ... | (_ , he1) | (_ , he2) = dom-eq-disj (holes-disjoint-disjoint he1 he2 hd) (holes-delta-synth he1 synth) (holes-delta-ana he2 ana)
{ "alphanum_fraction": 0.593156813, "avg_line_length": 65.6428571429, "ext": "agda", "hexsha": "9fd259770335cf5f56d19042044eb2d04e113e8a", "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": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_path": "disjointness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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/hazelnut-agda", "max_issues_repo_path": "disjointness.agda", "max_line_length": 343, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_path": "disjointness.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6372, "size": 16542 }
open import Data.Product using ( _×_ ; _,_ ) open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ ) open import FRP.LTL.Time.Interval using ( _⊑_ ; _~_ ; _⌢_∵_ ) open import FRP.LTL.ISet.Core using ( ISet ; [_] ; _,_ ; M⟦_⟧ ; splitM⟦_⟧ ; subsumM⟦_⟧ ) module FRP.LTL.ISet.Sum where _∨_ : ISet → ISet → ISet A ∨ B = [ (λ i → M⟦ A ⟧ i ⊎ M⟦ B ⟧ i) , split , subsum ] where split : ∀ i j i~j → (M⟦ A ⟧ (i ⌢ j ∵ i~j) ⊎ M⟦ B ⟧ (i ⌢ j ∵ i~j)) → ((M⟦ A ⟧ i ⊎ M⟦ B ⟧ i) × (M⟦ A ⟧ j ⊎ M⟦ B ⟧ j)) split i j i~j (inj₁ σ) with splitM⟦ A ⟧ i j i~j σ split i j i~j (inj₁ σ) | (σ₁ , σ₂) = (inj₁ σ₁ , inj₁ σ₂) split i j i~j (inj₂ τ) with splitM⟦ B ⟧ i j i~j τ split i j i~j (inj₂ τ) | (τ₁ , τ₂) = (inj₂ τ₁ , inj₂ τ₂) subsum : ∀ i j → (i ⊑ j) → (M⟦ A ⟧ j ⊎ M⟦ B ⟧ j) → (M⟦ A ⟧ i ⊎ M⟦ B ⟧ i) subsum i j i⊑j (inj₁ σ) = inj₁ (subsumM⟦ A ⟧ i j i⊑j σ) subsum i j i⊑j (inj₂ τ) = inj₂ (subsumM⟦ B ⟧ i j i⊑j τ)
{ "alphanum_fraction": 0.5005464481, "avg_line_length": 41.5909090909, "ext": "agda", "hexsha": "c9414ed3322f14f0e243996ae633d79bfb1a5751", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z", "max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z", "max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/agda-frp-ltl", "max_forks_repo_path": "src/FRP/LTL/ISet/Sum.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/agda-frp-ltl", "max_issues_repo_path": "src/FRP/LTL/ISet/Sum.agda", "max_line_length": 88, "max_stars_count": 21, "max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-frp-ltl", "max_stars_repo_path": "src/FRP/LTL/ISet/Sum.agda", "max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z", "num_tokens": 507, "size": 915 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Non-empty AVL trees, where equality for keys is propositional equality ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel; IsStrictTotalOrder; StrictTotalOrder) open import Relation.Binary.PropositionalEquality using (_≡_; refl; subst) module Data.AVL.NonEmpty.Propositional {k r} {Key : Set k} {_<_ : Rel Key r} (isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_) where open import Level private strictTotalOrder = record { isStrictTotalOrder = isStrictTotalOrder} open import Data.AVL.Value (StrictTotalOrder.Eq.setoid strictTotalOrder) import Data.AVL.NonEmpty strictTotalOrder as AVL⁺ Tree⁺ : ∀ {v} (V : Key → Set v) → Set (k ⊔ v ⊔ r) Tree⁺ V = AVL⁺.Tree⁺ λ where .Value.family → V .Value.respects refl t → t open AVL⁺ hiding (Tree⁺) public
{ "alphanum_fraction": 0.6168898043, "avg_line_length": 34.6785714286, "ext": "agda", "hexsha": "175ee682e0de3ea9e3d5a4fe69566398bc81503c", "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/AVL/NonEmpty/Propositional.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/AVL/NonEmpty/Propositional.agda", "max_line_length": 77, "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/AVL/NonEmpty/Propositional.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": 242, "size": 971 }
module Vec where import Nat import Fin open Nat hiding (_==_; _<_) open Fin data Nil : Set where vnil : Nil data Cons (A As : Set) : Set where vcons : A -> As -> Cons A As mutual Vec' : Nat -> Set -> Set Vec' zero A = Nil Vec' (suc n) A = Cons A (Vec n A) data Vec (n : Nat)(A : Set) : Set where vec : Vec' n A -> Vec n A ε : {A : Set} -> Vec zero A ε = vec vnil _∷_ : {A : Set}{n : Nat} -> A -> Vec n A -> Vec (suc n) A x ∷ xs = vec (vcons x xs) _!_ : {n : Nat}{A : Set} -> Vec n A -> Fin n -> A _!_ {zero} _ (fin ()) _!_ {suc n} (vec (vcons x xs)) (fin fz) = x _!_ {suc n} (vec (vcons x xs)) (fin (fs i)) = xs ! i map : {n : Nat}{A B : Set} -> (A -> B) -> Vec n A -> Vec n B map {zero} f (vec vnil) = ε map {suc n} f (vec (vcons x xs)) = f x ∷ map f xs fzeroToN-1 : (n : Nat) -> Vec n (Fin n) fzeroToN-1 zero = ε fzeroToN-1 (suc n) = fzero ∷ map fsuc (fzeroToN-1 n)
{ "alphanum_fraction": 0.5064239829, "avg_line_length": 21.7209302326, "ext": "agda", "hexsha": "d1a5817102e8910886514a654a000e1e24c11f0e", "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": "benchmark/ac/Vec.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": "benchmark/ac/Vec.agda", "max_line_length": 60, "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": "benchmark/ac/Vec.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": 395, "size": 934 }
-- Andreas, 2015-11-09, issue 1710 reported by vejkse -- {-# OPTIONS -v tc.with:20 #-} record wrap (A : Set) : Set where field out : A open wrap public record MapsFrom (A : Set) : Set₁ where field cod : Set map : A → cod open MapsFrom public wrapped : (A : Set) → MapsFrom A cod (wrapped A) = wrap A out (map (wrapped A) a) with a ... | _ = a
{ "alphanum_fraction": 0.6132596685, "avg_line_length": 19.0526315789, "ext": "agda", "hexsha": "8230d02e9afe7360710f1384ed1fbc5d5d679f7a", "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/Issue1710.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/Issue1710.agda", "max_line_length": 53, "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/Issue1710.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": 127, "size": 362 }
module Text.Lex where open import Prelude record TokenDFA {s} (A : Set) (Tok : Set) : Set (lsuc s) where field State : Set s initial : State accept : State → Maybe Tok consume : A → State → Maybe State instance FunctorTokenDFA : ∀ {s} {A : Set} → Functor (TokenDFA {s = s} A) TokenDFA.State (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.State dfa TokenDFA.initial (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.initial dfa TokenDFA.accept (fmap {{FunctorTokenDFA}} f dfa) s = f <$> TokenDFA.accept dfa s TokenDFA.consume (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.consume dfa keywordToken : {A : Set} {{EqA : Eq A}} → List A → TokenDFA A ⊤ TokenDFA.State (keywordToken {A = A} kw) = List A TokenDFA.initial (keywordToken kw) = kw TokenDFA.accept (keywordToken kw) [] = just _ TokenDFA.accept (keywordToken kw) (_ ∷ _) = nothing TokenDFA.consume (keywordToken kw) _ [] = nothing TokenDFA.consume (keywordToken kw) y (x ∷ xs) = ifYes (x == y) then just xs else nothing matchToken : ∀ {A : Set} (p : A → Bool) → TokenDFA A (List (Σ A (IsTrue ∘ p))) TokenDFA.State (matchToken {A = A} p) = List (Σ A (IsTrue ∘ p)) TokenDFA.initial (matchToken _) = [] TokenDFA.accept (matchToken _) xs = just (reverse xs) TokenDFA.consume (matchToken p) x xs = if′ p x then just ((x , it) ∷ xs) else nothing natToken : TokenDFA Char Nat natToken = pNat <$> matchToken isDigit where pNat = foldl (λ { n (d , _) → 10 * n + (charToNat d - charToNat '0') }) 0 identToken : ∀ {A : Set} → (A → Bool) → (A → Bool) → TokenDFA A (List A) TokenDFA.State (identToken {A = A} _ _) = Maybe (List A) TokenDFA.initial (identToken _ _) = nothing TokenDFA.accept (identToken _ _) = fmap reverse TokenDFA.consume (identToken first _) x nothing = if first x then just (just [ x ]) else nothing TokenDFA.consume (identToken _ then) x (just xs) = if then x then just (just (x ∷ xs)) else nothing module _ {s : Level} {A Tok : Set} where private DFA = TokenDFA {s = s} A Tok open TokenDFA init : DFA → Σ DFA State init d = d , initial d feed : A → Σ DFA State → Either DFA (Σ DFA State) feed x (d , s) = maybe (left d) (right ∘ _,_ d) (consume d x s) accepts : List (Σ DFA State) → List Tok accepts = concatMap (λ { (d , s) → maybe [] [_] (accept d s) }) tokenize-loop : List DFA → List (Σ DFA State) → List A → List Tok tokenize-loop idle active [] = case accepts active of λ where [] → [] -- not quite right if there are active DFAs (t ∷ _) → [ t ] tokenize-loop idle [] (x ∷ xs) = flip uncurry (partitionMap (feed x) (map init idle)) λ where idle₁ [] → [] idle₁ active₁ → tokenize-loop idle₁ active₁ xs tokenize-loop idle active (x ∷ xs) = flip uncurry (partitionMap (feed x) active) λ where idle₁ [] → case accepts active of λ where [] → [] (t ∷ _) → flip uncurry (partitionMap (feed x) (map init (idle ++ idle₁))) λ where _ [] → t ∷ [] idle₂ active₂ → t List.∷ tokenize-loop idle₂ active₂ xs idle₁ active₁ → tokenize-loop (idle ++ idle₁) active₁ xs tokenize : List (TokenDFA {s = s} A Tok) → List A → List Tok tokenize dfas xs = tokenize-loop dfas [] xs
{ "alphanum_fraction": 0.6038300419, "avg_line_length": 41.775, "ext": "agda", "hexsha": "0266e1640b9c8848f6e875e49d9c5f305d6a5ef5", "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": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_path": "src/Text/Lex.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "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": "t-more/agda-prelude", "max_issues_repo_path": "src/Text/Lex.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_path": "src/Text/Lex.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1085, "size": 3342 }
module Common.Equality where open import Common.Level infix 4 _≡_ data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} {-# BUILTIN REFL refl #-} subst : ∀ {a p}{A : Set a}(P : A → Set p){x y : A} → x ≡ y → P x → P y subst P refl t = t cong : ∀ {a b}{A : Set a}{B : Set b}(f : A → B){x y : A} → x ≡ y → f x ≡ f y cong f refl = refl sym : ∀ {a}{A : Set a}{x y : A} → x ≡ y → y ≡ x sym refl = refl trans : ∀ {a}{A : Set a}{x y z : A} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl
{ "alphanum_fraction": 0.4896810507, "avg_line_length": 22.2083333333, "ext": "agda", "hexsha": "fe2ea1289ad755f54cc5f244699a4943c9a27c74", "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/Common/Equality.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/Common/Equality.agda", "max_line_length": 76, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/Common/Equality.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": 235, "size": 533 }
-- Copyright: (c) 2016 Ertugrul Söylemez -- License: BSD3 -- Maintainer: Ertugrul Söylemez <[email protected]> module Data.Int.Core where open import Agda.Builtin.Int public renaming (Int to ℤ) using (pos; negsuc) open import Agda.Builtin.TrustMe open import Classes open import Core open import Data.Nat.Core renaming (module Props to ℕP) using (ℕ; ℕ-Number; ℕ-Plus; ℕ-Times; suc; zero) _-ℕ_ : ℕ → ℕ → ℤ x -ℕ zero = pos x zero -ℕ suc y = negsuc y suc x -ℕ suc y = x -ℕ y infixl 6 _-ℕ_ instance ℤ-Negative : Negative ℤ ℤ-Negative = record { Constraint = λ _ → ⊤; fromNeg = λ x → zero -ℕ x } ℤ-Number : Number ℤ ℤ-Number = record { Constraint = λ _ → ⊤; fromNat = λ x → pos x } ℤ,≡ : Equiv ℤ ℤ,≡ = PropEq ℤ instance ℤ-Plus : Plus ℤ ℤ-Plus = record { _+_ = _+ℤ_ } where _+ℤ_ : ℤ → ℤ → ℤ pos x +ℤ pos y = pos (x + y) pos x +ℤ negsuc y = x -ℕ suc y negsuc x +ℤ pos y = y -ℕ suc x negsuc x +ℤ negsuc y = negsuc (suc (x + y)) ℤ-Times : Times ℤ ℤ-Times = record { _*_ = _*ℤ_ } where _*ℤ_ : ℤ → ℤ → ℤ pos x *ℤ pos y = pos (x * y) pos zero *ℤ negsuc y = 0 pos (suc x) *ℤ negsuc y = negsuc (y + x * suc y) negsuc x *ℤ pos zero = 0 negsuc x *ℤ pos (suc y) = negsuc (y + x * suc y) negsuc x *ℤ negsuc y = pos (suc x * suc y) neg : ℤ → ℤ neg = _*_ -1 _-_ : ℤ → ℤ → ℤ x - y = x + neg y infixl 6 _-_ module Props where open module MyEquiv {A : Set} = Equiv (PropEq A) private _!+!_ = cong2 (the (ℤ → ℤ → ℤ) _+_) _!-ℕ!_ = cong2 _-ℕ_ _!*!_ = cong2 (the (ℤ → ℤ → ℤ) _*_) R = λ {A} (x : A) → refl {x = x} infixl 6 _!+!_ _!-ℕ!_ infixl 7 _!*!_ sub-neg-zero : ∀ x → x -ℕ zero ≈ pos x sub-neg-zero _ = refl +-left-id : ∀ x → 0 + x ≈ x +-left-id (pos n) = refl +-left-id (negsuc n) = refl +-right-id : ∀ x → x + 0 ≈ x +-right-id (pos x) = cong pos (ℕP.+-right-id x) +-right-id (negsuc x) = refl +-comm : ∀ x y → x + y ≈ y + x +-comm (pos x) (pos y) = cong pos (ℕP.+-comm x y) +-comm (pos x) (negsuc y) = refl +-comm (negsuc x) (pos y) = refl +-comm (negsuc x) (negsuc y) = cong negsuc (cong suc (ℕP.+-comm x y)) sub-sum-right : ∀ x y z → x -ℕ suc (y + z) ≈ negsuc y + (x -ℕ z) sub-sum-right x zero zero = refl sub-sum-right zero zero (suc z) = refl sub-sum-right (suc x) zero (suc z) = sub-sum-right x zero z sub-sum-right x (suc y) zero = R x !-ℕ! cong suc (cong suc (ℕP.+-right-id y)) sub-sum-right zero (suc y) (suc z) = cong negsuc (cong suc (ℕP.+-suc-assoc y z)) sub-sum-right (suc x) (suc y) (suc z) = begin x -ℕ suc (y + suc z) ≈[ R x !-ℕ! cong suc (ℕP.+-suc-assoc y z) ] x -ℕ suc (suc y + z) ≈[ sub-sum-right x (suc y) z ] negsuc (suc y) + (x -ℕ z) qed sub-sum-left : ∀ x y z → (x + y) -ℕ z ≈ pos x + (y -ℕ z) sub-sum-left zero y z = sym (+-left-id (y -ℕ z)) sub-sum-left (suc x) y zero = refl sub-sum-left (suc x) zero (suc z) = ℕP.+-right-id x !-ℕ! R z sub-sum-left (suc x) (suc y) (suc z) = begin (x + suc y) -ℕ z ≈[ ℕP.+-suc-assoc x y !-ℕ! R z ] suc (x + y) -ℕ z ≈[ sub-sum-left (suc x) y z ] pos (suc x) + (y -ℕ z) qed +-assoc : ∀ x y z → (x + y) + z ≈ x + (y + z) +-assoc (pos x) (pos y) (pos z) = cong pos (ℕP.+-assoc x _ _) +-assoc (pos x) (pos y) (negsuc z) = sub-sum-left x y (suc z) +-assoc (pos x) (negsuc y) (pos z) = begin (x -ℕ suc y) + pos z ≈[ +-comm (x -ℕ suc y) (pos z) ] pos z + (x -ℕ suc y) ≈[ sym (sub-sum-left z x (suc y)) ] (z + x) -ℕ suc y ≈[ ℕP.+-comm z x !-ℕ! R (suc y) ] (x + z) -ℕ suc y ≈[ sub-sum-left x z (suc y) ] pos x + (z -ℕ suc y) qed +-assoc (pos x) (negsuc y) (negsuc z) = begin x -ℕ suc y + negsuc z ≈[ +-comm (x -ℕ suc y) (negsuc z) ] negsuc z + (x -ℕ suc y) ≈[ sym (sub-sum-right x z (suc y)) ] x -ℕ (suc z + suc y) ≈[ R x !-ℕ! ℕP.+-comm (suc z) (suc y) ] x -ℕ (suc y + suc z) ≈[ R x !-ℕ! cong suc (ℕP.+-suc-assoc y z) ] x -ℕ suc (suc (y + z)) qed +-assoc (negsuc x) (pos y) (pos z) = begin (y -ℕ suc x) + pos z ≈[ +-comm (y -ℕ suc x) (pos z) ] pos z + (y -ℕ suc x) ≈[ sym (sub-sum-left z y (suc x)) ] (z + y) -ℕ suc x ≈[ ℕP.+-comm z y !-ℕ! R (suc x) ] (y + z) -ℕ suc x qed +-assoc (negsuc x) (pos y) (negsuc z) = begin y -ℕ suc x + negsuc z ≈[ +-comm (y -ℕ suc x) (negsuc z) ] negsuc z + (y -ℕ suc x) ≈[ sym (sub-sum-right y z (suc x)) ] y -ℕ (suc z + suc x) ≈[ R y !-ℕ! ℕP.+-comm (suc z) (suc x) ] y -ℕ (suc x + suc z) ≈[ sub-sum-right y x (suc z) ] negsuc x + (y -ℕ suc z) qed +-assoc (negsuc x) (negsuc y) (pos zero) = refl +-assoc (negsuc x) (negsuc y) (pos (suc z)) = sub-sum-right z x y +-assoc (negsuc x) (negsuc y) (negsuc z) = cong negsuc $ cong suc $ begin suc ((x + y) + z) ≈[ cong suc (ℕP.+-assoc x y z) ] suc (x + (y + z)) ≈[ sym (ℕP.+-suc-assoc x (y + z)) ] x + (suc (y + z)) qed *-left-id : ∀ x → 1 * x ≈ x *-left-id (pos x) = cong pos (ℕP.+-right-id x) *-left-id (negsuc x) = cong negsuc (ℕP.+-right-id x) *-right-id : ∀ x → x * 1 ≈ x *-right-id (pos x) = cong pos (ℕP.*-right-id x) *-right-id (negsuc x) = cong negsuc (trans (ℕP.*-comm x 1) (ℕP.+-right-id x)) *-assoc : ∀ x y z → (x * y) * z ≈ x * (y * z) *-assoc (pos x) (pos y) (pos z) = cong pos (ℕP.*-assoc x y z) *-assoc (pos zero) (pos zero) (negsuc z) = refl *-assoc (pos zero) (pos (suc y)) (negsuc z) = refl *-assoc (pos (suc x)) (pos zero) (negsuc z) = begin pos (x * 0) * negsuc z ≈[ cong pos (ℕP.*-right-zero x) !*! R (negsuc z) ] pos 0 * negsuc z ≈[ cong pos (sym (ℕP.*-right-zero x)) ] pos (x * 0) qed *-assoc (pos (suc x)) (pos (suc y)) (negsuc z) = cong negsuc $ ℕP.suc-inj $ ℕP.*-assoc (suc x) (suc y) (suc z) *-assoc (pos zero) (negsuc y) (pos zero) = refl *-assoc (pos zero) (negsuc y) (pos (suc z)) = refl *-assoc (pos (suc x)) (negsuc y) (pos zero) = cong pos (sym (ℕP.*-right-zero x)) *-assoc (pos (suc x)) (negsuc y) (pos (suc z)) = cong negsuc $ ℕP.suc-inj $ ℕP.*-assoc (suc x) (suc y) (suc z) *-assoc (pos zero) (negsuc y) (negsuc z) = refl *-assoc (pos (suc x)) (negsuc y) (negsuc z) = cong pos (ℕP.*-assoc (suc x) (suc y) (suc z)) *-assoc (negsuc x) (pos zero) (pos z) = refl *-assoc (negsuc x) (pos (suc y)) (pos zero) = R (negsuc x) !*! cong pos (sym (ℕP.*-right-zero y)) *-assoc (negsuc x) (pos (suc y)) (pos (suc z)) = cong negsuc $ ℕP.suc-inj $ ℕP.*-assoc (suc x) (suc y) (suc z) *-assoc (negsuc x) (pos zero) (negsuc z) = refl *-assoc (negsuc x) (pos (suc y)) (negsuc z) = cong pos (ℕP.*-assoc (suc x) (suc y) (suc z)) *-assoc (negsuc x) (negsuc y) (pos zero) = cong pos (ℕP.*-right-zero (y + x * suc y)) *-assoc (negsuc x) (negsuc y) (pos (suc z)) = cong pos (ℕP.*-assoc (suc x) (suc y) (suc z)) *-assoc (negsuc x) (negsuc y) (negsuc z) = cong negsuc $ ℕP.suc-inj $ ℕP.*-assoc (suc x) (suc y) (suc z) *-comm : ∀ x y → x * y ≈ y * x *-comm (pos x) (pos y) = cong pos (ℕP.*-comm x y) *-comm (pos zero) (negsuc y) = refl *-comm (pos (suc x)) (negsuc y) = cong negsuc (ℕP.suc-inj (ℕP.*-comm (suc x) (suc y))) *-comm (negsuc x) (pos zero) = refl *-comm (negsuc x) (pos (suc y)) = cong negsuc (ℕP.suc-inj (ℕP.*-comm (suc x) (suc y))) *-comm (negsuc x) (negsuc y) = cong pos (ℕP.*-comm (suc x) (suc y)) *-left-zero : ∀ x → 0 * x ≈ 0 *-left-zero (pos x) = refl *-left-zero (negsuc x) = refl neg-invol : ∀ x → neg (neg x) ≈ x neg-invol x = begin -1 * (-1 * x) ≈[ sym (*-assoc -1 -1 x) ] 1 * x ≈[ *-left-id x ] x qed *-right-zero : ∀ x → x * 0 ≈ 0 *-right-zero x = trans (*-comm x 0) (*-left-zero x) *-suc-dist : ∀ x y → pos (suc x) * y ≈ y + pos x * y *-suc-dist x (pos y) = refl *-suc-dist zero (negsuc y) = cong negsuc (ℕP.+-right-id y) *-suc-dist (suc x) (negsuc y) = sub-sum-right 0 y (suc (y + x * suc y)) *-+-left-dist-ℕ : ∀ x a b → pos x * (a + b) ≈ pos x * a + pos x * b *-+-left-dist-ℕ zero a b = begin 0 * (a + b) ≈[ *-left-zero (a + b) ] 0 ≈[ sym (*-left-zero a) !+! sym (*-left-zero b) ] 0 * a + 0 * b qed *-+-left-dist-ℕ (suc x) a b = begin pos (suc x) * (a + b) ≈[ *-suc-dist x (a + b) ] (a + b) + pos x * (a + b) ≈[ R (a + b) !+! *-+-left-dist-ℕ x a b ] (a + b) + (pos x * a + pos x * b) ≈[ +-assoc a b (pos x * a + pos x * b) ] a + (b + (pos x * a + pos x * b)) ≈[ R a !+! sym (+-assoc b (pos x * a) (pos x * b)) ] a + ((b + pos x * a) + pos x * b) ≈[ R a !+! (+-comm b (pos x * a) !+! R (pos x * b)) ] a + ((pos x * a + b) + pos x * b) ≈[ R a !+! +-assoc (pos x * a) b (pos x * b) ] a + (pos x * a + (b + pos x * b)) ≈[ sym (+-assoc a (pos x * a) (b + pos x * b)) ] (a + pos x * a) + (b + pos x * b) ≈[ sym (*-suc-dist x a) !+! sym (*-suc-dist x b) ] pos (suc x) * a + pos (suc x) * b qed *-+-left-dist : ∀ x a b → x * (a + b) ≈ x * a + x * b *-+-left-dist (pos x) a b = *-+-left-dist-ℕ x a b *-+-left-dist (negsuc x) a b = begin negsuc x * (a + b) ≈[ sym (neg-invol (negsuc x)) !*! R (a + b) ] -1 * (pos (suc (x + zero))) * (a + b) ≈[ cong neg (cong pos (ℕP.+-right-id (suc x))) !*! R (a + b) ] -1 * (pos (suc x)) * (a + b) ≈[ *-assoc -1 (pos (suc x)) (a + b) ] -1 * (pos (suc x) * (a + b)) ≈[ R -1 !*! *-+-left-dist-ℕ (suc x) a b ] -1 * (pos (suc x) * a + pos (suc x) * b) ≈[ -1-left-dist (pos (suc x) * a) (pos (suc x) * b) ] -1 * (pos (suc x) * a) + -1 * (pos (suc x) * b) ≈[ sym (*-assoc -1 (pos (suc x)) a) !+! sym (*-assoc -1 (pos (suc x)) b) ] -1 * pos (suc x) * a + -1 * pos (suc x) * b ≈[ R -1 !*! cong pos (cong suc (sym (ℕP.+-right-id x))) !*! R a !+! R -1 !*! cong pos (cong suc (sym (ℕP.+-right-id x))) !*! R b ] -1 * pos (suc (x + 0)) * a + -1 * pos (suc (x + 0)) * b ≈[ neg-invol (negsuc x) !*! R a !+! neg-invol (negsuc x) !*! R b ] negsuc x * a + negsuc x * b qed where -- TODO -1-left-dist : ∀ x y → neg (x + y) ≈ neg x + neg y -1-left-dist _ _ = primTrustMe *-+-right-dist : ∀ a b x → (a + b) * x ≈ a * x + b * x *-+-right-dist a b x = begin (a + b) * x ≈[ *-comm (a + b) x ] x * (a + b) ≈[ *-+-left-dist x a b ] x * a + x * b ≈[ (*-comm x a) !+! (*-comm x b) ] a * x + b * x qed +-left-inv : ∀ x → neg x + x ≈ 0 +-left-inv x = begin -1 * x + x ≈[ R (-1 * x) !+! sym (*-left-id x) ] -1 * x + 1 * x ≈[ sym (*-+-right-dist -1 1 x) ] 0 * x ≈[ *-left-zero x ] 0 qed +-right-inv : ∀ x → x + neg x ≈ 0 +-right-inv x = begin x + neg x ≈[ sym (neg-invol x) !+! R (neg x) ] neg (neg x) + neg x ≈[ +-left-inv (neg x) ] 0 qed neg-flip : ∀ x y → neg (x - y) ≈ y - x neg-flip x y = begin neg (x - y) ≈[ *-+-left-dist -1 x (neg y) ] neg x + neg (neg y) ≈[ R (neg x) !+! neg-invol y ] neg x + y ≈[ +-comm (neg x) y ] y - x qed
{ "alphanum_fraction": 0.4656145301, "avg_line_length": 35.3333333333, "ext": "agda", "hexsha": "25be0137f01712278f6fbcf94644763c7d242d0d", "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": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "esoeylemez/agda-simple", "max_forks_repo_path": "Data/Int/Core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": "esoeylemez/agda-simple", "max_issues_repo_path": "Data/Int/Core.agda", "max_line_length": 129, "max_stars_count": 1, "max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "esoeylemez/agda-simple", "max_stars_repo_path": "Data/Int/Core.agda", "max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z", "num_tokens": 5213, "size": 11342 }
{-# OPTIONS --without-K --safe #-} module Data.Bool where open import Data.Bool.Base public open import Data.Bool.Truth public
{ "alphanum_fraction": 0.7364341085, "avg_line_length": 18.4285714286, "ext": "agda", "hexsha": "265478806916cdaa407c20b6d9d8aa9ef1daa0d0", "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/Bool.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/Bool.agda", "max_line_length": 34, "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/Bool.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": 28, "size": 129 }
module WellTypedTermsNBEModel where open import Library open import Naturals open import WellTypedTerms open import RMonads.REM open import FunctorCat open import Categories.Sets open NatT open Σ -- normal forms mutual data Nf (Γ : Con) : Ty → Set where lam : ∀{σ τ} → Nf (Γ < σ) τ → Nf Γ (σ ⇒ τ) ne : Ne Γ ι → Nf Γ ι data Ne (Γ : Con) : Ty → Set where var : ∀{σ} → Var Γ σ → Ne Γ σ app : ∀{σ τ} → Ne Γ (σ ⇒ τ) → Nf Γ σ → Ne Γ τ mutual renNf : ∀{Γ Δ} → Ren Δ Γ → ∀{σ} → Nf Δ σ → Nf Γ σ renNf ρ (lam n) = lam (renNf (wk ρ) n) renNf ρ (ne n) = ne (renNe ρ n) renNe : ∀{Γ Δ} → Ren Δ Γ → ∀{σ} → Ne Δ σ → Ne Γ σ renNe ρ (var x) = var (ρ x) renNe ρ (app n n') = app (renNe ρ n) (renNf ρ n') mutual renNfid : ∀{Γ} σ (v : Nf Γ σ) → renNf id v ≅ v renNfid ι (ne x) = cong ne (renNeid ι x) renNfid (σ ⇒ τ) (lam v) = cong lam $ proof renNf (wk id) v ≅⟨ cong (λ (ρ : Ren _ _) → renNf ρ v) (iext λ _ → ext wkid) ⟩ renNf id v ≅⟨ renNfid τ v ⟩ v ∎ renNeid : ∀{Γ} σ (v : Ne Γ σ) → renNe id v ≅ v renNeid σ (var x) = refl renNeid τ (app {σ} v x) = cong₂ app (renNeid (σ ⇒ τ) v) (renNfid σ x) mutual renNecomp : ∀{Δ Γ B}(ρ : Ren Δ Γ)(ρ' : Ren Γ B) σ (v : Ne Δ σ) → renNe (ρ' ∘ ρ) v ≅ renNe ρ' (renNe ρ v) renNecomp ρ ρ' σ (var x) = refl renNecomp ρ ρ' τ (app {σ} v x) = cong₂ Ne.app (renNecomp ρ ρ' (σ ⇒ τ) v) (renNfcomp ρ ρ' σ x) renNfcomp : ∀{Δ Γ B}(ρ : Ren Δ Γ)(ρ' : Ren Γ B) σ (v : Nf Δ σ) → renNf (ρ' ∘ ρ) v ≅ renNf ρ' (renNf ρ v) renNfcomp ρ ρ' (σ ⇒ τ) (lam v) = cong Nf.lam $ proof renNf (wk (ρ' ∘ ρ)) v ≅⟨ cong (λ (ρ : Ren _ _) → renNf ρ v) (iext λ _ → ext (wkcomp ρ' ρ)) ⟩ renNf (wk ρ' ∘ wk ρ) v ≅⟨ renNfcomp (wk ρ) (wk ρ') τ v ⟩ renNf (wk ρ') (renNf (wk ρ) v) ∎ renNfcomp ρ ρ' ι (ne x) = cong ne (renNecomp ρ ρ' ι x) mutual Val : Con → Ty → Set Val Γ ι = Ne Γ ι Val Γ (σ ⇒ τ) = ∀{B} → Ren Γ B → Val B σ → Val B τ -- (λ f → ∀{B B'}(ρ : Ren Γ B)(ρ' : Ren B B')(a : Val B σ) → renV ρ' (f ρ a) ≅ f (ρ' ∘ ρ) (renV ρ' a)) renV : ∀{Γ Δ} → Ren Δ Γ → ∀{σ} → Val Δ σ → Val Γ σ renV ρ {ι} n = renNe ρ n renV {Γ}{Δ} ρ {σ ⇒ τ} f = λ ρ' → f (ρ' ∘ ρ) {- Ren Γ B → Val B σ → Val B τ | | \/ \/ Ren Γ B' → Val B' σ → Val B' τ -} -- interpretation of contexts Env : Con → Con → Set Env Γ Δ = ∀{σ} → Var Γ σ → Val Δ σ _<<_ : ∀{Γ Δ σ} → Env Γ Δ → Val Δ σ → Env (Γ < σ) Δ (γ << v) vz = v (γ << v) (vs x) = γ x eval : ∀{Γ Δ σ} → Env Δ Γ → Tm Δ σ → Val Γ σ eval γ (var i) = γ i eval γ (lam t) = λ ρ v → eval ((renV ρ ∘ γ) << v) t eval γ (app t u) = eval γ t id (eval γ u) lem : ∀{B Γ Δ σ}(ρ : Ren Γ B)(γ : Env Δ Γ)(t : Tm Δ σ) → renV ρ (eval γ t) ≅ eval (renV ρ ∘ γ) t lem = {!!} renVid : ∀{Γ} σ (v : Val Γ σ) → renV id v ≅ v renVid ι v = renNeid ι v renVid (σ ⇒ τ) v = refl renVcomp : ∀{Δ Γ B}(ρ : Ren Δ Γ)(ρ' : Ren Γ B) σ (v : Val Δ σ) → renV (ρ' ∘ ρ) v ≅ renV ρ' (renV ρ v) renVcomp ρ ρ' ι v = renNecomp ρ ρ' ι v renVcomp ρ ρ' (σ ⇒ τ) v = refl renV<< : ∀{B' B Γ}(α : Ren B B')(β : Env Γ B){σ}(v : Val B σ) → ∀{ρ}(y : Var (Γ < σ) ρ) → ((renV α ∘ β) << renV α v) y ≅ (renV α ∘ (β << v)) y renV<< α β v vz = refl renV<< α β v (vs y) = refl substeval : ∀{σ τ}(p : σ ≅ τ){Γ B : Con}{γ : Env Γ B}(t : Tm Γ σ) → (subst (Val B) p ∘ eval γ) t ≅ (eval γ ∘ subst (Tm Γ) p) t substeval refl t = refl wk<< : ∀{B Γ Δ}(α : Ren Γ Δ)(β : Env Δ B){σ}(v : Val B σ) → ∀{ρ}(y : Var (Γ < σ) ρ) → ((β ∘ α) << v) y ≅ (β << v) (wk α y) wk<< α β v vz = refl wk<< α β v (vs y) = refl <<eq : ∀{Γ Δ σ}{β β' : Env Γ Δ} → (λ{σ} → β {σ}) ≅ (λ{σ} → β' {σ}) → (v : Val Δ σ) → (λ {σ} → (β << v) {σ}) ≅ (λ {σ} → (β' << v) {σ}) <<eq refl v = refl reneval : ∀{B Γ Δ σ}(α : Ren Γ Δ)(β : Env Δ B)(t : Tm Γ σ) → eval (β ∘ α) t ≅ (eval β ∘ ren α) t reneval α β (var x) = refl reneval α β (app t u) = cong₂ (λ f x → f id x) (reneval α β t) (reneval α β u) reneval {B} α β (lam t) = iext λ B' → ext λ (ρ : Ren B B') → ext λ v → proof eval ((renV ρ ∘ β ∘ α) << v) t ≅⟨ cong (λ (γ : Env _ B') → eval γ t) (iext λ _ → ext (wk<< α (renV ρ ∘ β) v)) ⟩ eval (((renV ρ ∘ β) << v) ∘ wk α) t ≅⟨ reneval (wk α) ((renV ρ ∘ β) << v) t ⟩ eval ((renV ρ ∘ β) << v) (ren (wk α) t) ∎ lifteval : ∀{B Γ Δ σ τ}(α : Sub Γ Δ)(β : Env Δ B) (v : Val B σ)(y : Var (Γ < σ) τ) → ((eval β ∘ α) << v) y ≅ (eval (β << v) ∘ lift α) y lifteval α β v vz = refl lifteval α β v (vs x) = reneval vs (β << v) (α x) subeval : ∀{B Γ Δ σ}(α : Sub Γ Δ)(β : Env Δ B)(t : Tm Γ σ) → eval (eval β ∘ α) t ≅ (eval β ∘ sub α) t subeval α β (var x) = refl subeval α β (app t u) = cong₂ (λ f x → f id x) (subeval α β t) (subeval α β u) subeval {B} α β (lam t) = iext λ B' → ext λ (ρ : Ren B B') → ext λ v → proof eval ((renV ρ ∘ eval β ∘ α) << v) t ≅⟨ cong (λ (γ : Env _ B') → eval (γ << v) t) (iext λ _ → ext λ x → lem ρ β (α x)) ⟩ eval ((eval (renV ρ ∘ β) ∘ α) << v) t ≅⟨ cong (λ (γ : Env _ B') → eval γ t) (iext λ _ → ext λ x → lifteval α (renV ρ ∘ β) v x) ⟩ eval (eval ((renV ρ ∘ β) << v) ∘ lift α) t ≅⟨ subeval (lift α) ((renV ρ ∘ β) << v) t ⟩ eval ((λ {σ} x → renV ρ (β x)) << v) (sub (lift α) t) ∎ modelRAlg : Con → RAlg TmRMonad modelRAlg Γ = record { acar = Val Γ; astr = λ γ → eval γ; alaw1 = refl; alaw2 = λ {B} {Δ} {α} {γ} → iext (λ σ → ext (subeval α γ))}
{ "alphanum_fraction": 0.4536707056, "avg_line_length": 29.3821989529, "ext": "agda", "hexsha": "d71155f073db8415132da83793ffc8ae024e714d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_path": "WellTypedTermsNBEModel.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_path": "WellTypedTermsNBEModel.agda", "max_line_length": 107, "max_stars_count": 21, "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_path": "WellTypedTermsNBEModel.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "num_tokens": 2747, "size": 5612 }
------------------------------------------------------------------------ -- Regular expressions ------------------------------------------------------------------------ open import Setoids module RegExps (S : Setoid) where infix 8 _⋆ infixl 7 _⊙_ infixl 6 _∣_ infix 1 _∈‿⟦_⟧ open import Prelude private open module S' = Setoid S ------------------------------------------------------------------------ -- Regular expressions data RegExp : Set where ∅ : RegExp -- Matches nothing. ε : RegExp -- Matches the empty string. • : RegExp -- Matches any single character. sym : carrier -> RegExp -- Matches the given character. _⋆ : RegExp -> RegExp -- Kleene star. _∣_ : RegExp -> RegExp -> RegExp -- Choice. _⊙_ : RegExp -> RegExp -> RegExp -- Sequencing. ------------------------------------------------------------------------ -- Size of a regular expression size : RegExp -> ℕ size (re ⋆) = 1 + size re size (re₁ ∣ re₂) = 1 + size re₁ + size re₂ size (re₁ ⊙ re₂) = 1 + size re₁ + size re₂ size _ = 1 ------------------------------------------------------------------------ -- Semantics of regular expressions -- The type xs ∈‿⟦ re ⟧ is inhabited iff xs matches the regular -- expression re. data _∈‿⟦_⟧ : [ carrier ] -> RegExp -> Set where matches-ε : [] ∈‿⟦ ε ⟧ matches-• : forall {x} -> x ∷ [] ∈‿⟦ • ⟧ matches-sym : forall {x y} -> x ≈ y -> x ∷ [] ∈‿⟦ sym y ⟧ matches-⋆ : forall {xs re} -> xs ∈‿⟦ ε ∣ re ⊙ re ⋆ ⟧ -> xs ∈‿⟦ re ⋆ ⟧ matches-∣ˡ : forall {xs re₁ re₂} -> xs ∈‿⟦ re₁ ⟧ -> xs ∈‿⟦ re₁ ∣ re₂ ⟧ matches-∣ʳ : forall {xs re₁ re₂} -> xs ∈‿⟦ re₂ ⟧ -> xs ∈‿⟦ re₁ ∣ re₂ ⟧ matches-⊙ : forall {xs₁ xs₂ re₁ re₂} -> xs₁ ∈‿⟦ re₁ ⟧ -> xs₂ ∈‿⟦ re₂ ⟧ -> xs₁ ++ xs₂ ∈‿⟦ re₁ ⊙ re₂ ⟧ ------------------------------------------------------------------------ -- Is the regular expression bypassable? bypassable : (re : RegExp) -> Maybe ([] ∈‿⟦ re ⟧) bypassable ∅ = nothing bypassable ε = just matches-ε bypassable • = nothing bypassable (sym _) = nothing bypassable (re ⋆) = just (matches-⋆ (matches-∣ˡ matches-ε)) bypassable (re₁ ∣ re₂) with bypassable re₁ | bypassable re₂ bypassable (re₁ ∣ re₂) | just m | _ = just (matches-∣ˡ m) bypassable (re₁ ∣ re₂) | nothing | just m = just (matches-∣ʳ m) bypassable (re₁ ∣ re₂) | nothing | nothing = nothing bypassable (re₁ ⊙ re₂) with bypassable re₁ | bypassable re₂ bypassable (re₁ ⊙ re₂) | just m₁ | just m₂ = just (matches-⊙ m₁ m₂) bypassable (re₁ ⊙ re₂) | _ | _ = nothing
{ "alphanum_fraction": 0.4553207267, "avg_line_length": 36.4459459459, "ext": "agda", "hexsha": "b172a677c92a1c1d046935e926cf5c676c32a64f", "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/AIM6/RegExp/talk/RegExps.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/AIM6/RegExp/talk/RegExps.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": "examples/AIM6/RegExp/talk/RegExps.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": 867, "size": 2697 }
------------------------------------------------------------------------ -- The Agda standard library -- -- List membership and some related definitions ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.List.Membership.Setoid {c ℓ} (S : Setoid c ℓ) where open import Function using (_∘_; id; flip) open import Data.Fin using (Fin; zero; suc) open import Data.List.Base as List using (List; []; _∷_; length; lookup) open import Data.List.Relation.Unary.Any using (Any; index; map; here; there) open import Data.Product as Prod using (∃; _×_; _,_) open import Relation.Unary using (Pred) open import Relation.Nullary using (¬_) open Setoid S renaming (Carrier to A) open Data.List.Relation.Unary.Any using (_∷=_; _─_) public ------------------------------------------------------------------------ -- Definitions infix 4 _∈_ _∉_ _∈_ : A → List A → Set _ x ∈ xs = Any (x ≈_) xs _∉_ : A → List A → Set _ x ∉ xs = ¬ x ∈ xs ------------------------------------------------------------------------ -- Operations mapWith∈ : ∀ {b} {B : Set b} (xs : List A) → (∀ {x} → x ∈ xs → B) → List B mapWith∈ [] f = [] mapWith∈ (x ∷ xs) f = f (here refl) ∷ mapWith∈ xs (f ∘ there) ------------------------------------------------------------------------ -- Finding and losing witnesses module _ {p} {P : Pred A p} where find : ∀ {xs} → Any P xs → ∃ λ x → x ∈ xs × P x find (here px) = (_ , here refl , px) find (there pxs) = Prod.map id (Prod.map there id) (find pxs) lose : P Respects _≈_ → ∀ {x xs} → x ∈ xs → P x → Any P xs lose resp x∈xs px = map (flip resp px) x∈xs ------------------------------------------------------------------------ -- DEPRECATED ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.16 map-with-∈ = mapWith∈ {-# WARNING_ON_USAGE map-with-∈ "Warning: map-with-∈ was deprecated in v0.16. Please use mapWith∈ instead." #-}
{ "alphanum_fraction": 0.4780952381, "avg_line_length": 30, "ext": "agda", "hexsha": "b61250e559f141f8ac15c6b21cee5f7289fedee3", "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/Membership/Setoid.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/Membership/Setoid.agda", "max_line_length": 72, "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/Membership/Setoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 547, "size": 2100 }
{-# OPTIONS --without-K --safe #-} module Mult3 where open import Data.Nat open import Data.Nat.Properties open import Relation.Binary.PropositionalEquality data Mult3 : ℕ → Set where 0-mult : Mult3 0 SSS-mult : ∀ n → Mult3 n → Mult3 (suc (suc (suc n))) data Mult3' : ℕ → Set where 30-mult : Mult3' 30 21-mult : Mult3' 21 sum-mult : ∀ n m → Mult3' n → Mult3' m → Mult3' (n + m) diff-mult : ∀ l n m → Mult3' n → Mult3' m → l + n ≡ m → Mult3' l silly3 : Mult3' 3 silly3 = diff-mult 3 9 12 (diff-mult 9 21 30 21-mult 30-mult refl) (diff-mult 12 9 21 (diff-mult 9 21 30 21-mult 30-mult refl) 21-mult refl) refl lemma-plus : ∀ {n m : ℕ} → Mult3 n → Mult3 m → Mult3 (n + m) lemma-plus 0-mult m = m lemma-plus {m = m₁} (SSS-mult n n₁) m = SSS-mult (n + m₁) (lemma-plus n₁ m) lemma-minus : ∀ {l n : ℕ} → Mult3 n → Mult3 (n + l) → Mult3 l lemma-minus {l} {.0} 0-mult m₁ = m₁ lemma-minus {l} {.(suc (suc (suc n)))} (SSS-mult n n₁) (SSS-mult .(n + l) m₁) = lemma-minus n₁ m₁ lemma-silly : ∀ {m n : ℕ} → Mult3 m → m ≡ n → Mult3 n lemma-silly m eq rewrite eq = m mult-imp-mult' : ∀ {n : ℕ} → Mult3 n → Mult3' n mult-imp-mult' 0-mult = diff-mult zero 30 30 30-mult 30-mult refl mult-imp-mult' (SSS-mult n M) = sum-mult 3 n silly3 (mult-imp-mult' M) mult'-imp-mult : ∀ {n : ℕ} → Mult3' n → Mult3 n mult'-imp-mult 30-mult = SSS-mult 27 (SSS-mult 24 (SSS-mult 21 (SSS-mult 18 (SSS-mult 15 (SSS-mult 12 (SSS-mult 9 (SSS-mult 6 (SSS-mult 3 (SSS-mult zero 0-mult))))))))) mult'-imp-mult 21-mult = SSS-mult 18 (SSS-mult 15 (SSS-mult 12 (SSS-mult 9 (SSS-mult 6 (SSS-mult 3 (SSS-mult zero 0-mult)))))) mult'-imp-mult (sum-mult n m M M₁) = lemma-plus (mult'-imp-mult M) (mult'-imp-mult M₁) mult'-imp-mult (diff-mult l n m M M₁ x) rewrite +-comm l n = lemma-minus {l} {n} (mult'-imp-mult M) (lemma-silly {m} {n + l} (mult'-imp-mult M₁) (sym x))
{ "alphanum_fraction": 0.5432921028, "avg_line_length": 42.04, "ext": "agda", "hexsha": "5059f9abced38d46ff8dea01f0c4a9e8d89fd4d9", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z", "max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Brethland/LEARNING-STUFF", "max_forks_repo_path": "Agda/Mult3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "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": "Brethland/LEARNING-STUFF", "max_issues_repo_path": "Agda/Mult3.agda", "max_line_length": 153, "max_stars_count": 2, "max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Brethland/LEARNING-STUFF", "max_stars_repo_path": "Agda/Mult3.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z", "max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z", "num_tokens": 763, "size": 2102 }
module plfa.part1.Negation where open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Data.Nat using (ℕ; zero; suc; _<_) open import Data.Empty using (⊥; ⊥-elim) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Product using (_×_; _,_) open import plfa.part1.Isomorphism using (_≃_; extensionality) ¬_ : Set → Set ¬ A = A → ⊥ ¬-elim : ∀ {A : Set} → ¬ A → A --- → ⊥ ¬-elim ¬x x = ¬x x infix 3 ¬_ ¬¬-intro : ∀ {A : Set} → A ----- → ¬ ¬ A ¬¬-intro x = λ{¬x → ¬x x} ¬¬¬-elim : ∀ {A : Set} → ¬ ¬ ¬ A ------- → ¬ A ¬¬¬-elim ¬¬¬x = λ x → ¬¬¬x (¬¬-intro x) contraposition : ∀ {A B : Set} → (A → B) ----------- → (¬ B → ¬ A) contraposition f ¬y x = ¬y (f x) _≢_ : ∀ {A : Set} → A → A → Set x ≢ y = ¬ (x ≡ y) _ : 1 ≢ 2 _ = λ() peano : ∀ {m : ℕ} → zero ≢ suc m peano = λ() id : ⊥ → ⊥ id x = x id′ : ⊥ → ⊥ id′ () assimilation : ∀ {A : Set} (¬x ¬x′ : ¬ A) → ¬x ≡ ¬x′ assimilation ¬x ¬x′ = extensionality (λ x → ⊥-elim (¬x x)) assimilation' : ∀ {A : Set} {¬x ¬x′ : ¬ A} → ¬x ≡ ¬x′ assimilation' {A} {¬x} {¬x′} = assimilation ¬x ¬x′ <-irreflexive : ∀ {n : ℕ} → ¬ (n < n) <-irreflexive (Data.Nat.s≤s x) = <-irreflexive x ⊎-dual-× : ∀ {A B : Set} → ¬ (A ⊎ B) ≃ (¬ A) × (¬ B) ⊎-dual-× = record { to = λ {x → (λ z → x (inj₁ z)) , λ x₁ → x (inj₂ x₁) }; from = λ { (fst , snd) (inj₁ x) → fst x ; (fst , snd) (inj₂ y) → snd y} ; from∘to = λ {¬x → assimilation'} ; to∘from = λ { (fst , snd) → refl} }
{ "alphanum_fraction": 0.4457142857, "avg_line_length": 22.1830985915, "ext": "agda", "hexsha": "11f5d783179f1fd080a93d90e86bfec476ead14c", "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": "275ecc582b3a6a1da1af387251c6b4d74d9a5203", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sym-cereal/proofs", "max_forks_repo_path": "plfa/part1/Negation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203", "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": "sym-cereal/proofs", "max_issues_repo_path": "plfa/part1/Negation.agda", "max_line_length": 72, "max_stars_count": 6, "max_stars_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UnsoundWitch/proofs", "max_stars_repo_path": "plfa/part1/Negation.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T10:58:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-03T03:29:40.000Z", "num_tokens": 682, "size": 1575 }
-- Andreas 2012-07-07 module Issue674 where record unit : Set where constructor tt module A ⦃ t : unit ⦄ (i : unit) where id : unit → unit id x = x open A {{t = _}} tt module N = A {{ tt }} tt open N open A {{tt}} tt module M = A tt open M open A tt -- the last statement caused a panic when inserting the instance meta -- because due to open it found candidates in scope that were not -- in the signature yet
{ "alphanum_fraction": 0.6650943396, "avg_line_length": 16.3076923077, "ext": "agda", "hexsha": "65a596da56c23e65e982d64c725acd5c4b82ba0d", "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/succeed/Issue674.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/Issue674.agda", "max_line_length": 69, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/succeed/Issue674.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": 130, "size": 424 }
{-# OPTIONS --cubical --safe #-} module Chord where open import Cubical.Core.Everything using (_≡_; Level; Type; Σ; _,_; fst; snd; _≃_; ~_) open import Data.Fin using (Fin; toℕ) renaming (zero to fz; suc to fs) open import Data.List using (List; map; []; _∷_; _++_; zip) open import Data.Nat using (ℕ) open import Data.Product using (_×_) open import Data.String using (String) renaming (_++_ to _++s_) open import Function using (_∘_) open import AssocList open import BitVec open import Pitch open import Util using (_+N_) data Root : Type where root : Fin s12 → Root showRoot : Root → String showRoot (root fz) = "I" showRoot (root (fs fz)) = "♭II" showRoot (root (fs (fs fz))) = "II" showRoot (root (fs (fs (fs fz)))) = "♭III" showRoot (root (fs (fs (fs (fs fz))))) = "III" showRoot (root (fs (fs (fs (fs (fs fz)))))) = "IV" showRoot (root (fs (fs (fs (fs (fs (fs fz))))))) = "♭V" showRoot (root (fs (fs (fs (fs (fs (fs (fs fz)))))))) = "V" showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))) = "♭VI" showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))) = "VI" showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))))) = "♭VII" showRoot (root (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))))) = "VII" data Quality : Type where maj : Quality min : Quality dom7 : Quality maj7 : Quality showQuality : Quality → String showQuality maj = "maj" showQuality min = "min" showQuality dom7 = "⁷" showQuality maj7 = "maj⁷" RootQuality : Type RootQuality = Root × Quality showRootQuality : RootQuality → String showRootQuality (r , q) = showRoot r ++s showQuality q Notes : Type Notes = BitVec s12 ChordList : Type ChordList = AList Notes RootQuality -- The list should not include the root. makeChord : Root → List ℕ → Notes makeChord (root n) [] = BitVec.insert n empty makeChord (root n) (x ∷ xs) = BitVec.insert (n +N x) (makeChord (root n) xs) -- The list should not include the root. qualityNotes : Quality → List ℕ qualityNotes maj = 4 ∷ 7 ∷ [] qualityNotes min = 3 ∷ 7 ∷ [] qualityNotes dom7 = 4 ∷ 7 ∷ 10 ∷ [] qualityNotes maj7 = 4 ∷ 7 ∷ 11 ∷ [] makeChordQuality : RootQuality → Notes makeChordQuality (r , q) = makeChord r (qualityNotes q) --------- --addMajor aa = show (makeChordQuality (root fz , maj)) {- allPairs : {A : Type} → List A → List (A × A) allPairs [] = [] allPairs (x ∷ xs) = map (x ,_) xs ++ allPairs xs aa = allPairs (c 5 ∷ e 5 ∷ g 5 ∷ []) bb = zip aa (map (toℕ ∘ unIntervalClass ∘ pitchPairToIntervalClass) aa) -}
{ "alphanum_fraction": 0.5455486542, "avg_line_length": 31.8461538462, "ext": "agda", "hexsha": "358ae8a0dca140f6549f0959916a4d674ad9cd10", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z", "max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "halfaya/MusicTools", "max_forks_repo_path": "agda/Chord.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z", "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "halfaya/MusicTools", "max_issues_repo_path": "agda/Chord.agda", "max_line_length": 87, "max_stars_count": 28, "max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "halfaya/MusicTools", "max_stars_repo_path": "agda/Chord.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z", "num_tokens": 904, "size": 2898 }
module Base.Change.Equivalence.Realizers where open import Relation.Binary.PropositionalEquality open import Base.Change.Algebra open import Level open import Data.Unit open import Data.Product open import Function open import Postulate.Extensionality open import Base.Change.Equivalence -- Here we give lemmas about realizers for function changes. Using these lemmas, -- you can simply write a "realizer" for a derivative for f (that is, the -- computational part of the derivative, without any embedded proof), show -- separately that it's change-equivalent to the nil change for f and get a -- proper function change; this code proves the needed validity lemmas. -- -- Given a type of codes for types, such lemmas should be provable by induction -- on those types; something similar is done in the proof of erasure, though -- details are quite different. -- -- For now, we do something close to unrolling the induction manually for -- functions of arity 1, 2 and 3 since those are actually used in the codebase. -- I didn't actually write the induction though, and I'm not sure how to do it. -- -- So there are two attempts which might give ideas; one is -- equiv-raw-change-to-change-binary and equiv-raw-change-to-change-ternary, the -- other is equiv-raw-change-to-change-binary′ and -- equiv-raw-change-to-change-ternary′. module _ {a} {A : Set a} {{CA : ChangeAlgebra A}} {b} {B : Set b} {{CB : ChangeAlgebra B}} (f : A → B) where private Set′ = Set (a ⊔ b) equiv₁ : ∀ (df′ : Δ f) (df-realizer : RawChange f) → Set′ equiv₁ df′ df-realizer = apply df′ ≡ df-realizer equiv-raw-change-to-change-ResType : ∀ (df-realizer : RawChange f) → Set′ equiv-raw-change-to-change-ResType df-realizer = Σ[ df′ ∈ Δ f ] equiv₁ df′ df-realizer equiv-hp : ∀ (df : Δ f) (df-realizer : RawChange f) → Set′ equiv-hp df df-realizer = (∀ a da → apply df a da ≙₍ f a ₎ df-realizer a da) -- This is sort of the "base case" of the proof mentioned above. equiv-raw-change-to-change : ∀ (df : Δ f) (df-realizer : RawChange f) → equiv-hp df df-realizer → equiv-raw-change-to-change-ResType df-realizer equiv-raw-change-to-change df df-realizer ≙df = record { apply = df-realizer ; correct = df-realizer-correct} , refl where df-realizer-correct : ∀ a da → f (a ⊞ da) ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) ≡ f a ⊞ df-realizer a da df-realizer-correct a da rewrite sym (proof (≙df a da)) | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da)))) = correct df a da equiv-raw-deriv-to-deriv : ∀ (df-realizer : RawChange f) → equiv-hp (nil f) df-realizer → IsDerivative f df-realizer equiv-raw-deriv-to-deriv df-realizer ≙df with equiv-raw-change-to-change (nil f) df-realizer ≙df equiv-raw-deriv-to-deriv .(FunctionChanges.apply nil-f) ≙df | nil-f , refl = equiv-nil-is-derivative nil-f (delta-ext ≙df) module _ {a} {A : Set a} {{CA : ChangeAlgebra A}} {b} {B : Set b} {{CB : ChangeAlgebra B}} {c} {C : Set c} {{CC : ChangeAlgebra C}} (f : A → B → C) where private Set′ = Set (a ⊔ b ⊔ c) -- This is, sort of, an instance of the inductive step in the proof mentioned above. RawChangeBinary : Set′ RawChangeBinary = ∀ a (da : Δ a) → RawChange (f a) equiv-hp-binary : ∀ (df : Δ f) (df-realizer : RawChangeBinary) → Set′ equiv-hp-binary df df-realizer = ∀ a da → equiv-hp (f a) (apply df a da) (df-realizer a da) equiv₂ : ∀ (df′ : Δ f) (df-realizer : RawChangeBinary) → Set′ equiv₂ df′ df-realizer = ∀ a da → equiv₁ (f a) (apply df′ a da) (df-realizer a da) equiv-raw-change-to-change-binary-ResType : ∀ (df-realizer : RawChangeBinary) → Set′ equiv-raw-change-to-change-binary-ResType df-realizer = Σ[ df′ ∈ Δ f ] equiv₂ df′ df-realizer equiv-raw-change-to-change-binary equiv-raw-change-to-change-binary′ : ∀ (df : Δ f) (df-realizer : RawChangeBinary) → equiv-hp-binary df df-realizer → equiv-raw-change-to-change-binary-ResType df-realizer equiv-raw-change-to-change-binary df df-realizer ≙df = proj₁ (equiv-raw-change-to-change f df df₁′ ≙df₁′) , λ a da → refl where module _ (a : A) (da : Δ a) where f₁ = f a df₁ : Δ f₁ df₁ = apply df a da df-realizer₁ = df-realizer a da ≙df₁ = ≙df a da df-realizer₁-correct : ∀ b db → f₁ (b ⊞ db) ⊞ df-realizer₁ (b ⊞ db) (nil (b ⊞ db)) ≡ f₁ b ⊞ df-realizer₁ b db df-realizer₁-correct b db rewrite sym (proof (≙df₁ b db)) | sym (proof (≙df₁ (b ⊞ db) (nil (b ⊞ db)))) = correct df₁ b db df₁′ : Δ f₁ df₁′ = record { apply = df-realizer₁ ; correct = df-realizer₁-correct } ≙df₁′ : df₁ ≙₍ f₁ ₎ df₁′ ≙df₁′ = delta-ext ≙df₁ equiv-raw-change-to-change-binary′ df df-realizer ≙df = record { apply = df₁′ ; correct = λ a da → ext (df-realizer-correct a da) } , λ a da → refl where module _ (a : A) (da : Δ a) where f₁ = f a df₁ : Δ f₁ df₁ = apply df a da df-realizer₁ = df-realizer a da ≙df₁ = ≙df a da df₁′ = proj₁ (equiv-raw-change-to-change f₁ df₁ df-realizer₁ ≙df₁) df-realizer-correct : ∀ b → f (a ⊞ da) b ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) b (nil b) ≡ f a b ⊞ df-realizer a da b (nil b) df-realizer-correct b rewrite sym (proof (≙df a da b (nil b))) | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da)) b (nil b))) = cong (λ □ → □ b) (correct df a da) equiv-raw-deriv-to-deriv-binary : ∀ (df-realizer : RawChangeBinary) → (≙df : equiv-hp-binary (nil f) df-realizer) → IsDerivative f (apply (proj₁ (equiv-raw-change-to-change-binary (nil f) df-realizer ≙df))) equiv-raw-deriv-to-deriv-binary df-realizer ≙df a da with equiv-raw-change-to-change-binary (nil f) df-realizer ≙df ... | nil-f , nil-f≡df with sym (nil-f≡df a da) ... | df-a-da≡nil-f-a-da rewrite df-a-da≡nil-f-a-da = equiv-nil-is-derivative nil-f (delta-ext {df = nil f} {dg = nil-f} (λ a da → doe (ext (lemma a da)))) a da where lemma : ∀ a da b → (f a ⊞ apply (nil f) a da) b ≡ (f a ⊞ apply nil-f a da) b lemma a da b rewrite nil-f≡df a da = proof (≙df a da b (nil b)) module _ {a} {A : Set a} {{CA : ChangeAlgebra A}} {b} {B : Set b} {{CB : ChangeAlgebra B}} {c} {C : Set c} {{CC : ChangeAlgebra C}} {d} {D : Set d} {{CD : ChangeAlgebra D}} (f : A → B → C → D) where private Set′ = Set (a ⊔ b ⊔ c ⊔ d) -- This is an adapted copy of the above "inductive step". RawChangeTernary : Set′ RawChangeTernary = ∀ a (da : Δ a) → RawChangeBinary (f a) equiv-hp-ternary : ∀ (df : Δ f) (df-realizer : RawChangeTernary) → Set′ equiv-hp-ternary df df-realizer = ∀ a da → equiv-hp-binary (f a) (apply df a da) (df-realizer a da) equiv₃ : ∀ (df′ : Δ f) (df-realizer : RawChangeTernary) → Set′ equiv₃ df′ df-realizer = ∀ a da → equiv₂ (f a) (apply df′ a da) (df-realizer a da) equiv-raw-change-to-change-ternary-ResType : ∀ (df-realizer : RawChangeTernary) → Set′ equiv-raw-change-to-change-ternary-ResType df-realizer = Σ[ df′ ∈ Δ f ] equiv₃ df′ df-realizer equiv-raw-change-to-change-ternary equiv-raw-change-to-change-ternary′ : ∀ (df : Δ f) (df-realizer : RawChangeTernary) → equiv-hp-ternary df df-realizer → equiv-raw-change-to-change-ternary-ResType df-realizer equiv-raw-change-to-change-ternary df df-realizer ≙df = proj₁ (equiv-raw-change-to-change-binary f df df₁′ ≙df₁′) , λ a da b db → refl where module _ (a : A) (da : Δ a) (b : B) (db : Δ b) where f₁ = f a b df₁ : Δ f₁ df₁ = apply (apply df a da) b db df-realizer₁ = df-realizer a da b db ≙df₁ = ≙df a da b db df-realizer₁-correct : ∀ c dc → f₁ (c ⊞ dc) ⊞ df-realizer₁ (c ⊞ dc) (nil (c ⊞ dc)) ≡ f₁ c ⊞ df-realizer₁ c dc df-realizer₁-correct c dc rewrite sym (proof (≙df₁ c dc)) | sym (proof (≙df₁ (c ⊞ dc) (nil (c ⊞ dc)))) = correct df₁ c dc df₁′ : Δ f₁ df₁′ = record { apply = df-realizer₁ ; correct = df-realizer₁-correct } ≙df₁′ : df₁ ≙₍ f₁ ₎ df₁′ ≙df₁′ = delta-ext ≙df₁ equiv-raw-change-to-change-ternary′ df df-realizer ≙df = record { apply = df₁′ ; correct = λ a da → ext (λ b → ext (df-realizer-correct a da b)) } , λ a da b db → refl where module _ (a : A) (da : Δ a) where f₁ = f a df₁ : Δ f₁ df₁ = apply df a da df-realizer₁ = df-realizer a da ≙df₁ = ≙df a da df₁′ = proj₁ (equiv-raw-change-to-change-binary f₁ df₁ df-realizer₁ ≙df₁) df-realizer-correct : ∀ b c → f (a ⊞ da) b c ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) b (nil b) c (nil c) ≡ f a b c ⊞ df-realizer a da b (nil b) c (nil c) df-realizer-correct b c rewrite sym (proof (≙df a da b (nil b) c (nil c))) | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da)) b (nil b) c (nil c))) = cong (λ □ → □ b c) (correct df a da)
{ "alphanum_fraction": 0.6061315496, "avg_line_length": 42.7142857143, "ext": "agda", "hexsha": "ed604b5fb595b9d3c5a71b3a96b9492e5f765315", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Base/Change/Equivalence/Realizers.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Base/Change/Equivalence/Realizers.agda", "max_line_length": 169, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Base/Change/Equivalence/Realizers.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 3099, "size": 8970 }
open import Agda.Builtin.Nat open import Agda.Builtin.Int open import Agda.Builtin.Equality fromNeg : Nat → Int fromNeg zero = pos 0 fromNeg (suc x) = negsuc x {-# BUILTIN FROMNEG fromNeg #-} -- A negative number neg : Int neg = -20 -- Matching against negative numbers lit : Int → Nat lit -20 = 0 -- Error thrown here lit _ = 1 -- Testing reduction rules test0 : lit -20 ≡ 0 test0 = refl test1 : lit -2 ≡ 1 test1 = refl -- Error WAS: Internal error in expandLitPattern -- Error NOW: Type mismatch when checking that the pattern -20 has type Int -- Ideally, this would succeed.
{ "alphanum_fraction": 0.6974789916, "avg_line_length": 17.5, "ext": "agda", "hexsha": "ee17833a26bc5af4bc5f9f492b62a851540025ee", "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/Issue2365.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/Issue2365.agda", "max_line_length": 75, "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/Issue2365.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": 180, "size": 595 }
module Tactic.Reflection.Equality where open import Prelude open import Builtin.Reflection open import Builtin.Float instance EqVisibility : Eq Visibility _==_ {{EqVisibility}} visible visible = yes refl _==_ {{EqVisibility}} visible hidden = no (λ ()) _==_ {{EqVisibility}} visible instance′ = no (λ ()) _==_ {{EqVisibility}} hidden visible = no (λ ()) _==_ {{EqVisibility}} hidden hidden = yes refl _==_ {{EqVisibility}} hidden instance′ = no (λ ()) _==_ {{EqVisibility}} instance′ visible = no (λ ()) _==_ {{EqVisibility}} instance′ hidden = no (λ ()) _==_ {{EqVisibility}} instance′ instance′ = yes refl EqRelevance : Eq Relevance _==_ {{EqRelevance}} relevant relevant = yes refl _==_ {{EqRelevance}} relevant irrelevant = no (λ ()) _==_ {{EqRelevance}} irrelevant relevant = no (λ ()) _==_ {{EqRelevance}} irrelevant irrelevant = yes refl EqArgInfo : Eq ArgInfo _==_ {{EqArgInfo}} (arg-info v r) (arg-info v₁ r₁) = decEq₂ arg-info-inj₁ arg-info-inj₂ (v == v₁) (r == r₁) EqArg : ∀ {A} {{EqA : Eq A}} → Eq (Arg A) _==_ {{EqArg}} (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (x == x₁) EqLiteral : Eq Literal _==_ {{EqLiteral}} = eqLit where eqLit : (x y : Literal) → Dec (x ≡ y) eqLit (nat x) (nat y) = decEq₁ nat-inj (x == y) eqLit (word64 x) (word64 y) = decEq₁ word64-inj (x == y) eqLit (float x) (float y) = decEq₁ float-inj (x == y) eqLit (char x) (char y) = decEq₁ char-inj (x == y) eqLit (string x) (string y) = decEq₁ string-inj (x == y) eqLit (name x) (name y) = decEq₁ name-inj (x == y) eqLit (meta x) (meta y) = decEq₁ meta-inj (x == y) eqLit (nat _) (float _) = no λ() eqLit (nat _) (word64 _) = no λ() eqLit (nat _) (char _) = no λ() eqLit (nat _) (string _) = no λ() eqLit (nat _) (name _) = no λ() eqLit (nat _) (meta _) = no λ() eqLit (word64 _) (nat _) = no λ() eqLit (word64 _) (float _) = no λ() eqLit (word64 _) (char _) = no λ() eqLit (word64 _) (string _) = no λ() eqLit (word64 _) (name _) = no λ() eqLit (word64 _) (meta _) = no λ() eqLit (float _) (nat _) = no λ() eqLit (float _) (word64 _) = no λ() eqLit (float _) (char _) = no λ() eqLit (float _) (string _) = no λ() eqLit (float _) (name _) = no λ() eqLit (float _) (meta _) = no λ() eqLit (char _) (nat _) = no λ() eqLit (char _) (word64 _) = no λ() eqLit (char _) (float _) = no λ() eqLit (char _) (string _) = no λ() eqLit (char _) (name _) = no λ() eqLit (char _) (meta _) = no λ() eqLit (string _) (nat _) = no λ() eqLit (string _) (word64 _) = no λ() eqLit (string _) (float _) = no λ() eqLit (string _) (char _) = no λ() eqLit (string _) (name _) = no λ() eqLit (string _) (meta _) = no λ() eqLit (name _) (nat _) = no λ() eqLit (name _) (word64 _) = no λ() eqLit (name _) (float _) = no λ() eqLit (name _) (char _) = no λ() eqLit (name _) (string _) = no λ() eqLit (name _) (meta _) = no λ() eqLit (meta _) (nat _) = no λ() eqLit (meta _) (word64 _) = no λ() eqLit (meta _) (float _) = no λ() eqLit (meta _) (char _) = no λ() eqLit (meta _) (string _) = no λ() eqLit (meta _) (name _) = no λ() private eqSort : (x y : Sort) → Dec (x ≡ y) eqTerm : (x y : Term) → Dec (x ≡ y) eqPat : (x y : Pattern) → Dec (x ≡ y) eqClause : (x y : Clause) → Dec (x ≡ y) eqArgTerm : (x y : Arg Term) → Dec (x ≡ y) eqArgTerm (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqTerm x x₁) eqArgPat : (x y : Arg Pattern) → Dec (x ≡ y) eqArgPat (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqPat x x₁) eqAbsTerm : (x y : Abs Term) → Dec (x ≡ y) eqAbsTerm (abs s x) (abs s₁ x₁) = decEq₂ abs-inj₁ abs-inj₂ (s == s₁) (eqTerm x x₁) eqPats : (x y : List (Arg Pattern)) → Dec (x ≡ y) eqPats [] [] = yes refl eqPats [] (x ∷ xs) = no λ () eqPats (x ∷ xs) [] = no λ () eqPats (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgPat x y) (eqPats xs ys) eqArgs : (x y : List (Arg Term)) → Dec (x ≡ y) eqArgs [] [] = yes refl eqArgs [] (x ∷ xs) = no λ () eqArgs (x ∷ xs) [] = no λ () eqArgs (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgTerm x y) (eqArgs xs ys) eqClauses : (x y : List Clause) → Dec (x ≡ y) eqClauses [] [] = yes refl eqClauses [] (x ∷ xs) = no λ () eqClauses (x ∷ xs) [] = no λ () eqClauses (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqClause x y) (eqClauses xs ys) eqTerm (var x args) (var x₁ args₁) = decEq₂ var-inj₁ var-inj₂ (x == x₁) (eqArgs args args₁) eqTerm (con c args) (con c₁ args₁) = decEq₂ con-inj₁ con-inj₂ (c == c₁) (eqArgs args args₁) eqTerm (def f args) (def f₁ args₁) = decEq₂ def-inj₁ def-inj₂ (f == f₁) (eqArgs args args₁) eqTerm (meta x args) (meta x₁ args₁) = decEq₂ meta-inj₁ meta-inj₂ (x == x₁) (eqArgs args args₁) eqTerm (lam v x) (lam v₁ y) = decEq₂ lam-inj₁ lam-inj₂ (v == v₁) (eqAbsTerm x y) eqTerm (pi t₁ t₂) (pi t₃ t₄) = decEq₂ pi-inj₁ pi-inj₂ (eqArgTerm t₁ t₃) (eqAbsTerm t₂ t₄) eqTerm (agda-sort x) (agda-sort x₁) = decEq₁ sort-inj (eqSort x x₁) eqTerm (lit l) (lit l₁) = decEq₁ lit-inj (l == l₁) eqTerm (pat-lam c args) (pat-lam c₁ args₁) = decEq₂ pat-lam-inj₁ pat-lam-inj₂ (eqClauses c c₁) (eqArgs args args₁) eqTerm unknown unknown = yes refl eqTerm (var x args) (con c args₁) = no λ () eqTerm (var x args) (def f args₁) = no λ () eqTerm (var x args) (lam v y) = no λ () eqTerm (var x args) (pi t₁ t₂) = no λ () eqTerm (var x args) (agda-sort x₁) = no λ () eqTerm (var x args) (lit x₁) = no λ () eqTerm (var x args) unknown = no λ () eqTerm (con c args) (var x args₁) = no λ () eqTerm (con c args) (def f args₁) = no λ () eqTerm (con c args) (lam v y) = no λ () eqTerm (con c args) (pi t₁ t₂) = no λ () eqTerm (con c args) (agda-sort x) = no λ () eqTerm (con c args) (lit x) = no λ () eqTerm (con c args) unknown = no λ () eqTerm (def f args) (var x args₁) = no λ () eqTerm (def f args) (con c args₁) = no λ () eqTerm (def f args) (lam v y) = no λ () eqTerm (def f args) (pi t₁ t₂) = no λ () eqTerm (def f args) (agda-sort x) = no λ () eqTerm (def f args) (lit x) = no λ () eqTerm (def f args) unknown = no λ () eqTerm (lam v x) (var x₁ args) = no λ () eqTerm (lam v x) (con c args) = no λ () eqTerm (lam v x) (def f args) = no λ () eqTerm (lam v x) (pi t₁ t₂) = no λ () eqTerm (lam v x) (agda-sort x₁) = no λ () eqTerm (lam v x) (lit x₁) = no λ () eqTerm (lam v x) unknown = no λ () eqTerm (pi t₁ t₂) (var x args) = no λ () eqTerm (pi t₁ t₂) (con c args) = no λ () eqTerm (pi t₁ t₂) (def f args) = no λ () eqTerm (pi t₁ t₂) (lam v y) = no λ () eqTerm (pi t₁ t₂) (agda-sort x) = no λ () eqTerm (pi t₁ t₂) (lit x) = no λ () eqTerm (pi t₁ t₂) unknown = no λ () eqTerm (agda-sort x) (var x₁ args) = no λ () eqTerm (agda-sort x) (con c args) = no λ () eqTerm (agda-sort x) (def f args) = no λ () eqTerm (agda-sort x) (lam v y) = no λ () eqTerm (agda-sort x) (pi t₁ t₂) = no λ () eqTerm (agda-sort x) (lit x₁) = no λ () eqTerm (agda-sort x) unknown = no λ () eqTerm (lit x) (var x₁ args) = no λ () eqTerm (lit x) (con c args) = no λ () eqTerm (lit x) (def f args) = no λ () eqTerm (lit x) (lam v y) = no λ () eqTerm (lit x) (pi t₁ t₂) = no λ () eqTerm (lit x) (agda-sort x₁) = no λ () eqTerm (lit x) unknown = no λ () eqTerm unknown (var x args) = no λ () eqTerm unknown (con c args) = no λ () eqTerm unknown (def f args) = no λ () eqTerm unknown (lam v y) = no λ () eqTerm unknown (pi t₁ t₂) = no λ () eqTerm unknown (agda-sort x) = no λ () eqTerm unknown (lit x) = no λ () eqTerm (var _ _) (meta _ _) = no λ () eqTerm (con _ _) (meta _ _) = no λ () eqTerm (def _ _) (meta _ _) = no λ () eqTerm (lam _ _) (meta _ _) = no λ () eqTerm (pi _ _) (meta _ _) = no λ () eqTerm (agda-sort _) (meta _ _) = no λ () eqTerm (lit _) (meta _ _) = no λ () eqTerm unknown (meta _ _) = no λ () eqTerm (meta _ _) (var _ _) = no λ () eqTerm (meta _ _) (con _ _) = no λ () eqTerm (meta _ _) (def _ _) = no λ () eqTerm (meta _ _) (lam _ _) = no λ () eqTerm (meta _ _) (pi _ _) = no λ () eqTerm (meta _ _) (agda-sort _) = no λ () eqTerm (meta _ _) (lit _) = no λ () eqTerm (meta _ _) unknown = no λ () eqTerm (var _ _) (pat-lam _ _) = no λ () eqTerm (con _ _) (pat-lam _ _) = no λ () eqTerm (def _ _) (pat-lam _ _) = no λ () eqTerm (lam _ _) (pat-lam _ _) = no λ () eqTerm (pi _ _) (pat-lam _ _) = no λ () eqTerm (meta _ _) (pat-lam _ _) = no λ () eqTerm (agda-sort _) (pat-lam _ _) = no λ () eqTerm (lit _) (pat-lam _ _) = no λ () eqTerm unknown (pat-lam _ _) = no λ () eqTerm (pat-lam _ _) (var _ _) = no λ () eqTerm (pat-lam _ _) (con _ _) = no λ () eqTerm (pat-lam _ _) (def _ _) = no λ () eqTerm (pat-lam _ _) (lam _ _) = no λ () eqTerm (pat-lam _ _) (pi _ _) = no λ () eqTerm (pat-lam _ _) (meta _ _) = no λ () eqTerm (pat-lam _ _) (agda-sort _) = no λ () eqTerm (pat-lam _ _) (lit _) = no λ () eqTerm (pat-lam _ _) unknown = no λ () eqSort (set t) (set t₁) = decEq₁ set-inj (eqTerm t t₁) eqSort (lit n) (lit n₁) = decEq₁ slit-inj (n == n₁) eqSort unknown unknown = yes refl eqSort (set t) (lit n) = no λ () eqSort (set t) unknown = no λ () eqSort (lit n) (set t) = no λ () eqSort (lit n) unknown = no λ () eqSort unknown (set t) = no λ () eqSort unknown (lit n) = no λ () eqPat (con c ps) (con c₁ ps₁) = decEq₂ pcon-inj₁ pcon-inj₂ (c == c₁) (eqPats ps ps₁) eqPat dot dot = yes refl eqPat (var s) (var s₁) = decEq₁ pvar-inj (s == s₁) eqPat (lit l) (lit l₁) = decEq₁ plit-inj (l == l₁) eqPat (proj f) (proj f₁) = decEq₁ proj-inj (f == f₁) eqPat absurd absurd = yes refl eqPat (con _ _) dot = no λ () eqPat (con _ _) (var _) = no λ () eqPat (con _ _) (lit _) = no λ () eqPat (con _ _) (proj _) = no λ () eqPat (con _ _) absurd = no λ () eqPat dot (con _ _) = no λ () eqPat dot (var _) = no λ () eqPat dot (lit _) = no λ () eqPat dot (proj _) = no λ () eqPat dot absurd = no λ () eqPat (var _) (con _ _) = no λ () eqPat (var _) dot = no λ () eqPat (var _) (lit _) = no λ () eqPat (var _) (proj _) = no λ () eqPat (var _) absurd = no λ () eqPat (lit _) (con _ _) = no λ () eqPat (lit _) dot = no λ () eqPat (lit _) (var _) = no λ () eqPat (lit _) (proj _) = no λ () eqPat (lit _) absurd = no λ () eqPat (proj _) (con _ _) = no λ () eqPat (proj _) dot = no λ () eqPat (proj _) (var _) = no λ () eqPat (proj _) (lit _) = no λ () eqPat (proj _) absurd = no λ () eqPat absurd (con _ _) = no λ () eqPat absurd dot = no λ () eqPat absurd (var _) = no λ () eqPat absurd (lit _) = no λ () eqPat absurd (proj _) = no λ () eqClause (clause ps t) (clause ps₁ t₁) = decEq₂ clause-inj₁ clause-inj₂ (eqPats ps ps₁) (eqTerm t t₁) eqClause (absurd-clause ps) (absurd-clause ps₁) = decEq₁ absurd-clause-inj (eqPats ps ps₁) eqClause (clause _ _) (absurd-clause _) = no λ () eqClause (absurd-clause _) (clause _ _) = no λ () instance EqTerm : Eq Term _==_ {{EqTerm}} = eqTerm EqSort : Eq Sort _==_ {{EqSort}} = eqSort EqClause : Eq Clause _==_ {{EqClause}} = eqClause EqPattern : Eq Pattern _==_ {{EqPattern}} = eqPat
{ "alphanum_fraction": 0.5402867873, "avg_line_length": 39.7152542373, "ext": "agda", "hexsha": "1c98ffbd2fed23ade13879e2f3951fd1fb6ba635", "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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lclem/agda-prelude", "max_forks_repo_path": "src/Tactic/Reflection/Equality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "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": "lclem/agda-prelude", "max_issues_repo_path": "src/Tactic/Reflection/Equality.agda", "max_line_length": 116, "max_stars_count": null, "max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lclem/agda-prelude", "max_stars_repo_path": "src/Tactic/Reflection/Equality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4490, "size": 11716 }
module Natural where open import Agda.Builtin.Equality data ℕ : Set where zero : ℕ suc : ℕ → ℕ -- seven = suc (suc (suc (suc (suc (suc (suc zero)))))) {-# BUILTIN NATURAL ℕ #-} _+_ : ℕ → ℕ → ℕ infixl 6 _+_ zero + b = b (suc a) + b = suc (a + b) {-# BUILTIN NATPLUS _+_ #-} +-id : ∀ (a : ℕ) → a + zero ≡ zero + a +-id zero = refl +-id (suc a) rewrite +-id a = refl +-comm : ∀ (a b : ℕ) → a + b ≡ b + a +-comm zero b rewrite +-id b = refl +-comm (suc a) zero rewrite +-id (suc a) = refl +-comm (suc a) (suc b) rewrite +-comm a (suc b) | +-comm b (suc a) | +-comm a b = refl +-asso : ∀ (a b c : ℕ) → a + b + c ≡ a + (b + c) +-asso zero b c = refl +-asso (suc a) zero c rewrite +-id (suc a) | +-id a = refl +-asso (suc a) (suc b) zero rewrite +-id (suc a + suc b) | +-id b = refl +-asso (suc a) (suc b) (suc c) rewrite (+-comm a (suc b)) | +-comm (b + a) (suc c) | +-comm b a | +-comm c (a + b) | +-comm b (suc c) | +-comm a (suc (suc (c + b))) | +-comm c b | +-comm (b + c) a | +-asso a b c = refl +-rear : ∀ (a b c d : ℕ) → a + b + (c + d) ≡ a + (b + c) + d +-rear zero b c d rewrite +-asso b c d = refl +-rear (suc a) b c d rewrite (+-asso (suc a) b (c + d)) | +-asso a (b + c) d | +-asso b c d = refl +-swap : ∀ (a b c : ℕ) → a + (b + c) ≡ b + (a + c) +-swap a b c rewrite (+-comm a (b + c)) | +-comm b (a + c) | +-asso a c b | +-comm c b | +-comm a (b + c) = refl _*_ : ℕ → ℕ → ℕ infixl 7 _*_ zero * b = zero suc a * b = b + a * b {-# BUILTIN NATTIMES _*_ #-} *-id : ∀ (a : ℕ) → a * (suc zero) ≡ (suc zero) * a *-id zero = refl *-id (suc a) rewrite +-comm (suc zero) a | *-id a = refl *-z : ∀ (a : ℕ) → a * zero ≡ zero * a *-z zero = refl *-z (suc a) rewrite *-z a = refl *-comm : ∀ (a b : ℕ) → a * b ≡ b * a *-comm zero b rewrite *-z b = refl *-comm (suc a) zero rewrite *-z a = refl *-comm (suc a) (suc b) rewrite (*-comm a (suc b)) | (*-comm b (suc a)) | (*-comm a b ) | (+-comm b (a + b * a)) | (+-comm a (b + b * a)) | (+-comm a (b * a)) | (+-comm b (b * a)) | (+-asso (b * a) a b) | (+-asso (b * a) b a) | (+-comm a b) = refl *-+-dist-r : ∀ (a b c : ℕ) → (a + b) * c ≡ a * c + b * c *-+-dist-r zero b c = refl *-+-dist-r (suc a) zero c rewrite (+-comm (suc a) zero) | +-comm a zero | +-asso c (a * c) zero | +-comm (a * c) zero = refl *-+-dist-r (suc a) (suc b) c rewrite (+-comm a (suc b)) | +-rear c (a * c) c (b * c) | +-comm (a * c) c | +-asso c (c + a * c) (b * c) | +-asso c (a * c) (b * c) | +-comm (a * c) (b * c) | *-+-dist-r b a c = refl *-+-dist-l : ∀ (a b c : ℕ) → a * (b + c) ≡ a * b + a * c *-+-dist-l a zero c rewrite (*-z a) = refl *-+-dist-l a (suc b) zero rewrite (+-comm (suc b) zero) | *-z a | +-comm (a * suc b) zero = refl *-+-dist-l a (suc b) (suc c) rewrite (+-comm b (suc c)) | *-comm a (suc (suc (c + b))) | *-comm a (suc b) | *-comm a (suc c) | +-rear a (b * a) a (c * a) | +-comm (b * a) a | +-asso a (a + b * a) (c * a) | +-asso a (b * a) (c * a) | +-comm (b * a) (c * a) | *-comm (c + b) a | *-comm c a | *-comm b a | *-+-dist-l a c b = refl *-asso : ∀ (a b c : ℕ) → a * b * c ≡ a * (b * c) *-asso zero b c = refl *-asso (suc a) zero c rewrite (*-asso a zero c) = refl *-asso (suc a) (suc b) c rewrite (*-+-dist-r (suc b) (a * suc b) c) | *-asso a (suc b) c = refl _^_ : ℕ → ℕ → ℕ m ^ zero = suc zero m ^ (suc n) = m * (m ^ n) ^-dist-+-*-l : ∀ (a b c : ℕ) → a ^ (b + c) ≡ (a ^ b) * (a ^ c) ^-dist-+-*-l a zero c rewrite (+-comm zero (a ^ c)) | +-asso (a ^ c) zero zero = refl ^-dist-+-*-l a (suc b) c rewrite *-asso a (a ^ b) (a ^ c) | ^-dist-+-*-l a b c = refl ^-dist-*-r : ∀ (a b c : ℕ) → (a * b) ^ c ≡ (a ^ c) * (b ^ c) ^-dist-*-r a b zero rewrite (+-comm (suc zero) zero) = refl ^-dist-*-r a b (suc c) rewrite (*-asso a (a ^ c) (b * (b ^ c))) | *-comm (a ^ c) (b * (b ^ c)) | *-asso b (b ^ c) (a ^ c) | *-comm (b ^ c) (a ^ c) | *-asso a b ((a * b) ^ c) | ^-dist-*-r a b c = refl ^-asso-* : ∀ (a b c : ℕ) → (a ^ b) ^ c ≡ a ^ (b * c) ^-asso-* a b zero rewrite (*-comm b zero) = refl ^-asso-* a b (suc c) rewrite (*-comm b (suc c)) | ^-dist-+-*-l a b (c * b) | *-comm c b | ^-asso-* a b c = refl data Bin : Set where ⟨⟩ : Bin _O : Bin → Bin _I : Bin → Bin inc : Bin → Bin inc ⟨⟩ = ⟨⟩ I inc (n O) = n I inc (n I) = (inc n) O to : ℕ → Bin to zero = ⟨⟩ O to (suc n) = inc (to n) from : Bin → ℕ from ⟨⟩ = zero from (n O) = 2 * (from n) from (n I) = suc (2 * (from n)) thm₁ : ∀ (b : Bin) → from (inc b) ≡ suc (from b) thm₁ ⟨⟩ = refl thm₁ (a O) = refl thm₁ (a I) rewrite thm₁ a | +-comm (suc (from a)) zero | +-comm (from a) zero | +-comm (from a) (suc (from a)) = refl -- thm₂ : ∀ (b : Bin) → to (from b) = b -- 这是错误的,因为 Bin 中的 (⟨⟩ O) 和 (⟨⟩) -- 都和 自然数 的 0 对应 -- from 并非单射 thm₃ : ∀ (n : ℕ) → from (to n) ≡ n thm₃ zero = refl thm₃ (suc n) rewrite thm₁ (to (suc n)) | thm₁ (to n) | thm₃ n = refl
{ "alphanum_fraction": 0.431804878, "avg_line_length": 24.4047619048, "ext": "agda", "hexsha": "2356b644c5eb0850b67836a08224f03bf39b0819", "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": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "kands-code/agda-exercise", "max_forks_repo_path": "Natural.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd", "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": "kands-code/agda-exercise", "max_issues_repo_path": "Natural.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "b3c9c4f678feac75af6f30d0dd941ab58b9f40dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "kands-code/agda-exercise", "max_stars_repo_path": "Natural.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2299, "size": 5125 }