Search is not available for this dataset
text
string
meta
dict
module bstd.bign where
{ "alphanum_fraction": 0.7916666667, "avg_line_length": 8, "ext": "agda", "hexsha": "3c23dcf2ebb11937c6825491c9bbbf8ad70b4c40", "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/bign.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/bign.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/bign.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": 24 }
-- {-# OPTIONS -v tc.lhs.unify:100 #-} -- Reported by project member adamgundry, 2012-10-26 -- I was trying to extend Conor's KIPLING technique (Outrageous but -- Meaningful Coincidences, WGP 2010) which depends on indexing a -- syntax by functions, when I hit this problem: module Issue738 where open import Common.Equality data U : Set where a : U b : U -- works, with explicit equality: module Param where data D (f : U → U) : Set where da : (f ≡ λ x → a) → D f db : (f ≡ λ x → b) → D f app : ∀ {A B : Set}{f g : A → B} → f ≡ g → ∀ x → f x ≡ g x app refl x = refl fu : D (λ x → a) → Set fu (da refl) = U fu (db p) with app p a ... | () -- original formulation: module Index where data Foo : (U -> U) -> Set where mka : Foo (\ x -> a) mkb : Foo (\ x -> b) foo : Foo (\ x -> a) -> Set foo mka = ? -- This gives the error message: -- -- Cannot decide whether there should be a case for the constructor -- -- mkb, since the unification gets stuck on unifying the inferred -- -- indices -- -- [λ x → b] -- -- with the expected indices -- -- [λ x → a] -- -- when checking the definition of foo -- But these indices cannot be unified (a and b are constants) so it -- should be possible to exclude this case. Could we improve the -- unifier to notice this? -- Andreas, 2012-10-29 No, because if the domain type is empty, -- these two lambdas cannot be disunified
{ "alphanum_fraction": 0.6183098592, "avg_line_length": 24.0677966102, "ext": "agda", "hexsha": "1e5f0c124dc78f53c35e72cf80abba7265f0f4fa", "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/Issue738.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/Issue738.agda", "max_line_length": 70, "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/Issue738.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": 446, "size": 1420 }
module Functors where open import Library open import Categories open Cat record Fun {a b c d} (C : Cat {a}{b})(D : Cat {c}{d}) : Set (a ⊔ b ⊔ c ⊔ d) where constructor functor field OMap : Obj C → Obj D HMap : ∀{X Y} → Hom C X Y → Hom D (OMap X) (OMap Y) fid : ∀{X} → HMap (iden C {X}) ≅ iden D {OMap X} fcomp : ∀{X Y Z}{f : Hom C Y Z}{g : Hom C X Y} → HMap (comp C f g) ≅ comp D (HMap f) (HMap g) open Fun IdF : ∀{a b}(C : Cat {a}{b}) → Fun C C IdF C = record{OMap = id;HMap = id;fid = refl;fcomp = refl} _○_ : ∀{a b c d e f}{C : Cat {a}{b}}{D : Cat {c}{d}}{E : Cat {e}{f}} → Fun D E → Fun C D → Fun C E _○_ {C = C}{D}{E} F G = record{ OMap = OMap F ∘ OMap G; HMap = HMap F ∘ HMap G; fid = proof HMap F (HMap G (iden C)) ≅⟨ cong (HMap F) (fid G) ⟩ HMap F (iden D) ≅⟨ fid F ⟩ iden E ∎; fcomp = λ {_}{_}{_}{f}{g} → proof HMap F (HMap G (comp C f g)) ≅⟨ cong (HMap F) (fcomp G) ⟩ HMap F (comp D (HMap G f) (HMap G g)) ≅⟨ fcomp F ⟩ comp E (HMap F (HMap G f)) (HMap F (HMap G g)) ∎} infix 10 _○_ FunctorEq : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}(F G : Fun C D) → OMap F ≅ OMap G → (λ {X Y} → HMap F {X}{Y}) ≅ (λ {X}{Y} → HMap G {X}{Y}) → F ≅ G FunctorEq (functor fo fh _ _) (functor .fo .fh _ _) refl refl = cong₂ (functor fo fh) (iext λ _ → ir _ _) (iext λ _ → iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)
{ "alphanum_fraction": 0.4730538922, "avg_line_length": 30.06, "ext": "agda", "hexsha": "e885856ae2efecee16d0c3bf54c6beae195e7ed2", "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": "Functors.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": "Functors.agda", "max_line_length": 76, "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": "Functors.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": 679, "size": 1503 }
open import Oscar.Prelude open import Oscar.Class.Successor₀ open import Oscar.Class.Injectivity open import Oscar.Data.¶ open import Oscar.Data.Vec open import Oscar.Data.Proposequality import Oscar.Property.Thickandthin.FinFinProposequalityMaybeProposequality module Oscar.Class.Injectivity.Vec where instance 𝓘njection₂Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njection₂ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) 𝓘njection₂Vec .𝓘njection₂.injection₂ = _,_ [𝓘njectivity₂,₀,₁]Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → [𝓘njectivity₂,₀,₁] (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality [𝓘njectivity₂,₀,₁]Vec = ∁ 𝓘njectivity₂,₀,₁Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njectivity₂,₀,₁ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality 𝓘njectivity₂,₀,₁Vec .𝓘njectivity₂,₀,₁.injectivity₂,₀,₁ ∅ = ∅ [𝓘njectivity₂,₀,₂]Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → [𝓘njectivity₂,₀,₂] (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality [𝓘njectivity₂,₀,₂]Vec = ∁ 𝓘njectivity₂,₀,₂Vec : ∀ {N} {𝔭} {𝔓 : ¶ → Ø 𝔭} → 𝓘njectivity₂,₀,₂ (λ (x : 𝔓 N) (_ : Vec⟨ 𝔓 ⟩ N) → Vec⟨ 𝔓 ⟩ (⇑₀ N)) Proposequality Proposequality 𝓘njectivity₂,₀,₂Vec .𝓘njectivity₂,₀,₂.injectivity₂,₀,₂ ∅ = ∅
{ "alphanum_fraction": 0.6359262229, "avg_line_length": 44.5357142857, "ext": "agda", "hexsha": "1ea187bda3def386d77269c01888dfc30f15f716", "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/Injectivity/Vec.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/Injectivity/Vec.agda", "max_line_length": 149, "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/Injectivity/Vec.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 643, "size": 1247 }
{-# OPTIONS --without-K --safe #-} -- Exact category (https://ncatlab.org/nlab/show/exact+category) -- is a regular category -- in which every internal equivalence is a kernel pair module Categories.Category.Exact where open import Level open import Categories.Category.Core open import Categories.Diagram.Pullback open import Categories.Category.Cocartesian open import Categories.Object.Coproduct open import Categories.Morphism open import Categories.Category.Complete.Finitely using (FinitelyComplete) open import Categories.Diagram.Coequalizer open import Categories.Diagram.KernelPair open import Categories.Category.Regular open import Categories.Morphism.Regular open import Categories.Object.InternalRelation record Exact {o ℓ e : Level} (𝒞 : Category o ℓ e) : Set (suc (o ⊔ ℓ ⊔ e)) where open Category 𝒞 open Pullback open Coequalizer open Equivalence field regular : Regular 𝒞 quotient : ∀ {X : Obj} (E : Equivalence 𝒞 X) → Coequalizer 𝒞 (R.p₁ E) (R.p₂ E) effective : ∀ {X : Obj} (E : Equivalence 𝒞 X) → IsPullback 𝒞 (R.p₁ E) (R.p₂ E) (arr (quotient E)) (arr (quotient E))
{ "alphanum_fraction": 0.7424511545, "avg_line_length": 31.2777777778, "ext": "agda", "hexsha": "23cd34507e044066419c62b0e5c6ec740f6e9421", "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": "c202a616d4f376b11e8320e641c98db2ddc9d233", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Akshobhya1234/agda-categories", "max_forks_repo_path": "src/Categories/Category/Exact.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c202a616d4f376b11e8320e641c98db2ddc9d233", "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": "Akshobhya1234/agda-categories", "max_issues_repo_path": "src/Categories/Category/Exact.agda", "max_line_length": 84, "max_stars_count": null, "max_stars_repo_head_hexsha": "c202a616d4f376b11e8320e641c98db2ddc9d233", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Akshobhya1234/agda-categories", "max_stars_repo_path": "src/Categories/Category/Exact.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 309, "size": 1126 }
module VecS where open import Data.Empty open import Data.Product hiding (map) open import Data.Sum open import Data.Vec open import Data.Nat open import Data.Bool open import Data.Nat.Properties import Homotopy as Pi ------------------------------------------------------------------------------ data B : Set where ZERO : B ONE : B PLUS : B → B → B TIMES : B → B → B DUAL : B → B data BVAL : B → Set where UNIT : BVAL ONE LEFT : {b₁ b₂ : B} → BVAL b₁ → BVAL (PLUS b₁ b₂) RIGHT : {b₁ b₂ : B} → BVAL b₂ → BVAL (PLUS b₁ b₂) PAIR : {b₁ b₂ : B} → BVAL b₁ → BVAL b₂ → BVAL (TIMES b₁ b₂) FLIP : {b : B} → BVAL b → BVAL (DUAL b) data Iso : {b₁ b₂ : B} → BVAL b₁ → BVAL b₂ → Set where unite₊ : {b : B} {v : BVAL b} → Iso (RIGHT {ZERO} {b} v) v uniti₊ : {b : B} {v : BVAL b} → Iso v (RIGHT {ZERO} {b} v) swap₊1 : {b₁ b₂ : B} {v₁ : BVAL b₁} → Iso (LEFT {b₁} {b₂} v₁) (RIGHT {b₂} {b₁} v₁) swap₊2 : {b₁ b₂ : B} {v₂ : BVAL b₂} → Iso (RIGHT {b₁} {b₂} v₂) (LEFT {b₂} {b₁} v₂) assocl₊1 : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} → Iso (LEFT {b₁} {PLUS b₂ b₃} v₁) (LEFT {PLUS b₁ b₂} {b₃} (LEFT {b₁} {b₂} v₁)) assocl₊2 : {b₁ b₂ b₃ : B} {v₂ : BVAL b₂} → Iso (RIGHT {b₁} {PLUS b₂ b₃} (LEFT {b₂} {b₃} v₂)) (LEFT {PLUS b₁ b₂} {b₃} (RIGHT {b₁} {b₂} v₂)) assocl₊3 : {b₁ b₂ b₃ : B} {v₃ : BVAL b₃} → Iso (RIGHT {b₁} {PLUS b₂ b₃} (RIGHT {b₂} {b₃} v₃)) (RIGHT {PLUS b₁ b₂} {b₃} v₃) assocr₊1 : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} → Iso (LEFT {PLUS b₁ b₂} {b₃} (LEFT {b₁} {b₂} v₁)) (LEFT {b₁} {PLUS b₂ b₃} v₁) assocr₊2 : {b₁ b₂ b₃ : B} {v₂ : BVAL b₂} → Iso (LEFT {PLUS b₁ b₂} {b₃} (RIGHT {b₁} {b₂} v₂)) (RIGHT {b₁} {PLUS b₂ b₃} (LEFT {b₂} {b₃} v₂)) assocr₊3 : {b₁ b₂ b₃ : B} {v₃ : BVAL b₃} → Iso (RIGHT {PLUS b₁ b₂} {b₃} v₃) (RIGHT {b₁} {PLUS b₂ b₃} (RIGHT {b₂} {b₃} v₃)) unite⋆ : {b : B} {v : BVAL b} → Iso (PAIR UNIT v) v uniti⋆ : {b : B} {v : BVAL b} → Iso v (PAIR UNIT v) swap⋆ : {b₁ b₂ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} → Iso (PAIR v₁ v₂) (PAIR v₂ v₁) assocl⋆ : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} → Iso (PAIR v₁ (PAIR v₂ v₃)) (PAIR (PAIR v₁ v₂) v₃) assocr⋆ : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} → Iso (PAIR (PAIR v₁ v₂) v₃) (PAIR v₁ (PAIR v₂ v₃)) dist1 : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} {v₃ : BVAL b₃} → Iso (PAIR (LEFT {b₁} {b₂} v₁) v₃) (LEFT {TIMES b₁ b₃} {TIMES b₂ b₃} (PAIR v₁ v₃)) dist2 : {b₁ b₂ b₃ : B} {v₂ : BVAL b₂} {v₃ : BVAL b₃} → Iso (PAIR (RIGHT {b₁} {b₂} v₂) v₃) (RIGHT {TIMES b₁ b₃} {TIMES b₂ b₃} (PAIR v₂ v₃)) factor1 : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} {v₃ : BVAL b₃} → Iso (LEFT {TIMES b₁ b₃} {TIMES b₂ b₃} (PAIR v₁ v₃)) (PAIR (LEFT {b₁} {b₂} v₁) v₃) factor2 : {b₁ b₂ b₃ : B} {v₂ : BVAL b₂} {v₃ : BVAL b₃} → Iso (RIGHT {TIMES b₁ b₃} {TIMES b₂ b₃} (PAIR v₂ v₃)) (PAIR (RIGHT {b₁} {b₂} v₂) v₃) id⟷ : {b : B} {v : BVAL b} → Iso v v sym : {b₁ b₂ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} → Iso v₁ v₂ → Iso v₂ v₁ VSEMI : {b₁ b₂ b₃ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} → Iso v₁ v₂ → Iso v₂ v₃ → Iso v₁ v₃ VPLUS1 : {b₁ b₂ b₃ b₄ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} {v₄ : BVAL b₄} → Iso v₁ v₃ → Iso v₂ v₄ → Iso (LEFT {b₁} {b₂} v₁) (LEFT {b₃} {b₄} v₃) VPLUS2 : {b₁ b₂ b₃ b₄ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} {v₄ : BVAL b₄} → Iso v₁ v₃ → Iso v₂ v₄ → Iso (RIGHT {b₁} {b₂} v₂) (RIGHT {b₃} {b₄} v₄) VTIMES : {b₁ b₂ b₃ b₄ : B} {v₁ : BVAL b₁} {v₂ : BVAL b₂} {v₃ : BVAL b₃} {v₄ : BVAL b₄} → Iso v₁ v₃ → Iso v₂ v₄ → Iso (PAIR v₁ v₂) (PAIR v₃ v₄) refe⋆ : {b : B} {v : BVAL b} → Iso (FLIP (FLIP v)) v refi⋆ : {b : B} {v : BVAL b} → Iso v (FLIP (FLIP v)) rile⋆ : {b : B} {v : BVAL b} → Iso (PAIR v (PAIR v (FLIP v))) v rili⋆ : {b : B} {v : BVAL b} → Iso v (PAIR v (PAIR v (FLIP v))) ------------------------------------------------------------------------------ -- Pi combinators -- embed pi into the values with duals liftT : Pi.B → B liftT Pi.ZERO = ZERO liftT Pi.ONE = ONE liftT (Pi.PLUS b₁ b₂) = PLUS (liftT b₁) (liftT b₂) liftT (Pi.TIMES b₁ b₂) = TIMES (liftT b₁) (liftT b₂) lift : {b : Pi.B} → Pi.BVAL b → BVAL (liftT b) lift Pi.UNIT = UNIT lift (Pi.LEFT v) = LEFT (lift v) lift (Pi.RIGHT v) = RIGHT (lift v) lift (Pi.PAIR v₁ v₂) = PAIR (lift v₁) (lift v₂) embed : {b₁ b₂ : Pi.B} → Pi.Id_B (b₁ , b₂) → Pi.BVAL b₁ → BVAL (TIMES (DUAL (liftT b₁)) (liftT b₂)) embed c v = PAIR (FLIP (lift v)) (lift (Pi.eval c v)) -- the idea would be that: -- if eval pi-combinator v = v' -- then we would have a proof that -- (embed pi-combinator v , v) ~iso~ v' pibool : Pi.B pibool = Pi.PLUS Pi.ONE Pi.ONE pitrue : Pi.BVAL pibool pitrue = Pi.LEFT Pi.UNIT ex1 : BVAL (TIMES (DUAL (PLUS ONE ONE)) (PLUS ONE ONE)) ex1 = embed {pibool} {pibool} Pi.swap₊ pitrue -- ex1 = PAIR (FLIP (LEFT UNIT)) (RIGHT UNIT) -- Check: PAIR (PAIR (FLIP (LEFT UNIT)) (RIGHT UNIT)) (LEFT UNIT) ~ RIGHT UNIT
{ "alphanum_fraction": 0.5159952607, "avg_line_length": 45.6216216216, "ext": "agda", "hexsha": "eb78522fa30338cb67bc7a17252d54602a15cf05", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "agda/VecS.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "agda/VecS.agda", "max_line_length": 109, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "agda/VecS.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 2490, "size": 5064 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Finite sets ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Fin where ------------------------------------------------------------------------ -- Publicly re-export the contents of the base module open import Data.Fin.Base public ------------------------------------------------------------------------ -- Publicly re-export queries open import Data.Fin.Properties public using (_≟_; _≤?_; _<?_)
{ "alphanum_fraction": 0.3510273973, "avg_line_length": 27.8095238095, "ext": "agda", "hexsha": "5bab778c3726408a2e745f281472e9020af675e3", "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/Fin.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/Fin.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/Fin.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 83, "size": 584 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Function setoids and related constructions ------------------------------------------------------------------------ module Function.Equality where open import Function as Fun using (_on_) open import Level import Relation.Binary as B import Relation.Binary.Indexed as I ------------------------------------------------------------------------ -- Functions which preserve equality record Π {f₁ f₂ t₁ t₂} (From : B.Setoid f₁ f₂) (To : I.Setoid (B.Setoid.Carrier From) t₁ t₂) : Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where open I using (_=[_]⇒_) infixl 5 _⟨$⟩_ field _⟨$⟩_ : (x : B.Setoid.Carrier From) → I.Setoid.Carrier To x cong : B.Setoid._≈_ From =[ _⟨$⟩_ ]⇒ I.Setoid._≈_ To open Π public infixr 0 _⟶_ _⟶_ : ∀ {f₁ f₂ t₁ t₂} → B.Setoid f₁ f₂ → B.Setoid t₁ t₂ → Set _ From ⟶ To = Π From (B.Setoid.indexedSetoid To) -- Identity and composition. id : ∀ {a₁ a₂} {A : B.Setoid a₁ a₂} → A ⟶ A id = record { _⟨$⟩_ = Fun.id; cong = Fun.id } infixr 9 _∘_ _∘_ : ∀ {a₁ a₂} {A : B.Setoid a₁ a₂} {b₁ b₂} {B : B.Setoid b₁ b₂} {c₁ c₂} {C : B.Setoid c₁ c₂} → B ⟶ C → A ⟶ B → A ⟶ C f ∘ g = record { _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g) ; cong = Fun._∘_ (cong f) (cong g) } -- Constant equality-preserving function. const : ∀ {a₁ a₂} {A : B.Setoid a₁ a₂} {b₁ b₂} {B : B.Setoid b₁ b₂} → B.Setoid.Carrier B → A ⟶ B const {B = B} b = record { _⟨$⟩_ = Fun.const b ; cong = Fun.const (B.Setoid.refl B) } ------------------------------------------------------------------------ -- Function setoids -- Dependent. setoid : ∀ {f₁ f₂ t₁ t₂} (From : B.Setoid f₁ f₂) → I.Setoid (B.Setoid.Carrier From) t₁ t₂ → B.Setoid _ _ setoid From To = record { Carrier = Π From To ; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y ; isEquivalence = record { refl = λ {f} → cong f ; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y)) ; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y) } } where open module From = B.Setoid From using () renaming (_≈_ to _≈₁_) open module To = I.Setoid To using () renaming (_≈_ to _≈₂_) -- Non-dependent. infixr 0 _⇨_ _⇨_ : ∀ {f₁ f₂ t₁ t₂} → B.Setoid f₁ f₂ → B.Setoid t₁ t₂ → B.Setoid _ _ From ⇨ To = setoid From (B.Setoid.indexedSetoid To) -- A variant of setoid which uses the propositional equality setoid -- for the domain, and a more convenient definition of _≈_. ≡-setoid : ∀ {f t₁ t₂} (From : Set f) → I.Setoid From t₁ t₂ → B.Setoid _ _ ≡-setoid From To = record { Carrier = (x : From) → Carrier x ; _≈_ = λ f g → ∀ x → f x ≈ g x ; isEquivalence = record { refl = λ {f} x → refl ; sym = λ f∼g x → sym (f∼g x) ; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x) } } where open I.Setoid To -- Parameter swapping function. flip : ∀ {a₁ a₂} {A : B.Setoid a₁ a₂} {b₁ b₂} {B : B.Setoid b₁ b₂} {c₁ c₂} {C : B.Setoid c₁ c₂} → A ⟶ B ⇨ C → B ⟶ A ⇨ C flip {B = B} f = record { _⟨$⟩_ = λ b → record { _⟨$⟩_ = λ a → f ⟨$⟩ a ⟨$⟩ b ; cong = λ a₁≈a₂ → cong f a₁≈a₂ (B.Setoid.refl B) } ; cong = λ b₁≈b₂ a₁≈a₂ → cong f a₁≈a₂ b₁≈b₂ }
{ "alphanum_fraction": 0.4993924666, "avg_line_length": 28.6260869565, "ext": "agda", "hexsha": "510171b6a31b947c941dd7dfbb610620c3307c8f", "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/Function/Equality.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/Function/Equality.agda", "max_line_length": 74, "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/Function/Equality.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": 1293, "size": 3292 }
{- Eilenberg–Mac Lane type K(G, 1) -} {-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-} module Cubical.HITs.EilenbergMacLane1.Properties where open import Cubical.HITs.EilenbergMacLane1.Base open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.Data.Sigma open import Cubical.Data.Empty renaming (rec to ⊥-rec) hiding (elim) open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.AbGroup.Base open import Cubical.Functions.Morphism private variable ℓG ℓ : Level module _ ((G , str) : Group ℓG) where open GroupStr str elimGroupoid : {B : EM₁ (G , str) → Type ℓ} → ((x : EM₁ (G , str)) → isGroupoid (B x)) → (b : B embase) → (bloop : ((g : G) → PathP (λ i → B (emloop g i)) b b)) → ((g h : G) → PathP (λ i → PathP (λ j → B (emcomp g h j i)) (bloop g i) (bloop (g · h) i)) (λ _ → b) (bloop h)) → (x : EM₁ (G , str)) → B x elimGroupoid Bgroup b bloop bcomp embase = b elimGroupoid Bgroup b bloop bcomp (emloop x i) = bloop x i elimGroupoid Bgroup b bloop bcomp (emcomp g h j i) = bcomp g h i j elimGroupoid {B = B} Bgroup b bloop bcomp (emsquash g h p q r s i j k) = help i j k where help : PathP (λ i → PathP (λ j → PathP (λ k → B (emsquash g h p q r s i j k)) (elimGroupoid Bgroup b bloop bcomp g) (elimGroupoid Bgroup b bloop bcomp h)) (λ k → elimGroupoid Bgroup b bloop bcomp (p k)) λ k → elimGroupoid Bgroup b bloop bcomp (q k)) (λ j k → elimGroupoid Bgroup b bloop bcomp (r j k)) λ j k → elimGroupoid Bgroup b bloop bcomp (s j k) help = toPathP (isOfHLevelPathP' 1 (isOfHLevelPathP' 2 (Bgroup _) _ _) _ _ _ _) elimSet : {B : EM₁ (G , str) → Type ℓ} → ((x : EM₁ (G , str)) → isSet (B x)) → (b : B embase) → ((g : G) → PathP (λ i → B (emloop g i)) b b) → (x : EM₁ (G , str)) → B x elimSet Bset b bloop embase = b elimSet Bset b bloop (emloop g i) = bloop g i elimSet Bset b bloop (emcomp g h i j) = isSet→SquareP (λ i j → Bset (emcomp g h i j)) (λ j → bloop g j) (λ j → bloop (g · h) j) (λ i → b) (λ i → bloop h i) i j elimSet Bset b bloop (emsquash x y p q r s i j k) = isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (Bset x)) _ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (emsquash x y p q r s) i j k where g = elimSet Bset b bloop elimProp : {B : EM₁ (G , str) → Type ℓ} → ((x : EM₁ (G , str)) → isProp (B x)) → B embase → (x : EM₁ (G , str)) → B x elimProp Bprop b x = elimSet (λ x → isProp→isSet (Bprop x)) b (λ g → isProp→PathP (λ i → Bprop ((emloop g) i)) b b) x elimProp2 : {C : EM₁ (G , str) → EM₁ (G , str) → Type ℓ} → ((x y : EM₁ (G , str)) → isProp (C x y)) → C embase embase → (x y : EM₁ (G , str)) → C x y elimProp2 Cprop c = elimProp (λ x → isPropΠ (λ y → Cprop x y)) (elimProp (λ y → Cprop embase y) c) elim : {B : EM₁ (G , str) → Type ℓ} → ((x : EM₁ (G , str)) → isGroupoid (B x)) → (b : B embase) → (bloop : (g : G) → PathP (λ i → B (emloop g i)) b b) → ((g h : G) → SquareP (λ i j → B (emcomp g h i j)) (bloop g) (bloop (g · h)) (λ j → b) (bloop h)) → (x : EM₁ (G , str)) → B x elim Bgpd b bloop bcomp embase = b elim Bgpd b bloop bcomp (emloop g i) = bloop g i elim Bgpd b bloop bcomp (emcomp g h i j) = bcomp g h i j elim Bgpd b bloop bcomp (emsquash x y p q r s i j k) = isOfHLevel→isOfHLevelDep 3 Bgpd _ _ _ _ (λ j k → g (r j k)) (λ j k → g (s j k)) (emsquash x y p q r s) i j k where g = elim Bgpd b bloop bcomp rec : {B : Type ℓ} → isGroupoid B → (b : B) → (bloop : G → b ≡ b) → ((g h : G) → Square (bloop g) (bloop (g · h)) refl (bloop h)) → (x : EM₁ (G , str)) → B rec Bgpd = elim (λ _ → Bgpd)
{ "alphanum_fraction": 0.5448307411, "avg_line_length": 33.6307692308, "ext": "agda", "hexsha": "0505d4fd6a5eb940011a1564e929e21528276c05", "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/HITs/EilenbergMacLane1/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/HITs/EilenbergMacLane1/Properties.agda", "max_line_length": 85, "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/HITs/EilenbergMacLane1/Properties.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": 1631, "size": 4372 }
------------------------------------------------------------------------ -- An up-to technique for CCS ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude hiding (step-→) module Bisimilarity.Weak.Up-to.CCS {ℓ} {Name : Type ℓ} where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude.Size open import Function-universe equality-with-J hiding (id; _∘_) open import Bisimilarity.Weak.CCS import Bisimilarity.Weak.Equational-reasoning-instances open import Equational-reasoning open import Indexed-container hiding (⟨_⟩) open import Labelled-transition-system.CCS Name open import Relation open import Bisimilarity.Weak CCS open import Bisimilarity.Weak.Up-to CCS import Labelled-transition-system.Equational-reasoning-instances CCS as Dummy -- Up to (non-degenerate) context for CCS (for polyadic, coinductive -- contexts). Up-to-context : Trans₂ ℓ (Proc ∞) Up-to-context R (p , q) = ∃ λ n → ∃ λ (C : Context ∞ n) → Non-degenerate ∞ C × ∃ λ ps → ∃ λ qs → p ≡ C [ ps ] × q ≡ C [ qs ] × ∀ x → R (ps x , qs x) -- Up to context is monotone. up-to-context-monotone : Monotone Up-to-context up-to-context-monotone R⊆S = Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id (R⊆S ∘_) -- Up to context is size-preserving. up-to-context-size-preserving : Size-preserving Up-to-context up-to-context-size-preserving = _⇔_.from (monotone→⇔ up-to-context-monotone) (λ where (_ , C , D , ps , qs , refl , refl , ps∼qs) → C [ ps ] ∼⟨ D [ ps∼qs ]-cong ⟩■ C [ qs ]) -- Note that up to context is not compatible (assuming that Name is -- inhabited). -- -- This counterexample is a minor variant of one due to Pous and -- Sangiorgi, who state that up to context is contained in a larger -- function that is compatible for another, "one-sided" step function -- (see Section 6.5.3 in "Enhancements of the bisimulation proof -- method"). ¬-up-to-context-compatible : Name → ¬ Compatible Up-to-context ¬-up-to-context-compatible x comp = contradiction where a = x , true data R₀ : Rel₂ ℓ (Proc ∞) where base : R₀ (τ ∙ (a ∙) , a ∙) R : Rel₂ ℓ (Proc ∞) R = R₀ ⁼ !τa[R]!a : Up-to-context R (! τ ∙ (a ∙) , ! a ∙) !τa[R]!a = 1 , ! hole fzero , ! hole , (λ _ → τ ∙ (a ∙)) , (λ _ → a ∙) , refl , refl , (λ _ → inj₁ base) !a[τ]⇒̂→≡ : ∀ {P} → ! a ∙ [ τ ]⇒̂ P → P ≡ ! a ∙ !a[τ]⇒̂→≡ (non-silent ¬s _) = ⊥-elim $ ¬s _ !a[τ]⇒̂→≡ (silent _ done) = refl !a[τ]⇒̂→≡ (silent _ (step {μ = μ} s !a⟶ _)) = ⊥-elim $ name≢τ ( name a ≡⟨ !-only ·-only !a⟶ ⟩ μ ≡⟨ silent≡τ s ⟩∎ τ ∎) drop-[] : ∀ {P Q S} → Up-to-context R (P ∣ Q , ! S) → R (P ∣ Q , ! S) drop-[] (_ , hole i , _ , _ , _ , P∣Q≡Ps[i] , !S≡Qs[i] , PsRQs) = subst R (cong₂ _,_ (sym P∣Q≡Ps[i]) (sym !S≡Qs[i])) (PsRQs i) drop-[] (_ , ∅ , _ , _ , _ , () , _) drop-[] (_ , _ ∣ _ , _ , _ , _ , _ , () , _) drop-[] (_ , _ ⊕ _ , _ , _ , _ , () , _) drop-[] (_ , _ · _ , _ , _ , _ , () , _) drop-[] (_ , ⟨ν _ ⟩ _ , _ , _ , _ , () , _) drop-[] (_ , ! _ , _ , _ , _ , () , _) R⊆StepR : R ⊆ ⟦ StepC ⟧ R R⊆StepR (inj₁ base) = ⟨ lr , rl ⟩ where lr : ∀ {P μ} → τ ∙ (a ∙) [ μ ]⟶ P → ∃ λ Q → a ∙ [ μ ]⇒̂ Q × R (P , Q) lr action = _ , (a ∙ ■) , inj₂ refl rl : ∀ {Q μ} → a ∙ [ μ ]⟶ Q → ∃ λ P → τ ∙ (a ∙) [ μ ]⇒̂ P × R (P , Q) rl action = _ , (τ ∙ (a ∙) →⟨ ⟶: action ⟩ a ∙ →⟨ ⟶: action ⟩■ ∅) , inj₂ refl R⊆StepR {P , _} (inj₂ refl) = ⟨ Σ-map id (Σ-map id inj₂) ∘ lr , Σ-map id (Σ-map id (inj₂ ∘ sym)) ∘ lr ⟩ where lr : ∀ {P′ μ} → P [ μ ]⟶ P′ → ∃ λ Q′ → P [ μ ]⇒̂ Q′ × P′ ≡ Q′ lr P⟶P′ = _ , ⟶→⇒̂ P⟶P′ , refl -- Note the use of compatibility in [R]⊆Step[S]. [R]⊆Step[R] : Up-to-context R ⊆ ⟦ StepC ⟧ (Up-to-context R) [R]⊆Step[R] = Up-to-context R ⊆⟨ up-to-context-monotone (λ {x} → R⊆StepR {x}) ⟩ Up-to-context (⟦ StepC ⟧ R) ⊆⟨ comp ⟩∎ ⟦ StepC ⟧ (Up-to-context R) ∎ contradiction : ⊥ contradiction = $⟨ !τa[R]!a ⟩ Up-to-context R (! τ ∙ (a ∙) , ! a ∙) ↝⟨ [R]⊆Step[R] ⟩ ⟦ StepC ⟧ (Up-to-context R) (! τ ∙ (a ∙) , ! a ∙) ↝⟨ (λ s → StepC.left-to-right s (replication (par-right action))) ⟩ (∃ λ P → ! a ∙ [ τ ]⇒̂ P × Up-to-context R (! τ ∙ (a ∙) ∣ a ∙ , P)) ↝⟨ (λ { (_ , !a⟶ , hyp) → subst (Up-to-context R ∘ (_ ,_)) (!a[τ]⇒̂→≡ !a⟶) hyp }) ⟩ Up-to-context R (! τ ∙ (a ∙) ∣ a ∙ , ! a ∙) ↝⟨ drop-[] ⟩ R (! τ ∙ (a ∙) ∣ a ∙ , ! a ∙) ↝⟨ [ (λ ()) , (λ ()) ] ⟩□ ⊥ □
{ "alphanum_fraction": 0.4372012999, "avg_line_length": 31.703030303, "ext": "agda", "hexsha": "d2b17adcb109724724def6c7128d775907ba41e2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Bisimilarity/Weak/Up-to/CCS.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Bisimilarity/Weak/Up-to/CCS.agda", "max_line_length": 139, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Bisimilarity/Weak/Up-to/CCS.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1998, "size": 5231 }
-- Andreas, 2016-11-11 issue #2301, -- reported by stedolan and fredrikNorvallForsberg: -- compareTelescope ignored relevance. -- Faulty behavior probably existed since 2011. module Issue2301 where data Box (A : Set) : Set where wrap : A → Box A weird : ∀ A → .A → Box A weird A = wrap -- SHOULD FAIL with error: -- A → Box A !=< .A → Box A -- when checking that the expression wrap has type .A → Box A -- WAS: checked. -- Since the first argument to wrap is not actually irrelevant, -- this lets us write a function that discards irrelevance annotations: make-relevant : ∀ {A} → .A → A make-relevant a = unwrap (weird a) where unwrap : ∀ {A} → Box A → A unwrap (wrap a) = a -- or proves things we shouldn't: data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data Bool : Set where tt ff : Bool absurd : {X : Set} → X absurd {X} = different same where different : weird tt ≡ weird ff → X different () irr-eq : ∀ {A B : Set} {x y : A} (f : .A → B) → f x ≡ f y irr-eq f = refl same : weird tt ≡ weird ff same = irr-eq weird
{ "alphanum_fraction": 0.6219963031, "avg_line_length": 22.5416666667, "ext": "agda", "hexsha": "6bde70bd32e13d178d824c847a7a04c7bbef06e5", "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/Issue2301.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/Issue2301.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/Issue2301.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": 354, "size": 1082 }
mutual _ : Set _ : Set → Set
{ "alphanum_fraction": 0.5151515152, "avg_line_length": 8.25, "ext": "agda", "hexsha": "e72cda9c90de4b9bbcf00d30964455a587cca0f9", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Fail/Issue4881c.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/Issue4881c.agda", "max_line_length": 15, "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/Issue4881c.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": 15, "size": 33 }
module Dipsy.Example.CLL where open import Data.Nat using (ℕ) open import Data.Vec using (Vec; _∷_; []) open import Dipsy.Polarity using (Polarity; flip) renaming (pos to +; neg to -) mutual Op₀ : (r : Polarity) → Set Op₀ r = Op [] r Op₁ : (a r : Polarity) → Set Op₁ a r = Op (a ∷ []) r Op₂ : (a₁ a₂ r : Polarity) → Set Op₂ a₁ a₂ r = Op (a₁ ∷ a₂ ∷ []) r data Op : {n : ℕ} → Vec Polarity n → Polarity → Set where ″⊥″ : Op₀ - ″𝟏″ : Op₀ + ″⊤″ : Op₀ - ″𝟎″ : Op₀ + ″¬″ : {p : Polarity} → Op₁ (flip p) p ″⅋″ : Op₂ - - - ″⊗″ : Op₂ + + + ″&″ : Op₂ - - - ″⊕″ : Op₂ + + + open import Dipsy.Base Op Op pattern ⊥ = op ″⊥″ [] pattern 𝟏 = op ″𝟏″ [] pattern ⊤ = op ″⊤″ [] pattern 𝟎 = op ″𝟎″ [] pattern ¬_ A = op ″¬″ (A ∷ []) pattern _⅋_ A B = op ″⅋″ (A ∷ B ∷ []) pattern _⊗_ A B = op ″⊗″ (A ∷ B ∷ []) pattern _&_ A B = op ″&″ (A ∷ B ∷ []) pattern _⊕_ A B = op ″⊕″ (A ∷ B ∷ [])
{ "alphanum_fraction": 0.4749455338, "avg_line_length": 24.1578947368, "ext": "agda", "hexsha": "ca617ed09072931ec6571c5716b91f40aaad6bd8", "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": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "wenkokke/dipsy", "max_forks_repo_path": "src/Dipsy/Example/CLL.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed", "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": "wenkokke/dipsy", "max_issues_repo_path": "src/Dipsy/Example/CLL.agda", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "wenkokke/Dipsy", "max_stars_repo_path": "src/Dipsy/Example/CLL.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-10T13:43:29.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-10T13:43:29.000Z", "num_tokens": 450, "size": 918 }
-- Andreas, 2016-09-28, solve _ <= lzero. -- {-# OPTIONS -v tc.conv.nat:40 #-} open import Common.Level data C : Set₁ where c : Set _ → C -- This meta should be solved to lzero. -- ERROR WAS: -- Failed to solve the following constraints: -- [0] lsuc _0 =< lsuc lzero -- REASON: -- Non-canonical lzero in level constraint solver
{ "alphanum_fraction": 0.6557863501, "avg_line_length": 22.4666666667, "ext": "agda", "hexsha": "31460d818940fda73e0dd65baffce182a8ebab63", "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/LevelMetaLeqZero.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/LevelMetaLeqZero.agda", "max_line_length": 56, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/LevelMetaLeqZero.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": 103, "size": 337 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Coalgebra where -- Co-algebras of a Functor open import Level open import Function using (_$_) open import Categories.Category using (Category) open import Categories.Functor using (Functor; Endofunctor) record F-Coalgebra {o ℓ e} {C : Category o ℓ e} (F : Endofunctor C) : Set (o ⊔ ℓ) where open Category C field A : Obj α : A ⇒ Functor.F₀ F A open F-Coalgebra -- Given a F-Coalgebra F, one can apply F to it to obtain an new 'iterated' F-Coalgebra iterate : ∀ {o ℓ e} {C : Category o ℓ e} {F : Endofunctor C} → F-Coalgebra F → F-Coalgebra F iterate {F = F} F-alg = record { A = Functor.F₀ F $ A F-alg ; α = Functor.F₁ F $ α F-alg }
{ "alphanum_fraction": 0.6769662921, "avg_line_length": 32.3636363636, "ext": "agda", "hexsha": "b029ad4d676d451c73b278cbde017449f46b51db", "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/Functor/Coalgebra.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/Functor/Coalgebra.agda", "max_line_length": 92, "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/Functor/Coalgebra.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": 235, "size": 712 }
{-# OPTIONS --without-K --safe #-} module Data.Quiver where -- A Quiver, also known as a multidigraph, is the "underlying graph" of -- a category. Note how a Quiver has a *setoid* of edges. open import Level open import Relation.Binary using (Rel; IsEquivalence; Setoid) import Relation.Binary.Reasoning.Setoid as EqR -- a Quiver has vertices Obj and edges _⇒_, where edges form a setoid over _≈_. record Quiver o ℓ e : Set (suc (o ⊔ ℓ ⊔ e)) where infix 4 _≈_ _⇒_ field Obj : Set o _⇒_ : Rel Obj ℓ _≈_ : ∀ {A B} → Rel (A ⇒ B) e equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B}) setoid : {A B : Obj} → Setoid _ _ setoid {A} {B} = record { Carrier = A ⇒ B ; _≈_ = _≈_ ; isEquivalence = equiv } module Equiv {A B : Obj} = IsEquivalence (equiv {A} {B}) module EdgeReasoning {A B : Obj} = EqR (setoid {A} {B})
{ "alphanum_fraction": 0.6018306636, "avg_line_length": 28.1935483871, "ext": "agda", "hexsha": "3d262a18d164c441c2b1be348ecbf528128f7a4b", "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/Data/Quiver.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/Data/Quiver.agda", "max_line_length": 79, "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/Data/Quiver.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": 316, "size": 874 }
------------------------------------------------------------------------ -- Some definitions related to Dec ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Dec where open import Logical-equivalence hiding (_∘_) open import Prelude private variable a : Level A B : Type a -- A map function for Dec. Dec-map : A ⇔ B → Dec A → Dec B Dec-map A⇔B = ⊎-map to (_∘ from) where open _⇔_ A⇔B -- Dec preserves logical equivalences. Dec-preserves : A ⇔ B → Dec A ⇔ Dec B Dec-preserves A⇔B = record { to = Dec-map A⇔B ; from = Dec-map (inverse A⇔B) } -- If A and B are decided, then A × B is. Dec-× : Dec A → Dec B → Dec (A × B) Dec-× = [ (λ a → [ (λ b → yes (a , b)) , (λ ¬b → no (¬b ∘ proj₂)) ]) , (λ ¬a _ → no (¬a ∘ proj₁)) ] -- If A and B are decided, then A ⊎ B is. Dec-⊎ : Dec A → Dec B → Dec (A ⊎ B) Dec-⊎ = [ (λ a _ → yes (inj₁ a)) , (λ ¬a → [ (λ b → yes (inj₂ b)) , (λ ¬b → no [ ¬a , ¬b ]) ]) ]
{ "alphanum_fraction": 0.4337464252, "avg_line_length": 20.1730769231, "ext": "agda", "hexsha": "e483754c11e074ed242305b846b8d51dbc86eed0", "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/Dec.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/Dec.agda", "max_line_length": 72, "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/Dec.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": 360, "size": 1049 }
module System.Environment.Primitive where open import IO.Primitive open import Agda.Builtin.String open import Agda.Builtin.List open import Agda.Builtin.Unit import Foreign.Haskell as FFI open import System.FilePath.Posix postulate getArgs : IO (List String) getProgName : IO String getExecutablePath : IO AbsolutePath lookupEnv : String → IO (FFI.Maybe String) setEnv : String → String → IO ⊤ unsetEnv : String → IO ⊤ withArgs : ∀ {a} {A : Set a} → List String → IO A → IO A withProgName : ∀ {a} {A : Set a} → String → IO A → IO A getEnvironment : IO (List (FFI.Pair String String)) {-# FOREIGN GHC import qualified System.Environment as SE #-} {-# FOREIGN GHC import Data.Text #-} {-# FOREIGN GHC import Data.Function #-} {-# COMPILE GHC getArgs = fmap (fmap pack) SE.getArgs #-} {-# COMPILE GHC getProgName = fmap pack SE.getProgName #-} {-# COMPILE GHC getExecutablePath = SE.getExecutablePath #-} {-# COMPILE GHC lookupEnv = fmap (fmap pack) . SE.lookupEnv . unpack #-} {-# COMPILE GHC setEnv = SE.setEnv `on` unpack #-} {-# COMPILE GHC unsetEnv = SE.unsetEnv . unpack #-} {-# COMPILE GHC withArgs = \ _ _ -> SE.withArgs . fmap unpack #-} {-# COMPILE GHC withProgName = \ _ _ -> SE.withProgName . unpack #-} {-# COMPILE GHC getEnvironment = fmap (fmap (\ (a, b) -> (pack a, pack b))) SE.getEnvironment #-}
{ "alphanum_fraction": 0.4861849097, "avg_line_length": 52.2777777778, "ext": "agda", "hexsha": "4c09bc217f9244d7a2b0dd7ebdc7fb5db1247180", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_path": "data/github.com/gallais/agda-sizedIO/823d5a0a94a4b0c4bbaaac9b23997a6d94741885/src/System/Environment/Primitive.agda", "max_issues_count": 91, "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_path": "data/github.com/gallais/agda-sizedIO/823d5a0a94a4b0c4bbaaac9b23997a6d94741885/src/System/Environment/Primitive.agda", "max_line_length": 100, "max_stars_count": 9, "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_path": "data/github.com/gallais/agda-sizedIO/823d5a0a94a4b0c4bbaaac9b23997a6d94741885/src/System/Environment/Primitive.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z", "num_tokens": 391, "size": 1882 }
module bool-thms where open import bool open import eq open import sum open import empty open import level ~~-elim : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim tt = refl ~~-elim ff = refl &&-idem : ∀ {b} → b && b ≡ b &&-idem{tt} = refl &&-idem{ff} = refl ||-idem : ∀{b} → b || b ≡ b ||-idem{tt} = refl ||-idem{ff} = refl ||≡ff₁ : ∀ {b1 b2} → b1 || b2 ≡ ff → ff ≡ b1 ||≡ff₁ {ff} p = refl ||≡ff₁ {tt} p = sym p ||≡ff₂ : ∀ {b1 b2} → b1 || b2 ≡ ff → b2 ≡ ff ||≡ff₂ {tt} () ||≡ff₂ {ff}{tt} () ||≡ff₂ {ff}{ff} p = refl ||-tt : ∀ (b : 𝔹) → b || tt ≡ tt ||-tt tt = refl ||-tt ff = refl ||-cong₁ : ∀ {b1 b1' b2} → b1 ≡ b1' → b1 || b2 ≡ b1' || b2 ||-cong₁ refl = refl ||-cong₂ : ∀ {b1 b2 b2'} → b2 ≡ b2' → b1 || b2 ≡ b1 || b2' ||-cong₂ p rewrite p = refl ite-same : ∀{ℓ}{A : Set ℓ} → ∀(b : 𝔹) (x : A) → (if b then x else x) ≡ x ite-same tt x = refl ite-same ff x = refl ite-arg : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (f : A → B)(b : 𝔹)(x y : A) → (f (if b then x else y)) ≡ (if b then f x else f y) ite-arg f tt x y = refl ite-arg f ff x y = refl 𝔹-contra : ff ≡ tt → ∀{ℓ} {P : Set ℓ} → P 𝔹-contra () ||-split : ∀ {b b' : 𝔹} → b || b' ≡ tt → b ≡ tt ⊎ b' ≡ tt ||-split{tt}{tt} p = inj₁ refl ||-split{tt}{ff} p = inj₁ refl ||-split{ff}{tt} p = inj₂ refl ||-split{ff}{ff} () 𝔹-dec : ∀ (b : 𝔹) → b ≡ tt ⊎ b ≡ ff 𝔹-dec tt = inj₁ refl 𝔹-dec ff = inj₂ refl &&-snd : {p1 p2 : 𝔹} → p1 && p2 ≡ tt → p2 ≡ tt &&-snd{tt} p = p &&-snd{ff} () &&-fst : {p1 p2 : 𝔹} → p1 && p2 ≡ tt → p1 ≡ tt &&-fst{tt} p = refl &&-fst{ff} () &&-combo : {p1 p2 : 𝔹} → p1 ≡ tt → p2 ≡ tt → p1 && p2 ≡ tt &&-combo{tt} pr1 pr2 = pr2 &&-combo{ff} pr1 pr2 = 𝔹-contra pr1 &&-ff : ∀(b : 𝔹) → b && ff ≡ ff &&-ff tt = refl &&-ff ff = refl ff≡tt : ff ≡ tt → ⊥ {lzero} ff≡tt ()
{ "alphanum_fraction": 0.4633867277, "avg_line_length": 21.5802469136, "ext": "agda", "hexsha": "791c4f73e62f834cc67b882b1a8d1cc94065f9c9", "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": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "bool-thms.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "heades/AUGL", "max_issues_repo_path": "bool-thms.agda", "max_line_length": 124, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "bool-thms.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 913, "size": 1748 }
{-# OPTIONS --without-K #-} module Data.Bits.Count where open import Type hiding (★) open import Data.Two hiding (_==_) open import Data.Bits open import Data.Bits.OperationSyntax import Data.Bits.Search as Search open Search.SimpleSearch open import Data.Bits.Sum open import Data.Bool.Properties using (not-involutive) open import Data.Zero using (𝟘; 𝟘-elim) import Data.Fin as Fin open Fin using (Fin; zero; suc; #_; inject₁; inject+; raise) renaming (_+_ to _+ᶠ_) open import Data.Maybe.NP open import Data.Nat.NP hiding (_==_) open import Data.Nat.Properties import Data.Vec.NP as V open V hiding (rewire; rewireTbl; sum) renaming (map to vmap; swap to vswap) open import Data.Product using (_×_; _,_; uncurry; proj₁; proj₂) open import Function.NP import Relation.Binary.PropositionalEquality.NP as ≡ open ≡ #⟨_⟩ : ∀ {n} → (Bits n → 𝟚) → ℕ #⟨ pred ⟩ = sum (𝟚▹ℕ ∘ pred) -- #-ext #-≗ : ∀ {n} (f g : Bits n → 𝟚) → f ≗ g → #⟨ f ⟩ ≡ #⟨ g ⟩ #-≗ f g f≗g = sum-≗ (𝟚▹ℕ ∘ f) (𝟚▹ℕ ∘ g) (λ x → ≡.cong 𝟚▹ℕ (f≗g x)) #-comm : ∀ {n} (pad : Bits n) (f : Bits n → 𝟚) → #⟨ f ⟩ ≡ #⟨ f ∘ _⊕_ pad ⟩ #-comm pad f = sum-comm pad (𝟚▹ℕ ∘ f) #-bij : ∀ {n} f (g : Bits n → 𝟚) → #⟨ g ∘ eval f ⟩ ≡ #⟨ g ⟩ #-bij f g = sum-bij f (𝟚▹ℕ ∘ g) #-⊕ : ∀ {c} (bs : Bits c) (f : Bits c → 𝟚) → #⟨ f ⟩ ≡ #⟨ f ∘ _⊕_ bs ⟩ #-⊕ = #-comm #-const : ∀ n b → #⟨ (λ (_ : Bits n) → b) ⟩ ≡ ⟨2^ n * 𝟚▹ℕ b ⟩ #-const n b = sum-const n (𝟚▹ℕ b) #never≡0 : ∀ n → #⟨ never n ⟩ ≡ 0 #never≡0 = sum-const0≡0 #always≡2^_ : ∀ n → #⟨ always n ⟩ ≡ 2^ n #always≡2^ n = sum-const n 1 #-dist : ∀ {n} (f₀ f₁ : Bits n → 𝟚) → sum (λ x → 𝟚▹ℕ (f₀ x) + 𝟚▹ℕ (f₁ x)) ≡ #⟨ f₀ ⟩ + #⟨ f₁ ⟩ #-dist f₀ f₁ = sum-dist (𝟚▹ℕ ∘ f₀) (𝟚▹ℕ ∘ f₁) #-+ : ∀ {m n} (f : Bits (m + n) → 𝟚) → #⟨ f ⟩ ≡ sum {m} (λ xs → #⟨ (λ ys → f (xs ++ ys)) ⟩ ) #-+ {m} {n} f = sum-+ {m} {n} (𝟚▹ℕ ∘ f) #-# : ∀ {m n} (f : Bits (m + n) → 𝟚) → sum {m} (λ xs → #⟨ (λ ys → f (xs ++ ys)) ⟩) ≡ sum {n} (λ ys → #⟨ (λ (xs : Bits m) → f (xs ++ ys)) ⟩) #-# {m} {n} f = sum-sum {m} {n} (𝟚▹ℕ ∘ f) #-swap : ∀ {m n} (f : Bits (m + n) → 𝟚) → #⟨ f ∘ vswap n {m} ⟩ ≡ #⟨ f ⟩ #-swap {m} {n} f = sum-swap {m} {n} (𝟚▹ℕ ∘ f) #⟨==_⟩ : ∀ {n} (xs : Bits n) → #⟨ _==_ xs ⟩ ≡ 1 #⟨== [] ⟩ = refl #⟨==_⟩ {suc n} (true ∷ xs) rewrite #never≡0 n | #⟨== xs ⟩ = refl #⟨==_⟩ {suc n} (false ∷ xs) rewrite #never≡0 n | #⟨== xs ⟩ = refl ≗-cong-# : ∀ {n} (f g : Bits n → 𝟚) → f ≗ g → #⟨ f ⟩ ≡ #⟨ g ⟩ ≗-cong-# f g f≗g = sum-≗ _ _ (cong 𝟚▹ℕ ∘ f≗g) -- #-+ : ∀ {n a b} (f : Bits (suc n) → 𝟚) → #⟨ f ∘ 0∷_ ⟩ ≡ a → #⟨ f ∘ 1∷_ ⟩ ≡ b → #⟨ f ⟩ ≡ a + b -- #-+ f f0 f1 rewrite f0 | f1 = refl #-take-drop : ∀ m n (f : Bits m → 𝟚) (g : Bits n → 𝟚) → #⟨ (f ∘ take m) |∧| (g ∘ drop m) ⟩ ≡ #⟨ f ⟩ * #⟨ g ⟩ #-take-drop zero n f g with f [] ... | true rewrite ℕ°.+-comm #⟨ g ⟩ 0 = refl ... | false = #never≡0 n #-take-drop (suc m) n f g rewrite ≗-cong-# ((f ∘ take (suc m)) |∧| (g ∘ drop (suc m)) ∘ 0∷_) ((f ∘ 0∷_ ∘ take m) |∧| (g ∘ drop m)) (λ x → cong₂ (λ x y → f x ∧ g y) (take-∷ m 0' x) (drop-∷ m 0' x)) | #-take-drop m n (f ∘ 0∷_) g | ≗-cong-# ((f ∘ take (suc m)) |∧| (g ∘ drop (suc m)) ∘ 1∷_) ((f ∘ 1∷_ ∘ take m) |∧| (g ∘ drop m)) (λ x → cong₂ (λ x y → f x ∧ g y) (take-∷ m 1' x) (drop-∷ m 1' x)) | #-take-drop m n (f ∘ 1∷_) g = sym (proj₂ ℕ°.distrib #⟨ g ⟩ #⟨ f ∘ 0∷_ ⟩ #⟨ f ∘ 1∷_ ⟩) #-drop-take : ∀ m n (f : Bits n → 𝟚) (g : Bits m → 𝟚) → #⟨ (f ∘ drop m) |∧| (g ∘ take m) ⟩ ≡ #⟨ f ⟩ * #⟨ g ⟩ #-drop-take m n f g = #⟨ (f ∘ drop m) |∧| (g ∘ take m) ⟩ ≡⟨ ≗-cong-# ((f ∘ drop m) |∧| (g ∘ take m)) ((g ∘ take m) |∧| (f ∘ drop m)) (λ x → Bool°.+-comm (f (drop m x)) _) ⟩ #⟨ (g ∘ take m) |∧| (f ∘ drop m) ⟩ ≡⟨ #-take-drop m n g f ⟩ #⟨ g ⟩ * #⟨ f ⟩ ≡⟨ ℕ°.*-comm #⟨ g ⟩ _ ⟩ #⟨ f ⟩ * #⟨ g ⟩ ∎ where open ≡-Reasoning #-take : ∀ m n (f : Bits m → 𝟚) → #⟨ f ∘ take m {n} ⟩ ≡ 2^ n * #⟨ f ⟩ #-take m n f = #⟨ f ∘ take m {n} ⟩ ≡⟨ #-drop-take m n (always n) f ⟩ #⟨ always n ⟩ * #⟨ f ⟩ ≡⟨ cong (flip _*_ #⟨ f ⟩) (#always≡2^ n) ⟩ 2^ n * #⟨ f ⟩ ∎ where open ≡-Reasoning #-drop : ∀ m n (f : Bits m → 𝟚) → #⟨ f ∘ drop n ⟩ ≡ 2^ n * #⟨ f ⟩ #-drop m n f = #⟨ f ∘ drop n ⟩ ≡⟨ #-take-drop n m (always n) f ⟩ #⟨ always n ⟩ * #⟨ f ⟩ ≡⟨ cong (flip _*_ #⟨ f ⟩) (#always≡2^ n) ⟩ 2^ n * #⟨ f ⟩ ∎ where open ≡-Reasoning #⟨_==⟩ : ∀ {n} (xs : Bits n) → #⟨ flip _==_ xs ⟩ ≡ 1 #⟨ xs ==⟩ = trans (≗-cong-# (flip _==_ xs) (_==_ xs) (flip ==-comm xs)) #⟨== xs ⟩ #⇒ : ∀ {n} (f g : Bits n → 𝟚) → (∀ x → ✓ (f x) → ✓ (g x)) → #⟨ f ⟩ ≤ #⟨ g ⟩ #⇒ {zero} f g f⇒g with f [] | g [] | f⇒g [] ... | true | true | _ = s≤s z≤n ... | true | false | p = 𝟘-elim (p _) ... | false | _ | _ = z≤n #⇒ {suc n} f g f⇒g = #⇒ (f ∘ 0∷_) (g ∘ 0∷_) (f⇒g ∘ 0∷_) +-mono #⇒ (f ∘ 1∷_) (g ∘ 1∷_) (f⇒g ∘ 1∷_) #-∧-∨ᵇ : ∀ x y → 𝟚▹ℕ (x ∧ y) + 𝟚▹ℕ (x ∨ y) ≡ 𝟚▹ℕ x + 𝟚▹ℕ y #-∧-∨ᵇ true y rewrite ℕ°.+-comm (𝟚▹ℕ y) 1 = refl #-∧-∨ᵇ false y = refl #-LEM : ∀ {n} → (f g : Bits n → 𝟚) → #⟨ f ⟩ ≡ #⟨ g |∧| f ⟩ + #⟨ |not| g |∧| f ⟩ #-LEM {zero} f g with g [] ... | false = refl ... | true = ℕ°.+-comm 0 #⟨ f ⟩ #-LEM {suc n} f g rewrite #-LEM (f ∘ 0∷_) (g ∘ 0∷_) | #-LEM (f ∘ 1∷_) (g ∘ 1∷_) = +-interchange #⟨ (g ∘ 0∷_) |∧| (f ∘ 0∷_) ⟩ #⟨ |not| (g ∘ 0∷_) |∧| (f ∘ 0∷_) ⟩ #⟨ (g ∘ 1∷_) |∧| (f ∘ 1∷_) ⟩ #⟨ |not| (g ∘ 1∷_) |∧| (f ∘ 1∷_) ⟩ #-∧-snd : ∀ {n} (f g : Bits n → 𝟚) → #⟨ f |∧| g ⟩ ≤ #⟨ g ⟩ #-∧-snd {zero} f g with f [] | g [] ... | false | false = z≤n ... | false | true = z≤n ... | true | _ = ℕ≤.reflexive refl #-∧-snd {suc n} f g = #-∧-snd (f ∘ 0∷_) (g ∘ 0∷_) +-mono #-∧-snd (f ∘ 1∷_) (g ∘ 1∷_) #-∧-fst : ∀ {n} (f g : Bits n → 𝟚) → #⟨ f |∧| g ⟩ ≤ #⟨ f ⟩ #-∧-fst f g = #⟨ f |∧| g ⟩ ≡⟨ #-≗ (f |∧| g) (g |∧| f) (|∧|-comm f g) ⟩ #⟨ g |∧| f ⟩ ≤⟨ #-∧-snd g f ⟩ #⟨ f ⟩ ∎ where open ≤-Reasoning #-∧-∨ : ∀ {n} (f g : Bits n → 𝟚) → #⟨ f |∧| g ⟩ + #⟨ f |∨| g ⟩ ≡ #⟨ f ⟩ + #⟨ g ⟩ #-∧-∨ {zero} f g = #-∧-∨ᵇ (f []) (g []) #-∧-∨ {suc n} f g = trans (trans (helper #⟨ (f ∘ 0∷_) |∧| (g ∘ 0∷_) ⟩ #⟨ (f ∘ 1∷_) |∧| (g ∘ 1∷_) ⟩ #⟨ (f ∘ 0∷_) |∨| (g ∘ 0∷_) ⟩ #⟨ (f ∘ 1∷_) |∨| (g ∘ 1∷_) ⟩) (cong₂ _+_ (#-∧-∨ (f ∘ 0∷_) (g ∘ 0∷_)) (#-∧-∨ (f ∘ 1∷_) (g ∘ 1∷_)))) (helper #⟨ f ∘ 0∷_ ⟩ #⟨ g ∘ 0∷_ ⟩ #⟨ f ∘ 1∷_ ⟩ #⟨ g ∘ 1∷_ ⟩) where open SemiringSolver helper : ∀ x y z t → x + y + (z + t) ≡ x + z + (y + t) helper = solve 4 (λ x y z t → x :+ y :+ (z :+ t) := x :+ z :+ (y :+ t)) refl #∨' : ∀ {n} (f g : Bits n → 𝟚) → #⟨ f |∨| g ⟩ ≤ #⟨ f ⟩ + #⟨ g ⟩ #∨' {zero} f g with f [] ... | true = s≤s z≤n ... | false = ℕ≤.refl #∨' {suc _} f g = ℕ≤.trans (#∨' (f ∘ 0∷_) (g ∘ 0∷_) +-mono #∨' (f ∘ 1∷_) (g ∘ 1∷_)) (ℕ≤.reflexive (helper #⟨ f ∘ 0∷_ ⟩ #⟨ g ∘ 0∷_ ⟩ #⟨ f ∘ 1∷_ ⟩ #⟨ g ∘ 1∷_ ⟩)) where open SemiringSolver helper : ∀ x y z t → x + y + (z + t) ≡ x + z + (y + t) helper = solve 4 (λ x y z t → x :+ y :+ (z :+ t) := x :+ z :+ (y :+ t)) refl #∨ : ∀ {m n o} {f g : Bits o → 𝟚} → #⟨ f ⟩ ≤ m → #⟨ g ⟩ ≤ n → #⟨ f |∨| g ⟩ ≤ (m + n) #∨ {m} {n} {o} {f} {g} pf pg = ℕ≤.trans (#∨' f g) (pf +-mono pg) #∧ : ∀ {m n o} {f g : Bits o → 𝟚} → #⟨ f ⟩ ≤ m → #⟨ g ⟩ ≤ n → #⟨ f |∧| g ⟩ ≤ (m + n) #∧ {f = f} {g} pf pg = ℕ≤.trans (#⇒ (f |∧| g) (f |∨| g) (λ x → ∧⇒∨ (f x) (g x))) (#∨ {f = f} pf pg) #-bound : ∀ c (f : Bits c → 𝟚) → #⟨ f ⟩ ≤ 2^ c #-bound zero f = 𝟚≤1 (f []) #-bound (suc c) f = #-bound c (f ∘ 0∷_) +-mono #-bound c (f ∘ 1∷_) #-∘vnot : ∀ c (f : Bits c → 𝟚) → #⟨ f ⟩ ≡ #⟨ f ∘ vnot ⟩ #-∘vnot _ f = #-⊕ 1ⁿ f #-∘xorᵢ : ∀ {c} (i : Fin c) (f : Bits c → 𝟚) b → #⟨ f ⟩ ≡ #⟨ f ∘ onᵢ (_xor_ b) i ⟩ #-∘xorᵢ i f b = pf where pad = onᵢ (_xor_ b) i 0ⁿ pf : #⟨ f ⟩ ≡ #⟨ f ∘ onᵢ (_xor_ b) i ⟩ pf rewrite #-⊕ pad f = ≗-cong-# (f ∘ _⊕_ pad) (f ∘ onᵢ (_xor_ b) i) (cong (_$_ f) ∘ sym ∘ onᵢ-xor-⊕ b i) #-∘notᵢ : ∀ {c} (i : Fin c) (f : Bits c → 𝟚) → #⟨ f ⟩ ≡ #⟨ f ∘ notᵢ i ⟩ #-∘notᵢ i f = #-∘xorᵢ i f true #-not∘ : ∀ c (f : Bits c → 𝟚) → #⟨ f ⟩ ≡ 2^ c ∸ #⟨ not ∘ f ⟩ #-not∘ zero f with f [] ... | true = ≡.refl ... | false = ≡.refl #-not∘ (suc c) f rewrite #-not∘ c (f ∘ 0∷_) | #-not∘ c (f ∘ 1∷_) = factor-+-∸ (#-bound c (not ∘ f ∘ 0∷_)) (#-bound c (not ∘ f ∘ 1∷_)) #-not∘′ : ∀ c (f : Bits c → 𝟚) → #⟨ not ∘ f ⟩ ≡ 2^ c ∸ #⟨ f ⟩ #-not∘′ c f = #⟨ not ∘ f ⟩ ≡⟨ #-not∘ c (not ∘ f) ⟩ 2^ c ∸ #⟨ not ∘ not ∘ f ⟩ ≡⟨ ≡.cong (λ g → 2^ c ∸ g) (≗-cong-# (not ∘ not ∘ f) f (not-involutive ∘ f)) ⟩ 2^ c ∸ #⟨ f ⟩ ∎ where open ≡-Reasoning difference-lemma : ∀ {n}(A B F : Bits n → 𝟚) → #⟨ |not| F |∧| A ⟩ ≡ #⟨ |not| F |∧| B ⟩ → dist #⟨ A ⟩ #⟨ B ⟩ ≤ #⟨ F ⟩ difference-lemma A B F A∧¬F≡B∧¬F = dist #⟨ A ⟩ #⟨ B ⟩ ≡⟨ cong₂ dist (#-LEM A F) (#-LEM B F) ⟩ dist (#⟨ F |∧| A ⟩ + #⟨ |not| F |∧| A ⟩) (#⟨ F |∧| B ⟩ + #⟨ |not| F |∧| B ⟩) ≡⟨ cong₂ dist (ℕ°.+-comm #⟨ F |∧| A ⟩ #⟨ |not| F |∧| A ⟩) (ℕ°.+-comm #⟨ F |∧| B ⟩ #⟨ |not| F |∧| B ⟩) ⟩ dist (#⟨ |not| F |∧| A ⟩ + #⟨ F |∧| A ⟩) (#⟨ |not| F |∧| B ⟩ + #⟨ F |∧| B ⟩) ≡⟨ cong₂ dist (refl {x = #⟨ |not| F |∧| A ⟩ + #⟨ F |∧| A ⟩}) (cong₂ _+_ (sym A∧¬F≡B∧¬F) (refl {x = #⟨ F |∧| B ⟩})) ⟩ dist (#⟨ |not| F |∧| A ⟩ + #⟨ F |∧| A ⟩) (#⟨ |not| F |∧| A ⟩ + #⟨ F |∧| B ⟩) ≡⟨ dist-x+ #⟨ |not| F |∧| A ⟩ #⟨ F |∧| A ⟩ #⟨ F |∧| B ⟩ ⟩ dist #⟨ F |∧| A ⟩ #⟨ F |∧| B ⟩ ≤⟨ dist-bounded {#⟨ F |∧| A ⟩} {#⟨ F |∧| B ⟩} {#⟨ F ⟩} (#-∧-fst F A) (#-∧-fst F B) ⟩ #⟨ F ⟩ ∎ where open ≤-Reasoning #⟨_⟩ᶠ : ∀ {n} → (Bits n → 𝟚) → Fin (suc (2^ n)) #⟨ pred ⟩ᶠ = countᶠ pred (allBits _) #⟨⟩-spec : ∀ {n} (pred : Bits n → 𝟚) → #⟨ pred ⟩ ≡ Fin.toℕ #⟨ pred ⟩ᶠ #⟨⟩-spec {zero} pred with pred [] ... | true = refl ... | false = refl #⟨⟩-spec {suc n} pred rewrite count-++ pred (vmap 0∷_ (allBits n)) (vmap 1∷_ (allBits n)) | #⟨⟩-spec {n} (pred ∘ 0∷_) | #⟨⟩-spec {n} (pred ∘ 1∷_) | count-∘ 0∷_ pred (allBits n) | count-∘ 1∷_ pred (allBits n) = refl ext-# : ∀ {c} {f g : Bits c → 𝟚} → f ≗ g → #⟨ f ⟩ᶠ ≡ #⟨ g ⟩ᶠ ext-# f≗g = ext-countᶠ f≗g (allBits _) find? : ∀ {n a} {A : ★ a} → (Bits n →? A) →? A find? = search (M?._∣_ _) findKey : ∀ {n} → (Bits n → 𝟚) →? Bits n findKey pred = find? (λ x → if pred x then just x else nothing) -- -} -- -} -- -} -- -}
{ "alphanum_fraction": 0.3634860869, "avg_line_length": 37.4192439863, "ext": "agda", "hexsha": "6e45b66e9243de1e60204de5b49129a2b8af9c4e", "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": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/Experimental/DataBitsCount.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/Experimental/DataBitsCount.agda", "max_line_length": 127, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/Experimental/DataBitsCount.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 6107, "size": 10889 }
module Pi.Interp where open import Data.Unit open import Data.Product open import Data.Sum open import Pi.Syntax open import Pi.Opsem -- Big-step intepreter interp : {A B : 𝕌} → (A ↔ B) → ⟦ A ⟧ → ⟦ B ⟧ interp unite₊l (inj₂ v) = v interp uniti₊l v = inj₂ v interp swap₊ (inj₁ v) = inj₂ v interp swap₊ (inj₂ v) = inj₁ v interp assocl₊ (inj₁ v) = inj₁ (inj₁ v) interp assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v) interp assocl₊ (inj₂ (inj₂ v)) = inj₂ v interp assocr₊ (inj₁ (inj₁ v)) = inj₁ v interp assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v) interp assocr₊ (inj₂ v) = inj₂ (inj₂ v) interp unite⋆l (tt , v) = v interp uniti⋆l v = (tt , v) interp swap⋆ (v₁ , v₂) = (v₂ , v₁) interp assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃) interp assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃)) interp dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃) interp dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃) interp factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃) interp factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃) interp id↔ v = v interp (c₁ ⨾ c₂) v = interp c₂ (interp c₁ v) interp (c₁ ⊕ c₂) (inj₁ v) = inj₁ (interp c₁ v) interp (c₁ ⊕ c₂) (inj₂ v) = inj₂ (interp c₂ v) interp (c₁ ⊗ c₂) (v₁ , v₂) = (interp c₁ v₁ , interp c₂ v₂)
{ "alphanum_fraction": 0.5530596437, "avg_line_length": 37.9705882353, "ext": "agda", "hexsha": "cd01ed8b4c247271599119e5628b8f3929044ee0", "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": "Pi/Interp.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": "Pi/Interp.agda", "max_line_length": 58, "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": "Pi/Interp.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": 593, "size": 1291 }
module Oscar.Data.Unit where open import Agda.Builtin.Unit public using (⊤; tt)
{ "alphanum_fraction": 0.756097561, "avg_line_length": 16.4, "ext": "agda", "hexsha": "89b65bc77c16e19506c0ab8cb639a314339819cc", "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-2/Oscar/Data/Unit.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-2/Oscar/Data/Unit.agda", "max_line_length": 50, "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-2/Oscar/Data/Unit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 23, "size": 82 }
{-# OPTIONS --without-K #-} module hott.loop.core where open import sum open import equality open import function.core open import function.isomorphism.core open import function.overloading open import pointed.core open import sets.nat.core Ω₁ : ∀ {i} → PSet i → PSet i Ω₁ (X , x) = ((x ≡ x) , refl) ΩP : ∀ {i} → ℕ → PSet i → PSet _ ΩP 0 𝓧 = 𝓧 ΩP (suc n) 𝓧 = ΩP n (Ω₁ 𝓧) Ω : ∀ {i} → ℕ → {X : Set i} → X → Set i Ω n {X} x = proj₁ (ΩP n (X , x)) refl' : ∀ {i} n {X : Set i}(x : X) → Ω n x refl' n {X} x = proj₂ (ΩP n (X , x)) mapΩ₁ : ∀ {i j} → {𝓧 : PSet i}{𝓨 : PSet j} → PMap 𝓧 𝓨 → PMap (Ω₁ 𝓧) (Ω₁ 𝓨) mapΩ₁ (f , refl) = ap f , refl mapΩP : ∀ {i j} n → {𝓧 : PSet i}{𝓨 : PSet j} → PMap 𝓧 𝓨 → PMap (ΩP n 𝓧) (ΩP n 𝓨) mapΩP zero f = f mapΩP (suc n) f = mapΩP n (mapΩ₁ f) mapΩ : ∀ {i j} n → {X : Set i}{Y : Set j}(f : X → Y) → {x : X} → Ω n x → Ω n (f x) mapΩ n f = proj₁ (mapΩP n (f , refl)) constP : ∀ {i j} (𝓧 : PSet i)(𝓨 : PSet j) → PMap 𝓧 𝓨 constP _ (Y , y) = (λ _ → y) , refl
{ "alphanum_fraction": 0.526, "avg_line_length": 24.3902439024, "ext": "agda", "hexsha": "d2b6da2a63ec0f08c1665192e6101e35b3ef50f9", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/hott/loop/core.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/hott/loop/core.agda", "max_line_length": 52, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/hott/loop/core.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": 513, "size": 1000 }
{-# OPTIONS --without-K --rewriting --exact-split #-} open import lib.Basics open import lib.types.PushoutFmap open import lib.types.Span open import lib.types.Coproduct open import lib.types.Paths open import Graphs.Definition open import Coequalizers.Definition open import Util.Coproducts {- We show that given equivalences E ≃ E' and V ≃ V' that commute with endpoint maps we get an equivalence between coequalizers V / E ≃ V' / E'. This could have been derived from the corresponding result for pushouts in the HoTT-Agda library, but for reference we give the proof using univalence appearing in the paper. -} module Coequalizers.PreserveEquivalence where Coeq-preserves-= : {i j : ULevel} (V : Type i) (E : Type j) (π₀ π₁ : E → V) (V' : Type i) (E' : Type j) (π₀' π₁' : E' → V') (eV : V == V') (eE : E == E') (comm₀ : coe eV ∘ π₀ == π₀' ∘ coe eE ) (comm₁ : coe eV ∘ π₁ == π₁' ∘ coe eE) → (Coeq (graph π₀ π₁) ≃ Coeq (graph π₀' π₁')) Coeq-preserves-= V E π₀ π₁ .V .E .(λ x → π₀ x) .(λ x → π₁ x) idp idp idp idp = ide _ {- The easiest version of the lemma assumes that V has the same universe level as V' and E has the same universe level as E'. -} Coeq-emap-same-level : {i j : ULevel} {V : Type i} {E : Type j} ⦃ gph : Graph E V ⦄ {V' : Type i} {E' : Type j} ⦃ gph' : Graph E' V' ⦄ (eV : V ≃ V') (eE : E ≃ E') (comm₀ : –> eV ∘ π₀ ∼ π₀ ∘ –> eE ) (comm₁ : –> eV ∘ π₁ ∼ π₁ ∘ –> eE ) → (Coeq gph ≃ Coeq gph') Coeq-emap-same-level eV eE comm₀ comm₁ = Coeq-preserves-= _ _ π₀ π₁ _ _ π₀ π₁ (ua eV) (ua eE) (λ= (λ e → coe-β eV _ ∙ comm₀ e ∙ ap π₀ (! (coe-β eE e)))) (λ= (λ e → coe-β eV _ ∙ comm₁ e ∙ ap π₁ (! (coe-β eE e)))) {- We now deal with the case where all the types can have different universe levels. We first show that every coequalizer is equivalent to its lift to higher universe levels. -} module LiftGraph {i j : ULevel} (V : Type i) (E : Type j) ⦃ gph : Graph E V ⦄ (i' j' : ULevel) where instance lift-graph : Graph (Lift {j = j'} E) (Lift {j = i'} V) lift-graph = graph (λ { (lift e) → lift (π₀ e)}) λ { (lift e) → lift (π₁ e)} Coeq-Lift-≃ : Coeq gph ≃ Coeq (lift-graph) Coeq-Lift-≃ = equiv f g f-g g-f where f : V / E → (Lift V) / (Lift E) f = Coeq-rec (c[_] ∘ lift) (λ e → quot (lift e)) g : (Lift V) / (Lift E) → V / E g = Coeq-rec (λ {(lift v) → c[ v ]}) (λ {(lift e) → quot e}) g-f : (z : V / E) → (g (f z) == z) g-f = Coeq-elim _ (λ v → idp) (λ e → ↓-app=idf-in (! (p e))) where p : (e : E) → ap (g ∘ f) (quot e) ∙ idp == idp ∙' (quot e) p e = ap (g ∘ f) (quot e) ∙ idp =⟨ ∙-unit-r _ ⟩ ap (g ∘ f) (quot e) =⟨ ap-∘ g f (quot e) ⟩ ap g (ap f (quot e)) =⟨ ap (ap g) (Coeq-rec-β= _ _ e) ⟩ ap g (quot (lift e)) =⟨ Coeq-rec-β= _ _ (lift e) ⟩ quot e =⟨ ! (∙'-unit-l _) ⟩ idp ∙' (quot e) =∎ f-g : (z : (Lift V) / (Lift E)) → (f (g z) == z) f-g = Coeq-elim _ (λ v → idp) (λ {(lift e) → ↓-app=idf-in (! (p e))}) where p : (e : E) → ap (f ∘ g) (quot (lift e)) ∙ idp == idp ∙' quot (lift e) p e = ap (f ∘ g) (quot (lift e)) ∙ idp =⟨ ∙-unit-r _ ⟩ ap (f ∘ g) (quot (lift e)) =⟨ ap-∘ f g _ ⟩ ap f (ap g (quot (lift e))) =⟨ ap (ap f) (Coeq-rec-β= _ _ _) ⟩ ap f (quot e) =⟨ Coeq-rec-β= _ _ _ ⟩ quot (lift e) =⟨ ! (∙'-unit-l _) ⟩ idp ∙' quot (lift e) =∎ {- We can now derive that coequalizers preserve equivalences where the types can have different universe levels. -} Coeq-emap : {i j i' j' : ULevel} {V : Type i} {E : Type j} ⦃ gph : Graph E V ⦄ {V' : Type i'} {E' : Type j'} ⦃ gph' : Graph E' V' ⦄ → (eV : V ≃ V') (eE : E ≃ E') (comm₀ : –> eV ∘ π₀ ∼ π₀ ∘ –> eE ) (comm₁ : –> eV ∘ π₁ ∼ π₁ ∘ –> eE ) → (Coeq gph ≃ Coeq gph') Coeq-emap {i} {j} {i'} {j'} {V} {E} ⦃ gph ⦄ {V'} {E'} ⦃ gph' ⦄ eV eE comm₀ comm₁ = V / E ≃⟨ LEV.Coeq-Lift-≃ ⟩ Lift V / Lift E ≃⟨ Coeq-emap-same-level (lower-equiv ⁻¹ ∘e eV ∘e lower-equiv) (lower-equiv ⁻¹ ∘e eE ∘e lower-equiv) (λ {(lift e) → ap lift (comm₀ e)}) (λ {(lift e) → ap lift (comm₁ e)}) ⟩ Lift V' / Lift E' ≃⟨ LEV'.Coeq-Lift-≃ ⁻¹ ⟩ V' / E' ≃∎ where module LEV = LiftGraph V E i' j' module LEV' = LiftGraph V' E' i j
{ "alphanum_fraction": 0.4912739965, "avg_line_length": 38.8474576271, "ext": "agda", "hexsha": "9f9bdfc7e02eab2cb5456d30751fdea18c37ff15", "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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "awswan/nielsenschreier-hott", "max_forks_repo_path": "main/Coequalizers/PreserveEquivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "awswan/nielsenschreier-hott", "max_issues_repo_path": "main/Coequalizers/PreserveEquivalence.agda", "max_line_length": 110, "max_stars_count": null, "max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "awswan/nielsenschreier-hott", "max_stars_repo_path": "main/Coequalizers/PreserveEquivalence.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1866, "size": 4584 }
{- Normalize Integer Matrices -} {-# OPTIONS --safe #-} module Cubical.Experiments.IntegerMatrix where open import Cubical.Foundations.Prelude open import Cubical.Data.Nat open import Cubical.Data.Int open import Cubical.Data.FinData open import Cubical.Data.List open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤ to ℤRing) open import Cubical.Algebra.Matrix open import Cubical.Algebra.Matrix.CommRingCoefficient open import Cubical.Algebra.IntegerMatrix.Smith open import Cubical.Algebra.IntegerMatrix.Diagonalization private variable m n : ℕ open Coefficient ℤRing -- Get divisors directly open isSmithNormal open Smith open isDiagonal open Diag getElemDiv : Mat m n → List ℤ getElemDiv M = smith M .isnormal .divs .fst getDiagDiv : Mat m n → List ℤ getDiagDiv M = diagonalize M .isdiag .divs .fst -- Constructing matrices makeMat2×2 : ℤ → ℤ → ℤ → ℤ → Mat 2 2 makeMat2×2 a00 _ _ _ zero zero = a00 makeMat2×2 _ a01 _ _ zero one = a01 makeMat2×2 _ _ a10 _ one zero = a10 makeMat2×2 _ _ _ a11 one one = a11 makeMat3×3 : ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → Mat 3 3 makeMat3×3 a00 _ _ _ _ _ _ _ _ zero zero = a00 makeMat3×3 _ a01 _ _ _ _ _ _ _ zero one = a01 makeMat3×3 _ _ a02 _ _ _ _ _ _ zero two = a02 makeMat3×3 _ _ _ a10 _ _ _ _ _ one zero = a10 makeMat3×3 _ _ _ _ a11 _ _ _ _ one one = a11 makeMat3×3 _ _ _ _ _ a12 _ _ _ one two = a12 makeMat3×3 _ _ _ _ _ _ a20 _ _ two zero = a20 makeMat3×3 _ _ _ _ _ _ _ a21 _ two one = a21 makeMat3×3 _ _ _ _ _ _ _ _ a22 two two = a22 -- The Tests -- One can add flag "-vprofile.interactive:10" to this file, -- then C-c C-n to run these tests and also get the time. -- It turns out that, "smith" is much slower than "diagonalize" -- and it doesn't work even for simple 3×3-matrices. -- The "diagonalize" works only for very simple 3×3-matrices. -- One subtle point is, if one only do one-step in Smith normalization -- and simply add the time cost in each steps, -- the result is far less than running the whole function "smith". -- So the recursive procedure slows down the procedure -- for some reasons I don't fully understand. -- Also, the performance of "smith" is very bad at certain trivial cases, -- much worse than some non-trivial cases. mat1 = makeMat2×2 1 0 0 1 -- Time: 528ms test1 = getElemDiv mat1 -- Time: 51ms test1' = getDiagDiv mat1 mat2 = makeMat2×2 2 0 0 1 -- Time: 89,437ms -- Why so slow? test2 = getElemDiv mat2 -- Time: 51ms test2' = getDiagDiv mat2 mat3 = makeMat2×2 2 1 3 5 -- Time: 3,308ms test3 = getElemDiv mat3 -- Time: 1,887ms test3' = getDiagDiv mat3 mat4 = makeMat2×2 4 2 2 4 -- Time: 3,284ms test4 = getElemDiv mat4 -- Time: 1,942ms test4' = getDiagDiv mat4 mat5 = makeMat3×3 1 0 0 0 0 0 0 0 0 -- Time: 9,400ms test5 = getElemDiv mat5 -- Time: 337ms test5' = getDiagDiv mat5 mat6 = makeMat3×3 1 0 0 0 1 0 0 0 1 -- Time: ??? -- It doesn't work out already. test6 = getElemDiv mat6 -- Time: 8,598ms test6' = getDiagDiv mat6 mat7 = makeMat3×3 1 1 0 3 2 1 2 0 1 -- Time: ??? test7 = getElemDiv mat7 -- Time: 14,149ms test7' = getDiagDiv mat7 mat8 = makeMat3×3 2 3 1 2 2 3 1 1 0 -- Time: ??? test8 = getElemDiv mat8 -- Time: ??? -- Not working either. test8' = getDiagDiv mat8
{ "alphanum_fraction": 0.6816960287, "avg_line_length": 22.3266666667, "ext": "agda", "hexsha": "2331b6e54529447e807efcc1cd97f23d2cd80ae7", "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/Experiments/IntegerMatrix.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/Experiments/IntegerMatrix.agda", "max_line_length": 73, "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/Experiments/IntegerMatrix.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": 1308, "size": 3349 }
------------------------------------------------------------------------ -- Some properties related to the const function ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Const {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open import Logical-equivalence using (_⇔_) open import Prelude import Bijection eq as Bijection open Derived-definitions-and-properties eq open import Embedding eq open import Equivalence eq as Eq using (_≃_) open import Fin eq open import Function-universe eq open import H-level eq open import H-level.Closure eq open import Injection eq using (Injective) import Nat eq as Nat open import Univalence-axiom eq -- If A is inhabited, then the function const : B → (A → B) is -- injective. const-is-injective : ∀ {a b} → {A : Type a} {B : Type b} → A → Injective {B = A → B} const const-is-injective x {y} {z} = const y ≡ const z ↝⟨ cong (_$ x) ⟩□ y ≡ z □ -- Thus, if B is a set, then const is also an embedding (assuming -- extensionality). const-is-embedding : ∀ {a b} → Extensionality (a ⊔ b) (a ⊔ b) → {A : Type a} {B : Type b} → Is-set B → A → Is-embedding {B = A → B} const const-is-embedding {a} {b} ext B-set x = _≃_.to (Injective≃Is-embedding ext B-set (Π-closure (lower-extensionality b a ext) 2 λ _ → B-set) const) (const-is-injective x) -- However, if B is not a set, then one can construct a counterexample -- (assuming extensionality and univalence). -- -- This example is due to Thierry Coquand. (His proof was not -- identical to the one below.) const-is-not-embedding : ∀ {a b} → Extensionality (a ⊔ b) (lsuc b) → Univalence b → Univalence (# 0) → ¬ ({A : Type a} {B : Type (lsuc b)} → A → Is-embedding {B = A → B} const) const-is-not-embedding {a} {b} ext univ univ₀ hyp = from-⊎ (2 Nat.≟ 4) 2≡4 where ext-b : Extensionality b b ext-b = lower-extensionality a (lsuc b) ext ext-ab₊ : Extensionality a (lsuc b) ext-ab₊ = lower-extensionality b lzero ext ext₁ : Extensionality (# 0) (# 1) ext₁ = lower-extensionality _ (lsuc b) ext ext₀ : Extensionality (# 0) (# 0) ext₀ = lower-extensionality _ _ ext emb : Is-embedding {B = ↑ a (Fin 2) → Type b} const emb = hyp (lift true) 2≡4 : 2 ≡ 4 2≡4 = _⇔_.to isomorphic-same-size ( Fin 2 ↝⟨ inverse $ [Fin≡Fin]↔Fin! ext₀ univ₀ 2 ⟩ Fin 2 ≡ Fin 2 ↔⟨ inverse $ ≡-preserves-≃ ext-b univ univ₀ (Eq.↔⇒≃ Bijection.↑↔) (Eq.↔⇒≃ Bijection.↑↔) ⟩ ↑ b (Fin 2) ≡ ↑ b (Fin 2) ↔⟨ Eq.⟨ _ , emb (↑ b (Fin 2)) (↑ b (Fin 2)) ⟩ ⟩ const (↑ b (Fin 2)) ≡ const (↑ b (Fin 2)) ↔⟨ inverse $ Eq.extensionality-isomorphism ext-ab₊ ⟩ (↑ a (Fin 2) → ↑ b (Fin 2) ≡ ↑ b (Fin 2)) ↔⟨ →-cong ext-ab₊ (Eq.↔⇒≃ Bijection.↑↔) (≡-preserves-≃ ext-b univ univ₀ (Eq.↔⇒≃ Bijection.↑↔) (Eq.↔⇒≃ Bijection.↑↔)) ⟩ (Fin 2 → Fin 2 ≡ Fin 2) ↝⟨ ∀-cong ext₁ (λ _ → [Fin≡Fin]↔Fin! ext₀ univ₀ 2) ⟩ (Fin 2 → Fin 2) ↝⟨ [Fin→Fin]↔Fin^ ext₀ 2 2 ⟩□ Fin 4 □)
{ "alphanum_fraction": 0.5371498173, "avg_line_length": 33.8556701031, "ext": "agda", "hexsha": "4a7b5dfce4c7b1560fd21ec55ad7b002c11bde29", "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/Const.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/Const.agda", "max_line_length": 136, "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/Const.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": 1158, "size": 3284 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of membership of vectors based on propositional equality. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Membership.Propositional.Properties where open import Data.Fin.Base using (Fin; zero; suc) open import Data.Product as Prod using (_,_; ∃; _×_; -,_) open import Data.Vec hiding (here; there) open import Data.Vec.Relation.Unary.Any using (here; there) open import Data.List.Base using ([]; _∷_) open import Data.List.Relation.Unary.Any using (here; there) open import Data.Vec.Relation.Unary.Any using (Any; here; there) open import Data.Vec.Membership.Propositional open import Data.List.Membership.Propositional using () renaming (_∈_ to _∈ₗ_) open import Level using (Level) open import Function using (_∘_; id) open import Relation.Unary using (Pred) open import Relation.Binary.PropositionalEquality using (refl) private variable a b p : Level A : Set a B : Set b ------------------------------------------------------------------------ -- lookup ∈-lookup : ∀ {n} i (xs : Vec A n) → lookup xs i ∈ xs ∈-lookup zero (x ∷ xs) = here refl ∈-lookup (suc i) (x ∷ xs) = there (∈-lookup i xs) ------------------------------------------------------------------------ -- map ∈-map⁺ : (f : A → B) → ∀ {m v} {xs : Vec A m} → v ∈ xs → f v ∈ map f xs ∈-map⁺ f (here refl) = here refl ∈-map⁺ f (there x∈xs) = there (∈-map⁺ f x∈xs) ------------------------------------------------------------------------ -- _++_ ∈-++⁺ˡ : ∀ {m n v} {xs : Vec A m} {ys : Vec A n} → v ∈ xs → v ∈ xs ++ ys ∈-++⁺ˡ (here refl) = here refl ∈-++⁺ˡ (there x∈xs) = there (∈-++⁺ˡ x∈xs) ∈-++⁺ʳ : ∀ {m n v} (xs : Vec A m) {ys : Vec A n} → v ∈ ys → v ∈ xs ++ ys ∈-++⁺ʳ [] x∈ys = x∈ys ∈-++⁺ʳ (x ∷ xs) x∈ys = there (∈-++⁺ʳ xs x∈ys) ------------------------------------------------------------------------ -- tabulate ∈-tabulate⁺ : ∀ {n} (f : Fin n → A) i → f i ∈ tabulate f ∈-tabulate⁺ f zero = here refl ∈-tabulate⁺ f (suc i) = there (∈-tabulate⁺ (f ∘ suc) i) ------------------------------------------------------------------------ -- allFin ∈-allFin⁺ : ∀ {n} (i : Fin n) → i ∈ allFin n ∈-allFin⁺ = ∈-tabulate⁺ id ------------------------------------------------------------------------ -- allPairs ∈-allPairs⁺ : ∀ {m n x y} {xs : Vec A m} {ys : Vec B n} → x ∈ xs → y ∈ ys → (x , y) ∈ allPairs xs ys ∈-allPairs⁺ {xs = x ∷ xs} (here refl) = ∈-++⁺ˡ ∘ ∈-map⁺ (x ,_) ∈-allPairs⁺ {xs = x ∷ _} (there x∈xs) = ∈-++⁺ʳ (map (x ,_) _) ∘ ∈-allPairs⁺ x∈xs ------------------------------------------------------------------------ -- toList ∈-toList⁺ : ∀ {n} {v : A} {xs : Vec A n} → v ∈ xs → v ∈ₗ toList xs ∈-toList⁺ (here refl) = here refl ∈-toList⁺ (there x∈) = there (∈-toList⁺ x∈) ∈-toList⁻ : ∀ {n} {v : A} {xs : Vec A n} → v ∈ₗ toList xs → v ∈ xs ∈-toList⁻ {xs = x ∷ xs} (here refl) = here refl ∈-toList⁻ {xs = x ∷ xs} (there v∈xs) = there (∈-toList⁻ v∈xs) ------------------------------------------------------------------------ -- fromList ∈-fromList⁺ : ∀ {v : A} {xs} → v ∈ₗ xs → v ∈ fromList xs ∈-fromList⁺ (here refl) = here refl ∈-fromList⁺ (there x∈) = there (∈-fromList⁺ x∈) ∈-fromList⁻ : ∀ {v : A} {xs} → v ∈ fromList xs → v ∈ₗ xs ∈-fromList⁻ {xs = _ ∷ _} (here refl) = here refl ∈-fromList⁻ {xs = _ ∷ _} (there v∈xs) = there (∈-fromList⁻ v∈xs) ------------------------------------------------------------------------ -- Relationship to Any module _ {P : Pred A p} where fromAny : ∀ {n} {xs : Vec A n} → Any P xs → ∃ λ x → x ∈ xs × P x fromAny (here px) = -, here refl , px fromAny (there v) = Prod.map₂ (Prod.map₁ there) (fromAny v) toAny : ∀ {n x} {xs : Vec A n} → x ∈ xs → P x → Any P xs toAny (here refl) px = here px toAny (there v) px = there (toAny v px)
{ "alphanum_fraction": 0.4512008176, "avg_line_length": 34.6371681416, "ext": "agda", "hexsha": "46eca87b8043d89cac9a7842188ea4639d9c89de", "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/Vec/Membership/Propositional/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/Vec/Membership/Propositional/Properties.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/Vec/Membership/Propositional/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1351, "size": 3914 }
{-# OPTIONS --without-K --exact-split --safe #-} module Fragment.Algebra.Free.Atoms where open import Level using (Level; _⊔_) open import Data.Nat using (ℕ) open import Data.Fin using (Fin) open import Relation.Binary using (Setoid; IsEquivalence) open import Relation.Binary.PropositionalEquality as PE using (_≡_) private variable a ℓ : Level module _ (A : Set a) where data BT (n : ℕ) : Set a where sta : A → BT n dyn : Fin n → BT n module _ (S : Setoid a ℓ) (n : ℕ) where open Setoid S renaming (Carrier to A) data _≍_ : BT A n → BT A n → Set (a ⊔ ℓ) where sta : ∀ {x y} → x ≈ y → sta x ≍ sta y dyn : ∀ {x y} → x ≡ y → dyn x ≍ dyn y private ≍-refl : ∀ {x} → x ≍ x ≍-refl {sta _} = sta refl ≍-refl {dyn _} = dyn PE.refl ≍-sym : ∀ {x y} → x ≍ y → y ≍ x ≍-sym (sta x≈y) = sta (sym x≈y) ≍-sym (dyn x≡y) = dyn (PE.sym x≡y) ≍-trans : ∀ {x y z} → x ≍ y → y ≍ z → x ≍ z ≍-trans (sta x≈y) (sta y≈z) = sta (trans x≈y y≈z) ≍-trans (dyn x≡y) (dyn y≡z) = dyn (PE.trans x≡y y≡z) ≍-isEquivalence : IsEquivalence _≍_ ≍-isEquivalence = record { refl = ≍-refl ; sym = ≍-sym ; trans = ≍-trans } Atoms : Setoid a (a ⊔ ℓ) Atoms = record { Carrier = BT (Setoid.Carrier S) n ; _≈_ = _≍_ ; isEquivalence = ≍-isEquivalence }
{ "alphanum_fraction": 0.5020604396, "avg_line_length": 26, "ext": "agda", "hexsha": "192fbbd2aad22b623b06e3d848908e48559c5bef", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Algebra/Free/Atoms.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Algebra/Free/Atoms.agda", "max_line_length": 67, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Algebra/Free/Atoms.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 552, "size": 1456 }
------------------------------------------------------------------------ -- Validity of declarative kinding of Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Kinding.Declarative.Validity where open import Data.Fin using (zero) open import Data.Fin.Substitution.ExtraLemmas open import Data.Product as Prod using (_,_; _×_; proj₁; proj₂) open import Relation.Binary.PropositionalEquality using (_≡_; refl; subst) open import FOmegaInt.Syntax open import FOmegaInt.Kinding.Declarative ------------------------------------------------------------------------ -- Validity of declarative kinding, subkinding and subtyping open Syntax open Substitution hiding (subst) open TermCtx open Kinding open WfCtxOps using (lookup-kd) open KindedSubstitution open WfSubstitutionEquality -- An admissible rule for kinding η-expanded type operators. Tp∈-η : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd → Γ ⊢Tp Λ j (weaken a · var zero) ∈ Π j k Tp∈-η {k = k} a∈Πjk j-kd k-kd = ∈-Π-i j-kd (subst (_ ⊢Tp _ ∈_) k′[z]≡k (∈-Π-e a∈Πjk′ z∈k k-kd′ k[z]-kd)) k-kd where module KL = TermLikeLemmas termLikeLemmasKind j-wf = wf-kd j-kd j-kd′ = kd-weaken j-wf j-kd k-kd′ = kd-/Var k-kd (Var∈-↑ (wf-kd j-kd′) (Var∈-wk j-wf)) z∈k = ∈-var zero (j-wf ∷ kd-ctx j-kd) refl a∈Πjk′ = Tp∈-weaken j-wf a∈Πjk k[z]-kd = kd-[] k-kd′ (∈-tp z∈k) k′[z]≡k = Kind-wk↑-sub-zero-vanishes k mutual -- Validity of kinding: the kinds of well-kinded types are well-formed. Tp∈-valid : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ k kd Tp∈-valid (∈-var x Γ-ctx Γ[x]≡kd-k) = lookup-kd x Γ-ctx Γ[x]≡kd-k Tp∈-valid (∈-⊥-f Γ-ctx) = *-kd Γ-ctx Tp∈-valid (∈-⊤-f Γ-ctx) = *-kd Γ-ctx Tp∈-valid (∈-∀-f k-kd a∈*) = *-kd (kd-ctx k-kd) Tp∈-valid (∈-→-f a∈* b∈*) = *-kd (Tp∈-ctx a∈*) Tp∈-valid (∈-Π-i j-kd a∈k k-kd) = kd-Π j-kd (Tp∈-valid a∈k) Tp∈-valid (∈-Π-e a∈Πjk b∈j k-kd k[b]-kd) = k[b]-kd Tp∈-valid (∈-s-i a∈b⋯c) = let a∈* = Tp∈-⋯-* a∈b⋯c in kd-⋯ a∈* a∈* Tp∈-valid (∈-⇑ a∈j j<∷k) = proj₂ (<∷-valid j<∷k) -- Validity of subkinding: subkinds are well-formed. <∷-valid : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ⊢ j kd × Γ ⊢ k kd <∷-valid (<∷-⋯ a₂<:a₁∈* b₁<:b₂∈*) = let a₂∈* , a₁∈* = <:-valid a₂<:a₁∈* b₁∈* , b₂∈* = <:-valid b₁<:b₂∈* in kd-⋯ a₁∈* b₁∈* , kd-⋯ a₂∈* b₂∈* <∷-valid (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = Πj₁k₁-kd , kd-Π (proj₁ (<∷-valid j₂<∷j₁)) (proj₂ (<∷-valid k₁<∷k₂)) -- Validity of subtyping: subtypes that are related in some kind `k' -- inhabit `k'. <:-valid : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢Tp a ∈ k × Γ ⊢Tp b ∈ k <:-valid (<:-refl a∈k) = a∈k , a∈k <:-valid (<:-trans a<:b∈k b<:c∈k) = proj₁ (<:-valid a<:b∈k) , proj₂ (<:-valid b<:c∈k) <:-valid (<:-β₁ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) = ∈-Π-e (∈-Π-i j-kd a∈k k-kd) b∈j k-kd k[b]-kd , a[b]∈k[b] where j-kd = wf-kd-inv (wf-∷₁ (Tp∈-ctx a∈k)) <:-valid (<:-β₂ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) = a[b]∈k[b] , ∈-Π-e (∈-Π-i j-kd a∈k k-kd) b∈j k-kd k[b]-kd where j-kd = wf-kd-inv (wf-∷₁ (Tp∈-ctx a∈k)) <:-valid (<:-η₁ a∈Πjk) with Tp∈-valid a∈Πjk ... | (kd-Π j-kd k-kd) = Tp∈-η a∈Πjk j-kd k-kd , a∈Πjk <:-valid (<:-η₂ a∈Πjk) with Tp∈-valid a∈Πjk ... | (kd-Π j-kd k-kd) = a∈Πjk , Tp∈-η a∈Πjk j-kd k-kd <:-valid (<:-⊥ b∈c⋯d) = ∈-⊥-f (Tp∈-ctx b∈c⋯d) , Tp∈-⋯-* b∈c⋯d <:-valid (<:-⊤ b∈c⋯d) = Tp∈-⋯-* b∈c⋯d , ∈-⊤-f (Tp∈-ctx b∈c⋯d) <:-valid (<:-∀ k₂<∷k₁ a₁<:a₂∈* ∀k₁a₁∈*) = ∀k₁a₁∈* , ∈-∀-f (proj₁ (<∷-valid k₂<∷k₁)) (proj₂ (<:-valid a₁<:a₂∈*)) <:-valid (<:-→ a₂<:a₁∈* b₁<:b₂∈*) = let a₂∈* , a₁∈* = <:-valid a₂<:a₁∈* b₁∈* , b₂∈* = <:-valid b₁<:b₂∈* in ∈-→-f a₁∈* b₁∈* , ∈-→-f a₂∈* b₂∈* <:-valid (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) = Λj₁a₁∈Πjk , Λj₂a₂∈Πjk <:-valid (<:-· a₁<:a₂∈Πjk b₁≃b₂∈j b₁∈j k-kd k[b₁]-kd) = let a₁∈Πjk , a₂∈Πjk = <:-valid a₁<:a₂∈Πjk b₁∈j , b₂∈j = ≃-valid b₁≃b₂∈j in ∈-Π-e a₁∈Πjk b₁∈j k-kd k[b₁]-kd , ∈-⇑ (∈-Π-e a₂∈Πjk b₂∈j k-kd (kd-[] k-kd (∈-tp b₂∈j))) (≅⇒<∷ (kd-[≃′] k-kd b₂∈j b₁∈j (≃-sym b₁≃b₂∈j))) <:-valid (<:-⟨| a∈b⋯c) with Tp∈-valid a∈b⋯c ... | (kd-⋯ b∈* c∈*) = b∈* , Tp∈-⋯-* a∈b⋯c <:-valid (<:-|⟩ a∈b⋯c) with Tp∈-valid a∈b⋯c ... | (kd-⋯ b∈* c∈*) = Tp∈-⋯-* a∈b⋯c , c∈* <:-valid (<:-⋯-i a<:b∈c⋯d) = let a∈c⋯d , b∈c⋯d = <:-valid a<:b∈c⋯d a<:b∈* = <:-⋯-* a<:b∈c⋯d in ∈-⇑ (∈-s-i a∈c⋯d) (<∷-⋯ (<:-refl (Tp∈-⋯-* a∈c⋯d)) a<:b∈*) , ∈-⇑ (∈-s-i b∈c⋯d) (<∷-⋯ a<:b∈* (<:-refl (Tp∈-⋯-* b∈c⋯d))) <:-valid (<:-⇑ a<:b∈j j<∷k) = let a∈j , b∈j = <:-valid a<:b∈j in ∈-⇑ a∈j j<∷k , ∈-⇑ b∈j j<∷k -- Validity of type equality: types that are equal in some kind `k' -- inhabit `k'. ≃-valid : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢Tp a ∈ k × Γ ⊢Tp b ∈ k ≃-valid (<:-antisym a<:b∈k b<:a∈k) = <:-valid a<:b∈k -- Subtypes inhabiting interval kinds are proper types. <:-⋯-* : ∀ {n} {Γ : Ctx n} {a b c d} → Γ ⊢ a <: b ∈ c ⋯ d → Γ ⊢ a <: b ∈ * <:-⋯-* a<:b∈c⋯d = let a∈c⋯d , b∈c⋯d = <:-valid a<:b∈c⋯d in <:-⇑ (<:-⋯-i a<:b∈c⋯d) (<∷-⋯ (<:-⊥ a∈c⋯d) (<:-⊤ b∈c⋯d)) -- Validity of kind equality: equal kinds are well-formed. ≅-valid : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j kd × Γ ⊢ k kd ≅-valid (<∷-antisym j<∷k k<∷j) = <∷-valid j<∷k -- A corollary. <:-valid-kd : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢ k kd <:-valid-kd a<:b∈k = Tp∈-valid (proj₁ (<:-valid a<:b∈k)) ---------------------------------------------------------------------- -- Strengthened versions of kind formation and kinding functionality. -- Functionality of kind formation (strong version). kd-[≃] : ∀ {n} {Γ : Ctx n} {a b j k} → kd j ∷ Γ ⊢ k kd → Γ ⊢ a ≃ b ∈ j → Γ ⊢ k Kind[ a ] ≅ k Kind[ b ] kd-[≃] k-kd a≃b∈j = let a∈j , b∈j = ≃-valid a≃b∈j in kd-[≃′] k-kd a∈j b∈j a≃b∈j -- Functionality of kinding (strong version). Tp∈-[≃] : ∀ {n} {Γ : Ctx n} {a b c j k} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢ b ≃ c ∈ j → Γ ⊢ a [ b ] ≃ a [ c ] ∈ k Kind[ b ] Tp∈-[≃] a∈k b≃c∈j = let b∈j , c∈j = ≃-valid b≃c∈j in Tp∈-[≃′] a∈k b∈j c∈j b≃c∈j
{ "alphanum_fraction": 0.4573199809, "avg_line_length": 41.94, "ext": "agda", "hexsha": "2df62b3ba16be65e60892a6b6b64310bf8954912", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_line_length": 79, "max_stars_count": 12, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "num_tokens": 3477, "size": 6291 }
{-# OPTIONS --cubical #-} module _ where module _ where import Agda.Primitive open import Agda.Primitive.Cubical public postulate Path' : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ {-# BUILTIN PATH Path' #-} {-# BUILTIN PATHP PathP #-} infix 4 _≡_ _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ _≡_ {A = A} = PathP (λ _ → A) Path = _≡_ refl : ∀ {a} {A : Set a} {x : A} → x ≡ x refl {x = x} = \ _ → x testPath : ∀ {A : Set} {b a : A} (let H : Path b b; H = _) → ∀ i → H i ≡ b testPath i = refl
{ "alphanum_fraction": 0.4633333333, "avg_line_length": 22.2222222222, "ext": "agda", "hexsha": "35ce7b9ccbb5e13a181de7e966b4f2958aa428b8", "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/Issue2650.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/Issue2650.agda", "max_line_length": 74, "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/Issue2650.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": 260, "size": 600 }
open import Relation.Binary using (IsDecEquivalence) open import Agda.Builtin.Equality module UnifyMguF (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ where {- module UnifyMguF where postulate FunctionName : Set instance isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) -} open IsDecEquivalence isDecEquivalenceA using () renaming (_≟_ to _≟F_) open import UnifyTermF FunctionName open import Data.Product using (∃; _,_) open import Data.Maybe using (Maybe; just; nothing) open import Category.Monad using (RawMonad) import Level open RawMonad (Data.Maybe.monad {Level.zero}) open import Relation.Nullary using (Dec; yes; no) open import Data.Nat using (ℕ; _≟_) open import Function using (flip; _∘_) open import Data.Vec using (Vec; []; _∷_) record ⋆amgu (T : ℕ → Set) : Set where field amgu : ∀ {m} (s t : T m) (acc : ∃ (AList m)) -> Maybe (∃ (AList m)) open ⋆amgu ⦃ … ⦄ public mutual instance ⋆amguTerm : ⋆amgu Term ⋆amgu.amgu ⋆amguTerm leaf leaf acc = just acc ⋆amgu.amgu ⋆amguTerm leaf (function _ _) acc = nothing ⋆amgu.amgu ⋆amguTerm leaf (s' fork t') acc = nothing ⋆amgu.amgu ⋆amguTerm (s' fork t') leaf acc = nothing ⋆amgu.amgu ⋆amguTerm (s' fork t') (function _ _) acc = nothing ⋆amgu.amgu ⋆amguTerm (s1 fork s2) (t1 fork t2) acc = amgu s2 t2 =<< amgu s1 t1 acc ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) leaf acc = nothing ⋆amgu.amgu ⋆amguTerm (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc with fn₁ ≟F fn₂ … | no _ = nothing … | yes _ with n₁ ≟ n₂ … | no _ = nothing … | yes refl = amgu ts₁ ts₂ acc ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) (_ fork _) acc = nothing ⋆amgu.amgu ⋆amguTerm (i x) (i y) (m , anil) = just (flexFlex x y) ⋆amgu.amgu ⋆amguTerm (i x) t (m , anil) = flexRigid x t ⋆amgu.amgu ⋆amguTerm t (i x) (m , anil) = flexRigid x t ⋆amgu.amgu ⋆amguTerm s t (n , σ asnoc r / z) = (λ σ -> σ ∃asnoc r / z) <$> amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) instance ⋆amguVecTerm : ∀ {N} → ⋆amgu (flip Vec N ∘ Term) ⋆amgu.amgu ⋆amguVecTerm [] [] acc = just acc ⋆amgu.amgu ⋆amguVecTerm (t₁ ∷ t₁s) (t₂ ∷ t₂s) acc = amgu t₁s t₂s =<< amgu t₁ t₂ acc mgu : ∀ {m} -> (s t : Term m) -> Maybe (∃ (AList m)) mgu {m} s t = amgu s t (m , anil)
{ "alphanum_fraction": 0.6378494624, "avg_line_length": 35.2272727273, "ext": "agda", "hexsha": "03a0ffcc8c6324f0a96f486709cb33c86b18413e", "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/UnifyMguF.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/UnifyMguF.agda", "max_line_length": 109, "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/UnifyMguF.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 953, "size": 2325 }
open import FRP.JS.Nat using ( ℕ ; zero ; suc ; _≤_ ; _<_ ; _≟_ ; _+_ ) open import FRP.JS.Nat.Properties using ( ≤-impl-≯ ; <-impl-s≤ ; ≤≠-impl-< ; ≤-bot ) open import FRP.JS.Bool using ( Bool ; true ; false ; _∧_ ) open import FRP.JS.Maybe using ( Maybe ; just ; nothing ) open import FRP.JS.True using ( True ; contradiction ; dec ; yes ; no ) module FRP.JS.Array where infixr 5 _∷_ infixr 4 _++i_ -- IArray A m n is offset m of a length n array with contents of type A data IArray {α} (A : Set α) : ℕ → ℕ → Set α where [] : ∀ {n} → IArray A n n _∷_ : ∀ {m n} → (a : A) → (as : IArray A (suc m) n) → IArray A m n data Array {α} (A : Set α) : Set α where array : ∀ {n} → (as : IArray A 0 n) → Array A {-# COMPILED_JS IArray function(xs,v) { if ((xs.array.length) <= (xs.offset)) { return v["[]"](xs.offset); } else { return v["_∷_"](xs.offset,xs.array.length,xs.head(),xs.tail()); } } #-} {-# COMPILED_JS [] require("agda.array").iempty #-} {-# COMPILED_JS _∷_ function(m) { return function(n) { return function(x) { return function(xs) { return xs.cons(x); }; }; }; } #-} {-# COMPILED_JS Array function(as,v) { return v.array(as.length,require("agda.array").iarray(as)); } #-} {-# COMPILED_JS array function(n) { return function(as) { return as.array; }; } #-} length : ∀ {α A} → Array {α} A → ℕ length (array {n} as) = n {-# COMPILED_JS length function() { return function() { return function(as) { return as.length; }; }; } #-} iarray : ∀ {α A} → (as : Array {α} A) → IArray A 0 (length as) iarray (array as) = as {-# COMPILED_JS iarray function() { return function() { return require("agda.array").iarray; }; } #-} ⟨⟩ : ∀ {α A} → Array {α} A ⟨⟩ = array [] {-# COMPILED_JS ⟨⟩ function() { return function() { return require("agda.array").empty; }; } #-} ilookup : ∀ {α A m n} → IArray {α} A m n → ∀ i → {m≤i : True (m ≤ i)} → {i<n : True (i < n)} → A ilookup {m = m} [] i {m≤i} {i<m} = contradiction (≤-impl-≯ {m} {i} m≤i i<m) ilookup {m = m} (a ∷ as) i {m≤i} {i<n} with dec (m ≟ i) ... | yes m=i = a ... | no m≠i = ilookup as i {<-impl-s≤ {m} {i} (≤≠-impl-< {m} {i} m≤i m≠i)} {i<n} lookup : ∀ {α A} (as : Array {α} A) i → {i<#as : True (i < length as)} → A lookup (array as) i {i<#as} = ilookup as i {≤-bot {i}} {i<#as} {-# COMPILED_JS lookup function() { return function() { return function(as) { return function(i) { return function() { return require("agda.array").lookup(as,i); }; }; }; }; } #-} ilookup? : ∀ {α A m n} → IArray {α} A m n → ℕ → Maybe A ilookup? [] i = nothing ilookup? (a ∷ as) zero = just a ilookup? (a ∷ as) (suc i) = ilookup? as i lookup? : ∀ {α A} → Array {α} A → ℕ → Maybe A lookup? (array as) i = ilookup? as i {-# COMPILED_JS lookup? function() { return function() { return function(as) { return function(i) { return require("agda.box").box(require("agda.array").lookup(as,i)); }; }; }; } #-} imap : ∀ {α β A B m n} → (A → B) → IArray {α} A m n → IArray {β} B m n imap f [] = [] imap f (a ∷ as) = f a ∷ imap f as map : ∀ {α β A B} → (A → B) → Array {α} A → Array {β} B map f (array as) = array (imap f as) {-# COMPILED_JS map function() { return function() { return function() { return function() { return function(f) { return function(as) { return as.map(f); }; }; }; }; }; } #-} #filter : ∀ {α A m n} → (A → Bool) → IArray {α} A m n → ℕ → ℕ #filter p [] l = l #filter p (a ∷ as) l with p a ... | true = #filter p as (1 + l) ... | false = #filter p as l ifilter : ∀ {α A l m n} p as → IArray A l (#filter {α} {A} {m} {n} p as l) ifilter p [] = [] ifilter p (a ∷ as) with p a ... | true = a ∷ ifilter p as ... | false = ifilter p as filter : ∀ {α A} → (A → Bool) → Array {α} A → Array A filter p (array as) = array (ifilter p as) {-# COMPILED_JS filter function() { return function() { return function(p) { return function(as) { return as.filter(p); }; }; }; } #-} iall : ∀ {α A m n} → (A → Bool) → IArray {α} A m n → Bool iall f [] = true iall f (a ∷ as) = f a ∧ iall f as all : ∀ {α A} → (A → Bool) → Array {α} A → Bool all f (array as) = iall f as {-# COMPILED_JS all function() { return function() { return function(f) { return function(as) { return as.every(f); }; }; }; } #-} _≟i[_]_ : ∀ {α β A B l m n} → IArray {α} A l m → (A → B → Bool) → IArray {β} B l n → Bool [] ≟i[ p ] [] = true (a ∷ as) ≟i[ p ] (b ∷ bs) = (p a b) ∧ (as ≟i[ p ] bs) as ≟i[ p ] bs = false _≟[_]_ : ∀ {α β A B} → Array {α} A → (A → B → Bool) → Array {β} B → Bool array as ≟[ p ] array bs = as ≟i[ p ] bs {-# COMPILED_JS _≟[_]_ function() { return function() { return function() { return function() { return function(as) { return function(p) { return function(bs) { return require("agda.array").equals(as,bs,function(a,b) { return p(a)(b); }); }; }; }; }; }; }; } #-} _⊆i[_]_ : ∀ {α β A B l m n} → IArray {α} A l m → (A → B → Bool) → IArray {β} B l n → Bool [] ⊆i[ p ] bs = true (a ∷ as) ⊆i[ p ] [] = false (a ∷ as) ⊆i[ p ] (b ∷ bs) = (p a b) ∧ (as ⊆i[ p ] bs) _⊆[_]_ : ∀ {α β A B} → Array {α} A → (A → B → Bool) → Array {β} B → Bool array as ⊆[ p ] array bs = as ⊆i[ p ] bs {-# COMPILED_JS _⊆[_]_ function() { return function() { return function() { return function() { return function(as) { return function(p) { return function(bs) { return require("agda.array").subseteq(as,bs,function(a,b) { return p(a)(b); }); }; }; }; }; }; }; } #-} igrow : ∀ {α A l m n} → IArray {α} A l n → IArray A (l + m) (n + m) igrow [] = [] igrow (a ∷ as) = a ∷ igrow as _++i_ : ∀ {α A l m n} → IArray {α} A l m → IArray A 0 n → IArray A l (n + m) [] ++i bs = igrow bs (a ∷ as) ++i bs = a ∷ (as ++i bs) _++_ : ∀ {α A} → Array {α} A → Array {α} A → Array {α} A array as ++ array bs = array (as ++i bs) {-# COMPILED_JS _++_ function() { return function() { return function(as) { return function(bs) { return as.concat(bs); }; }; }; } #-} -- Surface syntax, e.g. ⟨ 1 , 2 , 3 ⟩ : Array ℕ infix 3 ⟨_ infixr 4 _,_ infixr 5 _⟩ data Sugar {α} (A : Set α) : Set α where ε : Sugar A _,_ : A → Sugar A → Sugar A _⟩ : ∀ {α A} → A → Sugar {α} A a ⟩ = (a , ε) slength : ∀ {α A} → Sugar {α} A → ℕ → ℕ slength ε m = m slength (a , as) m = slength as (1 + m) desugar : ∀ {α A m} as → IArray A m (slength {α} {A} as m) desugar ε = [] desugar (a , as) = a ∷ desugar as ⟨_ : ∀ {α A} → Sugar {α} A → Array A ⟨ as = array (desugar as)
{ "alphanum_fraction": 0.5306949205, "avg_line_length": 34.8804347826, "ext": "agda", "hexsha": "ec091b06bfbb5cf90bab7274de122064476af12a", "lang": "Agda", "max_forks_count": 7, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z", "max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z", "max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_forks_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_forks_repo_name": "agda/agda-frp-js", "max_forks_repo_path": "src/agda/FRP/JS/Array.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_issues_repo_name": "agda/agda-frp-js", "max_issues_repo_path": "src/agda/FRP/JS/Array.agda", "max_line_length": 118, "max_stars_count": 63, "max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_stars_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_stars_repo_name": "agda/agda-frp-js", "max_stars_repo_path": "src/agda/FRP/JS/Array.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z", "num_tokens": 2477, "size": 6418 }
module main where import parse open import lib open import huffman-types import huffman module parsem = parse huffman.gratr2-nt ptr open parsem open parsem.pnoderiv huffman.rrs huffman.huffman-rtn open import run ptr open noderiv {- from run.agda -} {- imports for Huffman trees and also Braun trees specialized to store Huffman trees with lower frequency ones nearer the root -} open import huffman-tree import braun-tree as bt open bt huffman-tree ht-compare --open import braun-tree huffman-tree ht-compare pqueue : ℕ → Set pqueue = braun-tree pq-empty : pqueue 0 pq-empty = bt-empty pq-insert : ∀ {n : ℕ} → huffman-tree → pqueue n → pqueue (suc n) pq-insert = bt-insert pq-remove-min : ∀ {p : ℕ} → pqueue (suc p) → huffman-tree × pqueue p pq-remove-min = bt-remove-min data output-type : Set where encode-output : string → string → string → string → output-type decode-output : string → output-type error-output : string → output-type -- error message if there is an error inc-frequency : word → trie ℕ → trie ℕ inc-frequency w t with trie-lookup t w inc-frequency w t | nothing = trie-insert t w 1 inc-frequency w t | just c = trie-insert t w (suc c) compute-frequencies : words → trie ℕ → trie ℕ compute-frequencies (WordsStart w) t = inc-frequency w t compute-frequencies (WordsNext w ww) t = compute-frequencies ww (inc-frequency w t) inc-frequency-nonempty : ∀(w : word)(t : trie ℕ) → trie-nonempty (inc-frequency w t) ≡ tt inc-frequency-nonempty w t with trie-lookup t w inc-frequency-nonempty w t | nothing = trie-insert-nonempty t w 1 inc-frequency-nonempty w t | just c = trie-insert-nonempty t w (suc c) compute-frequencies-nonempty : ∀(ws : words)(t : trie ℕ) → trie-nonempty (compute-frequencies ws t) ≡ tt compute-frequencies-nonempty (WordsNext w ww) t = compute-frequencies-nonempty ww (inc-frequency w t) compute-frequencies-nonempty (WordsStart w) t = inc-frequency-nonempty w t build-huffman-pqueue : (l : 𝕃 (string × ℕ)) → pqueue (length l) build-huffman-pqueue [] = pq-empty build-huffman-pqueue ((s , f) :: l) = pq-insert (ht-leaf s f) (build-huffman-pqueue l) -- where we call this function, we have enough evidence to prove the Braun tree is nonempty process-huffman-pqueue : ∀{n} → n =ℕ 0 ≡ ff → pqueue n → huffman-tree process-huffman-pqueue{0} () b process-huffman-pqueue{suc n} _ t with pq-remove-min t process-huffman-pqueue{suc 0} _ t | h , _ = h process-huffman-pqueue{suc (suc n)} _ _ | h , t with pq-remove-min t process-huffman-pqueue{suc (suc n)} _ _ | h , _ | h' , t = process-huffman-pqueue{suc n} refl (pq-insert (ht-node ((ht-frequency h) + (ht-frequency h')) h h') t) build-mappingh : huffman-tree → trie string → 𝕃 char → trie string build-mappingh (ht-leaf s _) m l = trie-insert m s (𝕃char-to-string (reverse l)) build-mappingh (ht-node _ h1 h2) m l = build-mappingh h2 (build-mappingh h1 m ('0' :: l)) ('1' :: l) build-mapping : huffman-tree → trie string build-mapping h = build-mappingh h empty-trie [] encode-word : trie string → word → string encode-word t w with trie-lookup t w encode-word t w | nothing = "error" encode-word t w | just s = s encode-words : trie string → words → string encode-words t (WordsNext w ww) = encode-word t w ^ encode-words t ww encode-words t (WordsStart w) = encode-word t w data code-tree : Set where ct-empty : code-tree ct-leaf : string → code-tree ct-node : code-tree → code-tree → code-tree flip-digit : digit → digit flip-digit Zero = One flip-digit One = Zero sub-ct : digit → code-tree → code-tree sub-ct _ ct-empty = ct-empty sub-ct _ (ct-leaf _) = ct-empty sub-ct Zero (ct-node t1 t2) = t1 sub-ct One (ct-node t1 t2) = t2 ct-node-digit : digit → code-tree → code-tree → code-tree ct-node-digit Zero t1 t2 = ct-node t1 t2 ct-node-digit One t1 t2 = ct-node t2 t1 ct-insert : code-tree → code → code-tree ct-insert t (Code s (BvlitStart d)) = -- child d of the new tree is the new leaf, and the other child is the other subtree of t ct-node-digit d (ct-leaf s) (sub-ct (flip-digit d) t) ct-insert t (Code s (BvlitCons d v)) = -- child d of the new tree is obtained recursively and the other child is the other subtree of t ct-node-digit d (ct-insert (sub-ct d t) (Code s v)) (sub-ct (flip-digit d) t) make-code-tree : code-tree → codes → code-tree make-code-tree t (CodesNext c cs) = make-code-tree (ct-insert t c) cs make-code-tree t (CodesStart c) = ct-insert t c decode-stringh : code-tree → code-tree → bvlit → string decode-stringh orig n (BvlitCons d v) with sub-ct d n decode-stringh orig n (BvlitCons d v) | ct-leaf s = s ^ " " ^ (decode-stringh orig orig v) decode-stringh orig n (BvlitCons d v) | ct-empty = "error\n" decode-stringh orig n (BvlitCons d v) | n' = decode-stringh orig n' v decode-stringh orig n (BvlitStart d) with sub-ct d n decode-stringh orig n (BvlitStart d) | ct-leaf s = s ^ "\n" decode-stringh orig n (BvlitStart d) | _ = "error\n" decode-string : code-tree → bvlit → string decode-string t v = decode-stringh t t v process-cmd : cmd → output-type process-cmd (Encode ww) = step (compute-frequencies ww empty-trie) (compute-frequencies-nonempty ww empty-trie) where step : (t : trie ℕ) → trie-nonempty t ≡ tt → output-type step t nonempty-t = let s1 = trie-to-string " -> " ℕ-to-string t in let m = trie-mappings t in let wt = build-huffman-pqueue m in let h = process-huffman-pqueue (is-empty-ff-length (trie-mappings t) (trie-mappings-nonempty t nonempty-t)) wt in let s2 = ht-to-string h in let mp = build-mapping h in let s3 = trie-to-string " <- " (λ s → s) mp in let s4 = "! " ^ s3 ^ (encode-words mp ww) in encode-output s1 s2 s3 s4 process-cmd (Decode cs v) = let ct = make-code-tree ct-empty cs in let s = decode-string ct v in decode-output s process-start : start → output-type process-start (File c) = process-cmd c process : Run → output-type process (ParseTree (parsed-start p) :: []) = process-start p process r = error-output ("Parsing failure (run with -" ^ "-showParsed).\n") putStrRunIf : 𝔹 → Run → IO ⊤ putStrRunIf tt r = putStr (Run-to-string r) >> putStr "\n" putStrRunIf ff r = return triv doOutput : output-type → string → IO ⊤ doOutput (error-output s) basename = putStr ("Error: " ^ s ^ "\n") doOutput (encode-output s1 s2 s3 s4) basename = writeFile (basename ^ "-frequencies.txt") s1 >> writeFile (basename ^ ".gv") s2 >> writeFile (basename ^ "-mapping.txt") s3 >> writeFile (basename ^ ".huff") s4 doOutput (decode-output s) basename = writeFile (basename ^ "-decoded.txt") s processArgs : (showRun : 𝔹) → (showParsed : 𝔹) → 𝕃 string → IO ⊤ processArgs showRun showParsed (input-filename :: []) = (readFiniteFile input-filename) >>= processText where processText : string → IO ⊤ processText x with runRtn (string-to-𝕃char x) processText x | s with s processText x | s | inj₁ cs = putStr "Characters left before failure : " >> putStr (𝕃char-to-string cs) >> putStr "\nCannot proceed to parsing.\n" processText x | s | inj₂ r with putStrRunIf showRun r | rewriteRun r processText x | s | inj₂ r | sr | r' with putStrRunIf showParsed r' processText x | s | inj₂ r | sr | r' | sr' = sr >> sr' >> doOutput (process r') (base-filename input-filename) processArgs showRun showParsed ("--showRun" :: xs) = processArgs tt showParsed xs processArgs showRun showParsed ("--showParsed" :: xs) = processArgs showRun tt xs processArgs showRun showParsed (x :: xs) = putStr ("Unknown option " ^ x ^ "\n") processArgs showRun showParsed [] = putStr "Please run with the name of a file to process.\n" main : IO ⊤ main = getArgs >>= processArgs ff ff
{ "alphanum_fraction": 0.6791505792, "avg_line_length": 41.550802139, "ext": "agda", "hexsha": "0122d662e5d0154283c2dc8dbca853a491667d58", "lang": "Agda", "max_forks_count": 17, "max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z", "max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rfindler/ial", "max_forks_repo_path": "huffman/main.agda", "max_issues_count": 8, "max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rfindler/ial", "max_issues_repo_path": "huffman/main.agda", "max_line_length": 154, "max_stars_count": 29, "max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rfindler/ial", "max_stars_repo_path": "huffman/main.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z", "max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z", "num_tokens": 2357, "size": 7770 }
{-# OPTIONS --safe #-} -- --without-K #-} open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; sym; refl; subst; trans; cong) open import Relation.Nullary using (Dec; yes; no) open import Relation.Nullary.Decidable using (True; toWitness; fromWitness) open import Function using (_∘_) import Data.Maybe as Maybe import Data.Empty as Empty import Data.Unit as Unit import Data.Nat as ℕ import Data.Nat.Properties as ℕₚ import Data.Product as Product import Data.Product.Properties as Productₚ import Data.Vec as Vec import Data.Vec.Relation.Unary.All as All import Data.Fin as Fin open Maybe using (nothing; just) open Empty using (⊥; ⊥-elim) open Unit using (⊤; tt) open ℕ using (ℕ; zero; suc) open Product using (Σ-syntax; ∃-syntax; _×_; _,_; proj₂; proj₁) open Vec using (Vec; []; _∷_) open All using (All; []; _∷_) open Fin using (Fin ; zero ; suc) open Relation.Binary.PropositionalEquality.≡-Reasoning import PiCalculus.Syntax open PiCalculus.Syntax.Scoped open import PiCalculus.Semantics open import PiCalculus.LinearTypeSystem.Algebras module PiCalculus.LinearTypeSystem.ContextLemmas (Ω : Algebras) where open Algebras Ω open import PiCalculus.LinearTypeSystem Ω private variable n : ℕ idxs idxsₗ idxsᵣ : Idxs n γ : PreCtx n idx idx' : Idx t : Type P Q : Scoped n i j : Fin n Γ Δ Ξ Θ : Ctx idxs x x' y z : Usage idx ² data _≔_⊗_ : Ctx idxs → Ctx idxs → Ctx idxs → Set where [] : [] ≔ [] ⊗ [] _,_ : Γ ≔ Δ ⊗ Ξ → x ≔ y ∙² z → (Γ -, x) ≔ (Δ -, y) ⊗ (Ξ -, z) ε : ∀ {idxs : Idxs n} → Ctx idxs ε {idxs = []} = [] ε {idxs = _ -, _} = ε -, (0∙ , 0∙) ⊗-get : {idxs : Idxs n} {Γ Δ Ξ : Ctx idxs} (i : Fin n) → Γ ≔ Δ ⊗ Ξ → All.lookup i Γ ≔ All.lookup i Δ ∙² All.lookup i Ξ ⊗-get zero (Γ≔ , x≔) = x≔ ⊗-get (suc i) (Γ≔ , x) = ⊗-get i Γ≔ ⊗-idˡ : {idxs : Idxs n} {Γ : Ctx idxs} → Γ ≔ ε {idxs = idxs} ⊗ Γ ⊗-idˡ {Γ = []} = [] ⊗-idˡ {Γ = Γ -, x} = ⊗-idˡ , ∙²-idˡ ⊗-unique : {Γ Γ' Δ Ξ : Ctx idxs} → Γ' ≔ Δ ⊗ Ξ → Γ ≔ Δ ⊗ Ξ → Γ' ≡ Γ ⊗-unique [] [] = refl ⊗-unique (Γ'≔ , x'≔) (Γ≔ , x≔) rewrite ⊗-unique Γ'≔ Γ≔ | ∙²-unique x'≔ x≔ = refl ⊗-uniqueˡ : {Γ Δ Δ' Ξ : Ctx idxs} → Γ ≔ Δ' ⊗ Ξ → Γ ≔ Δ ⊗ Ξ → Δ' ≡ Δ ⊗-uniqueˡ [] [] = refl ⊗-uniqueˡ (Δ'≔ , y'≔) (Δ≔ , y≔) rewrite ⊗-uniqueˡ Δ'≔ Δ≔ | ∙²-uniqueˡ y'≔ y≔ = refl ⊗-comm : {Γ Δ Ξ : Ctx idxs} → Γ ≔ Δ ⊗ Ξ → Γ ≔ Ξ ⊗ Δ ⊗-comm [] = [] ⊗-comm (Γ≔ , x≔) = ⊗-comm Γ≔ , ∙²-comm x≔ ⊗-assoc : {Γₘ Γₗ Γᵣ Γₗₗ Γₗᵣ : Ctx idxs} → Γₘ ≔ Γₗ ⊗ Γᵣ → Γₗ ≔ Γₗₗ ⊗ Γₗᵣ → Σ[ Γᵣ' ∈ Ctx idxs ] (Γₘ ≔ Γₗₗ ⊗ Γᵣ' × Γᵣ' ≔ Γₗᵣ ⊗ Γᵣ) ⊗-assoc [] [] = [] , [] , [] ⊗-assoc (Γₘ≔ , xₘ≔) (Γₗ≔ , xₗ≔) with ⊗-assoc Γₘ≔ Γₗ≔ | ∙²-assoc xₘ≔ xₗ≔ ... | (_ , Γₘ'≔ , Γᵣ'≔) | (_ , xₘ'≔ , xᵣ'≔) = _ , ((Γₘ'≔ , xₘ'≔) , (Γᵣ'≔ , xᵣ'≔)) ⊗-assoc⁻¹ : ∀ {x y z u v : Ctx idxs} → x ≔ y ⊗ z → z ≔ u ⊗ v → ∃[ w ] (x ≔ w ⊗ v × w ≔ y ⊗ u) ⊗-assoc⁻¹ a b = let _ , a' , b' = ⊗-assoc (⊗-comm a) (⊗-comm b) in _ , ⊗-comm a' , ⊗-comm b' ⊗-comp : {Γ Δₗ Δᵣ Δ Ξ Θ : Ctx idxs} → Γ ≔ Δₗ ⊗ Ξ → Ξ ≔ Δᵣ ⊗ Θ → Γ ≔ Δ ⊗ Θ → Δ ≔ Δₗ ⊗ Δᵣ ⊗-comp l≔ r≔ Γ≔ with ⊗-assoc (⊗-comm l≔) (⊗-comm r≔) ⊗-comp l≔ r≔ Γ≔ | _ , Γ'≔ , R'≔ rewrite ⊗-uniqueˡ Γ≔ (⊗-comm Γ'≔) = ⊗-comm R'≔ ⊗-idʳ : {Γ : Ctx idxs} → Γ ≔ Γ ⊗ ε ⊗-idʳ = ⊗-comm ⊗-idˡ ⊗-mut-cancel : ∀ {x y y' z : Ctx idxs} → x ≔ y ⊗ z → z ≔ y' ⊗ x → x ≡ z ⊗-mut-cancel [] [] = refl ⊗-mut-cancel (Γ≔ , x≔) (Ξ≔ , z≔) rewrite ⊗-mut-cancel Γ≔ Ξ≔ | ∙²-mut-cancel x≔ z≔ = refl ∋-≡Idx : {idxs : Idxs n} {i : Fin n} {Γ Δ : Ctx idxs} {x : Usage idx ²} → Γ ∋[ i ] x ▹ Δ → Vec.lookup idxs i ≡ idx ∋-≡Idx (zero x) = refl ∋-≡Idx (suc s) rewrite ∋-≡Idx s = refl ∋-≡Type : γ ∋[ i ] t → Vec.lookup γ i ≡ t ∋-≡Type zero = refl ∋-≡Type (suc t) rewrite ∋-≡Type t = refl ≡Type-∋ : Vec.lookup γ i ≡ t → γ ∋[ i ] t ≡Type-∋ {γ = _ -, _} {i = zero} refl = zero ≡Type-∋ {γ = _ -, _} {i = suc i} eq = suc (≡Type-∋ eq) ∋-⊗ : {Γ Ξ : Ctx idxs} → Γ ∋[ i ] x ▹ Ξ → Σ[ Δ ∈ Ctx idxs ] (Γ ≔ Δ ⊗ Ξ × Δ ∋[ i ] x ▹ ε {idxs = idxs}) ∋-⊗ (zero x) = _ , (⊗-idˡ , x) , zero ∙²-idʳ ∋-⊗ (suc s) with ∋-⊗ s ∋-⊗ (suc s) | _ , Γ≔ , Δ≔ = _ , (Γ≔ , ∙²-idˡ) , suc Δ≔ ⊗-∋ : {Γ Δ Ξ : Ctx idxs} → Γ ≔ Δ ⊗ Ξ → Δ ∋[ i ] x ▹ ε {idxs = idxs} → Γ ∋[ i ] x ▹ Ξ ⊗-∋ (sp , s) (zero x) rewrite ⊗-unique sp ⊗-idˡ | ∙²-unique x ∙²-idʳ = zero s ⊗-∋ (sp , s) (suc only) rewrite ∙²-unique s ∙²-idˡ = suc (⊗-∋ sp only) ∋-ℓ∅ : {idxs : Idxs n} {Γ : Ctx idxs} {i : Fin n} {idx : Idx}→ Vec.lookup idxs i ≡ idx → Γ ∋[ i ] ℓ∅ {idx} ▹ Γ ∋-ℓ∅ {Γ = _ -, _} {i = zero} refl = zero ∙²-idˡ ∋-ℓ∅ {Γ = _ -, _} {i = suc i} eq = suc (∋-ℓ∅ eq) -- TODO: deprecate, convert to context first ∋-uniqueʳ : {i : Fin n} {idxs : Idxs n} {Γ Δ Ξ : Ctx idxs} → Γ ∋[ i ] x ▹ Δ → Γ ∋[ i ] x ▹ Ξ → Δ ≡ Ξ ∋-uniqueʳ (zero a) (zero b) rewrite ∙²-uniqueˡ (∙²-comm a) (∙²-comm b) = refl ∋-uniqueʳ (suc a) (suc b) rewrite ∋-uniqueʳ a b = refl -- TODO: deprecate, convert to context first ∋-uniqueˡ : Γ ∋[ i ] x ▹ Δ → Ξ ∋[ i ] x ▹ Δ → Γ ≡ Ξ ∋-uniqueˡ (zero a) (zero b) rewrite ∙²-unique a b = refl ∋-uniqueˡ (suc a) (suc b) rewrite ∋-uniqueˡ a b = refl ∋-lookup-≡ : Γ ∋[ i ] x ▹ Δ → All.lookup i Γ ≔ x ∙² All.lookup i Δ ∋-lookup-≡ {Δ = _ -, _} (zero x) = x ∋-lookup-≡ {Δ = _ -, _} (suc s) = ∋-lookup-≡ s ∋-lookup-≢ : Γ ∋[ i ] x ▹ Δ → ∀ j → j ≢ i → All.lookup j Γ ≡ All.lookup j Δ ∋-lookup-≢ (zero x) zero j≢i = ⊥-elim (j≢i refl) ∋-lookup-≢ (suc xati) zero j≢i = refl ∋-lookup-≢ (zero x) (suc j) j≢i = refl ∋-lookup-≢ (suc xati) (suc j) j≢i = ∋-lookup-≢ xati j (j≢i ∘ cong suc) ∙²-⊗ : {Γ Δ Ξ : Ctx idxs} → Γ ∋[ i ] x ▹ ε → Δ ∋[ i ] y ▹ ε → Ξ ∋[ i ] z ▹ ε → x ≔ y ∙² z → Γ ≔ Δ ⊗ Ξ ∙²-⊗ (zero x) (zero y) (zero z) sp rewrite ∙²-unique x ∙²-idʳ | ∙²-unique y ∙²-idʳ | ∙²-unique z ∙²-idʳ = ⊗-idˡ , sp ∙²-⊗ (suc Γ≔) (suc Δ≔) (suc Ξ≔) sp = ∙²-⊗ Γ≔ Δ≔ Ξ≔ sp , ∙²-idˡ diamond : {Γ Ξ Ψ : Ctx idxs} → i ≢ j → Γ ∋[ j ] x ▹ Ξ → Γ ∋[ i ] y ▹ Ψ → Σ[ Θ ∈ Ctx idxs ] ( Ξ ∋[ i ] y ▹ Θ × Ψ ∋[ j ] x ▹ Θ ) diamond i≢j (zero _) (zero _) = ⊥-elim (i≢j refl) diamond i≢j (zero x) (suc ∋i) = _ , suc ∋i , zero x diamond i≢j (suc ∋j) (zero x) = _ , zero x , suc ∋j diamond i≢j (suc ∋j) (suc ∋i) with diamond (i≢j ∘ cong suc) ∋j ∋i diamond i≢j (suc ∋j) (suc ∋i) | _ , ∋i' , ∋j' = _ , suc ∋i' , suc ∋j' outer-diamond : {Γ Ξ Ψ Θ ΞΔ Δ ΨΔ : Ctx idxs} → i ≢ j → Γ ∋[ i ] x ▹ Ξ → Γ ∋[ j ] y ▹ Ψ → Ξ ∋[ j ] y ▹ Θ → Ψ ∋[ i ] x ▹ Θ → Ξ ≔ ΞΔ ⊗ Δ → Ψ ≔ ΨΔ ⊗ Δ → Σ[ ΘΔ ∈ Ctx idxs ] (Θ ≔ ΘΔ ⊗ Δ) outer-diamond i≢j (zero _) (zero _) (zero _) (zero _) a b = ⊥-elim (i≢j refl) outer-diamond i≢j (zero x₁) (suc ∋j) (suc ∈j) (zero x) (as , a) (bs , b) = _ , (bs , a) outer-diamond i≢j (suc ∋i) (zero ∋j) (zero ∈j) (suc ∈i) (as , a) (bs , b) = _ , (as , b) outer-diamond i≢j (suc ∋i) (suc ∋j) (suc ∈j) (suc ∈i) (as , a) (bs , b) with outer-diamond (i≢j ∘ cong suc) ∋i ∋j ∈j ∈i as bs outer-diamond i≢j (suc ∋i) (suc ∋j) (suc ∈j) (suc ∈i) (as , a) (bs , b) | _ , s = _ , (s , a) reverse : {Γ ΓΞ Ξ ΞΨ Ψ : Ctx idxs} → Γ ≔ ΓΞ ⊗ Ξ → Ξ ≔ ΞΨ ⊗ Ψ → Σ[ Θ ∈ Ctx idxs ] ( Γ ≔ ΞΨ ⊗ Θ × Θ ≔ ΓΞ ⊗ Ψ ) reverse Γ≔ΓΞ∙Ξ Ξ≔ΞΨ∙Ψ = let _ , Γ≔ΞΨ∙Θ , Θ≔Ψ∙ΓΞ = ⊗-assoc (⊗-comm Γ≔ΓΞ∙Ξ) Ξ≔ΞΨ∙Ψ in _ , Γ≔ΞΨ∙Θ , ⊗-comm Θ≔Ψ∙ΓΞ boil : {Γ Ξ ΞΨ Θ Ψ ΘΨ : Ctx idxs} → Γ ∋[ i ] x ▹ Θ → Γ ∋[ i ] y ▹ Ξ → Ξ ≔ ΞΨ ⊗ Ψ → Θ ≔ ΘΨ ⊗ Ψ → All.lookup i ΘΨ ≡ ℓ∅ → ∃[ z ] (x ≔ y ∙² z) boil {i = zero} (zero a) (zero b) (_ , c) (_ , d) refl rewrite ∙²-unique d ∙²-idˡ with ∙²-assoc⁻¹ b c boil {i = zero} (zero a) (zero b) (_ , c) (_ , d) refl | _ , e , f rewrite ∙²-uniqueˡ e a = _ , f boil {i = suc i} (suc a) (suc b) (c , _) (d , _) eq = boil a b c d eq split : x ≔ y ∙² z → Γ ∋[ i ] x ▹ Ξ → ∃[ Δ ] (Γ ∋[ i ] y ▹ Δ × Δ ∋[ i ] z ▹ Ξ) split s (zero x) = let _ , x' , s' = ∙²-assoc x s in _ , zero x' , zero s' split s (suc x) with split s x split s (suc x) | _ , y , z = _ , suc y , suc z split-ℓ∅ : {Γ ΓΨ Ψ ΓΘ Θ ΘΨ : Ctx idxs} → Γ ≔ ΓΨ ⊗ Ψ → Γ ≔ ΓΘ ⊗ Θ → Θ ≔ ΘΨ ⊗ Ψ → All.lookup i ΓΨ ≡ ℓ∅ → All.lookup i ΓΘ ≡ ℓ∅ × All.lookup i ΘΨ ≡ ℓ∅ split-ℓ∅ {i = zero} (a , x) (b , y) (c , z) refl rewrite ∙²-unique x ∙²-idˡ with ∙²-mut-cancel y z split-ℓ∅ {i = zero} (a , x) (b , y) (c , z) refl | refl = ∙²-uniqueˡ y ∙²-idˡ , ∙²-uniqueˡ z ∙²-idˡ split-ℓ∅ {i = suc i} (a , _) (b , _) (c , _) eq = split-ℓ∅ a b c eq ⊢-⊗ : {γ : PreCtx n} {idxs : Idxs n} {Γ Ξ : Ctx idxs} → γ ; Γ ⊢ P ▹ Ξ → Σ[ Δ ∈ Ctx idxs ] (Γ ≔ Δ ⊗ Ξ) ⊢-⊗ 𝟘 = ε , ⊗-idˡ ⊢-⊗ (ν t m μ ⊢P) with ⊢-⊗ ⊢P ⊢-⊗ (ν t m μ ⊢P) | (_ -, _) , (P≔ , _) = _ , P≔ ⊢-⊗ ((_ , x) ⦅⦆ ⊢P) with ⊢-⊗ ⊢P ⊢-⊗ ((_ , x) ⦅⦆ ⊢P) | (_ -, _) , (P≔ , _) = let _ , x≔ , _ = ∋-⊗ x _ , xP≔ , _ = ⊗-assoc⁻¹ x≔ P≔ in _ , xP≔ ⊢-⊗ ((_ , x) ⟨ _ , y ⟩ ⊢P) = let _ , x≔ , _ = ∋-⊗ x _ , y≔ , _ = ∋-⊗ y _ , P≔ = ⊢-⊗ ⊢P _ , xy≔ , _ = ⊗-assoc⁻¹ x≔ y≔ _ , Pxy≔ , _ = ⊗-assoc⁻¹ xy≔ P≔ in _ , Pxy≔ ⊢-⊗ (⊢P ∥ ⊢Q) = let _ , P≔ = ⊢-⊗ ⊢P _ , Q≔ = ⊢-⊗ ⊢Q _ , PQ≔ , _ = ⊗-assoc⁻¹ P≔ Q≔ in _ , PQ≔ ctx-insert : (i : Fin (suc n)) → Usage idx ² → Ctx idxs → Ctx (Vec.insert idxs i idx) ctx-insert zero xs' Γ = Γ -, xs' ctx-insert (suc i) xs' (Γ -, xs) = ctx-insert i xs' Γ -, xs ctx-remove : Ctx idxs → (i : Fin (suc n)) → Ctx (Vec.remove idxs i) ctx-remove (Γ -, _) zero = Γ ctx-remove (Γ -, ys -, xs) (suc i) = ctx-remove (Γ -, ys) i -, xs ctx-update : (i : Fin n) → Usage (Vec.lookup idxs i) ² → Ctx idxs → Ctx idxs ctx-update zero m' (ms -, m) = ms -, m' ctx-update (suc i) m' (ms -, m) = ctx-update i m' ms -, m fromFin : {γ : PreCtx n} {idxs : Idxs n} {Γ : Ctx idxs} → ∀ i → {y z : Usage (Vec.lookup idxs i) ²} → All.lookup i Γ ≔ y ∙² z → γ ; Γ ∋[ i ] Vec.lookup γ i ; y ▹ ctx-update i z Γ fromFin {γ = γ -, t} {Γ = Γ -, x} zero split = zero , (zero split) fromFin {γ = γ -, t} {Γ = Γ -, x} (suc i) split = there (fromFin i split) #_ : {γ : PreCtx n} {idxs : Idxs n} {Γ : Ctx idxs} → ∀ m {m<n : True (m ℕₚ.<? n)} → let i = Fin.fromℕ< (toWitness m<n) in {y : Usage (Vec.lookup idxs i) ²} → {check : True (∙²-computeʳ (All.lookup i Γ) y)} → let z , _ = toWitness check in γ ; Γ ∋[ i ] Vec.lookup γ i ; y ▹ ctx-update i z Γ (# m) {m<n} {check = check} = let _ , split = toWitness check in fromFin (Fin.fromℕ< (toWitness m<n)) split
{ "alphanum_fraction": 0.4795213542, "avg_line_length": 37.1083032491, "ext": "agda", "hexsha": "8366994229d444c5675092e637fd17566d777f0c", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z", "max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/typing-linear-pi", "max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/ContextLemmas.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/typing-linear-pi", "max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/ContextLemmas.agda", "max_line_length": 125, "max_stars_count": 26, "max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/typing-linear-pi", "max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/ContextLemmas.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z", "num_tokens": 5650, "size": 10279 }
module Examples where open import Data.List using ([]; _∷_) open import Data.Fin using () renaming (zero to fzero) open import Relation.Binary using (Rel) open import Level using () renaming (zero to lzero) open import Syntax open import Theory module NatBool where data Gr : Set where nat : Gr bool : Gr data Func : Set where zero plus true false not : Func open PType Gr sorting : Func -> Sorting sorting zero = record { dom = Unit ; cod = ⌊ nat ⌋ } sorting plus = record { dom = ⌊ nat ⌋ * ⌊ nat ⌋ ; cod = ⌊ nat ⌋ } sorting true = record { dom = Unit ; cod = ⌊ bool ⌋ } sorting false = record { dom = Unit ; cod = ⌊ bool ⌋ } sorting not = record { dom = ⌊ bool ⌋ ; cod = ⌊ bool ⌋ } Sg : Signature lzero lzero Sg = record { Gr = Gr ; Func = Func ; sorting = sorting } open Term Sg data Ax : forall Γ A -> Rel (Γ ⊢ A) lzero where not-true≡false : Ax [] ⌊ bool ⌋ (func not (func true unit)) (func false unit) not-false≡true : Ax [] ⌊ bool ⌋ (func not (func false unit)) (func true unit) plus-identityˡ : Ax (⌊ nat ⌋ ∷ []) ⌊ nat ⌋ (func plus (pair (func zero unit) var)) var Th : Theory lzero lzero lzero Th = record { Sg = Sg ; Ax = Ax } open Theory.Theory Th import Relation.Binary.Reasoning.Setoid as S thm1 : forall {Γ} -> Γ ⊢ func not (func true unit) ≡ func false unit thm1 = begin func not (func true unit) ≈˘⟨ cong/func (cong/func (comm/unit _ _ _)) ⟩ func not (func true (unit [ ! ])) ≈˘⟨ cong/func (comm/func _ _ _ _ _) ⟩ func not (func true unit [ ! ]) ≈˘⟨ comm/func _ _ _ _ _ ⟩ func not (func true unit) [ ! ] ≈⟨ cong/sub refl (ax not-true≡false) ⟩ func false unit [ ! ] ≈⟨ comm/func _ _ _ _ _ ⟩ func false (unit [ ! ]) ≈⟨ cong/func (comm/unit _ _ _) ⟩ func false unit ∎ where open S TermSetoid
{ "alphanum_fraction": 0.5881410256, "avg_line_length": 27.9402985075, "ext": "agda", "hexsha": "b536a8ec7a383b35edaafd7532ad75648bc6435a", "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": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "elpinal/exsub-ccc", "max_forks_repo_path": "Examples.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "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": "elpinal/exsub-ccc", "max_issues_repo_path": "Examples.agda", "max_line_length": 81, "max_stars_count": 3, "max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "elpinal/exsub-ccc", "max_stars_repo_path": "Examples.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z", "num_tokens": 656, "size": 1872 }
{-# OPTIONS --rewriting #-} {-# OPTIONS --allow-unsolved-metas #-} module NfCBPVLaws where open import Library hiding (_×̇_) open import NfCBPV -- NB: mon⁺ is a comonad coalgebra module MonIsComonadCoalgebra where mon-id : ∀ (P : Ty⁺) {Γ} (a : ⟦ P ⟧⁺ Γ) → mon⁺ P a ⊆-refl ≡ a mon-id (base o) x = {!monVar-id!} mon-id (P₁ ×̇ P₂) (a₁ , a₂) = cong₂ _,_ (mon-id P₁ a₁) (mon-id P₂ a₂) mon-id (Σ̇ I Ps) (i , a) = cong (i ,_) (mon-id (Ps i) a) mon-id (□̇ N) f = funExtH (funExt (λ τ → cong f {!!})) -- ⊆-trans ⊆-refl τ ≡ τ -- Identity: extract ∘ mon⁺ ≡ id extract∘mon : ∀ (P : Ty⁺) {Γ} → extract ∘ mon⁺ P ≗ id {A = ⟦ P ⟧⁺ Γ} extract∘mon = mon-id -- Associativity: □-map (mon⁺ P) ∘ mon⁺ P ≡ duplicate ∘ mon⁺ P mon∘mon : ∀ (P : Ty⁺) {Γ} (a : ⟦ P ⟧⁺ Γ) {Δ} {τ : Γ ⊆ Δ} {Φ} {τ' : Δ ⊆ Φ} → mon⁺ P (mon⁺ P a τ) τ' ≡ mon⁺ P a (⊆-trans τ τ') mon∘mon (base o) x = {!!} -- monVar∘monVar mon∘mon (P₁ ×̇ P₂) (a₁ , a₂) = cong₂ _,_ (mon∘mon P₁ a₁) (mon∘mon P₂ a₂) mon∘mon (Σ̇ I Ps) (i , a) = cong (i ,_) (mon∘mon (Ps i) a) mon∘mon (□̇ N) f = {!!} -- □-mon∘□-mon map-mon∘mon : ∀ (P : Ty⁺) {Γ} → □-map (mon⁺ P) ∘ mon⁺ P ≗ duplicate ∘ mon⁺ P {Γ} map-mon∘mon P a = funExtH $ funExt λ τ → funExtH $ funExt λ τ' → mon∘mon P a module RunIsMonadAlgebra where -- Identity: run⁻ N ∘ return ≡ id -- Associativity: run⁻ N ∘ ◇-map (run⁻ N) ≡ run⁻ N ∘ join monNe : ∀{N} → Mon (Ne N) monNe = {!!} monNf : ∀{N} → Mon (Nf N) monNf = {!!} -- ◇ preserves monotonicity ------------------------------------------------------------------------ -- This needs weakening of neutrals ◇-mon : Mon A → Mon (◇ A) ◇-mon mA (return a) τ = return (mA a τ) ◇-mon mA (bind u c) τ = bind (monNe u τ) (◇-mon mA c (refl ∷ τ)) -- need monotonicity of Ne ◇-mon mA (case x t) τ = case (monVar x τ) (λ i → ◇-mon mA (t i) (refl ∷ τ)) ◇-mon mA (split x c) τ = split (monVar x τ) (◇-mon mA c (refl ∷ refl ∷ τ)) -- From ◇-mon we get □-run □-run : Run B → Run (□ B) □-run rB c = rB ∘ ◇-map extract ∘ ◇-mon □-mon c -- Run for Nf? -- Seems to need a category of renamings rather just OPE bindNf : ∀ {N} {Γ} {P} → Ne (◇̇ P) Γ → Nf N (P ∷ Γ) → Nf N Γ bindNf u (ret v) = ret (bind u v) bindNf u (ne n) = ne (bind u n) bindNf u (rec t) = rec λ i → bindNf u (t i) bindNf u (abs t) = abs (bindNf (monNe u (_ ∷ʳ ⊆-refl)) (monNf t {!!})) -- The remaining goal Q ∷ P ∷ Γ ⊆ P ∷ Q ∷ Γ -- cannot be filled since OPEs do not support swap. runNf : ∀{N} → ◇ (Nf N) →̇ Nf N runNf (return j) = j runNf (bind u c) = bindNf u (runNf c) -- Problem! runNf (case x t) = {!!} runNf (split x c) = {!!} -- Monoidal functoriality ★ module _ {A B : ISet} (mA : Mon A) (mB : Mon B) where zip : ⟨ ◇ A ⊙ ◇ B ⟩→̇ ◇ (A ×̂ B) zip cA cB = join (◇-map! (λ τ a → ◇-map! (λ τ' b → mA a τ' , b) (◇-mon mB cB τ)) cA) -- Alternative definitions of freshᶜ freshᶜ₀ : (Γ : Cxt) → ◇ ⟦ Γ ⟧ᶜ Γ freshᶜ₀ [] = return [] freshᶜ₀ (P ∷ Γ) = ◇-ext $ □-weak (◇-mon (monᶜ Γ) (freshᶜ₀ Γ)) -- BAD, use of ◇-mon ⋉ fresh◇ -- freshᶜ (P ∷ Γ) = ◇-ext $ -- (λ τ → ◇-mon (monᶜ Γ) (freshᶜ Γ) (⊆-trans (_ ∷ʳ ⊆-refl) τ)) -- BAD, use of ◇-mon -- ⋉ fresh◇ freshG₀ : □ (◇ ⟦ Γ ⟧ᶜ) Γ -- freshG₀ : (τ : Γ ⊆ Δ) → ◇ ⟦ Γ ⟧ᶜ Δ freshG₀ [] = return [] freshG₀ (P ∷ʳ τ) = ◇-mon (monᶜ _) (freshG₀ τ) (P ∷ʳ ⊆-refl) -- BAD, use of ◇-mon freshG₀ (refl ∷ τ) = ◇-ext $ (λ τ₁ → freshG₀ (⊆-trans τ (⊆-trans (_ ∷ʳ ⊆-refl) τ₁))) ⋉ fresh◇
{ "alphanum_fraction": 0.5014551804, "avg_line_length": 30.954954955, "ext": "agda", "hexsha": "7ddb4ba100f107ddee02470276081190517bd8cc", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z", "max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "andreasabel/ipl", "max_forks_repo_path": "src-cbpv/NfCBPVLaws.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "andreasabel/ipl", "max_issues_repo_path": "src-cbpv/NfCBPVLaws.agda", "max_line_length": 93, "max_stars_count": 19, "max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "andreasabel/ipl", "max_stars_repo_path": "src-cbpv/NfCBPVLaws.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z", "num_tokens": 1687, "size": 3436 }
{-# OPTIONS --rewriting #-} open import FFI.Data.Either using (Either; Left; Right) open import Luau.Type using (Type; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_) open import Luau.TypeNormalization using (normalize) module Luau.FunctionTypes where -- The domain of a normalized type srcⁿ : Type → Type srcⁿ (S ⇒ T) = S srcⁿ (S ∩ T) = srcⁿ S ∪ srcⁿ T srcⁿ never = unknown srcⁿ T = never -- To get the domain of a type, we normalize it first We need to do -- this, since if we try to use it on non-normalized types, we get -- -- src(number ∩ string) = src(number) ∪ src(string) = never ∪ never -- src(never) = unknown -- -- so src doesn't respect type equivalence. src : Type → Type src (S ⇒ T) = S src T = srcⁿ(normalize T) -- The codomain of a type tgt : Type → Type tgt nil = never tgt (S ⇒ T) = T tgt never = never tgt unknown = unknown tgt number = never tgt boolean = never tgt string = never tgt (S ∪ T) = (tgt S) ∪ (tgt T) tgt (S ∩ T) = (tgt S) ∩ (tgt T)
{ "alphanum_fraction": 0.6646341463, "avg_line_length": 25.2307692308, "ext": "agda", "hexsha": "7607052be0e043fba3ff571c65a5e31a260e47e7", "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": "72d8d443431875607fd457a13fe36ea62804d327", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "TheGreatSageEqualToHeaven/luau", "max_forks_repo_path": "prototyping/Luau/FunctionTypes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "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": "TheGreatSageEqualToHeaven/luau", "max_issues_repo_path": "prototyping/Luau/FunctionTypes.agda", "max_line_length": 95, "max_stars_count": 1, "max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TheGreatSageEqualToHeaven/luau", "max_stars_repo_path": "prototyping/Luau/FunctionTypes.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z", "num_tokens": 326, "size": 984 }
{-# OPTIONS --without-K --safe #-} module Data.List.Kleene.Syntax where open import Data.List hiding ([_]) open import Data.List.Kleene.Base open import Data.Product infixr 4 _,_ infixr 5 _] data ListSyntax {a} (A : Set a) : Set a where _] : A → ListSyntax A _,_ : A → ListSyntax A → ListSyntax A infixr 4 ⋆[_ ⁺[_ [_ ⋆[_ : ∀ {a} {A : Set a} → ListSyntax A → A ⋆ ⋆[ x ] = ∹ x & [] ⋆[ x , xs = ∹ x & (⋆[ xs) ⁺[_ : ∀ {a} {A : Set a} → ListSyntax A → A ⁺ ⁺[ x ] = x & [] ⁺[ x , xs = x & ∹ (⁺[ xs) [_ : ∀ {a} {A : Set a} → ListSyntax A → List A [ x ] = x ∷ [] [ x , xs = x ∷ ([ xs) private open import Data.Nat _ : ℕ ⋆ _ = ⋆[ 1 , 2 , 3 ] _ : ℕ ⁺ _ = ⁺[ 1 , 2 , 3 ] _ : List ℕ _ = [ 1 , 2 , 3 ]
{ "alphanum_fraction": 0.4860724234, "avg_line_length": 18.4102564103, "ext": "agda", "hexsha": "248f1b676bc2da96010a10582b3949765351d187", "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": "a7e99bc288e12e83440c891dbd3e5077d9b1657e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-kleene-lists", "max_forks_repo_path": "Data/List/Kleene/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e", "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-kleene-lists", "max_issues_repo_path": "Data/List/Kleene/Syntax.agda", "max_line_length": 46, "max_stars_count": null, "max_stars_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-kleene-lists", "max_stars_repo_path": "Data/List/Kleene/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 327, "size": 718 }
{-# OPTIONS --without-K #-} module sets.int where open import sets.int.definition public open import sets.int.utils public open import sets.int.core public open import sets.int.properties public
{ "alphanum_fraction": 0.7817258883, "avg_line_length": 21.8888888889, "ext": "agda", "hexsha": "870c474727ae5fcbf912b0b6374aeda52b661232", "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/sets/int.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/sets/int.agda", "max_line_length": 38, "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/sets/int.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 39, "size": 197 }
module Issue2959.M (_ : Set₁) where record R : Set₁ where field A : Set
{ "alphanum_fraction": 0.6455696203, "avg_line_length": 13.1666666667, "ext": "agda", "hexsha": "c0d8c018ea855fa6a1e8f280b5201b2a239891d9", "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/Issue2959/M.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/Issue2959/M.agda", "max_line_length": 35, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue2959/M.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": 27, "size": 79 }
{-# OPTIONS --prop #-} postulate f : Prop → Prop P : Prop₁ x : Prop x = f P -- WAS: -- Set₁ != Set -- when checking that the expression P has type Prop -- SHOULD BE: -- Prop₁ != Prop -- when checking that the expression P has type Prop
{ "alphanum_fraction": 0.6229508197, "avg_line_length": 14.3529411765, "ext": "agda", "hexsha": "24b8350a3cd81cf763ddea544d808ecf8467afb8", "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/Issue3582.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/Issue3582.agda", "max_line_length": 52, "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/Issue3582.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": 71, "size": 244 }
{-# OPTIONS --inversion-max-depth=10 #-} open import Agda.Builtin.Nat open import Agda.Builtin.Equality data ⊥ : Set where double : Nat → Nat double zero = zero double (suc n) = suc (suc (double n)) postulate doubleSuc : (x y : Nat) → double x ≡ suc (double y) → ⊥ diverge : ⊥ diverge = doubleSuc _ _ refl {- double ?x == suc (double ?y) ?x := suc ?x₁ suc (suc (double ?x₁)) == suc (double ?y) suc (double ?x₁) == double ?y ?y := suc ?y₁ double ?x₁ == suc (double ?y₁) . . . -}
{ "alphanum_fraction": 0.5851272016, "avg_line_length": 17.6206896552, "ext": "agda", "hexsha": "977d42e8a4923270e2aad670fe9a8e513902686d", "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/Issue431.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/Issue431.agda", "max_line_length": 57, "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/Issue431.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": 187, "size": 511 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category using (Category; module Definitions) -- Definition of the "Twisted" Functor between certain Functor Categories module Categories.Functor.Instance.Twisted {o ℓ e o′ ℓ′ e′} (𝒞 : Category o ℓ e) (𝒟 : Category o′ ℓ′ e′) where import Categories.Category.Construction.TwistedArrow as TW open import Categories.Category.Product open import Categories.Category.Construction.Functors open import Categories.Functor open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) open import Data.Product using (_,_) private module C = Category 𝒞 Twist : Functor (Product C.op 𝒞) 𝒟 → Functor (TW.TwistedArrow 𝒞) 𝒟 Twist F = record { F₀ = λ x → F₀ (dom x , cod x) ; F₁ = λ f → F₁ (dom⇐ f , cod⇒ f) ; identity = identity ; homomorphism = homomorphism ; F-resp-≈ = F-resp-≈ } where open Functor F open TW.Morphism open TW.Morphism⇒ Twist′ : Functor (Product C.op 𝒞) 𝒟 → Functor (Category.op (TW.TwistedArrow C.op)) 𝒟 Twist′ F = record { F₀ = λ x → F₀ (dom x , cod x) ; F₁ = λ f → F₁ (dom⇐ f , cod⇒ f) ; identity = identity ; homomorphism = homomorphism ; F-resp-≈ = F-resp-≈ } where open Functor F open TW.Morphism open TW.Morphism⇒ Twisted : Functor (Functors (Product C.op 𝒞) 𝒟) (Functors (TW.TwistedArrow 𝒞) 𝒟) Twisted = record { F₀ = Twist ; F₁ = Nat ; identity = D.Equiv.refl ; homomorphism = D.Equiv.refl ; F-resp-≈ = λ f≈g → f≈g } where open TW.Morphism open TW.Morphism⇒ module D = Category 𝒟 Nat : {F G : Functor (Product C.op 𝒞) 𝒟} → NaturalTransformation F G → NaturalTransformation (Twist F) (Twist G) Nat nt = ntHelper record { η = λ x → η nt (dom x , cod x) ; commute = λ f → commute nt (dom⇐ f , cod⇒ f) } where open NaturalTransformation
{ "alphanum_fraction": 0.67233809, "avg_line_length": 28.9206349206, "ext": "agda", "hexsha": "3088328fee06dad4ae2d5a191155f26419190a1a", "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/Functor/Instance/Twisted.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/Functor/Instance/Twisted.agda", "max_line_length": 114, "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/Functor/Instance/Twisted.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": 644, "size": 1822 }
module ModusPonens where modusPonens : {P Q : Set} → (P → Q) → P → Q modusPonens = {!!}
{ "alphanum_fraction": 0.595505618, "avg_line_length": 17.8, "ext": "agda", "hexsha": "7ff3522791c6fc84d2a716052f3df681dc8f7ad3", "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": "ece25bed081a24f02e9f85056d05933eae2afabf", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "danr/agder", "max_forks_repo_path": "problems/ModusPonens/ModusPonens.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf", "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": "danr/agder", "max_issues_repo_path": "problems/ModusPonens/ModusPonens.agda", "max_line_length": 43, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "danr/agder", "max_stars_repo_path": "problems/ModusPonens/ModusPonens.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-17T12:07:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-05-17T12:07:03.000Z", "num_tokens": 39, "size": 89 }
module hello-world-dep-lookup where open import Data.Nat using (ℕ) open import Data.Vec using (Vec; _∷_) open import Data.Fin using (Fin; zero; suc) variable A : Set n : ℕ lookup : Vec A n → Fin n → A lookup (a ∷ as) zero = a lookup (a ∷ as) (suc i) = lookup as i
{ "alphanum_fraction": 0.6568265683, "avg_line_length": 19.3571428571, "ext": "agda", "hexsha": "8420c9663a1e3dd00048fc981593f454f068c698", "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": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "avieor/agda-demos", "max_forks_repo_path": "hello-world-dep-lookup.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d", "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": "avieor/agda-demos", "max_issues_repo_path": "hello-world-dep-lookup.agda", "max_line_length": 43, "max_stars_count": null, "max_stars_repo_head_hexsha": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "avieor/agda-demos", "max_stars_repo_path": "hello-world-dep-lookup.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 96, "size": 271 }
--{-# OPTIONS --allow-unsolved-metas #-} module StateSizedIO.GUI.WxGraphicsLibLevel3 where open import StateSizedIO.GUI.Prelude data GuiLev1Command : Set where putStrLn : String → GuiLev1Command createFrame : GuiLev1Command addButton : Frame → Button → GuiLev1Command createTextCtrl : Frame → String → GuiLev1Command fireCustomEvent : Frame → GuiLev1Command setAttribButton : Button → WxColor → GuiLev1Command setAttribTextCtrl : TextCtrl → WxColor → GuiLev1Command setChildredLayout : Frame → ℕ → ℕ → ℕ → ℕ → GuiLev1Command createButton : Frame → String → GuiLev1Command deleteButton : Button → GuiLev1Command deleteTextCtrl : TextCtrl → GuiLev1Command drawBitmap : DC → Bitmap → Point → Bool → GuiLev1Command repaint : Frame → GuiLev1Command bitmapGetWidth : Bitmap → GuiLev1Command GuiLev1Response : GuiLev1Command → Set GuiLev1Response createFrame = Frame GuiLev1Response (createButton _ _) = Button GuiLev1Response (bitmapGetWidth _) = ℤ GuiLev1Response (createTextCtrl _ _) = TextCtrl GuiLev1Response _ = Unit GuiLev1Interface : IOInterface GuiLev1Interface .Command = GuiLev1Command GuiLev1Interface .Response = GuiLev1Response GuiLev2State : Set₁ GuiLev2State = VarList data GuiLev2Command (s : GuiLev2State) : Set₁ where level1C : GuiLev1Command → GuiLev2Command s createVar : {A : Set} → A → GuiLev2Command s setButtonHandler : Button → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setTimer : Frame → ℤ → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setKeyHandler : Button → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → List (prod s → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s setOnPaint : Frame → List (prod s → DC → Rect → IO GuiLev1Interface ∞ (prod s)) → GuiLev2Command s GuiLev2Response : (s : GuiLev2State) → GuiLev2Command s → Set GuiLev2Response _ (level1C c) = GuiLev1Response c GuiLev2Response _ (createVar {A} a) = Var A GuiLev2Response _ (setTimer fra x p) = Timer GuiLev2Response _ _ = Unit GuiLev2Next : (s : GuiLev2State) (c : GuiLev2Command s) → GuiLev2Response s c → GuiLev2State GuiLev2Next s (createVar {A} a) var = addVar A var s GuiLev2Next s _ _ = s GuiLev2Interface : IOInterfaceˢ Stateˢ GuiLev2Interface = GuiLev2State Commandˢ GuiLev2Interface = GuiLev2Command Responseˢ GuiLev2Interface = GuiLev2Response nextˢ GuiLev2Interface = GuiLev2Next translateLev1Local : (c : GuiLev1Command) → NativeIO (GuiLev1Response c) translateLev1Local createFrame = nativeCreateFrame translateLev1Local (setChildredLayout win a b c d) = nativeSetChildredLayout win a b c d translateLev1Local (createButton fra str) = nativeMakeButton fra str translateLev1Local (deleteButton bt) = nativeDeleteButton bt translateLev1Local (deleteTextCtrl txt) = nativeDeleteTextCtrl txt translateLev1Local (addButton fra bt) = nativeAddButton fra bt translateLev1Local (setAttribButton bt col) = nativeSetColorButton bt col translateLev1Local (setAttribTextCtrl txt col) = nativeSetColorTextCtrl txt col translateLev1Local (drawBitmap dc bm p b) = nativeDrawBitmap dc bm p b translateLev1Local (repaint fra) = nativeRepaint fra translateLev1Local (bitmapGetWidth b) = nativeBitmapGetWidth b translateLev1Local (putStrLn s) = nativePutStrLn s translateLev1Local (fireCustomEvent fr) = nativeFireCustomEvent fr translateLev1Local (createTextCtrl f str) = nativeMakeTextCtrl f str translateLev1 : {A : Set} → IO GuiLev1Interface ∞ A → NativeIO A translateLev1 = translateIO translateLev1Local translateLev1List : {A : Set} → List (IO GuiLev1Interface ∞ A) → List (NativeIO A) translateLev1List l = map translateLev1 l translateLev2Local : (s : GuiLev2State) → (c : GuiLev2Command s) → NativeIO (GuiLev2Response s c) translateLev2Local s (level1C c) = translateLev1Local c translateLev2Local s (createVar {A} a) = nativeNewVar {A} a translateLev2Local s (setButtonHandler bt proglist) = nativeSetButtonHandler bt (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglist)) translateLev2Local s (setTimer fra interv proglist) = nativeSetTimer fra interv (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglist)) translateLev2Local s (setKeyHandler bt proglistRight proglistLeft proglistUp proglistDown) = nativeSetKeyHandler bt (λ key -> case (showKey key) of λ { "Right" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistRight)) ; "Left" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistLeft)) ; "Up" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistUp)) ; "Down" → (dispatchList s (map (λ prog → translateLev1 ∘ prog) proglistDown)) ; _ → nativeReturn unit } ) translateLev2Local s (setOnPaint fra proglist) = nativeSetOnPaint fra (λ dc rect → (dispatchList s (map (λ prog aa → translateLev1 (prog aa dc rect)) proglist))) translateLev2 : {s : GuiLev2State} → {A : Set} → IOˢ GuiLev2Interface ∞ (λ _ → A) s → NativeIO A translateLev2 = translateIOˢ {I = GuiLev2Interface} translateLev2Local data GuiLev3Command (s : GuiLev2State) : Set₂ where level2C : GuiLev2Command s → GuiLev3Command s setCustomEvent : Frame → List ((x : prod s) → IOˢ GuiLev2Interface ∞ (λ _ → prod s) s) → GuiLev3Command s setRightClick : Frame → List ( (x : prod s) → IOˢ GuiLev2Interface ∞ (λ _ → prod s) s) → GuiLev3Command s GuiLev3Response : (s : GuiLev2State) → GuiLev3Command s → Set GuiLev3Response s (level2C c) = GuiLev2Response s c GuiLev3Response _ _ = Unit GuiLev3Next : (s : GuiLev2State) → (c : GuiLev3Command s) → GuiLev3Response s c → GuiLev2State GuiLev3Next s (level2C c) r = GuiLev2Next s c r GuiLev3Next s (setRightClick _ _) _ = s GuiLev3Next s (setCustomEvent _ _) _ = s GuiLev3Interface : IOInterfaceˢ GuiLev3Interface .Stateˢ = GuiLev2State GuiLev3Interface .Commandˢ = GuiLev3Command GuiLev3Interface .Responseˢ = GuiLev3Response GuiLev3Interface .nextˢ = GuiLev3Next translateLev3Local : (s : GuiLev2State) → (c : GuiLev3Command s) → NativeIO (GuiLev3Response s c) translateLev3Local s (level2C c) = translateLev2Local s c translateLev3Local s (setRightClick f proglist) = nativeSetClickRight f (dispatchList s (map (λ prog → translateLev2{s} ∘ prog ) proglist)) translateLev3Local s (setCustomEvent f proglist) = nativeRegisterCustomEvent f (dispatchList s (map (λ prog → translateLev2{s} ∘ prog ) proglist)) translateLev3 : {s : GuiLev2State} → {A : Set} → IOˢ GuiLev3Interface ∞ (λ _ → A) s → NativeIO A translateLev3 = translateIOˢ {I = GuiLev3Interface} translateLev3Local mutual translateLev1toLev2∞ : ∀{s : GuiLev2State} → {A : Set} → IO' GuiLev1Interface ∞ A → IOˢ' GuiLev2Interface ∞ (λ _ → A) s translateLev1toLev2∞ (do' c f) = doˢ' (level1C c) λ r → translateLev1toLev2 (f r) translateLev1toLev2∞ (return' a) = returnˢ' a translateLev1toLev2ₚ∞ : ∀{s : GuiLev2State} → {A : Set} → IO' GuiLev1Interface ∞ A → IOₚˢ' GuiLev2Interface ∞ A s s translateLev1toLev2ₚ∞ (do' c f) = doˢ' (level1C c) (λ r → translateLev1toLev2ₚ (f r)) translateLev1toLev2ₚ∞ (return' a) = returnˢ' (refl , a) translateLev1toLev2 : ∀{s : GuiLev2State} → {A : Set} → IO GuiLev1Interface ∞ A → IOˢ GuiLev2Interface ∞ (λ _ → A) s translateLev1toLev2 x .forceˢ = translateLev1toLev2∞ (x .force) translateLev1toLev2ₚ : ∀{s : GuiLev2State} → {A : Set} → IO GuiLev1Interface ∞ A → IOₚˢ GuiLev2Interface ∞ A s s translateLev1toLev2ₚ x .forceˢ = translateLev1toLev2ₚ∞ (x .force) mutual translateLev2toLev3∞ : ∀{α}{s : GuiLev2State} → {A : GuiLev2State → Set α} → IOˢ' GuiLev2Interface ∞ A s → IOˢ' GuiLev3Interface ∞ A s translateLev2toLev3∞ (doˢ'{s} c f) = doˢ' (level2C c) λ r → translateLev2toLev3 (f r) translateLev2toLev3∞ (returnˢ' a) = returnˢ' a translateLev2toLev3 : ∀{α}{s : GuiLev2State} → {A : GuiLev2State → Set α} → IOˢ GuiLev2Interface ∞ A s → IOˢ GuiLev3Interface ∞ A s translateLev2toLev3 x .forceˢ = translateLev2toLev3∞ (x .forceˢ) -- -- Example -- example : IO GuiLev1Interface ∞ Frame example = do createFrame λ frame → do (putStrLn "Frame created") λ _ → return frame private main : NativeIO Frame main = translateIO translateLev1Local example
{ "alphanum_fraction": 0.6578523057, "avg_line_length": 37.3614457831, "ext": "agda", "hexsha": "258af079f13c33d8eb45c21a551b2a6cf60d8db6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "stephanadls/state-dependent-gui", "max_forks_repo_path": "src/StateSizedIO/GUI/WxGraphicsLibLevel3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "stephanadls/state-dependent-gui", "max_issues_repo_path": "src/StateSizedIO/GUI/WxGraphicsLibLevel3.agda", "max_line_length": 98, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "stephanadls/state-dependent-gui", "max_stars_repo_path": "src/StateSizedIO/GUI/WxGraphicsLibLevel3.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z", "num_tokens": 3111, "size": 9303 }
module Tactic.Monoid where open import Prelude open import Tactic.Reflection open import Tactic.Reflection.Quote open import Structure.Monoid.Laws open import Tactic.Monoid.Exp open import Tactic.Monoid.Reflect open import Tactic.Monoid.Proofs monoidTactic : ∀ {a} {A : Set a} {MonA : Monoid A} {{_ : MonoidLaws A {{MonA}}}} → Tactic monoidTactic {A = A} {dict} {{laws}} hole = do goal ← inferNormalisedType hole `A ← quoteTC A unify goal (def (quote _≡_) (hArg unknown ∷ hArg `A ∷ vArg unknown ∷ vArg unknown ∷ [])) <|> do typeError $ strErr "Goal is not an equality" ∷ termErr goal ∷ [] goal ← normalise goal ensureNoMetas goal match ← monoidMatcher dict `dict ← quoteTC dict `laws ← quoteTC laws ensureNoMetas `dict debugPrint "tactic.monoid" 20 $ strErr "monoidTactic" ∷ termErr goal ∷ strErr "dict =" ∷ termErr `dict ∷ [] (lhs , rhs) , env ← parseGoal match goal unify hole (def (quote proof) (iArg `dict ∷ iArg `laws ∷ vArg (` lhs) ∷ vArg (` rhs) ∷ vArg (quoteEnv `dict env) ∷ vArg (con (quote refl) []) ∷ [])) <|> do typeError $ strErr "Can't prove" ∷ termErr (` lhs) ∷ strErr "==" ∷ termErr (` rhs) ∷ strErr "because" ∷ termErr (` (flatten lhs)) ∷ strErr "/=" ∷ termErr (` (flatten rhs)) ∷ [] macro auto-monoid : ∀ {a} {A : Set a} {Mon : Monoid A} {{Laws : MonoidLaws A {{Mon}}}} → Tactic auto-monoid {{Laws}} = monoidTactic {{Laws}}
{ "alphanum_fraction": 0.6176870748, "avg_line_length": 39.7297297297, "ext": "agda", "hexsha": "fce0527315fde401f03d77bffb3f5c278690181a", "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/Monoid.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/Monoid.agda", "max_line_length": 109, "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/Monoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 492, "size": 1470 }
{-# OPTIONS --guardedness #-} module Cubical.Codata.Conat where open import Cubical.Codata.Conat.Base public open import Cubical.Codata.Conat.Properties public
{ "alphanum_fraction": 0.7914110429, "avg_line_length": 20.375, "ext": "agda", "hexsha": "f35a316c922614d9b67d84e6c08b92aed68ff578", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Codata/Conat.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Codata/Conat.agda", "max_line_length": 50, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Codata/Conat.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 37, "size": 163 }
-- Linear monoidal closed structure for families module SOAS.Families.Linear {T : Set} where open import SOAS.Common open import SOAS.Context {T} open import SOAS.Sorting {T} open import SOAS.Families.Core {T} open import SOAS.Families.Isomorphism {T} open import Categories.Category.Monoidal open import Categories.Category.Monoidal.Closed open import Categories.Functor.Bifunctor -- | Monoidal tensor and unit -- Linear tensor product that combines two families with two disjoint contexts data _⊗_ (X Y : Family) : Ctx → Set where merge : (Γ Δ : Ctx) → X Γ → Y Δ → (X ⊗ Y) (Δ ∔ Γ) infixr 20 _⊗_ pattern _⊹_ {Γ}{Δ} t s = merge Γ Δ t s infix 30 _⊹_ -- ⊗ is a bifunctor ⊗F : Bifunctor 𝔽amilies 𝔽amilies 𝔽amilies ⊗F = record { F₀ = λ (X , Y) → X ⊗ Y ; F₁ = λ{ {X , Y}{X′ , Y′} (f , g) (x ⊹ y) → (f x) ⊹ (g y)} ; identity = λ{ {X , Y}{Γ}{x ⊹ y} → refl } ; homomorphism = λ{ {X , Y}{X′ , Y′}{X″ , Y″}{f , g}{f′ , g′}{Γ}{x ⊹ y} → refl } ; F-resp-≈ = λ{ (p₁ , p₂) {.(Δ ∔ Γ)} {merge Γ Δ t s} → cong₂ (merge Γ Δ) p₁ p₂ } } _⊗̣_ : Familyₛ → Familyₛ → Familyₛ _⊗̣_ = sorted₂ _⊗_ 𝒚 : Ctx → Family 𝒚 Γ Δ = Γ ≡ Δ -- Family which is only inhabited at the empty context E : Family E = 𝒚 ∅ -- Sorted family which is only inhabited at a singleton context N : Familyₛ N α = 𝒚 ⌈ α ⌋ -- | Monoidal exponential -- Linear exponential between families _⊸_ : Family → Family → Family (X ⊸ Y) Γ = {Δ : Ctx} → X Δ → Y (Δ ∔ Γ) infixr 15 _⊸_ -- Linear exponential between sorted families _⊸∙_ : Familyₛ → Familyₛ → Familyₛ _⊸∙_ = sorted₂ _⊸_ infixr 15 _⊸∙_ -- ⊸ is a bifunctor ⊸F : Bifunctor 𝔽am.op 𝔽amilies 𝔽amilies ⊸F = record { F₀ = λ (X , Y) → X ⊸ Y ; F₁ = λ{ {X , Y}{X′ , Y′} (f , g) e x → g (e (f x))} ; identity = refl ; homomorphism = refl ; F-resp-≈ = λ{ {X , Y}{X′ , Y′}{f , g} (p₁ , p₂) {Γ}{e} → dext′ (trans (cong (g ∘ e) p₁) p₂) } }
{ "alphanum_fraction": 0.5940488842, "avg_line_length": 26.1388888889, "ext": "agda", "hexsha": "1963a36f916ffad8db10dd62740155796e67deee", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "SOAS/Families/Linear.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "SOAS/Families/Linear.agda", "max_line_length": 82, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "SOAS/Families/Linear.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 809, "size": 1882 }
open import Nat open import Prelude open import contexts module core where -- types data htyp : Set where b : htyp ⦇-⦈ : htyp _==>_ : htyp → htyp → htyp -- arrow type constructors bind very tightly infixr 25 _==>_ -- external expressions data hexp : Set where c : hexp _·:_ : hexp → htyp → hexp X : Nat → hexp ·λ : Nat → hexp → hexp ·λ_[_]_ : Nat → htyp → hexp → hexp ⦇-⦈[_] : Nat → hexp ⦇⌜_⌟⦈[_] : hexp → Nat → hexp _∘_ : hexp → hexp → hexp -- the type of type contexts, i.e. Γs in the judegments below tctx : Set tctx = htyp ctx mutual -- identity substitution, substitition environments data env : Set where Id : (Γ : tctx) → env Subst : (d : ihexp) → (y : Nat) → env → env -- internal expressions data ihexp : Set where c : ihexp X : Nat → ihexp ·λ_[_]_ : Nat → htyp → ihexp → ihexp ⦇-⦈⟨_⟩ : (Nat × env) → ihexp ⦇⌜_⌟⦈⟨_⟩ : ihexp → (Nat × env) → ihexp _∘_ : ihexp → ihexp → ihexp _⟨_⇒_⟩ : ihexp → htyp → htyp → ihexp _⟨_⇒⦇-⦈⇏_⟩ : ihexp → htyp → htyp → ihexp -- convenient notation for chaining together two agreeable casts _⟨_⇒_⇒_⟩ : ihexp → htyp → htyp → htyp → ihexp d ⟨ t1 ⇒ t2 ⇒ t3 ⟩ = d ⟨ t1 ⇒ t2 ⟩ ⟨ t2 ⇒ t3 ⟩ -- type consistency data _~_ : (t1 t2 : htyp) → Set where TCRefl : {τ : htyp} → τ ~ τ TCHole1 : {τ : htyp} → τ ~ ⦇-⦈ TCHole2 : {τ : htyp} → ⦇-⦈ ~ τ TCArr : {τ1 τ2 τ1' τ2' : htyp} → τ1 ~ τ1' → τ2 ~ τ2' → τ1 ==> τ2 ~ τ1' ==> τ2' -- type inconsistency data _~̸_ : (τ1 τ2 : htyp) → Set where ICBaseArr1 : {τ1 τ2 : htyp} → b ~̸ τ1 ==> τ2 ICBaseArr2 : {τ1 τ2 : htyp} → τ1 ==> τ2 ~̸ b ICArr1 : {τ1 τ2 τ3 τ4 : htyp} → τ1 ~̸ τ3 → τ1 ==> τ2 ~̸ τ3 ==> τ4 ICArr2 : {τ1 τ2 τ3 τ4 : htyp} → τ2 ~̸ τ4 → τ1 ==> τ2 ~̸ τ3 ==> τ4 --- matching for arrows data _▸arr_ : htyp → htyp → Set where MAHole : ⦇-⦈ ▸arr ⦇-⦈ ==> ⦇-⦈ MAArr : {τ1 τ2 : htyp} → τ1 ==> τ2 ▸arr τ1 ==> τ2 -- the type of hole contexts, i.e. Δs in the judgements hctx : Set hctx = (htyp ctx × htyp) ctx -- notation for a triple to match the CMTT syntax _::_[_] : Nat → htyp → tctx → (Nat × (tctx × htyp)) u :: τ [ Γ ] = u , (Γ , τ) -- the hole name u does not appear in the term e data hole-name-new : (e : hexp) (u : Nat) → Set where HNConst : ∀{u} → hole-name-new c u HNAsc : ∀{e τ u} → hole-name-new e u → hole-name-new (e ·: τ) u HNVar : ∀{x u} → hole-name-new (X x) u HNLam1 : ∀{x e u} → hole-name-new e u → hole-name-new (·λ x e) u HNLam2 : ∀{x e u τ} → hole-name-new e u → hole-name-new (·λ x [ τ ] e) u HNHole : ∀{u u'} → u' ≠ u → hole-name-new (⦇-⦈[ u' ]) u HNNEHole : ∀{u u' e} → u' ≠ u → hole-name-new e u → hole-name-new (⦇⌜ e ⌟⦈[ u' ]) u HNAp : ∀{ u e1 e2 } → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (e1 ∘ e2) u -- two terms that do not share any hole names data holes-disjoint : (e1 : hexp) → (e2 : hexp) → Set where HDConst : ∀{e} → holes-disjoint c e HDAsc : ∀{e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (e1 ·: τ) e2 HDVar : ∀{x e} → holes-disjoint (X x) e HDLam1 : ∀{x e1 e2} → holes-disjoint e1 e2 → holes-disjoint (·λ x e1) e2 HDLam2 : ∀{x e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (·λ x [ τ ] e1) e2 HDHole : ∀{u e2} → hole-name-new e2 u → holes-disjoint (⦇-⦈[ u ]) e2 HDNEHole : ∀{u e1 e2} → hole-name-new e2 u → holes-disjoint e1 e2 → holes-disjoint (⦇⌜ e1 ⌟⦈[ u ]) e2 HDAp : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint (e1 ∘ e2) e3 -- bidirectional type checking judgements for hexp mutual -- synthesis data _⊢_=>_ : (Γ : tctx) (e : hexp) (τ : htyp) → Set where SConst : {Γ : tctx} → Γ ⊢ c => b SAsc : {Γ : tctx} {e : hexp} {τ : htyp} → Γ ⊢ e <= τ → Γ ⊢ (e ·: τ) => τ SVar : {Γ : tctx} {τ : htyp} {x : Nat} → (x , τ) ∈ Γ → Γ ⊢ X x => τ SAp : {Γ : tctx} {e1 e2 : hexp} {τ τ1 τ2 : htyp} → holes-disjoint e1 e2 → Γ ⊢ e1 => τ1 → τ1 ▸arr τ2 ==> τ → Γ ⊢ e2 <= τ2 → Γ ⊢ (e1 ∘ e2) => τ SEHole : {Γ : tctx} {u : Nat} → Γ ⊢ ⦇-⦈[ u ] => ⦇-⦈ SNEHole : {Γ : tctx} {e : hexp} {τ : htyp} {u : Nat} → hole-name-new e u → Γ ⊢ e => τ → Γ ⊢ ⦇⌜ e ⌟⦈[ u ] => ⦇-⦈ SLam : {Γ : tctx} {e : hexp} {τ1 τ2 : htyp} {x : Nat} → x # Γ → (Γ ,, (x , τ1)) ⊢ e => τ2 → Γ ⊢ ·λ x [ τ1 ] e => τ1 ==> τ2 -- analysis data _⊢_<=_ : (Γ : htyp ctx) (e : hexp) (τ : htyp) → Set where ASubsume : {Γ : tctx} {e : hexp} {τ τ' : htyp} → Γ ⊢ e => τ' → τ ~ τ' → Γ ⊢ e <= τ ALam : {Γ : tctx} {e : hexp} {τ τ1 τ2 : htyp} {x : Nat} → x # Γ → τ ▸arr τ1 ==> τ2 → (Γ ,, (x , τ1)) ⊢ e <= τ2 → Γ ⊢ (·λ x e) <= τ -- those types without holes data _tcomplete : htyp → Set where TCBase : b tcomplete TCArr : ∀{τ1 τ2} → τ1 tcomplete → τ2 tcomplete → (τ1 ==> τ2) tcomplete -- those external expressions without holes data _ecomplete : hexp → Set where ECConst : c ecomplete ECAsc : ∀{τ e} → τ tcomplete → e ecomplete → (e ·: τ) ecomplete ECVar : ∀{x} → (X x) ecomplete ECLam1 : ∀{x e} → e ecomplete → (·λ x e) ecomplete ECLam2 : ∀{x e τ} → e ecomplete → τ tcomplete → (·λ x [ τ ] e) ecomplete ECAp : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → (e1 ∘ e2) ecomplete -- those internal expressions without holes data _dcomplete : ihexp → Set where DCVar : ∀{x} → (X x) dcomplete DCConst : c dcomplete DCLam : ∀{x τ d} → d dcomplete → τ tcomplete → (·λ x [ τ ] d) dcomplete DCAp : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → (d1 ∘ d2) dcomplete DCCast : ∀{d τ1 τ2} → d dcomplete → τ1 tcomplete → τ2 tcomplete → (d ⟨ τ1 ⇒ τ2 ⟩) dcomplete -- contexts that only produce complete types _gcomplete : tctx → Set Γ gcomplete = (x : Nat) (τ : htyp) → (x , τ) ∈ Γ → τ tcomplete -- those internal expressions where every cast is the identity cast and -- there are no failed casts data cast-id : ihexp → Set where CIConst : cast-id c CIVar : ∀{x} → cast-id (X x) CILam : ∀{x τ d} → cast-id d → cast-id (·λ x [ τ ] d) CIHole : ∀{u} → cast-id (⦇-⦈⟨ u ⟩) CINEHole : ∀{d u} → cast-id d → cast-id (⦇⌜ d ⌟⦈⟨ u ⟩) CIAp : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id (d1 ∘ d2) CICast : ∀{d τ} → cast-id d → cast-id (d ⟨ τ ⇒ τ ⟩) -- expansion mutual -- synthesis data _⊢_⇒_~>_⊣_ : (Γ : tctx) (e : hexp) (τ : htyp) (d : ihexp) (Δ : hctx) → Set where ESConst : ∀{Γ} → Γ ⊢ c ⇒ b ~> c ⊣ ∅ ESVar : ∀{Γ x τ} → (x , τ) ∈ Γ → Γ ⊢ X x ⇒ τ ~> X x ⊣ ∅ ESLam : ∀{Γ x τ1 τ2 e d Δ } → (x # Γ) → (Γ ,, (x , τ1)) ⊢ e ⇒ τ2 ~> d ⊣ Δ → Γ ⊢ ·λ x [ τ1 ] e ⇒ (τ1 ==> τ2) ~> ·λ x [ τ1 ] d ⊣ Δ ESAp : ∀{Γ e1 τ τ1 τ1' τ2 τ2' d1 Δ1 e2 d2 Δ2 } → holes-disjoint e1 e2 → Δ1 ## Δ2 → Γ ⊢ e1 => τ1 → τ1 ▸arr τ2 ==> τ → Γ ⊢ e1 ⇐ (τ2 ==> τ) ~> d1 :: τ1' ⊣ Δ1 → Γ ⊢ e2 ⇐ τ2 ~> d2 :: τ2' ⊣ Δ2 → Γ ⊢ e1 ∘ e2 ⇒ τ ~> (d1 ⟨ τ1' ⇒ τ2 ==> τ ⟩) ∘ (d2 ⟨ τ2' ⇒ τ2 ⟩) ⊣ (Δ1 ∪ Δ2) ESEHole : ∀{ Γ u } → Γ ⊢ ⦇-⦈[ u ] ⇒ ⦇-⦈ ~> ⦇-⦈⟨ u , Id Γ ⟩ ⊣ ■ (u :: ⦇-⦈ [ Γ ]) ESNEHole : ∀{ Γ e τ d u Δ } → Δ ## (■ (u , Γ , ⦇-⦈)) → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇒ ⦇-⦈ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ ⊣ (Δ ,, u :: ⦇-⦈ [ Γ ]) ESAsc : ∀ {Γ e τ d τ' Δ} → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ → Γ ⊢ (e ·: τ) ⇒ τ ~> d ⟨ τ' ⇒ τ ⟩ ⊣ Δ -- analysis data _⊢_⇐_~>_::_⊣_ : (Γ : tctx) (e : hexp) (τ : htyp) (d : ihexp) (τ' : htyp) (Δ : hctx) → Set where EALam : ∀{Γ x τ τ1 τ2 e d τ2' Δ } → (x # Γ) → τ ▸arr τ1 ==> τ2 → (Γ ,, (x , τ1)) ⊢ e ⇐ τ2 ~> d :: τ2' ⊣ Δ → Γ ⊢ ·λ x e ⇐ τ ~> ·λ x [ τ1 ] d :: τ1 ==> τ2' ⊣ Δ EASubsume : ∀{e Γ τ' d Δ τ} → ((u : Nat) → e ≠ ⦇-⦈[ u ]) → ((e' : hexp) (u : Nat) → e ≠ ⦇⌜ e' ⌟⦈[ u ]) → Γ ⊢ e ⇒ τ' ~> d ⊣ Δ → τ ~ τ' → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ EAEHole : ∀{ Γ u τ } → Γ ⊢ ⦇-⦈[ u ] ⇐ τ ~> ⦇-⦈⟨ u , Id Γ ⟩ :: τ ⊣ ■ (u :: τ [ Γ ]) EANEHole : ∀{ Γ e u τ d τ' Δ } → Δ ## (■ (u , Γ , τ)) → Γ ⊢ e ⇒ τ' ~> d ⊣ Δ → Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇐ τ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ :: τ ⊣ (Δ ,, u :: τ [ Γ ]) -- ground types data _ground : (τ : htyp) → Set where GBase : b ground GHole : ⦇-⦈ ==> ⦇-⦈ ground mutual -- substitution typing data _,_⊢_:s:_ : hctx → tctx → env → tctx → Set where STAId : ∀{Γ Γ' Δ} → ((x : Nat) (τ : htyp) → (x , τ) ∈ Γ' → (x , τ) ∈ Γ) → Δ , Γ ⊢ Id Γ' :s: Γ' STASubst : ∀{Γ Δ σ y Γ' d τ } → Δ , Γ ,, (y , τ) ⊢ σ :s: Γ' → Δ , Γ ⊢ d :: τ → Δ , Γ ⊢ Subst d y σ :s: Γ' -- type assignment data _,_⊢_::_ : (Δ : hctx) (Γ : tctx) (d : ihexp) (τ : htyp) → Set where TAConst : ∀{Δ Γ} → Δ , Γ ⊢ c :: b TAVar : ∀{Δ Γ x τ} → (x , τ) ∈ Γ → Δ , Γ ⊢ X x :: τ TALam : ∀{ Δ Γ x τ1 d τ2} → x # Γ → Δ , (Γ ,, (x , τ1)) ⊢ d :: τ2 → Δ , Γ ⊢ ·λ x [ τ1 ] d :: (τ1 ==> τ2) TAAp : ∀{ Δ Γ d1 d2 τ1 τ} → Δ , Γ ⊢ d1 :: τ1 ==> τ → Δ , Γ ⊢ d2 :: τ1 → Δ , Γ ⊢ d1 ∘ d2 :: τ TAEHole : ∀{ Δ Γ σ u Γ' τ} → (u , (Γ' , τ)) ∈ Δ → Δ , Γ ⊢ σ :s: Γ' → Δ , Γ ⊢ ⦇-⦈⟨ u , σ ⟩ :: τ TANEHole : ∀ { Δ Γ d τ' Γ' u σ τ } → (u , (Γ' , τ)) ∈ Δ → Δ , Γ ⊢ d :: τ' → Δ , Γ ⊢ σ :s: Γ' → Δ , Γ ⊢ ⦇⌜ d ⌟⦈⟨ u , σ ⟩ :: τ TACast : ∀{ Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 → τ1 ~ τ2 → Δ , Γ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2 TAFailedCast : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 → τ1 ground → τ2 ground → τ1 ≠ τ2 → Δ , Γ ⊢ d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ :: τ2 -- substitution [_/_]_ : ihexp → Nat → ihexp → ihexp [ d / y ] c = c [ d / y ] X x with natEQ x y [ d / y ] X .y | Inl refl = d [ d / y ] X x | Inr neq = X x [ d / y ] (·λ x [ x₁ ] d') with natEQ x y [ d / y ] (·λ .y [ τ ] d') | Inl refl = ·λ y [ τ ] d' [ d / y ] (·λ x [ τ ] d') | Inr x₁ = ·λ x [ τ ] ( [ d / y ] d') [ d / y ] ⦇-⦈⟨ u , σ ⟩ = ⦇-⦈⟨ u , Subst d y σ ⟩ [ d / y ] ⦇⌜ d' ⌟⦈⟨ u , σ ⟩ = ⦇⌜ [ d / y ] d' ⌟⦈⟨ u , Subst d y σ ⟩ [ d / y ] (d1 ∘ d2) = ([ d / y ] d1) ∘ ([ d / y ] d2) [ d / y ] (d' ⟨ τ1 ⇒ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒ τ2 ⟩ [ d / y ] (d' ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ -- applying an environment to an expression apply-env : env → ihexp → ihexp apply-env (Id Γ) d = d apply-env (Subst d y σ) d' = [ d / y ] ( apply-env σ d') -- values data _val : (d : ihexp) → Set where VConst : c val VLam : ∀{x τ d} → (·λ x [ τ ] d) val -- boxed values data _boxedval : (d : ihexp) → Set where BVVal : ∀{d} → d val → d boxedval BVArrCast : ∀{ d τ1 τ2 τ3 τ4 } → τ1 ==> τ2 ≠ τ3 ==> τ4 → d boxedval → d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ boxedval BVHoleCast : ∀{ τ d } → τ ground → d boxedval → d ⟨ τ ⇒ ⦇-⦈ ⟩ boxedval mutual -- indeterminate forms data _indet : (d : ihexp) → Set where IEHole : ∀{u σ} → ⦇-⦈⟨ u , σ ⟩ indet INEHole : ∀{d u σ} → d final → ⦇⌜ d ⌟⦈⟨ u , σ ⟩ indet IAp : ∀{d1 d2} → ((τ1 τ2 τ3 τ4 : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨(τ1 ==> τ2) ⇒ (τ3 ==> τ4)⟩)) → d1 indet → d2 final → (d1 ∘ d2) indet ICastArr : ∀{d τ1 τ2 τ3 τ4} → τ1 ==> τ2 ≠ τ3 ==> τ4 → d indet → d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ indet ICastGroundHole : ∀{ τ d } → τ ground → d indet → d ⟨ τ ⇒ ⦇-⦈ ⟩ indet ICastHoleGround : ∀ { d τ } → ((d' : ihexp) (τ' : htyp) → d ≠ (d' ⟨ τ' ⇒ ⦇-⦈ ⟩)) → d indet → τ ground → d ⟨ ⦇-⦈ ⇒ τ ⟩ indet IFailedCast : ∀{ d τ1 τ2 } → d final → τ1 ground → τ2 ground → τ1 ≠ τ2 → d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ indet -- final expressions data _final : (d : ihexp) → Set where FBoxedVal : ∀{d} → d boxedval → d final FIndet : ∀{d} → d indet → d final -- contextual dynamics -- evaluation contexts data ectx : Set where ⊙ : ectx _∘₁_ : ectx → ihexp → ectx _∘₂_ : ihexp → ectx → ectx ⦇⌜_⌟⦈⟨_⟩ : ectx → (Nat × env ) → ectx _⟨_⇒_⟩ : ectx → htyp → htyp → ectx _⟨_⇒⦇-⦈⇏_⟩ : ectx → htyp → htyp → ectx -- note: this judgement is redundant: in the absence of the premises in -- the red brackets, all syntactically well formed ectxs are valid. with -- finality premises, that's not true, and that would propagate through -- additions to the calculus. so we leave it here for clarity but note -- that, as written, in any use case its either trival to prove or -- provides no additional information --ε is an evaluation context data _evalctx : (ε : ectx) → Set where ECDot : ⊙ evalctx ECAp1 : ∀{d ε} → ε evalctx → (ε ∘₁ d) evalctx ECAp2 : ∀{d ε} → -- d final → -- red brackets ε evalctx → (d ∘₂ ε) evalctx ECNEHole : ∀{ε u σ} → ε evalctx → ⦇⌜ ε ⌟⦈⟨ u , σ ⟩ evalctx ECCast : ∀{ ε τ1 τ2} → ε evalctx → (ε ⟨ τ1 ⇒ τ2 ⟩) evalctx ECFailedCast : ∀{ ε τ1 τ2 } → ε evalctx → ε ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ evalctx -- d is the result of filling the hole in ε with d' data _==_⟦_⟧ : (d : ihexp) (ε : ectx) (d' : ihexp) → Set where FHOuter : ∀{d} → d == ⊙ ⟦ d ⟧ FHAp1 : ∀{d1 d1' d2 ε} → d1 == ε ⟦ d1' ⟧ → (d1 ∘ d2) == (ε ∘₁ d2) ⟦ d1' ⟧ FHAp2 : ∀{d1 d2 d2' ε} → -- d1 final → -- red brackets d2 == ε ⟦ d2' ⟧ → (d1 ∘ d2) == (d1 ∘₂ ε) ⟦ d2' ⟧ FHNEHole : ∀{ d d' ε u σ} → d == ε ⟦ d' ⟧ → ⦇⌜ d ⌟⦈⟨ (u , σ ) ⟩ == ⦇⌜ ε ⌟⦈⟨ (u , σ ) ⟩ ⟦ d' ⟧ FHCast : ∀{ d d' ε τ1 τ2 } → d == ε ⟦ d' ⟧ → d ⟨ τ1 ⇒ τ2 ⟩ == ε ⟨ τ1 ⇒ τ2 ⟩ ⟦ d' ⟧ FHFailedCast : ∀{ d d' ε τ1 τ2} → d == ε ⟦ d' ⟧ → (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) == (ε ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) ⟦ d' ⟧ -- matched ground types data _▸gnd_ : htyp → htyp → Set where MGArr : ∀{τ1 τ2} → (τ1 ==> τ2) ≠ (⦇-⦈ ==> ⦇-⦈) → (τ1 ==> τ2) ▸gnd (⦇-⦈ ==> ⦇-⦈) -- instruction transition judgement data _→>_ : (d d' : ihexp) → Set where ITLam : ∀{ x τ d1 d2 } → -- d2 final → -- red brackets ((·λ x [ τ ] d1) ∘ d2) →> ([ d2 / x ] d1) ITCastID : ∀{d τ } → -- d final → -- red brackets (d ⟨ τ ⇒ τ ⟩) →> d ITCastSucceed : ∀{d τ } → -- d final → -- red brackets τ ground → (d ⟨ τ ⇒ ⦇-⦈ ⇒ τ ⟩) →> d ITCastFail : ∀{ d τ1 τ2} → -- d final → -- red brackets τ1 ground → τ2 ground → τ1 ≠ τ2 → (d ⟨ τ1 ⇒ ⦇-⦈ ⇒ τ2 ⟩) →> (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) ITApCast : ∀{d1 d2 τ1 τ2 τ1' τ2' } → -- d1 final → -- red brackets -- d2 final → -- red brackets ((d1 ⟨ (τ1 ==> τ2) ⇒ (τ1' ==> τ2')⟩) ∘ d2) →> ((d1 ∘ (d2 ⟨ τ1' ⇒ τ1 ⟩)) ⟨ τ2 ⇒ τ2' ⟩) ITGround : ∀{ d τ τ'} → -- d final → -- red brackets τ ▸gnd τ' → (d ⟨ τ ⇒ ⦇-⦈ ⟩) →> (d ⟨ τ ⇒ τ' ⇒ ⦇-⦈ ⟩) ITExpand : ∀{d τ τ' } → -- d final → -- red brackets τ ▸gnd τ' → (d ⟨ ⦇-⦈ ⇒ τ ⟩) →> (d ⟨ ⦇-⦈ ⇒ τ' ⇒ τ ⟩) -- single step (in contextual evaluation sense) data _↦_ : (d d' : ihexp) → Set where Step : ∀{ d d0 d' d0' ε} → d == ε ⟦ d0 ⟧ → d0 →> d0' → d' == ε ⟦ d0' ⟧ → d ↦ d' -- reflexive transitive closure of single steps into multi steps data _↦*_ : (d d' : ihexp) → Set where MSRefl : ∀{d} → d ↦* d MSStep : ∀{d d' d''} → d ↦ d' → d' ↦* d'' → d ↦* d'' -- freshness mutual -- ... with respect to a hole context data envfresh : Nat → env → Set where EFId : ∀{x Γ} → x # Γ → envfresh x (Id Γ) EFSubst : ∀{x d σ y} → fresh x d → envfresh x σ → x ≠ y → envfresh x (Subst d y σ) -- ... for inernal expressions data fresh : Nat → ihexp → Set where FConst : ∀{x} → fresh x c FVar : ∀{x y} → x ≠ y → fresh x (X y) FLam : ∀{x y τ d} → x ≠ y → fresh x d → fresh x (·λ y [ τ ] d) FHole : ∀{x u σ} → envfresh x σ → fresh x (⦇-⦈⟨ u , σ ⟩) FNEHole : ∀{x d u σ} → envfresh x σ → fresh x d → fresh x (⦇⌜ d ⌟⦈⟨ u , σ ⟩) FAp : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x (d1 ∘ d2) FCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒ τ2 ⟩) FFailedCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) -- ... for external expressions data freshh : Nat → hexp → Set where FRHConst : ∀{x} → freshh x c FRHAsc : ∀{x e τ} → freshh x e → freshh x (e ·: τ) FRHVar : ∀{x y} → x ≠ y → freshh x (X y) FRHLam1 : ∀{x y e} → x ≠ y → freshh x e → freshh x (·λ y e) FRHLam2 : ∀{x τ e y} → x ≠ y → freshh x e → freshh x (·λ y [ τ ] e) FRHEHole : ∀{x u} → freshh x (⦇-⦈[ u ]) FRHNEHole : ∀{x u e} → freshh x e → freshh x (⦇⌜ e ⌟⦈[ u ]) FRHAp : ∀{x e1 e2} → freshh x e1 → freshh x e2 → freshh x (e1 ∘ e2) -- x is not used in a binding site in d mutual data unbound-in-σ : Nat → env → Set where UBσId : ∀{x Γ} → unbound-in-σ x (Id Γ) UBσSubst : ∀{x d y σ} → unbound-in x d → unbound-in-σ x σ → x ≠ y → unbound-in-σ x (Subst d y σ) data unbound-in : (x : Nat) (d : ihexp) → Set where UBConst : ∀{x} → unbound-in x c UBVar : ∀{x y} → unbound-in x (X y) UBLam2 : ∀{x d y τ} → x ≠ y → unbound-in x d → unbound-in x (·λ_[_]_ y τ d) UBHole : ∀{x u σ} → unbound-in-σ x σ → unbound-in x (⦇-⦈⟨ u , σ ⟩) UBNEHole : ∀{x u σ d } → unbound-in-σ x σ → unbound-in x d → unbound-in x (⦇⌜ d ⌟⦈⟨ u , σ ⟩) UBAp : ∀{ x d1 d2 } → unbound-in x d1 → unbound-in x d2 → unbound-in x (d1 ∘ d2) UBCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒ τ2 ⟩) UBFailedCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) mutual data binders-disjoint-σ : env → ihexp → Set where BDσId : ∀{Γ d} → binders-disjoint-σ (Id Γ) d BDσSubst : ∀{d1 d2 y σ} → binders-disjoint d1 d2 → binders-disjoint-σ σ d2 → binders-disjoint-σ (Subst d1 y σ) d2 -- two terms that do not share any binders data binders-disjoint : (d1 : ihexp) → (d2 : ihexp) → Set where BDConst : ∀{d} → binders-disjoint c d BDVar : ∀{x d} → binders-disjoint (X x) d BDLam : ∀{x τ d1 d2} → binders-disjoint d1 d2 → unbound-in x d2 → binders-disjoint (·λ_[_]_ x τ d1) d2 BDHole : ∀{u σ d2} → binders-disjoint-σ σ d2 → binders-disjoint (⦇-⦈⟨ u , σ ⟩) d2 BDNEHole : ∀{u σ d1 d2} → binders-disjoint-σ σ d2 → binders-disjoint d1 d2 → binders-disjoint (⦇⌜ d1 ⌟⦈⟨ u , σ ⟩) d2 BDAp : ∀{d1 d2 d3} → binders-disjoint d1 d3 → binders-disjoint d2 d3 → binders-disjoint (d1 ∘ d2) d3 BDCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒ τ2 ⟩) d2 BDFailedCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) d2 mutual -- each term has to be binders unique, and they have to be pairwise -- disjoint with the collection of bound vars data binders-unique-σ : env → Set where BUσId : ∀{Γ} → binders-unique-σ (Id Γ) BUσSubst : ∀{d y σ} → binders-unique d → binders-unique-σ σ → binders-disjoint-σ σ d → binders-unique-σ (Subst d y σ) -- all the variable names in the term are unique data binders-unique : ihexp → Set where BUHole : binders-unique c BUVar : ∀{x} → binders-unique (X x) BULam : {x : Nat} {τ : htyp} {d : ihexp} → binders-unique d → unbound-in x d → binders-unique (·λ_[_]_ x τ d) BUEHole : ∀{u σ} → binders-unique-σ σ → binders-unique (⦇-⦈⟨ u , σ ⟩) BUNEHole : ∀{u σ d} → binders-unique d → binders-unique-σ σ → binders-unique (⦇⌜ d ⌟⦈⟨ u , σ ⟩) BUAp : ∀{d1 d2} → binders-unique d1 → binders-unique d2 → binders-disjoint d1 d2 → binders-unique (d1 ∘ d2) BUCast : ∀{d τ1 τ2} → binders-unique d → binders-unique (d ⟨ τ1 ⇒ τ2 ⟩) BUFailedCast : ∀{d τ1 τ2} → binders-unique d → binders-unique (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩)
{ "alphanum_fraction": 0.403398336, "avg_line_length": 38.3086003373, "ext": "agda", "hexsha": "be735f542f738cdfe53b40cde8056462739742a4", "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": "core.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": "core.agda", "max_line_length": 105, "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": "core.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": 9551, "size": 22717 }
{-# OPTIONS --rewriting #-} module Luau.TypeCheck where open import Agda.Builtin.Equality using (_≡_) open import FFI.Data.Maybe using (Maybe; just) open import Luau.Syntax using (Expr; Stat; Block; BinaryOperator; yes; nil; addr; number; bool; string; val; var; var_∈_; _⟨_⟩∈_; function_is_end; _$_; block_is_end; binexp; local_←_; _∙_; done; return; name; +; -; *; /; <; >; ==; ~=; <=; >=; ··) open import Luau.Var using (Var) open import Luau.Addr using (Addr) open import Luau.Heap using (Heap; Object; function_is_end) renaming (_[_] to _[_]ᴴ) open import Luau.Type using (Type; nil; unknown; number; boolean; string; _⇒_; src; tgt) open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_) renaming (_[_] to _[_]ⱽ) open import FFI.Data.Vector using (Vector) open import FFI.Data.Maybe using (Maybe; just; nothing) open import Properties.Product using (_×_; _,_) orUnknown : Maybe Type → Type orUnknown nothing = unknown orUnknown (just T) = T srcBinOp : BinaryOperator → Type srcBinOp + = number srcBinOp - = number srcBinOp * = number srcBinOp / = number srcBinOp < = number srcBinOp > = number srcBinOp == = unknown srcBinOp ~= = unknown srcBinOp <= = number srcBinOp >= = number srcBinOp ·· = string tgtBinOp : BinaryOperator → Type tgtBinOp + = number tgtBinOp - = number tgtBinOp * = number tgtBinOp / = number tgtBinOp < = boolean tgtBinOp > = boolean tgtBinOp == = boolean tgtBinOp ~= = boolean tgtBinOp <= = boolean tgtBinOp >= = boolean tgtBinOp ·· = string data _⊢ᴮ_∈_ : VarCtxt → Block yes → Type → Set data _⊢ᴱ_∈_ : VarCtxt → Expr yes → Type → Set data _⊢ᴮ_∈_ where done : ∀ {Γ} → --------------- Γ ⊢ᴮ done ∈ nil return : ∀ {M B T U Γ} → Γ ⊢ᴱ M ∈ T → Γ ⊢ᴮ B ∈ U → --------------------- Γ ⊢ᴮ return M ∙ B ∈ T local : ∀ {x M B T U V Γ} → Γ ⊢ᴱ M ∈ U → (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V → -------------------------------- Γ ⊢ᴮ local var x ∈ T ← M ∙ B ∈ V function : ∀ {f x B C T U V W Γ} → (Γ ⊕ x ↦ T) ⊢ᴮ C ∈ V → (Γ ⊕ f ↦ (T ⇒ U)) ⊢ᴮ B ∈ W → ------------------------------------------------- Γ ⊢ᴮ function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B ∈ W data _⊢ᴱ_∈_ where nil : ∀ {Γ} → -------------------- Γ ⊢ᴱ (val nil) ∈ nil var : ∀ {x T Γ} → T ≡ orUnknown(Γ [ x ]ⱽ) → ---------------- Γ ⊢ᴱ (var x) ∈ T addr : ∀ {a Γ} T → ----------------- Γ ⊢ᴱ val(addr a) ∈ T number : ∀ {n Γ} → --------------------------- Γ ⊢ᴱ val(number n) ∈ number bool : ∀ {b Γ} → -------------------------- Γ ⊢ᴱ val(bool b) ∈ boolean string : ∀ {x Γ} → --------------------------- Γ ⊢ᴱ val(string x) ∈ string app : ∀ {M N T U Γ} → Γ ⊢ᴱ M ∈ T → Γ ⊢ᴱ N ∈ U → ---------------------- Γ ⊢ᴱ (M $ N) ∈ (tgt T) function : ∀ {f x B T U V Γ} → (Γ ⊕ x ↦ T) ⊢ᴮ B ∈ V → ----------------------------------------------------- Γ ⊢ᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) ∈ (T ⇒ U) block : ∀ {b B T U Γ} → Γ ⊢ᴮ B ∈ U → ------------------------------------ Γ ⊢ᴱ (block var b ∈ T is B end) ∈ T binexp : ∀ {op Γ M N T U} → Γ ⊢ᴱ M ∈ T → Γ ⊢ᴱ N ∈ U → ---------------------------------- Γ ⊢ᴱ (binexp M op N) ∈ tgtBinOp op data ⊢ᴼ_ : Maybe(Object yes) → Set where nothing : --------- ⊢ᴼ nothing function : ∀ {f x T U V B} → (x ↦ T) ⊢ᴮ B ∈ V → ---------------------------------------------- ⊢ᴼ (just function f ⟨ var x ∈ T ⟩∈ U is B end) ⊢ᴴ_ : Heap yes → Set ⊢ᴴ H = ∀ a {O} → (H [ a ]ᴴ ≡ O) → (⊢ᴼ O) _⊢ᴴᴱ_▷_∈_ : VarCtxt → Heap yes → Expr yes → Type → Set (Γ ⊢ᴴᴱ H ▷ M ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴱ M ∈ T) _⊢ᴴᴮ_▷_∈_ : VarCtxt → Heap yes → Block yes → Type → Set (Γ ⊢ᴴᴮ H ▷ B ∈ T) = (⊢ᴴ H) × (Γ ⊢ᴮ B ∈ T)
{ "alphanum_fraction": 0.4704453441, "avg_line_length": 23.4493670886, "ext": "agda", "hexsha": "cabd27a8a04d41c983b5db68562b49cebaf72a1a", "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": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MeltzDev/luau", "max_forks_repo_path": "prototyping/Luau/TypeCheck.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "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": "MeltzDev/luau", "max_issues_repo_path": "prototyping/Luau/TypeCheck.agda", "max_line_length": 246, "max_stars_count": null, "max_stars_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MeltzDev/luau", "max_stars_repo_path": "prototyping/Luau/TypeCheck.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1495, "size": 3705 }
module Pi.Syntax where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product infixr 12 _×ᵤ_ infixr 11 _+ᵤ_ infixr 50 _⨾_ infixr 10 _↔_ infix 99 !_ -- Types data 𝕌 : Set where 𝟘 : 𝕌 𝟙 : 𝕌 _+ᵤ_ : 𝕌 → 𝕌 → 𝕌 _×ᵤ_ : 𝕌 → 𝕌 → 𝕌 ⟦_⟧ : (A : 𝕌) → Set ⟦ 𝟘 ⟧ = ⊥ ⟦ 𝟙 ⟧ = ⊤ ⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧ ⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧ -- Combinators data _↔_ : 𝕌 → 𝕌 → Set where unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ↔ t uniti₊l : {t : 𝕌} → t ↔ 𝟘 +ᵤ t swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ↔ t₂ +ᵤ t₁ assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ↔ (t₁ +ᵤ t₂) +ᵤ t₃ assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ↔ t₁ +ᵤ (t₂ +ᵤ t₃) unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ↔ t uniti⋆l : {t : 𝕌} → t ↔ 𝟙 ×ᵤ t swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ↔ t₂ ×ᵤ t₁ assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ↔ (t₁ ×ᵤ t₂) ×ᵤ t₃ assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ↔ t₁ ×ᵤ (t₂ ×ᵤ t₃) absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ↔ 𝟘 factorzl : {t : 𝕌} → 𝟘 ↔ 𝟘 ×ᵤ t dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ↔ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ↔ (t₁ +ᵤ t₂) ×ᵤ t₃ id↔ : {t : 𝕌} → t ↔ t _⨾_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ↔ t₂) → (t₂ ↔ t₃) → (t₁ ↔ t₃) _⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ↔ t₃) → (t₂ ↔ t₄) → (t₁ +ᵤ t₂ ↔ t₃ +ᵤ t₄) _⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ↔ t₃) → (t₂ ↔ t₄) → (t₁ ×ᵤ t₂ ↔ t₃ ×ᵤ t₄) -- Some useful combinators unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ↔ t unite₊r = swap₊ ⨾ unite₊l uniti₊r : {t : 𝕌} → t ↔ t +ᵤ 𝟘 uniti₊r = uniti₊l ⨾ swap₊ unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ↔ t unite⋆r = swap⋆ ⨾ unite⋆l uniti⋆r : {t : 𝕌} → t ↔ t ×ᵤ 𝟙 uniti⋆r = uniti⋆l ⨾ swap⋆ absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ↔ 𝟘 absorbl = swap⋆ ⨾ absorbr factorzr : {t : 𝕌} → 𝟘 ↔ t ×ᵤ 𝟘 factorzr = factorzl ⨾ swap⋆ distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ↔ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) distl = swap⋆ ⨾ dist ⨾ (swap⋆ ⊕ swap⋆) factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ↔ t₁ ×ᵤ (t₂ +ᵤ t₃) factorl = (swap⋆ ⊕ swap⋆) ⨾ factor ⨾ swap⋆ -- Inverses of combinators !_ : {A B : 𝕌} → A ↔ B → B ↔ A ! unite₊l = uniti₊l ! uniti₊l = unite₊l ! swap₊ = swap₊ ! assocl₊ = assocr₊ ! assocr₊ = assocl₊ ! unite⋆l = uniti⋆l ! uniti⋆l = unite⋆l ! swap⋆ = swap⋆ ! assocl⋆ = assocr⋆ ! assocr⋆ = assocl⋆ ! absorbr = factorzl ! factorzl = absorbr ! dist = factor ! factor = dist ! id↔ = id↔ ! (c₁ ⨾ c₂) = ! c₂ ⨾ ! c₁ ! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂) ! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
{ "alphanum_fraction": 0.4647540984, "avg_line_length": 26.5217391304, "ext": "agda", "hexsha": "87edbfe6686fef728f60ad7e3ef17cb95834a44f", "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": "Pi/Syntax.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": "Pi/Syntax.agda", "max_line_length": 78, "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": "Pi/Syntax.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": 1709, "size": 2440 }
module Automata.Nondeterministic where -- Standard libraries imports ---------------------------------------- open import Level using () renaming (zero to ℓ₀) open import Data.Nat using (ℕ) open import Data.Product using (_×_) open import Data.Vec using (Vec ; [] ; _∷_) open import Relation.Unary using (Pred) open import Relation.Binary.PropositionalEquality using (_≡_) ---------------------------------------------------------------------- -- Thesis imports ---------------------------------------------------- open import Utilities.ExistsSyntax using (∃-syntax) ---------------------------------------------------------------------- record NDA (Σ : Set) : Set₁ where constructor ⟨_,_,_,_⟩ field Q : Set S : Pred Q ℓ₀ F : Pred Q ℓ₀ Δ : Q → Σ → Pred Q ℓ₀ Δ* : Q → {n : ℕ} → Vec Σ n → Pred Q ℓ₀ Δ* q [] = q ≡_ Δ* q (x ∷ xs) q′ = ∃ q₀ ∶ Q • ((Δ q x q₀) × (Δ* q₀ xs q′)) Accepts : {n : ℕ} → Pred (Vec Σ n) ℓ₀ Accepts xs = ∃ q ∶ Q • (S q × ∃ q′ ∶ Q • ((F q′) × (Δ* q xs q′))) -- :TODO: are these useful? _-Reachable : ℕ → Q → Pred Q ℓ₀ _-Reachable n q q′ = ∃ xs ∶ Vec Σ n • (Δ* q xs q′) Reachable : Q → Pred Q ℓ₀ Reachable q q′ = ∃ n ∶ ℕ • (n -Reachable) q q′
{ "alphanum_fraction": 0.4495268139, "avg_line_length": 29.488372093, "ext": "agda", "hexsha": "eede442ed51371b5c4e3a3e5e8e5bff07690cb31", "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": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "armkeh/agda-computability", "max_forks_repo_path": "src/Automata/Nondeterministic.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "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": "armkeh/agda-computability", "max_issues_repo_path": "src/Automata/Nondeterministic.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "armkeh/agda-computability", "max_stars_repo_path": "src/Automata/Nondeterministic.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 394, "size": 1268 }
module ByteCount where open import Agda.Builtin.Word {-# FOREIGN GHC import Foreign.C.Types #-} postulate CSize : Set mkCSize : Word64 → CSize {-# COMPILE GHC CSize = type CSize #-} {-# COMPILE GHC mkCSize = CSize #-} ByteCount : Set ByteCount = CSize
{ "alphanum_fraction": 0.69348659, "avg_line_length": 16.3125, "ext": "agda", "hexsha": "c221676ee16e4ffdbddf2e92fbe3c8d2312f24e8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda-editor", "max_forks_repo_path": "src/ByteCount.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda-editor", "max_issues_repo_path": "src/ByteCount.agda", "max_line_length": 42, "max_stars_count": null, "max_stars_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda-editor", "max_stars_repo_path": "src/ByteCount.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 74, "size": 261 }
------------------------------------------------------------------------ -- Primitive IO: simple bindings to Haskell types and functions ------------------------------------------------------------------------ module IO.Primitive where open import Data.String hiding (Costring) open import Data.Char open import Foreign.Haskell ------------------------------------------------------------------------ -- The IO monad postulate IO : Set → Set {-# COMPILED_TYPE IO IO #-} infixl 1 _>>=_ postulate return : ∀ {A} → A → IO A _>>=_ : ∀ {A B} → IO A → (A → IO B) → IO B {-# COMPILED return (\_ -> return :: a -> IO a) #-} {-# COMPILED _>>=_ (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-} ------------------------------------------------------------------------ -- Simple lazy IO (UTF8-based) private Costring = Colist Char postulate getContents : IO Costring readFile : String → IO Costring writeFile : String → Costring → IO Unit putStr : Costring → IO Unit putStrLn : Costring → IO Unit {-# IMPORT System.IO.UTF8 #-} {-# COMPILED getContents System.IO.UTF8.getContents #-} {-# COMPILED readFile System.IO.UTF8.readFile #-} {-# COMPILED writeFile System.IO.UTF8.writeFile #-} {-# COMPILED putStr System.IO.UTF8.putStr #-} {-# COMPILED putStrLn System.IO.UTF8.putStrLn #-}
{ "alphanum_fraction": 0.4888226528, "avg_line_length": 28.5531914894, "ext": "agda", "hexsha": "27cc94399fa04774b156569aa58a40a7749d3a7f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/IO/Primitive.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/IO/Primitive.agda", "max_line_length": 72, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/IO/Primitive.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 315, "size": 1342 }
{-# OPTIONS --cubical -van-extra-option-just-to-test-a-hack:0 #-}
{ "alphanum_fraction": 0.6666666667, "avg_line_length": 33, "ext": "agda", "hexsha": "fd613ccbdfd1f3f463509668ed6f61efbc3b2ca6", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "cagix/agda", "max_forks_repo_path": "test/Compiler/simple/Cubical-is-not-supported.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "cagix/agda", "max_issues_repo_path": "test/Compiler/simple/Cubical-is-not-supported.agda", "max_line_length": 65, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "cagix/agda", "max_stars_repo_path": "test/Compiler/simple/Cubical-is-not-supported.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": 20, "size": 66 }
open import Function using (_$_) open import Relation.Nullary using (yes; no) open import Relation.Binary using (Decidable; Irrelevant; Antisymmetric; Setoid) open import AKS.Algebra.Bundles using (NonZeroCommutativeRing; Field) module AKS.Algebra.Consequences {c ℓ} (R : NonZeroCommutativeRing c ℓ) where open import AKS.Nat using (ℕ) open import Algebra.Bundles using (CommutativeRing) open NonZeroCommutativeRing R using (_+_; _*_; -_; _-_; 0#; 1#) renaming (Carrier to C) open NonZeroCommutativeRing R using (_≈_; _≉_; setoid) open Setoid setoid using (refl; sym) open import Relation.Binary.Reasoning.Setoid setoid open NonZeroCommutativeRing R using (isNonZeroCommutativeRing; commutativeRing) open CommutativeRing commutativeRing using (+-identityʳ; +-assoc; +-comm; +-congʳ; +-congˡ; +-cong; -‿cong; -‿inverseʳ) open CommutativeRing commutativeRing using (*-identityˡ; *-cong; *-congʳ; *-congˡ; *-assoc; *-comm; zeroʳ; zeroˡ; commutativeSemiring) open import AKS.Algebra.Structures C _≈_ using (IsField; IsEuclideanDomain; module Modulus; module Divisibility; IsIntegralDomain; IsGCDDomain; IsUniqueFactorizationDomain) open import AKS.Algebra.Divisibility commutativeSemiring using (module Euclidean) open Modulus using (Remainder; 0≈) open Divisibility _*_ using (_∣_; divides) module Division⇒EuclideanDomain (_≈?_ : Decidable _≈_) (≈-irrelevant : Irrelevant _≈_) (≉-irrelevant : Irrelevant _≉_) (∣_∣ : ∀ n {n≉0 : n ≉ 0#} → ℕ) (_div_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C) (_mod_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C) (division : ∀ n m {m≉0 : m ≉ 0#} → n ≈ m * (n div m) {m≉0} + (n mod m) {m≉0}) (modulus : ∀ n m {m≉0 : m ≉ 0#} → Remainder 0# ∣_∣ _mod_ n m {m≉0}) (div-cong : ∀ {x₁ x₂} {y₁ y₂} → x₁ ≈ x₂ → y₁ ≈ y₂ → ∀ {y₁≉0 y₂≉0} → (x₁ div y₁) {y₁≉0} ≈ (x₂ div y₂) {y₂≉0}) (mod-distribʳ-* : ∀ c a b {b≉0} {b*c≉0} → ((a * c) mod (b * c)) {b*c≉0} ≈ (a mod b) {b≉0} * c) (*-cancelˡ : ∀ x {y z} → x ≉ 0# → x * y ≈ x * z → y ≈ z) where private remainder : ∀ n m {m≉0 : m ≉ 0#} → (n mod m) {m≉0} ≈ n - m * (n div m) {m≉0} remainder n m {m≉0} = begin n mod m ≈⟨ sym (+-identityʳ (n mod m)) ⟩ n mod m + 0# ≈⟨ +-congˡ (sym (-‿inverseʳ (m * n div m))) ⟩ n mod m + (m * n div m - m * n div m) ≈⟨ sym (+-assoc (n mod m) (m * n div m) (- (m * n div m))) ⟩ (n mod m + m * n div m) - m * n div m ≈⟨ +-congʳ (+-comm (n mod m) (m * n div m)) ⟩ (m * n div m + n mod m) - m * n div m ≈⟨ +-congʳ (sym (division n m {m≉0})) ⟩ n - m * n div m ∎ mod-cong : ∀ {x₁ x₂} {y₁ y₂} → x₁ ≈ x₂ → y₁ ≈ y₂ → ∀ {y₁≉0 y₂≉0} → (x₁ mod y₁) {y₁≉0} ≈ (x₂ mod y₂) {y₂≉0} mod-cong {x₁} {x₂} {y₁} {y₂} x₁≈x₂ y₁≈y₂ {y₁≉0} {y₂≉0} = begin x₁ mod y₁ ≈⟨ remainder x₁ y₁ {y₁≉0} ⟩ x₁ - y₁ * x₁ div y₁ ≈⟨ +-cong x₁≈x₂ (-‿cong (*-cong y₁≈y₂ (div-cong x₁≈x₂ y₁≈y₂))) ⟩ x₂ - y₂ * x₂ div y₂ ≈⟨ sym (remainder x₂ y₂ {y₂≉0}) ⟩ x₂ mod y₂ ∎ open Euclidean ∣_∣ _div_ _mod_ _≈?_ ≈-irrelevant ≉-irrelevant division modulus mod-cong mod-distribʳ-* using (gcd; gcd-isGCD) public isIntegralDomain : IsIntegralDomain _+_ _*_ -_ 0# 1# isIntegralDomain = record { isNonZeroCommutativeRing = isNonZeroCommutativeRing; *-cancelˡ = *-cancelˡ } isGCDDomain : IsGCDDomain _+_ _*_ -_ 0# 1# gcd isGCDDomain = record { isIntegralDomain = isIntegralDomain; gcd-isGCD = gcd-isGCD } isUniqueFactorizationDomain : IsUniqueFactorizationDomain _+_ _*_ -_ 0# 1# gcd isUniqueFactorizationDomain = record { isGCDDomain = isGCDDomain } isEuclideanDomain : IsEuclideanDomain _+_ _*_ -_ 0# 1# ∣_∣ _div_ _mod_ gcd isEuclideanDomain = record { isUniqueFactorizationDomain = isUniqueFactorizationDomain ; division = division ; modulus = modulus ; div-cong = div-cong ; mod-cong = mod-cong } module Inverse⇒Field (_≈?_ : Decidable _≈_) (≈-irrelevant : Irrelevant _≈_) (≉-irrelevant : Irrelevant _≉_) (_/_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C) (inverse : ∀ (n m : C) {m≉0 : m ≉ 0#} → n ≈ m * (n / m) {m≉0}) where private ∣_∣ : ∀ n {n≉0 : n ≉ 0#} → ℕ ∣ _ ∣ = 0 _mod_ : ∀ (n m : C) {m≉0 : m ≉ 0#} → C _ mod _ = 0# division : ∀ n m {m≉0 : m ≉ 0#} → n ≈ m * (n / m) {m≉0} + (n mod m) {m≉0} division n m {m≉0} = begin n ≈⟨ inverse n m {m≉0} ⟩ m * (n / m) ≈⟨ sym (+-identityʳ (m * (n / m))) ⟩ m * (n / m) {m≉0} + (n mod m) {m≉0} ∎ modulus : ∀ n m {m≉0 : m ≉ 0#} → Remainder 0# ∣_∣ _mod_ n m {m≉0} modulus _ _ = 0≈ refl *-cancelˡ : ∀ x {y z} → x ≉ 0# → x * y ≈ x * z → y ≈ z *-cancelˡ x {y} {z} x≢0 x*y≡x*z = begin y ≈⟨ sym (*-identityˡ y) ⟩ 1# * y ≈⟨ *-congʳ (inverse 1# x {x≢0}) ⟩ (x * (1# / x)) * y ≈⟨ *-congʳ (*-comm x (1# / x)) ⟩ ((1# / x) * x) * y ≈⟨ *-assoc _ _ _ ⟩ (1# / x) * (x * y) ≈⟨ *-congˡ x*y≡x*z ⟩ (1# / x) * (x * z) ≈⟨ sym (*-assoc _ _ _) ⟩ ((1# / x) * x) * z ≈⟨ *-congʳ (*-comm (1# / x) x) ⟩ (x * (1# / x)) * z ≈⟨ *-congʳ (sym (inverse 1# x {x≢0})) ⟩ 1# * z ≈⟨ *-identityˡ z ⟩ z ∎ div-cong : ∀ {x₁ x₂} {y₁ y₂} → x₁ ≈ x₂ → y₁ ≈ y₂ → ∀ {y₁≉0 y₂≉0} → (x₁ / y₁) {y₁≉0} ≈ (x₂ / y₂) {y₂≉0} div-cong {x₁} {x₂} {y₁} {y₂} x₁≈x₂ y₁≈y₂ {y₁≉0} {y₂≉0} = *-cancelˡ y₁ y₁≉0 $ begin y₁ * (x₁ / y₁) ≈⟨ sym (inverse x₁ y₁) ⟩ x₁ ≈⟨ x₁≈x₂ ⟩ x₂ ≈⟨ inverse x₂ y₂ ⟩ y₂ * (x₂ / y₂) ≈⟨ *-congʳ (sym y₁≈y₂) ⟩ y₁ * (x₂ / y₂) ∎ mod-distribʳ-* : ∀ c a b {b≉0} {b*c≉0} → ((a * c) mod (b * c)) {b*c≉0} ≈ (a mod b) {b≉0} * c mod-distribʳ-* c a b = sym (zeroˡ c) open Division⇒EuclideanDomain _≈?_ ≈-irrelevant ≉-irrelevant ∣_∣ _/_ _mod_ division modulus div-cong mod-distribʳ-* *-cancelˡ using (gcd; isEuclideanDomain) public isField : IsField _+_ _*_ -_ 0# 1# _/_ gcd isField = record { isEuclideanDomain = isEuclideanDomain } [field] : Field c ℓ [field] = record { isField = isField }
{ "alphanum_fraction": 0.5446652196, "avg_line_length": 45.7175572519, "ext": "agda", "hexsha": "8d5f999fda8f6ce5b4dc6a3426c5fadc5fe4ad9c", "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": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_path": "proofs/AKS/Algebra/Consequences.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "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": "mckeankylej/thesis", "max_issues_repo_path": "proofs/AKS/Algebra/Consequences.agda", "max_line_length": 172, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_path": "proofs/AKS/Algebra/Consequences.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "num_tokens": 2787, "size": 5989 }
------------------------------------------------------------------------------ -- Natural numbers (PCF version) ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LTC-PCF.Data.Nat where open import LTC-PCF.Base open import LTC-PCF.Data.Nat.Rec open import LTC-PCF.Data.Nat.Type public infixl 7 _*_ infixl 6 _+_ _∸_ ------------------------------------------------------------------------------ -- Addition with recursion on the first argument. _+_ : D → D → D m + n = rec m n (lam (λ _ → lam succ₁)) -- Subtraction with recursion on the second argument. _∸_ : D → D → D m ∸ n = rec n m (lam (λ _ → lam pred₁)) -- Multiplication with recursion on the first argument. _*_ : D → D → D m * n = rec m zero (lam (λ _ → lam (λ x → n + x)))
{ "alphanum_fraction": 0.4551214361, "avg_line_length": 30.5483870968, "ext": "agda", "hexsha": "12acfb527cbd86c9aa451e0dc5cc4f51aa52347e", "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/LTC-PCF/Data/Nat.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/LTC-PCF/Data/Nat.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/LTC-PCF/Data/Nat.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": 221, "size": 947 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module CombiningProofs.Erasing where postulate D : Set succ₁ : D → D data N : D → Set where nsucc₁ : ∀ {n} → N n → N (succ₁ n) nsucc₂ : ∀ {n} → (Nn : N n) → N (succ₁ n) -- The types of nsucc₁ and nsucc₂ are the same. -- (18 April 2013) -- $ dump-agdai Erasing -- Qname: Erasing.N.nsucc₁ -- Type: El {getSort = Type (Max []), unEl = Pi []r{El {getSort = Type (Max []), unEl = Def Erasing.D []}} (Abs "n" El {getSort = Type (Max []), unEl = Pi []r(El {getSort = Type (Max []), unEl = Def Erasing.N [[]r(Var 0 [])]}) (NoAbs "_" El {getSort = Type (Max []), unEl = Def Erasing.N [[]r(Def Erasing.succ₁ [[]r(Var 0 [])])]})})} -- Qname: Erasing.N.nsucc₂ -- Type: El {getSort = Type (Max []), unEl = Pi []r{El {getSort = Type (Max []), unEl = Def Erasing.D []}} (Abs "n" El {getSort = Type (Max []), unEl = Pi []r(El {getSort = Type (Max []), unEl = Def Erasing.N [[]r(Var 0 [])]}) (NoAbs "Nn" El {getSort = Type (Max []), unEl = Def Erasing.N [[]r(Def Erasing.succ₁ [[]r(Var 0 [])])]})})}
{ "alphanum_fraction": 0.5451448041, "avg_line_length": 45.1538461538, "ext": "agda", "hexsha": "aa13a50bf50323f2a1558993afe5a7c1366204e3", "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/thesis/report/CombiningProofs/Erasing.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/thesis/report/CombiningProofs/Erasing.agda", "max_line_length": 334, "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/thesis/report/CombiningProofs/Erasing.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": 421, "size": 1174 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Functions.Definition open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Order.WellFounded open import Semirings.Definition open import Orders.Total.Definition open import Orders.Partial.Definition open import Orders.WellFounded.Definition open import Orders.WellFounded.Induction module Sets.CantorBijection.Order where order : Rel (ℕ && ℕ) order (a ,, b) (c ,, d) = ((a +N b) <N (c +N d)) || (((a +N b) ≡ (c +N d)) && (b <N d)) totalOrder : TotalOrder (ℕ && ℕ) PartialOrder._<_ (TotalOrder.order totalOrder) = order PartialOrder.irreflexive (TotalOrder.order totalOrder) {fst ,, snd} (inl x) = exFalso (TotalOrder.irreflexive ℕTotalOrder x) PartialOrder.irreflexive (TotalOrder.order totalOrder) {fst ,, snd} (inr (_ ,, p)) = exFalso (TotalOrder.irreflexive ℕTotalOrder p) PartialOrder.<Transitive (TotalOrder.order totalOrder) {x1 ,, x2} {y1 ,, y2} {z1 ,, z2} (inl pr1) (inl pr2) = inl (TotalOrder.<Transitive ℕTotalOrder pr1 pr2) PartialOrder.<Transitive (TotalOrder.order totalOrder) {x1 ,, x2} {y1 ,, y2} {z1 ,, z2} (inl pr1) (inr (f1 ,, f2)) = inl (identityOfIndiscernablesRight _<N_ pr1 f1) PartialOrder.<Transitive (TotalOrder.order totalOrder) {x1 ,, x2} {y1 ,, y2} {z1 ,, z2} (inr (f1 ,, f2)) (inl x) = inl (identityOfIndiscernablesLeft _<N_ x (equalityCommutative f1)) PartialOrder.<Transitive (TotalOrder.order totalOrder) {x1 ,, x2} {y1 ,, y2} {z1 ,, z2} (inr (f1 ,, f2)) (inr (fst ,, snd)) = inr (transitivity f1 fst ,, TotalOrder.<Transitive ℕTotalOrder f2 snd) TotalOrder.totality totalOrder (a ,, b) (c ,, d) with TotalOrder.totality ℕTotalOrder (a +N b) (c +N d) TotalOrder.totality totalOrder (a ,, b) (c ,, d) | inl (inl x) = inl (inl (inl x)) TotalOrder.totality totalOrder (a ,, b) (c ,, d) | inl (inr x) = inl (inr (inl x)) TotalOrder.totality totalOrder (a ,, b) (c ,, d) | inr eq with TotalOrder.totality ℕTotalOrder b d TotalOrder.totality totalOrder (a ,, b) (c ,, d) | inr eq | inl (inl x) = inl (inl (inr (eq ,, x))) TotalOrder.totality totalOrder (a ,, b) (c ,, d) | inr eq | inl (inr x) = inl (inr (inr (equalityCommutative eq ,, x))) TotalOrder.totality totalOrder (a ,, b) (c ,, .b) | inr eq | inr refl rewrite canSubtractFromEqualityRight {a} {b} {c} eq = inr refl leastElement : {y : ℕ && ℕ} → order y (0 ,, 0) → False leastElement {zero ,, b} (inl ()) leastElement {zero ,, b} (inr ()) leastElement {succ a ,, b} (inl ()) leastElement {succ a ,, b} (inr ()) mustDescend : (a b t : ℕ) → order (a ,, b) (t ,, zero) → a +N b <N t mustDescend a b zero ord = exFalso (leastElement ord) mustDescend a b (succ t) (inl x) rewrite Semiring.sumZeroRight ℕSemiring t = x orderWellfounded : WellFounded order orderWellfounded (a ,, b) = access (go b a) where g0 : (c : ℕ) (y : ℕ && ℕ) → order y (c ,, 0) → Accessible order y -- We want to induct on the second entry of x here, so we decompose so as to put that first. g : (x : ℕ) → ((y : ℕ) → y <N x → (b : ℕ) (z : ℕ && ℕ) → order z (b ,, y) → Accessible order z) → (c : ℕ) (y : ℕ && ℕ) → order y (c ,, x) → Accessible order y g0 = rec <NWellfounded (λ z → (x : ℕ && ℕ) (x₁ : order x (z ,, zero)) → Accessible order x) f where p : (a b : ℕ) → a ≡ b → (a ,, zero) ≡ (b ,, zero) p a .a refl = refl f : (x : ℕ) (x₁ : (x₂ : ℕ) (x₃ : x₂ <N x) (x₄ : ℕ && ℕ) (x₅ : order x₄ (x₂ ,, zero)) → Accessible order x₄) (x₂ : ℕ && ℕ) (x₃ : order x₂ (x ,, zero)) → Accessible order x₂ f zero pr y ord = exFalso (leastElement ord) f (succ m) pr (fst ,, snd) (inl pr2) = h snd fst pr2 where go : (x : ℕ) (x₁ : (x₂ : ℕ) (x₃ : x₂ <N x) (x₄ : ℕ) (x₅ : x₄ +N x₂ <N succ (m +N zero)) → Accessible order (x₄ ,, x₂)) (x₂ : ℕ) (x₃ : x₂ +N x <N succ (m +N zero)) → Accessible order (x₂ ,, x) go bound pr2 toProve bounded with TotalOrder.totality ℕTotalOrder (toProve +N bound) (m +N 0) ... | inl (inl bl) = pr m (le 0 refl) (toProve ,, bound) (inl bl) ... | inl (inr bl) = exFalso (noIntegersBetweenXAndSuccX (m +N 0) bl bounded) go zero pr2 toProve _ | inr bl rewrite Semiring.sumZeroRight ℕSemiring m | Semiring.sumZeroRight ℕSemiring toProve = access λ i i<z → pr m (le 0 refl) i (inl (mustDescend (_&&_.fst i) (_&&_.snd i) (m +N zero) (identityOfIndiscernablesLeft order (identityOfIndiscernablesRight order i<z (p toProve (m +N 0) (transitivity bl (equalityCommutative (Semiring.sumZeroRight ℕSemiring m))))) refl))) go (succ bound) pr2 toProve _ | inr bl = access desc where desc : (i : ℕ && ℕ) → (order i (toProve ,, succ bound)) → Accessible order i desc (i1 ,, i2) (inl ord) = pr m (le zero refl) (i1 ,, i2) (inl (identityOfIndiscernablesRight _<N_ ord bl)) desc (i1 ,, i2) (inr (ord1 ,, ord2)) = pr2 i2 ord2 i1 (le 0 (applyEquality succ (transitivity ord1 bl))) h : (a : ℕ) (b : ℕ) (pr2 : b +N a <N succ m +N 0) → Accessible order (b ,, a) h = rec <NWellfounded (λ z → (x2 : ℕ) (x1 : x2 +N z <N succ (m +N zero)) → Accessible order (x2 ,, z)) go g zero _ = g0 g (succ x) pr zero (y1 ,, y2) (inl pr1) with TotalOrder.totality ℕTotalOrder (y1 +N y2) x g (succ x) pr zero (y1 ,, y2) (inl pr1) | inl (inl y1+y2<x) = pr x (le 0 refl) zero (y1 ,, y2) (inl y1+y2<x) g (succ x) pr zero (y1 ,, y2) (inl pr1) | inl (inr x<y1+y2) = exFalso (noIntegersBetweenXAndSuccX x x<y1+y2 pr1) g (succ x) pr zero (y1 ,, y2) (inl pr1) | inr y1+y2=x = access (λ y y<zs → pr x (le 0 refl) zero y (ans y y<zs)) where ans : (y : ℕ && ℕ) → order y (y1 ,, y2) → (_&&_.fst y +N _&&_.snd y <N x) || ((_&&_.fst y +N _&&_.snd y ≡ x) && (_&&_.snd y <N x)) ans (fst ,, snd) (inl x) rewrite y1+y2=x = inl x ans (zero ,, snd) (inr (a1 ,, a2)) rewrite y1+y2=x | a1 = exFalso (bad x y1 y2 y1+y2=x a2) where bad : (x y1 y2 : ℕ) → y1 +N y2 ≡ x → x <N y2 → False bad x zero y2 y1+y2=x x<y2 = TotalOrder.irreflexive ℕTotalOrder (identityOfIndiscernablesRight _<N_ x<y2 y1+y2=x) bad x (succ y1) y2 y1+y2=x x<y2 rewrite equalityCommutative y1+y2=x = TotalOrder.irreflexive ℕTotalOrder (TotalOrder.<Transitive ℕTotalOrder x<y2 (identityOfIndiscernablesRight _<N_ (addingIncreases y2 y1) (Semiring.commutative ℕSemiring y2 (succ y1)))) ans (succ fst ,, snd) (inr (a1 ,, a2)) rewrite y1+y2=x = inr (a1 ,, le fst a1) g (succ x) pr zero (zero ,, y2) (inr (fst ,, snd)) = exFalso (TotalOrder.irreflexive ℕTotalOrder (identityOfIndiscernablesLeft _<N_ snd fst)) g (succ x) pr zero (succ y1 ,, y2) (inr (fst ,, snd)) = pr y2 snd (succ (succ y1)) (succ y1 ,, y2) (inl (le 0 refl)) g (succ x) pr (succ c) y (inl z) = pr x (le 0 refl) (succ (succ c)) y (inl (identityOfIndiscernablesRight _<N_ z (applyEquality succ (transitivity (Semiring.commutative ℕSemiring c (succ x)) (applyEquality succ (Semiring.commutative ℕSemiring x c)))))) g (succ x) pr (succ c) y (inr (fst ,, snd)) with TotalOrder.totality ℕTotalOrder (_&&_.snd y) x ... | inl (inl bl) = pr x (le 0 refl) (succ (succ c)) y (inr (transitivity fst (applyEquality succ (transitivity (Semiring.commutative ℕSemiring c (succ x)) (applyEquality succ (Semiring.commutative ℕSemiring x c)))) ,, bl)) ... | inl (inr bl) = exFalso (noIntegersBetweenXAndSuccX x bl snd) g (succ x) pr (succ c) (y1 ,, .x) (inr (fst ,, _)) | inr refl with canSubtractFromEqualityRight {y1} {x} {succ (succ c)} (transitivity fst (applyEquality succ (transitivity (Semiring.commutative ℕSemiring c (succ x)) (applyEquality succ (Semiring.commutative ℕSemiring x c))))) g (succ x) pr (succ c) (.(succ (succ c)) ,, .x) (inr (_ ,, _)) | inr refl | refl = pr x (le 0 refl) (succ (succ (succ c))) (succ (succ c) ,, x) (inl (le 0 refl)) go : (a : ℕ) → (b : ℕ) → (y : ℕ && ℕ) → order y (b ,, a) → Accessible order y go = rec <NWellfounded (λ (a : ℕ) → (b : ℕ) → (y : ℕ && ℕ) → order y (b ,, a) → Accessible order y) g
{ "alphanum_fraction": 0.6151083591, "avg_line_length": 79.9504950495, "ext": "agda", "hexsha": "b6a67746782ad841134514a84d1553f16153190a", "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": "Sets/CantorBijection/Order.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": "Sets/CantorBijection/Order.agda", "max_line_length": 403, "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": "Sets/CantorBijection/Order.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": 3016, "size": 8075 }
module Basic.Axiomatic.Partial where open import Data.Bool hiding (not; if_then_else_; _∧_) open import Data.Vec hiding ([_]; _++_; split) open import Function open import Relation.Binary.PropositionalEquality open import Data.Product import Level as L open import Utils.Decidable open import Basic.AST open import Basic.BigStep {- Here we define a Hoare logic for partial correctness of While programs (chapter 6.2). The most important point here is the choice of representation for predicates. The book mention intensional and extensional approaches. In the intensional approach, we define a separate assertion language. However, the assertion language has to be powerful enough to be able to express useful properties of the program state, and it takes quite a bit of work to define such a language. An advatange of the intensional approach is that we could reuse the same assertion language to extend the object language in other ways. The book uses the extensional approach, and so do we. We go a bit further than the book though: the book has boolean predicates over the program state, while we have type theoretic "(State n → Set)" predicates. This means that our predicates can be proof-relevant and contain data, so they can express computations and transformations on states. However, the higher-order nature of the "(State n → Set)" representation of predicates also makes type inference quite hard. I attepmeted to do some correctness proofs with the Hoare logics, and it's certainly feasible, but we would need a lot more machinery and lots of helper functions to make it convenient enough. It's interesting to note that manual proof-writing is generally easier with Hoare logics than with raw semantics, but here in Agda it's the opposite: the proofs in raw semantics (see e. g. the factorial proofs in Basic.SmallStep, Basic.BigStep and Extended.FunRetRec) are pretty neat convenient, since Agda keeps track of the program state for us and hides lots of unnecessary details. Side note: we could have made our definition universe polymorphic. It would be a trivial extension; the reason we don't have it is that we don't need that much power of expression for any of our proofs. Just using "Set" suffices. -} {- Predicate combinators: these just lift conjunction and implication into the State environment. -} _∧_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → (A → Set _) _∧_ f g x = f x × g x _==>_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → Set _ _==>_ f g = ∀ {x} → f x → g x infixr 4 _,_ data 〈_〉_〈_〉 {n} : (State n → Set) → St n → (State n → Set) → Set₁ where skip : ∀ {P} → ----------------- 〈 P 〉 skip 〈 P 〉 ass : ∀ {x a P} → ---------------------------------------------- 〈 (λ s → P (s [ x ]≔ ⟦ a ⟧ᵉ s)) 〉 x := a 〈 P 〉 _,_ : ∀ {P Q R S₁ S₂} → 〈 P 〉 S₁ 〈 Q 〉 → 〈 Q 〉 S₂ 〈 R 〉 → -------------------------------- 〈 P 〉 S₁ , S₂ 〈 R 〉 if : ∀ {P Q b S₁ S₂} → 〈 (T ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₁ 〈 Q 〉 → 〈 (F ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₂ 〈 Q 〉 → -------------------------------------------------------------- 〈 P 〉 if b then S₁ else S₂ 〈 Q 〉 while : ∀ {P b S} → 〈 (T ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S 〈 P 〉 → ---------------------------------------- 〈 P 〉 while b do S 〈 (F ∘ ⟦ b ⟧ᵉ) ∧ P 〉 cons : ∀ {P' Q' P Q S} → P ==> P' → 〈 P' 〉 S 〈 Q' 〉 → Q' ==> Q → ----------------------------------------- 〈 P 〉 S 〈 Q 〉 {- A part of exercise 6.13 (associativity of statement composition with respect to our logic). -} split : ∀ {n P R}{S₁ S₂ : St n} → 〈 P 〉 S₁ , S₂ 〈 R 〉 → ∃ λ Q → (〈 P 〉 S₁ 〈 Q 〉) × (〈 Q 〉 S₂ 〈 R 〉) split (p , p₁) = _ , (p , p₁) split (cons x p y) with split p ... | Q , (p1 , p2) = Q , (cons x p1 id , cons id p2 y) ex-613a : ∀ {n P Q}{S₁ S₂ S₃ : St n} → 〈 P 〉 S₁ , (S₂ , S₃) 〈 Q 〉 → 〈 P 〉 (S₁ , S₂) , S₃ 〈 Q 〉 ex-613a (p , p₁) with split p₁ ... | _ , (p₁₁ , p₁₂) = (p , p₁₁) , p₁₂ ex-613a (cons x p x₁) = cons x (ex-613a p) x₁ ex-613b : ∀ {n P Q}{S₁ S₂ S₃ : St n} → 〈 P 〉 (S₁ , S₂) , S₃ 〈 Q 〉 → 〈 P 〉 S₁ , (S₂ , S₃) 〈 Q 〉 ex-613b (p₁ , p₂) with split p₁ ... | _ , (p₁₁ , p₁₂) = p₁₁ , (p₁₂ , p₂) ex-613b (cons x p x₁) = cons x (ex-613b p) x₁ {- Now we set out to prove soundess and completeness of our Hoare logic (see chapter 6.3). Note that we express validity of a Hoare triple in terms of the weakest liberal precondition: ⊨ₚ { P } S { Q } := (P ==> wlp S Q) This is just a notational conveneince, but for some reason I also find it pleasing to the eye. -} -- Weakest liberal precondition ------------------------------------------------------------ wlp : ∀ {n} → St n → (State n → Set) → State n → Set wlp S Q s = ∀ {s'} → ⟨ S , s ⟩⟱ s' → Q s' -- Soundness ------------------------------------------------------------ {- This proof is the same as in the book, because it's rather simple and there's not much choice. -} sound : ∀ {n}{S : St n}{P Q} → 〈 P 〉 S 〈 Q 〉 → (P ==> wlp S Q) sound skip ps skip = ps sound ass ps ass = ps sound (p , p₁) ps (run , run₁) = sound p₁ (sound p ps run) run₁ sound (if p p₁) ps (if-true x run) = sound p (x , ps) run sound (if p p₁) ps (if-false x run) = sound p₁ (x , ps) run sound (while p) ps (while-true x run run₁) = sound (while p) (sound p (x , ps) run) run₁ sound (while p) ps (while-false x) = x , ps sound (cons x p x₁) ps run = x₁ (sound p (x ps) run) -- Completeness ------------------------------------------------------------ {- This one differs from the book proof. The book proves the following: ∀ S Q → 〈 wlp S Q 〉 S 〈 Q 〉 then uses "cons" and the definition of "wlp" to infer 〈 P 〉 S 〈 Q 〉 from (P ==> wlp S Q). We instead prove completeness directly. Our job here is essentially to recurse on sub-statements, while making the postcondition of that statement equal to the weakest precondition of the following statement. As a result, the proofs for the "if_then_else_" , composition and "while" cases are all a bit simpler than the book proofs. In the case of "while", the book makes an unnecessary twist. It uses the law of excluded middle on "〈 while b do S , s' 〉⟶ s''" derivations, but there's actually no need for that. It would be indeed ugly in Agda, where we would have to assume classical logic and destroy constructivity in order to be able to write that proof. -} complete : ∀ {n}(S : St n){P Q} → (P ==> wlp S Q) → 〈 P 〉 S 〈 Q 〉 complete (x := a) f = cons (λ z → f z ass) ass id complete skip f = cons (λ z → f z skip) skip id complete (S , S₁){P}{Q} f = complete S {P} {wlp S₁ Q} (λ ps runS runS₁ → f ps (runS , runS₁)) , complete S₁ id complete (if b then S else S₁){P}{Q} f = if (complete S {(T ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} (λ {(pb , pP) → λ runS → f pP (if-true pb runS)})) (complete S₁ {(F ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} (λ {(pb , pP) → λ runS₁ → f pP (if-false pb runS₁)})) complete (while b do S){P}{Q} f = cons f (while (complete S {(T ∘ ⟦ b ⟧ᵉ) ∧ W} {W} (λ {(pb , pw) → λ runS runW → pw (while-true pb runS runW)}))) (λ {(pb , pw) → pw (while-false pb)}) where W = wlp (while b do S) Q
{ "alphanum_fraction": 0.5620932755, "avg_line_length": 33.8348623853, "ext": "agda", "hexsha": "a982e946537f634c76ff046c9b58838fa5b4edf8", "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": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_forks_repo_path": "Basic/Axiomatic/Partial.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "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": "AndrasKovacs/SemanticsWithApplications", "max_issues_repo_path": "Basic/Axiomatic/Partial.agda", "max_line_length": 103, "max_stars_count": 8, "max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_stars_repo_path": "Basic/Axiomatic/Partial.agda", "max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z", "num_tokens": 2535, "size": 7376 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.LT-Models where -- Given a fixed Lawvere Theory LT and a fixed category C, -- the Functors [LT , C] form a category. -- The proof is basically the same as that of Functors. open import Level open import Categories.Category.Core using (Category) open import Categories.Category.Cartesian.Bundle using (CartesianCategory) open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-CartesianCategory) open import Categories.NaturalTransformation using (NaturalTransformation; _∘ᵥ_) renaming (id to idN) open import Categories.NaturalTransformation.Equivalence using (_≃_; ≃-isEquivalence) open import Categories.Theory.Lawvere using (LawvereTheory; ModelsOf_In_) private variable o ℓ e o′ ℓ′ e′ : Level -- The reason the proofs below are so easy is that _∘ᵥ_ 'computes' all the way down into -- expressions in C, from which the properties follow. LT-Models : LawvereTheory ℓ e → CartesianCategory o′ ℓ′ e′ → Category (ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (ℓ ⊔ ℓ′ ⊔ e′) e′ LT-Models LT C = record { Obj = ModelsOf LT In C ; _⇒_ = λ m₁ m₂ → NaturalTransformation (ModelsOf_In_.mod m₁) (ModelsOf_In_.mod m₂) ; _≈_ = _≃_ ; id = idN ; _∘_ = _∘ᵥ_ ; assoc = assoc ; sym-assoc = sym-assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; identity² = identity² ; equiv = ≃-isEquivalence ; ∘-resp-≈ = λ eq eq′ → ∘-resp-≈ eq eq′ } where module C = CartesianCategory C using (U) open Category C.U LT-SetoidsModels : {ℓ′ e′ : Level} → LawvereTheory ℓ e → Category (ℓ ⊔ e ⊔ suc (ℓ′ ⊔ e′)) (ℓ ⊔ ℓ′ ⊔ e′) (ℓ′ ⊔ e′) LT-SetoidsModels {ℓ′ = ℓ′} {e′} LT = LT-Models LT (Setoids-CartesianCategory ℓ′ e′)
{ "alphanum_fraction": 0.6798396334, "avg_line_length": 37.9565217391, "ext": "agda", "hexsha": "dfac09952cde29acbeeda4165ead2fa1142bab6d", "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/Category/Construction/LT-Models.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/Category/Construction/LT-Models.agda", "max_line_length": 113, "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/Category/Construction/LT-Models.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": 583, "size": 1746 }
module Auto-Modules where open import Auto.Prelude hiding (cong; trans) module NonemptySet (X : Set) (x : X) where h0 : (P : X → Set) → (∀ x → P x) → Σ X P h0 = {!!} -- h0 = λ P h → Σ-i x (h x) module WithRAA (RAA : ∀ A → ¬ (¬ A) → A) where h1 : ∀ A → A ∨ ¬ A h1 = {!!} --h1 = λ A → RAA (A ∨ ((x : A) → ⊥)) (λ z → z (∨-i₂ (λ x → z (∨-i₁ x)))) module B where h2 : ∀ A → A ∨ ¬ A h2 = {!!} module A (X : Set) (x : X) where postulate AllSame : {x y : X} → x ≡ y n0 : (P : X → Set) → Σ X P → ∀ x → P x -- n0 = {!subst AllSame!} -- no solution found n0 = λ P h x → subst P (Σ.wit h) x AllSame (Σ.prf h) module B (X : Set) (x y : X) (P : X → Set) where postulate p : P x h3 : P x h3 = {!p!} -- h3 = p module Setoid (X : Set) (Eq : X → X → Set) (refl : ∀ {x} → Eq x x) (symm : ∀ {x₁ x₂} → Eq x₁ x₂ → Eq x₂ x₁) (subst : ∀ {x₁ x₂} → (P : X → Set) → Eq x₁ x₂ → P x₁ → P x₂) where cong : ∀ {x₁ x₂} → (f : X → X) → Eq x₁ x₂ → Eq (f x₁) (f x₂) cong = {!!} -- hole 4 -- cong = λ {x₁} {x₂} f z → subst (λ z₁ → Eq (f x₁) (f z₁)) z refl trans : ∀ {x₁ x₂ x₃} → Eq x₁ x₂ → Eq x₂ x₃ → Eq x₁ x₃ trans = {!!} -- hole 5 -- trans = λ {x₁} {x₂} {x₃} z z₁ → subst (Eq x₁) z₁ z
{ "alphanum_fraction": 0.4453376206, "avg_line_length": 24.88, "ext": "agda", "hexsha": "adaa96f6b723b18eb66d2d571c7066f10688b4df", "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/Auto-Modules.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/Auto-Modules.agda", "max_line_length": 74, "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/Auto-Modules.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": 575, "size": 1244 }
module Base where data True : Set where T : True data False : Set where infix 20 _*_ data _*_ (A : Set)(B : A -> Set) : Set where <_,_> : (x : A) -> B x -> A * B rel : Set -> Set1 rel A = A -> A -> Set pred : Set -> Set1 pred A = A -> Set Refl : {A : Set} -> rel A -> Set Refl {A} R = {x : A} -> R x x Sym : {A : Set} -> rel A -> Set Sym {A} R = {x y : A} -> R x y -> R y x Trans : {A : Set} -> rel A -> Set Trans {A} R = {x y z : A} -> R x y -> R y z -> R x z Map : {A : Set} -> rel A -> {B : Set} -> rel B -> pred (A -> B) Map {A} _R_ _S_ f = {x y : A} -> x R y -> f x S f y
{ "alphanum_fraction": 0.4521008403, "avg_line_length": 18.59375, "ext": "agda", "hexsha": "276ce54cb93f808c555289912277ca9e315dad8c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/univ/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/univ/Base.agda", "max_line_length": 63, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/univ/Base.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": 253, "size": 595 }
------------------------------------------------------------------------ -- Pointers to results from the paper ------------------------------------------------------------------------ -- Note that the code has evolved after the paper was published. For -- code that is closer to the paper, see the version of the code that -- is distributed with the paper. {-# OPTIONS --sized-types #-} module README.Pointers-to-results-from-the-paper where import Bisimilarity import Bisimilarity.CCS import Bisimilarity.Classical import Bisimilarity.Comparison import Bisimilarity.Delay-monad import Bisimilarity.Equational-reasoning-instances import Bisimilarity.CCS.Examples import Bisimilarity.CCS.Examples.Natural-numbers import Bisimilarity.Step import Bisimilarity.Up-to import Bisimilarity.Up-to.CCS import Bisimilarity.Up-to.Counterexamples import Bisimilarity.Weak import Bisimilarity.Weak.CCS import Bisimilarity.Weak.Delay-monad import Bisimilarity.Weak.Up-to import Delay-monad import Delay-monad.Bisimilarity import Delay-monad.Bisimilarity.Alternative import Delay-monad.Bisimilarity.Negative import Expansion import Expansion.CCS import Expansion.Delay-monad import Indexed-container import Indexed-container.Delay-monad import Labelled-transition-system import Labelled-transition-system.CCS import Labelled-transition-system.Delay-monad import Relation import Similarity import Similarity.CCS import Up-to import Up-to.Closure ------------------------------------------------------------------------ -- Section 2 -- The Delay monad. -- -- Note that, unlike the definition in the paper, this definition is -- universe-polymorphic. Similar remarks apply to many definitions -- below as well. Delay = Delay-monad.Delay Delay′ = Delay-monad.Delay′ -- The non-terminating computation never. never = Delay-monad.never -- Strong bisimilarity for the delay monad. -- -- Note that, unlike in the paper, strong bisimilarity, weak -- bisimilarity and the expansion relation are defined as a single -- family (with an extra index). [_]_∼D_ = Delay-monad.Bisimilarity.[_]_∼_ [_]_∼′D_ = Delay-monad.Bisimilarity.[_]_∼′_ -- Strong bisimilarity is transitive. -- -- (The proof is more general than the one in the paper.) transitiveˢ = Delay-monad.Bisimilarity.transitive-∼ʳ ------------------------------------------------------------------------ -- Section 3 -- Indexed containers. -- -- The paper defines indexed containers with one index type, but this -- definition uses two. Container = Indexed-container.Container ⟦_⟧ = Indexed-container.⟦_⟧ map = Indexed-container.map -- Index-preserving functions. _⊆_ = Relation._⊆_ -- The greatest fixpoint. ν = Indexed-container.ν ν′ = Indexed-container.ν′ ν-out = Indexed-container.ν-out ν-in = Indexed-container.ν-in unfold = Indexed-container.unfold -- Relation containment (_⊆_) is not antisymmetric if the index type -- is inhabited. ⊆-not-antisymmetric = Relation.⊆-not-antisymmetric -- The shapes of a container are in pointwise bijective correspondence -- with the interpretation of the container applied to the constant -- function yielding the unit type. Shape↔⟦⟧⊤ = Indexed-container.Shape↔⟦⟧⊤ -- A container corresponding to the Delay monad. DelayC = Indexed-container.Delay-monad.DelayC -- A (size-preserving) logical equivalence between the direct -- definition of the delay monad and the indirect definition using ν -- and the container DelayC. Delay⇔νDelayC = Indexed-container.Delay-monad.Delay⇔νDelayC -- Bisimilarity for ν. ν-bisimilar = Indexed-container.ν-bisimilar -- The two components of Delay⇔νDelayC {i = ∞} are inverses up to -- (strong) bisimilarity. Delay⇔νDelayC-inverses = Indexed-container.Delay-monad.Delay⇔νDelayC-inverses ------------------------------------------------------------------------ -- Section 4 -- Labelled transition systems. LTS = Labelled-transition-system.LTS -- The record type B. -- -- The type is parametrised so that it can also be used to define weak -- bisimilarity and expansion. B = Bisimilarity.Step.Step -- The container B^C, roughly as given in the paper. B^C = Bisimilarity.Step.StepC′ -- The code mainly uses another definition of B^C, built up from -- smaller building blocks, and employing a trick to make it easier -- for Agda to infer implicit arguments. B^C-code = Bisimilarity.Step.StepC -- The two definitions of B^C have interpretations that are pointwise -- logically equivalent, and in the presence of extensionality they -- are pointwise isomorphic. B^C-code↔B^C = Bisimilarity.Step.StepC↔StepC′ -- The interpretation of B^C is pointwise logically equivalent to B, -- and in the presence of extensionality they are pointwise -- isomorphic. B↔B^C = Bisimilarity.Step.Step↔StepC′ -- The traditional definition of bisimilarity. Bisimilar = Bisimilarity.Classical._∼_ -- The definition using ν. [_]_∼_ = Bisimilarity.[_]_∼_ -- The two definitions are pointwise logically equivalent. classical-and-ν-equivalent = Bisimilarity.Comparison.classical⇔coinductive -- The definition using ν′. [_]_∼′_ = Bisimilarity.[_]_∼′_ -- Derived transition relations. _⇒_ = Labelled-transition-system.LTS._⇒_ _[_]⇒_ = Labelled-transition-system.LTS._[_]⇒_ _[_]⇒̂_ = Labelled-transition-system.LTS._[_]⇒̂_ _[_]→̂_ = Labelled-transition-system.LTS._[_]⟶̂_ -- Weak bisimilarity. [_]_≈_ = Bisimilarity.Weak.[_]_≈_ -- Expansion. [_]_≳_ = Expansion.[_]_≳_ -- A general definition that can be instantiated with different -- transition relations to yield strong or weak bisimilarity or the -- expansion relation. import Bisimilarity.General -- The labelled transition system for the delay monad. delay-monad-lts = Labelled-transition-system.Delay-monad.delay-monad -- The definition of bisimilarity obtained from this LTS is pointwise -- logically equivalent to the direct definition of strong -- bisimilarity for the delay monad. delay-monad-direct⇔indirect = Bisimilarity.Delay-monad.direct⇔indirect -- Symmetry of bisimilarity for an arbitrary LTS. -- -- Note that, due to the use of a container in the definition of -- strong bisimilarity, the proof uses a helper function instead of -- the copatterns left-to-right and right-to-left. Furthermore the -- function map₃ is not used, but rather a combination of other -- functions. Similar remarks apply to several definitions below. symmetric = Bisimilarity.symmetric-∼ symmetric′ = Bisimilarity.symmetric-∼′ -- Transitivity of bisimilarity for an arbitrary LTS. transitive = Bisimilarity.transitive-∼ ------------------------------------------------------------------------ -- Section 5 -- CCS. Name-with-kind = Labelled-transition-system.CCS.Name-with-kind co = Labelled-transition-system.CCS.co Action = Labelled-transition-system.CCS.Action is-silent = Labelled-transition-system.CCS.is-silent Proc = Labelled-transition-system.CCS.Proc Proc′ = Labelled-transition-system.CCS.Proc′ _[_]→_ = Labelled-transition-system.CCS._[_]⟶_ _∉_ = Labelled-transition-system.CCS._∉_ -- The transition relation takes finite processes to finite processes. finite→finite = Labelled-transition-system.CCS.finite→finite -- Restricted and the corresponding lemma. Restricted = Bisimilarity.CCS.Examples.Restricted Restricted∼∅ = Bisimilarity.CCS.Examples.Restricted∼∅ -- ∅ is a left identity for parallel composition. ∣-left-identity = Bisimilarity.CCS.∣-left-identity -- Proofs showing that all the CCS process constructors preserve -- strong bisimilarity. (For ∅ the proof is simply reflexivity of -- strong bisimilarity.) -- -- The proofs are written in such a way that the arguments can be -- reused for similar proofs about strong similarity. (See below for -- proofs that are closer to the proofs in the paper.) module Strong-bisimilarity-congruence where _∣-cong_ = Bisimilarity.CCS._∣-cong_ ·-cong = Bisimilarity.CCS._·-cong_ !-cong = Bisimilarity.CCS.!-cong_ _⊕-cong_ = Bisimilarity.CCS._⊕-cong_ ⟨ν_⟩-cong = Bisimilarity.CCS.⟨ν_⟩-cong ∅-cong = Bisimilarity.reflexive-∼ -- Some proofs have been repeated in order to provide code which is -- closer to that presented in the paper. module As-in-the-paper where _∣-cong_ = Bisimilarity.CCS._∣-congP_ ·-cong = Bisimilarity.CCS.·-congP !-cong = Bisimilarity.CCS.!-congP -- The code uses overloaded equational reasoning combinators. import Equational-reasoning -- The proof As-in-the-paper._∣-cong_ does not use symmetric′, but the -- overloaded combinator symmetric. Agda resolves this use of -- symmetric to an instance corresponding to symmetric′. symmetric′-instance = Bisimilarity.Equational-reasoning-instances.symmetric∼′ -- Lemmas corresponding to ·-cong for expansion and weak bisimilarity. module ·-cong where expansion = Expansion.CCS._·-cong_ weak-bisimilarity = Bisimilarity.Weak.CCS._·-cong_ -- The example with P and Q. P = Bisimilarity.CCS.Examples.Natural-numbers.P Q = Bisimilarity.CCS.Examples.Natural-numbers.Q P∼Q = Bisimilarity.CCS.Examples.Natural-numbers.P∼Q -- The processes in the family P are irregular. P-irregular = Bisimilarity.CCS.Examples.Natural-numbers.P-irregular -- The combinators _■ and _∼⟨_⟩_ presented in the paper correspond to -- two instances. _■ = Bisimilarity.Equational-reasoning-instances.reflexive∼ _∼⟨_⟩_ = Bisimilarity.Equational-reasoning-instances.trans∼∼ -- Equations of the form [ ∞ ] P ∼ (C [ P ]) have unique solutions up -- to bisimilarity for contexts C where every hole is under a prefix. existence = Bisimilarity.CCS.solutions-exist uniqueness = Bisimilarity.CCS.unique-solutions ------------------------------------------------------------------------ -- Section 6 -- Up-to techniques. Up-to-technique = Up-to.Up-to-technique -- Relation transformers. Trans = Relation.Trans -- Size-preserving transformers. Size-preserving = Up-to.Size-preserving -- Composition of binary relations. _⊙_ = Relation._⊙_ -- Up to bisimilarity. Up-to-bisimilarity = Bisimilarity.Up-to.Up-to-bisimilarity up-to-bisimilarity-size-preserving = Bisimilarity.Up-to.up-to-bisimilarity-size-preserving -- Up to context. Up-to-context = Bisimilarity.Up-to.CCS.Up-to-context up-to-context-size-preserving = Bisimilarity.Up-to.CCS.up-to-context-size-preserving -- Up to the simple context consisting of replication applied to a -- single hole. Up-to-! = Bisimilarity.Up-to.CCS.Up-to-! up-to-!-size-preserving = Bisimilarity.Up-to.CCS.up-to-!-size-preserving -- If a transformer is size-preserving, then it satisfies a -- corresponding property for ν′ (and vice versa). size-preserving′ = Up-to.size-preserving⇔size-preserving′ -- Size-preserving transformers are up-to techniques. size-preserving→up-to = Up-to.size-preserving→up-to -- Monotonicity. Monotone = Relation.Monotone -- The definition of Size-preserving can be simplified for monotone -- transformers. simplification = Up-to.monotone→⇔ -- There are at least two size-preserving relation transformers that -- are not monotone (or extensive). not-monotone = Bisimilarity.Up-to.Counterexamples.∃-2-size-preserving׬[monotone⊎extensive] -- There is a container C such that there are at least two -- transformers that, despite preserving every approximation of the -- greatest fixpoint of C, are not up-to techniques with respect to C. not-up-to = Bisimilarity.Up-to.Counterexamples.∃special-case-of-size-preserving׬up-to -- There are monotone (and extensive) up-to techniques G and H such -- that G ∘ H is not an up-to-technique. not-closed-under-composition = Bisimilarity.Up-to.Counterexamples.∃[monotone×extensive×up-to]²×¬∘-up-to -- Size-preserving is closed under composition. ∘-closure = Up-to.∘-closure -- It is not the case that every (monotone and extensive) up-to -- technique is size-preserving. ¬up-to→size-preserving = Bisimilarity.Up-to.Counterexamples.¬monotone×extensive×up-to→size-preserving -- There are at least two up-to techniques that are not -- size-preserving (despite being monotone and extensive). not-size-preserving = Bisimilarity.Up-to.Counterexamples.∃monotone×extensive×up-to׬size-preserving -- Monotone and compatible transformers are up-to techniques. monotone→compatible→up-to = Up-to.monotone→compatible→up-to -- If F is monotone and symmetric, and compatible for strong -- similarity for some LTS, then F is compatible for strong -- bisimilarity for this LTS. compatible-for-similarity→compatible-for-bisimilarity = Up-to.Closure.compatible-for-similarity→compatible-for-bisimilarity -- It is not in general the case that if F is monotone and symmetric, -- and size-preserving for strong similarity for some LTS, then F is -- size-preserving for strong bisimilarity for this LTS. ¬-compatible-for-similarity→compatible-for-bisimilarity = Up-to.Closure.¬-Size-preserving-⟷/⊗ ------------------------------------------------------------------------ -- Section 7 -- The companion. Companion = Up-to.Companion -- Transformers below the companion. Below-the-companion = Up-to.Below-the-companion -- Transformers are below the companion if and only if they are -- size-preserving. below-the-companion⇔size-preserving = Up-to.below-the-companion⇔size-preserving -- The companion is size-preserving. companion-size-preserving = Up-to.companion-size-preserving -- Compatibility. Compatible = Up-to.Compatible -- The large companion. Companion₁ = Up-to.Companion₁ -- Monotone and compatible transformers are size-preserving. compatible→size-preserving = Up-to.monotone→compatible→size-preserving -- The large companion is below the small one. companion₁⊆companion = Up-to.companion₁⊆companion -- The small companion is monotone. companion-monotone = Up-to.companion-monotone -- The small companion is compatible if and only if it is below the -- large one. companion-compatible⇔companion⊆companion₁ = Up-to.companion-compatible⇔companion⊆companion₁ -- The small companion is compatible if certain assumptions (including -- a strong version of excluded middle) are satisfied. However, at the -- time of writing I don't know if these assumptions are consistent -- with the variant of Agda that is used in this development. companion-compatible = Up-to.companion-compatible -- The identity function is below the companion. id-below = Up-to.id-below -- The interpretation ⟦ C ⟧ of a container C is below the -- corresponding companion. ⟦⟧-below = Up-to.⟦⟧-below -- The companion composed with itself is below the companion. companion∘companion-below = Up-to.companion∘companion-below -- An example: If F is below the companion, then ⟦ C ⟧ ∘ F is below -- Companion ∘ Companion, which is below the companion. below-the-companion-example = Up-to.below-the-companion-example -- The greatest fixpoint is pointwise logically equivalent to the -- companion applied to an empty relation. ν⊆companion-⊥ = Up-to.ν⇔companion-⊥ companion-⊥⊆ν = Up-to.ν⇔companion-⊥ -- The companion is an up-to technique. companion-up-to = Up-to.companion-up-to ------------------------------------------------------------------------ -- Section 8 -- Pous and Sangiorgi's lemma 6.1.3, part (2). 6-1-3-2 = Bisimilarity.CCS.6-1-3-2 -- Instances corresponding to some equational reasoning combinators -- mentioned in the paper. _∼′⟨_⟩′_ = Bisimilarity.Equational-reasoning-instances.trans∼′∼′ _∼⟨_⟩′_ = Bisimilarity.Equational-reasoning-instances.trans∼∼′ _■′ = Bisimilarity.Equational-reasoning-instances.reflexive∼′ -- The primed variant of _∣-cong_. _∣-cong′_ = Bisimilarity.CCS._∣-cong′_ -- Replication preserves strong bisimilarity (already mentioned -- above). !-cong₂ = Bisimilarity.CCS.!-congP -- Proofs showing that all the CCS process constructors preserve -- strong bisimilarity (already mentioned above). module Strong-bisimilarity-congruence₂ = Strong-bisimilarity-congruence -- Proofs showing that all the CCS process constructors preserve -- strong similarity. (For ∅ the proof is simply reflexivity.) module Strong-similarity-congruence where _∣-cong_ = Similarity.CCS._∣-cong_ ·-cong = Similarity.CCS._·-cong_ !-cong = Similarity.CCS.!-cong_ _⊕-cong_ = Similarity.CCS._⊕-cong_ ⟨ν_⟩-cong = Similarity.CCS.⟨ν_⟩-cong ∅-cong = Similarity.reflexive-≤ -- Proofs showing that all the CCS process constructors, except for -- sum, preserve the expansion relation. (For ∅ the proof is simply -- reflexivity.) module Expansion-almost-congruence where _∣-cong_ = Expansion.CCS._∣-cong_ ·-cong = Expansion.CCS._·-cong_ !-cong = Expansion.CCS.!-cong_ ⟨ν_⟩-cong = Expansion.CCS.⟨ν_⟩-cong ∅-cong = Expansion.reflexive-≳ -- Proofs showing that all the CCS process constructors, except for -- sum, preserve weak bisimilarity. (For ∅ the proof is simply -- reflexivity.) module Weak-bisimilarity-almost-congruence where _∣-cong_ = Bisimilarity.Weak.CCS._∣-cong_ ·-cong = Bisimilarity.Weak.CCS._·-cong_ !-cong = Bisimilarity.Weak.CCS.!-cong_ ⟨ν_⟩-cong = Bisimilarity.Weak.CCS.⟨ν_⟩-cong ∅-cong = Bisimilarity.Weak.reflexive-≈ ------------------------------------------------------------------------ -- Section 9 -- Weak bisimilarity for the delay monad. -- -- Note that, unlike in the paper, strong bisimilarity, weak -- bisimilarity and the expansion relation are defined as a single -- family (with an extra index). [_]_≈D_ = Delay-monad.Bisimilarity.[_]_≈_ [_]_≈′D_ = Delay-monad.Bisimilarity.[_]_≈′_ -- This definition is pointwise logically equivalent, in a -- size-preserving way, to the one obtained from the LTS for the delay -- monad. direct⇔indirect = Bisimilarity.Weak.Delay-monad.direct⇔indirect -- Capretta's definition of weak bisimilarity, formulated using sized -- types. Capretta's-weak-bisimilarity = Delay-monad.Bisimilarity.Alternative.[_]_≈₃_ -- Capretta's definition is pointwise logically equivalent, in a -- size-preserving way, to the one used in the paper. direct⇔Capretta = Delay-monad.Bisimilarity.Alternative.≈⇔≈₃ ------------------------------------------------------------------------ -- Section 9.1 -- Weak bisimilarity is transitive for every LTS. transitiveʷ-lts = Bisimilarity.Weak.transitive-≈ -- The later constructors can be removed. -- -- (Two of the proofs are more general than the corresponding proofs -- in the paper.) laterʳ⁻¹ = Delay-monad.Bisimilarity.laterʳ⁻¹ laterˡ⁻¹ = Delay-monad.Bisimilarity.laterˡ⁻¹ later⁻¹ = Delay-monad.Bisimilarity.later⁻¹ -- Weak bisimilarity for the delay monad is transitive. -- -- (The proof is not quite identical to the one in the paper.) transitiveʷ-now = Delay-monad.Bisimilarity.transitive-≈-now transitiveʷ-later = Delay-monad.Bisimilarity.transitive-≈-later transitiveʷ = Delay-monad.Bisimilarity.transitive-≈ ------------------------------------------------------------------------ -- Section 9.2 -- If transitivity of weak bisimilarity for the delay monad is -- size-preserving in both arguments, then weak bisimilarity is -- trivial. size-preserving→trivial = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈→trivial -- Weak bisimilarity for the delay monad is reflexive. _∎ʷ = Delay-monad.Bisimilarity.reflexive -- The computation now x is not weakly bisimilar to never. -- -- (The proof is more general than the one in the paper.) now≉never = Delay-monad.Bisimilarity.now≉never -- If transitivity of weak bisimilarity for the delay monad is -- size-preserving in both arguments, then the carrier type is -- uninhabited. not-size-preservingʷ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈→uninhabited -- If transitivity of weak bisimilarity is size-preserving in the -- first argument, then weak bisimulations up to weak bisimilarity are -- contained in weak bisimilarity. size-preserving→weak-bisimulations-up-to-weak-bisimilarity-works = Bisimilarity.Weak.Up-to.size-preserving-transitivity→up-to-weak-bisimilarity-up-to -- The Drop-later predicate. Drop-later = Delay-monad.Bisimilarity.Negative.Laterˡ⁻¹-∼≈ -- Drop-later A implies that A is not inhabited, and vice versa. -- -- The implementation of basic-counterexample in the paper is -- different, because it does not include the "and vice versa" part. basic-counterexample = Delay-monad.Bisimilarity.Negative.size-preserving-laterˡ⁻¹-∼≈⇔uninhabited -- If there is a transitivity-like proof that takes a fully defined -- weak bisimilarity proof and a strong bisimilarity proof of size i -- to a weak bisimilarity proof of size i, then the carrier type is -- uninhabited (and vice versa). -- -- The implementation is superficially different from the one in the -- paper (except for the "vice versa" part, which is not present in -- the paper). not-size-preservingʷˢ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈∼ʳ⇔uninhabited -- A size-preserving translation from strong to weak bisimilarity for -- the delay monad. -- -- (The implementation is more general than the one in the paper.) strong-to-weak = Delay-monad.Bisimilarity.∼→ -- Size-preserving translations from strong bisimilarity to expansion -- and from expansion to weak bisimilarity for any LTS. strong-to-expansion = Expansion.∼⇒≳ expansion-to-weak = Bisimilarity.Weak.≳⇒≈ -- If there is a proof of transitivity that takes a fully defined weak -- bisimilarity proof and a weak bisimilarity proof of size i to a -- weak bisimilarity proof of size i, then the carrier type is -- uninhabited (and vice versa). -- -- The implementation is superficially different from the one in the -- paper (except for the "vice versa" part, which is not present in -- the paper). not-size-preservingʷʳ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈ʳ⇔uninhabited -- Size-preserving symmetry proofs for strong and weak bisimilarity. -- -- (Actually a single proof that works for both relations.) symmetryˢ = Delay-monad.Bisimilarity.symmetric symmetryʷ = Delay-monad.Bisimilarity.symmetric -- If there is a proof of transitivity that takes a strong (or -- alternatively weak) bisimilarity proof of size i and a fully -- defined weak bisimilarity proof to a weak bisimilarity proof of -- size i, then the carrier type is uninhabited (and vice versa). not-size-preservingˢʷ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≈ˡ⇔uninhabited not-size-preservingʷˡ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈ˡ⇔uninhabited -- If the carrier type is not inhabited, then weak bisimilarity is -- trivial. -- -- (The proof is more general than the one in the paper.) trivial = Delay-monad.Bisimilarity.uninhabited→trivial -- If the type A is uninhabited, then Drop-later A is inhabited (and -- vice versa). basic-counterexample′ = Delay-monad.Bisimilarity.Negative.size-preserving-laterˡ⁻¹-∼≈⇔uninhabited -- If the carrier type is uninhabited, then there is a fully -- size-preserving transitivity proof for weak bisimilarity (and vice -- versa). size-preservingʷ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈⇔uninhabited -- Size-preserving transitivity-like proofs involving strong and weak -- bisimilarity. -- -- (The type signatures of the proofs are more general than those -- given in the paper.) transitiveˢʷ = Delay-monad.Bisimilarity.transitive-∼ˡ transitiveʷˢ = Delay-monad.Bisimilarity.transitive-∞∼ʳ -- A direct definition of expansion for the delay monad. [_]_≳D_ = Delay-monad.Bisimilarity.[_]_≳_ -- The direct definition of expansion for the delay monad is pointwise -- logically equivalent, in a size-preserving way, to the one obtained -- from the LTS for the delay monad. direct⇔indirect-expansion = Expansion.Delay-monad.direct⇔indirect -- Size-preserving transitivity-like proofs involving the direct -- definitions of weak bisimilarity and expansion for the delay monad. -- -- (The type signatures of the first three proofs are more general -- than those given in the paper.) transitiveᵉˢ = Delay-monad.Bisimilarity.transitive-∼ʳ transitiveᵉ = Delay-monad.Bisimilarity.transitive-≳ˡ transitiveᵉʷ = Delay-monad.Bisimilarity.transitive-≳ˡ transitiveʷᵉ = Delay-monad.Bisimilarity.transitive-≈≲ -- Size-preserving transitivity-like proofs involving weak -- bisimilarity and expansion defined for an arbitrary LTS. transitiveᵉˢ-lts = Expansion.transitive-≳∼ transitiveᵉ-lts = Expansion.transitive-≳ transitiveᵉʷ-lts = Bisimilarity.Weak.transitive-≳≈ transitiveʷᵉ-lts = Bisimilarity.Weak.transitive-≈≲ -- Negative results related to expansion. not-size-preservingˢᵉ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≳ˡ⇔uninhabited not-size-preservingᵉʷ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳≈ˡ⇔uninhabited not-size-preservingʷᵉ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈≳ˡ⇔uninhabited -- The functions transitiveᵉ, transitiveᵉʷ and transitiveʷᵉ cannot in -- general be made fully size-preserving. not-fully-size-preservingᵉ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳⇔uninhabited not-fully-size-preservingᵉʷ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳≈⇔uninhabited not-fully-size-preservingʷᵉ = Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈≲⇔uninhabited -- Up to expansion. Up-to-expansion = Bisimilarity.Weak.Up-to.Up-to-expansion up-to-expansion-size-preserving = Bisimilarity.Weak.Up-to.up-to-expansion-size-preserving -- Relations that satisfy the diagrams of the variant of up to -- expansion where two occurrences of the expansion relation have been -- replaced by weak bisimilarity are contained in weak bisimilarity. variant-of-up-to-expansion = Bisimilarity.Weak.Up-to.6-5-2-4
{ "alphanum_fraction": 0.73443742, "avg_line_length": 31.3661800487, "ext": "agda", "hexsha": "f9f2e6f04f92594d9938ed918eecb750d3d8af6d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "README/Pointers-to-results-from-the-paper.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "README/Pointers-to-results-from-the-paper.agda", "max_line_length": 84, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "README/Pointers-to-results-from-the-paper.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7149, "size": 25783 }
{-# OPTIONS --type-in-type #-} -- yes, I will let you cheat in this exercise {-# OPTIONS --allow-unsolved-metas #-} -- allows import, unfinished ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- CS410 2017/18 Exercise 2 CATEGORIES AND MONADS (worth 25%) ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- NOTE (19/10/17) This file is currently incomplete: more will arrive on -- GitHub. -- NOTE (29/10/17) All components are now present. ------------------------------------------------------------------------------ -- Dependencies ------------------------------------------------------------------------------ open import CS410-Prelude open import CS410-Categories open import Ex1 ------------------------------------------------------------------------------ -- Categorical Jigsaws (based on Ex1) ------------------------------------------------------------------------------ OPE : Category -- The category of order-preserving embeddings... OPE = record { Obj = Nat -- ...has numbers as objects... ; _~>_ = _<=_ -- ...and "thinnings" as arrows. ; id~> = oi ; _>~>_ = _o>>_ ; law-id~>>~> = idThen-o>> ; law->~>id~> = idAfter-o>> ; law->~>>~> = assoc-o>> } VEC : Nat -> SET => SET -- Vectors of length n... VEC n = record { F-Obj = \ X -> Vec X n -- ...give a functor from SET to SET... ; F-map = \ f xs -> vMap f xs -- ...doing vMap to arrows. -- Now prove the laws. ; F-map-id~> = extensionality \ xs -> {!!} ; F-map->~> = \ f g -> extensionality \ xs -> {!!} } Op : Category -> Category -- Every category has an opposite... Op C = record { Obj = Obj -- ...with the same objects, but... ; _~>_ = \ S T -> T ~> S -- ...arrows that go backwards! -- Now, find the rest! ; id~> = id~> ; _>~>_ = \ f g -> g >~> f ; law-id~>>~> = law->~>id~> ; law->~>id~> = law-id~>>~> ; law->~>>~> = {!!} } where open Category C CHOOSE : Set -> OPE => Op SET -- Show that thinnings from n to m... CHOOSE X = record -- ...act by selection... { F-Obj = Vec X -- ...to cut vectors down from m to n. ; F-map = {!!} ; F-map-id~> = extensionality {!!} ; F-map->~> = \ f g -> extensionality {!!} } --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- The List Monad (a warm-up) ------------------------------------------------------------------------------ -- The declaration of List has been added to the CS410-Prelude file: -- data List (X : Set) : Set where -- [] : List X -- _,-_ : (x : X)(xs : List X) -> List X -- infixr 4 _,-_ -- Appending two lists is rather well known, so I'll not ask you to write it. _+L_ : {X : Set} -> List X -> List X -> List X [] +L ys = ys (x ,- xs) +L ys = x ,- (xs +L ys) infixr 4 _+L_ -- But I will ask you to find some structure for it. --??--2.2--------------------------------------------------------------------- LIST-MONOID : Set -> Category LIST-MONOID X = -- Show that _+L_ is the operation of a monoid,... record { Obj = One -- ... i.e., a category with one object. ; _~>_ = {!!} ; id~> = {!!} ; _>~>_ = {!!} ; law-id~>>~> = {!!} ; law->~>id~> = {!!} ; law->~>>~> = {!!} } where -- useful helper proofs (lemmas) go here --??-------------------------------------------------------------------------- -- Next, functoriality of lists. Given a function on elements, show how to -- apply that function to all the elements of a list. (Haskell calls this -- operation "map".) --??--2.3--------------------------------------------------------------------- list : {X Y : Set} -> (X -> Y) -> List X -> List Y list f xs = {!!} LIST : SET => SET LIST = record { F-Obj = List ; F-map = list ; F-map-id~> = extensionality {!!} ; F-map->~> = \ f g -> extensionality {!!} } where -- useful helper proofs (lemmas) go here --??-------------------------------------------------------------------------- -- Moreover, applying a function elementwise should respect appending. --??--2.4--------------------------------------------------------------------- LIST+L : {X Y : Set}(f : X -> Y) -> LIST-MONOID X => LIST-MONOID Y LIST+L {X}{Y} f = record { F-Obj = id ; F-map = list f -- this yellow will go once LIST-MONOID has arrows! ; F-map-id~> = {!!} ; F-map->~> = {!!} } where -- useful helper proofs (lemmas) go here --??-------------------------------------------------------------------------- -- Next, we have two very important "natural transformations". --??--2.5--------------------------------------------------------------------- SINGLE : ID ~~> LIST SINGLE = record { xf = \ x -> x ,- [] -- turn a value into a singleton list ; naturality = \ f -> {!!} } --??-------------------------------------------------------------------------- -- Here, naturality means that it doesn't matter -- whether you apply a function f, then make a singleton list -- or you make a singleton list, then apply f to all (one of) its elements. -- Now, define the operation that concatenates a whole list of lists, and -- show that it, too, is natural. That is, it doesn't matter whether you -- transform the elements (two layers inside) then concatenate, or you -- concatenate, then transform the elements. --??--2.6--------------------------------------------------------------------- concat : {X : Set} -> List (List X) -> List X concat xss = {!!} CONCAT : (LIST >=> LIST) ~~> LIST CONCAT = record { xf = concat ; naturality = {!!} } where -- useful helper proofs (lemmas) go here --??-------------------------------------------------------------------------- -- You've nearly built your first monad! You just need to prove that -- single and concat play nicely with each other. --??--2.7--------------------------------------------------------------------- module LIST-MONAD where open MONAD LIST public ListMonad : Monad ListMonad = record { unit = SINGLE ; mult = CONCAT ; unitMult = {!!} ; multUnit = {!!} ; multMult = {!!} } where -- useful helper proofs (lemmas) go here -- open LIST-MONAD --??-------------------------------------------------------------------------- -- More monads to come... ------------------------------------------------------------------------------ -- Categories of Indexed Sets ------------------------------------------------------------------------------ -- We can think of some -- P : I -> Set -- as a collection of sets indexed by I, such that -- P i -- means "exactly the P-things which fit with i". -- You've met -- Vec X : Nat -> Set -- where -- Vec X n -- means "exactly the vectors which fit with n". -- Now, given two such collections, S and T, we can make a collection -- of function types: the functions which fit with i map the -- S-things which fit with i to the T-things which fit with i. _-:>_ : {I : Set} -> (I -> Set) -> (I -> Set) -> (I -> Set) (S -:> T) i = S i -> T i -- So, (Vec X -:> Vec Y) n contains the functions which turn -- n Xs into n Ys. -- Next, if we know such a collection of sets, we can claim to have -- one for each index. [_] : {I : Set} -> (I -> Set) -> Set [ P ] = forall i -> P i -- [_] {I} P = (i : I) -> P i -- E.g., [ Vec X -:> Vec Y ] is the type of functions from X-vectors -- to Y-vectors which preserve length. -- For any such I, we get a category of indexed sets with index-preserving -- functions. _->SET : Set -> Category I ->SET = record { Obj = I -> Set -- I-indexed sets ; _~>_ = \ S T -> [ S -:> T ] -- index-respecting functions ; id~> = \ i -> id -- the identity at every index ; _>~>_ = \ f g i -> f i >> g i -- composition at every index ; law-id~>>~> = refl -- and the laws are very boring ; law->~>id~> = refl ; law->~>>~> = \ f g h -> refl _ } -- In fact, we didn't need to choose SET here. We could do this construction -- for any category: index the objects; index the morphisms. -- But SET is plenty to be getting on with. -- Now, let me define an operation that makes types from lists. All : {X : Set} -> (X -> Set) -> (List X -> Set) All P [] = One All P (x ,- xs) = P x * All P xs -- The idea is that we get a tuple of P-things: one for each list element. -- So -- All P (1 ,- 2 ,- 3 ,- []) -- = P 1 * P 2 * P 3 * One -- Note that if you think of List One as a version of Nat, -- All becomes a lot like Vec. copy : Nat -> List One copy zero = [] copy (suc n) = <> ,- copy n VecCopy : Set -> Nat -> Set VecCopy X n = All (\ _ -> X) (copy n) -- Now, your turn... --??--2.8--------------------------------------------------------------------- -- Show that, for any X, All induces a functor -- from (X ->SET) to (List X ->SET) all : {X : Set}{S T : X -> Set} -> [ S -:> T ] -> [ All S -:> All T ] all f xs ss = {!!} ALL : (X : Set) -> (X ->SET) => (List X ->SET) ALL X = record { F-Obj = All ; F-map = all ; F-map-id~> = {!!} ; F-map->~> = {!!} } where -- useful helper facts go here --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Cutting Things Up ------------------------------------------------------------------------------ -- Next, we're going to develop a very general technique for building -- data structures. -- We may think of an I |> O as a way to "cut O-shapes into I-shaped pieces". -- The pointy end points to the type being cut; the flat end to the type of -- pieces. record _|>_ (I O : Set) : Set where field Cuts : O -> Set -- given o : O, how may we cut it? inners : {o : O} -> Cuts o -> List I -- given how we cut it, what are -- the shapes of its pieces? -- Let us have some examples right away! VecCut : One |> Nat -- cut numbers into boring pieces VecCut = record { Cuts = \ n -> One -- there is one way to cut n ; inners = \ {n} _ -> copy n -- and you get n pieces } -- Here's a less boring example. You can cut a number into *two* pieces -- by finding two numbers that add to it. NatCut : Nat |> Nat NatCut = record { Cuts = \ mn -> Sg Nat \ m -> Sg Nat \ n -> (m +N n) == mn ; inners = \ { (m , n , _) -> m ,- n ,- [] } } -- The point is that we can make data structures that record how we -- built an O-shaped thing from I-shaped pieces. record Cutting {I O}(C : I |> O)(P : I -> Set)(o : O) : Set where constructor _8><_ -- "scissors" open _|>_ C field cut : Cuts o -- we decide how to cut o pieces : All P (inners cut) -- then we give all the pieces. infixr 3 _8><_ -- For example... VecCutting : Set -> Nat -> Set VecCutting X = Cutting VecCut (\ _ -> X) myVecCutting : VecCutting Char 5 myVecCutting = <> 8>< 'h' , 'e' , 'l' , 'l' , 'o' , <> -- Or, if you let me fiddle about with strings for a moment,... length : {X : Set} -> List X -> Nat length [] = zero length (x ,- xs) = suc (length xs) listVec : {X : Set}(xs : List X) -> Vec X (length xs) listVec [] = [] listVec (x ,- xs) = x ,- listVec xs strVec : (s : String) -> Vec Char (length (primStringToList s)) strVec s = listVec (primStringToList s) -- ...an example of cutting a number in two, with vector pieces. footprints : Cutting NatCut (Vec Char) 10 footprints = (4 , 6 , refl 10) 8>< strVec "foot" , strVec "prints" , <> -- Now, let me direct you to the =$ operator, now in CS410-Prelude.agda, -- which you may find helps with the proofs in the following. --??--2.9--------------------------------------------------------------------- -- Using what you already built for ALL, show that every Cutting C gives us -- a functor between categories of indexed sets. CUTTING : {I O : Set}(C : I |> O) -> (I ->SET) => (O ->SET) CUTTING {I}{O} C = record { F-Obj = Cutting C ; F-map = {!!} ; F-map-id~> = extensionality \ o -> extensionality \ { (c 8>< ps) -> {!!} } ; F-map->~> = \ f g -> extensionality \ o -> extensionality \ { (c 8>< ps) -> {!!} } } where open _|>_ C open _=>_ (ALL I) --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Interiors ------------------------------------------------------------------------------ -- Next, let me define the notion of an algebra for a given functor in C => C module ALGEBRA {C : Category}(F : C => C) where open Category C open _=>_ F Algebra : (X : Obj) -> Set -- we call X the "carrier" of the algebra... Algebra X = F-Obj X ~> X -- ...and we explain how to turn a bunch of Xs -- into one open ALGEBRA -- Some week, we'll build categories whose objects are algebras. Not this week. -- Instead, let's work with them a bit. -- If we know a way to cut I-shapes into I-shaped pieces, we can build the -- ways to "tile" an I with I-shaped T-tiles. data Interior {I}(C : I |> I)(T : I -> Set)(i : I) : Set where -- either... tile : T i -> Interior C T i -- we have a tile that fits, or... <_> : Cutting C (Interior C T) i -> -- ...we cut, then tile the pieces. Interior C T i -- Let me give you an example of an interior. subbookkeeper : Interior NatCut (Vec Char) 13 subbookkeeper = < (3 , 10 , refl _) 8>< tile (strVec "sub") , < (4 , 6 , refl _) 8>< tile (strVec "book") , tile (strVec "keeper") , <> > , <> > -- We make a 13-interior from -- a 3-tile and a 10-interior made from a 4-tile and a 6-tile. -- Guess what? Interior C is always a Monad! We'll get there. module INTERIOR {I : Set}{C : I |> I} where -- fix some C... open _|>_ C -- ...and open it open module I->SET {I : Set} = Category (I ->SET) -- work in I ->SET -- tile gives us an arrow from T into Interior C T tile' : {T : I -> Set} -> [ T -:> Interior C T ] tile' i = tile -- <_> gives us an algebra! cut' : {T : I -> Set} -> Algebra (CUTTING C) (Interior C T) cut' i = <_> -- Now, other (CUTTING C) algebras give us operators on interiors. module INTERIORFOLD {P Q : I -> Set} where interiorFold : [ P -:> Q ] -> -- if we can turn a P into a Q... Algebra (CUTTING C) Q -> -- ...and a bunch of Qs into a Q... [ Interior C P -:> Q ] -- ...we can turn an interior of Ps into a Q allInteriorFold : -- annoyingly, we'll need a specialized "all" [ P -:> Q ] -> Algebra (CUTTING C) Q -> [ All (Interior C P) -:> All Q ] interiorFold pq qalg i (tile p) = pq i p interiorFold pq qalg i < c 8>< pis > = qalg i (c 8>< allInteriorFold pq qalg (inners c) pis) -- recursively turn all the sub-interiors into Qs allInteriorFold pq qalg [] <> = <> allInteriorFold pq qalg (i ,- is) (pi , pis) = interiorFold pq qalg i pi , allInteriorFold pq qalg is pis -- The trouble is that if you use -- all (interiorFold pq qalg) -- to process the sub-interiors, the termination checker complains. -- But if you've built "all" correctly, you should be able to prove this: --??--2.10-------------------------------------------------------------------- allInteriorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q) -> allInteriorFold pq qalg == all (interiorFold pq qalg) allInteriorFoldLaw pq qalg = extensionality \ is -> extensionality \ ps -> {!!} where -- helper lemmas go here --??-------------------------------------------------------------------------- -- Now, do me a favour and prove this extremely useful fact. -- Its purpose is to bottle the inductive proof method for functions -- built with interiorFold. --??--2.11-------------------------------------------------------------------- interiorFoldLemma : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q) (f : [ Interior C P -:> Q ]) -> ((i : I)(p : P i) -> pq i p == f i (tile p)) -> ((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) -> qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) -> (i : I)(pi : Interior C P i) -> interiorFold pq qalg i pi == f i pi interiorFoldLemma pq qalg f base step i pi = {!!} --??-------------------------------------------------------------------------- -- We'll use it in this form: interiorFoldLaw : (pq : [ P -:> Q ])(qalg : Algebra (CUTTING C) Q) (f : [ Interior C P -:> Q ]) -> ((i : I)(p : P i) -> pq i p == f i (tile p)) -> ((i : I)(c : Cuts i)(ps : All (Interior C P) (inners c)) -> qalg i (c 8>< all f (inners c) ps) == f i < c 8>< ps >) -> interiorFold pq qalg == f interiorFoldLaw pq qalg f base step = extensionality \ i -> extensionality \ pi -> interiorFoldLemma pq qalg f base step i pi open INTERIORFOLD -- Let me pay you back immediately! -- An interiorBind is an interiorFold which computes an Interior, -- rewrapping each layer with < ... > interiorBind : {X Y : I -> Set} -> [ X -:> Interior C Y ] -> [ Interior C X -:> Interior C Y ] interiorBind f = interiorFold f (\ i -> <_>) -- Because an interiorBind *makes* an interior, we can say something useful -- about what happens if we follow it with an interiorFold. interiorBindFusion : {X Y Z : I -> Set} -> (f : [ X -:> Interior C Y ]) (yz : [ Y -:> Z ])(zalg : Algebra (CUTTING C) Z) -> (interiorBind f >~> interiorFold yz zalg) == interiorFold (f >~> interiorFold yz zalg) zalg -- That is, we can "fuse" the two together, making one interiorFold. -- I'll do the proof as it's a bit hairy. You've given me all I need. -- Note that I don't use extensionality, just laws that relate functions. interiorBindFusion f yz zalg = (interiorBind f >~> interiorFold yz zalg) =< interiorFoldLaw (f >~> interiorFold yz zalg) zalg (interiorBind f >~> interiorFold yz zalg) (\ i p -> refl (interiorFold yz zalg i (f i p))) (\ i c ps -> refl (zalg i) =$= (refl (c 8><_) =$= ( ((all (interiorBind f >~> interiorFold yz zalg) =[ F-map->~> (interiorBind f) (interiorFold yz zalg) >= (all (interiorBind f) >~> all (interiorFold yz zalg)) =< refl _>~>_ =$= allInteriorFoldLaw f cut' =$= allInteriorFoldLaw yz zalg ]= allInteriorFold f (\ i -> <_>) >~> allInteriorFold yz zalg [QED]) =$ inners c =$= refl ps)))) ]= interiorFold (f >~> interiorFold yz zalg) zalg [QED] where open _=>_ (ALL I) -- You should find that a very useful piece of kit. In fact, you should -- not need extensionality, either. -- We need Interior C to be a functor. --??--2.12-------------------------------------------------------------------- -- using interiorBind, implement the "F-map" for Interiors as a one-liner interior : {X Y : I -> Set} -> [ X -:> Y ] -> [ Interior C X -:> Interior C Y ] interior f = {!!} -- using interiorBindFusion, prove the following law for "fold after map" interiorFoldFusion : {P Q R : I -> Set} (pq : [ P -:> Q ])(qr : [ Q -:> R ])(ralg : Algebra (CUTTING C) R) -> (interior pq >~> interiorFold qr ralg) == interiorFold (pq >~> qr) ralg interiorFoldFusion pq qr ralg = interior pq >~> interiorFold qr ralg =[ {!!} >= interiorFold (pq >~> qr) ralg [QED] where open _=>_ (ALL I) -- and now, using interiorFoldFusion if it helps, -- complete the functor construction INTERIOR : (I ->SET) => (I ->SET) INTERIOR = record { F-Obj = Interior C ; F-map = interior ; F-map-id~> = {!!} ; F-map->~> = {!!} } where open _=>_ (ALL I) --??-------------------------------------------------------------------------- -- Now let's build the Monad. -- You should find that all the laws you have to prove follow from the -- fusion laws you already have. open MONAD INTERIOR --??--2.13-------------------------------------------------------------------- WRAP : ID ~~> INTERIOR WRAP = record { xf = {!!} ; naturality = {!!} } -- use interiorBind to define the following FLATTEN : (INTERIOR >=> INTERIOR) ~~> INTERIOR FLATTEN = record { xf = {!!} ; naturality = {!!} } INTERIOR-Monad : Monad INTERIOR-Monad = record { unit = WRAP ; mult = FLATTEN ; unitMult = {!!} ; multUnit = {!!} ; multMult = {!!} } where open _=>_ INTERIOR --??-------------------------------------------------------------------------- open INTERIOR open INTERIORFOLD -- You should be able to define an algebra on vectors for NatCut, using +V --??--2.14-------------------------------------------------------------------- NatCutVecAlg : {X : Set} -> Algebra (CUTTING NatCut) (Vec X) NatCutVecAlg n xsc = {!!} --??-------------------------------------------------------------------------- -- Check that it puts things together suitably when you evaluate this: test1 : Vec Char 13 test1 = interiorFold (\ _ -> id) NatCutVecAlg 13 subbookkeeper ------------------------------------------------------------------------------ -- Cutting Up Pairs ------------------------------------------------------------------------------ module CHOICE where open _|>_ --??--2.15-------------------------------------------------------------------- -- Show that if you can cut up I and cut up J, then you can cut up I * J. -- You now have two dimensions (I and J). The idea is that you choose one -- dimension in which to make a cut, and keep everything in the other -- dimension the same. _+C_ : {I J : Set} -> I |> I -> J |> J -> (I * J) |> (I * J) Cuts (P +C Q) (i , j) = Cuts P i + Cuts Q j inners (P +C Q) = {!!} --??-------------------------------------------------------------------------- open CHOICE -- That should get us the ability to cut up *rectangules* by cutting either -- vertically or horizontally. NatCut2D : (Nat * Nat) |> (Nat * Nat) NatCut2D = NatCut +C NatCut Matrix : Set -> Nat * Nat -> Set Matrix X (w , h) = Vec (Vec X w) h -- If you've done it right, you should find that the following typechecks. -- It's the interior of a rectangle, tiled with matrices of characters. rectangle : Interior NatCut2D (Matrix Char) (15 , 6) rectangle = < inr (4 , 2 , refl _) 8>< < inl (7 , 8 , refl _) 8>< tile (strVec "seventy" ,- strVec "kitchen" ,- strVec "program" ,- strVec "mistake" ,- []) , tile (strVec "thousand" ,- strVec "soldiers" ,- strVec "probably" ,- strVec "undefine" ,- []) , <> > , tile (strVec "acknowledgement" ,- strVec "procrastination" ,- []) , <> > -- Later, we'll use rectangular interiors as the underlying data structure -- for a window manager. -- But for now, one last thing. --??--2.16-------------------------------------------------------------------- -- Show that if you have a vector of n Ps for every element of a list, -- then you can make a vector of n (All P)s . -- Hint: Ex1 provides some useful equipment for this job. vecAll : {I : Set}{P : I -> Set}{is : List I}{n : Nat} -> All (\ i -> Vec (P i) n) is -> Vec (All P is) n vecAll {is = is} pss = {!!} -- Given vecAll, show that algebra for any cutting can be lifted -- to an algebra on vectors. VecLiftAlg : {I : Set}(C : I |> I){X : I -> Set} (alg : Algebra (CUTTING C) X){n : Nat} -> Algebra (CUTTING C) (\ i -> Vec (X i) n) VecLiftAlg C alg i (c 8>< pss) = {!!} -- Now show that you can build an algebra for matrices -- which handles cuts in either dimension, -- combining them either horizontally or vertically! NatCut2DMatAlg : {X : Set} -> Algebra (CUTTING NatCut2D) (Matrix X) NatCut2DMatAlg _ (inl c 8>< ms) = {!!} NatCut2DMatAlg _ (inr c 8>< ms) = {!!} --??-------------------------------------------------------------------------- -- And that should give you a way to glue pictures together from interiors. picture : [ Interior NatCut2D (Matrix Char) -:> Matrix Char ] picture = interiorFold (\ _ -> id) NatCut2DMatAlg -- You should be able to check that the following gives you something -- sensible: test2 = picture _ rectangle
{ "alphanum_fraction": 0.4711708525, "avg_line_length": 33.3460026212, "ext": "agda", "hexsha": "a1c1f6c9018ccdd7cf1fe32c9045b45da4762624", "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": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "m-schmidt/CS410-17-Exercises", "max_forks_repo_path": "Ex2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c", "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": "m-schmidt/CS410-17-Exercises", "max_issues_repo_path": "Ex2.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "5db8e95bbcbe8dc0eec810f3e73130ecd78d207c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "m-schmidt/CS410-17-Exercises", "max_stars_repo_path": "Ex2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6768, "size": 25443 }
-- A predicate transformer allowing one to express that -- some value definitely does /not/ own some resource infixl 9 _◇_ data _◇_ {p} (P : SPred p) (Φᵢ : Carrier) : SPred (p ⊔ a) where ⟪_,_⟫ : ∀ {Φₚ Φ} → P Φₚ → Φᵢ ⊎ Φₚ ≣ Φ → (P ◇ Φᵢ) Φ -- | This gives another wand like thing module _ {p q} (P : SPred p) (Q : SPred q) where infixr 8 _◇─_ _◇─_ : SPred (p ⊔ q ⊔ a) _◇─_ Φᵢ = ∀[ P ◇ Φᵢ ⇒ Q ] module _ {p q} {P : SPred p} {Q : SPred q} where pair : ε[ P ◇─ (Q ◇─ P ✴ Q) ] pair ⟪ px , σ₁ ⟫ ⟪ qx , σ₂ ⟫ rewrite ⊎-id⁻ˡ σ₁ = px ×⟨ σ₂ ⟩ qx module _ {p} {P : SPred p} where ◇-ε : ∀[ P ◇ ε ⇒ P ] ◇-ε ⟪ px , σ ⟫ rewrite ⊎-id⁻ˡ σ = px -- pure : ∀ {p q} {P : SPred p} {Q : SPred q} → (P ε → Q Φ) → (P ─✴ Q) Φ -- pure f px = {!!} -- -- pure = {!!} -- a pure wand is a resource-polymorphic function -- unwand : ε[ P ─✴ Q ] → ∀[ P ⇒ Q ] -- unwand f p = f p ⊎-idˡ -- ✴-pure : ∀ {p q} {P : SPred p} {Q : SPred q} → (∀ {Φ} → P Φ → ε ⊎ Φ ≣ Φ → Q Φ) → ε[ P ─✴ Q ] -- ✴-pure f px σ rewrite ⊎-id⁻ˡ σ = f px ⊎-idˡ -- ✴-flip : ∀ {p q r} {P : SPred p} {Q : SPred q} {R : SPred r} → ε[ (P ─✴ (Q ─✴ R)) ─✴ (Q ─✴ (P ─✴ R)) ] -- ✴-flip {P = P} {Q} {R} = -- ✴-pure {P = P ─✴ (Q ─✴ R)} {Q = Q ─✴ (P ─✴ R)} λ f σ₁ q σ₂ p σ₃ → -- let _ , σ₃ , σ₄ = ⊎-assoc (⊎-comm σ₂) σ₃ in f p σ₄ q (⊎-comm σ₃) -- ─[id] : ∀ {p} {P : Pred _ p} → ε[ P ─✴ P ] -- ─[id] px σ rewrite ⊎-id⁻ˡ σ = px
{ "alphanum_fraction": 0.4270122783, "avg_line_length": 34.9047619048, "ext": "agda", "hexsha": "caea4c1768562d6cdf474ebe4b2f10a8387b7f61", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Relation/Ternary/Separation/Experiments.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Relation/Ternary/Separation/Experiments.agda", "max_line_length": 109, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Relation/Ternary/Separation/Experiments.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 786, "size": 1466 }
-- This file is ported from a part of Martin Escardó's HoTT lecture notes -- (https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html). {-# OPTIONS --without-K --safe #-} module Util.HoTT.Section where open import Util.HoTT.HLevel.Core open import Util.Prelude open import Util.Relation.Binary.PropositionalEquality using ( Σ-≡⁺ ; subst-subst-sym ) private variable α β γ : Level A B C : Set α infix 4 _◁_ record HasSection {A : Set α} {B : Set β} (f : A → B) : Set (α ⊔ℓ β) where field section : B → A isSection : ∀ x → f (section x) ≡ x open HasSection public record _◁_ (A : Set α) (B : Set β) : Set (α ⊔ℓ β) where field retraction : B → A hasSection : HasSection retraction open HasSection hasSection public renaming (isSection to retraction∘section) open _◁_ public ◁-refl : A ◁ A ◁-refl = record { retraction = id ; hasSection = record { section = id ; isSection = λ _ → refl } } ◁-trans : A ◁ B → B ◁ C → A ◁ C ◁-trans A◁B B◁C = record { retraction = A◁B .retraction ∘ B◁C .retraction ; hasSection = record { section = B◁C .section ∘ A◁B .section ; isSection = λ x → trans (cong (A◁B .retraction) (B◁C .retraction∘section _)) (A◁B .retraction∘section _) } } Σ-◁ : {A : Set α} {B : A → Set β} {C : A → Set γ} → (∀ a → B a ◁ C a) → Σ A B ◁ Σ A C Σ-◁ B◁C = record { retraction = λ { (a , c) → a , B◁C a .retraction c } ; hasSection = record { section = λ { (a , b) → a , B◁C a .section b } ; isSection = λ { (a , b) → cong (a ,_) (B◁C a .retraction∘section b) } } } ◁-pres-IsContr : A ◁ B → IsContr B → IsContr A ◁-pres-IsContr A◁B (b , canon) = A◁B .retraction b , λ a → trans (cong (A◁B .retraction) (canon (A◁B .section a))) (A◁B .retraction∘section a) Σ-◁-reindexing : {A : Set α} {B : Set β} {P : A → Set γ} → (r : A ◁ B) → Σ A P ◁ Σ B (P ∘ r .retraction) Σ-◁-reindexing {P = P} r = record { retraction = λ { (b , x) → r .retraction b , x } ; hasSection = record { section = λ where (a , x) → r .section a , subst P (sym (r .retraction∘section a)) x ; isSection = λ where (a , x) → Σ-≡⁺ ( r .retraction∘section a , subst-subst-sym (r .retraction∘section a) ) } }
{ "alphanum_fraction": 0.5599654875, "avg_line_length": 23.8969072165, "ext": "agda", "hexsha": "f97dbaf2a07d4d48c5664659fbd36266001d7749", "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": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Util/HoTT/Section.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "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": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Util/HoTT/Section.agda", "max_line_length": 84, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Util/HoTT/Section.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 924, "size": 2318 }
module TimeSpace where open import Data.Product open import Data.Sum open import Data.List open import Data.Nat open import Data.Nat.Properties open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Pi.Syntax open import Pi.Opsem open import Pi.Eval open import Pi.Examples -- 𝔹+ n = 𝔹 +ᵤ … +ᵤ 𝔹 𝔹+ : ℕ → 𝕌 𝔹+ 0 = 𝟘 𝔹+ 1 = 𝔹 𝔹+ (suc (suc n)) = 𝔹 +ᵤ (𝔹+ (suc n)) -- 𝔹* n = 𝔹 ×ᵤ … ×ᵤ 𝔹 𝔹* : ℕ → 𝕌 𝔹* 0 = 𝔹 𝔹* (suc n) = 𝔹 ×ᵤ 𝔹* n convert : ∀ {n} → 𝔹+ (2 ^ n) ↔ 𝔹* n convert {0} = id↔ convert {1} = (uniti⋆l ⊕ uniti⋆l) ⨾ factor convert {suc (suc n)} = split ⨾ (convert {suc n} ⊕ (coe {n} ⨾ convert {suc n})) ⨾ (uniti⋆l ⊕ uniti⋆l) ⨾ factor where coe : ∀ {n} → 𝔹+ ((2 ^ n) + ((2 ^ n) + 0) + 0) ↔ 𝔹+ (2 ^ (1 + n)) coe {n} rewrite +-identityʳ ((2 ^ n) + ((2 ^ n) + 0)) = id↔ split : ∀ {n m} → 𝔹+ (n + m) ↔ (𝔹+ n +ᵤ 𝔹+ m) split {0} {m} = uniti₊l split {1} {0} = uniti₊r split {1} {1} = id↔ split {1} {suc (suc m)} = id↔ split {suc (suc n)} {m} = (id↔ ⊕ split) ⨾ assocl₊ -- flip the last 𝔹 flip+ : (n : ℕ) → 𝔹+ n ↔ 𝔹+ n flip+ 0 = id↔ flip+ 1 = swap₊ flip+ (suc (suc n)) = id↔ ⊕ flip+ (suc n) -- flip* n (b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (b₁ ∧ … ∧ bₙ)) flip* : (n : ℕ) → (𝔹* n) ↔ (𝔹* n) flip* 0 = swap₊ flip* (suc n) = dist ⨾ (id↔ ⊕ (id↔ ⊗ flip* n)) ⨾ factor v* : (n : ℕ) → ⟦ 𝔹* n ⟧ v* 0 = 𝔽 v* 1 = 𝕋 , v* 0 v* (suc (suc n)) = 𝕋 , v* (suc n) v+ : (n : ℕ) → n ≢ 0 → ⟦ 𝔹+ n ⟧ v+ 0 0≠0 = 0≠0 refl v+ 1 _ = 𝔽 v+ (suc (suc n)) _ = inj₂ (v+ (suc n) (λ ())) -- Counting number of values in given context #ctx : ∀ {A B} → Context {A} {B} → ℕ #ctx ☐ = 0 #ctx (☐⨾ c₂ • κ) = #ctx κ #ctx (c₁ ⨾☐• κ) = #ctx κ #ctx (☐⊕ c₂ • κ) = #ctx κ #ctx (c₁ ⊕☐• κ) = #ctx κ #ctx (☐⊗[ c₂ , x ]• κ) = 1 + #ctx κ #ctx ([ c₁ , x ]⊗☐• κ) = 1 + #ctx κ #st : State → ℕ #st ⟨ c ∣ v ∣ κ ⟩ = 1 + #ctx κ #st [ c ∣ v ∣ κ ] = 1 + #ctx κ -- Returns the number of steps and maximum #st in a execution trace runST : ∀ {A B} → A ↔ B → ⟦ A ⟧ → List State × ℕ × ℕ runST c v = states , length states , foldl (λ { s st → s ⊔ #st st }) 0 states where states = evalₜᵣ c v -- Examples ex1 : ℕ × ℕ ex1 = let(_ , t , s) = runST (flip* 9) (v* 9) in (t , s) -- t=128 , s=10 ex2 : ℕ × ℕ ex2 = let (_ , t , s) = runST (flip+ 512) (v+ 512 (λ ())) in (t , s) -- t=1024 , s=1
{ "alphanum_fraction": 0.493006993, "avg_line_length": 26, "ext": "agda", "hexsha": "facd09331772b92b961b2821dc1bd8ed0a90d91c", "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": "TimeSpace.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": "TimeSpace.agda", "max_line_length": 110, "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": "TimeSpace.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": 1256, "size": 2288 }
open import Oscar.Prelude open import Oscar.Class.Smap open import Oscar.Data.Proposequality open import Oscar.Class.Surjection module Oscar.Data.Surjcollation where 𝓼urjcollation : ∀ {𝔵₁ 𝔵₂ 𝔞 𝔟} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (surjection : Surjection.type 𝔛₁ 𝔛₂) 𝔟̇ (𝔅 : 𝔛₂ → Ø 𝔟) (𝔄 : π̂² 𝔞 𝔛₁) → Ø 𝔵₁ ∙̂ 𝔞 ∙̂ 𝔟 ∙̂ ↑̂ 𝔟̇ 𝓼urjcollation surjection 𝔟̇ 𝔅 𝔄 = ∀ {m} → 𝔅 (surjection m) → 𝔅 (surjection m) → LeftṖroperty 𝔟̇ 𝔄 m module _ {𝔵₁ 𝔵₂ 𝔞 𝔟 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (𝔅 : 𝔛₂ → Ø 𝔟) (𝔄 : π̂² 𝔞 𝔛₁) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ (𝔅̇ : ∀̇ π̂² 𝔟̇ 𝔅) (let infix 4 _⟨𝔅̇⟩_ _⟨𝔅̇⟩_ : ∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇ _⟨𝔅̇⟩_ p q = 𝔅̇ p q) where surjcollation[_]⟦_/_⟧ : 𝓼urjcollation surjection 𝔟̇ 𝔅 𝔄 surjcollation[_]⟦_/_⟧ p q .π₀ x = x ◃ p ⟨𝔅̇⟩ x ◃ q module _ {𝔵₁ 𝔵₂ 𝔞 𝔟 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} {𝔅 : 𝔛₂ → Ø 𝔟} (𝔄 : π̂² 𝔞 𝔛₁) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ (𝔅̇ : ∀̇ π̂² 𝔟̇ 𝔅) where surjcollation⟦_/_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ ⟧ module _ {𝔵₁ 𝔵₂ 𝔞} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (𝔄 : 𝔛₁ → 𝔛₁ → Ø 𝔞) {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ {𝔟̇} {𝔅̇ : ∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇} where surjcollation⟦_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ ⟧ module _ {𝔵₁ 𝔵₂ 𝔞 𝔟} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (𝔅 : 𝔛₂ → Ø 𝔟) (𝔄 : π̂² 𝔞 𝔛₁) ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ where ≡-surjcollation[_]⟦_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / _≡_ ⟧ module _ {𝔵₁ 𝔞} {𝔛₁ : Ø 𝔵₁} (𝔄 : π̂² 𝔞 𝔛₁) {𝔵₂} {𝔛₂ : Ø 𝔵₂} ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ where ≡-surjcollation⟦_⟧ = ≡-surjcollation[ 𝔅 ]⟦ 𝔄 ⟧ module _ {𝔵₁ 𝔞} {𝔛₁ : Ø 𝔵₁} {𝔄 : π̂² 𝔞 𝔛₁} where ≡-surjcollation = ≡-surjcollation⟦ 𝔄 ⟧ module Surjcollation {𝔵₁ 𝔵₂ 𝔞 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄ (𝔄 : 𝔛₁ → 𝔛₁ → Ø 𝔞) (𝔅̇ : ∀ {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} → (∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇)) {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄ where method = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ {𝔅 = 𝔅} ⟧ infix 18 _⟹_ _⟹_ = method
{ "alphanum_fraction": 0.5253045923, "avg_line_length": 28.0789473684, "ext": "agda", "hexsha": "482448c3c1ed912fc17c56aa4e4bd01885074912", "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/Data/Surjcollation.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/Data/Surjcollation.agda", "max_line_length": 100, "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/Data/Surjcollation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1518, "size": 2134 }
{-# OPTIONS --without-K #-} -- Finished half of the proof! -- - functions between Bool * A and ∑ A are written -- - One direction of the inverse proof is done! -- -- Wrapping up the camera ready version of our -- PLDI paper took more time than I thought it would and so -- I got a late start on this. I think by class on Tuesday -- I could have the other half finished. -- -- Noet: I collaborated w/ Andre on this some. module thm8511part2 where open import Level using (_⊔_) open import Data.Bool using (Bool; true; false; if_then_else_) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Product using (_×_; _,_; proj₁; proj₂; Σ; Σ-syntax) open import Function renaming (_∘_ to _·_) import Relation.Binary.Core as C import Relation.Binary.PropositionalEquality as P --open P.≡-Reasoning infixr 8 _∘_ -- path composition infix 4 _≡_ -- propositional equality infix 4 _∼_ -- homotopy between two functions infix 4 _≃_ -- type of equivalences -- macros from tzaikin for equational rewriting over non-standard ≡ infixr 4 _≡⟨_⟩_ infix 4 _∎ indBool : (C : Bool → Set) → (C true) → (C false) → (b : Bool) → (C b) indBool C ct cf true = ct indBool C ct cf false = cf ind× : ∀ {A B : Set} {C : A × B → Set} → ((a : A) → (b : B) → C (a , b)) → (p : A × B) → (C p) ind× {C} f (a , b) = f a b ------------------------------------------------------------------------------ -- Some abbreviations and simple lemmas and paths _≡_ : ∀ {ℓ} {A : Set ℓ} → (x y : A) → Set ℓ _≡_ {ℓ} {A} x y = C._≡_ {ℓ} {A} x y -- Groupoid refl : ∀ {ℓ} {A} → (x : A) → x ≡ x refl {ℓ} {A} x = C.refl {ℓ} {A} {x} ! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x) ! = P.sym _∘_ : ∀ {ℓ} {A : Set ℓ} {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) _∘_ = P.trans unitTransL : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x ∘ p) unitTransL C.refl = C.refl unitTransR : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ p ∘ refl y) unitTransR C.refl = C.refl invComp : {A : Set} {x y z : A} → (p : x ≡ y) → (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p invComp C.refl C.refl = C.refl assocP : {A : Set} {x y z w : A} → (p : x ≡ y) → (q : y ≡ z) → (r : z ≡ w) → (p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r) assocP C.refl C.refl C.refl = C.refl invTransL : {A : Set} {x y : A} → (p : x ≡ y) → (! p ∘ p ≡ refl y) invTransL C.refl = C.refl invId : {A : Set} {x y : A} → (p : x ≡ y) → (! (! p) ≡ p) invId C.refl = C.refl -- Handy "macros" (from tzaikin) _∎ : ∀ {ℓ} → {A : Set ℓ} → (p : A) → p ≡ p p ∎ = refl p _≡⟨_⟩_ : ∀ {ℓ} → {A : Set ℓ} → {q r : A} → (p : A) → p ≡ q → q ≡ r → p ≡ r p ≡⟨ α ⟩ β = α ∘ β -- Functors ap : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂} → (f : A → B) → {x y : A} → (x ≡ y) → (f x ≡ f y) ap = P.cong apfId : {A : Set} {x y : A} → (p : x ≡ y) → ap id p ≡ p apfId C.refl = C.refl apfInv : ∀ {u} → {A B : Set u} {x y : A} → (f : A → B) → (p : x ≡ y) → ap f (! p) ≡ ! (ap f p) apfInv f C.refl = C.refl apfTrans : ∀ {u} → {A B : Set u} {x y z : A} → (f : A → B) → (p : x ≡ y) → (q : y ≡ z) → ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q) apfTrans f C.refl C.refl = C.refl apfComp : {A B C : Set} {x y : A} → (f : A → B) → (g : B → C) → (p : x ≡ y) → ap g (ap f p) ≡ ap (g · f) p apfComp f g C.refl = C.refl apconst : {A B : Set} {x y : A} → (p : x ≡ y) (b : B) → ap (λ _ → b) p ≡ refl b apconst C.refl b = C.refl -- Transport transport : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} (B : A → Set ℓ₂) → {x y : A} → (x ≡ y) → B x → B y transport = P.subst transportId : {A B : Set} {y z : A} → (f g : A → B) → (p : y ≡ z) → (q : f y ≡ g y) → transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ q ∘ (ap g p) transportId f g C.refl q = (q ≡⟨ unitTransR q ⟩ q ∘ C.refl ≡⟨ unitTransL (q ∘ C.refl) ⟩ ! C.refl ∘ (q ∘ C.refl) ∎) apd : ∀ {ℓ₁ ℓ₂} → {A : Set ℓ₁} {B : A → Set ℓ₂} → (f : (x : A) → B x) → {x y : A} → (p : x ≡ y) → transport B p (f x) ≡ f y apd f C.refl = C.refl -- Homotopies and equivalences _∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} → (f g : (x : A) → P x) → Set (ℓ ⊔ ℓ') _∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkqinv field g : B → A α : (f · g) ∼ id β : (g · f) ∼ id record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkisequiv field g : B → A α : (f · g) ∼ id h : B → A β : (h · f) ∼ id iso : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f iso (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ') A ≃ B = Σ (A → B) isequiv postulate univalence : {A B : Set} → (A ≡ B) ≃ (A ≃ B) ------------------------------------------------------------------------------ -- Some higher-inductive types module Circle where private data S¹* : Set where base* : S¹* -- define the interface for S¹ S¹ : Set S¹ = S¹* base : S¹ base = base* postulate loop : base ≡ base -- recursion principle recS¹ : {C : Set} → (cbase : C) → (cloop : cbase ≡ cbase) → S¹ → C recS¹ cbase cloop base* = cbase postulate βrecS¹ : {C : Set} → (cbase : C) → (cloop : cbase ≡ cbase) → ap (recS¹ cbase cloop) loop ≡ cloop -- induction principle indS¹ : {C : S¹ → Set} → (cbase : C base) → (cloop : transport C loop cbase ≡ cbase) → (circle : S¹) → C circle indS¹ cbase cloop base* = cbase ------------------------------------------------------------------------------ module Suspension where private data ∑* (A : Set) : Set where N* : ∑* A S* : ∑* A -- define the interface for ∑A ∑ : (A : Set) → Set ∑ = ∑* N : {A : Set} → ∑ A N = N* S : {A : Set} → ∑ A S = S* postulate merid : {A : Set} → A → (N {A} ≡ S {A}) -- recursion principle rec∑ : {A : Set} → {C : Set} → (cn cs : C) → (cm : A → (cn ≡ cs)) → ∑ A → C rec∑ cn cs cm N* = cn rec∑ cn cs cm S* = cs postulate βrec∑ : {A : Set} → {C : Set} → (cn cs : C) → (cm : A → (cn ≡ cs)) → (a : A) → ap (rec∑ cn cs cm) (merid a) ≡ (cm a) -- induction principle ind∑ : {A : Set} → {C : ∑ A → Set} → (cn : C N) → (cs : C S) → ((a : A) → transport C (merid a) cn ≡ cs) → (s : ∑ A) → C s ind∑ cn cs m N* = cn ind∑ cn cs m S* = cs ------------------------------------------------------------------------------ module Join where private data _**_ (A B : Set) : Set where inl* : A → A ** B inr* : B → A ** B -- define the interface for A*B _*_ : (A B : Set) → Set A * B = A ** B inl : {A B : Set} → A → A * B inl = inl* inr : {A B : Set} → B → A * B inr = inr* postulate glue : {A B : Set} → (c : A × B) → inl (proj₁ c) ≡ inr (proj₂ c) -- recursion principle rec* : {A B : Set} {D : Set} → (ad : A → D) → (bd : B → D) → (gd : (c : A × B) → ad (proj₁ c) ≡ bd (proj₂ c)) → A * B → D rec* ad bd gd (inl* a) = ad a rec* ad bd gd (inr* b) = bd b postulate βrec* : {A B : Set} {D : Set} → (ad : A → D) → (bd : B → D) → (gd : (c : A × B) → ad (proj₁ c) ≡ bd (proj₂ c)) → (c : A × B) → ap (rec* ad bd gd) (glue c) ≡ gd c -- induction principle ind* : {A B : Set} {D : A * B → Set} → (ad : (a : A) → D (inl a)) → (bd : (b : B) → D (inr b)) → (gd : (c : A × B) → transport D (glue c) (ad (proj₁ c)) ≡ bd (proj₂ c)) (c : A * B) → D c ind* ad bd gd (inl* a) = ad a ind* ad bd gd (inr* b) = bd b ------------------------------------------------------------------------------ -- Lemma 6.5.1 module ∑Bool≡S¹ where open Circle open Suspension east : N ≡ S east = merid false west : N ≡ S west = merid true -- S¹ → ∑ Bool fcircle : S¹ → ∑ Bool fcircle = recS¹ N (east ∘ ! west) floop : ap fcircle loop ≡ east ∘ ! west floop = βrecS¹ N (east ∘ ! west) -- ∑ Bool → S¹ gcircle : ∑ Bool → S¹ gcircle = rec∑ base base (λ b → if b then refl base else loop) geast : ap gcircle east ≡ loop geast = βrec∑ base base (λ b → if b then refl base else loop) false gwest : ap gcircle west ≡ (refl base) gwest = βrec∑ base base (λ b → if b then refl base else loop) true -- round trip S¹ → S¹ gf : S¹ → S¹ gf = gcircle · fcircle gfloop : ap gf loop ≡ loop gfloop = (ap gf loop ≡⟨ ! (apfComp fcircle gcircle loop) ⟩ ap gcircle (ap fcircle loop) ≡⟨ ap (ap gcircle) floop ⟩ ap gcircle (east ∘ ! west) ≡⟨ apfTrans gcircle east (! west) ⟩ ap gcircle east ∘ ap gcircle (! west) ≡⟨ ap (λ x → ap gcircle east ∘ x) (apfInv gcircle west) ⟩ ap gcircle east ∘ ! (ap gcircle west) ≡⟨ ap (λ x → ap gcircle east ∘ ! x) gwest ⟩ ap gcircle east ∘ (refl base) ≡⟨ ! (unitTransR (ap gcircle east)) ⟩ ap gcircle east ≡⟨ geast ⟩ loop ∎) αloop : transport (λ x → gf x ≡ x) loop (refl base) ≡ refl base αloop = (transport (λ x → gf x ≡ x) loop (refl base) ≡⟨ transportId gf id loop (refl base) ⟩ ! (ap gf loop) ∘ refl base ∘ ap id loop ≡⟨ ap (λ x → ! (ap gf loop) ∘ refl base ∘ x) (apfId loop) ⟩ ! (ap gf loop) ∘ refl base ∘ loop ≡⟨ ap (λ x → ! (ap gf loop) ∘ x) (! (unitTransL loop)) ⟩ ! (ap gf loop) ∘ loop ≡⟨ ap (λ x → ! x ∘ loop) gfloop ⟩ ! loop ∘ loop ≡⟨ invTransL loop ⟩ refl base ∎) βcircle : gf ∼ id βcircle = indS¹ {λ x → gf x ≡ x} (refl base) αloop -- round trip ∑ Bool → ∑ Bool fg : ∑ Bool → ∑ Bool fg = fcircle · gcircle fgeast : ap fg east ≡ east ∘ ! west fgeast = (ap fg east ≡⟨ ! (apfComp gcircle fcircle east) ⟩ ap fcircle (ap gcircle east) ≡⟨ ap (ap fcircle) geast ⟩ ap fcircle loop ≡⟨ floop ⟩ (east ∘ ! west) ∎) fgwest : ap fg west ≡ refl N fgwest = (ap fg west ≡⟨ ! (apfComp gcircle fcircle west) ⟩ ap fcircle (ap gcircle west) ≡⟨ ap (ap fcircle) gwest ⟩ ap fcircle (refl base) ≡⟨ C.refl ⟩ refl N ∎) αeast : transport (λ x → fg x ≡ x) east (refl N) ≡ west αeast = (transport (λ x → fg x ≡ x) east (refl N) ≡⟨ transportId fg id east (refl N) ⟩ ! (ap fg east) ∘ refl N ∘ ap id east ≡⟨ ap (λ x → ! (ap fg east) ∘ refl N ∘ x) (apfId east) ⟩ ! (ap fg east) ∘ refl N ∘ east ≡⟨ ap (λ x → ! (ap fg east) ∘ x) (! (unitTransL east)) ⟩ ! (ap fg east) ∘ east ≡⟨ ap (λ x → ! x ∘ east) fgeast ⟩ ! (east ∘ ! west) ∘ east ≡⟨ ap (λ x → x ∘ east) (invComp east (! west)) ⟩ (! (! west) ∘ ! east) ∘ east ≡⟨ ! (assocP (! (! west)) (! east) east) ⟩ ! (! west) ∘ ! east ∘ east ≡⟨ ap (λ x → ! (! west) ∘ x) (invTransL east) ⟩ ! (! west) ∘ refl S ≡⟨ ! (unitTransR (! (! west))) ⟩ ! (! west) ≡⟨ invId west ⟩ west ∎) αwest : transport (λ x → fg x ≡ x) west (refl N) ≡ west αwest = (transport (λ x → fg x ≡ x) west (refl N) ≡⟨ transportId fg id west (refl N) ⟩ ! (ap fg west) ∘ refl N ∘ ap id west ≡⟨ ap (λ x → ! (ap fg west) ∘ refl N ∘ x) (apfId west) ⟩ ! (ap fg west) ∘ refl N ∘ west ≡⟨ ap (λ x → ! (ap fg west) ∘ x) (! (unitTransL west)) ⟩ ! (ap fg west) ∘ west ≡⟨ ap (λ x → ! x ∘ west) fgwest ⟩ ! (refl N) ∘ west ≡⟨ ! (unitTransL west) ⟩ west ∎) αcircle : fg ∼ id αcircle = ind∑ (refl N) west (λ { false → αeast; true → αwest }) -- main lemmas equivlemma : ∑ Bool ≃ S¹ equivlemma = (gcircle , iso (mkqinv fcircle βcircle αcircle)) lemma : ∑ Bool ≡ S¹ lemma with univalence ... | (_ , eq) = isequiv.g eq equivlemma ------------------------------------------------------------------------------ -- Lemma 8.5.10 module ∑A≡Bool*A {A : Set} where open Suspension open Join f : ∑ A → Bool * A f = rec∑ (inl true) (inl false) (λ a → glue (true , a) ∘ ! (glue (false , a))) fmerid : (a : A) → ap f (merid a) ≡ glue (true , a) ∘ ! (glue (false , a)) fmerid = βrec∑ (inl true) (inl false) (λ a → glue (true , a) ∘ ! (glue (false , a))) g : Bool * A → ∑ A g = rec* (λ b → if b then N else S) (λ a → S) (λ c → indBool (λ b → (if b then N else S) ≡ S) (merid (proj₂ c)) (refl S) (proj₁ c)) fg = f · g gf = g · f gglue-true : (a : A) → (ap g (glue (true , a))) ≡ merid a gglue-true a = βrec* (λ b → if b then N else S) (λ a → S) (λ c → indBool (λ b → (if b then N else S) ≡ S) (merid (proj₂ c)) (refl S) (proj₁ c)) (true , a) gglue-false : (a : A) → (ap g (glue (false , a))) ≡ refl S gglue-false a = βrec* (λ b → if b then N else S) (λ a → S) (λ c → indBool (λ b → (if b then N else S) ≡ S) (merid (proj₂ c)) (refl S) (proj₁ c)) (false , a) α : (f · g) ∼ id α = ind* (indBool (λ b → fg (inl b) ≡ id (inl b)) (refl (inl true)) (refl (inl false))) (λ a → glue (false , a)) (λ c → ind× (λ b a → indBool (λ b → transport (λ z → fg z ≡ id z) (glue (b , a)) (indBool (λ b₁ → fg (inl b₁) ≡ id (inl b₁)) (refl (inl true)) (refl (inl false)) b) ≡ glue (false , a)) -- big α equivalence proof 1 (transport (λ z → fg z ≡ id z) (glue (true , a)) (refl (inl true)) ≡⟨ transportId fg id (glue (true , a)) (refl (inl true)) ⟩ ((! (ap fg (glue (true , a)))) ∘ (refl (inl true)) ∘ ap id (glue (true , a))) ≡⟨ ap (λ p → ((! (ap fg (glue (true , a)))) ∘ (refl (inl true)) ∘ p)) (apfId (glue (true , a))) ⟩ ((! (ap fg (glue (true , a)))) ∘ (refl (inl true)) ∘ (glue (true , a))) ≡⟨ ap (λ p → ((! (ap fg (glue (true , a)))) ∘ p)) (unitTransL (glue (true , a))) ⟩ ((! (ap (f · g) (glue (true , a)))) ∘ (glue (true , a))) ≡⟨ ap (λ p → ((! p) ∘ (glue (true , a)))) (! (apfComp g f (glue (true , a)))) ⟩ ((! (ap f (ap g (glue (true , a))))) ∘ (glue (true , a))) ≡⟨ ap (λ p → (! (ap f p)) ∘ (glue (true , a))) (gglue-true a) ⟩ ((! (ap f (merid a))) ∘ (glue (true , a))) ≡⟨ ap (λ p → (! p) ∘ (glue (true , a))) (fmerid a) ⟩ ((! (glue (true , a) ∘ ! (glue (false , a)))) ∘ (glue (true , a))) ≡⟨ ap (λ p → (p ∘ (glue (true , a)))) (invComp (glue (true , a)) (! (glue (false , a)))) ⟩ ((! (! (glue (false , a)))) ∘ (! (glue (true , a)))) ∘ (glue (true , a)) ≡⟨ ! (assocP (! (! (glue (false , a)))) (! (glue (true , a))) (glue (true , a))) ⟩ (! (! (glue (false , a)))) ∘ ((! (glue (true , a))) ∘ (glue (true , a))) ≡⟨ ap (λ p → (! (! (glue (false , a)))) ∘ p) (invTransL (glue (true , a))) ⟩ (! (! (glue (false , a)))) ∘ (refl (inr a)) ≡⟨ ! (unitTransR (! (! (glue (false , a))))) ⟩ (! (! (glue (false , a)))) ≡⟨ (invId (glue (false , a))) ⟩ (glue (false , a)) ∎) -- big α equivalence proof 2 ((transport (λ z → fg z ≡ id z) (glue (false , a)) (refl (inl false)) ≡⟨ transportId fg id (glue (false , a)) (refl (inl false)) ⟩ ((! (ap fg (glue (false , a)))) ∘ (refl (inl false)) ∘ ap id (glue (false , a))) ≡⟨ ap (λ p → (! (ap fg (glue (false , a)))) ∘ (refl (inl false)) ∘ p) (apfId (glue (false , a))) ⟩ ((! (ap fg (glue (false , a)))) ∘ ((refl (inl false)) ∘ (glue (false , a)))) ≡⟨ ap (λ p → (! (ap fg (glue (false , a)))) ∘ p) (unitTransL (glue (false , a))) ⟩ (! (ap (f · g) (glue (false , a)))) ∘ (glue (false , a)) ≡⟨ ! (ap (λ p → (! p) ∘ (glue (false , a))) (apfComp g f (glue (false , a)))) ⟩ (! (ap f (ap g (glue (false , a))))) ∘ (glue (false , a)) ≡⟨ ap (λ p → (! (ap f p)) ∘ (glue (false , a))) (gglue-false a) ⟩ (! (ap f (refl S))) ∘ (glue (false , a)) ≡⟨ C.refl ⟩ (refl (inl false)) ∘ (glue (false , a)) ≡⟨ unitTransL (glue (false , a)) ⟩ (glue (false , a)) ∎)) b) c) -- fmerid : (a : A) → -- ap f (merid a) ≡ glue (true , a) ∘ ! (glue (false , a)) β : (g · f) ∼ id β = ind∑ (refl N) (refl S) (λ a → transport (λ z → gf z ≡ id z) (merid a) (refl N) ≡⟨ transportId gf id (merid a) (refl N) ⟩ ((! (ap gf (merid a))) ∘ (refl N) ∘ ap id (merid a)) ≡⟨ ap (λ p → ((! (ap gf (merid a))) ∘ (refl N) ∘ p)) (apfId (merid a)) ⟩ ((! (ap gf (merid a))) ∘ (refl N) ∘ (merid a)) ≡⟨ ap (λ p → (! (ap gf (merid a))) ∘ p) (! (unitTransL (merid a))) ⟩ ((! (ap (g · f) (merid a))) ∘ (merid a)) ≡⟨ ap (λ p → (! p) ∘ (merid a)) (! (apfComp f g (merid a))) ⟩ ((! (ap g (ap f (merid a)))) ∘ (merid a)) ≡⟨ ap (λ p → ((! (ap g p)) ∘ (merid a))) (fmerid a) ⟩ ((! (ap g (glue (true , a) ∘ ! (glue (false , a))))) ∘ (merid a)) ≡⟨ ap (λ p → (! p) ∘ (merid a)) (apfTrans g (glue (true , a)) (! (glue (false , a)))) ⟩ ((! ((ap g (glue (true , a))) ∘ (ap g (! (glue (false , a)))))) ∘ (merid a)) ≡⟨ ap (λ p → ((! (p ∘ (ap g (! (glue (false , a)))))) ∘ (merid a))) (gglue-true a) ⟩ ((! ((merid a) ∘ (ap g (! (glue (false , a)))))) ∘ (merid a)) ≡⟨ ap (λ p → ((! ((merid a) ∘ p)) ∘ (merid a))) (apfInv g (glue (false , a))) ⟩ ((! ((merid a) ∘ (! (ap g (glue (false , a)))))) ∘ (merid a)) ≡⟨ ap (λ p → ((! ((merid a) ∘ (! p))) ∘ (merid a))) (gglue-false a) ⟩ ((! ((merid a) ∘ (! (refl S)))) ∘ (merid a)) ≡⟨ C.refl ⟩ ((! ((merid a) ∘ (refl S))) ∘ (merid a)) ≡⟨ ap (λ p → (! p) ∘ (merid a)) (! (unitTransR (merid a))) ⟩ ((! (merid a)) ∘ (merid a)) ≡⟨ invTransL (merid a) ⟩ refl S ∎) ΣA≃Bool*A : ∑ A ≃ Bool * A ΣA≃Bool*A = (f , iso (mkqinv g α β)) lemma : ∑ A ≡ Bool * A lemma with univalence ... | (_ , eq) = isequiv.g eq ΣA≃Bool*A ------------------------------------------------------------------------------ -- Lemma 8.5.9 module JoinAssoc where open Join lemma : {A B C : Set} → (A * B) * C ≡ A * (B * C) lemma {A} {B} {C} = {!!} ------------------------------------------------------------------------------ -- Thm 8.5.11 open Circle open Suspension open Join S² S³ : Set S² = ∑ S¹ S³ = ∑ S² -- Proof of the main theorem S¹*S¹≡S³ : S¹ * S¹ ≡ S³ S¹*S¹≡S³ = (S¹ * S¹ ≡⟨ P.cong (λ a → a * S¹) (! ∑Bool≡S¹.lemma) ⟩ ∑ Bool * S¹ ≡⟨ P.cong (λ a → a * S¹) ∑A≡Bool*A.lemma ⟩ (Bool * Bool) * S¹ ≡⟨ JoinAssoc.lemma ⟩ Bool * (Bool * S¹) ≡⟨ P.cong (λ b → Bool * b) (! ∑A≡Bool*A.lemma) ⟩ Bool * S² ≡⟨ ! ∑A≡Bool*A.lemma ⟩ S³ ∎) ------------------------------------------------------------------------------
{ "alphanum_fraction": 0.38194154, "avg_line_length": 31.3688046647, "ext": "agda", "hexsha": "f2865517330e22f23c9ed36b286e658d86152436", "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": "b05c58ffdaed99932ca2acc632deca8d14742b04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andmkent/misc-HoTT", "max_forks_repo_path": "thm8511part2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04", "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": "andmkent/misc-HoTT", "max_issues_repo_path": "thm8511part2.agda", "max_line_length": 107, "max_stars_count": 1, "max_stars_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andmkent/misc-HoTT", "max_stars_repo_path": "thm8511part2.agda", "max_stars_repo_stars_event_max_datetime": "2016-01-26T18:17:16.000Z", "max_stars_repo_stars_event_min_datetime": "2016-01-26T18:17:16.000Z", "num_tokens": 8070, "size": 21519 }
-- Properties involving susbets and membership -- between sets. module sv20.assign2.SetTheory.Subset where open import sv20.assign2.SetTheory.Logic open import sv20.assign2.SetTheory.ZAxioms memberEq : (x y z : 𝓢) → x ∈ y ∧ y ≡ z → x ∈ z memberEq x y z (x₁ , x₂) = subs _ x₂ x₁ -- Theorem 1, p. 21 (Suppes 1960) notInEmpty : ∀ x → x ∉ ∅ notInEmpty x h = (proj₂ _ empt) x h prop-∅ : (x A : 𝓢) → x ∈ A → A ≢ ∅ prop-∅ x A x∈A h = notInEmpty x (subs _ h x∈A) prop₂-∅ : (x : 𝓢) → ∃ (λ y → y ∈ x) → x ≢ ∅ prop₂-∅ x h₁ h₂ = cont _ (h₂ , prop-∅ _ _ aux-p) where aux : 𝓢 aux = proj₁ h₁ aux-p : aux ∈ x aux-p = proj₂ _ h₁ -- Theorem 3, p. 22 (Suppes 1960) subsetOfItself : ∀ {x} → x ⊆ x subsetOfItself _ t∈x = t∈x -- Theorem 4, p. 22 (Suppes 1960) equalitySubset : (x y : 𝓢) → x ⊆ y ∧ y ⊆ x → x ≡ y equalitySubset x y (x⊆y , y⊆x) = ext x y ((x⊆y x) , (y⊆x x)) -- Theorem 6, p. 23 (Suppes 1960) trans-⊆ : (x y z : 𝓢) → x ⊆ y ∧ y ⊆ z → x ⊆ z trans-⊆ x y z (x⊆y , y⊆z) t t∈x = y⊆z t (x⊆y t t∈x) -- Theorem 7, p. 23 (Suppes 1960) notContainedInItself : ∀ {x} → ¬ (x ⊂ x) notContainedInItself (_ , x≢x) = x≢x refl -- Theorem 8, p. 23 (Suppes 1960) nonSymmetry-⊂ : (x y : 𝓢) (p : x ⊂ y) → ¬ (y ⊂ x) nonSymmetry-⊂ x y (x⊆y , x≢y) (y⊆x , _) = x≢y (equalitySubset x y (x⊆y , y⊆x)) -- Theorem 10, p. 23 (Suppes 1960) ⊂→⊆ : ∀ {x y} → x ⊂ y → x ⊆ y ⊂→⊆ (x⊆y , _) z z∈x = x⊆y z z∈x prop-⊆ : (x A B : 𝓢) → x ∈ A → A ⊆ B → x ∈ B prop-⊆ x A B x₁ x₂ = i x₁ where i : x ∈ A → x ∈ B i = x₂ _ -- References -- -- Suppes, Patrick (1960). Axiomatic Set Theory. -- The University Series in Undergraduate Mathematics. -- D. Van Nostrand Company, inc. -- -- Enderton, Herbert B. (1977). Elements of Set Theory. -- Academic Press Inc.
{ "alphanum_fraction": 0.5585689556, "avg_line_length": 25.8656716418, "ext": "agda", "hexsha": "9f558b292a09ce04aea3eff87a9268c11125288b", "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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "helq/old_code", "max_forks_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Subset.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z", "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "helq/old_code", "max_issues_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Subset.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "helq/old_code", "max_stars_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Subset.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 858, "size": 1733 }
module NaturalAndLevelDifferent where data ℕ : Set where zero : ℕ suc : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} {-# BUILTIN LEVEL ℕ #-}
{ "alphanum_fraction": 0.6277372263, "avg_line_length": 15.2222222222, "ext": "agda", "hexsha": "b56da36ece26004eedbb7165a66f3c762e644b68", "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/NaturalAndLevelDifferent.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/NaturalAndLevelDifferent.agda", "max_line_length": 37, "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/NaturalAndLevelDifferent.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": 40, "size": 137 }
{-# OPTIONS --allow-unsolved-metas #-} -- {-# OPTIONS -v tc.rewrite:25 -v tc.with:40 --show-implicit #-} -- {-# OPTIONS -v tc:100 #-} -- Andreas, 2014-05-17, reported by Fabien Renaud. -- Error in reification of interaction metas -- leading to strange error messages for rewrite. module _ where open import Common.Prelude open import Common.Equality postulate comm : ∀{n m} → n + m ≡ m + n -- module With where -- foo : ∀{x y} → x + (x + y) ≡ x + (y + x) -- foo {x} {y} with x + y | comm {x} {y} -- foo | ._ | refl = refl test0 : ∀{x y} → x + (x + y) ≡ x + (y + x) test0 rewrite comm {n = {!!}} {m = {!!}} = {!!} test : ∀{x y} → x + (x + y) ≡ x + (y + x) test {x}{y} rewrite comm {n = {!!}} {m = {!!}} = {!!} -- Error WAS: -- .Agda.Primitive.Level !=< Nat of type Set -- when checking that the expression ?0 has type Nat -- Now this type checks.
{ "alphanum_fraction": 0.5555555556, "avg_line_length": 24.6857142857, "ext": "agda", "hexsha": "4917dd866f846fb4760790f9f38a8a5b74e43005", "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/Issue1111.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/Issue1111.agda", "max_line_length": 65, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1111.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": 299, "size": 864 }
{-# OPTIONS --without-K #-} open import Type open import Type.Identities open import Level.NP open import Data.Two open import Function open import Function.Extensionality open import Data.Product open import Data.Sum open import Data.Fin open import Relation.Binary.PropositionalEquality.NP using (_≡_; refl; !_; _∙_) open import Relation.Binary.Sum open import HoTT open import Explore.Sum open import Explore.Core open import Explore.Properties open import Explore.Explorable module Explore.Two where module _ {ℓ} where 𝟚ᵉ : Explore ℓ 𝟚 𝟚ᵉ _ _∙_ f = f 0₂ ∙ f 1₂ 𝟚ⁱ : ∀ {p} → ExploreInd p 𝟚ᵉ 𝟚ⁱ _ _ _P∙_ Pf = Pf 0₂ P∙ Pf 1₂ module _ {ℓ₁ ℓ₂ ℓᵣ} {R : 𝟚 → 𝟚 → ★₀} {r0 : R 0₂ 0₂}{r1 : R 1₂ 1₂} where ⟦𝟚ᵉ⟧ : ⟦Explore⟧ {ℓ₁} {ℓ₂} ℓᵣ R 𝟚ᵉ 𝟚ᵉ ⟦𝟚ᵉ⟧ _ _ _∙ᵣ_ fᵣ = fᵣ r0 ∙ᵣ fᵣ r1 module 𝟚ⁱ = FromExploreInd 𝟚ⁱ open 𝟚ⁱ public using () renaming (sum to 𝟚ˢ ;product to 𝟚ᵖ ;reify to 𝟚ʳ ;unfocus to 𝟚ᵘ ) module _ {ℓ} where module _ {{_ : UA}}{{_ : FunExt}} where Σᵉ𝟚-ok : Adequate-Σ {ℓ} (Σᵉ 𝟚ᵉ) Σᵉ𝟚-ok _ = ! Σ𝟚-⊎ Πᵉ𝟚-ok : Adequate-Π {ℓ} (Πᵉ 𝟚ᵉ) Πᵉ𝟚-ok _ = ! Π𝟚-× 𝟚ˡ : Lookup {ℓ} 𝟚ᵉ 𝟚ˡ = proj 𝟚ᶠ : Focus {ℓ} 𝟚ᵉ 𝟚ᶠ (0₂ , x) = inj₁ x 𝟚ᶠ (1₂ , x) = inj₂ x explore𝟚 = 𝟚ᵉ explore𝟚-ind = 𝟚ⁱ lookup𝟚 = 𝟚ˡ reify𝟚 = 𝟚ʳ focus𝟚 = 𝟚ᶠ unfocus𝟚 = 𝟚ᵘ sum𝟚 = 𝟚ˢ module _ {{_ : UA}}{{_ : FunExt}} where open Adequacy _≡_ 𝟚ˢ-ok : Adequate-sum 𝟚ˢ 𝟚ˢ-ok f = ! (Σ𝟚-⊎ ∙ Fin-⊎-+)
{ "alphanum_fraction": 0.5927868852, "avg_line_length": 22.1014492754, "ext": "agda", "hexsha": "df1a2e05e4d48050ab3a43b8003bdbfa4df8a10b", "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": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/Two.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/Two.agda", "max_line_length": 79, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/Two.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 841, "size": 1525 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Membership for containers ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Container.Membership where open import Level using (_⊔_) open import Relation.Unary using (Pred) open import Relation.Binary.PropositionalEquality open import Data.Container.Core open import Data.Container.Relation.Unary.Any module _ {s p} {C : Container s p} {x} {X : Set x} where infix 4 _∈_ _∈_ : X → Pred (⟦ C ⟧ X) (p ⊔ x) x ∈ xs = ◇ C (_≡_ x) xs
{ "alphanum_fraction": 0.5235008104, "avg_line_length": 26.8260869565, "ext": "agda", "hexsha": "68892e8e4f1963a56a429831b5a0c83f27da4e72", "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/Data/Container/Membership.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/Container/Membership.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/Data/Container/Membership.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": 146, "size": 617 }
{-# OPTIONS --cubical --safe #-} module Data.Maybe.Properties where open import Data.Maybe.Base open import Prelude fromMaybe : A → Maybe A → A fromMaybe x = maybe x id just-inj : ∀ {x y : A} → just x ≡ just y → x ≡ y just-inj {x = x} = cong (fromMaybe x) just≢nothing : {x : A} → just x ≢ nothing just≢nothing p = subst (maybe ⊥ (const ⊤)) p tt nothing≢just : {x : A} → nothing ≢ just x nothing≢just p = subst (maybe ⊤ (const ⊥)) p tt discreteMaybe : Discrete A → Discrete (Maybe A) discreteMaybe _≟_ nothing nothing = yes refl discreteMaybe _≟_ nothing (just x) = no nothing≢just discreteMaybe _≟_ (just x) nothing = no just≢nothing discreteMaybe _≟_ (just x) (just y) = ⟦yes cong just ,no just-inj ⟧ (x ≟ y)
{ "alphanum_fraction": 0.6643454039, "avg_line_length": 28.72, "ext": "agda", "hexsha": "8763be39a8ae9d7838c6a18884d654191d5ef4c9", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Data/Maybe/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Data/Maybe/Properties.agda", "max_line_length": 75, "max_stars_count": 4, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Data/Maybe/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "num_tokens": 253, "size": 718 }
{-# OPTIONS --without-K #-} open import Base import Homotopy.TruncationHIT as T {- The definition of the truncation is in TruncationHIT, here I just make some arguments implicit, define easier to use helper functions and prove the universal property -} module Homotopy.Truncation {i} where τ : (n : ℕ₋₂) → (Set i → Set i) τ = T.τ proj : {n : ℕ₋₂} {A : Set i} → (A → τ n A) proj {n} {A} = T.proj n A τ-is-truncated : (n : ℕ₋₂) (A : Set i) → is-truncated n (τ n A) τ-is-truncated = T.τ-is-truncated τ-is-truncated#instance : {n : ℕ₋₂} {A : Set i} → is-truncated n (τ n A) τ-is-truncated#instance = T.τ-is-truncated _ _ τ-extend : ∀ {j} {n : ℕ₋₂} {A : Set i} {P : (τ n A) → Set j} ⦃ p : (x : τ n A) → is-truncated n (P x) ⦄ (f : (x : A) → P (proj x)) → ((x : τ n A) → P x) τ-extend {j} {n} {A} {P} ⦃ p ⦄ f = T.τ-rec _ _ _ f {transp} p where abstract transp : (pa : n ≡ ⟨-2⟩) (x y : τ n A) (x* : P x) (y* : P y) → transport P (T.hack-prop n A pa x y) x* ≡ y* transp pa x y x* y* = π₁ (contr-is-prop (transport (λ m → is-truncated m _) pa (p y)) _ _) τ-extend-nondep : ∀ {j} {n : ℕ₋₂} {A : Set i} {B : Set j} ⦃ p : is-truncated n B ⦄ → ((f : A → B) → (τ n A → B)) τ-extend-nondep {j} {n} {A} {B} ⦃ p ⦄ f = T.τ-rec-nondep _ _ _ f {transp} p where abstract transp : (pa : n ≡ ⟨-2⟩) (x y : τ n A) (x* y* : B) → x* ≡ y* transp pa x y x* y* = π₁ (contr-is-prop (transport (λ m → is-truncated m _) pa p) _ _) -- Special syntax for hProp-reflection [_] : Set i → Set i [_] = τ ⟨-1⟩ abstract []-is-prop : {A : Set i} → is-prop [ A ] []-is-prop = T.τ-is-truncated _ _ []-extend : ∀ {j} {A : Set i} {P : [ A ] → Set j} ⦃ p : (x : [ A ]) → is-prop (P x) ⦄ (f : (x : A) → P (proj x)) → ((x : [ A ]) → P x) []-extend f = τ-extend f []-extend-nondep : ∀ {j} {A : Set i} {B : Set j} ⦃ p : is-prop B ⦄ → ((f : A → B) → ([ A ] → B)) []-extend-nondep f = τ-extend-nondep f -- Special syntax for hSet-reflection π₀ : Set i → Set i π₀ = τ ⟨0⟩ π₀-is-set : (A : Set i) → is-set (π₀ A) π₀-is-set A = T.τ-is-truncated _ _ π₀-extend : ∀ {j} {A : Set i} {P : π₀ A → Set j} ⦃ p : (x : π₀ A) → is-set (P x) ⦄ (f : (x : A) → P (proj x)) → ((x : π₀ A) → P x) π₀-extend f = τ-extend f π₀-extend-nondep : ∀ {j} {A : Set i} {B : Set j} ⦃ p : is-set B ⦄ → ((f : A → B) → (π₀ A → B)) π₀-extend-nondep f = τ-extend-nondep f -- Universal property of the truncation abstract τ-up : ∀ {j} (n : ℕ₋₂) (A : Set i) (B : Set j) ⦃ p : is-truncated n B ⦄ → is-equiv (λ (f : τ n A → B) → (λ x → f (proj x))) τ-up n A B ⦃ p ⦄ = iso-is-eq _ (τ-extend-nondep) (λ _ → refl) (λ f → funext (τ-extend ⦃ p = λ x → ≡-is-truncated n p ⦄ (λ x → refl))) τ-extend-nondep-is-equiv : ∀ {j} (n : ℕ₋₂) (A : Set i) (B : Set j) ⦃ p : is-truncated n B ⦄ → is-equiv (τ-extend-nondep {n = n} {A} {B}) τ-extend-nondep-is-equiv n A B ⦃ p ⦄ = iso-is-eq _ (λ f → f ◯ proj) (λ f → funext (τ-extend ⦃ λ x → ≡-is-truncated n p ⦄ (λ x → refl))) (λ _ → refl) -- Equivalence associated to the universal property τ-equiv : ∀ {j} (n : ℕ₋₂) (A : Set i) (B : Set j) ⦃ p : is-truncated n B ⦄ → (τ n A → B) ≃ (A → B) τ-equiv n A B = (_ , τ-up n _ _) -- Equivalence associated to the universal property τ-extend-equiv : ∀ {j} (n : ℕ₋₂) (A : Set i) (B : Set j) ⦃ p : is-truncated n B ⦄ → (A → B) ≃ (τ n A → B) τ-extend-equiv n A B = (τ-extend-nondep , τ-extend-nondep-is-equiv n A B) τ-fmap : {n : ℕ₋₂} {A B : Set i} → ((A → B) → (τ n A → τ n B)) τ-fmap f = τ-extend-nondep (proj ◯ f) τ-fpmap : {n : ℕ₋₂} {A B : Set i} {f g : A → B} (h : (a : A) → f a ≡ g a) → ((a : τ n A) → τ-fmap f a ≡ τ-fmap g a) τ-fpmap h = τ-extend ⦃ λ _ → ≡-is-truncated _ (τ-is-truncated _ _) ⦄ (ap proj ◯ h)
{ "alphanum_fraction": 0.4888888889, "avg_line_length": 32.8991596639, "ext": "agda", "hexsha": "2d624e3d26506dd21fc042e89413d5db34c7383b", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Homotopy/Truncation.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Homotopy/Truncation.agda", "max_line_length": 76, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "old/Homotopy/Truncation.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": 1674, "size": 3915 }
module Lists where open import Nats open import Bools open import Agda.Builtin.List public using (List; []; _∷_) infixr 5 _++_ _∷ʳ_ [_] : ∀ {a} {A : Set a} → A → List A [ x ] = x ∷ [] _++_ : ∀ {a} {A : Set a} → List A → List A → List A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) _∷ʳ_ : ∀ {a} {A : Set a} → List A → A → List A xs ∷ʳ x = xs ++ [ x ] null : ∀ {a} {A : Set a} → List A → 𝔹 null [] = true null (x ∷ xs) = false reverse : ∀ {a} {A : Set a} → List A → List A reverse [] = [] reverse (x ∷ xs) = reverse xs ∷ʳ x replicate : ∀ {a} {A : Set a} → (n : ℕ) → A → List A replicate zero x = [] replicate (suc n) x = x ∷ replicate n x
{ "alphanum_fraction": 0.4939759036, "avg_line_length": 20.75, "ext": "agda", "hexsha": "ea0a90ad8c49ae71f69604825f42417ecf7fd30d", "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": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ice1k/Theorems", "max_forks_repo_path": "src/Lists.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "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": "ice1k/Theorems", "max_issues_repo_path": "src/Lists.agda", "max_line_length": 52, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ice1k/Theorems", "max_stars_repo_path": "src/Lists.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z", "num_tokens": 283, "size": 664 }
module HelloWorld where open import IO open import Data.String open import Data.Unit main = run (putStrLn "Hello World!")
{ "alphanum_fraction": 0.7741935484, "avg_line_length": 15.5, "ext": "agda", "hexsha": "9a0346ae9e46bcfa9bfd845f22666d6e8932eada", "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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Compiler/with-stdlib/HelloWorld.agda", "max_issues_count": 16, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Compiler/with-stdlib/HelloWorld.agda", "max_line_length": 36, "max_stars_count": 7, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Compiler/with-stdlib/HelloWorld.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z", "num_tokens": 28, "size": 124 }
open import MJ.Types as Types import MJ.Classtable.Core as Core module MJ.Semantics.Environments {c}(Ct : Core.Classtable c) where open import Prelude open import Data.List open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.All as All open import Data.List.Relation.Unary.Any open import MJ.LexicalScope c {- We equip MJ with mutable lexical environments. We could choose to model this directly, moving the environment from the Reader part of the evaluation monad to the State part. Instead we choose to keep our environments immutable and model mutability of the values in it by an indirection via the mutable store. This greatly simplifies the treatment of environments in the interpreter and keeps the representation lightweight, even though we support block scopes. -} Env : ∀ (Γ : Ctx)(W : World c) → Set Env Γ W = All (λ a → vty a ∈ W) Γ _⊕_ : ∀ {Γ W a} → Env Γ W → (vty a) ∈ W → Env (Γ +local a) W _⊕_ E v = v ∷ E open import Data.List.Any getvar : ∀ {Γ W a} → Var Γ a → Env Γ W → vty a ∈ W getvar px E = All.lookup E px
{ "alphanum_fraction": 0.7406367041, "avg_line_length": 32.3636363636, "ext": "agda", "hexsha": "2c20d49f8964ed234f49550d0fa3b0490547b5c9", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/MJ/Semantics/Environments.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/MJ/Semantics/Environments.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/MJ/Semantics/Environments.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 302, "size": 1068 }
------------------------------------------------------------------------------ -- ABP Lemma 2 ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- From Dybjer and Sander's paper: The second lemma states that given -- a state of the latter kind (see Lemma 1) we will arrive at a new -- start state, which is identical to the old start state except that -- the bit has alternated and the first item in the input stream has -- been removed. module FOTC.Program.ABP.Lemma2ATP where open import FOTC.Base open import FOTC.Base.List open import FOTC.Base.Loop open import FOTC.Data.Bool open import FOTC.Data.Bool.PropertiesATP using ( not-x≢x ; not-involutive ) open import FOTC.Data.List open import FOTC.Program.ABP.ABP open import FOTC.Program.ABP.Fair.Type open import FOTC.Program.ABP.Fair.PropertiesATP open import FOTC.Program.ABP.Terms ------------------------------------------------------------------------------ -- 30 November 2013. If we don't have the following definitions -- outside the where clause, the ATPs cannot prove the theorems. ds^ : D → D → D ds^ cs' os₂^ = corrupt os₂^ · cs' {-# ATP definition ds^ #-} as^ : D → D → D → D → D → D as^ b i' is' cs' os₂^ = await b i' is' (ds^ cs' os₂^) {-# ATP definition as^ #-} bs^ : D → D → D → D → D → D → D bs^ b i' is' cs' os₁^ os₂^ = corrupt os₁^ · as^ b i' is' cs' os₂^ {-# ATP definition bs^ #-} cs^ : D → D → D → D → D → D → D cs^ b i' is' cs' os₁^ os₂^ = ack (not b) · bs^ b i' is' cs' os₁^ os₂^ {-# ATP definition cs^ #-} os₁^ : D → D os₁^ os₁' = tail₁ os₁' {-# ATP definition os₁^ #-} os₂^ : D → D → D os₂^ ft₂ os₂'' = ft₂ ++ os₂'' {-# ATP definition os₂^ #-} -- Helper function for Lemma 2. helper₂ : ∀ {b i' is' os₁' os₂' as' bs' cs' ds' js'} → Bit b → Fair os₁' → S' b i' is' os₁' os₂' as' bs' cs' ds' js' → ∀ ft₂ os₂'' → F*T ft₂ → Fair os₂'' → os₂' ≡ ft₂ ++ os₂'' → ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ] Fair os₁'' ∧ Fair os₂'' ∧ S (not b) is' os₁'' os₂'' as'' bs'' cs'' ds'' js' helper₂ {b} {i'} {is'} {js' = js'} Bb Fos₁' s' .(T ∷ []) os₂'' f*tnil Fos₂'' os₂'-eq = prf where postulate prf : ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ] Fair os₁'' ∧ Fair os₂'' ∧ as'' ≡ send (not b) · is' · ds'' ∧ bs'' ≡ corrupt os₁'' · as'' ∧ cs'' ≡ ack (not b) · bs'' ∧ ds'' ≡ corrupt os₂'' · cs'' ∧ js' ≡ out (not b) · bs'' {-# ATP prove prf #-} helper₂ {b} {i'} {is'} {os₁'} {os₂'} {as'} {bs'} {cs'} {ds'} {js'} Bb Fos₁' s' .(F ∷ ft₂) os₂'' (f*tcons {ft₂} FTft₂) Fos₂'' os₂'-eq = helper₂ Bb (tail-Fair Fos₁') ihS' ft₂ os₂'' FTft₂ Fos₂'' refl where postulate os₂'-eq-helper : os₂' ≡ F ∷ os₂^ ft₂ os₂'' {-# ATP prove os₂'-eq-helper #-} postulate ds'-eq : ds' ≡ error ∷ ds^ cs' (os₂^ ft₂ os₂'') {-# ATP prove ds'-eq os₂'-eq-helper #-} postulate as'-eq : as' ≡ < i' , b > ∷ as^ b i' is' cs' (os₂^ ft₂ os₂'') {-# ATP prove as'-eq #-} postulate bs'-eq : bs' ≡ ok < i' , b > ∷ bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') ∨ bs' ≡ error ∷ bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') {-# ATP prove bs'-eq as'-eq head-tail-Fair #-} postulate cs'-eq-helper₁ : bs' ≡ ok < i' , b > ∷ bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') → cs' ≡ b ∷ cs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') {-# ATP prove cs'-eq-helper₁ not-x≢x not-involutive #-} postulate cs'-eq-helper₂ : bs' ≡ error ∷ bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') → cs' ≡ b ∷ cs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') {-# ATP prove cs'-eq-helper₂ not-involutive #-} cs'-eq : cs' ≡ b ∷ cs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') cs'-eq = case cs'-eq-helper₁ cs'-eq-helper₂ bs'-eq postulate js'-eq : js' ≡ out (not b) · bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'') -- TODO (21 November 2014). See Apia issue 16 -- {-# ATP prove js'-eq not-x≢x bs'-eq #-} postulate ds^-eq : ds^ cs' (os₂^ ft₂ os₂'') ≡ corrupt (os₂^ ft₂ os₂'') · (b ∷ cs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'')) {-# ATP prove ds^-eq cs'-eq #-} ihS' : S' b i' is' (os₁^ os₁') (os₂^ ft₂ os₂'') (as^ b i' is' cs' (os₂^ ft₂ os₂'')) (bs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'')) (cs^ b i' is' cs' (os₁^ os₁') (os₂^ ft₂ os₂'')) (ds^ cs' (os₂^ ft₂ os₂'')) js' ihS' = refl , refl , refl , ds^-eq , js'-eq -- From Dybjer and Sander's paper: From the assumption that -- os₂' ∈ Fair and hence by unfolding Fair, we conclude that there are -- ft₂ : F*T and os₂'' : Fair, such that os₂' = ft₂ ++ os₂''. -- -- We proceed by induction on ft₂ : F*T using helper. lemma₂ : ∀ {b i' is' os₁' os₂' as' bs' cs' ds' js'} → Bit b → Fair os₁' → Fair os₂' → S' b i' is' os₁' os₂' as' bs' cs' ds' js' → ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ] Fair os₁'' ∧ Fair os₂'' ∧ S (not b) is' os₁'' os₂'' as'' bs'' cs'' ds'' js' lemma₂ {b} {is' = is'} {os₂' = os₂'} {js' = js'} Bb Fos₁' Fos₂' s' = helper₁ (Fair-out Fos₂') where helper₁ : (∃[ ft₂ ] ∃[ os₂'' ] F*T ft₂ ∧ os₂' ≡ ft₂ ++ os₂'' ∧ Fair os₂'') → ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ] Fair os₁'' ∧ Fair os₂'' ∧ S (not b) is' os₁'' os₂'' as'' bs'' cs'' ds'' js' helper₁ (ft₂ , os₂'' , FTft₂ , os₂'-eq , Fos₂'') = helper₂ Bb Fos₁' s' ft₂ os₂'' FTft₂ Fos₂'' os₂'-eq
{ "alphanum_fraction": 0.4733969986, "avg_line_length": 35.756097561, "ext": "agda", "hexsha": "24f91c755c53c924a65c740d23813658457c894d", "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/Lemma2ATP.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/Lemma2ATP.agda", "max_line_length": 80, "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/Lemma2ATP.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": 2272, "size": 5864 }
{-# OPTIONS --universe-polymorphism #-} module Rewrite-with-doubly-indexed-equality where open import Common.Level infix 4 _≡_ data _≡_ {a} {A : Set a} : A → A → Set a where refl : ∀ {x} → x ≡ x {-# BUILTIN EQUALITY _≡_ #-} {-# BUILTIN REFL refl #-} sym : {A : Set}{x y : A} → x ≡ y → y ≡ x sym refl = refl data Nat : Set where zero : Nat suc : Nat → Nat infixl 6 _+_ _+_ : Nat → Nat → Nat zero + m = m suc n + m = suc (n + m) plus-zero : ∀ n → n + zero ≡ n plus-zero zero = refl plus-zero (suc n) rewrite plus-zero n = refl plus-suc : ∀ n m → n + suc m ≡ suc (n + m) plus-suc zero m = refl plus-suc (suc n) m rewrite plus-suc n m = refl -- Proving things about functions using rewrite data IsRefl {A : Set}{x : A} : ∀ {y} → x ≡ y → Set where isRefl : IsRefl refl plus-suc-isrefl : ∀ {n m} → IsRefl (plus-suc n m) plus-suc-isrefl {zero } {m} = isRefl plus-suc-isrefl {suc n} {m} rewrite plus-suc n m = isRefl -- Multiple rewrites com : ∀ n m → n + m ≡ m + n com n zero = plus-zero _ com n (suc m) rewrite plus-suc n m | com n m = refl -- rewrite followed by with thm : ∀ a b c → a + (b + c) ≡ (c + b) + a thm a b c rewrite com b c with c + b ... | cb = com a cb data List A : Set where [] : List A _∷_ : (x : A)(xs : List A) → List A infixr 30 _∷_ _++_ _++_ : ∀ {A} → List A → List A → List A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) -- rewrite in parameterised module module ListProps {A : Set} where append-nil : (xs : List A) → xs ++ [] ≡ xs append-nil [] = refl append-nil (x ∷ xs) rewrite append-nil xs = refl append-assoc : (as bs cs : List A) → (as ++ bs) ++ cs ≡ as ++ (bs ++ cs) append-assoc [] bs cs = refl append-assoc (a ∷ as) bs cs rewrite append-assoc as bs cs = refl -- With implicit arguments append-assoc′ : ∀ (as : List A) {bs cs} → (as ++ bs) ++ cs ≡ as ++ (bs ++ cs) append-assoc′ [] = refl append-assoc′ (a ∷ as) {bs}{cs} rewrite append-assoc′ as {bs} {cs} = refl reverse : List A → List A reverse [] = [] reverse (x ∷ xs) = reverse xs ++ x ∷ [] reverse-append : ∀ as bs → reverse (as ++ bs) ≡ reverse bs ++ reverse as reverse-append [] bs rewrite append-nil (reverse bs) = refl reverse-append (a ∷ as) bs rewrite reverse-append as bs = append-assoc (reverse bs) _ _ reverse-reverse : ∀ as → reverse (reverse as) ≡ as reverse-reverse [] = refl reverse-reverse (a ∷ as) rewrite reverse-append (reverse as) (a ∷ []) | reverse-reverse as = refl open ListProps map : ∀ {A B} → (A → B) → List A → List B map f [] = [] map f (x ∷ xs) = f x ∷ map f xs _∘_ : {A : Set}{B : A → Set}{C : ∀ x → B x → Set} (f : ∀ {x} (y : B x) → C x y)(g : ∀ x → B x) (x : A) → C x (g x) (f ∘ g) x = f (g x) id : {A : Set} → A → A id x = x map-id : ∀ {A} (xs : List A) → map id xs ≡ xs map-id [] = refl map-id (x ∷ xs) rewrite map-id xs = refl map-compose : ∀ {A B C} (f : B → C)(g : A → B)(xs : List A) → map (f ∘ g) xs ≡ (map f ∘ map g) xs map-compose f g [] = refl map-compose f g (x ∷ xs) rewrite map-compose f g xs = refl map-append : ∀ {A B} (f : A → B) (xs ys : List A) → map f (xs ++ ys) ≡ map f xs ++ map f ys map-append f [] ys = refl map-append f (x ∷ xs) ys rewrite map-append f xs ys = refl map-reverse : ∀ {A B} (f : A → B) (xs : List A) → map f (reverse xs) ≡ reverse (map f xs) map-reverse f [] = refl map-reverse f (x ∷ xs) rewrite map-append f (reverse xs) (x ∷ []) | map-reverse f xs = refl foldr : {A B : Set} → (A → B → B) → B → List A → B foldr f z [] = z foldr f z (x ∷ xs) = f x (foldr f z xs) foldl : {A B : Set} → (B → A → B) → B → List A → B foldl f z [] = z foldl f z (x ∷ xs) = foldl f (f z x) xs module FoldAssoc {A : Set}(_∙_ : A → A → A) (assoc : ∀ x y z → ((x ∙ y) ∙ z) ≡ (x ∙ (y ∙ z))) where smashr = foldr _∙_ smashl = foldl _∙_ foldr-append : ∀ ∅ z xs ys → (∀ x → (∅ ∙ x) ≡ x) → smashr z (xs ++ ys) ≡ (smashr ∅ xs ∙ smashr z ys) foldr-append ∅ z [] ys idl = sym (idl _) foldr-append ∅ z (x ∷ xs) ys idl rewrite assoc x (smashr ∅ xs) (smashr z ys) | foldr-append ∅ z xs ys idl = refl foldl-plus : ∀ z₁ z₂ xs → smashl (z₁ ∙ z₂) xs ≡ (z₁ ∙ smashl z₂ xs) foldl-plus z₁ z₂ [] = refl foldl-plus z₁ z₂ (x ∷ xs) rewrite assoc z₁ z₂ x = foldl-plus _ _ xs foldr=foldl : ∀ ∅ → (∀ x → (∅ ∙ x) ≡ (x ∙ ∅)) → ∀ xs → foldr _∙_ ∅ xs ≡ foldl _∙_ ∅ xs foldr=foldl ∅ id [] = refl foldr=foldl ∅ id (x ∷ xs) rewrite id x | foldl-plus x ∅ xs | foldr=foldl ∅ id xs = refl foldr-compose : ∀ {A B C : Set} (f : B → C → C) (z : C) (g : A → B) (xs : List A) → foldr (f ∘ g) z xs ≡ foldr f z (map g xs) foldr-compose f z g [] = refl foldr-compose f z g (x ∷ xs) rewrite foldr-compose f z g xs = refl foldr-fusion : ∀ {A B C : Set} (f : B → C) (_⊕_ : A → B → B) (_⊗_ : A → C → C) (z : B) → (∀ x y → f (x ⊕ y) ≡ (x ⊗ f y)) → ∀ xs → f (foldr _⊕_ z xs) ≡ foldr _⊗_ (f z) xs foldr-fusion f _⊕_ _⊗_ z distr [] = refl foldr-fusion f _⊕_ _⊗_ z distr (x ∷ xs) rewrite sym (foldr-fusion f _⊕_ _⊗_ z distr xs) with foldr _⊕_ z xs ... | y = distr x y
{ "alphanum_fraction": 0.4852862493, "avg_line_length": 31.15, "ext": "agda", "hexsha": "a3a22d85d935066dff0f246477723162fd08cd9b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Succeed/Rewrite-with-doubly-indexed-equality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Succeed/Rewrite-with-doubly-indexed-equality.agda", "max_line_length": 88, "max_stars_count": null, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/Rewrite-with-doubly-indexed-equality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2124, "size": 5607 }
-- | The core type system. module Ethambda.System where open import Ethambda.Common using () -- ((<.>), (<.)) data Tp : Type -> Type where Var : a -> Tp a Fun : Tp a -> Tp a -> Tp a Show a => Show (Tp a) where show t = case t of -- Var a => ?foo Var a => show a Fun a0 b0 => mbrackets a0 <+> "→" <+> show b0 -- where -- brackets : String -> String -- brackets s = "(" <+> s <+> ")" -- mbrackets : Show a => Tp a -> String -- mbrackets a = case a of -- Var _ => neutral -- Fun _ _ => brackets (show a)
{ "alphanum_fraction": 0.5090252708, "avg_line_length": 25.1818181818, "ext": "agda", "hexsha": "43ce18b77348f65eed7976e13d6bc81138a2db0c", "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": "18e1f9271a3ce76319cdfbcffe027c2088a418aa", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "fredefox/ethambda-agda", "max_forks_repo_path": "src/Ethambda/System.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "18e1f9271a3ce76319cdfbcffe027c2088a418aa", "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": "fredefox/ethambda-agda", "max_issues_repo_path": "src/Ethambda/System.agda", "max_line_length": 53, "max_stars_count": null, "max_stars_repo_head_hexsha": "18e1f9271a3ce76319cdfbcffe027c2088a418aa", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "fredefox/ethambda-agda", "max_stars_repo_path": "src/Ethambda/System.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 193, "size": 554 }
------------------------------------------------------------------------------ -- Properties for the relation _◁_ ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.McCarthy91.WF-Relation.PropertiesATP where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.EliminationPropertiesATP using ( x<y→y<x→⊥ ) open import FOTC.Data.Nat.Inequalities.PropertiesATP using ( x∸y<Sx ; <-trans ; x<x∸y→⊥ ; x∸y<x∸z→Sx∸y<Sx∸z ; x<y→y≤z→x<z ; x∸Sy≤x∸y ) open import FOTC.Data.Nat.PropertiesATP using ( ∸-N ; S∸S ) open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Data.Nat.UnaryNumbers.TotalityATP using ( 101-N ) open import FOTC.Program.McCarthy91.ArithmeticATP open import FOTC.Program.McCarthy91.WF-Relation ------------------------------------------------------------------------------ ◁-fn-N : ∀ {n} → N n → N (◁-fn n) ◁-fn-N Nn = ∸-N 101-N Nn 0◁x→⊥ : ∀ {n} → N n → ¬ (zero ◁ n) 0◁x→⊥ nzero 0◁n = prf where postulate prf : ⊥ {-# ATP prove prf #-} 0◁x→⊥ (nsucc Nn) 0◁Sn = prf where postulate prf : ⊥ {-# ATP prove prf ∸-N x∸y<Sx x<y→y<x→⊥ S∸S #-} ◁-trans : ∀ {m n o} → N m → N n → N o → m ◁ n → n ◁ o → m ◁ o ◁-trans Nm Nn No m◁n n◁o = <-trans (∸-N 101-N Nm) (∸-N 101-N Nn) (∸-N 101-N No) m◁n n◁o Sx◁Sy→x◁y : ∀ {m n} → N m → N n → succ₁ m ◁ succ₁ n → m ◁ n Sx◁Sy→x◁y nzero nzero S0◁S0 = prf where postulate prf : zero ◁ zero {-# ATP prove prf #-} Sx◁Sy→x◁y nzero (nsucc {n} Nn) S0◁SSn = prf where postulate prf : zero ◁ succ₁ n {-# ATP prove prf x<x∸y→⊥ S∸S #-} Sx◁Sy→x◁y (nsucc {m} Nm) nzero SSm◁S0 = prf where postulate prf : succ₁ m ◁ zero {-# ATP prove prf ∸-N x∸y<Sx S∸S #-} Sx◁Sy→x◁y (nsucc {m} Nm) (nsucc {n} Nn) SSm◁SSn = prf where postulate prf : succ₁ m ◁ succ₁ n -- 2018-06-27: The ATPs could not prove the theorem (300 sec), but -- Vampire 4.2.2, via `online-atps`, could prove it. -- {-# ATP prove prf x∸y<x∸z→Sx∸y<Sx∸z S∸S #-} x◁Sy→x◁y : ∀ {m n} → N m → N n → m ◁ succ₁ n → m ◁ n x◁Sy→x◁y {n = n} nzero Nn 0◁Sn = ⊥-elim (0◁x→⊥ (nsucc Nn) 0◁Sn) x◁Sy→x◁y (nsucc {m} Nm) nzero Sm◁S0 = prf where postulate prf : succ₁ m ◁ zero {-# ATP prove prf x∸y<Sx S∸S #-} x◁Sy→x◁y (nsucc {m} Nm) (nsucc {n} Nn) Sm◁SSn = x<y→y≤z→x<z (∸-N 101-N (nsucc Nm)) (∸-N 101-N (nsucc (nsucc Nn))) (∸-N 101-N (nsucc Nn)) Sm◁SSn (x∸Sy≤x∸y 101-N (nsucc Nn))
{ "alphanum_fraction": 0.511176255, "avg_line_length": 29.6630434783, "ext": "agda", "hexsha": "d6d0544d699da4c2e178b58ec023f4a0535f8a46", "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/McCarthy91/WF-Relation/PropertiesATP.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/McCarthy91/WF-Relation/PropertiesATP.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/McCarthy91/WF-Relation/PropertiesATP.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": 1189, "size": 2729 }
{-# OPTIONS --universe-polymorphism #-} module Issue256 where open import Imports.Level const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A const x = λ _ → x level : ∀ {ℓ} → Set ℓ → Level level {ℓ} _ = ℓ -- termination check should fail for the following definition ℓ : Level ℓ = const zero (Set ℓ) -- A : Set (suc {!ℓ!}) -- A = Set (level A)
{ "alphanum_fraction": 0.5988538682, "avg_line_length": 18.3684210526, "ext": "agda", "hexsha": "4a5a0c51cf7e76b0dfcaa2ddfe9ac8e8f9ecee2b", "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/fail/Issue256.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/fail/Issue256.agda", "max_line_length": 61, "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/fail/Issue256.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": 122, "size": 349 }
open import Prelude open import core module lemmas-ground where -- not ground types aren't hole to hole ground-arr-not-hole : ∀{τ} → (τ ground → ⊥) → (τ ≠ (⦇-⦈ ==> ⦇-⦈)) ground-arr-not-hole notg refl = notg GHole -- not ground types either have to be hole or an arrow notground : ∀{τ} → (τ ground → ⊥) → (τ == ⦇-⦈) + (Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] (τ == (τ1 ==> τ2))) notground {b} gnd = abort (gnd GBase) notground {⦇-⦈} gnd = Inl refl notground {b ==> b} gnd = Inr (b , b , refl) notground {b ==> ⦇-⦈} gnd = Inr (b , ⦇-⦈ , refl) notground {b ==> τ2 ==> τ3} gnd = Inr (b , τ2 ==> τ3 , refl) notground {⦇-⦈ ==> b} gnd = Inr (⦇-⦈ , b , refl) notground {⦇-⦈ ==> ⦇-⦈} gnd = abort (gnd GHole) notground {⦇-⦈ ==> τ2 ==> τ3} gnd = Inr (⦇-⦈ , τ2 ==> τ3 , refl) notground {(τ1 ==> τ2) ==> b} gnd = Inr (τ1 ==> τ2 , b , refl) notground {(τ1 ==> τ2) ==> ⦇-⦈} gnd = Inr (τ1 ==> τ2 , ⦇-⦈ , refl) notground {(τ1 ==> τ2) ==> τ3 ==> τ4} gnd = Inr (τ1 ==> τ2 , τ3 ==> τ4 , refl)
{ "alphanum_fraction": 0.4812680115, "avg_line_length": 43.375, "ext": "agda", "hexsha": "7a43ab263c0e40674ceab297b682dab509c9455f", "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-ground.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-ground.agda", "max_line_length": 101, "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-ground.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": 480, "size": 1041 }
------------------------------------------------------------------------ -- Traditional non-dependent lenses with erased lens laws ------------------------------------------------------------------------ import Equality.Path as P module Lens.Non-dependent.Traditional.Erased {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude as P hiding (id; [_,_]) renaming (_∘_ to _⊚_) import Bi-invertibility.Erased open import Bijection equality-with-J as Bij using (_↔_) open import Circle eq using (𝕊¹) open import Circle.Erased eq as CE using (𝕊¹ᴱ) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_; Is-equivalenceᴱ) open import Equivalence.Erased.Contractible-preimages equality-with-J as ECP using (Contractibleᴱ; _⁻¹ᴱ_) open import Erased.Cubical eq 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 PT using (∥_∥) open import H-level.Truncation.Propositional.Erased eq as TE using (∥_∥ᴱ; ∣_∣) open import Preimage equality-with-J using (_⁻¹_) open import Surjection equality-with-J as Surjection using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq as Non-dependent hiding (no-first-projection-lens) import Lens.Non-dependent.Traditional eq as T import Lens.Non-dependent.Traditional.Combinators eq as TC private variable a b c p : Level A A₁ A₂ B B₁ B₂ C D : Type a u v x₁ x₂ y₁ y₂ : A ------------------------------------------------------------------------ -- Traditional lenses -- Lenses with erased lens laws. record Lens (A : Type a) (B : Type b) : Type (a ⊔ b) where field -- Getter and setter. get : A → B set : A → B → A -- Lens laws. @0 get-set : ∀ a b → get (set a b) ≡ b @0 set-get : ∀ a → set a (get a) ≡ a @0 set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ -- A combination of get and set. modify : (B → B) → A → A modify f x = set x (f (get x)) instance -- Traditional lenses with erased laws 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 } -- Lens A B is isomorphic to a nested Σ-type. Lens-as-Σ : Lens A B ↔ ∃ λ (get : A → B) → ∃ λ (set : A → B → A) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) Lens-as-Σ = record { surjection = record { logical-equivalence = record { to = λ l → get l , set l , [ get-set l , set-get l , set-set l ] ; from = λ { (get , set , [ get-set , set-get , set-set ]) → record { get = get ; set = set ; get-set = get-set ; set-get = set-get ; set-set = set-set } } } ; right-inverse-of = refl } ; left-inverse-of = refl } where open Lens -- In erased contexts Lens A B is equivalent to T.Lens A B. @0 Lens≃Traditional-lens : Lens A B ≃ T.Lens A B Lens≃Traditional-lens {A = A} {B = B} = Lens A B ↔⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → erased Erased↔) ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↔⟨ inverse T.Lens-as-Σ ⟩□ T.Lens A B □ -- Lenses without erased proofs can be turned into lenses with erased -- proofs (in erased contexts). @0 Traditional-lens→Lens : T.Lens A B → Lens A B Traditional-lens→Lens = _≃_.from Lens≃Traditional-lens private -- The forward direction of Lens≃Traditional-lens. @0 trad : Lens A B → T.Lens A B trad = _≃_.to Lens≃Traditional-lens private variable l₁ l₂ : Lens A B ------------------------------------------------------------------------ -- Somewhat coherent lenses -- Traditional lenses with erased lens laws that satisfy some extra -- coherence properties (that are also erased). record Coherent-lens (A : Type a) (B : Type b) : Type (a ⊔ b) where field lens : Lens A B open Lens lens public field @0 get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a) @0 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₂)) instance -- Somewhat coherent lenses have getters and setters. coherent-has-getter-and-setter : Has-getter-and-setter (Coherent-lens {a = a} {b = b}) coherent-has-getter-and-setter = record { get = Coherent-lens.get ; set = Coherent-lens.set } -- Coherent-lens A B is equivalent to a nested Σ-type. Coherent-lens-as-Σ : Coherent-lens A B ≃ ∃ λ (l : Lens A B) → let open Lens l in Erased ((∀ a → cong get (set-get a) ≡ get-set a (get a)) × (∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) Coherent-lens-as-Σ = Eq.↔→≃ (λ l → lens l , [ get-set-get l , get-set-set l ]) (λ (l , [ get-set-get , get-set-set ]) → record { lens = l ; get-set-get = get-set-get ; get-set-set = get-set-set }) refl refl where open Coherent-lens -- In erased contexts Coherent-lens A B is equivalent to -- T.Coherent-lens A B. @0 Coherent-lens≃Traditional-coherent-lens : Coherent-lens A B ≃ T.Coherent-lens A B Coherent-lens≃Traditional-coherent-lens {A = A} {B = B} = Coherent-lens A B ↔⟨ Coherent-lens-as-Σ ⟩ (∃ λ (l : Lens A B) → let open Lens l in Erased ((∀ a → cong get (set-get a) ≡ get-set a (get a)) × (∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))) ↔⟨ (Σ-cong Lens≃Traditional-lens λ _ → erased Erased↔) ⟩ (∃ λ (l : T.Lens A B) → let open T.Lens l in (∀ a → cong get (set-get a) ≡ get-set a (get a)) × (∀ a b₁ b₂ → cong get (set-set a b₁ b₂) ≡ trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) ↔⟨ inverse T.Coherent-lens-as-Σ ⟩ T.Coherent-lens A B □ ------------------------------------------------------------------------ -- Some lemmas -- If two lenses have equal setters, then they also have equal -- getters (in erased contexts). @0 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₂ = Lens.set l₁ ≡ Lens.set l₂ ↔⟨⟩ T.Lens.set (trad l₁) ≡ T.Lens.set (trad l₂) ↝⟨ T.getters-equal-if-setters-equal (trad l₁) (trad l₂) ⟩ T.Lens.get (trad l₁) ≡ T.Lens.get (trad l₂) ↔⟨⟩ Lens.get l₁ ≡ Lens.get l₂ □ -- If the forward direction of an equivalence with erased proofs is -- Lens.get l, then the setter of l can be expressed using the other -- direction of the equivalence (in erased contexts). @0 from≡set : ∀ (l : Lens A B) is-equiv → let open Lens A≃B = EEq.⟨ get l , is-equiv ⟩ in ∀ a b → _≃ᴱ_.from A≃B b ≡ set l a b from≡set l is-equiv = T.from≡set (trad l) (EEq.Is-equivalenceᴱ→Is-equivalence is-equiv) -- If A and B are "very stable n levels up" (given certain -- assumptions), then Lens A B is "very stable n levels up". Very-stable-Lensⁿ : ∀ n → (A → B → For-iterated-equality n Very-stable A) → (A → For-iterated-equality n Very-stable B) → For-iterated-equality n Very-stable (Lens A B) Very-stable-Lensⁿ {A = A} {B = B} n A-s B-s = Very-stable-congⁿ _ n (inverse Lens-as-Σ) $ Very-stable-Σⁿ n (Very-stable-Πⁿ ext n λ a → B-s a) λ _ → Very-stable-Σⁿ n (Very-stable-Πⁿ ext n λ a → Very-stable-Πⁿ ext n λ b → A-s a b) λ _ → Very-stable→Very-stableⁿ n Very-stable-Erased ------------------------------------------------------------------------ -- Some lens isomorphisms -- Lens preserves equivalences. Lens-cong : 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-Σ ⟩ (∃ λ (get : A₁ → B₁) → ∃ λ (set : A₁ → B₁ → A₁) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↝⟨ (Σ-cong (→-cong ext A₁≃A₂ B₁≃B₂) λ get → Σ-cong (→-cong ext A₁≃A₂ $ →-cong ext B₁≃B₂ A₁≃A₂) λ set → Erased-cong ( (Π-cong ext A₁≃A₂ λ a → Π-cong ext B₁≃B₂ λ b → inverse (Eq.≃-≡ B₁≃B₂) F.∘ (≡⇒≃ $ cong (_≡ _) (get (set a b) ≡⟨ sym $ cong₂ (λ a b → get (set a b)) (_≃_.left-inverse-of A₁≃A₂ _) (_≃_.left-inverse-of B₁≃B₂ _) ⟩ get (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))) ≡⟨ cong get $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎ get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))))) ∎))) ×-cong (Π-cong ext A₁≃A₂ λ a → inverse (Eq.≃-≡ A₁≃A₂) F.∘ (≡⇒≃ $ cong (_≡ _) (set a (get a) ≡⟨ cong (set a) $ sym $ _≃_.left-inverse-of B₁≃B₂ _ ⟩ set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a))) ≡⟨ cong (λ a → set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a)))) $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎ set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a)) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))))) ∎))) ×-cong (inverse $ Π-cong ext (inverse A₁≃A₂) λ a → inverse $ Π-cong ext B₁≃B₂ λ b₁ → inverse $ Π-cong ext (inverse B₁≃B₂) λ b₂ → (≡⇒≃ $ cong (λ a′ → set a′ (_≃_.from B₁≃B₂ b₂) ≡ set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ b₂)) (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ (set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)))) ≡⟨ _≃_.left-inverse-of A₁≃A₂ _ ⟩ set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)) ≡⟨ cong (set (_≃_.from A₁≃A₂ a)) $ _≃_.left-inverse-of B₁≃B₂ _ ⟩∎ set (_≃_.from A₁≃A₂ a) b₁ ∎)) F.∘ Eq.≃-≡ A₁≃A₂))) ⟩ (∃ λ (get : A₂ → B₂) → ∃ λ (set : A₂ → B₂ → A₂) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ inverse Lens-as-Σ ⟩□ Lens A₂ B₂ □ -- If B is a proposition (when A is inhabited), then Lens A B is -- equivalent (with erased proofs) to -- (A → B) × Erased ((a : A) → a ≡ a). lens-to-proposition≃ᴱ : @0 (A → Is-proposition B) → Lens A B ≃ᴱ ((A → B) × Erased ((a : A) → a ≡ a)) lens-to-proposition≃ᴱ {A = A} {B = B} B-prop = Lens A B ↔⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong ( drop-⊤-left-× λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ a → Π-closure ext 0 λ _ → +⇒≡ (B-prop a))) ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → Erased ((∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ get → ∃-cong λ set → Erased-cong (∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒≃ ( (set (set a b₁) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a b) b₂ ≡ _) (B-prop a _ _) ⟩ (set (set a (get a)) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a (get a)) b ≡ _) (B-prop a _ _) ⟩ (set (set a (get a)) (get (set a (get a))) ≡ set a b₂) ≡⟨ cong (λ b → _ ≡ set a b) (B-prop a _ _) ⟩∎ (set (set a (get a)) (get (set a (get a))) ≡ set a (get a)) ∎))) ⟩ (∃ λ (get : A → B) → ∃ λ (set : A → B → A) → Erased ((∀ a → set a (get a) ≡ a) × (∀ a → B → B → set (set a (get a)) (get (set a (get a))) ≡ set a (get a)))) ↝⟨ (∃-cong λ get → EEq.Σ-cong-≃ᴱ-Erased (A→B→A≃ᴱA→A get) λ _ → F.id) ⟩ ((A → B) × ∃ λ (f : A → A) → Erased ((∀ a → f a ≡ a) × (∀ a → B → B → f (f a) ≡ f a))) ↝⟨ (∃-cong λ get → ∃-cong λ _ → Erased-cong (∃-cong λ _ → ∀-cong ext λ a → EEq.drop-⊤-left-Π-≃ᴱ-Erased ext (B≃ᴱ⊤ get a) F.∘ EEq.drop-⊤-left-Π-≃ᴱ-Erased ext (B≃ᴱ⊤ get a))) ⟩ ((A → B) × ∃ λ (f : A → A) → Erased ((∀ a → f a ≡ a) × (∀ a → f (f a) ≡ f a))) ↔⟨ (∃-cong λ _ → ∃-cong λ f → Erased-cong ( Σ-cong (Eq.extensionality-isomorphism ext) λ f≡id → ∀-cong ext λ a → ≡⇒≃ (cong₂ _≡_ (trans (f≡id (f a)) (f≡id a)) (f≡id a)))) ⟩ ((A → B) × ∃ λ (f : A → A) → Erased (f ≡ P.id × ((a : A) → a ≡ a))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-Σ↔Σ) ⟩ ((A → B) × ∃ λ (f : A → A) → Erased (f ≡ P.id) × Erased ((a : A) → a ≡ a)) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩ (A → B) × (∃ λ (f : A → A) → Erased (f ≡ P.id)) × Erased ((a : A) → a ≡ a) ↝⟨ (∃-cong λ _ → EEq.drop-⊤-left-Σ-≃ᴱ-Erased $ _⇔_.to EEq.Contractibleᴱ⇔≃ᴱ⊤ Contractibleᴱ-Erased-singleton) ⟩□ (A → B) × Erased ((a : A) → a ≡ a) □ where B≃ᴱ⊤ : (A → B) → A → B ≃ᴱ ⊤ B≃ᴱ⊤ get a = EEq.inhabited→Is-proposition→≃ᴱ⊤ (get a) (B-prop a) A→B→A≃ᴱA→A : (A → B) → (A → B → A) ≃ᴱ (A → A) A→B→A≃ᴱA→A get = (A → B → A) ↝⟨ ∀-cong ext (λ a → EEq.drop-⊤-left-Π-≃ᴱ-Erased ext $ B≃ᴱ⊤ get a) ⟩□ (A → A) □ -- If equality is very stable for A (when B is inhabited) and B is a -- proposition (when A is inhabited), then Lens A B is equivalent to -- (A → B) × Erased ((a : A) → a ≡ a). Very-stable-≡→lens-to-proposition≃ : (B → Very-stable-≡ A) → (A → Is-proposition B) → Lens A B ≃ ((A → B) × Erased ((a : A) → a ≡ a)) Very-stable-≡→lens-to-proposition≃ {B = B} {A = A} A-s B-prop = Stable-≡→≃ᴱ→≃ stable₁ stable₂ (lens-to-proposition≃ᴱ B-prop) where stable₁ : Stable-≡ (Lens A B) stable₁ = Very-stable→Stable 1 $ Very-stable-Lensⁿ 1 (λ _ → A-s) (H-level→Very-stable 1 ⊚ B-prop) stable₂ : Stable-≡ ((A → B) × Erased ((a : A) → a ≡ a)) stable₂ = Very-stable→Stable 1 $ Very-stable-×ⁿ 1 (Very-stable-Πⁿ ext 1 λ a → H-level→Very-stable 1 (B-prop a)) (Very-stable→Very-stable-≡ 0 Very-stable-Erased) -- Lens A ⊤ is equivalent (with erased proofs) to -- Erased ((a : A) → a ≡ a). lens-to-⊤≃ᴱ : Lens A ⊤ ≃ᴱ Erased ((a : A) → a ≡ a) lens-to-⊤≃ᴱ {A = A} = Lens A ⊤ ↝⟨ lens-to-proposition≃ᴱ (λ _ → mono₁ 0 ⊤-contractible) ⟩ (A → ⊤) × Erased ((a : A) → a ≡ a) ↔⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□ Erased ((a : A) → a ≡ a) □ -- Lens A ⊥ is equivalent to ¬ A. lens-to-⊥≃ : Lens A (⊥ {ℓ = b}) ≃ (¬ A) lens-to-⊥≃ {A = A} = Lens A ⊥ ↝⟨ Very-stable-≡→lens-to-proposition≃ (λ ()) (λ _ → ⊥-propositional) ⟩ (A → ⊥) × Erased ((a : A) → a ≡ a) ↔⟨ (×-cong₁ λ _ → →-cong ext F.id (Bij.⊥↔uninhabited ⊥-elim)) ⟩ ¬ A × Erased ((a : A) → a ≡ a) ↔⟨ (drop-⊤-right λ ¬a → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (H-level-Erased 1 ( Π-closure ext 1 λ a → ⊥-elim (¬a a))) [ refl ]) ⟩□ ¬ A □ -- See also lens-from-⊥≃⊤ and lens-from-⊤≃codomain-contractible below. ------------------------------------------------------------------------ -- Some lens 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 (in erased contexts). @0 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 l = T.h-level-respects-lens-from-inhabited n (trad l) -- Lenses with contractible domains have contractible codomains (in -- erased contexts). @0 contractible-to-contractible : Lens A B → Contractible A → Contractible B contractible-to-contractible l = T.contractible-to-contractible (trad l) -- A variant for Contractibleᴱ. Contractibleᴱ→Contractibleᴱ : Lens A B → Contractibleᴱ A → Contractibleᴱ B Contractibleᴱ→Contractibleᴱ l c@(a , _) = ECP.Contractibleᴱ-respects-surjection (Lens.get l) (λ b → Lens.set l a b , (Lens.get l (Lens.set l a b) ≡⟨ Lens.get-set l _ _ ⟩∎ b ∎)) c -- If A and B have h-level n given the assumption that A is inhabited, -- then Lens A B also has h-level n. lens-preserves-h-level : ∀ n → (A → H-level n A) → (A → H-level n B) → H-level n (Lens A B) lens-preserves-h-level n hA hB = H-level.respects-surjection (_↔_.surjection (inverse Lens-as-Σ)) n $ Σ-closure n (Π-closure ext n λ a → hB a) λ _ → Σ-closure n (Π-closure ext n λ a → Π-closure ext n λ _ → hA a) λ _ → H-level-Erased n (×-closure n (Π-closure ext n λ a → Π-closure ext n λ _ → +⇒≡ $ mono₁ n (hB a)) $ ×-closure n (Π-closure ext n λ a → +⇒≡ $ mono₁ n (hA a)) (Π-closure ext n λ a → Π-closure ext n λ _ → Π-closure ext n λ _ → +⇒≡ $ mono₁ n (hA a))) -- If A has positive h-level n, then Lens A B also has h-level n (in -- erased contexts). @0 lens-preserves-h-level-of-domain : ∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B) lens-preserves-h-level-of-domain {A = A} {B = B} n = H-level (1 + n) A ↝⟨ T.lens-preserves-h-level-of-domain n ⟩ H-level (1 + n) (T.Lens A B) ↝⟨ H-level-cong _ (1 + n) (inverse Lens≃Traditional-lens) ⟩□ H-level (1 + n) (Lens A B) □ -- Lens 𝕊¹ᴱ ⊤ is not propositional (assuming univalence). ¬-lens-to-⊤-propositional : @0 Univalence (# 0) → ¬ Is-proposition (Lens 𝕊¹ᴱ ⊤) ¬-lens-to-⊤-propositional univ = Stable-¬ [ Is-proposition (Lens 𝕊¹ᴱ ⊤) ↝⟨ H-level-cong _ 1 (Lens-cong (inverse CE.𝕊¹≃𝕊¹ᴱ) Eq.id) ⟩ Is-proposition (Lens 𝕊¹ ⊤) ↝⟨ H-level-cong _ 1 Lens≃Traditional-lens ⟩ Is-proposition (T.Lens 𝕊¹ ⊤) ↝⟨ T.¬-lens-to-⊤-propositional univ ⟩□ ⊥₀ □ ] ------------------------------------------------------------------------ -- Some equality characterisation lemmas abstract -- An equality characterisation lemma. equality-characterisation₁ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} = let l₁′ = _↔_.to Lens-as-Σ l₁ l₂′ = _↔_.to Lens-as-Σ l₂ in l₁ ≡ l₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Lens-as-Σ)) ⟩ l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Σ-assoc)) ⟩ ((get l₁ , set l₁) , proj₂ (proj₂ l₁′)) ≡ ((get l₂ , set l₂) , proj₂ (proj₂ l₂′)) ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩ (∃ λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) → subst (λ (get , set) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) gs (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ Σ-cong (inverse ≡×≡↔≡) (λ gs → ≡⇒↝ _ $ cong (λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) → subst (λ (get , set) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) gs (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) (sym $ _↔_.right-inverse-of ≡×≡↔≡ gs)) ⟩ (∃ λ (gs : get l₁ ≡ get l₂ × set l₁ ≡ set l₂) → subst (λ (get , set) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) (_↔_.to ≡×≡↔≡ gs) (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ inverse Σ-assoc ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → subst (λ (get , set) → Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ l₁′)) ≡ proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ≡⇒↝ _ $ cong (_≡ proj₂ (proj₂ l₂′)) push-subst-[]) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → [ subst (λ (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) (_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ] ≡ [ erased (proj₂ (proj₂ l₂′)) ]) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Erased-≡↔[]≡[]) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased (subst (λ (get , set) → (∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) (_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ≡ erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (≡⇒↝ _ $ cong (λ x → x ≡ erased (proj₂ (proj₂ l₂′))) (push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased (( subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) , subst (λ { (get , set) → (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (erased (proj₂ (proj₂ l₁′)))) ) ≡ erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (inverse ≡×≡↔≡)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased (subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × subst (λ { (get , set) → (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) }) (_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (erased (proj₂ (proj₂ l₁′)))) ≡ proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ proj₂ (erased (proj₂ (proj₂ l₂′)))) (push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased (subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × ( subst (λ { (get , set) → ∀ a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) , subst (λ { (get , set) → ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ) ≡ proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (∃-cong λ _ → inverse ≡×≡↔≡)) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased (subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡ get-set l₂ × subst (λ { (get , set) → ∀ a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) ≡ set-get l₂ × subst (λ { (get , set) → ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ≡ set-set l₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong ( lemma₁ (λ { (get , set) a → ∀ b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) ×-cong lemma₁ (λ { (get , set) a → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) ×-cong lemma₁ (λ { (get , set) a → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a → subst (λ { (get , set) → ∀ b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a) ≡ get-set l₂ a) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a → subst (λ { (get , set) → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a) ≡ set-set l₂ a))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong ( (∀-cong ext λ a → lemma₁ (λ { (get , set) b → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s))) ×-cong F.id ×-cong (∀-cong ext λ a → lemma₁ (λ { (get , set) b₁ → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s))))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ → subst (λ { (get , set) → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁) ≡ set-set l₂ a b₁))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → lemma₁ (λ { (get , set) b₂ → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b }) (_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → subst (λ { (get , set) → set a (get a) ≡ a }) (_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) (_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong ( (∀-cong ext λ a → ∀-cong ext λ b → lemma₂ (λ { (get , set) → get (set a b) ≡ b }) g s) ×-cong (∀-cong ext λ a → lemma₂ (λ { (get , set) → set a (get a) ≡ a }) g s) ×-cong (∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → lemma₂ (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) g s))) ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ get → set l₂ (set l₂ a b₁) b₂ ≡ set l₂ a b₂) g (subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂)) ≡ set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ _) $ subst-const g)) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂))) □ where open Lens abstract lemma₁ : ∀ (C : A → B → Type c) (eq : u ≡ v) {f g} → (subst (λ x → ∀ y → C x y) eq f ≡ g) ↔ (∀ y → subst (λ x → C x y) eq (f y) ≡ g y) lemma₁ C eq {f} {g} = subst (λ x → ∀ y → C x y) eq f ≡ g ↔⟨ inverse $ Eq.extensionality-isomorphism ext ⟩ (∀ y → subst (λ x → ∀ y → C x y) eq f y ≡ g y) ↝⟨ (∀-cong ext λ y → ≡⇒↝ _ $ cong (λ x → x ≡ _) (sym $ push-subst-application eq _)) ⟩□ (∀ y → subst (λ x → C x y) eq (f y) ≡ g y) □ lemma₂ : (P : A × B → Type p) (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : y₁ ≡ y₂) → ∀ {p p′} → (subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ p′) ↔ (subst (λ x → P (x , y₂)) x₁≡x₂ (subst (λ y → P (x₁ , y)) y₁≡y₂ p) ≡ p′) lemma₂ P x₁≡x₂ y₁≡y₂ {p = p} = ≡⇒↝ _ $ cong (_≡ _) $ elim¹ (λ y₁≡y₂ → subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ subst (λ x → P (x , _)) x₁≡x₂ (subst (λ y → P (_ , y)) y₁≡y₂ p)) (subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , refl _)) p ≡⟨⟩ subst P (cong₂ _,_ x₁≡x₂ (refl _)) p ≡⟨⟩ subst P (trans (cong (_, _) x₁≡x₂) (cong (_ ,_) (refl _))) p ≡⟨ cong (λ eq → subst P (trans (cong (_, _) x₁≡x₂) eq) p) $ cong-refl _ ⟩ subst P (trans (cong (_, _) x₁≡x₂) (refl _)) p ≡⟨ cong (λ eq → subst P eq p) $ trans-reflʳ _ ⟩ subst P (cong (_, _) x₁≡x₂) p ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ x → P (x , _)) x₁≡x₂ p ≡⟨ cong (subst (λ x → P (x , _)) x₁≡x₂) $ sym $ subst-refl _ _ ⟩∎ subst (λ x → P (x , _)) x₁≡x₂ (subst (λ y → P (_ , y)) (refl _) p) ∎) _ -- Another equality characterisation lemma. equality-characterisation₂ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂)) equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ get-set l₂ a b) × (∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong ( (∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (_≡ _) $ lemma₁ g s a b) ×-cong (∀-cong ext λ a → ≡⇒↝ _ $ cong (_≡ _) $ lemma₂ g s a) ×-cong F.id)) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂))) □ where open Lens @0 lemma₁ : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡ trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) lemma₁ g s a b = subst (λ get → get (set l₂ a b) ≡ b) g (subst (λ set → get l₁ (set a b) ≡ b) s (get-set l₁ a b)) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g eq) $ subst-in-terms-of-trans-and-cong {f = λ set → get l₁ (set a b)} {g = λ _ → b} {x≡y = s} {fx≡gx = (get-set l₁ a b)} ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans (get-set l₁ a b) (cong (const b) s))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans _ eq))) $ cong-const s ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (trans (get-set l₁ a b) (refl _))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) eq)) $ trans-reflʳ _ ⟩ subst (λ get → get (set l₂ a b) ≡ b) g (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g} {fx≡gx = trans _ (get-set l₁ a b)} ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) (cong (const b) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) eq)) $ cong-const g ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) (refl _)) ≡⟨ cong (trans _) $ trans-reflʳ _ ⟩ trans (sym (cong (λ get → get (set l₂ a b)) g)) (trans (sym (cong (λ set → get l₁ (set a b)) s)) (get-set l₁ a b)) ≡⟨ sym $ trans-assoc _ _ (get-set l₁ a b) ⟩ trans (trans (sym (cong (λ get → get (set l₂ a b)) g)) (sym (cong (λ set → get l₁ (set a b)) s))) (get-set l₁ a b) ≡⟨ cong (λ eq → trans eq (get-set l₁ a b)) $ sym $ sym-trans _ (cong (λ get → get (set l₂ a b)) g) ⟩ trans (sym (trans (cong (λ set → get l₁ (set a b)) s) (cong (λ get → get (set l₂ a b)) g))) (get-set l₁ a b) ≡⟨⟩ trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ∎ @0 lemma₂ : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a → subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡ trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) lemma₂ g s a = subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡⟨⟩ subst (λ get → set l₂ a (get a) ≡ a) g (subst (λ set → set a (get l₁ a) ≡ a) s (set-get l₁ a)) ≡⟨ cong (subst (λ get → set l₂ a (get a) ≡ a) g) $ subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-get l₁ a} ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans (set-get l₁ a) (cong (const a) s))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans _ eq))) $ cong-const s ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (trans (set-get l₁ a) (refl _))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) eq)) $ trans-reflʳ _ ⟩ subst (λ get → set l₂ a (get a) ≡ a) g (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g} {fx≡gx = trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)} ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) (cong (const a) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) eq)) $ cong-const g ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) (refl _)) ≡⟨ cong (trans _) $ trans-reflʳ _ ⟩ trans (sym (cong (λ get → set l₂ a (get a)) g)) (trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)) ≡⟨ sym $ trans-assoc _ _ (set-get l₁ a) ⟩ trans (trans (sym (cong (λ get → set l₂ a (get a)) g)) (sym (cong (λ set → set a (get l₁ a)) s))) (set-get l₁ a) ≡⟨ cong (λ eq → trans eq (set-get l₁ a)) $ sym $ sym-trans _ (cong (λ get → set l₂ a (get a)) g) ⟩ trans (sym (trans (cong (λ set → set a (get l₁ a)) s) (cong (λ get → set l₂ a (get a)) g))) (set-get l₁ a) ≡⟨⟩ trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ∎ -- And another one. equality-characterisation₃ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂))) equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $ lemma g s a b₁ b₂)) ⟩□ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂)))) □ where open Lens @0 lemma : (g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) → ∀ a b₁ b₂ → (subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂) ≡ (trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂)) lemma g s a b₁ b₂ = subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s (set-set l₁ a b₁ b₂) ≡ set-set l₂ a b₁ b₂ ≡⟨ cong (_≡ _) $ subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-set l₁ a b₁ b₂} ⟩ trans (sym (cong (λ set → set (set a b₁) b₂) s)) (trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s)) ≡ set-set l₂ a b₁ b₂ ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩ trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (sym (sym (cong (λ set → set (set a b₁) b₂) s))) (set-set l₂ a b₁ b₂) ≡⟨ cong (λ eq → trans _ (cong (λ set → set a b₂) s) ≡ trans eq (set-set l₂ a b₁ b₂)) $ sym-sym (cong (λ set → set (set a b₁) b₂) s) ⟩ trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂) ∎ -- And yet another one. equality-characterisation₄ : let open Lens in l₁ ≡ l₂ ↔ ∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) → Erased ((∀ a b → trans (sym (trans (cong (get l₁) (s a b)) (g (set l₂ a b)))) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (trans (s a (get l₁ a)) (cong (set l₂ a) (g a)))) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l₂ a b₁ b₂))) equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} = l₁ ≡ l₂ ↝⟨ equality-characterisation₃ ⟩ (∃ λ (g : get l₁ ≡ get l₂) → ∃ λ (s : set l₁ ≡ set l₂) → Erased ((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g)) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g)) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡ trans (cong (λ set → set (set a b₁) b₂) s) (set-set l₂ a b₁ b₂)))) ↝⟨ (Σ-cong (inverse $ Eq.extensionality-isomorphism ext) λ g → Σ-cong (inverse $ Eq.extensionality-isomorphism ext F.∘ ∀-cong ext λ _ → Eq.extensionality-isomorphism ext) λ s → Erased-cong ( (∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (λ eq → trans (sym eq) (get-set l₁ a b) ≡ _) ( cong₂ (λ set get → get (set a b)) s g ≡⟨⟩ trans (cong (λ set → get l₁ (set a b)) s) (cong (λ get → get (set l₂ a b)) g) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $ cong-∘ _ _ s ⟩ trans (cong (get l₁ ⊚ (_$ b)) (ext⁻¹ s a)) (ext⁻¹ g (set l₂ a b)) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $ cong-∘ _ _ (ext⁻¹ s a) ⟩∎ trans (cong (get l₁) (ext⁻¹ (ext⁻¹ s a) b)) (ext⁻¹ g (set l₂ a b)) ∎)) ×-cong (∀-cong ext λ a → ≡⇒↝ _ $ cong (λ eq → trans (sym eq) (set-get l₁ a) ≡ _) ( cong₂ (λ set get → set a (get a)) s g ≡⟨⟩ trans (cong (λ set → set a (get l₁ a)) s) (cong (λ get → set l₂ a (get a)) g) ≡⟨ sym $ cong₂ trans (cong-∘ _ _ s) (cong-∘ _ _ g) ⟩ trans (ext⁻¹ (ext⁻¹ s a) (get l₁ a)) (cong (set l₂ a) (ext⁻¹ g a)) ∎)) ×-cong ∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $ cong₂ (λ p q → trans _ p ≡ trans (cong (λ set → set (set a b₁) b₂) q) (set-set l₂ a b₁ b₂)) ( cong (λ set → set a b₂) s ≡⟨ sym $ cong-∘ _ _ s ⟩∎ ext⁻¹ (ext⁻¹ s a) b₂ ∎) ( s ≡⟨ sym $ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩ ⟨ext⟩ (ext⁻¹ s) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _) ⟩∎ ⟨ext⟩ (⟨ext⟩ ⊚ ext⁻¹ ⊚ ext⁻¹ s) ∎))) ⟩□ (∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) → ∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) → Erased ((∀ a b → trans (sym (trans (cong (get l₁) (s a b)) (g (set l₂ a b)))) (get-set l₁ a b) ≡ get-set l₂ a b) × (∀ a → trans (sym (trans (s a (get l₁ a)) (cong (set l₂ a) (g a)))) (set-get l₁ a) ≡ set-get l₂ a) × (∀ a b₁ b₂ → trans (set-set l₁ a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (set-set l₂ a b₁ b₂)))) □ where open Lens -- A lemma that can be used to prove that two lenses with -- definitionally equal getters and setters are equal. equal-laws→≡ : {get : A → B} {set : A → B → A} {l₁′ l₂′ : Erased ((∀ a b → get (set a b) ≡ b) × (∀ a → set a (get a) ≡ a) × (∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))} → let l₁ = _↔_.from Lens-as-Σ (get , set , l₁′) l₂ = _↔_.from Lens-as-Σ (get , set , l₂′) open Lens in @0 (∀ a b → get-set l₁ a b ≡ get-set l₂ a b) → @0 (∀ a → set-get l₁ a ≡ set-get l₂ a) → @0 (∀ a b₁ b₂ → set-set l₁ a b₁ b₂ ≡ set-set l₂ a b₁ b₂) → l₁ ≡ l₂ equal-laws→≡ {l₁′ = l₁′} {l₂′ = l₂′} hyp₁ hyp₂ hyp₃ = let l₁″ = _↔_.from Lens-as-Σ (_ , _ , l₁′) l₂″ = _↔_.from Lens-as-Σ (_ , _ , l₂′) in _↔_.from equality-characterisation₂ ( refl _ , refl _ , [ (λ a b → trans (sym (cong₂ (λ set get → get (set a b)) (refl _) (refl _))) (get-set l₁″ a b) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩ trans (sym (refl _)) (get-set l₁″ a b) ≡⟨ cong (flip trans _) sym-refl ⟩ trans (refl _) (get-set l₁″ a b) ≡⟨ trans-reflˡ _ ⟩ get-set l₁″ a b ≡⟨ hyp₁ _ _ ⟩∎ get-set l₂″ a b ∎) , (λ a → trans (sym (cong₂ (λ set get → set a (get a)) (refl _) (refl _))) (set-get l₁″ a) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩ trans (sym (refl _)) (set-get l₁″ a) ≡⟨ cong (flip trans _) sym-refl ⟩ trans (refl _) (set-get l₁″ a) ≡⟨ trans-reflˡ _ ⟩ set-get l₁″ a ≡⟨ hyp₂ _ ⟩∎ set-get l₂″ a ∎) , (λ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) (refl _) (set-set l₁″ a b₁ b₂) ≡⟨ subst-refl _ _ ⟩ set-set l₁″ a b₁ b₂ ≡⟨ hyp₃ _ _ _ ⟩∎ set-set l₂″ a b₁ b₂ ∎) ] ) where open Lens -- An equality characterisation lemma for lenses from sets. @0 equality-characterisation-for-sets : let open Lens in {l₁ l₂ : Lens A B} → Is-set A → l₁ ≡ l₂ ↔ set l₁ ≡ set l₂ equality-characterisation-for-sets {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set = l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Traditional-lens ⟩ trad l₁ ≡ trad l₂ ↝⟨ T.equality-characterisation-for-sets A-set ⟩□ set l₁ ≡ set l₂ □ where open Lens ------------------------------------------------------------------------ -- More isomorphisms/equivalences related to lenses -- Lens ⊤ B is equivalent (with erased proofs) to Contractibleᴱ B. lens-from-⊤≃codomain-contractible : Lens ⊤ B ≃ᴱ Contractibleᴱ B lens-from-⊤≃codomain-contractible = EEq.⇔→≃ᴱ (lens-preserves-h-level-of-domain 0 (mono₁ 0 ⊤-contractible)) (ECP.Contractibleᴱ-propositional ext) (λ l → Contractibleᴱ→Contractibleᴱ l (ECP.Contractible→Contractibleᴱ ⊤-contractible)) (λ (b , irrB) → record { get = λ _ → b ; get-set = λ _ → erased irrB ; set-get = refl ; set-set = λ _ _ _ → refl _ }) -- Lens ⊥ B is equivalent to the unit type. lens-from-⊥≃⊤ : Lens (⊥ {ℓ = a}) B ≃ ⊤ lens-from-⊥≃⊤ = Eq.↔⇒≃ $ _⇔_.to contractible⇔↔⊤ $ record { get = ⊥-elim ; set = ⊥-elim ; get-set = λ a → ⊥-elim a ; set-get = λ a → ⊥-elim a ; set-set = λ a → ⊥-elim a } , λ l → _↔_.from equality-characterisation₁ ( ⟨ext⟩ (λ a → ⊥-elim a) , ⟨ext⟩ (λ a → ⊥-elim a) , [ (λ a → ⊥-elim a) , (λ a → ⊥-elim a) , (λ a → ⊥-elim a) ] ) -- If A is a set and there is a lens from A to B, then A is equivalent -- (with erased proofs) to the cartesian product of some type (that -- can be expressed using the setter of l) and B. -- -- This result is based on Theorem 2.3.9 from "Lenses and View Update -- Translation" by Pierce and Schmitt. ≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× : @0 Is-set A → (l : Lens A B) → A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B) ≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× {A = A} {B = B} A-set l = EEq.↔→≃ᴱ (λ a → (set a , ∣ a , [ refl _ ] ∣) , get a) (λ ((f , _) , b) → f b) to-from (λ a → set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Lens l @0 B-set : A → Is-set B B-set a = h-level-respects-lens-from-inhabited 2 l a A-set @0 to-from : ∀ _ → _ to-from ((f , p) , b) = flip TE.rec p λ @0 where .TE.truncation-is-propositionʳ → ×-closure 2 (Σ-closure 2 (Π-closure ext 2 λ _ → A-set) λ _ → mono₁ 1 TE.truncation-is-proposition) (B-set (f b)) .TE.∣∣ʳ (a , [ q ]) → let lemma₁ = set (f b) ≡⟨ cong (λ f → set (f b)) $ sym q ⟩ set (set a b) ≡⟨ ⟨ext⟩ $ set-set a b ⟩ set a ≡⟨ q ⟩∎ f ∎ lemma₂ = get (f b) ≡⟨ cong (λ f → get (f b)) $ sym q ⟩ get (set a b) ≡⟨ get-set _ _ ⟩∎ b ∎ in (set (f b) , ∣ f b , [ refl _ ] ∣) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ (TE.truncation-is-proposition _ _)) lemma₂ ⟩∎ (f , p) , b ∎ -- If B is an inhabited set and there is a lens from A to B, then A is -- equivalent (with erased proofs) to the cartesian product of some -- type (that can be expressed using the getter of l) and B. -- -- This result is based on Corollary 13 from "Algebras and Update -- Strategies" by Johnson, Rosebrugh and Wood. ≃ᴱget⁻¹ᴱ× : @0 Is-set B → (b : B) (l : Lens A B) → A ≃ᴱ (Lens.get l ⁻¹ᴱ b × B) ≃ᴱget⁻¹ᴱ× {B = B} {A = A} B-set b₀ l = EEq.↔→≃ᴱ (λ a → (set a b₀ , [ get-set a b₀ ]) , get a) (λ ((a , _) , b) → set a b) (λ ((a , [ h ]) , b) → let lemma = set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩ set a b₀ ≡⟨ cong (set a) (sym h) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎ in (set (set a b) b₀ , [ get-set (set a b) b₀ ]) , get (set a b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma ([]-cong [ B-set _ _ ])) (get-set a b) ⟩∎ (a , [ h ]) , b ∎) (λ a → set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Lens l -- For somewhat coherent lenses the previous result can be proved -- without the assumption that the codomain is a set. ≃ᴱget⁻¹ᴱ×-coherent : (b : B) (l : Coherent-lens A B) → A ≃ᴱ (Coherent-lens.get l ⁻¹ᴱ b × B) ≃ᴱget⁻¹ᴱ×-coherent {B = B} {A = A} b₀ l = EEq.↔→≃ᴱ (λ a → (set a b₀ , [ get-set a b₀ ]) , get a) (λ ((a , _) , b) → set a b) (λ ((a , [ h ]) , b) → let lemma₁ = set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩ set a b₀ ≡⟨ cong (set a) (sym h) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎ lemma₂₁ = cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) ≡⟨ trans (cong-trans _ _ _) $ cong (trans _) $ trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _ ⟩ trans (cong get (set-set a b b₀)) (trans (cong (get ⊚ set a) (sym h)) (cong get (set-get a))) ≡⟨ cong₂ (λ p q → trans p (trans (cong (get ⊚ set a) (sym h)) q)) (get-set-set _ _ _) (get-set-get _) ⟩∎ trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ⊚ set a) (sym h)) (get-set a (get a))) ∎ lemma₂₂ = sym (trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ⊚ set a) (sym h)) (get-set a (get a)))) ≡⟨ trans (sym-trans _ _) $ cong₂ trans (sym-trans _ _) (sym-trans _ _) ⟩ trans (trans (sym (get-set a (get a))) (sym (cong (get ⊚ set a) (sym h)))) (trans (sym (sym (get-set a b₀))) (sym (get-set (set a b) b₀))) ≡⟨ cong₂ (λ p q → trans (trans (sym (get-set a (get a))) p) (trans q (sym (get-set (set a b) b₀)))) (trans (cong sym $ cong-sym _ _) $ sym-sym _) (sym-sym _) ⟩ trans (trans (sym (get-set a (get a))) (cong (get ⊚ set a) h)) (trans (get-set a b₀) (sym (get-set (set a b) b₀))) ≡⟨ trans (sym $ trans-assoc _ _ _) $ cong (flip trans _) $ trans-assoc _ _ _ ⟩∎ trans (trans (sym (get-set a (get a))) (trans (cong (get ⊚ set a) h) (get-set a b₀))) (sym (get-set (set a b) b₀)) ∎ lemma₂′ = subst (λ a → get a ≡ b₀) (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) (get-set (set a b) b₀) ≡⟨ subst-∘ _ _ _ ⟩ subst (_≡ b₀) (cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a)))) (get-set (set a b) b₀) ≡⟨ subst-trans-sym ⟩ trans (sym (cong get (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))))) (get-set (set a b) b₀) ≡⟨ cong (flip (trans ⊚ sym) _) lemma₂₁ ⟩ trans (sym (trans (trans (get-set (set a b) b₀) (sym (get-set a b₀))) (trans (cong (get ⊚ set a) (sym h)) (get-set a (get a))))) (get-set (set a b) b₀) ≡⟨ cong (flip trans _) lemma₂₂ ⟩ trans (trans (trans (sym (get-set a (get a))) (trans (cong (get ⊚ set a) h) (get-set a b₀))) (sym (get-set (set a b) b₀))) (get-set (set a b) b₀) ≡⟨ trans-[trans-sym]- _ _ ⟩ trans (sym (get-set a (get a))) (trans (cong (get ⊚ set a) h) (get-set a b₀)) ≡⟨ cong (λ f → trans (sym (f (get a))) (trans (cong (get ⊚ set a) h) (f b₀))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) (get-set a) ⟩ trans (sym (ext⁻¹ (⟨ext⟩ (get-set a)) (get a))) (trans (cong (get ⊚ set a) h) (ext⁻¹ (⟨ext⟩ (get-set a)) b₀)) ≡⟨ elim₁ (λ {f} eq → trans (sym (ext⁻¹ eq (get a))) (trans (cong f h) (ext⁻¹ eq b₀)) ≡ h) ( trans (sym (ext⁻¹ (refl P.id) (get a))) (trans (cong P.id h) (ext⁻¹ (refl P.id) b₀)) ≡⟨ cong₂ (λ p q → trans p (trans (cong P.id h) q)) (trans (cong sym (ext⁻¹-refl _)) sym-refl) (ext⁻¹-refl _) ⟩ trans (refl _) (trans (cong P.id h) (refl _)) ≡⟨ trans-reflˡ _ ⟩ trans (cong P.id h) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id h ≡⟨ sym $ cong-id _ ⟩∎ h ∎) _ ⟩∎ h ∎ lemma₂ = subst (λ a → Erased (get a ≡ b₀)) (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) [ get-set (set a b) b₀ ] ≡⟨ push-subst-[] ⟩ [ subst (λ a → get a ≡ b₀) (trans (set-set a b b₀) (trans (cong (set a) (sym h)) (set-get a))) (get-set (set a b) b₀) ] ≡⟨ []-cong [ lemma₂′ ] ⟩∎ [ h ] ∎ in ((set (set a b) b₀ , [ get-set (set a b) b₀ ]) , get (set a b)) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ lemma₂) (get-set a b) ⟩∎ ((a , [ h ]) , b ) ∎) (λ a → set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩ set a (get a) ≡⟨ set-get a ⟩∎ a ∎) where open Coherent-lens l ------------------------------------------------------------------------ -- A conversion function -- If A is a set, then Lens A B is equivalent to Coherent-lens A B. ≃coherent : @0 Is-set A → Lens A B ≃ Coherent-lens A B ≃coherent {A = A} {B = B} A-set = Eq.↔→≃ to Coherent-lens.lens (λ l → let l′ = Coherent-lens.lens l in $⟨ H-level-Erased 1 (×-closure 1 (Π-closure ext 1 λ a → mono₁ 2 (B-set l′ a)) (Π-closure ext 1 λ a → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → mono₁ 2 (B-set l′ a))) ⟩ Is-proposition _ ↝⟨ (λ p → cong (l′ ,_) (p _ _)) ⦂ (_ → _) ⟩ (l′ , _) ≡ (l′ , _) ↔⟨ Eq.≃-≡ Coherent-lens-as-Σ ⟩□ to l′ ≡ l □) refl where @0 B-set : Lens A B → A → Is-set B B-set l a = h-level-respects-lens-from-inhabited 2 l a A-set to : Lens A B → Coherent-lens A B to l = record { lens = l ; get-set-get = λ a → B-set l a _ _ ; get-set-set = λ a _ _ → B-set l a _ _ } -- The conversion preserves getters and setters. ≃coherent-preserves-getters-and-setters : {A : Type a} (@0 s : Is-set A) → Preserves-getters-and-setters-⇔ A B (_≃_.logical-equivalence (≃coherent s)) ≃coherent-preserves-getters-and-setters _ = (λ _ → refl _ , refl _) , (λ _ → refl _ , refl _) ------------------------------------------------------------------------ -- Lens combinators module Lens-combinators where -- If two types are isomorphic, then there is a lens between them. ↔→lens : A ↔ B → Lens A B ↔→lens A↔B = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = left-inverse-of ; set-set = λ _ _ _ → refl _ } where open _↔_ A↔B -- If there is an equivalence with erased proofs between two types, -- then there is a lens between them. ≃ᴱ→lens : A ≃ᴱ B → Lens A B ≃ᴱ→lens A≃B = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = left-inverse-of ; set-set = λ _ _ _ → refl _ } where open _≃ᴱ_ A≃B -- Identity lens. id : Lens A A id = ≃ᴱ→lens F.id -- The identity lens is equal to the one obtained from the -- traditional identity lens without erased proofs. Traditional-lens-id≡id : Traditional-lens→Lens TC.id ≡ id {A = A} Traditional-lens-id≡id = refl _ -- Composition of lenses. infixr 9 _∘_ _∘_ : Lens B C → Lens A B → Lens A C l₁ ∘ l₂ = record { get = λ a → get l₁ (get l₂ a) ; set = λ a c → let b = set l₁ (get l₂ a) c in set l₂ a b ; get-set = T.Lens.get-set l₁∘l₂ ; set-get = T.Lens.set-get l₁∘l₂ ; set-set = T.Lens.set-set l₁∘l₂ } where open Lens @0 l₁∘l₂ : _ l₁∘l₂ = trad l₁ TC.∘ trad l₂ -- Traditional-lens→Lens commutes with composition. @0 Traditional-lens-∘≡∘ : {l₁ : T.Lens B C} {l₂ : T.Lens A B} → Traditional-lens→Lens (l₁ TC.∘ l₂) ≡ Traditional-lens→Lens l₁ ∘ Traditional-lens→Lens l₂ Traditional-lens-∘≡∘ = refl _ -- Note that composition can be defined in several different ways. -- Here are two alternative implementations. infixr 9 _∘′_ _∘″_ _∘′_ : Lens B C → Lens A B → Lens A C l₁ ∘′ l₂ = record (l₁ ∘ l₂) { set-set = T.Lens.set-set l₁∘′l₂ } where @0 l₁∘′l₂ : _ l₁∘′l₂ = trad l₁ TC.∘′ trad l₂ _∘″_ : Lens B C → Lens A B → Lens A C l₁ ∘″ l₂ = record (l₁ ∘ l₂) { set-set = T.Lens.set-set l₁∘″l₂ } where @0 l₁∘″l₂ : _ l₁∘″l₂ = trad l₁ TC.∘″ trad l₂ -- These two implementations are pointwise equal to the other one. -- However, I don't know if there is some other definition that is -- distinct from these two (if we require that the definitions are -- polymorphic, that get and set are implemented in the same way as -- for _∘_, and that the three composition laws below hold). ∘≡∘′ : l₁ ∘ l₂ ≡ l₁ ∘′ l₂ ∘≡∘′ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ b₁ c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (set-set l₂ a b₁ b′) (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁))) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ cong (flip trans _) $ elim₁ (λ eq → trans (set-set l₂ _ b₁ _) (cong (λ b → set l₂ a (set l₁ b c₂)) eq) ≡ trans (cong (λ b → set l₂ _ (set l₁ b _)) eq) (set-set l₂ _ _ _)) ( trans (set-set l₂ a b₁ b₂) (cong (λ b → set l₂ a (set l₁ b c₂)) (refl _)) ≡⟨ trans (cong (trans _) $ cong-refl _) $ trans-reflʳ _ ⟩ set-set l₂ a b₁ b₂ ≡⟨ sym $ trans (cong (flip trans _) $ cong-refl _) $ trans-reflˡ _ ⟩∎ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (refl _)) (set-set l₂ a b₁ b₂) ∎) (get-set l₂ a b₁) ⟩ trans (trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (set-set l₂ a b₁ b₂)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂)) ≡⟨ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (set-set l₂ a b₁ b₂) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨⟩ set-set (l₁ ∘′ l₂) a c₁ c₂ ∎) where open Lens ∘≡∘″ : l₁ ∘ l₂ ≡ l₁ ∘″ l₂ ∘≡∘″ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡ (λ _ _ → refl _) (λ _ → refl _) (λ a c₁ c₂ → let b₁ = set l₁ (get l₂ a) c₁ b₂ = set l₁ (get l₂ a) c₂ a′ = set l₂ a b₁ b′ = set l₁ (get l₂ a′) c₂ eq : b′ ≡ b₂ eq = trans (cong (λ b → set l₁ b c₂) (get-set l₂ a b₁)) (set-set l₁ (get l₂ a) c₁ c₂) in set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩ trans (set-set l₂ a b₁ b′) (trans (cong (λ b → set l₂ a (set l₁ b c₂)) (get-set l₂ a b₁)) (cong (set l₂ a) (set-set l₁ (get l₂ a) c₁ c₂))) ≡⟨ cong (trans (set-set l₂ a b₁ b′)) $ trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _ ⟩ trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡⟨ elim¹ (λ {b₂} eq → trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂)) ( trans (set-set l₂ a b₁ b′) (cong (set l₂ a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩ trans (set-set l₂ a b₁ b′) (refl _) ≡⟨ trans-reflʳ _ ⟩ set-set l₂ a b₁ b′ ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl _) (set-set l₂ a b₁ b′) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎ trans (cong (set l₂ a′) (refl _)) (set-set l₂ a b₁ b′) ∎) eq ⟩ trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂) ≡⟨ trans (cong (flip trans _) $ trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) $ trans-assoc _ _ _ ⟩ trans (cong (λ b → set l₂ a′ (set l₁ b c₂)) (get-set l₂ a b₁)) (trans (cong (set l₂ a′) (set-set l₁ (get l₂ a) c₁ c₂)) (set-set l₂ a b₁ b₂)) ≡⟨⟩ set-set (l₁ ∘″ l₂) a c₁ c₂ ∎) where open Lens -- id is a left identity of _∘_. left-identity : (l : Lens A B) → id ∘ l ≡ l left-identity l = equal-laws→≡ (λ a b → trans (cong P.id (get-set a b)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (get-set a b) ≡⟨ sym $ cong-id _ ⟩∎ get-set a b ∎) (λ a → trans (cong (set a) (refl _)) (set-get a) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (set-get a) ≡⟨ trans-reflˡ _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (set-set a b₁ b₂) (trans (cong (λ _ → set a b₂) (get-set a b₁)) (cong (set a) (refl _))) ≡⟨ cong₂ (λ p q → trans _ (trans p q)) (cong-const _) (cong-refl _) ⟩ trans (set-set a b₁ b₂) (trans (refl _) (refl _)) ≡⟨ trans (cong (trans _) trans-refl-refl) $ trans-reflʳ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- id is a right identity of _∘_. right-identity : (l : Lens A B) → l ∘ id ≡ l right-identity l = equal-laws→≡ (λ a b → trans (cong get (refl _)) (get-set a b) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩ trans (refl _) (get-set a b) ≡⟨ trans-reflˡ _ ⟩∎ get-set a b ∎) (λ a → trans (cong P.id (set-get a)) (refl _) ≡⟨ trans-reflʳ _ ⟩ cong P.id (set-get a) ≡⟨ sym $ cong-id _ ⟩∎ set-get a ∎) (λ a b₁ b₂ → trans (refl _) (trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂))) ≡⟨ trans-reflˡ _ ⟩ trans (cong (λ b → set b b₂) (refl _)) (cong P.id (set-set a b₁ b₂)) ≡⟨ cong₂ trans (cong-refl _) (sym $ cong-id _) ⟩ trans (refl _) (set-set a b₁ b₂) ≡⟨ trans-reflˡ _ ⟩∎ set-set a b₁ b₂ ∎) where open Lens l -- _∘_ is associative. associativity : (l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) → l₁ ∘ (l₂ ∘ l₃) ≡ (l₁ ∘ l₂) ∘ l₃ associativity l₁ l₂ l₃ = equal-laws→≡ lemma₁ lemma₂ lemma₃ where open Lens @0 lemma₁ : _ lemma₁ = λ a d → let f = get l₁ g = get l₂ b = get l₃ a c = g b c′ = set l₁ c d x = get-set l₃ a (set l₂ b c′) y = get-set l₂ b c′ z = get-set l₁ c d in trans (cong f $ trans (cong g x) y) z ≡⟨ cong (λ x → trans x z) (cong-trans f _ y) ⟩ trans (trans (cong f $ cong g x) (cong f y)) z ≡⟨ trans-assoc _ _ z ⟩ trans (cong f $ cong g x) (trans (cong f y) z) ≡⟨ cong (λ x → trans x (trans (cong f y) z)) (cong-∘ f g x) ⟩∎ trans (cong (f ⊚ g) x) (trans (cong f y) z) ∎ @0 lemma₂ : _ lemma₂ = λ a → let b = get l₃ a f = set l₃ a g = set l₂ b x = set-get l₁ (get l₂ b) y = set-get l₂ b z = set-get l₃ a in trans (cong (f ⊚ g) x) (trans (cong f y) z) ≡⟨ sym $ trans-assoc _ _ z ⟩ trans (trans (cong (f ⊚ g) x) (cong f y)) z ≡⟨ cong (λ x → trans (trans x (cong f y)) z) (sym $ cong-∘ f g x) ⟩ trans (trans (cong f (cong g x)) (cong f y)) z ≡⟨ cong (λ x → trans x z) (sym $ cong-trans f _ y) ⟩∎ trans (cong f $ trans (cong g x) y) z ∎ @0 lemma₃ : _ lemma₃ = λ a d₁ d₂ → let f = set l₃ a g = set l₂ (get l₃ a) h = λ x → set l₁ x d₂ i = get l₂ c₁ = set l₁ (get (l₂ ∘ l₃) a) d₁ c₂ = h (i (get l₃ a)) c₂′ = h (i (get l₃ (set (l₂ ∘ l₃) a c₁))) c₂″ = h (i (set l₂ (get l₃ a) c₁)) b₁ = g c₁ b₁′ = get l₃ (f b₁) x = set-set l₃ a b₁ (set l₂ b₁′ c₂′) y = get-set l₃ a b₁ z = set-set l₂ (get l₃ a) c₁ u = get-set l₂ (get l₃ a) c₁ v = set-set l₁ (get (l₂ ∘ l₃) a) d₁ d₂ c₂′≡c₂″ = c₂′ ≡⟨ cong (h ⊚ i) y ⟩∎ c₂″ ∎ lemma₁₀ = trans (sym (cong (h ⊚ i) y)) (cong h (cong i y)) ≡⟨ cong (trans _) (cong-∘ h i y) ⟩ trans (sym (cong (h ⊚ i) y)) (cong (h ⊚ i) y) ≡⟨ trans-symˡ (cong (h ⊚ i) y) ⟩∎ refl _ ∎ lemma₉ = trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″) ≡⟨ cong (trans (cong (λ x → set l₂ x c₂′) y)) (cong-∘ (set l₂ b₁) (h ⊚ i) y) ⟩ trans (cong (λ x → set l₂ x (h (i b₁′))) y) (cong (λ x → set l₂ b₁ (h (i x ))) y) ≡⟨ trans-cong-cong (λ x y → set l₂ x (h (i y))) y ⟩∎ cong (λ x → set l₂ x (h (i x))) y ∎ lemma₈ = sym (cong (set l₂ b₁) (sym c₂′≡c₂″)) ≡⟨ sym $ cong-sym (set l₂ b₁) (sym c₂′≡c₂″) ⟩ cong (set l₂ b₁) (sym (sym c₂′≡c₂″)) ≡⟨ cong (cong (set l₂ b₁)) (sym-sym c₂′≡c₂″) ⟩∎ cong (set l₂ b₁) c₂′≡c₂″ ∎ lemma₇ = trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y))) ≡⟨ sym $ cong-trans g _ (cong h (cong i y)) ⟩ cong g (trans (sym c₂′≡c₂″) (cong h (cong i y))) ≡⟨ cong (cong g) lemma₁₀ ⟩ cong g (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ lemma₆ = trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) ≡⟨ sym $ trans-assoc _ _ (trans _ (cong g (sym c₂′≡c₂″))) ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″)) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₉ ⟩ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ sym $ trans-assoc _ _ (cong g (sym c₂′≡c₂″)) ⟩∎ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″)) ∎ lemma₅ = z c₂′ ≡⟨ sym $ dcong z (sym c₂′≡c₂″) ⟩ subst (λ x → set l₂ b₁ x ≡ g x) (sym c₂′≡c₂″) (z c₂″) ≡⟨ subst-in-terms-of-trans-and-cong {f = set l₂ b₁} {g = g} {x≡y = sym c₂′≡c₂″} ⟩ trans (sym (cong (set l₂ b₁) (sym c₂′≡c₂″))) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₈ ⟩∎ trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))) ∎ lemma₄ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans (trans (cong (λ x → set l₂ x c₂′) y) e) (cong g (cong h (cong i y)))) lemma₅ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (trans (cong (set l₂ b₁) c₂′≡c₂″) (trans (z c₂″) (cong g (sym c₂′≡c₂″))))) (cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans e (cong g (cong h (cong i y)))) lemma₆ ⟩ trans (trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (sym c₂′≡c₂″))) (cong g (cong h (cong i y))) ≡⟨ trans-assoc _ _ (cong g (cong h (cong i y))) ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y)))) ≡⟨ cong (trans (trans _ (z c₂″))) lemma₇ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (refl _) ≡⟨ trans-reflʳ _ ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″) ∎ lemma₃ = cong g (trans (cong h (trans (cong i y) u)) v) ≡⟨ cong (λ e → cong g (trans e v)) (cong-trans h _ u) ⟩ cong g (trans (trans (cong h (cong i y)) (cong h u)) v) ≡⟨ cong (cong g) (trans-assoc _ _ v) ⟩ cong g (trans (cong h (cong i y)) (trans (cong h u) v)) ≡⟨ cong-trans g _ (trans _ v) ⟩∎ trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v)) ∎ lemma₂ = trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (trans (trans _ (z c₂′))) lemma₃ ⟩ trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (trans (cong g (cong h (cong i y))) (cong g (trans (cong h u) v))) ≡⟨ sym $ trans-assoc _ _ (cong g (trans _ v)) ⟩ trans (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (cong h (cong i y)))) (cong g (trans (cong h u) v)) ≡⟨ cong (λ e → trans e (cong g (trans (cong h u) v))) lemma₄ ⟩ trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″)) (cong g (trans (cong h u) v)) ≡⟨ trans-assoc _ _ (cong g (trans _ v)) ⟩∎ trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v))) ∎ lemma₁ = trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (λ e → trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) e) (sym $ cong-∘ f g (trans _ v)) ⟩ trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong f (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ sym $ cong-trans f (trans _ (z c₂′)) (cong g (trans _ v)) ⟩ cong f (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)) (cong g (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (cong f) lemma₂ ⟩ cong f (trans (cong (λ x → set l₂ x (h (i x))) y) (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong-trans _ _ _ ⟩ trans (cong f (cong (λ x → set l₂ x (h (i x))) y)) (cong f (trans (z c₂″) (cong g (trans (cong h u) v)))) ≡⟨ cong₂ (λ p q → trans p (cong f (trans (z c₂″) q))) (cong-∘ _ _ _) (trans (cong-trans _ _ _) $ cong (flip trans _) $ cong-∘ _ _ _) ⟩∎ trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v)))) ∎ in trans (trans x (trans (cong (λ x → f (set l₂ x c₂′)) y) (cong f (z c₂′)))) (trans (cong (f ⊚ g ⊚ h) (trans (cong i y) u)) (cong (f ⊚ g) v)) ≡⟨ cong₂ (λ p q → trans (trans x p) q) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) (trans (cong (flip trans _) $ sym $ cong-∘ _ _ _) $ sym $ cong-trans _ _ _) ⟩ trans (trans x (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ trans-assoc _ _ _ ⟩ trans x (trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))) (cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (trans x) lemma₁ ⟩∎ trans x (trans (cong (λ x → f (set l₂ x (h (i x)))) y) (cong f (trans (z c₂″) (trans (cong (g ⊚ h) u) (cong g v))))) ∎ -- Every lens of type Lens A A that satisfies a certain right -- identity law is equal to the identity lens. id-unique : (id′ : Lens A A) → ((l : Lens A A) → l ∘ id′ ≡ l) → id′ ≡ id id-unique id′ right-identity = id′ ≡⟨ sym $ left-identity _ ⟩ id ∘ id′ ≡⟨ right-identity _ ⟩∎ id ∎ -- An equality characterisation lemma that can be used when one of -- the lenses is the identity. equality-characterisation-id : {l : Lens A A} → let open Lens l in l ≡ id ↔ ∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → Erased ((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))) equality-characterisation-id {l = l} = l ≡ id ↝⟨ equality-characterisation₄ ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → Erased ((∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (cong P.id (g a)))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))) (refl _)))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ → (∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → trans (sym (trans _ eq)) (set-get _) ≡ _) $ sym $ cong-id (g _)) ×-cong ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_ ≡_) $ trans-reflʳ _)) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → Erased ((∀ a b → trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡ refl _) × (∀ a → trans (sym (trans (s a (get a)) (g a))) (set-get a) ≡ refl _) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong ( (∀-cong ext λ _ → ∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong (∀-cong ext λ _ → ≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘ ≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm) ×-cong F.id)) ⟩□ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a b → set a b ≡ b) → Erased ((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a b₁ b₂ → trans (set-set a b₁ b₂) (s a b₂) ≡ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) □ where open Lens l -- A lemma that can be used to show that a lens with a constant -- setter (such as the ones produced by getter-equivalence→lens -- below) is equal to the identity lens. constant-setter→≡id : {l′ : ∃ λ (get : A → A) → ∃ λ (set : A → A) → Erased ((A → ∀ a → get (set a) ≡ a) × (∀ a → set (get a) ≡ a) × (A → A → ∀ a → set a ≡ set a))} → let l = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l hiding (set) in (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → Erased ((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) → l ≡ id constant-setter→≡id {A = A} {l′ = l′} = (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → Erased ((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) ↝⟨ (Σ-map P.id $ Σ-map P.id λ {s} → Erased-cong ( Σ-map P.id $ Σ-map P.id λ hyp a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡⟨ cong (λ eq → trans eq (s a₂)) $ hyp _ _ _ ⟩ trans (refl _) (s a₂) ≡⟨ trans-reflˡ (s _) ⟩∎ s a₂ ∎)) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → Erased ((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ s a₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ a → ∀-cong ext λ a₁ → ∀-cong ext λ a₂ → ≡⇒↝ F.equivalence $ cong (trans _ (s _) ≡_) ( s a₂ ≡⟨ sym $ cong-ext s ⟩ cong (λ set → set a₂) (⟨ext⟩ s) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ s) ⟩ cong (λ set → set (set a a₁) a₂) (cong const (⟨ext⟩ s)) ≡⟨ cong (cong (λ set → set (set a a₁) a₂)) $ sym $ ext-const (⟨ext⟩ s) ⟩∎ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s) ∎))) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : ∀ a → set a ≡ a) → Erased ((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s)))) ↝⟨ Σ-map P.id (Σ-map const P.id) ⟩ (∃ λ (g : ∀ a → get a ≡ a) → ∃ λ (s : A → ∀ a → set a ≡ a) → Erased ((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₁ a₂)) (g a₂)) × (∀ a → set-get a ≡ trans (s a (get a)) (g a)) × (∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a a₂) ≡ cong (λ set → set (set a a₁) a₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↔⟨ inverse equality-characterisation-id ⟩□ l″ ≡ id □ where l″ = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′) set = proj₁ (proj₂ l′) open Lens l″ hiding (set) -- An identity function for lenses for which the forward direction -- is an equivalence (with erased proofs). -- -- Note that the setter of the resulting lens is definitionally -- equal to a constant function returning the right-to-left -- direction of the equivalence. -- -- Note also that two proofs, set-get and set-set, have been -- "obfuscated". They could have been shorter, but then it might not -- have been possible to prove getter-equivalence→lens≡. getter-equivalence→lens : (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) → Lens A B getter-equivalence→lens l is-equiv = record { get = to ; set = const from ; get-set = const right-inverse-of ; set-get = λ a → from (to a) ≡⟨ cong from (sym (get-set a (to a))) ⟩ from (get (set a (to a))) ≡⟨⟩ from (to (set a (get a))) ≡⟨ cong (from ⊚ to) (set-get a) ⟩ from (to a) ≡⟨ left-inverse-of _ ⟩∎ a ∎ ; set-set = λ a b₁ b₂ → let s = from≡set l is-equiv in from b₂ ≡⟨ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)) ⟩ set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩ set a b₂ ≡⟨ sym (s a b₂) ⟩∎ from b₂ ∎ } where A≃B = EEq.⟨ _ , is-equiv ⟩ open _≃ᴱ_ A≃B open Lens l -- In erased contexts it can be proved that the function -- getter-equivalence→lens returns its input. @0 getter-equivalence→lens≡ : ∀ (l : Lens A B) is-equiv → getter-equivalence→lens l is-equiv ≡ l getter-equivalence→lens≡ l is-equiv = $⟨ TC.getter-equivalence→lens≡ (trad l) is-equiv′ ⟩ TC.getter-equivalence→lens (trad l) is-equiv′ ≡ trad l ↝⟨ cong Traditional-lens→Lens ⟩□ getter-equivalence→lens l is-equiv ≡ l □ where is-equiv′ = EEq.Is-equivalenceᴱ→Is-equivalence is-equiv ------------------------------------------------------------------------ -- 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 -- There are two lenses with equal setters that are not equal -- (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by CE.not-refl≢refl, which is only used in an -- erased context.) equal-setters-but-not-equal : @0 Univalence lzero → ∃ λ (A : Type) → ∃ λ (B : Type) → ∃ λ (l₁ : Lens A B) → ∃ λ (l₂ : Lens A B) → Lens.set l₁ ≡ Lens.set l₂ × l₁ ≢ l₂ equal-setters-but-not-equal _ = block λ b → 𝕊¹ᴱ , ⊤ , l₁′ b , l₂′ , refl _ , l₁′≢l₂′ b where open Lens @0 not-refl : Block "not-refl" → (x : 𝕊¹ᴱ) → x ≡ x not-refl ⊠ = CE.not-refl @0 not-refl≢refl : ∀ b → not-refl b ≢ refl not-refl≢refl ⊠ = CE.not-refl≢refl l₁′ : Block "not-refl" → Lens 𝕊¹ᴱ ⊤ l₁′ b = _≃ᴱ_.from lens-to-⊤≃ᴱ [ not-refl b ] l₂′ : Lens 𝕊¹ᴱ ⊤ l₂′ = _≃ᴱ_.from lens-to-⊤≃ᴱ [ refl ] l₁′≢l₂′ : ∀ b → l₁′ b ≢ l₂′ l₁′≢l₂′ b = Stable-¬ [ l₁′ b ≡ l₂′ ↔⟨ Eq.≃-≡ (EEq.≃ᴱ→≃ $ inverse lens-to-⊤≃ᴱ) {x = [ not-refl b ]} {y = [ refl ]} ⟩ [ not-refl b ] ≡ [ refl ] ↝⟨ cong erased ⟩ not-refl b ≡ refl ↝⟨ not-refl≢refl b ⟩□ ⊥ □ ] -- A lens which is used in some counterexamples below. bad : (a : Level) → Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ) bad a = record { get = P.id ; set = const P.id ; get-set = λ _ → cong lift ⊚ CE.not-refl ⊚ lower ; set-get = refl ; set-set = λ _ _ → cong lift ⊚ CE.not-refl ⊚ lower } -- The lens bad a has a getter which is an equivalence, but it does -- not satisfy either of the coherence laws that Coherent-lens lenses -- must satisfy (assuming univalence). -- -- (The lemma does not actually use the univalence argument, but -- univalence is used by CE.not-refl≢refl, which is only used in -- erased contexts.) getter-equivalence-but-not-coherent : @0 Univalence lzero → let open Lens (bad a) in Is-equivalence get × ¬ (∀ a → cong get (set-get a) ≡ get-set a (get a)) × ¬ (∀ a₁ a₂ a₃ → cong get (set-set a₁ a₂ a₃) ≡ trans (get-set (set a₁ a₂) a₃) (sym (get-set a₁ a₃))) getter-equivalence-but-not-coherent {a = a} univ = _≃_.is-equivalence F.id , Stable-¬ [ ((x : ↑ a 𝕊¹ᴱ) → cong get (set-get x) ≡ get-set x (get x)) ↔⟨⟩ ((x : ↑ a 𝕊¹ᴱ) → cong P.id (refl _) ≡ cong lift (CE.not-refl (lower x))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩ ((x : 𝕊¹ᴱ) → cong P.id (refl _) ≡ cong lift (CE.not-refl x)) ↝⟨ trans (trans (cong-refl _) (cong-id _)) ⊚_ ⟩ ((x : 𝕊¹ᴱ) → cong lift (refl x) ≡ cong lift (CE.not-refl x)) ↔⟨ (∀-cong ext λ _ → Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩ ((x : 𝕊¹ᴱ) → refl x ≡ CE.not-refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩ refl ≡ CE.not-refl ↝⟨ CE.not-refl≢refl ⊚ sym ⟩□ ⊥ □ ] , Stable-¬ [ ((x y z : ↑ a 𝕊¹ᴱ) → cong get (set-set x y z) ≡ trans (get-set (set x y) z) (sym (get-set x z))) ↔⟨⟩ ((x y z : ↑ a 𝕊¹ᴱ) → cong P.id (cong lift (CE.not-refl (lower z))) ≡ trans (cong lift (CE.not-refl (lower z))) (sym (cong lift (CE.not-refl (lower z))))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Π-cong ext Bij.↑↔ λ _ → Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩ ((x y z : 𝕊¹ᴱ) → cong P.id (cong lift (CE.not-refl z)) ≡ trans (cong lift (CE.not-refl z)) (sym (cong lift (CE.not-refl z)))) ↝⟨ (λ hyp → hyp CE.base CE.base) ⟩ ((x : 𝕊¹ᴱ) → cong P.id (cong lift (CE.not-refl x)) ≡ trans (cong lift (CE.not-refl x)) (sym (cong lift (CE.not-refl x)))) ↔⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong₂ _≡_ (sym $ cong-id _) (trans (trans-symʳ _) $ sym $ cong-refl _)) ⟩ ((x : 𝕊¹ᴱ) → cong lift (CE.not-refl x) ≡ cong lift (refl x)) ↔⟨ (∀-cong ext λ _ → Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩ ((x : 𝕊¹ᴱ) → CE.not-refl x ≡ refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩ CE.not-refl ≡ refl ↝⟨ CE.not-refl≢refl ⟩□ ⊥ □ ] where open Lens (bad a) -- The lenses bad a and Lens-combinators.id {A = ↑ a 𝕊¹ᴱ} have equal -- setters, and their getters are equivalences, but they are not equal -- (assuming univalence). equal-setters-and-equivalences-as-getters-but-not-equal : @0 Univalence lzero → let l₁ = bad a l₂ = Lens-combinators.id {A = ↑ a 𝕊¹ᴱ} in Is-equivalence (Lens.get l₁) × Is-equivalence (Lens.get l₂) × Lens.set l₁ ≡ Lens.set l₂ × l₁ ≢ l₂ equal-setters-and-equivalences-as-getters-but-not-equal {a = ℓa} univ = let is-equiv , not-coherent , _ = getter-equivalence-but-not-coherent univ in is-equiv , _≃_.is-equivalence F.id , refl _ , Stable-¬ [ bad ℓa ≡ id ↝⟨ (λ eq → subst (λ l → ∀ a → cong (get l) (set-get l a) ≡ get-set l a (get l a)) (sym eq) (λ _ → cong-refl _)) ⟩ (∀ a → cong (get (bad ℓa)) (set-get (bad ℓa) a) ≡ get-set (bad ℓa) a (get (bad ℓa) a)) ↝⟨ not-coherent ⟩□ ⊥ □ ] where open Lens open Lens-combinators -- There is in general no split surjection from equivalences with -- erased proofs to lenses with getters that are equivalences with -- erased proofs, if the right-to-left direction of the split -- surjection is required to return the lens's getter plus some proof -- (assuming univalence). ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get : @0 Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) → Is-equivalenceᴱ (Lens.get l))) → ∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p) ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get {a = a} univ = Stable-¬ [ (let is-equiv₁′ , is-equiv₂′ , setters-equal , bad≢id = equal-setters-and-equivalences-as-getters-but-not-equal univ is-equiv₁ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₁′ is-equiv₂ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₂′ in λ (f , hyp) → $⟨ setters-equal ⟩ Lens.set (bad a) ≡ Lens.set id ↝⟨ getters-equal-if-setters-equal (bad a) id ⟩ Lens.get (bad a) ≡ Lens.get id ↝⟨ (λ eq → trans (hyp _) (trans eq (sym (hyp _)))) ⟩ _≃ᴱ_.to (_↠_.from f (bad a , is-equiv₁)) ≡ _≃ᴱ_.to (_↠_.from f (id , is-equiv₂)) ↝⟨ EEq.to≡to→≡ ext ⟩ _↠_.from f (bad a , is-equiv₁) ≡ _↠_.from f (id , is-equiv₂) ↝⟨ _↠_.to (Surjection.↠-≡ f) ⟩ (bad a , is-equiv₁) ≡ (id , is-equiv₂) ↝⟨ cong proj₁ ⟩ bad a ≡ id ↝⟨ bad≢id ⟩□ ⊥ □) ] where open Lens-combinators -- There is in general no equivalence with erased proofs from -- equivalences with erased proofs to lenses with getters that are -- equivalences with erased proofs, if the right-to-left direction of -- the equivalence is required to return the lens's getter plus some -- proof (assuming univalence). ¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get : @0 Univalence lzero → ¬ ∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) → Is-equivalenceᴱ (Lens.get l))) → ∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p) ¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get {a = a} univ = Stable-¬ [ (∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) → Is-equivalenceᴱ (Lens.get l))) → ∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩ (∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) → Is-equivalenceᴱ (Lens.get l))) → ∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ ⟩□ ⊥ □ ] ------------------------------------------------------------------------ -- Isomorphisms expressed using lens quasi-inverses private module B {a} = Bi-invertibility.Erased equality-with-J (Type a) Lens Lens-combinators.id Lens-combinators._∘_ module BM {a} = B.More {a = a} Lens-combinators.left-identity Lens-combinators.right-identity Lens-combinators.associativity -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≅ᴱ_ to _≅ᴱ_; Has-quasi-inverseᴱ to Has-quasi-inverseᴱ) -- In erased contexts Has-quasi-inverseᴱ (Traditional-lens→Lens l) is -- equivalent to TC.Has-quasi-inverse l. @0 Has-quasi-inverseᴱ≃Has-quasi-inverse : (l : T.Lens A B) → Has-quasi-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-quasi-inverse l Has-quasi-inverseᴱ≃Has-quasi-inverse l = (∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩ (∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse (Eq.≃-≡ Lens≃Traditional-lens) ×-cong inverse (Eq.≃-≡ Lens≃Traditional-lens)) ⟩□ (∃ λ l⁻¹ → l TC.∘ l⁻¹ ≡ TC.id × l⁻¹ TC.∘ l ≡ TC.id ) □ where module LC = Lens-combinators l′ = Traditional-lens→Lens l -- In erased contexts A ≅ᴱ B is equivalent to A TC.≅ B. @0 ≅ᴱ≃≅ : (A ≅ᴱ B) ≃ (A TC.≅ B) ≅ᴱ≃≅ {A = A} {B = B} = (∃ λ (l : Lens A B) → Has-quasi-inverseᴱ l) ↝⟨ Σ-cong-contra (inverse Lens≃Traditional-lens) Has-quasi-inverseᴱ≃Has-quasi-inverse ⟩□ (∃ λ (l : T.Lens A B) → TC.Has-quasi-inverse l) □ -- An equality characterisation lemma for A ≅ B that applies when A is -- a set. @0 equality-characterisation-for-sets-≅ᴱ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≅ᴱ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≅ᴱ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≅ᴱ≃≅ ⟩ _≃_.to ≅ᴱ≃≅ f₁ ≡ _≃_.to ≅ᴱ≃≅ f₂ ↝⟨ TC.equality-characterisation-for-sets-≅ A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a logical equivalence between A ≃ᴱ B and A ≅ᴱ B. ≃ᴱ⇔≅ᴱ : (A ≃ᴱ B) ⇔ (A ≅ᴱ B) ≃ᴱ⇔≅ᴱ {A = A} {B = B} = record { to = λ A≃B → ≃ᴱ→lens A≃B , ≃ᴱ→lens (inverse A≃B) , [ lemma A≃B , (≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B ≡⟨ cong {x = A≃B} {y = inverse $ inverse A≃B} (λ A≃B′ → ≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B′) $ sym $ EEq.to≡to→≡ ext (refl _) ⟩ ≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens (inverse $ inverse A≃B) ≡⟨ lemma (inverse A≃B) ⟩∎ id ∎) ] ; from = λ (l₁ , l₂ , [ eq₁ , eq₂ ]) → EEq.↔→≃ᴱ (get l₁) (get l₂) (ext⁻¹ $ getters-equal-if-setters-equal (l₁ ∘ l₂) id (cong set eq₁)) (ext⁻¹ $ getters-equal-if-setters-equal (l₂ ∘ l₁) id (cong set eq₂)) } where open Lens open Lens-combinators @0 lemma : (C≃D : C ≃ᴱ D) → ≃ᴱ→lens C≃D ∘ ≃ᴱ→lens (inverse C≃D) ≡ id lemma C≃D = _↔_.from equality-characterisation₂ ( ⟨ext⟩ (_≃ᴱ_.right-inverse-of C≃D) , (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) , [ lemma₁ , lemma₂ , lemma₃ ] ) where @0 lemma₁ : _ lemma₁ = λ d₁ d₂ → let lemma = cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))) $ ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂))) (cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₂))) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D) (cong (λ set → set d₂) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)) $ cong-ext _ ⟩ cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D) (_≃ᴱ_.right-inverse-of C≃D _) ≡⟨ sym $ cong-∘ _ _ (_≃ᴱ_.right-inverse-of C≃D _) ⟩ cong (_≃ᴱ_.to C≃D) (cong (_≃ᴱ_.from C≃D) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D)) $ _≃ᴱ_.right-left-lemma C≃D _ ⟩∎ cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _) ∎ in trans (sym (trans (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) (cong (λ get → get d₂) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)))) (trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _)) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong₂ (λ p q → trans (sym (trans p q)) (trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _)) (_≃ᴱ_.right-inverse-of C≃D _))) lemma (cong-ext _) ⟩ trans (sym (trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _)) (_≃ᴱ_.right-inverse-of C≃D _))) (trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _)) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ @0 lemma₂ : _ lemma₂ = λ d → let lemma = cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))) $ ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d))) (cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ cong (λ set → set (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d))) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-ext _ ⟩∎ _≃ᴱ_.right-inverse-of C≃D _ ∎ in trans (sym (trans (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d))) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) (cong (λ get → get d) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)))) (trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _)) (_≃ᴱ_.left-inverse-of (inverse C≃D) _)) ≡⟨ cong₂ (λ p q → trans (sym p) q) (cong₂ trans lemma (cong-ext _)) (cong₂ trans (_≃ᴱ_.left-right-lemma C≃D _) (EEq.left-inverse-of∘inverse C≃D)) ⟩ trans (sym (trans (_≃ᴱ_.right-inverse-of C≃D _) (_≃ᴱ_.right-inverse-of C≃D _))) (trans (_≃ᴱ_.right-inverse-of C≃D _) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎ refl _ ∎ @0 lemma₃ : _ lemma₃ = λ d d₁ d₂ → subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) (trans (refl _) (trans (cong (λ _ → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d₂)) (_≃ᴱ_.right-inverse-of (inverse C≃D) (_≃ᴱ_.from C≃D d₁))) (cong (_≃ᴱ_.to C≃D) (refl _)))) ≡⟨ cong (subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) $ trans (trans-reflˡ _) $ trans (cong (flip trans _) $ cong-const _) $ trans (trans-reflˡ _) $ cong-refl _ ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) (refl _) ≡⟨ cong (flip (subst (λ set → set (set d d₁) d₂ ≡ set d d₂)) _) $ ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩ subst (λ set → set (set d d₁) d₂ ≡ set d d₂) (cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) (refl _) ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ set → set d₂ ≡ set d₂) (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) (refl _) ≡⟨ subst-ext _ _ ⟩ subst (λ set → set ≡ set) (_≃ᴱ_.right-inverse-of C≃D d₂) (refl _) ≡⟨ ≡⇒↝ _ (sym [subst≡]≡[trans≡trans]) ( trans (refl _) (_≃ᴱ_.right-inverse-of C≃D d₂) ≡⟨ trans-reflˡ _ ⟩ _≃ᴱ_.right-inverse-of C≃D d₂ ≡⟨ sym $ trans-reflʳ _ ⟩ trans (_≃ᴱ_.right-inverse-of C≃D d₂) (refl _) ∎) ⟩ refl _ ∎ -- In erased contexts the left-to-right direction of ≃ᴱ⇔≅ᴱ is a right -- inverse of the right-to-left direction. @0 ≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ : (A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≅ᴱ (_⇔_.to ≃ᴱ⇔≅ᴱ A≃B) ≡ A≃B ≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ _ = EEq.to≡to→≡ ext (refl _) -- The forward direction of ≃ᴱ⇔≅ᴱ maps identity to an isomorphism for -- which the first projection is the identity. ≃ᴱ⇔≅ᴱ-id≡id : let open Lens-combinators in proj₁ (_⇔_.to ≃ᴱ⇔≅ᴱ F.id) ≡ id {A = A} ≃ᴱ⇔≅ᴱ-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩ cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) where open Lens-combinators -- If A is a set, then there is an equivalence with erased proofs -- between A ≃ᴱ B and A ≅ᴱ B. ≃ᴱ≃ᴱ≅ᴱ : @0 Is-set A → (A ≃ᴱ B) ≃ᴱ (A ≅ᴱ B) ≃ᴱ≃ᴱ≅ᴱ A-set = EEq.↔→≃ᴱ (_⇔_.to ≃ᴱ⇔≅ᴱ) (_⇔_.from ≃ᴱ⇔≅ᴱ) (λ (l₁ , l₂ , [ eq₁ , eq₂ ]) → _↔_.from (equality-characterisation-for-sets-≅ᴱ A-set) $ ⟨ext⟩ λ a → ⟨ext⟩ λ b → get l₂ b ≡⟨ sym $ ext⁻¹ (ext⁻¹ (cong set eq₂) _) _ ⟩ set l₁ (set l₁ a b) (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ set-set l₁ _ _ _ ⟩ set l₁ a (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ cong (λ b′ → set l₁ a (set l₂ b′ (get l₂ b))) $ get-set l₁ _ _ ⟩ set l₁ a (set l₂ b (get l₂ b)) ≡⟨ cong (set l₁ a) $ set-get l₂ _ ⟩∎ set l₁ a b ∎) ≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ where open Lens open Lens-combinators -- The equivalence maps identity to an isomorphism for which the first -- projection is the identity. ≃ᴱ≃ᴱ≅ᴱ-id≡id : let open Lens-combinators in (@0 A-set : Is-set A) → proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≅ᴱ A-set) F.id) ≡ id ≃ᴱ≃ᴱ≅ᴱ-id≡id _ = ≃ᴱ⇔≅ᴱ-id≡id -- The type Has-quasi-inverseᴱ id is not necessarily a proposition -- (assuming univalence). Has-quasi-inverseᴱ-id-not-proposition : @0 Univalence lzero → let open Lens-combinators in ∃ λ (A : Type a) → ¬ Is-proposition (Has-quasi-inverseᴱ (id {A = A})) Has-quasi-inverseᴱ-id-not-proposition univ = _ , Stable-¬ [ Is-proposition (Has-quasi-inverseᴱ Lens-combinators.id) ↝⟨ H-level-cong _ 1 $ Has-quasi-inverseᴱ≃Has-quasi-inverse TC.id ⟩ Is-proposition (TC.Has-quasi-inverse TC.id) ↝⟨ proj₂ $ TC.Has-quasi-inverse-id-not-proposition univ ⟩□ ⊥ □ ] -- There is not necessarily a split surjection from -- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a -- lens between types in the same universe (assuming univalence). ¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ : @0 Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ {a = a} univ = Stable-¬ [ ({A B : Type a} (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp l → from-equivalence (Has-quasi-inverseᴱ≃Has-quasi-inverse l) F.∘ hyp (Traditional-lens→Lens l) F.∘ from-equivalence EEq.Is-equivalence≃Is-equivalenceᴱ) ⟩ ({A B : Type a} (l : T.Lens A B) → Is-equivalence (T.Lens.get l) ↠ TC.Has-quasi-inverse l) ↝⟨ TC.¬Is-equivalence↠Has-quasi-inverse univ ⟩□ ⊥ □ ] -- There is not necessarily an equivalence with erased proofs from -- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a -- lens between types in the same universe (assuming univalence). ¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ : @0 Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l) ¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ {a = a} univ = Stable-¬ [ ({A B : Type a} (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp → _≃_.surjection ⊚ EEq.≃ᴱ→≃ ⊚ hyp) ⟩ ({A B : Type a} (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ ¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ univ ⟩□ ⊥ □ ] ------------------------------------------------------------------------ -- Isomorphisms expressed using bi-invertibility for lenses -- A form of isomorphism between types, expressed using lenses. open B public using () renaming (_≊ᴱ_ to _≊ᴱ_; Has-left-inverseᴱ to Has-left-inverseᴱ; Has-right-inverseᴱ to Has-right-inverseᴱ; Is-bi-invertibleᴱ to Is-bi-invertibleᴱ) open BM public using () renaming (Is-bi-invertibleᴱ-propositional to Is-bi-invertibleᴱ-propositional) -- In erased contexts Has-left-inverseᴱ (Traditional-lens→Lens l) is -- equivalent to TC.Has-left-inverse l. @0 Has-left-inverseᴱ≃Has-left-inverse : (l : T.Lens A B) → Has-left-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-left-inverse l Has-left-inverseᴱ≃Has-left-inverse l = (∃ λ l⁻¹ → Erased (l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩ (∃ λ l⁻¹ → l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□ (∃ λ l⁻¹ → l⁻¹ TC.∘ l ≡ TC.id ) □ where module LC = Lens-combinators l′ = Traditional-lens→Lens l -- In erased contexts Has-right-inverseᴱ (Traditional-lens→Lens l) is -- equivalent to TC.Has-right-inverse l. @0 Has-right-inverseᴱ≃Has-right-inverse : (l : T.Lens A B) → Has-right-inverseᴱ (Traditional-lens→Lens l) ≃ TC.Has-right-inverse l Has-right-inverseᴱ≃Has-right-inverse l = (∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩ (∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□ (∃ λ l⁻¹ → l TC.∘ l⁻¹ ≡ TC.id ) □ where module LC = Lens-combinators l′ = Traditional-lens→Lens l -- In erased contexts Is-bi-invertibleᴱ (Traditional-lens→Lens l) is -- equivalent to TC.Is-bi-invertible l. @0 Is-bi-invertibleᴱ≃Is-bi-invertible : (l : T.Lens A B) → Is-bi-invertibleᴱ (Traditional-lens→Lens l) ≃ TC.Is-bi-invertible l Is-bi-invertibleᴱ≃Is-bi-invertible l = Is-bi-invertibleᴱ l′ ↔⟨⟩ Has-left-inverseᴱ l′ × Has-right-inverseᴱ l′ ↝⟨ Has-left-inverseᴱ≃Has-left-inverse l ×-cong Has-right-inverseᴱ≃Has-right-inverse l ⟩ TC.Has-left-inverse l × TC.Has-right-inverse l ↔⟨⟩ TC.Is-bi-invertible l □ where l′ = Traditional-lens→Lens l -- In erased contexts A ≊ᴱ B is equivalent to A TC.≊ B. @0 ≊ᴱ≃≊ : (A ≊ᴱ B) ≃ (A TC.≊ B) ≊ᴱ≃≊ {A = A} {B = B} = (∃ λ (l : Lens A B) → Is-bi-invertibleᴱ l) ↝⟨ (inverse $ Σ-cong (inverse Lens≃Traditional-lens) λ l → inverse $ Is-bi-invertibleᴱ≃Is-bi-invertible l) ⟩□ (∃ λ (l : T.Lens A B) → TC.Is-bi-invertible l) □ -- An equality characterisation lemma for A ≊ᴱ B that applies when A -- is a set. @0 equality-characterisation-for-sets-≊ᴱ : let open Lens in {f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≊ᴱ B} → Is-set A → f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂ equality-characterisation-for-sets-≊ᴱ {f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set = f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≊ᴱ≃≊ ⟩ _≃_.to ≊ᴱ≃≊ f₁ ≡ _≃_.to ≊ᴱ≃≊ f₂ ↝⟨ TC.equality-characterisation-for-sets-≊ A-set ⟩□ set l₁₁ ≡ set l₁₂ □ where open Lens -- There is a logical equivalence between A ≃ᴱ B and A ≊ᴱ B. ≃ᴱ⇔≊ᴱ : (A ≃ᴱ B) ⇔ (A ≊ᴱ B) ≃ᴱ⇔≊ᴱ = record { to = _⇔_.to BM.≅ᴱ⇔≊ᴱ ⊚ _⇔_.to ≃ᴱ⇔≅ᴱ ; from = _⇔_.from ≃ᴱ⇔≅ᴱ ⊚ _⇔_.from BM.≅ᴱ⇔≊ᴱ } -- In erased contexts the left-to-right direction of ≃ᴱ⇔≊ᴱ is a right -- inverse of the right-to-left direction. @0 ≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ : (A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≊ᴱ (_⇔_.to ≃ᴱ⇔≊ᴱ A≃B) ≡ A≃B ≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ _ = EEq.to≡to→≡ ext (refl _) -- The forward direction of ≃ᴱ⇔≊ᴱ maps identity to an isomorphism for -- which the first projection is the identity. ≃ᴱ⇔≊ᴱ-id≡id : let open Lens-combinators in proj₁ (_⇔_.to ≃ᴱ⇔≊ᴱ F.id) ≡ id {A = A} ≃ᴱ⇔≊ᴱ-id≡id = equal-laws→≡ (λ _ _ → refl _) (λ a → _≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩ cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩ cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎ refl _ ∎) (λ _ _ _ → refl _) where open Lens-combinators -- If A is a set, then there is an equivalence between A ≃ᴱ B and -- A ≊ᴱ B. ≃ᴱ≃ᴱ≊ᴱ : @0 Is-set A → (A ≃ᴱ B) ≃ᴱ (A ≊ᴱ B) ≃ᴱ≃ᴱ≊ᴱ {A = A} {B = B} A-set = A ≃ᴱ B ↝⟨ ≃ᴱ≃ᴱ≅ᴱ A-set ⟩ A ≅ᴱ B ↝⟨ inverse $ BM.≊ᴱ≃ᴱ≅ᴱ-domain (lens-preserves-h-level-of-domain 1 A-set) ⟩□ A ≊ᴱ B □ -- The equivalence ≃ᴱ≃ᴱ≊ᴱ maps identity to an isomorphism for which the -- first projection is the identity. ≃ᴱ≃ᴱ≊ᴱ-id≡id : let open Lens-combinators in (@0 A-set : Is-set A) → proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≊ᴱ A-set) F.id) ≡ id ≃ᴱ≃ᴱ≊ᴱ-id≡id _ = ≃ᴱ⇔≊ᴱ-id≡id where open Lens-combinators -- The right-to-left direction of ≃ᴱ≃ᴱ≊ᴱ maps bi-invertible lenses to -- their getter functions. to-from-≃ᴱ≃ᴱ≊ᴱ≡get : (@0 A-set : Is-set A) (A≊B@(l , _) : A ≊ᴱ B) → _≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ A-set) A≊B) ≡ Lens.get l to-from-≃ᴱ≃ᴱ≊ᴱ≡get _ _ = refl _ -- The getter function of a bi-invertible lens is an equivalence (with -- erased proofs). Is-bi-invertibleᴱ→Is-equivalenceᴱ-get : (l : Lens A B) → Is-bi-invertibleᴱ l → Is-equivalenceᴱ (Lens.get l) Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l is-bi-inv = _≃ᴱ_.is-equivalence (_⇔_.from ≃ᴱ⇔≊ᴱ (l , is-bi-inv)) -- If the getter function is an equivalence (with erased proofs), then -- the lens is bi-invertible (with erased proofs). Is-equivalenceᴱ-get→Is-bi-invertibleᴱ : (l : Lens A B) → Is-equivalenceᴱ (Lens.get l) → Is-bi-invertibleᴱ l Is-equivalenceᴱ-get→Is-bi-invertibleᴱ {A = A} {B = B} l′ is-equiv = block λ b → $⟨ l⁻¹′ b , [ l∘l⁻¹≡id b , l⁻¹∘l≡id b ] ⟩ Has-quasi-inverseᴱ l ↝⟨ B.Has-quasi-inverseᴱ→Is-bi-invertibleᴱ l ⟩ Is-bi-invertibleᴱ l ↝⟨ subst (λ l → Is-bi-invertibleᴱ (erased l)) ([]-cong [ getter-equivalence→lens≡ l′ is-equiv ]) ⟩□ Is-bi-invertibleᴱ l′ □ where open Lens open Lens-combinators -- A lens that is equal to l′. l : Lens A B l = getter-equivalence→lens l′ is-equiv A≃B = EEq.⟨ get l , is-equiv ⟩ open _≃ᴱ_ A≃B -- An inverse of l. -- -- Note that the set-get and set-set proofs have been "obfuscated". -- They could have been shorter, but then it might not have been -- possible to prove l∘l⁻¹≡id and l⁻¹∘l≡id. l⁻¹ : Lens B A l⁻¹ = record { get = from ; set = λ _ → get l ; get-set = λ _ a → from (get l a) ≡⟨ left-inverse-of a ⟩∎ a ∎ ; set-get = λ b → get l (from b) ≡⟨ sym $ cong (get l) $ set-get l (from b) ⟩ get l (from (get l (from b))) ≡⟨ right-inverse-of (get l (from b)) ⟩ get l (from b) ≡⟨ right-inverse-of b ⟩∎ b ∎ ; set-set = λ b a₁ a₂ → get l a₂ ≡⟨ sym $ right-inverse-of _ ⟩ get l (from (get l a₂)) ≡⟨ sym $ cong (get l) (set-set l (from b) (get l a₁) (get l a₂)) ⟩ get l (from (get l a₂)) ≡⟨ right-inverse-of _ ⟩∎ get l a₂ ∎ } -- A blocked variant of l⁻¹. l⁻¹′ : Block "l⁻¹" → Lens B A l⁻¹′ ⊠ = l⁻¹ -- The lens l⁻¹ is a right inverse of l. @0 l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹′ b ≡ id l∘l⁻¹≡id ⊠ = constant-setter→≡id ( right-inverse-of , right-inverse-of , [ (λ b₁ b₂ → get-set (l ∘ l⁻¹) b₁ b₂ ≡⟨⟩ trans (cong (get l) (get-set l⁻¹ b₁ (from b₂))) (get-set l (from b₁) b₂) ≡⟨⟩ trans (cong (get l) (left-inverse-of (from b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans (cong (get l) eq) (right-inverse-of b₂)) $ sym $ right-left-lemma _ ⟩ trans (cong (get l) (cong from (right-inverse-of b₂))) (right-inverse-of b₂) ≡⟨ cong (λ eq → trans eq (right-inverse-of b₂)) $ cong-∘ _ _ (right-inverse-of b₂) ⟩ trans (cong (get l ⊚ from) (right-inverse-of b₂)) (right-inverse-of b₂) ≡⟨⟩ trans (cong (get (l ∘ l⁻¹)) (right-inverse-of b₂)) (right-inverse-of b₂) ∎) , (λ b → set-get (l ∘ l⁻¹) b ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (set-get l⁻¹ b) ≡⟨⟩ trans (cong (get l) (set-get l (from b))) (trans (sym (cong (get l) (set-get l (from b)))) (trans (right-inverse-of (get l (from b))) (right-inverse-of b))) ≡⟨ trans--[trans-sym] _ _ ⟩ trans (right-inverse-of (get l (from b))) (right-inverse-of b) ≡⟨⟩ trans (right-inverse-of (get (l ∘ l⁻¹) b)) (right-inverse-of b) ∎) , (λ b b₁ b₂ → set-set (l ∘ l⁻¹) b b₁ b₂ ≡⟨⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (trans (cong (λ _ → get l (from b₂)) (get-set l⁻¹ b (from b₁))) (cong (get l) (set-set l (from b) b₁ b₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l⁻¹ b (from b₁) (from b₂)) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) (get l (from b₁)) (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ b′ → trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b′ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ right-inverse-of _ ⟩ trans (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (right-inverse-of _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ f → trans (trans (sym (f _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (f _))) (cong (get l) (set-set l (from b) b₁ b₂))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) right-inverse-of ⟩ trans (trans (sym (ext⁻¹ (⟨ext⟩ right-inverse-of) _)) (trans (sym (cong (get l) (set-set l (from b) b₁ (get l (from b₂))))) (ext⁻¹ (⟨ext⟩ right-inverse-of) _))) (cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ b → f b ≡ f b) → trans (trans (sym (ext⁻¹ p (f b₂))) (trans (sym (q (f b₂))) (ext⁻¹ p (f b₂)))) (q b₂) ≡ refl _) (λ q → trans (trans (sym (ext⁻¹ (refl P.id) _)) (trans (sym (q _)) (ext⁻¹ (refl P.id) _))) (q _) ≡⟨ cong (λ eq → trans (trans (sym eq) (trans (sym (q _)) eq)) (q _)) $ ext⁻¹-refl _ ⟩ trans (trans (sym (refl _)) (trans (sym (q _)) (refl _))) (q _) ≡⟨ cong₂ (λ p r → trans (trans p r) (q _)) sym-refl (trans-reflʳ _) ⟩ trans (trans (refl _) (sym (q _))) (q _) ≡⟨ cong (λ eq → trans eq (q _)) $ trans-reflˡ (sym (q _)) ⟩ trans (sym (q _)) (q _) ≡⟨ trans-symˡ (q _) ⟩∎ refl _ ∎) (⟨ext⟩ right-inverse-of) (cong (get l) ⊚ set-set l (from b) b₁) ⟩ refl _ ∎) ] ) -- The lens l⁻¹ is a left inverse of l. @0 l⁻¹∘l≡id : ∀ b → l⁻¹′ b ∘ l ≡ id l⁻¹∘l≡id ⊠ = constant-setter→≡id ( left-inverse-of , left-inverse-of , [ (λ a₁ a₂ → get-set (l⁻¹ ∘ l) a₁ a₂ ≡⟨⟩ trans (cong from (get-set l a₁ (to a₂))) (get-set l⁻¹ (get l a₁) a₂) ≡⟨⟩ trans (cong from (right-inverse-of (to a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans (cong from eq) (left-inverse-of _)) $ sym $ left-right-lemma _ ⟩ trans (cong from (cong (get l) (left-inverse-of a₂))) (left-inverse-of a₂) ≡⟨ cong (λ eq → trans eq (left-inverse-of _)) $ cong-∘ _ _ (left-inverse-of _) ⟩ trans (cong (from ⊚ get l) (left-inverse-of a₂)) (left-inverse-of a₂) ≡⟨⟩ trans (cong (get (l⁻¹ ∘ l)) (left-inverse-of a₂)) (left-inverse-of a₂) ∎) , (λ a → let lemma₁ = cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans _ (right-inverse-of _)) ⟩ trans (cong from (sym (cong (get l) (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong (λ eq → trans (cong from eq) (cong from (trans (right-inverse-of _) (right-inverse-of _)))) $ sym $ cong-sym _ (set-get l (from (get l a))) ⟩ trans (cong from (cong (get l) (sym (set-get l (from (get l a)))))) (cong from (trans (right-inverse-of _) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-∘ _ _ (sym (set-get l (from (get l a))))) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (cong from (right-inverse-of _)) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p q → trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans p q)) (right-left-lemma _) (right-left-lemma _) ⟩∎ trans (cong (from ⊚ get l) (sym (set-get l (from (get l a))))) (trans (left-inverse-of _) (left-inverse-of _)) ∎ f = from ⊚ get l lemma₂ : ∀ _ → _ lemma₂ = λ a → trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨ cong (λ g → trans (g (f a)) (g a)) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ∎ lemma₃ = trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ≡⟨ cong₂ trans (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩ trans (refl _) (refl _) ≡⟨ trans-refl-refl ⟩∎ refl _ ∎ in trans (cong from (set-get l⁻¹ (get l a))) (set-get l a) ≡⟨⟩ trans (cong from (trans (sym (cong (get l) (set-get l (from (get l a))))) (trans (right-inverse-of _) (right-inverse-of _)))) (set-get l a) ≡⟨ cong (λ eq → trans eq (set-get l a)) lemma₁ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (left-inverse-of (f (f a))) (left-inverse-of (f a)))) (set-get l a) ≡⟨ cong (λ eq → trans (trans (cong f (sym (set-get l (f a)))) eq) (set-get l a)) $ lemma₂ _ ⟩ trans (trans (cong f (sym (set-get l (f a)))) (trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f (f a))) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)))) (set-get l a) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : ∀ a → f a ≡ a) → trans (trans (cong f (sym (q (f a)))) (trans (ext⁻¹ p (f (f a))) (ext⁻¹ p (f a)))) (q a) ≡ trans (ext⁻¹ p (f a)) (ext⁻¹ p a)) (λ q → trans (trans (cong P.id (sym (q a))) (trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a))) (q a) ≡⟨ cong₂ (λ p r → trans (trans p r) (q a)) (sym $ cong-id _) lemma₃ ⟩ trans (trans (sym (q a)) (refl _)) (q a) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩ trans (sym (q a)) (q a) ≡⟨ trans-symˡ (q a) ⟩ refl _ ≡⟨ sym lemma₃ ⟩∎ trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ∎) (⟨ext⟩ left-inverse-of) (set-get l) ⟩ trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a)) (ext⁻¹ (⟨ext⟩ left-inverse-of) a) ≡⟨ sym $ lemma₂ _ ⟩ trans (left-inverse-of (f a)) (left-inverse-of a) ≡⟨⟩ trans (left-inverse-of (get (l⁻¹ ∘ l) a)) (left-inverse-of a) ∎) , (λ a a₁ a₂ → let q = set-set l a (get l a₁) (get l a₂) lemma = cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong-trans _ _ (trans (sym (cong (get l) q)) (right-inverse-of _)) ⟩ trans (cong from (sym (right-inverse-of _))) (cong from (trans (sym (cong (get l) q)) (right-inverse-of _))) ≡⟨ cong₂ trans (cong-sym _ (right-inverse-of _)) (cong-trans _ _ (right-inverse-of _)) ⟩ trans (sym (cong from (right-inverse-of _))) (trans (cong from (sym (cong (get l) q))) (cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p r → trans (sym p) (trans (cong from (sym (cong (get l) q))) r)) (right-left-lemma _) (right-left-lemma _) ⟩ trans (sym (left-inverse-of _)) (trans (cong from (sym (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans eq (left-inverse-of _))) $ cong-sym _ (cong (get l) q) ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong from (cong (get l) q))) (left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _)) (trans (sym eq) (left-inverse-of _))) $ cong-∘ _ _ q ⟩ trans (sym (left-inverse-of _)) (trans (sym (cong (from ⊚ get l) q)) (left-inverse-of _)) ≡⟨ cong (λ g → trans (sym (g _)) (trans (sym (cong (from ⊚ get l) q)) (g _))) $ sym $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) left-inverse-of ⟩∎ trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) (trans (sym (cong (from ⊚ get l) q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) _)) ∎ f = from ⊚ get l in set-set (l⁻¹ ∘ l) a a₁ a₂ ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (trans (cong (λ _ → from (get l a₂)) (right-inverse-of (get l a₁))) (cong from (set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (trans _) $ trans (cong (flip trans _) $ cong-const _) $ trans-reflˡ _ ⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (set-set l⁻¹ (get l a) a₁ a₂)) ≡⟨⟩ trans (set-set l a (get l a₁) (get l a₂)) (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l (from (get l a)) (get l a₁) (get l a₂)))) (right-inverse-of _)))) ≡⟨ cong (λ a′ → trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) (set-set l a′ (get l a₁) (get l a₂)))) (right-inverse-of _))))) $ left-inverse-of _ ⟩ trans q (cong from (trans (sym (right-inverse-of _)) (trans (sym (cong (get l) q)) (right-inverse-of _)))) ≡⟨ cong (trans q) lemma ⟩ trans q (trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂))) (trans (sym (cong f q)) (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))) ≡⟨ elim₁ (λ {f} (p : f ≡ P.id) → (q : f a₂ ≡ f a₂) → trans q (trans (sym (ext⁻¹ p (f a₂))) (trans (sym (cong f q)) (ext⁻¹ p (f a₂)))) ≡ refl _) (λ q → trans q (trans (sym (ext⁻¹ (refl P.id) a₂)) (trans (sym (cong P.id q)) (ext⁻¹ (refl P.id) a₂))) ≡⟨ cong (λ eq → trans q (trans (sym eq) (trans (sym (cong P.id q)) eq))) $ ext⁻¹-refl _ ⟩ trans q (trans (sym (refl _)) (trans (sym (cong P.id q)) (refl _))) ≡⟨ cong₂ (λ p r → trans q (trans p r)) sym-refl (trans-reflʳ _) ⟩ trans q (trans (refl _) (sym (cong P.id q))) ≡⟨ cong (trans q) $ trans-reflˡ (sym (cong P.id q)) ⟩ trans q (sym (cong P.id q)) ≡⟨ cong (λ eq → trans q (sym eq)) $ sym $ cong-id q ⟩ trans q (sym q) ≡⟨ trans-symʳ q ⟩∎ refl _ ∎) (⟨ext⟩ left-inverse-of) q ⟩ refl _ ∎) ] ) -- There is an equivalence with erased proofs between "l is -- bi-invertible (with erased proofs) " and "the getter of l is an -- equivalence (with erased proofs)". Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get : (l : Lens A B) → Is-bi-invertibleᴱ l ≃ᴱ Is-equivalenceᴱ (Lens.get l) Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l = EEq.⇔→≃ᴱ (BM.Is-bi-invertibleᴱ-propositional l) (EEq.Is-equivalenceᴱ-propositional ext _) (Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l) (Is-equivalenceᴱ-get→Is-bi-invertibleᴱ l) -- There is in general no split surjection from equivalences (with -- erased proofs) to lenses that are bi-invertible (with erased -- proofs), if the right-to-left direction of the split surjection is -- required to map bi-invertible lenses to their getter functions -- (assuming univalence). ¬≃ᴱ↠≊ᴱ : @0 Univalence lzero → ¬ ∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) → (x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) → _≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l ¬≃ᴱ↠≊ᴱ {a = a} univ = Stable-¬ [ (∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) → (x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) → _≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l) ↝⟨ Σ-map ((∃-cong λ l → _≃_.surjection $ EEq.≃ᴱ→≃ $ Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l) F.∘_) (λ hyp _ → hyp _) ⟩ (∃ λ (f : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (∃ λ (l : Lens (↑ a 𝕊¹ᴱ) (↑ a 𝕊¹ᴱ)) → Is-equivalenceᴱ (Lens.get l))) → ∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ ⟩□ ⊥ □ ] -- There is in general no equivalence with erased proofs between -- equivalences (with erased proofs) and lenses that are bi-invertible -- (with erased proofs), if the right-to-left direction of the -- equivalence is required to map bi-invertible lenses to their getter -- functions (assuming univalence). ¬≃ᴱ≃ᴱ≊ᴱ : @0 Univalence lzero → ¬ ∃ λ (≃ᴱ≃ᴱ≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) → (x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) → _≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ x) ≡ Lens.get l ¬≃ᴱ≃ᴱ≊ᴱ {a = a} univ = Stable-¬ [ (∃ λ (≃ᴱ≃ᴱ≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ≃ᴱ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) → (x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) → _≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ x) ≡ Lens.get l) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩ (∃ λ (≃ᴱ↠≊ᴱ : (↑ a 𝕊¹ᴱ ≃ᴱ ↑ a 𝕊¹ᴱ) ↠ (↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ)) → (x@(l , _) : ↑ a 𝕊¹ᴱ ≊ᴱ ↑ a 𝕊¹ᴱ) → _≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ x) ≡ Lens.get l) ↝⟨ ¬≃ᴱ↠≊ᴱ univ ⟩□ ⊥ □ ] -- The lemma ≃ᴱΣ∥set⁻¹ᴱ∥ᴱ× does not hold in general if the requirement -- that A is a set is dropped (assuming univalence). ≄ᴱΣ∥set⁻¹ᴱ∥ᴱ× : @0 Univalence lzero → ¬ ({A B : Type a} (l : Lens A B) → A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)) ≄ᴱΣ∥set⁻¹ᴱ∥ᴱ× {a = a} univ = Stable-¬ [ ({A B : Type a} (l : Lens A B) → A ≃ᴱ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)) ↝⟨ EEq.≃ᴱ→≃ ⊚_ ⟩ ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥ᴱ) × B)) ↝⟨ ((×-cong₁ λ _ → ∃-cong λ _ → PT.∥∥ᴱ≃∥∥) F.∘_) ⊚_ ⟩ ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ᴱ f ∥) × B)) ↝⟨ ((×-cong₁ λ _ → ∃-cong λ _ → PT.∥∥-cong $ inverse ECP.⁻¹≃⁻¹ᴱ) F.∘_) ⊚_ ⟩ ({A B : Type a} (l : Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)) ↝⟨ _⊚ Traditional-lens→Lens ⟩ ({A B : Type a} (l : T.Lens A B) → A ≃ ((∃ λ (f : B → A) → ∥ T.Lens.set l ⁻¹ f ∥) × B)) ↝⟨ TC.≄Σ∥set⁻¹∥× univ ⟩□ ⊥ □ ]
{ "alphanum_fraction": 0.3670442467, "avg_line_length": 46.8273606371, "ext": "agda", "hexsha": "dc4724086c959be7572e860d727b9b61c2336ebf", "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/Traditional/Erased.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/Traditional/Erased.agda", "max_line_length": 162, "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/Traditional/Erased.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": 54173, "size": 164645 }
{- This second-order equational theory was created from the following second-order syntax description: syntax Lens | L type S : 0-ary A : 0-ary term get : S -> A put : S A -> S theory (PG) s : S a : A |> get (put (s, a)) = a (GP) s : S |> put (s, get(s)) = s (PP) s : S a b : A |> put (put(s, a), b) = put (s, a) -} module Lens.Equality where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Families.Build open import SOAS.ContextMaps.Inductive open import Lens.Signature open import Lens.Syntax open import SOAS.Metatheory.SecondOrder.Metasubstitution L:Syn open import SOAS.Metatheory.SecondOrder.Equality L:Syn private variable α β γ τ : LT Γ Δ Π : Ctx infix 1 _▹_⊢_≋ₐ_ -- Axioms of equality data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ L) α Γ → (𝔐 ▷ L) α Γ → Set where PG : ⁅ S ⁆ ⁅ A ⁆̣ ▹ ∅ ⊢ get (put 𝔞 𝔟) ≋ₐ 𝔟 GP : ⁅ S ⁆̣ ▹ ∅ ⊢ put 𝔞 (get 𝔞) ≋ₐ 𝔞 PP : ⁅ S ⁆ ⁅ A ⁆ ⁅ A ⁆̣ ▹ ∅ ⊢ put (put 𝔞 𝔟) 𝔠 ≋ₐ put 𝔞 𝔟 open EqLogic _▹_⊢_≋ₐ_ open ≋-Reasoning
{ "alphanum_fraction": 0.5969062784, "avg_line_length": 21.98, "ext": "agda", "hexsha": "02ca423ec451c0c6853f97b1ebe88254af51a4b4", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "out/Lens/Equality.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "out/Lens/Equality.agda", "max_line_length": 99, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "out/Lens/Equality.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 482, "size": 1099 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature module Fragment.Algebra.Homomorphism (Σ : Signature) where open import Fragment.Algebra.Homomorphism.Base Σ public open import Fragment.Algebra.Homomorphism.Definitions Σ public open import Fragment.Algebra.Homomorphism.Properties Σ public open import Fragment.Algebra.Homomorphism.Setoid Σ public open import Fragment.Algebra.Homomorphism.Equivalence Σ public
{ "alphanum_fraction": 0.8252212389, "avg_line_length": 37.6666666667, "ext": "agda", "hexsha": "5f50267ccced34600b2a5575aee71fd0a143bcd4", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Algebra/Homomorphism.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Algebra/Homomorphism.agda", "max_line_length": 62, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Algebra/Homomorphism.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 110, "size": 452 }
module sv20.exam1 where open import Data.Product using (∃-syntax) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Function.Base using (_∘_) record _⇔_ (A B : Set) : Set where field to : A → B from : B → A -- An idiom that makes things slightly more readable (sometimes) case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B case x of f = f x -- Exam starts from here: -- 1. first : ∀ {Object : Set} {P Q : Object → Set} → (∃[ x ] (P x ⊎ Q x)) ⇔ (∃[ x ] (P x) ⊎ ∃[ x ] (Q x)) -- We prove each side separately of the bijection separately. If we are able to -- prove both ways, we will have proved the bijection first = record { to = to ; from = from } where -- First, we prove that (∃[ x ] (P x ⊎ Q x)) → (∃[ x ] (P x) ⊎ ∃[ x ] (Q x)) to : ∀ {Object : Set} {P Q : Object → Set} → (∃[ x ] (P x ⊎ Q x)) → (∃[ x ] (P x) ⊎ ∃[ x ] (Q x)) -- Proof --to ⟨ x , inj₁ px ⟩ = inj₁ ⟨ x , px ⟩ --to ⟨ x , inj₂ qx ⟩ = inj₂ ⟨ x , qx ⟩ -- -- Proof explained: to ∃x-px⊎qx = let ⟨ x , px⊎qx ⟩ = ∃x-px⊎qx -- From ∃[ x ] (P x ⊎ Q x) we find an element x that fullfills (P x ⊎ Q x) in case px⊎qx of -- P x ⊎ Q x indicates two possible cases, either λ { (inj₁ px) → inj₁ ⟨ x , px ⟩ -- P x is true, and so ∃[ x ] (P x) ; (inj₂ qx) → inj₂ ⟨ x , qx ⟩ -- or, Q x is true, and so ∃[ x ] (Q x) } -- Now, we prove the inverse (∃[ x ] (P x) ⊎ ∃[ x ] (Q x)) → (∃[ x ] (P x ⊎ Q x)) from : ∀ {Object : Set} {P Q : Object → Set} → (∃[ x ] (P x) ⊎ ∃[ x ] (Q x)) → (∃[ x ] (P x ⊎ Q x)) -- Proof --from (inj₁ ⟨ x , px ⟩) = ⟨ x , inj₁ px ⟩ --from (inj₂ ⟨ x , qx ⟩) = ⟨ x , inj₂ qx ⟩ -- -- Proof explained: -- There are two possible properties that get fulfilled, either from (inj₁ ⟨ x , px ⟩) = ⟨ x , inj₁ px ⟩ -- ∃[ x ] (P x) gets fulfilled from (inj₂ ⟨ x , qx ⟩) = ⟨ x , inj₂ qx ⟩ -- or, ∃[ x ] (Q x) gets fulfilled -- 2. second : ∀ {Object : Set} {P Q : Object → Set} {_R_ : Object → Object → Set} → ∃[ x ] (P x) → ∃[ x ] (Q x) → (∀ x → P x → ∀ y → Q y → x R y) --------------------------------- → ∃[ x ] ∃[ y ] (x R y) --Proof: --second ⟨ x₁ , px₁ ⟩ ⟨ x₂ , qx₂ ⟩ ∀x→px→∀y→qy→xry = ⟨ x₁ , ⟨ x₂ , ∀x→px→∀y→qy→xry x₁ px₁ x₂ qx₂ ⟩ ⟩ -- --Proof explained: second ∃x-px ∃x-qx ∀x→px→∀y→qy→xry = let ⟨ x₁ , px₁ ⟩ = ∃x-px -- If we have a value from ∃[ x ] (P x), we can get an x₁ that fulfills P ⟨ x₂ , qx₂ ⟩ = ∃x-qx -- and there is a value x₂ that fulfills Q px→∀y→qy→xry = ∀x→px→∀y→qy→xry x₁ -- For all x it is true that (P x → ∀ y → Q y → x R y), including x₁ ∀y→qy→xry = px→∀y→qy→xry px₁ -- P is fulfilled by x₁ xry = ∀y→qy→xry x₂ qx₂ -- In a similar way, x₂ is a value that fulfills Qy, so we can instanciate (∀ y → Q y → x₁ R y) into (x₁ R x₂) in ⟨ x₁ , ⟨ x₂ , xry ⟩ ⟩ -- So, we know there is an element x₁ and an element x₂ for which x₁ R x₂ is true
{ "alphanum_fraction": 0.4882075472, "avg_line_length": 39.5733333333, "ext": "agda", "hexsha": "dc97001b86c6b4f57f2db9216b285a9d91c5c66b", "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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "helq/old_code", "max_forks_repo_path": "proglangs-learning/Agda/sv20/exam1.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z", "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "helq/old_code", "max_issues_repo_path": "proglangs-learning/Agda/sv20/exam1.agda", "max_line_length": 150, "max_stars_count": null, "max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "helq/old_code", "max_stars_repo_path": "proglangs-learning/Agda/sv20/exam1.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1266, "size": 2968 }
{-# OPTIONS --without-K --safe #-} -- https://personal.cis.strath.ac.uk/conor.mcbride/pub/DepRep/DepRep.pdf module Experiment.Outrageous.#02 where data Zero : Set where magic : Zero → (X : Set) → X magic () record 𝟏 : Set where constructor void data 𝟐 : Set where tt : 𝟐 ff : 𝟐 If : 𝟐 → Set → Set → Set If tt T F = T If ff T F = F if : (b : 𝟐) → (P : 𝟐 → Set) → P tt → P ff → P b if tt P t f = t if ff P t f = f data ℕ : Set where ze : ℕ su : ℕ → ℕ rec : (n : ℕ) → (P : ℕ → Set) → P ze → ((n : ℕ) → P n → P (su n)) → P n rec ze P z s = z rec (su n) P z s = s n (rec n P z s) record Σ (S : Set) (T : S → Set) : Set where constructor _,_ field fst : S snd : T fst
{ "alphanum_fraction": 0.5412445731, "avg_line_length": 21.59375, "ext": "agda", "hexsha": "8cb8a964e7edb1cbf43b7b841822cfede5bb5a3d", "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/Outrageous/#02.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/Outrageous/#02.agda", "max_line_length": 72, "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/Outrageous/#02.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": 292, "size": 691 }
{-# OPTIONS --without-K --safe #-} -- Monadic Adjunctions -- https://ncatlab.org/nlab/show/monadic+adjunction module Categories.Adjoint.Monadic where open import Level open import Categories.Adjoint open import Categories.Adjoint.Properties open import Categories.Category open import Categories.Category.Equivalence open import Categories.Functor open import Categories.Monad open import Categories.Category.Construction.EilenbergMoore open import Categories.Category.Construction.Properties.EilenbergMoore private variable o ℓ e : Level 𝒞 𝒟 : Category o ℓ e -- An adjunction is monadic if the adjunction "comes from" the induced monad in some sense. record IsMonadicAdjunction {L : Functor 𝒞 𝒟} {R : Functor 𝒟 𝒞} (adjoint : L ⊣ R) : Set (levelOfTerm 𝒞 ⊔ levelOfTerm 𝒟) where private T : Monad 𝒞 T = adjoint⇒monad adjoint field Comparison⁻¹ : Functor (EilenbergMoore T) 𝒟 comparison-equiv : WeakInverse (ComparisonF adjoint) Comparison⁻¹
{ "alphanum_fraction": 0.7674180328, "avg_line_length": 29.5757575758, "ext": "agda", "hexsha": "a86a01319a976c46b642c6cdd7b115e23cd960bb", "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/Monadic.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/Monadic.agda", "max_line_length": 124, "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/Monadic.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": 277, "size": 976 }
open import Agda.Builtin.Nat open import Agda.Builtin.FromNat open import Agda.Builtin.FromNeg open import Agda.Builtin.FromString open import Agda.Builtin.String open import Agda.Builtin.Unit open import Agda.Builtin.List open import Agda.Builtin.Char open import Agda.Builtin.Int instance NumberNat : Number Nat Number.Constraint NumberNat _ = ⊤ Number.fromNat NumberNat n = n StringIsString : IsString String IsString.Constraint StringIsString _ = ⊤ IsString.fromString StringIsString s = s ListIsString : IsString (List Char) IsString.Constraint ListIsString _ = ⊤ IsString.fromString ListIsString s = primStringToList s NegativeInt : Negative Int Negative.Constraint NegativeInt _ = ⊤ Negative.fromNeg NegativeInt zero = pos 0 Negative.fromNeg NegativeInt (suc n) = negsuc n abs : Int → Nat abs (pos n) = n abs (negsuc n) = suc n postulate _+Z_ : Int → Int → Int append : ∀ {a} {A : Set a} → List A → List A → List A append [] ys = ys append (x ∷ xs) ys = x ∷ append xs ys -- no paren give1 : Nat give1 = suc {!4!} -- paren give2 : Nat give2 = suc {!fromNat 4!} -- no paren give3 : List Char give3 = append "foo" {!"bar"!} -- paren give4 : List Char give4 = append "foo" {!fromString "bar"!} -- no paren give5 : Nat give5 = abs {!-4!} -- paren give6 : Nat give6 = abs {!fromNeg 4!} -- 4 + ? refine1 : Nat refine1 = {!_+_ 4!} -- fromNat 4 + ? refine2 : Nat refine2 = {!_+_ (fromNat 4)!} -- append "foo" ? refine3 : List Char refine3 = {!append "foo"!} -- append (fromString "foo") ? refine4 : List Char refine4 = {!append (fromString "foo")!} -- -4 +Z ? refine5 : Int refine5 = {!-4 +Z_!} -- fromNeg 4 +Z ? refine6 : Int refine6 = {!fromNeg 4 +Z_!} postulate P : Nat → Int → List Char → Set -- No fromXs in the goal goal : P 4 -5 "6" goal = {!!}
{ "alphanum_fraction": 0.6705555556, "avg_line_length": 19.1489361702, "ext": "agda", "hexsha": "5a1bfd20f23aaed289400e121c494d0fa56bdc84", "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/Issue2565.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/Issue2565.agda", "max_line_length": 57, "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/Issue2565.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": 616, "size": 1800 }
module _ where module _ (A : Set) where postulate F : Set₁ → Set {-# POLARITY F ++ #-} data D : Set where d : F D Set → D
{ "alphanum_fraction": 0.5441176471, "avg_line_length": 11.3333333333, "ext": "agda", "hexsha": "628ce87102ee7290413e8c67bf81c77e5d0b84b8", "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/Polarity-pragma-in-local-module.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/Polarity-pragma-in-local-module.agda", "max_line_length": 24, "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/Polarity-pragma-in-local-module.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": 49, "size": 136 }
-- {-# OPTIONS -v interaction.give:30 -v 10 #-} -- {-# OPTIONS -v tc.conv.irr:20 #-} module GiveInSpiteOfUnsolvedIrr where postulate .irrAxiom : ∀ {a}{A : Set a} → .A → A {-# BUILTIN IRRAXIOM irrAxiom #-} postulate _≡_ : {A : Set} → A → A → Set funExt : ∀ {A : Set}{B : A → Set}{f g : (x : A) → B x} → (∀ x → f x ≡ g x) → f ≡ g record MC (M : Set) (op : M → M → M) : Set where field elem : M fun : M → M .match : fun ≡ op elem unitM : ∀ {M : Set} {op : M → M → M} → MC M op unitM {M = M} = record { elem = {!!} ; fun = λ x → x ; match = {!funExt ?!} -- try give here } {- No variable of type {M : Set} {.op : M → M → M} → (λ x → x) ≡ .op ?0 was found in scope. -} -- This declaration needs to stay to trigger the error! compM : ∀ {M : Set} {op : M → M → M} → MC M op → MC M op → MC M op compM = {!!}
{ "alphanum_fraction": 0.4946871311, "avg_line_length": 22.8918918919, "ext": "agda", "hexsha": "2c3c63da6c23397a6fea165d7e3d57db1fbd177b", "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/interaction/GiveInSpiteOfUnsolvedIrr.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/interaction/GiveInSpiteOfUnsolvedIrr.agda", "max_line_length": 66, "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/interaction/GiveInSpiteOfUnsolvedIrr.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 354, "size": 847 }
-- Andreas, 2017-01-12, issue #2386 open import Agda.Primitive data _≡_ {a b} {A : Set (a ⊔ b)} : (x y : A) → Set where refl : (x : A) → x ≡ x {-# BUILTIN EQUALITY _≡_ #-} -- Should be accepted -- The type of primTrustMe has to match the flavor of EQUALITY primitive primTrustMe : ∀ {a b}{A : Set _} {x y : A} → x ≡ y testTM : ∀{A : Set} {a : A} → primTrustMe {x = a} {y = a} ≡ refl _ testTM = refl _ -- Testing rewrite subst : ∀{ℓ}{A : Set ℓ} {P : A → Set}{a b : A} → _≡_ {a = ℓ} {b = ℓ} a b → P a → P b subst eq p rewrite eq = p
{ "alphanum_fraction": 0.5535055351, "avg_line_length": 23.5652173913, "ext": "agda", "hexsha": "abf6224980cca2e436d1516d488beeb28c880a5c", "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/Issue2386BuiltinEqualityUniverseLub.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/Issue2386BuiltinEqualityUniverseLub.agda", "max_line_length": 84, "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/Issue2386BuiltinEqualityUniverseLub.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": 225, "size": 542 }
{-# OPTIONS --erased-cubical --safe #-} module Canon where open import Data.Fin using (Fin; #_; toℕ) open import Data.Integer using (ℤ; +_; -[1+_]; _-_) open import Data.List using (List; _∷_; []; map; concat; _++_; replicate; zip; length; take; drop) open import Data.Nat using (_*_; ℕ; suc; _+_) open import Data.Nat.DivMod using (_mod_) open import Data.Nat.Show using (show) open import Data.Product using (_,_; uncurry) open import Data.Sign renaming (+ to s+ ; - to s-) open import Data.Vec using (fromList; toList; Vec; _∷_; []) renaming (replicate to rep; zip to vzip; map to vmap; concat to vconcat; _++_ to _+v_) open import Function using (_∘_) open import Interval open import Note open import Pitch open import MidiEvent open import Util using (repeat) open import Transformation makeImitations : {k : ℕ} → List Note → Vec Opi k → Vec (List Note) k makeImitations subject [] = [] makeImitations subject (i ∷ is) = map (transposeNoteInterval i) subject ∷ makeImitations subject is addDelays : {k : ℕ} → Duration → Vec (List Note) k → Vec (List Note) k addDelays d lines = ads 0 lines where ads : {k : ℕ} → ℕ → Vec (List Note) k → Vec (List Note) k ads n [] = [] ads n (notes ∷ lines) = (rest n ∷ notes) ∷ ads (n + d) lines makeCanon : {k : ℕ} → List Note → ℕ → Duration → Vec Opi k → Vec (List Note) k makeCanon subject reps d = addDelays d ∘ vmap (repeat reps) ∘ makeImitations subject makeCanon2 : {k : ℕ} → List Note → Duration → Vec Opi k → Vec (List Note) k makeCanon2 subject d is = addDelays d (makeImitations ( repeat 2 subject ++ inversion subject ++ retrograde subject ++ (retrograde ∘ inversion) subject) is)
{ "alphanum_fraction": 0.647967945, "avg_line_length": 38.8222222222, "ext": "agda", "hexsha": "6cc2b460aa1568f2121af1ee3c1ea7f5eecc1f33", "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/Canon.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/Canon.agda", "max_line_length": 153, "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/Canon.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": 523, "size": 1747 }
{-# OPTIONS --without-K --safe #-} -- https://ncatlab.org/nlab/show/span -- The colimit of a functor from this category is a pushout in the target category. module Categories.Category.Instance.Span where open import Level open import Categories.Category open import Relation.Binary.PropositionalEquality data SpanObj : Set where center : SpanObj left : SpanObj right : SpanObj data SpanArr : SpanObj → SpanObj → Set where span-id : ∀ {o} → SpanArr o o span-arrˡ : SpanArr center left span-arrʳ : SpanArr center right span-compose : ∀ {x y z} → SpanArr y z → SpanArr x y → SpanArr x z span-compose span-id span-id = span-id span-compose span-id span-arrˡ = span-arrˡ span-compose span-id span-arrʳ = span-arrʳ span-compose span-arrˡ span-id = span-arrˡ span-compose span-arrʳ span-id = span-arrʳ Span : Category 0ℓ 0ℓ 0ℓ Span = record { Obj = SpanObj ; _⇒_ = SpanArr ; _≈_ = _≡_ ; id = span-id ; _∘_ = span-compose ; assoc = assoc ; sym-assoc = sym assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; identity² = λ {x} → identity² {x} ; equiv = isEquivalence ; ∘-resp-≈ = λ { refl refl → refl } } where assoc : ∀ {x y z w} {f : SpanArr x y} {g : SpanArr y z} {h : SpanArr z w} → span-compose (span-compose h g) f ≡ span-compose h (span-compose g f) assoc {_} {_} {_} {_} {span-id} {span-id} {span-id} = refl assoc {_} {_} {_} {_} {span-id} {span-id} {span-arrˡ} = refl assoc {_} {_} {_} {_} {span-id} {span-id} {span-arrʳ} = refl assoc {_} {_} {_} {_} {span-id} {span-arrˡ} {span-id} = refl assoc {_} {_} {_} {_} {span-id} {span-arrʳ} {span-id} = refl assoc {_} {_} {_} {_} {span-arrˡ} {span-id} {span-id} = refl assoc {_} {_} {_} {_} {span-arrʳ} {span-id} {span-id} = refl identityˡ : ∀ {x y} {f : SpanArr x y} → span-compose span-id f ≡ f identityˡ {_} {_} {span-id} = refl identityˡ {_} {_} {span-arrˡ} = refl identityˡ {_} {_} {span-arrʳ} = refl identityʳ : ∀ {x y} {f : SpanArr x y} → span-compose f span-id ≡ f identityʳ {_} {_} {span-id} = refl identityʳ {_} {_} {span-arrˡ} = refl identityʳ {_} {_} {span-arrʳ} = refl identity² : {x : SpanObj} → span-compose span-id span-id ≡ span-id identity² = refl
{ "alphanum_fraction": 0.5731454621, "avg_line_length": 36.5606060606, "ext": "agda", "hexsha": "76b75683a85dac29f79a2f30aa729be6737d5cd3", "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/Category/Instance/Span.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/Category/Instance/Span.agda", "max_line_length": 83, "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/Category/Instance/Span.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": 836, "size": 2413 }
module ctxt-types where open import cedille-types open import general-util open import syntax-util location : Set location = string × posinfo -- file path and starting position in the file -- file path and starting / ending position in file span-location = string × posinfo × posinfo -- missing locations missing-location : location missing-location = ("missing" , "missing") missing-span-location : span-location missing-span-location = ("missing" , "missing" , "missing") {- we will generally keep classifiers of variables in hnf in the ctxt, although we will not necessarily unfold recursive type definitions. -} defScope : Set defScope = 𝔹 pattern localScope = tt pattern globalScope = ff pattern concrete-datatype = globalScope pattern abstract-datatype = localScope defParams : Set defParams = maybe params data ctxt-info : Set where -- for defining a datatype -- datatype-def : defParams → (ind reg : kind) → ctrs → ctxt-info -- for defining a datatype constructor ctr-def : params → type → (ctrs-length ctr-index ctr-unerased-arrows : ℕ) → ctxt-info -- for declaring the type that proves a type is a datatype (X/Mu) -- mu-def : defParams → var → kind → ctxt-info -- for declaring a variable to have a given type (with no definition) term-decl : type → ctxt-info -- for defining a variable to equal a term with a given type -- maybe term, because datatype X/Mu and X/mu have params, etc... but no def term-def : defParams → opacity → maybe term → type → ctxt-info -- for untyped term definitions term-udef : defParams → opacity → term → ctxt-info -- for declaring a variable to have a given kind (with no definition) type-decl : kind → ctxt-info -- for defining a variable to equal a type with a given kind type-def : defParams → opacity → maybe type → kind → ctxt-info -- for defining a variable to equal a kind kind-def : params → kind → ctxt-info -- to rename a variable at any level to another rename-def : var → ctxt-info -- representing a declaration of a variable with no other information about it var-decl : ctxt-info sym-info : Set sym-info = ctxt-info × location data-info : Set data-info = params × kind × kind × ctrs × encoding-defs × encoded-defs is-term-level : ctxt-info → 𝔹 is-term-level (term-decl _) = tt is-term-level (term-def _ _ _ _) = tt is-term-level (term-udef _ _ _) = tt is-term-level (ctr-def _ _ _ _ _ ) = tt is-term-level _ = ff record ctxt : Set where constructor mk-ctxt field -- current module fields fn : string mn : string ps : params qual : qualif -- filename → module name × symbols declared in that module, syms : trie (string × 𝕃 string) -- module name → filename × params, mod-map : trie (string × params) -- file ID's for use in to-string.agda id-map : trie ℕ id-current : ℕ id-list : 𝕍 string id-current -- symbols → ctxt-info × location i : trie sym-info -- concrete/global datatypes μ : trie data-info -- abstract/local datatypes μ' : trie (var × args) -- Is/D map Is/μ : trie var -- encoding defs (needed to generate fmaps for some datatypes, like rose tree) μ~ : trie (𝕃 (var × tmtp)) -- highlighting datatypes (μ̲ = \Gm \_--) μᵤ : maybe encoding-defs -- most recent datatype declaration, for use in untyped μ['] μ̲ : stringset ctxt-binds-var : ctxt → var → 𝔹 ctxt-binds-var Γ x = trie-contains (ctxt.qual Γ) x || trie-contains (ctxt.i Γ) x ctxt-var-decl' : location → var → ctxt → ctxt ctxt-var-decl' loc v Γ = record Γ { qual = trie-insert (ctxt.qual Γ) v (v , []); i = trie-insert (ctxt.i Γ) v (var-decl , loc); μ = trie-remove (ctxt.μ Γ) v; μ' = trie-remove (ctxt.μ' Γ) v; Is/μ = trie-remove (ctxt.Is/μ Γ) v; μ~ = trie-remove (ctxt.μ~ Γ) v; μ̲ = trie-remove (ctxt.μ̲ Γ) v } ctxt-var-decl = ctxt-var-decl' missing-location ctxt-var-decl-loc : posinfo → var → ctxt → ctxt ctxt-var-decl-loc pi v Γ = ctxt-var-decl' (ctxt.fn Γ , pi) v Γ qualif-var : ctxt → var → var qualif-var Γ v with trie-lookup (ctxt.qual Γ) v ...| just (v' , _) = v' ...| nothing = v ctxt-get-current-mod : ctxt → string × string × params × qualif ctxt-get-current-mod (mk-ctxt fn mn ps qual _ _ _ _ _ _ _ _ _ _ _ _) = fn , mn , ps , qual
{ "alphanum_fraction": 0.6650372439, "avg_line_length": 29.6275862069, "ext": "agda", "hexsha": "e54924dccde4592cfa3a031bcf114d4db5585a5f", "lang": "Agda", "max_forks_count": 34, "max_forks_repo_forks_event_max_datetime": "2022-02-20T18:33:16.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-17T11:51:36.000Z", "max_forks_repo_head_hexsha": "75f72bf2e41ac4042efc3128fa9958d4cd69b947", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mudathirmahgoub/cedille", "max_forks_repo_path": "src/ctxt-types.agda", "max_issues_count": 123, "max_issues_repo_head_hexsha": "75f72bf2e41ac4042efc3128fa9958d4cd69b947", "max_issues_repo_issues_event_max_datetime": "2022-01-12T03:51:28.000Z", "max_issues_repo_issues_event_min_datetime": "2018-09-17T10:53:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mudathirmahgoub/cedille", "max_issues_repo_path": "src/ctxt-types.agda", "max_line_length": 90, "max_stars_count": 328, "max_stars_repo_head_hexsha": "75f72bf2e41ac4042efc3128fa9958d4cd69b947", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mudathirmahgoub/cedille", "max_stars_repo_path": "src/ctxt-types.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-26T10:33:07.000Z", "max_stars_repo_stars_event_min_datetime": "2018-09-14T20:06:09.000Z", "num_tokens": 1218, "size": 4296 }