hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
7cbc08283d4584e3c25a7b17e604da55b091fdfd
4,705
agda
Agda
theorems/cohomology/Sigma.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
theorems/cohomology/Sigma.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
theorems/cohomology/Sigma.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.CofiberSequence open import cohomology.Exactness open import cohomology.FunctionOver open import cohomology.SplitExactRight open import cohomology.Theory module cohomology.Sigma {i} (CT : CohomologyTheory i) where open CohomologyTheory CT open import cohomology.Functor CT open import cohomology.BaseIndependence CT {- Cⁿ(Σx:X.Y) = Cⁿ(⋁x:X.Y) × Cⁿ(X). The proof is by constructing a - splitting exact sequence 0 → Cⁿ(⋁x:X.Y) → Cⁿ(Σx:X.Y) → Cⁿ(X) - by observing that the map [select : x ↦ (x, snd Yₓ)] has a left inverse - and satisfies [Cofiber select == ⋁x:X.Y. -} module CofSelect (X : Ptd i) (Y : fst X → Ptd i) where select : fst X → fst (⊙Σ X Y) select x = (x , snd (Y x)) ⊙select : fst (X ⊙→ ⊙Σ X Y) ⊙select = (select , idp) ⊙Σbwin : fst (⊙Σ X Y ⊙→ ⊙BigWedge Y) ⊙Σbwin = (uncurry bwin , ! (bwglue (snd X))) eq : Cofiber select ≃ BigWedge Y eq = equiv Into.f Out.f into-out out-into where module Into = CofiberRec select {C = BigWedge Y} bwbase (uncurry bwin) bwglue module Out = BigWedgeRec {X = Y} {C = Cofiber select} (cfbase _) (curry (cfcod _)) (cfglue _) into-out : ∀ w → Into.f (Out.f w) == w into-out = BigWedge-elim idp (λ _ _ → idp) (↓-∘=idf-in Into.f Out.f ∘ λ x → ap (ap Into.f) (Out.glue-β x) ∙ Into.glue-β x) out-into : ∀ c → Out.f (Into.f c) == c out-into = Cofiber-elim select idp (λ _ → idp) (↓-∘=idf-in Out.f Into.f ∘ λ x → ap (ap Out.f) (Into.glue-β x) ∙ Out.glue-β x) ⊙path : ⊙Cof ⊙select == ⊙BigWedge Y ⊙path = ⊙ua eq idp cfcod-over : cfcod _ == uncurry bwin [ (λ U → fst (⊙Σ X Y) → fst U) ↓ ⊙path ] cfcod-over = ↓-cst2-in _ _ $ codomain-over-equiv _ _ ext-glue-cst : ext-glue {s = cofiber-span select} == cst (north _) ext-glue-cst = λ= $ Cofiber-elim _ idp (λ {(x , y) → ! (merid _ x)}) (↓-='-from-square ∘ λ x → ExtGlue.glue-β x ∙v⊡ tr-square (merid _ x) ⊡v∙ ! (ap-cst (north _) (cfglue _ x))) ext-over : ext-glue == cst (north _) [ (λ U → fst U → fst (⊙Susp X)) ↓ ⊙path ] ext-over = ↓-cst2-in _ _ $ ext-glue-cst ◃ domain-over-equiv _ _ module CΣ (n : ℤ) (X : Ptd i) (Y : fst X → Ptd i) where open CofSelect X Y private seq : HomSequence _ _ seq = C n (⊙Susp X) ⟨ cst-hom ⟩→ C n (⊙BigWedge Y) ⟨ CF-hom n ⊙Σbwin ⟩→ C n (⊙Σ X Y) ⟨ CF-hom n ⊙select ⟩→ C n X ⊣| eseq : is-exact-seq seq eseq = exact-build seq (transport (λ {(φ , ψ) → is-exact ψ φ}) (pair×= (CF-base-indep n _ _ _) (CF-base-indep n _ _ _ ∙ CF-cst n)) (transport {A = Σ _ (λ {(U , g , h) → (g (snd (⊙Σ X Y)) == snd U) × (h (snd U) == north _)})} (λ {((_ , g , h) , (p , q)) → is-exact (CF-hom n (h , q)) (CF-hom n (g , p))}) (pair= (pair= ⊙path (↓-×-in cfcod-over ext-over)) (↓-×-in (from-transp _ _ idp) (from-transp _ _ idp))) (transport {A = Σ _ (λ {(U , g) → g (cfbase _) == snd U})} (λ {((_ , g) , p) → is-exact (CF-hom n (g , p)) (CF-hom n (⊙cfcod ⊙select))}) (pair= (pair= (Cof².space-path ⊙select) (Cof².cfcod²-over ⊙select)) (from-transp _ _ idp)) (C-exact n (⊙cfcod ⊙select))))) (transport (λ φ → is-exact φ (CF-hom n ⊙select)) (CF-base-indep n _ _ _) (transport {A = Σ _ (λ {(U , g) → g (snd (⊙Σ X Y)) == snd U})} (λ {((_ , g) , p) → is-exact (CF-hom n (g , p)) (CF-hom n ⊙select)}) (pair= (pair= ⊙path cfcod-over) (from-transp _ _ idp)) (C-exact n ⊙select))) module SER = SplitExactRight (C-abelian n _) (CF-hom n ⊙Σbwin) (CF-hom n ⊙select) eseq (CF-hom n (⊙dfst Y)) (app= $ ap GroupHom.f $ CF-inverse n ⊙select (⊙dfst Y) (λ _ → idp)) path : C n (⊙Σ X Y) == C n (⊙BigWedge Y) ×ᴳ C n X path = SER.iso ⊙Σbwin-over : CF-hom n ⊙Σbwin == ×ᴳ-inl [ (λ G → GroupHom (C n (⊙BigWedge Y)) G) ↓ path ] ⊙Σbwin-over = SER.φ-over-iso ⊙select-over : CF-hom n ⊙select == ×ᴳ-snd {G = C n (⊙BigWedge Y)} [ (λ G → GroupHom G (C n X)) ↓ path ] ⊙select-over = SER.ψ-over-iso open CofSelect public using (select; ⊙select; ⊙Σbwin) module C⊔ (n : ℤ) (X Y : Ptd i) where private T : Sphere {i} 0 → Ptd i T (lift true) = X T (lift false) = Y path : C n (X ⊙⊔ Y) == C n (X ⊙∨ Y) ×ᴳ C n (⊙Sphere 0) path = ap (C n) (! (⊙ua (ΣBool-equiv-⊔ (fst ∘ T)) idp)) ∙ CΣ.path n (⊙Sphere 0) T ∙ ap (λ Z → C n Z ×ᴳ C n (⊙Sphere 0)) (BigWedge-Bool-⊙path T)
33.133803
79
0.520085
7cca2a2570c316f35e28dfd4aa39fa78dd9cbb07
1,205
agda
Agda
agda-stdlib/src/Category/Applicative.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Category/Applicative.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Category/Applicative.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Applicative functors ------------------------------------------------------------------------ -- Note that currently the applicative functor laws are not included -- here. {-# OPTIONS --without-K --safe #-} module Category.Applicative where open import Level using (Level; suc; _⊔_) open import Data.Unit open import Category.Applicative.Indexed private variable f : Level RawApplicative : (Set f → Set f) → Set (suc f) RawApplicative F = RawIApplicative {I = ⊤} λ _ _ → F module RawApplicative {F : Set f → Set f} (app : RawApplicative F) where open RawIApplicative app public RawApplicativeZero : (Set f → Set f) → Set _ RawApplicativeZero F = RawIApplicativeZero {I = ⊤} (λ _ _ → F) module RawApplicativeZero {F : Set f → Set f} (app : RawApplicativeZero F) where open RawIApplicativeZero app public RawAlternative : (Set f → Set f) → Set _ RawAlternative F = RawIAlternative {I = ⊤} (λ _ _ → F) module RawAlternative {F : Set f → Set f} (app : RawAlternative F) where open RawIAlternative app public
28.690476
72
0.585062
43f90834621158038b2cdc5be981972a1c81b03a
1,796
agda
Agda
Testing/PropEqTest.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
16
2015-02-09T15:43:38.000Z
2019-10-24T17:38:20.000Z
Testing/PropEqTest.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
4
2015-02-06T15:03:33.000Z
2015-05-28T14:48:03.000Z
Testing/PropEqTest.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
null
null
null
open import Prelude open import Relation.Binary.PropositionalEquality open import RW.Language.RTerm using (Name) open import RW.Strategy.PropEq open import RW.RW (≡-strat ∷ []) open import Data.Nat.Properties.Simple using (+-comm; +-right-identity; +-assoc) module PropEqTest where ++-assoc : ∀{a}{A : Set a}(xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs) ++-assoc [] ys zs = refl ++-assoc (x ∷ xs) ys zs = tactic (by (quote ++-assoc)) open ≡-Reasoning ++-assocH : ∀{a}{A : Set a}(xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs) ++-assocH [] ys zs = begin ([] ++ ys) ++ zs ≡⟨ refl ⟩ ys ++ zs ≡⟨ refl ⟩ [] ++ (ys ++ zs) ∎ ++-assocH {A = A} (x ∷ xs) ys zs = begin ((x ∷ xs) ++ ys) ++ zs ≡⟨ refl ⟩ x ∷ (xs ++ ys) ++ zs ≡⟨ refl ⟩ x ∷ ((xs ++ ys) ++ zs) ≡⟨ (tactic (by (quote ++-assocH))) ⟩ x ∷ (xs ++ (ys ++ zs)) ≡⟨ refl ⟩ (x ∷ xs) ++ (ys ++ zs) ∎ []-++-neutral : ∀{a}{A : Set a}(xs : List A) → xs ++ [] ≡ xs []-++-neutral [] = refl []-++-neutral (x ∷ xs) = tactic (by (quote []-++-neutral)) test1 : (x y : ℕ) → (x + y) + 0 ≡ y + (x + 0) test1 x y = begin (x + y) + 0 ≡⟨ (tactic (by+ acts)) ⟩ x + y ≡⟨ (tactic (by+ acts)) ⟩ y + x ≡⟨ (tactic (by+ acts)) ⟩ (y + x) + 0 ≡⟨ (tactic (by+ acts)) ⟩ y + (x + 0) ∎ where acts : List Name acts = quote +-right-identity ∷ quote +-assoc ∷ quote +-comm ∷ []
28.0625
73
0.377506
1905c814e5e165b69b2bdbda29609847a8d4746a
223
agda
Agda
test/Succeed/Issue3785.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3785.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3785.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --allow-unsolved-metas #-} open import Agda.Builtin.Unit open import Agda.Builtin.Equality postulate A : Set u₁ u₂ : ⊤ mutual X : (⊤ → ⊤) → A X = _ test : X (λ x → u₁) ≡ X (λ x → u₂) test = refl
13.9375
38
0.573991
fd3dcc9151992bb2dac18da12c2a8f620266c8d1
1,239
agda
Agda
test/Succeed/Issue2045.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Issue2045.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue2045.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2016-06-16 Issue #2045 -- Size solver should be called before checking extended lambda -- {-# OPTIONS -v tc.term.exlam:100 #-} open import Common.Size postulate anything : ∀{a}{A : Set a} → A data Exp : Size → Set where abs : ∀ i (t : Exp i) → Exp (↑ i) data Val : ∀ i (t : Exp i) → Set where valAbs : ∀ i (t : Exp i) → Val (↑ i) (abs i t) data Whnf i (t : Exp i) : Set where immed : (v : Val i t) → Whnf i t postulate Evaluate : ∀ i (t : Exp i) (P : (w : Whnf i t) → Set) → Set worksE : ∀ i (fa : Exp i) → Set worksE i fa = Evaluate i fa λ{ (immed (valAbs _ _)) → anything } works : ∀ i (fa : Exp i) → Set works i fa = Evaluate i fa aux where aux : Whnf i fa → Set aux (immed (valAbs _ _)) = anything test : ∀ i (fa : Exp i) → Set test i fa = Evaluate _ fa λ{ (immed (valAbs _ _)) → anything } -- Should work. -- WAS: -- extended lambda's implementation ".extendedlambda1" has type: -- (Whnf (_38 i fa) fa → Set) -- Cannot instantiate the metavariable _38 to solution (↑ i₁) since it -- contains the variable i₁ which is not in scope of the metavariable -- or irrelevant in the metavariable but relevant in the solution -- when checking that the pattern (valAbs _ _) has type -- (Val (_38 i fa) fa)
27.533333
70
0.626312
224ef37172d41422ef90824f55725ac7fbb1296f
11,551
agda
Agda
lib/types/Truncation.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/Truncation.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/Truncation.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.TLevel open import lib.types.Pointed open import lib.types.Pi open import lib.types.Sigma open import lib.NType2 module lib.types.Truncation where module _ {i} where private data #Trunc-aux (n : ℕ₋₂) (A : Type i) : Type i where #[_] : A → #Trunc-aux n A data #Trunc (n : ℕ₋₂) (A : Type i) : Type i where #trunc : #Trunc-aux n A → (Unit → Unit) → #Trunc n A Trunc : (n : ℕ₋₂) (A : Type i) → Type i Trunc = #Trunc [_] : {n : ℕ₋₂} {A : Type i} → A → Trunc n A [ a ] = #trunc #[ a ] _ postulate Trunc-level : {n : ℕ₋₂} {A : Type i} → has-level n (Trunc n A) module TruncElim {n : ℕ₋₂} {A : Type i} {j} {P : Trunc n A → Type j} (p : (x : Trunc n A) → has-level n (P x)) (d : (a : A) → P [ a ]) where f : Π (Trunc n A) P f = f-aux phantom where f-aux : Phantom p → Π (Trunc n A) P f-aux phantom (#trunc #[ a ] _) = d a open TruncElim public renaming (f to Trunc-elim) module TruncRec {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (p : has-level n B) (d : A → B) where private module M = TruncElim (λ x → p) d f : Trunc n A → B f = M.f open TruncRec public renaming (f to Trunc-rec) module TruncRecType {i j} {n : ℕ₋₂} {A : Type i} (d : A → n -Type j) where open TruncRec (n -Type-level j) d public flattening-Trunc : Σ (Trunc (S n) A) (fst ∘ f) ≃ Trunc (S n) (Σ A (fst ∘ d)) flattening-Trunc = equiv to from to-from from-to where to-aux : (x : Trunc (S n) A) → (fst (f x) → Trunc (S n) (Σ A (fst ∘ d))) to-aux = Trunc-elim (λ _ → →-level Trunc-level) (λ a b → [ (a , b) ]) to : Σ (Trunc (S n) A) (fst ∘ f) → Trunc (S n) (Σ A (fst ∘ d)) to (x , y) = to-aux x y from-aux : Σ A (fst ∘ d) → Σ (Trunc (S n) A) (fst ∘ f) from-aux (a , b) = ([ a ] , b) from : Trunc (S n) (Σ A (fst ∘ d)) → Σ (Trunc (S n) A) (fst ∘ f) from = Trunc-rec (Σ-level Trunc-level (λ x → raise-level _ (snd (f x)))) from-aux to-from : (x : Trunc (S n) (Σ A (fst ∘ d))) → to (from x) == x to-from = Trunc-elim (λ _ → =-preserves-level (S n) Trunc-level) (λ _ → idp) from-to-aux : (a : Trunc (S n) A) (b : fst (f a)) → from (to-aux a b) == (a , b) from-to-aux = Trunc-elim (λ _ → Π-level (λ _ → =-preserves-level (S n) (Σ-level Trunc-level (λ x → raise-level _ (snd (f x)))))) (λ a b → idp) from-to : (x : Σ (Trunc (S n) A) (fst ∘ f)) → from (to x) == x from-to (a , b) = from-to-aux a b ⊙Trunc : ∀ {i} → ℕ₋₂ → Ptd i → Ptd i ⊙Trunc n (A , a) = ⊙[ Trunc n A , [ a ] ] module _ {i} {n : ℕ₋₂} {A : Type i} where Trunc= : (a b : Trunc (S n) A) → n -Type i Trunc= = Trunc-elim (λ _ → →-level (n -Type-level i)) (λ a → Trunc-elim (λ _ → n -Type-level i) ((λ b → (Trunc n (a == b) , Trunc-level)))) Trunc=-equiv : (a b : Trunc (S n) A) → (a == b) ≃ fst (Trunc= a b) Trunc=-equiv a b = equiv (to a b) (from a b) (to-from a b) (from-to a b) where to-aux : (a : Trunc (S n) A) → fst (Trunc= a a) to-aux = Trunc-elim (λ x → raise-level _ (snd (Trunc= x x))) (λ a → [ idp ]) to : (a b : Trunc (S n) A) → (a == b → fst (Trunc= a b)) to a .a idp = to-aux a from-aux : (a b : A) → a == b → [ a ] == [ b ] :> Trunc (S n) A from-aux a .a idp = idp from : (a b : Trunc (S n) A) → (fst (Trunc= a b) → a == b) from = Trunc-elim (λ _ → Π-level (λ _ → →-level (=-preserves-level (S n) Trunc-level))) (λ a → Trunc-elim (λ _ → →-level (=-preserves-level _ Trunc-level)) (λ b → Trunc-rec (Trunc-level {n = S n} _ _) (from-aux a b))) to-from-aux : (a b : A) → (p : a == b) → to _ _ (from-aux a b p) == [ p ] to-from-aux a .a idp = idp to-from : (a b : Trunc (S n) A) (x : fst (Trunc= a b)) → to a b (from a b x) == x to-from = Trunc-elim (λ x → Π-level (λ y → Π-level (λ _ → =-preserves-level _ (raise-level _ (snd (Trunc= x y)))))) (λ a → Trunc-elim (λ x → Π-level (λ _ → raise-level _ (=-preserves-level _ (snd (Trunc= [ a ] x))))) (λ b → Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (to-from-aux a b))) from-to-aux : (a : Trunc (S n) A) → from a a (to-aux a) == idp from-to-aux = Trunc-elim (λ x → =-preserves-level _ (=-preserves-level _ Trunc-level)) (λ _ → idp) from-to : (a b : Trunc (S n) A) (p : a == b) → from a b (to a b p) == p from-to a .a idp = from-to-aux a Trunc=-path : (a b : Trunc (S n) A) → (a == b) == fst (Trunc= a b) Trunc=-path a b = ua (Trunc=-equiv a b) {- Universal property -} abstract Trunc-rec-is-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j) (p : has-level n B) → is-equiv (Trunc-rec p :> ((A → B) → (Trunc n A → B))) Trunc-rec-is-equiv n A B p = is-eq _ (λ f → f ∘ [_]) (λ f → λ= (Trunc-elim (λ _ → =-preserves-level _ p) (λ a → idp))) (λ f → idp) Trunc-preserves-level : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂) → has-level n A → has-level n (Trunc m A) Trunc-preserves-level {n = ⟨-2⟩} _ (a₀ , p) = ([ a₀ ] , Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ a → ap [_] (p a))) Trunc-preserves-level ⟨-2⟩ _ = contr-has-level Trunc-level Trunc-preserves-level {n = (S n)} (S m) c = λ t₁ t₂ → Trunc-elim (λ s₁ → prop-has-level-S {A = has-level n (s₁ == t₂)} has-level-is-prop) (λ a₁ → Trunc-elim (λ s₂ → prop-has-level-S {A = has-level n ([ a₁ ] == s₂)} has-level-is-prop) (λ a₂ → equiv-preserves-level ((Trunc=-equiv [ a₁ ] [ a₂ ])⁻¹) (Trunc-preserves-level {n = n} m (c a₁ a₂))) t₂) t₁ {- an n-type is equivalent to its n-truncation -} unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (A : Type i) → has-level n A → Trunc n A ≃ A unTrunc-equiv A nA = equiv f [_] (λ _ → idp) g-f where f = Trunc-rec nA (idf _) g-f = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ _ → idp) -- Equivalence associated to the universal property Trunc-extend-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j) (p : has-level n B) → (A → B) ≃ (Trunc n A → B) Trunc-extend-equiv n A B p = (Trunc-rec p , Trunc-rec-is-equiv n A B p) Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → ((A → B) → (Trunc n A → Trunc n B)) Trunc-fmap f = Trunc-rec Trunc-level ([_] ∘ f) Trunc-fmap2 : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k} → ((A → B → C) → (Trunc n A → Trunc n B → Trunc n C)) Trunc-fmap2 f = Trunc-rec (Π-level (λ _ → Trunc-level)) (λ a → Trunc-fmap (f a)) Trunc-fpmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {f g : A → B} (h : (a : A) → f a == g a) → ((a : Trunc n A) → Trunc-fmap f a == Trunc-fmap g a) Trunc-fpmap h = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (ap [_] ∘ h) Trunc-fmap-∘ : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k} → (g : B → C) → (f : A → B) → ∀ x → Trunc-fmap {n = n} g (Trunc-fmap f x) == Trunc-fmap (g ∘ f) x Trunc-fmap-∘ g f = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ _ → idp) {- Pushing concatentation through Trunc= -} module _ {i} {n : ℕ₋₂} {A : Type i} where {- concatenation in Trunc= -} Trunc=-∙ : {ta tb tc : Trunc (S n) A} → fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc) Trunc=-∙ {ta = ta} {tb = tb} {tc = tc} = Trunc-elim {P = λ ta → C ta tb tc} (λ ta → level ta tb tc) (λ a → Trunc-elim {P = λ tb → C [ a ] tb tc} (λ tb → level [ a ] tb tc) (λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc} (λ tc → level [ a ] [ b ] tc) (λ c → Trunc-fmap2 _∙_) tc) tb) ta where C : (ta tb tc : Trunc (S n) A) → Type i C ta tb tc = fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc) level : (ta tb tc : Trunc (S n) A) → has-level (S n) (C ta tb tc) level ta tb tc = raise-level _ $ Π-level (λ _ → Π-level (λ _ → snd (Trunc= ta tc))) Trunc=-∙-comm : {x y z : Trunc (S n) A } (p : x == y) (q : y == z) → –> (Trunc=-equiv x z) (p ∙ q) == Trunc=-∙ {ta = x} (–> (Trunc=-equiv x y) p) (–> (Trunc=-equiv y z) q) Trunc=-∙-comm {x = x} idp idp = Trunc-elim {P = λ x → –> (Trunc=-equiv x x) idp == Trunc=-∙ {ta = x} (–> (Trunc=-equiv x x) idp) (–> (Trunc=-equiv x x) idp)} (λ x → raise-level _ $ =-preserves-level _ (snd (Trunc= x x))) (λ a → idp) x {- Truncation preserves equivalences - more convenient than univalence+ap - when we need to know the forward or backward function explicitly -} module _ {i j} (n : ℕ₋₂) {A : Type i} {B : Type j} where equiv-Trunc : A ≃ B → Trunc n A ≃ Trunc n B equiv-Trunc e = equiv f g f-g g-f where f = Trunc-fmap (–> e) g = Trunc-fmap (<– e) f-g : ∀ tb → f (g tb) == tb f-g = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (ap [_] ∘ <–-inv-r e) g-f : ∀ ta → g (f ta) == ta g-f = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (ap [_] ∘ <–-inv-l e) is-equiv-Trunc : (f : A → B) → is-equiv f → is-equiv (Trunc-fmap {n = n} f) is-equiv-Trunc f ie = snd (equiv-Trunc (f , ie)) transport-Trunc : ∀ {i j} {A : Type i} {n : ℕ₋₂} (P : A → Type j) {x y : A} (p : x == y) (b : P x) → transport (Trunc n ∘ P) p [ b ] == [ transport P p b ] transport-Trunc _ idp _ = idp fuse-Trunc : ∀ {i} (A : Type i) (m n : ℕ₋₂) → Trunc m (Trunc n A) ≃ Trunc (minT m n) A fuse-Trunc A m n = equiv (Trunc-rec (raise-level-≤T (minT≤l m n) Trunc-level) (Trunc-rec (raise-level-≤T (minT≤r m n) Trunc-level) [_])) (Trunc-rec l ([_] ∘ [_])) (Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ _ → idp)) (Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (Trunc-elim (λ _ → =-preserves-level _ (Trunc-preserves-level _ Trunc-level)) (λ _ → idp))) where l : has-level (minT m n) (Trunc m (Trunc n A)) l with (minT-out m n) l | inl p = transport (λ k → has-level k (Trunc m (Trunc n A))) (! p) Trunc-level l | inr q = Trunc-preserves-level _ (transport (λ k → has-level k (Trunc n A)) (! q) Trunc-level) {- Truncating a binary product is equivalent to truncating its components -} Trunc-×-equiv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j) → Trunc n (A × B) ≃ Trunc n A × Trunc n B Trunc-×-equiv n A B = equiv f g f-g g-f where f : Trunc n (A × B) → Trunc n A × Trunc n B f = Trunc-rec (×-level Trunc-level Trunc-level) (λ {(a , b) → [ a ] , [ b ]}) g : Trunc n A × Trunc n B → Trunc n (A × B) g (ta , tb) = Trunc-rec Trunc-level (λ a → Trunc-rec Trunc-level (λ b → [ a , b ]) tb) ta f-g : ∀ p → f (g p) == p f-g (ta , tb) = Trunc-elim {P = λ ta → f (g (ta , tb)) == (ta , tb)} (λ _ → =-preserves-level _ (×-level Trunc-level Trunc-level)) (λ a → Trunc-elim {P = λ tb → f (g ([ a ] , tb)) == ([ a ] , tb)} (λ _ → =-preserves-level _ (×-level Trunc-level Trunc-level)) (λ b → idp) tb) ta g-f : ∀ tab → g (f tab) == tab g-f = Trunc-elim {P = λ tab → g (f tab) == tab} (λ _ → =-preserves-level _ Trunc-level) (λ ab → idp) Trunc-×-path : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j) → Trunc n (A × B) == Trunc n A × Trunc n B Trunc-×-path n A B = ua (Trunc-×-equiv n A B)
37.625407
132
0.495974
7ce7098398db217176e93b7fcf98f7b9068cbe60
5,103
agda
Agda
Parametric/Change/Evaluation.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
10
2015-03-04T06:09:20.000Z
2019-07-19T07:06:59.000Z
Parametric/Change/Evaluation.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
6
2015-07-01T18:09:31.000Z
2017-05-04T13:53:59.000Z
Parametric/Change/Evaluation.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
1
2016-02-18T12:26:44.000Z
2016-02-18T12:26:44.000Z
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Connecting Parametric.Change.Term and Parametric.Change.Value. ------------------------------------------------------------------------ import Parametric.Syntax.Type as Type import Parametric.Syntax.Term as Term import Parametric.Denotation.Value as Value import Parametric.Denotation.Evaluation as Evaluation import Parametric.Change.Type as ChangeType import Parametric.Change.Term as ChangeTerm import Parametric.Change.Value as ChangeValue module Parametric.Change.Evaluation {Base : Type.Structure} {Const : Term.Structure Base} (⟦_⟧Base : Value.Structure Base) (⟦_⟧Const : Evaluation.Structure Const ⟦_⟧Base) (ΔBase : ChangeType.Structure Base) (apply-base : ChangeTerm.ApplyStructure Const ΔBase) (diff-base : ChangeTerm.DiffStructure Const ΔBase) (nil-base : ChangeTerm.NilStructure Const ΔBase) (⟦apply-base⟧ : ChangeValue.ApplyStructure Const ⟦_⟧Base ΔBase) (⟦diff-base⟧ : ChangeValue.DiffStructure Const ⟦_⟧Base ΔBase) (⟦nil-base⟧ : ChangeValue.NilStructure Const ⟦_⟧Base ΔBase) where open Type.Structure Base open Term.Structure Base Const open Value.Structure Base ⟦_⟧Base open Evaluation.Structure Const ⟦_⟧Base ⟦_⟧Const open ChangeType.Structure Base ΔBase open ChangeTerm.Structure Const ΔBase apply-base diff-base nil-base open ChangeValue.Structure Const ⟦_⟧Base ΔBase ⟦apply-base⟧ ⟦diff-base⟧ ⟦nil-base⟧ open import Relation.Binary.PropositionalEquality open import Base.Denotation.Notation open import Postulate.Extensionality -- Extension point 1: Relating ⊕ and its value on base types ApplyStructure : Set ApplyStructure = ∀ ι {Γ} → {t : Term Γ (base ι)} {Δt : Term Γ (ΔType (base ι))} {ρ : ⟦ Γ ⟧} → ⟦ t ⟧ ρ ⟦⊕₍ base ι ₎⟧ ⟦ Δt ⟧ ρ ≡ ⟦ t ⊕₍ base ι ₎ Δt ⟧ ρ -- Extension point 2: Relating ⊝ and its value on base types DiffStructure : Set DiffStructure = ∀ ι {Γ} → {s : Term Γ (base ι)} {t : Term Γ (base ι)} {ρ : ⟦ Γ ⟧} → ⟦ s ⟧ ρ ⟦⊝₍ base ι ₎⟧ ⟦ t ⟧ ρ ≡ ⟦ s ⊝₍ base ι ₎ t ⟧ ρ -- Extension point 3: Relating nil-term and its value on base types NilStructure : Set NilStructure = ∀ ι {Γ} → {t : Term Γ (base ι)} {ρ : ⟦ Γ ⟧} → ⟦nil₍ base ι ₎⟧ (⟦ t ⟧ ρ) ≡ ⟦ onil₍ base ι ₎ t ⟧ ρ module Structure (meaning-⊕-base : ApplyStructure) (meaning-⊝-base : DiffStructure) (meaning-onil-base : NilStructure) where -- unique names with unambiguous types -- to help type inference figure things out private module Disambiguation where infixr 9 _⋆_ _⋆_ : Type → Context → Context _⋆_ = _•_ -- We provide: Relating ⊕ and ⊝ and their values on arbitrary types. meaning-⊕ : ∀ {τ Γ} {t : Term Γ τ} {Δt : Term Γ (ΔType τ)} {ρ : ⟦ Γ ⟧} → ⟦ t ⟧ ρ ⟦⊕₍ τ ₎⟧ ⟦ Δt ⟧ ρ ≡ ⟦ t ⊕₍ τ ₎ Δt ⟧ ρ meaning-⊝ : ∀ {τ Γ} {s : Term Γ τ} {t : Term Γ τ} {ρ : ⟦ Γ ⟧} → ⟦ s ⟧ ρ ⟦⊝₍ τ ₎⟧ ⟦ t ⟧ ρ ≡ ⟦ s ⊝₍ τ ₎ t ⟧ ρ meaning-onil : ∀ {τ Γ} {t : Term Γ τ} {ρ : ⟦ Γ ⟧} → ⟦nil₍ τ ₎⟧ (⟦ t ⟧ ρ) ≡ ⟦ onil₍ τ ₎ t ⟧ ρ meaning-⊕ {base ι} {Γ} {τ} {Δt} {ρ} = meaning-⊕-base ι {Γ} {τ} {Δt} {ρ} meaning-⊕ {σ ⇒ τ} {Γ} {t} {Δt} {ρ} = ext (λ v → let Γ′ = σ ⋆ (σ ⇒ τ) ⋆ ΔType (σ ⇒ τ) ⋆ Γ ρ′ : ⟦ Γ′ ⟧ ρ′ = v • (⟦ t ⟧ ρ) • (⟦ Δt ⟧ ρ) • ρ x : Term Γ′ σ x = var this f : Term Γ′ (σ ⇒ τ) f = var (that this) Δf : Term Γ′ (ΔType (σ ⇒ τ)) Δf = var (that (that this)) y = app f x Δy = app (app Δf x) (onil x) in begin ⟦ t ⟧ ρ v ⟦⊕₍ τ ₎⟧ ⟦ Δt ⟧ ρ v (⟦nil₍ σ ₎⟧ v) ≡⟨ cong (λ hole → ⟦ t ⟧ ρ v ⟦⊕₍ τ ₎⟧ ⟦ Δt ⟧ ρ v hole) (meaning-onil {t = x} {ρ′}) ⟩ ⟦ t ⟧ ρ v ⟦⊕₍ τ ₎⟧ ⟦ Δt ⟧ ρ v (⟦ onil x ⟧ ρ′) ≡⟨ meaning-⊕ {t = y} {Δt = Δy} {ρ′} ⟩ ⟦ y ⊕₍ τ ₎ Δy ⟧ ρ′ ∎) where open ≡-Reasoning open Disambiguation meaning-⊝ {base ι} {Γ} {s} {t} {ρ} = meaning-⊝-base ι {Γ} {s} {t} {ρ} meaning-⊝ {σ ⇒ τ} {Γ} {s} {t} {ρ} = ext (λ v → ext (λ Δv → let Γ′ = ΔType σ ⋆ σ ⋆ (σ ⇒ τ) ⋆ (σ ⇒ τ) ⋆ Γ ρ′ : ⟦ Γ′ ⟧Context ρ′ = Δv • v • ⟦ t ⟧Term ρ • ⟦ s ⟧Term ρ • ρ Δx : Term Γ′ (ΔType σ) Δx = var this x : Term Γ′ σ x = var (that this) f : Term Γ′ (σ ⇒ τ) f = var (that (that this)) g : Term Γ′ (σ ⇒ τ) g = var (that (that (that this))) y = app f x y′ = app g (x ⊕₍ σ ₎ Δx) in begin ⟦ s ⟧ ρ (v ⟦⊕₍ σ ₎⟧ Δv) ⟦⊝₍ τ ₎⟧ ⟦ t ⟧ ρ v ≡⟨ cong (λ hole → ⟦ s ⟧ ρ hole ⟦⊝₍ τ ₎⟧ ⟦ t ⟧ ρ v) (meaning-⊕ {t = x} {Δt = Δx} {ρ′}) ⟩ ⟦ s ⟧ ρ (⟦ x ⊕₍ σ ₎ Δx ⟧ ρ′) ⟦⊝₍ τ ₎⟧ ⟦ t ⟧ ρ v ≡⟨ meaning-⊝ {s = y′} {y} {ρ′} ⟩ ⟦ y′ ⊝ y ⟧ ρ′ ∎)) where open ≡-Reasoning open Disambiguation meaning-onil {base ι} {Γ} {t} {ρ} = meaning-onil-base ι {Γ} {t} {ρ} meaning-onil {σ ⇒ τ} {Γ} {t} {ρ} = meaning-⊝ {σ ⇒ τ} {Γ} {t} {t} {ρ} -- Ideally, this proof should simply be: -- meaning-⊝ {σ ⇒ τ} {Γ} {t} {t} {ρ} -- -- However, the types of the results don't match because using onil constructs -- different environments.
34.02
82
0.526553
36055be3b3f59fbbdf035d13cf8338fa3fae2427
11,013
agda
Agda
Data/Bin/Minus.agda
Rotsor/BinDivMod
09cc5104421e88da82f9fead5a43f0028f77810d
[ "Unlicense" ]
1
2019-11-18T13:58:14.000Z
2019-11-18T13:58:14.000Z
Data/Bin/Minus.agda
Rotsor/BinDivMod
09cc5104421e88da82f9fead5a43f0028f77810d
[ "Unlicense" ]
null
null
null
Data/Bin/Minus.agda
Rotsor/BinDivMod
09cc5104421e88da82f9fead5a43f0028f77810d
[ "Unlicense" ]
null
null
null
module Data.Bin.Minus where open import Data.Bin hiding (suc; fromℕ) open Data.Bin using (2+_) open import Data.Bin.Bijection using (fromℕ) open import Data.Fin hiding (_-_; _+_; toℕ; _<_; fromℕ) open import Data.List open import Data.Digit open import Relation.Binary.PropositionalEquality open import Data.Nat using (ℕ; _∸_; suc; zero) renaming (_+_ to _ℕ+_) infixl 6 _-?_ infixl 6 _-_ open import Function pred' : Bin → Bin pred' 0# = 0# pred' ([] 1#) = 0# pred' ((zero ∷ t) 1#) = case Data.Bin.pred t of λ { 0# → [] 1# ; (t' 1#) → (suc zero ∷ t') 1# } pred' ((suc zero ∷ t) 1#) = (zero ∷ t) 1# pred' ((suc (suc ()) ∷ _) 1#) open import Data.Sum open import Data.Unit import Data.Nat.Properties data Greater (a b : Bin) : Set where greater : ∀ (diff : Bin⁺) → b + diff 1# ≡ a → Greater a b open import Data.Empty using (⊥; ⊥-elim) import Data.Bin.Addition open import Data.Bin.Props greater-to-< : ∀ a b → Greater a b → b < a greater-to-< ._ b (greater diff refl) = let zz = Data.Nat.Properties.+-mono-≤ {1} {toℕ (diff 1#)} {toℕ b} {toℕ b} (case z<nz diff of λ { (Data.Bin.less p) → p }) Data.Nat.Properties.≤-refl in Data.Bin.less (Data.Nat.Properties.≤-trans zz ( Data.Nat.Properties.≤-reflexive ( trans (sym (Data.Nat.Properties.+-comm (toℕ b) _)) (sym (Data.Bin.Addition.+-is-addition b (diff 1#))) ))) open import Data.Product data Difference (a b : Bin) : Set where positive : Greater a b → Difference a b negative : Greater b a → Difference a b equal : a ≡ b → Difference a b open import Relation.Nullary open import Algebra.Structures import Data.Bin.Addition open IsCommutativeMonoid Data.Bin.Addition.is-commutativeMonoid using (identity; identityˡ) renaming (comm to +-comm; assoc to +-assoc) open import Data.Product identityʳ = proj₂ identity ∷-pred : Bit → Bin⁺ → Bin⁺ ∷-pred zero [] = [] ∷-pred zero (h ∷ t) = suc zero ∷ ∷-pred h t ∷-pred (suc zero) l = zero ∷ l ∷-pred (suc (suc ())) l open Relation.Binary.PropositionalEquality.≡-Reasoning open import Data.Bin.Multiplication using (∷1#-interpretation) open import Function using (_⟨_⟩_) seems-trivial : ∀ xs → (zero ∷ xs) 1# + [] 1# ≡ (suc zero ∷ xs) 1# seems-trivial xs = cong (λ q → q + [] 1#) (∷1#-interpretation zero xs ⟨ trans ⟩ (identityˡ (xs 1# *2))) ⟨ trans ⟩ +-comm (xs 1# *2) ([] 1#) ⟨ trans ⟩ sym (∷1#-interpretation (suc zero) xs) open import Data.Bin.Props carry : ∀ t → [] 1# + (suc zero ∷ t) 1# ≡ ([] 1# + t 1#) *2 carry t = begin [] 1# + (suc zero ∷ t) 1# ≡⟨ cong (_+_ ([] 1#)) (∷1#-interpretation (suc zero) t) ⟩ [] 1# + ([] 1# + t 1# *2) ≡⟨ sym (+-assoc ([] 1#) ([] 1#) (t 1# *2)) ⟩ [] 1# *2 + (t 1# *2) ≡⟨ sym (*2-distrib ([] 1#) (t 1#)) ⟩ ([] 1# + t 1#) *2 ∎ 1+∷-pred : ∀ h t → [] 1# + (∷-pred h t) 1# ≡ (h ∷ t) 1# 1+∷-pred zero [] = refl 1+∷-pred zero (x ∷ xs) = begin [] 1# + (suc zero ∷ ∷-pred x xs) 1# ≡⟨ carry (∷-pred x xs) ⟩ ([] 1# + (∷-pred x xs) 1#) *2 ≡⟨ cong _*2 (1+∷-pred x xs) ⟩ (x ∷ xs) 1# *2 ≡⟨ refl ⟩ (zero ∷ x ∷ xs) 1# ∎ 1+∷-pred (suc zero) t = +-comm ([] 1#) ((zero ∷ t) 1#) ⟨ trans ⟩ seems-trivial t 1+∷-pred (suc (suc ())) t data Comparison (A : Set) : Set where greater : A → Comparison A equal : Comparison A less : A → Comparison A map-cmp : {A B : Set} → (A → B) → Comparison A → Comparison B map-cmp f (greater a) = greater (f a) map-cmp f (less a) = less (f a) map-cmp f equal = equal _%f_ : ∀ {b} → Fin (suc b) → Fin (suc b) → Comparison (Fin b) zero %f zero = equal zero %f suc b = less b suc a %f zero = greater a _%f_ {suc base} (suc a) (suc b) = map-cmp inject₁ (a %f b) _%f_ {zero} (suc ()) (suc ()) _*2-1 : Bin⁺ → Bin⁺ [] *2-1 = [] (suc zero ∷ t) *2-1 = suc zero ∷ zero ∷ t (zero ∷ t) *2-1 = suc zero ∷ (t *2-1) (suc (suc ()) ∷ t) *2-1 _*2+1' : Bin⁺ → Bin⁺ l *2+1' = suc zero ∷ l addBit : Bin⁺ → Comparison (Fin 1) → Bin⁺ addBit gt (greater zero) = gt *2+1' addBit gt equal = zero ∷ gt addBit gt (less zero) = gt *2-1 addBit gt (less (suc ())) addBit gt (greater (suc ())) open import Data.Bin.Utils *2-1-lem : ∀ d → (d *2-1) 1# + [] 1# ≡ d 1# *2 *2-1-lem [] = refl *2-1-lem (zero ∷ xs) = begin (zero ∷ xs) *2-1 1# + [] 1# ≡⟨ refl ⟩ (suc zero ∷ (xs *2-1)) 1# + [] 1# ≡⟨ +-comm ((suc zero ∷ xs *2-1) 1#) ([] 1#) ⟩ [] 1# + (suc zero ∷ (xs *2-1)) 1# ≡⟨ carry (xs *2-1) ⟩ ([] 1# + (xs *2-1) 1#) *2 ≡⟨ cong _*2 (+-comm ([] 1#) ((xs *2-1) 1#)) ⟩ ((xs *2-1) 1# + [] 1#) *2 ≡⟨ cong _*2 (*2-1-lem xs) ⟩ (xs 1# *2) *2 ≡⟨ refl ⟩ (zero ∷ xs) 1# *2 ∎ *2-1-lem (suc zero ∷ xs) = begin (suc zero ∷ zero ∷ xs) 1# + [] 1# ≡⟨ cong (λ q → q + [] 1#) (∷1#-interpretation (suc zero) (zero ∷ xs)) ⟩ [] 1# + (zero ∷ xs) 1# *2 + [] 1# ≡⟨ refl ⟩ [] 1# + xs 1# *2 *2 + [] 1# ≡⟨ +-comm ([] 1# + xs 1# *2 *2) ([] 1#) ⟩ [] 1# + ([] 1# + xs 1# *2 *2) ≡⟨ sym (+-assoc ([] 1#) ([] 1#) (xs 1# *2 *2)) ⟩ [] 1# *2 + xs 1# *2 *2 ≡⟨ sym (*2-distrib ([] 1#) (xs 1# *2)) ⟩ ([] 1# + xs 1# *2) *2 ≡⟨ cong _*2 (sym (∷1#-interpretation (suc zero) xs)) ⟩ (suc zero ∷ xs) 1# *2 ≡⟨ refl ⟩ (zero ∷ suc zero ∷ xs) 1# ∎ *2-1-lem (suc (suc ()) ∷ xs) addBit-lem : ∀ x y d → addBit d (x %f y) 1# + bitToBin y ≡ d 1# *2 + bitToBin x addBit-lem zero zero d = refl addBit-lem (suc zero) zero d = refl addBit-lem zero (suc zero) d = *2-1-lem d ⟨ trans ⟩ sym (identityʳ (d 1# *2)) addBit-lem (suc zero) (suc zero) d = refl addBit-lem (suc (suc ())) _ d addBit-lem _ (suc (suc ())) d +-cong₁ : ∀ {z} {x y} → x ≡ y → x + z ≡ y + z +-cong₁ {z} = cong (λ q → q + z) +-cong₂ : ∀ {z} {x y} → x ≡ y → z + x ≡ z + y +-cong₂ {z} = cong (λ q → z + q) refineGt : ∀ xs ys (x y : Bit) → Greater (xs 1#) (ys 1#) → Greater ((x ∷ xs) 1#) ((y ∷ ys) 1#) refineGt xs ys x y (greater d ys+d=xs) = greater (addBit d (x %f y)) good where good : (y ∷ ys) 1# + addBit d (x %f y) 1# ≡ (x ∷ xs) 1# good = begin (y ∷ ys) 1# + addBit d (x %f y) 1# ≡⟨ +-cong₁ {addBit d (x %f y) 1#} (∷1#-interpretation y ys) ⟩ bitToBin y + (ys 1#) *2 + addBit d (x %f y) 1# ≡⟨ +-comm (bitToBin y + (ys 1#) *2) (addBit d (x %f y) 1#) ⟩ addBit d (x %f y) 1# + (bitToBin y + (ys 1#) *2) ≡⟨ sym (+-assoc (addBit d (x %f y) 1#) (bitToBin y) ((ys 1#) *2)) ⟩ (addBit d (x %f y) 1# + bitToBin y) + (ys 1#) *2 ≡⟨ +-cong₁ {(ys 1#) *2} (addBit-lem x y d) ⟩ (d 1# *2 + bitToBin x) + (ys 1#) *2 ≡⟨ +-cong₁ {(ys 1#) *2} (+-comm (d 1# *2) (bitToBin x)) ⟩ (bitToBin x + d 1# *2 ) + (ys 1#) *2 ≡⟨ +-assoc (bitToBin x) (d 1# *2) ((ys 1#) *2) ⟩ bitToBin x + (d 1# *2 + (ys 1#) *2) ≡⟨ +-cong₂ {bitToBin x} (+-comm (d 1# *2) ((ys 1#) *2)) ⟩ bitToBin x + ((ys 1#) *2 + d 1# *2) ≡⟨ +-cong₂ {bitToBin x} (sym (*2-distrib (ys 1#) (d 1#))) ⟩ bitToBin x + (ys 1# + d 1#) *2 ≡⟨ +-cong₂ {bitToBin x} (cong _*2 ys+d=xs) ⟩ bitToBin x + xs 1# *2 ≡⟨ sym (∷1#-interpretation x xs) ⟩ (x ∷ xs) 1# ∎ compare-bit : ∀ a b xs → Difference ((a ∷ xs) 1#) ((b ∷ xs) 1#) compare-bit 0b 0b xs = equal refl compare-bit 1b 0b xs = positive (greater [] (seems-trivial xs)) compare-bit 0b 1b xs = negative (greater [] (seems-trivial xs)) compare-bit 1b 1b xs = equal refl compare-bit (2+ ()) _ xs compare-bit _ (2+ ()) xs _-⁺_ : ∀ a b → Difference (a 1#) (b 1#) [] -⁺ [] = equal refl [] -⁺ (x ∷ xs) = negative (greater (∷-pred x xs) (1+∷-pred x xs)) (x ∷ xs) -⁺ [] = positive (greater (∷-pred x xs) (1+∷-pred x xs)) (x ∷ xs) -⁺ (y ∷ ys) = case xs -⁺ ys of λ { (positive gt) → positive (refineGt xs ys x y gt) ; (negative lt) → negative (refineGt ys xs y x lt) ; (equal refl) → compare-bit _ _ xs } _-?_ : ∀ a b → Difference a b 0# -? 0# = equal refl a 1# -? 0# = positive (greater a (identityˡ (a 1#))) 0# -? a 1# = negative (greater a (identityˡ (a 1#))) a 1# -? b 1# = a -⁺ b _%⁺_ : Bin⁺ → Bin⁺ → Comparison Bin⁺ [] %⁺ [] = equal (h ∷ t) %⁺ [] = greater (∷-pred h t) [] %⁺ (h ∷ t) = less (∷-pred h t) (x ∷ xs) %⁺ (y ∷ ys) with xs %⁺ ys ... | greater gt = greater (addBit gt (x %f y)) ... | less lt = less (addBit lt (y %f x)) ... | equal = map-cmp (λ _ → []) (x %f y) succ : Bin⁺ → Bin⁺ succ [] = zero ∷ [] succ (zero ∷ t) = suc zero ∷ t succ (suc zero ∷ t) = zero ∷ succ t succ (suc (suc ()) ∷ t) succpred-id : ∀ x xs → succ (∷-pred x xs) ≡ x ∷ xs succpred-id zero [] = refl succpred-id zero (x ∷ xs) = cong (λ z → zero ∷ z) (succpred-id x xs) succpred-id (suc zero) xs = refl succpred-id (suc (suc ())) xs -- CR: difference-to-∸ : ∀ {a b} → Difference a b → Bin -- difference-to-bin _-_ : Bin → Bin → Bin x - y with x -? y ... | positive (greater d _) = d 1# ... | equal _ = 0# ... | negative _ = 0# open import Data.Bin.Bijection using (fromℕ-bijection; toℕ-inj; fromToℕ-inverse; fromℕ-inj) open import Data.Bin.Addition using (+-is-addition) suc-inj : ∀ {x y : ℕ} → Data.Nat.suc x ≡ suc y → x ≡ y suc-inj {x} .{x} refl = refl ℕ-+-inj₂ : ∀ z {a b} → Data.Nat._+_ z a ≡ Data.Nat._+_ z b → a ≡ b ℕ-+-inj₂ zero refl = refl ℕ-+-inj₂ (suc n) eq = ℕ-+-inj₂ n (suc-inj eq) +-inj₂ : ∀ z {a b} → z + a ≡ z + b → a ≡ b +-inj₂ z {a} {b} z+a≡z+b = toℕ-inj ( ℕ-+-inj₂ (toℕ z) (sym (+-is-addition z a) ⟨ trans ⟩ cong toℕ z+a≡z+b ⟨ trans ⟩ +-is-addition z b) ) nat-+zz : ∀ a b → Data.Nat._+_ a b ≡ 0 → a ≡ 0 nat-+zz zero b _ = refl nat-+zz (suc _) b () +zz : ∀ a b → a + b ≡ 0# → a ≡ 0# +zz a b eq = toℕ-inj (nat-+zz (toℕ a) (toℕ b) (sym (+-is-addition a b) ⟨ trans ⟩ cong toℕ eq)) minus-elim : ∀ x z → z + x - z ≡ x minus-elim x z with (z + x -? z) ... | positive (greater d z+d=z+x) = +-inj₂ z z+d=z+x ... | equal z+x≡z = +-inj₂ z (identityʳ z ⟨ trans ⟩ sym z+x≡z) ... | negative (greater d z+x+d≡z) = sym (+zz x (d 1#) (+-inj₂ z ( sym (+-assoc z x (d 1#)) ⟨ trans ⟩ z+x+d≡z ⟨ trans ⟩ sym (identityʳ z)))) import Data.Bin.NatHelpers x≮z→x≡z+y : ∀ {x z} → ¬ x < z → ∃ λ y → x ≡ z + y x≮z→x≡z+y {x} {z} x≮z = case Data.Bin.NatHelpers.x≮z→x≡z+y (λ toℕ-leq → x≮z (less toℕ-leq)) of λ { (y , eq) → fromℕ y , toℕ-inj ( begin toℕ x ≡⟨ eq ⟩ toℕ z ℕ+ y ≡⟨ cong (λ q → toℕ z ℕ+ q) (fromℕ-inj (sym (fromToℕ-inverse (fromℕ y)))) ⟩ toℕ z ℕ+ toℕ (fromℕ y) ≡⟨ sym (+-is-addition z (fromℕ y)) ⟩ toℕ (z + fromℕ y) ∎) } -+-elim' : ∀ {x z} → ¬ x < z → x - z + z ≡ x -+-elim' {x} {z} x≮z = case x≮z→x≡z+y x≮z of λ { (y , refl) → begin z + y - z + z ≡⟨ cong (λ q → q + z) (minus-elim y z)⟩ y + z ≡⟨ +-comm y z ⟩ z + y ∎ }
31.737752
190
0.489694
d1e2385c8c0861d2dbec8d9db8c113240b772a46
374
agda
Agda
test/Negation.agda
andreabedini/plutus-metatheory
cb596a1eb697c083c4bdf2ade4d37bbd2c3cb0bc
[ "MIT" ]
12
2018-09-10T16:51:17.000Z
2021-12-14T16:27:38.000Z
test/Negation.agda
andreabedini/plutus-metatheory
cb596a1eb697c083c4bdf2ade4d37bbd2c3cb0bc
[ "MIT" ]
1
2018-10-22T12:21:16.000Z
2018-10-22T12:38:47.000Z
test/Negation.agda
andreabedini/plutus-metatheory
cb596a1eb697c083c4bdf2ade4d37bbd2c3cb0bc
[ "MIT" ]
4
2018-10-18T13:42:11.000Z
2022-01-15T13:53:57.000Z
module test.Negation where open import Type open import Declarative.Term open import Builtin open import Builtin.Constant.Type open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆ -- plutus/language-plutus-core/test/data/negation.plc open import Declarative.StdLib.Bool negate : ∀{Γ} → Γ ⊢ boolean ⇒ boolean negate {Γ} = ƛ (if ·⋆ boolean · ` Z · false · true)
24.933333
62
0.737968
9a11f5e406990bfe3a08d0c6f7c1eb10bd151fe0
4,679
agda
Agda
papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda
imikushin/plutus
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
[ "Apache-2.0" ]
1,299
2018-10-02T13:41:39.000Z
2022-03-28T01:10:02.000Z
papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda
imikushin/plutus
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
[ "Apache-2.0" ]
2,493
2018-09-28T19:28:17.000Z
2022-03-31T15:31:31.000Z
papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda
imikushin/plutus
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
[ "Apache-2.0" ]
399
2018-10-05T09:36:10.000Z
2022-03-31T11:18:25.000Z
{-# OPTIONS --type-in-type #-} module Compilation.Encode.Examples where open import Context open import Type.Core open import Compilation.Data open import Compilation.Encode.Core open import Function open import Data.Product open import Data.List.Base module ProdTreeTreeExample where open ProdTreeTree open prodTreeTree ProdTreeTree′ = ⟦ prodTreeTree ⟧ᵈ ProdTree′ : Set -> Set -> Set ProdTree′ with ProdTreeTree′ ... | ø ▶ PT′ ▶ T′ = PT′ Tree′ : Set -> Set Tree′ with ProdTreeTree′ ... | ø ▶ PT′ ▶ T′ = T′ mutual fromProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree A B -> ProdTree′ A′ B′ fromProdTree f g (Prod tree) = Wrap λ R h -> h $ fromTree (λ{ (x , y) _ k -> k (f x) (g y) }) tree fromTree : ∀ {A A′} -> (A -> A′) -> Tree A -> Tree′ A′ fromTree f (Leaf x) = Wrap λ R g h -> g $ f x fromTree f (Fork prod) = Wrap λ R g h -> h $ fromProdTree f f prod {-# TERMINATING #-} mutual toProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree′ A B -> ProdTree A′ B′ toProdTree f g (Wrap k) = k _ λ tree -> Prod $ toTree (λ k -> k _ λ x y -> f x , g y) tree toTree : ∀ {A A′} -> (A -> A′) -> Tree′ A -> Tree A′ toTree f (Wrap k) = k _ (Leaf ∘ f) (Fork ∘ toProdTree f f) module ListExample where list : Data⁺ (ε ▻ (ε ▻ ⋆)) list = PackData $ ø ▶ ( endᶜ ∷ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) List′ : Set -> Set List′ with ⟦ list ⟧ᵈ ... | ø ▶ L′ = L′ fromList : ∀ {A} -> List A -> List′ A fromList [] = Wrap λ R z f -> z fromList (x ∷ xs) = Wrap λ R z f -> f x $ fromList xs {-# TERMINATING #-} toList : ∀ {A} -> List′ A -> List A toList (Wrap k) = k _ [] λ x xs -> x ∷ toList xs module InterListExample where data InterList (A B : Set) : Set where InterNil : InterList A B InterCons : A -> B -> InterList B A -> InterList A B interlist : Data⁺ (ε ▻ (ε ▻ ⋆ ▻ ⋆)) interlist = PackData $ ø ▶ ( endᶜ ∷ Var (vs vz) ⇒ᶜ Var vz ⇒ᶜ Var (vs vs vz) ∙ Var vz ∙ Var (vs vz) ⇒ᶜ endᶜ ∷ [] ) InterList′ : Set -> Set -> Set InterList′ with ⟦ interlist ⟧ᵈ ... | ø ▶ IL′ = IL′ fromInterList : ∀ {A B} -> InterList A B -> InterList′ A B fromInterList InterNil = Wrap λ R z f -> z fromInterList (InterCons x y yxs) = Wrap λ R z f -> f x y $ fromInterList yxs {-# TERMINATING #-} toInterList : ∀ {A B} -> InterList′ A B -> InterList A B toInterList (Wrap k) = k _ InterNil λ x y yxs -> InterCons x y $ toInterList yxs module TreeForestExample where mutual data Tree (A : Set) : Set where node : A -> Forest A -> Tree A data Forest (A : Set) : Set where nil : Forest A cons : Tree A -> Forest A -> Forest A treeForest : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ (ε ▻ ⋆)) treeForest = PackData $ ø ▶ ( Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) ▶ ( endᶜ ∷ Var (vs vs vz) ∙ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) TreeForest′ = ⟦ treeForest ⟧ᵈ Tree′ : Set -> Set Tree′ with TreeForest′ ... | ø ▶ T′ ▶ F′ = T′ Forest′ : Set -> Set Forest′ with TreeForest′ ... | ø ▶ T′ ▶ F′ = F′ mutual fromTree : ∀ {A} -> Tree A -> Tree′ A fromTree (node x forest) = Wrap λ R f -> f x $ fromForest forest fromForest : ∀ {A} -> Forest A -> Forest′ A fromForest nil = Wrap λ R z f -> z fromForest (cons tree forest) = Wrap λ R z f -> f (fromTree tree) (fromForest forest) {-# TERMINATING #-} mutual toTree : ∀ {A} -> Tree′ A -> Tree A toTree (Wrap k) = k _ λ x forest -> node x $ toForest forest toForest : ∀ {A} -> Forest′ A -> Forest A toForest (Wrap k) = k _ nil λ tree forest -> cons (toTree tree) (toForest forest) module MNExample where mutual data M (A : Set) : Set where p : A -> M A n : N -> M A data N : Set where m : M N -> N mn : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ ε) mn = PackData $ ø ▶ ( Var vz ⇒ᶜ endᶜ ∷ Var (vs vz) ⇒ᶜ endᶜ ∷ [] ) ▶ ( Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) MN′ = ⟦ mn ⟧ᵈ M′ : Set -> Set M′ with MN′ ... | ø ▶ M′ ▶ N′ = M′ N′ : Set N′ with MN′ ... | ø ▶ M′ ▶ N′ = N′ {-# TERMINATING #-} mutual fromM : ∀ {A B} -> (A -> B) -> M A -> M′ B fromM f (p x) = Wrap λ R g h -> g $ f x fromM f (n x) = Wrap λ R g h -> h $ fromN x fromN : N -> N′ fromN (m x) = Wrap λ R f -> f $ fromM fromN x {-# TERMINATING #-} mutual toM : ∀ {A B} -> (A -> B) -> M′ A -> M B toM f (Wrap k) = k _ (λ x -> p (f x)) (λ x -> n (toN x)) toN : N′ -> N toN (Wrap k) = k _ λ x -> m (toM toN x)
24.888298
93
0.508656
5e8cf0731063a390b63427d2682ae06b2e01d7ea
2,087
agda
Agda
agda-stdlib-0.9/src/Data/BoundedVec.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/BoundedVec.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/BoundedVec.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Bounded vectors ------------------------------------------------------------------------ -- Vectors of a specified maximum length. module Data.BoundedVec where open import Data.Nat open import Data.List as List using (List) open import Data.Vec as Vec using (Vec) open import Relation.Binary.PropositionalEquality open import Data.Nat.Properties open SemiringSolver ------------------------------------------------------------------------ -- The type abstract data BoundedVec (a : Set) : ℕ → Set where bVec : ∀ {m n} (xs : Vec a n) → BoundedVec a (n + m) [] : ∀ {a n} → BoundedVec a n [] = bVec Vec.[] infixr 5 _∷_ _∷_ : ∀ {a n} → a → BoundedVec a n → BoundedVec a (suc n) x ∷ bVec xs = bVec (Vec._∷_ x xs) ------------------------------------------------------------------------ -- Pattern matching infixr 5 _∷v_ data View (a : Set) : ℕ → Set where []v : ∀ {n} → View a n _∷v_ : ∀ {n} (x : a) (xs : BoundedVec a n) → View a (suc n) abstract view : ∀ {a n} → BoundedVec a n → View a n view (bVec Vec.[]) = []v view (bVec (Vec._∷_ x xs)) = x ∷v bVec xs ------------------------------------------------------------------------ -- Increasing the bound abstract ↑ : ∀ {a n} → BoundedVec a n → BoundedVec a (suc n) ↑ {a = a} (bVec {m = m} {n = n} xs) = subst (BoundedVec a) lemma (bVec {m = suc m} xs) where lemma : n + (1 + m) ≡ 1 + (n + m) lemma = solve 2 (λ m n → n :+ (con 1 :+ m) := con 1 :+ (n :+ m)) refl m n ------------------------------------------------------------------------ -- Conversions abstract fromList : ∀ {a} → (xs : List a) → BoundedVec a (List.length xs) fromList {a = a} xs = subst (BoundedVec a) lemma (bVec {m = zero} (Vec.fromList xs)) where lemma : List.length xs + 0 ≡ List.length xs lemma = solve 1 (λ m → m :+ con 0 := m) refl _ toList : ∀ {a n} → BoundedVec a n → List a toList (bVec xs) = Vec.toList xs
26.75641
72
0.445616
0dca21cf0a8953b9c27be8eba5a3b8b458418c8f
1,190
agda
Agda
src/Categories/Morphism/Regular.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
src/Categories/Morphism/Regular.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
src/Categories/Morphism/Regular.agda
maxsnew/agda-categories
8f3c844d929508040dfa21f681fa260056214b73
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} {- Properties regarding Morphisms of a category: - Regular Monomorphism - Regular Epimorphism https://ncatlab.org/nlab/show/regular+epimorphism These are defined here rather than in Morphism, as this might cause import cycles (and make the dependency graph very odd). -} open import Categories.Category.Core module Categories.Morphism.Regular {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Categories.Morphism 𝒞 open import Categories.Diagram.Equalizer 𝒞 open import Categories.Diagram.Coequalizer 𝒞 open Category 𝒞 private variable A B : Obj f : A ⇒ B record RegularMono (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where field { C } : Obj g : B ⇒ C h : B ⇒ C equalizer : IsEqualizer f h g record RegularEpi (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where field { C } : Obj h : C ⇒ A g : C ⇒ A coequalizer : IsCoequalizer h g f RegularMono⇒Mono : RegularMono f → Mono f RegularMono⇒Mono regular = IsEqualizer⇒Mono equalizer where open RegularMono regular RegularEpi⇒Epi : RegularEpi f → Epi f RegularEpi⇒Epi regular = IsCoequalizer⇒Epi coequalizer where open RegularEpi regular
21.636364
69
0.689916
0d3030e34dc2147e71c5bc8bb00386b5690777f5
449
agda
Agda
test/Succeed/Issue2208.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Issue2208.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue2208.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
open import Agda.Builtin.Bool open import Agda.Builtin.Equality open import Agda.Builtin.Float NaN : Float NaN = primFloatDiv 0.0 0.0 -NaN : Float -NaN = primFloatNegate NaN NaN≮NaN : primFloatNumericalLess NaN NaN ≡ false NaN≮NaN = refl -NaN≮-NaN : primFloatNumericalLess -NaN -NaN ≡ false -NaN≮-NaN = refl NaN≮-NaN : primFloatNumericalLess NaN -NaN ≡ false NaN≮-NaN = refl -NaN<NaN : primFloatNumericalLess -NaN NaN ≡ false -NaN<NaN = refl
19.521739
52
0.739421
9ad27d2de1a2488628dd53cc4ade751da395d44a
12,315
agda
Agda
src/subst.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/subst.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/subst.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
module subst where open import lib open import cedille-types open import ctxt-types open import is-free open import rename open import general-util open import syntax-util substh-ret-t : Set → Set substh-ret-t T = ∀ {ed} → ctxt → renamectxt → trie ⟦ ed ⟧ → T → T substh : ∀ {ed} → substh-ret-t ⟦ ed ⟧ substh-term : substh-ret-t term substh-type : substh-ret-t type substh-kind : substh-ret-t kind substh-tk : substh-ret-t tk substh-optClass : substh-ret-t optClass substh-optGuide : substh-ret-t optGuide substh-optTerm : substh-ret-t optTerm substh-optType : substh-ret-t optType substh-liftingType : substh-ret-t liftingType substh-arg : substh-ret-t arg substh-args : substh-ret-t args substh-params : substh-ret-t params substh-cases : substh-ret-t cases substh-varargs : {ed : exprd} → ctxt → renamectxt → trie ⟦ ed ⟧ → varargs → varargs × renamectxt substh{TERM} = substh-term substh{TYPE} = substh-type substh{KIND} = substh-kind substh{LIFTINGTYPE} = substh-liftingType substh{TK} = substh-tk substh{ARG} = substh-arg substh{QUALIF} = λ Γ ρ σ q → q subst-rename-var-if : {ed : exprd} → ctxt → renamectxt → var → trie ⟦ ed ⟧ → var subst-rename-var-if Γ ρ "_" σ = "_" subst-rename-var-if Γ ρ x σ = {- rename bound variable x iff it is one of the vars being substituted for, or if x occurs free in one of the terms we are substituting for vars, or if it is the renamed version of any variable -} if trie-contains σ x || trie-any (is-free-in check-erased x) σ || renamectxt-in-range ρ x || ctxt-binds-var Γ x then rename-away-from x (λ s → ctxt-binds-var Γ s || trie-contains σ s) ρ else x substh-term Γ ρ σ (App t m t') = App (substh-term Γ ρ σ t) m (substh-term Γ ρ σ t') substh-term Γ ρ σ (AppTp t tp) = AppTp (substh-term Γ ρ σ t) (substh-type Γ ρ σ tp) substh-term Γ ρ σ (Hole x₁) = Hole x₁ substh-term Γ ρ σ (Lam _ b _ x oc t) = let x' = subst-rename-var-if Γ ρ x σ in Lam posinfo-gen b posinfo-gen x' (substh-optClass Γ ρ σ oc) (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) substh-term Γ ρ σ (Let _ (DefTerm _ x m t) t') = let x' = subst-rename-var-if Γ ρ x σ in (Let posinfo-gen (DefTerm posinfo-gen x' (substh-optType Γ ρ σ m) (substh-term Γ ρ σ t)) (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t')) substh-term Γ ρ σ (Let _ (DefType _ x k t) t') = let x' = subst-rename-var-if Γ ρ x σ in (Let posinfo-gen (DefType posinfo-gen x' (substh-kind Γ ρ σ k) (substh-type Γ ρ σ t)) (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t')) substh-term Γ ρ σ (Open _ x t) = Open posinfo-gen x (substh-term Γ ρ σ t) substh-term Γ ρ σ (Parens _ t _) = substh-term Γ ρ σ t substh-term{TERM} Γ ρ σ (Var _ x) = let x' = renamectxt-rep ρ x in trie-lookup-else (Var posinfo-gen x') σ x' substh-term{ARG} Γ ρ σ (Var _ x) = let x' = renamectxt-rep ρ x in inst-lookup-term σ x' substh-term{QUALIF} Γ ρ σ (Var _ x) = let x' = renamectxt-rep ρ x in qualif-lookup-term σ x' substh-term Γ ρ σ (Var _ x) = Var posinfo-gen (renamectxt-rep ρ x) substh-term Γ ρ σ (Beta _ ot ot') = Beta posinfo-gen (substh-optTerm Γ ρ σ ot) (substh-optTerm Γ ρ σ ot') substh-term Γ ρ σ (IotaPair _ t1 t2 og pi') = IotaPair posinfo-gen (substh-term Γ ρ σ t1) (substh-term Γ ρ σ t2) (substh-optGuide Γ ρ σ og) pi' substh-term Γ ρ σ (IotaProj t n _) = IotaProj (substh-term Γ ρ σ t) n posinfo-gen substh-term Γ ρ σ (Epsilon _ lr m t) = Epsilon posinfo-gen lr m (substh-term Γ ρ σ t) substh-term Γ ρ σ (Sigma _ t) = Sigma posinfo-gen (substh-term Γ ρ σ t) substh-term Γ ρ σ (Phi _ t t₁ t₂ _) = Phi posinfo-gen (substh-term Γ ρ σ t) (substh-term Γ ρ σ t₁) (substh-term Γ ρ σ t₂) posinfo-gen substh-term Γ ρ σ (Rho _ op on t og t') = Rho posinfo-gen op on (substh-term Γ ρ σ t) (substh-optGuide Γ ρ σ og) (substh-term Γ ρ σ t') substh-term Γ ρ σ (Chi _ T t') = Chi posinfo-gen (substh-optType Γ ρ σ T) (substh-term Γ ρ σ t') substh-term Γ ρ σ (Delta _ T t') = Delta posinfo-gen (substh-optType Γ ρ σ T) (substh-term Γ ρ σ t') substh-term Γ ρ σ (Theta _ θ t ls) = Theta posinfo-gen (substh-theta θ) (substh-term Γ ρ σ t) (substh-lterms ls) where substh-lterms : lterms → lterms substh-lterms (LtermsNil pi) = LtermsNil pi substh-lterms (LtermsCons m t ls) = LtermsCons m (substh-term Γ ρ σ t) (substh-lterms ls) substh-vars : vars → vars substh-vars (VarsStart x) = VarsStart (renamectxt-rep ρ x) substh-vars (VarsNext x xs) = VarsNext (renamectxt-rep ρ x) (substh-vars xs) substh-theta : theta → theta substh-theta (AbstractVars xs) = AbstractVars (substh-vars xs) substh-theta θ = θ substh-term Γ ρ σ (Mu _ x t ot _ cs _) = let x' = subst-rename-var-if Γ ρ x σ in let ρ' = renamectxt-insert ρ x x' in Mu posinfo-gen x' (substh-term (ctxt-var-decl x' Γ) ρ' σ t) (substh-optType Γ ρ σ ot) posinfo-gen (substh-cases Γ ρ' σ cs) posinfo-gen substh-term Γ ρ σ (Mu' _ t ot _ cs _) = Mu' posinfo-gen (substh-term Γ ρ σ t) (substh-optType Γ ρ σ ot) posinfo-gen (substh-cases Γ ρ σ cs) posinfo-gen substh-cases Γ ρ σ NoCase = NoCase substh-cases Γ ρ σ (SomeCase _ x varargs t cs) = let res = substh-varargs Γ ρ σ varargs in SomeCase posinfo-gen x (fst res) (substh-term Γ (snd res) σ t) (substh-cases Γ ρ σ cs) substh-varargs Γ ρ σ NoVarargs = NoVarargs , ρ substh-varargs Γ ρ σ (NormalVararg x varargs) = let x' = subst-rename-var-if Γ ρ x σ in let ρ' = renamectxt-insert ρ x x' in let res = substh-varargs Γ ρ' σ varargs in NormalVararg x' (fst res) , snd res substh-varargs Γ ρ σ (ErasedVararg x varargs) = let x' = subst-rename-var-if Γ ρ x σ in let ρ' = renamectxt-insert ρ x x' in let res = substh-varargs Γ ρ' σ varargs in ErasedVararg x' (fst res) , snd res substh-varargs Γ ρ σ (TypeVararg x varargs) = let x' = subst-rename-var-if Γ ρ x σ in let ρ' = renamectxt-insert ρ x x' in let res = substh-varargs Γ ρ' σ varargs in TypeVararg x' (fst res) , snd res substh-type Γ ρ σ (Abs _ b _ x atk t) = let x' = subst-rename-var-if Γ ρ x σ in Abs posinfo-gen b posinfo-gen x' (substh-tk Γ ρ σ atk) (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) substh-type Γ ρ σ (TpLambda _ _ x atk t) = let x' = subst-rename-var-if Γ ρ x σ in TpLambda posinfo-gen posinfo-gen x' (substh-tk Γ ρ σ atk) (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) substh-type Γ ρ σ (Iota _ _ x m t) = let x' = subst-rename-var-if Γ ρ x σ in Iota posinfo-gen posinfo-gen x' (substh-type Γ ρ σ m) (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) substh-type Γ ρ σ (Lft _ _ x t l) = let x' = subst-rename-var-if Γ ρ x σ in Lft posinfo-gen posinfo-gen x' (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) (substh-liftingType Γ ρ σ l) substh-type Γ ρ σ (TpApp tp tp₁) = TpApp (substh-type Γ ρ σ tp) (substh-type Γ ρ σ tp₁) substh-type Γ ρ σ (TpAppt tp t) = TpAppt (substh-type Γ ρ σ tp) (substh-term Γ ρ σ t) substh-type Γ ρ σ (TpArrow tp arrowtype tp₁) = TpArrow (substh-type Γ ρ σ tp) arrowtype (substh-type Γ ρ σ tp₁) substh-type Γ ρ σ (TpEq _ x₁ x₂ _) = TpEq posinfo-gen (substh-term Γ ρ σ x₁) (substh-term Γ ρ σ x₂) posinfo-gen substh-type Γ ρ σ (TpParens _ tp _) = substh-type Γ ρ σ tp substh-type Γ ρ σ (NoSpans tp _) = substh-type Γ ρ σ tp substh-type{TYPE} Γ ρ σ (TpVar _ x) = let x' = renamectxt-rep ρ x in trie-lookup-else (TpVar posinfo-gen x') σ x' substh-type{ARG} Γ ρ σ (TpVar _ x) = let x' = renamectxt-rep ρ x in inst-lookup-type σ x' substh-type{QUALIF} Γ ρ σ (TpVar _ x) = let x' = renamectxt-rep ρ x in qualif-lookup-type σ x' substh-type Γ ρ σ (TpVar _ x) = TpVar posinfo-gen (renamectxt-rep ρ x) substh-type Γ ρ σ (TpHole _) = TpHole posinfo-gen --ACG substh-type Γ ρ σ (TpLet _ (DefTerm _ x m t) t') = let x' = subst-rename-var-if Γ ρ x σ in (TpLet posinfo-gen (DefTerm posinfo-gen x' (substh-optType Γ ρ σ m) (substh-term Γ ρ σ t)) (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t')) substh-type Γ ρ σ (TpLet _ (DefType _ x k t) t') = let x' = subst-rename-var-if Γ ρ x σ in (TpLet posinfo-gen (DefType posinfo-gen x' (substh-kind Γ ρ σ k) (substh-type Γ ρ σ t)) (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t')) substh-kind Γ ρ σ (KndArrow k k₁) = KndArrow (substh-kind Γ ρ σ k) (substh-kind Γ ρ σ k₁) substh-kind Γ ρ σ (KndParens x₁ k x₂) = substh-kind Γ ρ σ k substh-kind Γ ρ σ (KndPi _ _ x atk k) = let x' = subst-rename-var-if Γ ρ x σ in KndPi posinfo-gen posinfo-gen x' (substh-tk Γ ρ σ atk) (substh-kind (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ k) substh-kind Γ ρ σ (KndTpArrow t k) = KndTpArrow (substh-type Γ ρ σ t) (substh-kind Γ ρ σ k) substh-kind{QUALIF} Γ ρ σ (KndVar _ x xs) = qualif-lookup-kind (substh-args Γ ρ σ xs) σ x substh-kind Γ ρ σ (KndVar _ x xs) = KndVar posinfo-gen x (substh-args Γ ρ σ xs) substh-kind Γ ρ σ (Star _) = Star posinfo-gen substh-arg Γ ρ σ (TermArg me t) = TermArg me (substh-term Γ ρ σ t) substh-arg Γ ρ σ (TypeArg T) = TypeArg (substh-type Γ ρ σ T) substh-args Γ ρ σ (ArgsCons a as) = ArgsCons (substh-arg Γ ρ σ a) (substh-args Γ ρ σ as) substh-args Γ ρ σ ArgsNil = ArgsNil substh-params{QUALIF} Γ ρ σ (ParamsCons (Decl _ pi me x atk _) ps) = ParamsCons (Decl posinfo-gen posinfo-gen me (pi % x) (substh-tk Γ ρ σ atk) posinfo-gen) (substh-params Γ (renamectxt-insert ρ x (pi % x)) (trie-remove σ (pi % x)) ps) substh-params Γ ρ σ (ParamsCons (Decl _ _ me x atk _) ps) = ParamsCons (Decl posinfo-gen posinfo-gen me x (substh-tk Γ ρ σ atk) posinfo-gen) (substh-params Γ (renamectxt-insert ρ x x) (trie-remove σ x) ps) substh-params Γ ρ σ ParamsNil = ParamsNil substh-tk Γ ρ σ (Tkk k) = Tkk (substh-kind Γ ρ σ k) substh-tk Γ ρ σ (Tkt t) = Tkt (substh-type Γ ρ σ t) substh-optClass Γ ρ σ NoClass = NoClass substh-optClass Γ ρ σ (SomeClass atk) = SomeClass (substh-tk Γ ρ σ atk) substh-liftingType Γ ρ σ (LiftArrow l l₁) = LiftArrow (substh-liftingType Γ ρ σ l) (substh-liftingType Γ ρ σ l₁) substh-liftingType Γ ρ σ (LiftParens _ l _) = substh-liftingType Γ ρ σ l substh-liftingType Γ ρ σ (LiftPi _ x tp l) = let x' = subst-rename-var-if Γ ρ x σ in LiftPi posinfo-gen x' (substh-type Γ ρ σ tp) (substh-liftingType (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ l) substh-liftingType Γ ρ σ (LiftStar _) = LiftStar posinfo-gen substh-liftingType Γ ρ σ (LiftTpArrow tp l) = LiftTpArrow (substh-type Γ ρ σ tp) (substh-liftingType Γ ρ σ l) substh-optType Γ ρ σ NoType = NoType substh-optType Γ ρ σ (SomeType T) = SomeType (substh-type Γ ρ σ T) substh-optTerm Γ ρ σ NoTerm = NoTerm substh-optTerm Γ ρ σ (SomeTerm t _) = (SomeTerm (substh-term Γ ρ σ t) posinfo-gen) substh-optGuide Γ ρ σ NoGuide = NoGuide substh-optGuide Γ ρ σ (Guide _ x T) = let x' = subst-rename-var-if Γ ρ x σ in Guide posinfo-gen x' (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ T) subst-ret-t : Set → Set subst-ret-t T = {ed : exprd} → ctxt → ⟦ ed ⟧ → var → T → T subst : ∀ {ed} → subst-ret-t ⟦ ed ⟧ subst Γ t x = substh Γ empty-renamectxt (trie-single x t) subst-term = subst {TERM} subst-type = subst {TYPE} subst-kind = subst {KIND} subst-liftingType = subst {LIFTINGTYPE} subst-tk = subst {TK} subst-renamectxt : ∀ {ed : exprd} → ctxt → renamectxt → ⟦ ed ⟧ → ⟦ ed ⟧ subst-renamectxt {ed} Γ ρ = substh {ed} {ed} Γ ρ empty-trie rename-var : ∀ {ed} → ctxt → var → var → ⟦ ed ⟧ → ⟦ ed ⟧ rename-var Γ x x' = subst-renamectxt Γ (renamectxt-single x x') substs-ret-t : Set → Set substs-ret-t T = ∀ {ed} → ctxt → trie ⟦ ed ⟧ → T → T substs : ∀ {ed} → substs-ret-t ⟦ ed ⟧ substs Γ = substh Γ empty-renamectxt substs-term = substs {TERM} substs-type = substs {TYPE} substs-kind = substs {KIND} substs-liftingType = substs {LIFTINGTYPE} substs-tk = substs {TK} substs-args : substs-ret-t args substs-args Γ = substh-args Γ empty-renamectxt substs-params : substs-ret-t params substs-params Γ = substh-params Γ empty-renamectxt subst-params-args : ∀ {ed} → ctxt → params → args → ⟦ ed ⟧ → ⟦ ed ⟧ × params × args subst-params-args Γ (ParamsCons (Decl _ _ me x atk _) ps) (ArgsCons a as) t = subst-params-args Γ (substs-params Γ (trie-single x a) ps) as (subst Γ a x t) subst-params-args Γ ps as t = t , ps , as
47.365385
151
0.664799
52d123ad92887359c4c0836cc3c876f47b1ffbe1
7,138
agda
Agda
src/Examples/Exp2.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
29
2021-07-14T03:18:28.000Z
2022-03-22T20:35:11.000Z
src/Examples/Exp2.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
null
null
null
src/Examples/Exp2.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
2
2021-10-06T10:28:24.000Z
2022-01-29T08:12:01.000Z
{-# OPTIONS --prop --rewriting #-} module Examples.Exp2 where open import Calf.CostMonoid open import Calf.CostMonoids using (ℕ²-ParCostMonoid) parCostMonoid = ℕ²-ParCostMonoid open ParCostMonoid parCostMonoid open import Calf costMonoid open import Calf.ParMetalanguage parCostMonoid open import Calf.Types.Bool open import Calf.Types.Nat open import Calf.Types.Bounded costMonoid open import Calf.Types.BigO costMonoid open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; _≢_; module ≡-Reasoning) open import Data.Nat as Nat using (_+_; pred; _*_; _^_; _⊔_) import Data.Nat.Properties as N open import Data.Nat.PredExp2 open import Data.Product open import Data.Empty Correct : cmp (Π nat λ _ → F nat) → Set Correct exp₂ = (n : ℕ) → ◯ (exp₂ n ≡ ret (2 ^ n)) module Slow where exp₂ : cmp (Π nat λ _ → F nat) exp₂ zero = ret (suc zero) exp₂ (suc n) = bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) → step (F nat) (1 , 1) (ret (r₁ + r₂)) exp₂/correct : Correct exp₂ exp₂/correct zero u = refl exp₂/correct (suc n) u = begin exp₂ (suc n) ≡⟨⟩ (bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) → step (F nat) (1 , 1) (ret (r₁ + r₂))) ≡⟨ Eq.cong (bind (F nat) (exp₂ n & exp₂ n)) (funext (λ (r₁ , r₂) → step/ext (F nat) _ (1 , 1) u)) ⟩ (bind (F nat) (exp₂ n & exp₂ n) λ (r₁ , r₂) → ret (r₁ + r₂)) ≡⟨ Eq.cong (λ e → bind (F nat) (e & e) _) (exp₂/correct n u) ⟩ step (F nat) (𝟘 ⊗ 𝟘) (ret (2 ^ n + 2 ^ n)) ≡⟨⟩ ret (2 ^ n + 2 ^ n) ≡⟨ Eq.cong ret (lemma/2^suc n) ⟩ ret (2 ^ suc n) ∎ where open ≡-Reasoning exp₂/cost : cmp (Π nat λ _ → cost) exp₂/cost zero = 𝟘 exp₂/cost (suc n) = bind cost (exp₂ n & exp₂ n) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕ ((1 , 1) ⊕ 𝟘) exp₂/cost/closed : cmp (Π nat λ _ → cost) exp₂/cost/closed n = pred[2^ n ] , n exp₂/cost≤exp₂/cost/closed : ∀ n → ◯ (exp₂/cost n ≤ exp₂/cost/closed n) exp₂/cost≤exp₂/cost/closed zero u = ≤-refl exp₂/cost≤exp₂/cost/closed (suc n) u = let ≡ = exp₂/correct n u in let open ≤-Reasoning in begin exp₂/cost (suc n) ≡⟨⟩ (bind cost (exp₂ n & exp₂ n) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕ ((1 , 1) ⊕ 𝟘)) ≡⟨ Eq.cong₂ (λ e₁ e₂ → bind cost (e₁ & e₂) λ (r₁ , r₂) → (exp₂/cost n ⊗ exp₂/cost n) ⊕ _) (≡) (≡) ⟩ (exp₂/cost n ⊗ exp₂/cost n) ⊕ ((1 , 1) ⊕ 𝟘) ≡⟨ Eq.cong ((exp₂/cost n ⊗ exp₂/cost n) ⊕_) (⊕-identityʳ _) ⟩ (exp₂/cost n ⊗ exp₂/cost n) ⊕ (1 , 1) ≤⟨ ⊕-monoˡ-≤ (1 , 1) (⊗-mono-≤ (exp₂/cost≤exp₂/cost/closed n u) (exp₂/cost≤exp₂/cost/closed n u)) ⟩ (exp₂/cost/closed n ⊗ exp₂/cost/closed n) ⊕ (1 , 1) ≡⟨ Eq.cong₂ _,_ arithmetic/work arithmetic/span ⟩ exp₂/cost/closed (suc n) ∎ where arithmetic/work : proj₁ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡ proj₁ (exp₂/cost/closed (suc n)) arithmetic/work = begin proj₁ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡⟨⟩ proj₁ (exp₂/cost/closed n) + proj₁ (exp₂/cost/closed n) + 1 ≡⟨ N.+-comm _ 1 ⟩ suc (proj₁ (exp₂/cost/closed n) + proj₁ (exp₂/cost/closed n)) ≡⟨⟩ suc (pred[2^ n ] + pred[2^ n ]) ≡⟨ pred[2^suc[n]] n ⟩ pred[2^ suc n ] ≡⟨⟩ proj₁ (exp₂/cost/closed (suc n)) ∎ where open ≡-Reasoning arithmetic/span : proj₂ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡ proj₂ (exp₂/cost/closed (suc n)) arithmetic/span = begin proj₂ (exp₂/cost/closed n ⊗ exp₂/cost/closed n ⊕ (1 , 1)) ≡⟨⟩ proj₂ (exp₂/cost/closed n) ⊔ proj₂ (exp₂/cost/closed n) + 1 ≡⟨⟩ n ⊔ n + 1 ≡⟨ Eq.cong (_+ 1) (N.⊔-idem n) ⟩ n + 1 ≡⟨ N.+-comm _ 1 ⟩ suc n ≡⟨⟩ proj₂ (exp₂/cost/closed (suc n)) ∎ where open ≡-Reasoning exp₂≤exp₂/cost : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost n) exp₂≤exp₂/cost zero = bound/ret exp₂≤exp₂/cost (suc n) = bound/bind (exp₂/cost n ⊗ exp₂/cost n) _ (bound/par (exp₂≤exp₂/cost n) (exp₂≤exp₂/cost n)) λ (r₁ , r₂) → bound/step (1 , 1) 𝟘 bound/ret exp₂≤exp₂/cost/closed : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost/closed n) exp₂≤exp₂/cost/closed n = bound/relax (exp₂/cost≤exp₂/cost/closed n) (exp₂≤exp₂/cost n) exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → 2 ^ n , n) exp₂/asymptotic = 0 ≤n⇒f[n]≤g[n]via λ n _ → bound/relax (λ u → N.pred[n]≤n , N.≤-refl) (exp₂≤exp₂/cost/closed n) module Fast where exp₂ : cmp (Π nat λ _ → F nat) exp₂ zero = ret (suc zero) exp₂ (suc n) = bind (F nat) (exp₂ n) λ r → step (F nat) (1 , 1) (ret (r + r)) exp₂/correct : Correct exp₂ exp₂/correct zero u = refl exp₂/correct (suc n) u = begin exp₂ (suc n) ≡⟨⟩ (bind (F nat) (exp₂ n) λ r → step (F nat) (1 , 1) (ret (r + r))) ≡⟨ Eq.cong (bind (F nat) (exp₂ n)) (funext (λ r → step/ext (F nat) _ (1 , 1) u)) ⟩ (bind (F nat) (exp₂ n) λ r → ret (r + r)) ≡⟨ Eq.cong (λ e → bind (F nat) e _) (exp₂/correct n u) ⟩ (bind (F nat) (ret {nat} (2 ^ n)) λ r → ret (r + r)) ≡⟨⟩ ret (2 ^ n + 2 ^ n) ≡⟨ Eq.cong ret (lemma/2^suc n) ⟩ ret (2 ^ suc n) ∎ where open ≡-Reasoning exp₂/cost : cmp (Π nat λ _ → cost) exp₂/cost zero = 𝟘 exp₂/cost (suc n) = bind cost (exp₂ n) λ r → exp₂/cost n ⊕ ((1 , 1) ⊕ 𝟘) exp₂/cost/closed : cmp (Π nat λ _ → cost) exp₂/cost/closed n = n , n exp₂/cost≤exp₂/cost/closed : ∀ n → ◯ (exp₂/cost n ≤ exp₂/cost/closed n) exp₂/cost≤exp₂/cost/closed zero u = ≤-refl exp₂/cost≤exp₂/cost/closed (suc n) u = let open ≤-Reasoning in begin exp₂/cost (suc n) ≡⟨⟩ (bind cost (exp₂ n) λ r → exp₂/cost n ⊕ ((1 , 1) ⊕ 𝟘)) ≡⟨ Eq.cong (λ e → bind cost e λ r → exp₂/cost n ⊕ _) (exp₂/correct n u) ⟩ exp₂/cost n ⊕ ((1 , 1) ⊕ 𝟘) ≤⟨ ⊕-monoˡ-≤ ((1 , 1) ⊕ 𝟘) (exp₂/cost≤exp₂/cost/closed n u) ⟩ exp₂/cost/closed n ⊕ ((1 , 1) ⊕ 𝟘) ≡⟨ Eq.cong (exp₂/cost/closed n ⊕_) (⊕-identityʳ _) ⟩ exp₂/cost/closed n ⊕ (1 , 1) ≡⟨ Eq.cong₂ _,_ (N.+-comm _ 1) (N.+-comm _ 1) ⟩ exp₂/cost/closed (suc n) ∎ exp₂≤exp₂/cost : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost n) exp₂≤exp₂/cost zero = bound/ret exp₂≤exp₂/cost (suc n) = bound/bind (exp₂/cost n) _ (exp₂≤exp₂/cost n) λ r → bound/step (1 , 1) 𝟘 bound/ret exp₂≤exp₂/cost/closed : ∀ n → IsBounded nat (exp₂ n) (exp₂/cost/closed n) exp₂≤exp₂/cost/closed n = bound/relax (exp₂/cost≤exp₂/cost/closed n) (exp₂≤exp₂/cost n) exp₂/asymptotic : given nat measured-via (λ n → n) , exp₂ ∈𝓞(λ n → n , n) exp₂/asymptotic = 0 ≤n⇒f[n]≤ 1 g[n]via λ n _ → Eq.subst (IsBounded _ _) (Eq.sym (⊕-identityʳ _)) (exp₂≤exp₂/cost/closed n) slow≡fast : ◯ (Slow.exp₂ ≡ Fast.exp₂) slow≡fast u = funext λ n → begin Slow.exp₂ n ≡⟨ Slow.exp₂/correct n u ⟩ ret (2 ^ n) ≡˘⟨ Fast.exp₂/correct n u ⟩ Fast.exp₂ n ∎ where open ≡-Reasoning
34.15311
124
0.542589
4e28b21b72e36df0ae05505361a6a2c20920b1d5
774
agda
Agda
Cubical/Algebra/Magma/Construct/Left.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Magma/Construct/Left.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Magma/Construct/Left.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} open import Cubical.Core.Everything open import Cubical.Foundations.HLevels module Cubical.Algebra.Magma.Construct.Left {ℓ} (Aˢ : hSet ℓ) where open import Cubical.Foundations.Prelude open import Cubical.Algebra.Magma private A = ⟨ Aˢ ⟩ isSetA = Aˢ .snd _◂_ : Op₂ A x ◂ y = x ------------------------------------------------------------------------ -- Properties ◂-zeroˡ : ∀ x → LeftZero x _◂_ ◂-zeroˡ _ _ = refl ◂-identityʳ : ∀ x → RightIdentity x _◂_ ◂-identityʳ _ _ = refl ------------------------------------------------------------------------ -- Magma definition Left-isMagma : IsMagma A _◂_ Left-isMagma = record { is-set = isSetA } LeftMagma : Magma ℓ LeftMagma = record { isMagma = Left-isMagma }
20.918919
72
0.559432
37a3a3842669512c07c0cb86108057bf1223e940
471
agda
Agda
README/Safe/Cubical/Erased/Guardedness.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
README/Safe/Cubical/Erased/Guardedness.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
README/Safe/Cubical/Erased/Guardedness.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Safe modules that use --erased-cubical and --guardedness ------------------------------------------------------------------------ {-# OPTIONS --safe --erased-cubical --guardedness #-} module README.Safe.Cubical.Erased.Guardedness where -- M-types for indexed containers, defined coinductively (in Cubical -- Agda). import Container.Indexed.Variant.M.Codata import Container.Indexed.M.Codata
33.642857
72
0.528662
14542fe88b309ceffe56ed6962ab2373924af567
478
agda
Agda
Tools/Nullary.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Tools/Nullary.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Tools/Nullary.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
-- Some proposition constructors. {-# OPTIONS --without-K --safe #-} module Tools.Nullary where open import Tools.Empty -- Negation. infix 3 ¬_ ¬_ : Set → Set ¬ P = P → ⊥ -- Decidable propositions. data Dec (P : Set) : Set where yes : ( p : P) → Dec P no : (¬p : ¬ P) → Dec P -- If A and B are logically equivalent, then so are Dec A and Dec B. map : ∀ {A B} → (A → B) → (B → A) → Dec A → Dec B map f g (yes p) = yes (f p) map f g (no ¬p) = no (λ x → ¬p (g x))
17.703704
68
0.554393
fd4edc6d23465068a74363c2e97459f33d3fd630
82
agda
Agda
src/L/Base/Id.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
null
null
null
src/L/Base/Id.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
10
2020-10-19T10:13:16.000Z
2020-11-09T16:40:39.000Z
src/L/Base/Id.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
null
null
null
module L.Base.Id where -- Reexport definitions open import L.Base.Id.Core public
16.4
33
0.780488
143d96925bac7170dcc4137ec41f1e04d10f679a
169
agda
Agda
data/declaration/Module.agda
msuperdock/agda-unused
f327f9aab8dcb07022b857736d8201906bba02e9
[ "MIT" ]
6
2020-10-29T09:38:43.000Z
2022-03-01T16:38:05.000Z
data/declaration/Module.agda
msuperdock/agda-unused
f327f9aab8dcb07022b857736d8201906bba02e9
[ "MIT" ]
null
null
null
data/declaration/Module.agda
msuperdock/agda-unused
f327f9aab8dcb07022b857736d8201906bba02e9
[ "MIT" ]
1
2022-03-01T16:38:14.000Z
2022-03-01T16:38:14.000Z
module Module where record R : Set where module M where module N where module O where postulate A : Set x : R x = record {M} module P = N
6.5
19
0.585799
43ab704adad8868163d5f15fb2218b7ee83c1366
17,004
agda
Agda
typingrules.agda
guillaumebrunerie/general-type-theories
f9bfefd0a70ae5bdc3906829ee1165c731882bca
[ "MIT" ]
null
null
null
typingrules.agda
guillaumebrunerie/general-type-theories
f9bfefd0a70ae5bdc3906829ee1165c731882bca
[ "MIT" ]
null
null
null
typingrules.agda
guillaumebrunerie/general-type-theories
f9bfefd0a70ae5bdc3906829ee1165c731882bca
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting --prop #-} open import common open import syntx open import derivability {- Helper functions to compute the arity of a rule given the arity of the symbol. -} SStoJS : SyntaxSort → JudgmentSort SStoJS Ty = Ty SStoJS Tm = Tm TArityArgs : SyntaxArityArgs → JudgmentArityArgs TArityArgs [] = [] TArityArgs (ar , (n , k)) = TArityArgs ar , (n , SStoJS k) TArity : SyntaxArity → JudgmentArity TArity ar = (TArityArgs (args ar) , SStoJS (sort ar)) SStoJS= : SyntaxSort → JudgmentSort SStoJS= Ty = Ty= SStoJS= Tm = Tm= CArityArgs : SyntaxArityArgs → JudgmentArityArgs CArityArgs [] = [] CArityArgs (ar , (n , k)) = CArityArgs ar , (n , SStoJS= k) CArity : SyntaxArity → JudgmentArity CArity ar = (CArityArgs (args ar) , SStoJS= (sort ar)) {- [↑DerivationRule r] extends the derivation rule [r] to an extended signature. This is easy because derivation rules were designed to be extendable. -} ↑DerivationRule : {Σ : Signature} {sar : SyntaxArity} {jar : JudgmentArity} → DerivationRule Σ jar → DerivationRule (ExtSig Σ sar) jar rule (↑DerivationRule r) ↑ Γ = rule r (Ext→ ↑) Γ {- Record combining the typing and congruence rules for a new symbol. -} record DerivationRules {Σ : Signature} (E : DerivabilityStructure Σ) (ar : SyntaxArity) : Set₁ where field typingdrule : DerivationRule (ExtSig Σ ar) (TArity ar) congruencedrule : DerivationRule (ExtSig Σ ar) (CArity ar) open DerivationRules public {- [extend E tc] extends the derivability structure [E] to an extended signature, where [tc] is the typing/congruence rules of a new symbol. We also use a custom data type in order to add the two new rules, in order to get something readable. -} data ExtT (A : JudgmentArity → Set) (sar : SyntaxArity) : JudgmentArity → Set where typingrule : ExtT A sar (TArity sar) prev : {jar : JudgmentArity} → A jar → ExtT A sar jar data ExtC (A : JudgmentArity → Set) (sar : SyntaxArity) : JudgmentArity → Set where congruencerule : ExtC A sar (CArity sar) prev : {jar : JudgmentArity} → A jar → ExtC A sar jar extend : {Σ : Signature} (E : DerivabilityStructure Σ) {ar : SyntaxArity} (tc : DerivationRules E ar) → DerivabilityStructure (ExtSig Σ ar) Rules (extend E {ar} tc) S = Rules E S Rules (extend E {ar} tc) T = ExtT (Rules E T) ar Rules (extend E {ar} tc) C = ExtC (Rules E C) ar Rules (extend E {ar} tc) Eq = Rules E Eq derivationRule (extend E tc) {t = S} r = ↑DerivationRule (derivationRule E r) derivationRule (extend E tc) {t = T} (prev r) = ↑DerivationRule (derivationRule E r) derivationRule (extend E tc) {t = T} typingrule = typingdrule tc derivationRule (extend E tc) {t = C} (prev r) = ↑DerivationRule (derivationRule E r) derivationRule (extend E tc) {t = C} congruencerule = congruencedrule tc derivationRule (extend E tc) {t = Eq} r = ↑DerivationRule (derivationRule E r) -- data Ext (A : Tag → JudgmentArity → Set) (sar : SyntaxArity) : Tag → JudgmentArity → Set where -- typingrule : Ext A sar T (TArity sar) -- congruencerule : Ext A sar C (CArity sar) -- prev : {t : Tag} {jar : JudgmentArity} → A t jar → Ext A sar t jar -- extend : {Σ : Signature} (E : DerivabilityStructure Σ) -- {ar : SyntaxArity} -- (tc : DerivationRules E ar 0) -- → DerivabilityStructure (ExtSig Σ ar) -- Rules (extend E {ar} tc) = Ext (Rules E) ar -- derivationRule (extend E tc) typingrule = typingdrule tc -- derivationRule (extend E tc) congruencerule = congruencedrule tc -- derivationRule (extend E tc) (prev r) = ↑DerivationRule (derivationRule E r) {- Typing rules for basic metavariables (simply a derivable type in the empty context) -} record BMTypingRule {Σ : Signature} (E : DerivabilityStructure Σ) : Set where constructor _/_ field type : TyExpr Σ 0 der : Derivable E {Γ = ◇} (◇ ⊢ type) open BMTypingRule public {- The derivation rules corresponding to a basic metavariable (on the extended signature). -} BMRules : {Σ : Signature} {E : DerivabilityStructure Σ} (t : BMTypingRule E) → DerivationRules E ([] , Tm) rule (typingdrule (BMRules t)) ↑ Γ [] = return (◇ ⊢ (↑ $ new) [] :> ↑Expr (Ext→ ↑) (weaken0 (type t))) rule (congruencedrule (BMRules t)) ↑ Γ [] = return (◇ ⊢ (↑ $ new) [] == (↑ $ new) [] :> ↑Expr (Ext→ ↑) (weaken0 (type t))) -- -------------- ----------------- -- Γ ⊢ s : A Γ ⊢ s = s : A {- The premises of a typing rule for a metavariables form essentially a list of typing rules for basic metavariables in increasingly extended signatures. There are two different ways to order the premises: - either we have the first premise, and then the rest in an extended signature, - or we have all but the last premises, and then the last one in a signature extended by all the previous ones. The first option looks simpler, but we use the second option because we will need to talk about multiple substitution later anyway, and also it allows us to keep typing rules in the empty context. The type [MTypingRulePremises E n] represents a list of length [n] of such premises. It is defined simultaneously with multiple substitution: [extend^BM E ts] represents the derivability structure [E] extended by all the basic metavariables of [ts]. -} data MTypingRulePremises : {Σ : Signature} (E : DerivabilityStructure Σ) (n : ℕ) → Set extend^BM : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} (ts : MTypingRulePremises E n) → DerivabilityStructure (ExtSig^ Σ (MArityArgs n)) data MTypingRulePremises where [] : ∀ {Σ} {E : DerivabilityStructure Σ} → MTypingRulePremises E 0 _,_ : ∀ {Σ} {E : DerivabilityStructure Σ} {n : ℕ} → (ts : MTypingRulePremises E n) → (t : BMTypingRule (extend^BM E ts)) → MTypingRulePremises E (suc n) extend^BM E [] = E extend^BM E (ts , t) = extend (extend^BM E ts) (BMRules t) {- [MTypingRule E n k] represents typing rules in derivability structure [E] for a metavariable of arity (n , k). There are two cases depending on [k]: - if [k] is [Ty], then we simply need a list of premises, - if [k] is [Tm], then we need a list of premises and a type for the conclusion, in the correctly extended derivability structure. -} data MTypingRule {Σ : Signature} (E : DerivabilityStructure Σ) (n : ℕ) : (k : SyntaxSort) → Set where Ty : MTypingRulePremises E n → MTypingRule E n Ty Tm : (ts : MTypingRulePremises E n) → BMTypingRule (extend^BM E ts) → MTypingRule E n Tm {- Γ, n : ℕ, y : P n ⊢ dS : P (n + 1) ◇ ⊢ _n : ℕ ◇ ⊢ _y : P _n ---------------------------- ◇ ⊢ dS(_n , _y) : P (_n + 1) Γ ⊢ n = m : ℕ Γ ⊢ u = v : P n ----------- Γ ⊢ dS(n , u) = dS(m , v) : P (n + 1) Γ ⊢ 3 : ℕ Γ ⊢ u : P 3 ~~~> Γ ⊢ dS(3 , u) : P (3 + 1) (n : ℕ, y : P n) -} {- The derivation rules associated to a typing rule for a metavariable. -} MTypingRule-TArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {n m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m} (ts : MTypingRulePremises E n) (js : DerivationRulePremises Σ' Γ (TArityArgs (MArityArgs n))) → Partial (Args Σ' m (MArityArgs n)) MTypingRule-TArgs E ↑ [] [] = return [] MTypingRule-TArgs E ↑ (ts , t) (js , ◇ ⊢ a :> A) = do as ← MTypingRule-TArgs E ↑ ts js assume (A ≡ ↑Expr (SubstM ↑ as) (weaken0 (type t))) return (as , a) MTypingRule-TRule : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} {k : SyntaxSort} (t : MTypingRule E n k) → DerivationRule (ExtSig Σ (MArity n k)) (TArity (MArity n k)) rule (MTypingRule-TRule E (Ty ts)) ↑ Γ js = do as ← MTypingRule-TArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as) rule (MTypingRule-TRule E (Tm ts t)) ↑ Γ js = do as ← MTypingRule-TArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t))) MTypingRule-CArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {n m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m} (ts : MTypingRulePremises E n) (js : DerivationRulePremises Σ' Γ (CArityArgs (MArityArgs n))) → Partial (Args Σ' m (MArityArgs n) × Args Σ' m (MArityArgs n)) MTypingRule-CArgs E ↑ [] [] = return ([] , []) MTypingRule-CArgs E ↑ (ts , t) (js , ◇ ⊢ a == a' :> A) = do (as , as') ← MTypingRule-CArgs E ↑ ts js assume (A ≡ ↑Expr (SubstM ↑ as) (weaken0 (type t))) return ((as , a) , (as' , a')) MTypingRule-CRule : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} {k : SyntaxSort} (t : MTypingRule E n k) → DerivationRule (ExtSig Σ (MArity n k)) (CArity (MArity n k)) rule (MTypingRule-CRule E (Ty ts)) ↑ Γ js = do (as , as') ← MTypingRule-CArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as == (↑ $ new) as') rule (MTypingRule-CRule E (Tm ts t)) ↑ Γ js = do (as , as') ← MTypingRule-CArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as == (↑ $ new) as' :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t))) MRules : {Σ : Signature} {E : DerivabilityStructure Σ} {n : ℕ} {k : SyntaxSort} (t : MTypingRule E n k) → DerivationRules E (MArity n k) typingdrule (MRules t) = MTypingRule-TRule _ t congruencedrule (MRules t) = MTypingRule-CRule _ t {- General typing rules are very similar to typing rules of metavariables, except that they are using [MTypingRule] instead of [BMTypingRule] for the premises. -} data TypingRulePremises : {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) → Set extend^M : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} (ts : TypingRulePremises E args) → DerivabilityStructure (ExtSig^ Σ args) data TypingRulePremises where [] : ∀ {Σ} {E : DerivabilityStructure Σ} → TypingRulePremises E [] _,_ : ∀ {Σ} {E : DerivabilityStructure Σ} {args : SyntaxArityArgs} {m : ℕ} {k : SyntaxSort} → (ts : TypingRulePremises E args) → (t : MTypingRule (extend^M E ts) m k) → TypingRulePremises E (args , (m , k)) extend^M E [] = E extend^M E (ts , t) = extend (extend^M E ts) (MRules t) data TypingRule {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) : (k : SyntaxSort) → Set where Ty : TypingRulePremises E args → TypingRule E args Ty Tm : (ts : TypingRulePremises E args) → BMTypingRule (extend^M E ts) → TypingRule E args Tm {- The derivation rules associated to a typing rule. -} {- List of all the last [n] variables in scope [m + n] -} Vars : {Σ : Signature} {n : ℕ} (m : ℕ) → Args Σ (m + n) (MArityArgs n) Vars {n = zero} m = [] Vars {n = suc n} m = weakenA {{≤-+ {m + n} {1}}} last (Vars m) , var last {- [check-DepCtx ↑ as ts Δ] checks that the premises [ts] correspond to the dependent context [Δ], where [as] corresponds to the interpretations of the metavariables. -} check-DepCtx : {Σ Σ' : Signature} {m n : ℕ} {args : SyntaxArityArgs} {E : DerivabilityStructure (ExtSig^ Σ args)} → (Σ →Sig Σ') m → Args Σ' m args → MTypingRulePremises E n → DepCtx Σ' m n → Prop check-DepCtx ↑ as [] ◇ = ⊤ check-DepCtx {m = m} {n = suc n} ↑ as (ts , t) (Δ , A) = ΣP (check-DepCtx ↑ as ts Δ) (λ _ → A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t)))) TypingRule-TArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m} (ts : TypingRulePremises E args) (js : DerivationRulePremises Σ' Γ (TArityArgs args)) → Partial (Args Σ' m args) TypingRule-TArgs E ↑ [] [] = return [] TypingRule-TArgs E ↑ (ts , Ty t's) (js , Δ ⊢ A) = do as ← TypingRule-TArgs E ↑ ts js assume (check-DepCtx ↑ as t's Δ) return (as , A) TypingRule-TArgs E {m = m} ↑ (ts , Tm t's t) (_,_ {m = m'} js (Δ ⊢ u :> A)) = do as ← TypingRule-TArgs E ↑ ts js assume (check-DepCtx ↑ as t's Δ) assume (A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t)))) return (as , u) TypingRule-TRule : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {k : SyntaxSort} (t : TypingRule E args k) → DerivationRule (ExtSig Σ (args , k)) (TArity (args , k)) rule (TypingRule-TRule E (Ty ts)) ↑ Γ js = do as ← TypingRule-TArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as) rule (TypingRule-TRule E (Tm ts t)) ↑ Γ js = do as ← TypingRule-TArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t))) TypingRule-CArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m} (ts : TypingRulePremises E args) (js : DerivationRulePremises Σ' Γ (CArityArgs args)) → Partial (Args Σ' m args × Args Σ' m args) TypingRule-CArgs E ↑ [] [] = return ([] , []) TypingRule-CArgs E {args = args , (n , Ty)} {m} ↑ (ts , Ty t's) (js , Δ ⊢ A == A') = do (as , as') ← TypingRule-CArgs E ↑ ts js assume (check-DepCtx ↑ as t's Δ) return ((as , A) , (as' , A')) TypingRule-CArgs E {args = args , (n , Tm)} {m} ↑ (ts , Tm t's t) (js , Δ ⊢ u == u' :> A) = do (as , as') ← TypingRule-CArgs E ↑ ts js assume (check-DepCtx ↑ as t's Δ) assume (A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t)))) return ((as , u) , (as' , u')) TypingRule-CRule : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {k : SyntaxSort} (t : TypingRule E args k) → DerivationRule (ExtSig Σ (args , k)) (CArity (args , k)) rule (TypingRule-CRule E (Ty ts)) ↑ Γ js = do (as , as') ← TypingRule-CArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as == (↑ $ new) as') rule (TypingRule-CRule E (Tm ts t)) {n = n} ↑ Γ js = do (as , as') ← TypingRule-CArgs E (Ext→ ↑) ts js return (◇ ⊢ (↑ $ new) as == (↑ $ new) as' :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t))) TRules : {Σ : Signature} {E : DerivabilityStructure Σ} {ar : SyntaxArity} (t : TypingRule E (args ar) (sort ar)) → DerivationRules E ar typingdrule (TRules t) = TypingRule-TRule _ t congruencedrule (TRules t) = TypingRule-CRule _ t {- Γ ⊢ A == A' Γ , x : A ⊢ B == B' -------------------- Γ ⊢ Π A B == Π A' B' -} {- Equality rules -} {- [extendE E tc] extends the derivability structure with one single (equality) rule -} data ExtE (A : JudgmentArity → Set) (nar : JudgmentArity) : JudgmentArity → Set where equalityrule : ExtE A nar nar prev : {jar : JudgmentArity} → A jar → ExtE A nar jar extendE : {Σ : Signature} (E : DerivabilityStructure Σ) {ar : JudgmentArity} (tc : DerivationRule Σ ar) → DerivabilityStructure Σ Rules (extendE E {ar} tc) S = Rules E S Rules (extendE E {ar} tc) T = Rules E T Rules (extendE E {ar} tc) C = Rules E C Rules (extendE E {ar} tc) Eq = ExtE (Rules E Eq) ar derivationRule (extendE E tc) {S} r = derivationRule E r derivationRule (extendE E tc) {T} r = derivationRule E r derivationRule (extendE E tc) {C} r = derivationRule E r derivationRule (extendE E tc) {Eq} (prev r) = derivationRule E r derivationRule (extendE E tc) {Eq} equalityrule = tc -- data ExtE (A : Tag → JudgmentArity → Set) (nar : JudgmentArity) : Tag → JudgmentArity → Set where -- equalityrule : ExtE A nar Eq nar -- prev : {t : Tag} {jar : JudgmentArity} → A t jar → ExtE A nar t jar -- extendE : {Σ : Signature} (E : DerivabilityStructure Σ) -- {ar : JudgmentArity} -- (tc : {n : ℕ} → DerivationRule Σ ar n) -- → DerivabilityStructure Σ -- Rules (extendE E {ar} tc) = ExtE (Rules E) ar -- derivationRule (extendE E tc) (prev r) = derivationRule E r -- derivationRule (extendE E tc) equalityrule = tc record TermEquality {Σ : Signature} (E : DerivabilityStructure Σ) : Set where constructor _<:_/_//_/_ field type : TyExpr Σ 0 term1 : TmExpr Σ 0 der1 : Derivable E {Γ = ◇} (◇ ⊢ term1 :> type) term2 : TmExpr Σ 0 der2 : Derivable E {Γ = ◇} (◇ ⊢ term2 :> type) open BMTypingRule public data EqualityRule {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) : (k : SyntaxSort) → Set where Ty= : (ts : TypingRulePremises E args) (A B : BMTypingRule (extend^M E ts)) → EqualityRule E args Ty Tm= : (ts : TypingRulePremises E args) (A : TermEquality (extend^M E ts)) → EqualityRule E args Tm ERule : {Σ : Signature} {E : DerivabilityStructure Σ} {args : SyntaxArityArgs} {k : SyntaxSort} → EqualityRule E args k → DerivationRule Σ (TArityArgs args , SStoJS= k) rule (ERule {E = E} (Ty= ts A B)) ↑ Γ js = do as ← TypingRule-TArgs E ↑ ts js return (◇ ⊢ (↑Expr (SubstM ↑ as) (weaken0 (A .type))) == (↑Expr (SubstM ↑ as) (weaken0 (B .type)))) rule (ERule {E = E} (Tm= ts (A <: u / _ // v / _))) ↑ Γ js = do as ← TypingRule-TArgs E ↑ ts js return (◇ ⊢ (↑Expr (SubstM ↑ as) (weaken0 u)) == (↑Expr (SubstM ↑ as) (weaken0 v)) :> ↑Expr (SubstM ↑ as) (weaken0 A))
41.881773
155
0.617678
4e74ce3df4186e3db9ac2938b8341451fc63cb6e
1,311
agda
Agda
agda-stdlib/src/Data/Erased.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Erased.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Erased.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Wrapper for the erased modality -- -- This allows us to store erased proofs in a record and use projections -- to manipulate them without having to turn on the unsafe option -- --irrelevant-projections. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Erased where open import Level using (Level) private variable a b c : Level A : Set a B : Set b C : Set c ------------------------------------------------------------------------ -- Type record Erased (A : Set a) : Set a where constructor [_] field .erased : A open Erased public ------------------------------------------------------------------------ -- Algebraic structure: Functor, Appplicative and Monad-like map : (A → B) → Erased A → Erased B map f [ a ] = [ f a ] pure : A → Erased A pure x = [ x ] infixl 4 _<*>_ _<*>_ : Erased (A → B) → Erased A → Erased B [ f ] <*> [ a ] = [ f a ] infixl 1 _>>=_ _>>=_ : Erased A → (.A → Erased B) → Erased B [ a ] >>= f = f a ------------------------------------------------------------------------ -- Other functions zipWith : (A → B → C) → Erased A → Erased B → Erased C zipWith f a b = ⦇ f a b ⦈
24.277778
72
0.440122
355a971dcabf6323867a51f44a7c9c5cd7aae9f2
16,995
agda
Agda
holes-disjoint-checks.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
holes-disjoint-checks.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
holes-disjoint-checks.agda
hazelgrove/hazelnut-agda
a3640d7b0f76cdac193afd382694197729ed6d57
[ "MIT" ]
null
null
null
open import Prelude open import Nat open import dynamics-core open import contexts open import disjointness -- this module contains lemmas and properties about the holes-disjoint -- judgement that double check that it acts as we would expect module holes-disjoint-checks where -- these lemmas are all structurally recursive and quite -- mechanical. morally, they establish the properties about reduction -- that would be obvious / baked into Agda if holes-disjoint was defined -- as a function rather than a judgement (datatype), or if we had defined -- all the O(n^2) cases rather than relying on a little indirection to -- only have O(n) cases. that work has to go somewhwere, and we prefer -- that it goes here. ds-lem-num : ∀{e n} → holes-disjoint e (N n) ds-lem-num {N x} = HDNum ds-lem-num {e ·+ e₁} = HDPlus ds-lem-num ds-lem-num ds-lem-num {e ·: x} = HDAsc ds-lem-num ds-lem-num {X x} = HDVar ds-lem-num {·λ x e} = HDLam1 ds-lem-num ds-lem-num {·λ x ·[ x₁ ] e} = HDLam2 ds-lem-num ds-lem-num {e ∘ e₁} = HDAp ds-lem-num ds-lem-num ds-lem-num {inl e} = HDInl ds-lem-num ds-lem-num {inr e} = HDInr ds-lem-num ds-lem-num {case e x e₁ x₁ e₂} = HDCase ds-lem-num ds-lem-num ds-lem-num ds-lem-num {⟨ e , e₁ ⟩} = HDPair ds-lem-num ds-lem-num ds-lem-num {fst e} = HDFst ds-lem-num ds-lem-num {snd e} = HDSnd ds-lem-num ds-lem-num {⦇-⦈[ x ]} = HDHole HNNum ds-lem-num {⦇⌜ e ⌟⦈[ x ]} = HDNEHole HNNum ds-lem-num ds-lem-plus : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 (e1 ·+ e2) ds-lem-plus HDNum ν = HDNum ds-lem-plus (HDPlus hd hd₁) (HDPlus ν ν₁) = HDPlus (ds-lem-plus hd ν) (ds-lem-plus hd₁ ν₁) ds-lem-plus (HDAsc hd) (HDAsc ν) = HDAsc (ds-lem-plus hd ν) ds-lem-plus HDVar HDVar = HDVar ds-lem-plus (HDLam1 hd) (HDLam1 ν) = HDLam1 (ds-lem-plus hd ν) ds-lem-plus (HDLam2 hd) (HDLam2 ν) = HDLam2 (ds-lem-plus hd ν) ds-lem-plus (HDAp hd hd₁) (HDAp ν ν₁) = HDAp (ds-lem-plus hd ν) (ds-lem-plus hd₁ ν₁) ds-lem-plus (HDInl hd) (HDInl ν) = HDInl (ds-lem-plus hd ν) ds-lem-plus (HDInr hd) (HDInr ν) = HDInr (ds-lem-plus hd ν) ds-lem-plus (HDCase hd hd₁ hd₂) (HDCase ν ν₁ ν₂) = HDCase (ds-lem-plus hd ν) (ds-lem-plus hd₁ ν₁) (ds-lem-plus hd₂ ν₂) ds-lem-plus (HDPair hd hd₁) (HDPair ν ν₁) = HDPair (ds-lem-plus hd ν) (ds-lem-plus hd₁ ν₁) ds-lem-plus (HDFst hd) (HDFst ν) = HDFst (ds-lem-plus hd ν) ds-lem-plus (HDSnd hd) (HDSnd ν) = HDSnd (ds-lem-plus hd ν) ds-lem-plus (HDHole x) (HDHole x₁) = HDHole (HNPlus x x₁) ds-lem-plus (HDNEHole x hd) (HDNEHole x₁ ν) = HDNEHole (HNPlus x x₁) (ds-lem-plus hd ν) ds-lem-var : ∀{e x} → holes-disjoint e (X x) ds-lem-var {N x} = HDNum ds-lem-var {e ·+ e₁} = HDPlus ds-lem-var ds-lem-var ds-lem-var {e ·: x} = HDAsc ds-lem-var ds-lem-var {X x} = HDVar ds-lem-var {·λ x e} = HDLam1 ds-lem-var ds-lem-var {·λ x ·[ x₁ ] e} = HDLam2 ds-lem-var ds-lem-var {e ∘ e₁} = HDAp ds-lem-var ds-lem-var ds-lem-var {inl e} = HDInl ds-lem-var ds-lem-var {inr e} = HDInr ds-lem-var ds-lem-var {case e x e₁ x₁ e₂} = HDCase ds-lem-var ds-lem-var ds-lem-var ds-lem-var {⟨ e , e₁ ⟩} = HDPair ds-lem-var ds-lem-var ds-lem-var {fst e} = HDFst ds-lem-var ds-lem-var {snd e} = HDSnd ds-lem-var ds-lem-var {⦇-⦈[ x ]} = HDHole HNVar ds-lem-var {⦇⌜ e ⌟⦈[ x ]} = HDNEHole HNVar ds-lem-var ds-lem-asc : ∀{e1 e2 τ} → holes-disjoint e2 e1 → holes-disjoint e2 (e1 ·: τ) ds-lem-asc HDNum = HDNum ds-lem-asc (HDPlus hd hd₁) = HDPlus (ds-lem-asc hd) (ds-lem-asc hd₁) ds-lem-asc (HDAsc hd) = HDAsc (ds-lem-asc hd) ds-lem-asc HDVar = HDVar ds-lem-asc (HDLam1 hd) = HDLam1 (ds-lem-asc hd) ds-lem-asc (HDLam2 hd) = HDLam2 (ds-lem-asc hd) ds-lem-asc (HDAp hd hd₁) = HDAp (ds-lem-asc hd) (ds-lem-asc hd₁) ds-lem-asc (HDInl hd) = HDInl (ds-lem-asc hd) ds-lem-asc (HDInr hd) = HDInr (ds-lem-asc hd) ds-lem-asc (HDCase hd hd₁ hd₂) = HDCase (ds-lem-asc hd) (ds-lem-asc hd₁) (ds-lem-asc hd₂) ds-lem-asc (HDPair hd hd₁) = HDPair (ds-lem-asc hd) (ds-lem-asc hd₁) ds-lem-asc (HDFst hd) = HDFst (ds-lem-asc hd) ds-lem-asc (HDSnd hd) = HDSnd (ds-lem-asc hd) ds-lem-asc (HDHole x) = HDHole (HNAsc x) ds-lem-asc (HDNEHole x hd) = HDNEHole (HNAsc x) (ds-lem-asc hd) ds-lem-lam1 : ∀{e1 e2 x} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x e1) ds-lem-lam1 HDNum = HDNum ds-lem-lam1 (HDPlus hd hd₁) = HDPlus (ds-lem-lam1 hd) (ds-lem-lam1 hd₁) ds-lem-lam1 (HDAsc hd) = HDAsc (ds-lem-lam1 hd) ds-lem-lam1 HDVar = HDVar ds-lem-lam1 (HDLam1 hd) = HDLam1 (ds-lem-lam1 hd) ds-lem-lam1 (HDLam2 hd) = HDLam2 (ds-lem-lam1 hd) ds-lem-lam1 (HDAp hd hd₁) = HDAp (ds-lem-lam1 hd) (ds-lem-lam1 hd₁) ds-lem-lam1 (HDInl hd) = HDInl (ds-lem-lam1 hd) ds-lem-lam1 (HDInr hd) = HDInr (ds-lem-lam1 hd) ds-lem-lam1 (HDCase hd hd₁ hd₂) = HDCase (ds-lem-lam1 hd) (ds-lem-lam1 hd₁) (ds-lem-lam1 hd₂) ds-lem-lam1 (HDPair hd hd₁) = HDPair (ds-lem-lam1 hd) (ds-lem-lam1 hd₁) ds-lem-lam1 (HDFst hd) = HDFst (ds-lem-lam1 hd) ds-lem-lam1 (HDSnd hd) = HDSnd (ds-lem-lam1 hd) ds-lem-lam1 (HDHole x₁) = HDHole (HNLam1 x₁) ds-lem-lam1 (HDNEHole x₁ hd) = HDNEHole (HNLam1 x₁) (ds-lem-lam1 hd) ds-lem-lam2 : ∀{e1 e2 x τ} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x ·[ τ ] e1) ds-lem-lam2 HDNum = HDNum ds-lem-lam2 (HDPlus hd hd₁) = HDPlus (ds-lem-lam2 hd) (ds-lem-lam2 hd₁) ds-lem-lam2 (HDAsc hd) = HDAsc (ds-lem-lam2 hd) ds-lem-lam2 HDVar = HDVar ds-lem-lam2 (HDLam1 hd) = HDLam1 (ds-lem-lam2 hd) ds-lem-lam2 (HDLam2 hd) = HDLam2 (ds-lem-lam2 hd) ds-lem-lam2 (HDAp hd hd₁) = HDAp (ds-lem-lam2 hd) (ds-lem-lam2 hd₁) ds-lem-lam2 (HDInl hd) = HDInl (ds-lem-lam2 hd) ds-lem-lam2 (HDInr hd) = HDInr (ds-lem-lam2 hd) ds-lem-lam2 (HDCase hd hd₁ hd₂) = HDCase (ds-lem-lam2 hd) (ds-lem-lam2 hd₁) (ds-lem-lam2 hd₂) ds-lem-lam2 (HDPair hd hd₁) = HDPair (ds-lem-lam2 hd) (ds-lem-lam2 hd₁) ds-lem-lam2 (HDFst hd) = HDFst (ds-lem-lam2 hd) ds-lem-lam2 (HDSnd hd) = HDSnd (ds-lem-lam2 hd) ds-lem-lam2 (HDHole x₁) = HDHole (HNLam2 x₁) ds-lem-lam2 (HDNEHole x₁ hd) = HDNEHole (HNLam2 x₁) (ds-lem-lam2 hd) ds-lem-ap : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 (e1 ∘ e2) ds-lem-ap HDNum hd2 = HDNum ds-lem-ap (HDPlus hd1 hd2) (HDPlus hd3 hd4) = HDPlus (ds-lem-ap hd1 hd3) (ds-lem-ap hd2 hd4) ds-lem-ap (HDAsc hd1) (HDAsc hd2) = HDAsc (ds-lem-ap hd1 hd2) ds-lem-ap HDVar hd2 = HDVar ds-lem-ap (HDLam1 hd1) (HDLam1 hd2) = HDLam1 (ds-lem-ap hd1 hd2) ds-lem-ap (HDLam2 hd1) (HDLam2 hd2) = HDLam2 (ds-lem-ap hd1 hd2) ds-lem-ap (HDAp hd1 hd2) (HDAp hd3 hd4) = HDAp (ds-lem-ap hd1 hd3) (ds-lem-ap hd2 hd4) ds-lem-ap (HDInl hd) (HDInl ν) = HDInl (ds-lem-ap hd ν) ds-lem-ap (HDInr hd) (HDInr ν) = HDInr (ds-lem-ap hd ν) ds-lem-ap (HDCase hd hd₁ hd₂) (HDCase ν ν₁ ν₂) = HDCase (ds-lem-ap hd ν) (ds-lem-ap hd₁ ν₁) (ds-lem-ap hd₂ ν₂) ds-lem-ap (HDPair hd hd₁) (HDPair ν ν₁) = HDPair (ds-lem-ap hd ν) (ds-lem-ap hd₁ ν₁) ds-lem-ap (HDFst hd) (HDFst ν) = HDFst (ds-lem-ap hd ν) ds-lem-ap (HDSnd hd) (HDSnd ν) = HDSnd (ds-lem-ap hd ν) ds-lem-ap (HDHole x) (HDHole x₁) = HDHole (HNAp x x₁) ds-lem-ap (HDNEHole x hd1) (HDNEHole x₁ hd2) = HDNEHole (HNAp x x₁) (ds-lem-ap hd1 hd2) ds-lem-inl : ∀{e1 e2} → holes-disjoint e2 e1 → holes-disjoint e2 (inl e1) ds-lem-inl HDNum = HDNum ds-lem-inl (HDPlus hd hd₁) = HDPlus (ds-lem-inl hd) (ds-lem-inl hd₁) ds-lem-inl (HDAsc hd) = HDAsc (ds-lem-inl hd) ds-lem-inl HDVar = HDVar ds-lem-inl (HDLam1 hd) = HDLam1 (ds-lem-inl hd) ds-lem-inl (HDLam2 hd) = HDLam2 (ds-lem-inl hd) ds-lem-inl (HDAp hd hd₁) = HDAp (ds-lem-inl hd) (ds-lem-inl hd₁) ds-lem-inl (HDInl hd) = HDInl (ds-lem-inl hd) ds-lem-inl (HDInr hd) = HDInr (ds-lem-inl hd) ds-lem-inl (HDCase hd hd₁ hd₂) = HDCase (ds-lem-inl hd) (ds-lem-inl hd₁) (ds-lem-inl hd₂) ds-lem-inl (HDPair hd hd₁) = HDPair (ds-lem-inl hd) (ds-lem-inl hd₁) ds-lem-inl (HDFst hd) = HDFst (ds-lem-inl hd) ds-lem-inl (HDSnd hd) = HDSnd (ds-lem-inl hd) ds-lem-inl (HDHole x) = HDHole (HNInl x) ds-lem-inl (HDNEHole x hd) = HDNEHole (HNInl x) (ds-lem-inl hd) ds-lem-inr : ∀{e1 e2} → holes-disjoint e2 e1 → holes-disjoint e2 (inr e1) ds-lem-inr HDNum = HDNum ds-lem-inr (HDPlus hd hd₁) = HDPlus (ds-lem-inr hd) (ds-lem-inr hd₁) ds-lem-inr (HDAsc hd) = HDAsc (ds-lem-inr hd) ds-lem-inr HDVar = HDVar ds-lem-inr (HDLam1 hd) = HDLam1 (ds-lem-inr hd) ds-lem-inr (HDLam2 hd) = HDLam2 (ds-lem-inr hd) ds-lem-inr (HDAp hd hd₁) = HDAp (ds-lem-inr hd) (ds-lem-inr hd₁) ds-lem-inr (HDInl hd) = HDInl (ds-lem-inr hd) ds-lem-inr (HDInr hd) = HDInr (ds-lem-inr hd) ds-lem-inr (HDCase hd hd₁ hd₂) = HDCase (ds-lem-inr hd) (ds-lem-inr hd₁) (ds-lem-inr hd₂) ds-lem-inr (HDPair hd hd₁) = HDPair (ds-lem-inr hd) (ds-lem-inr hd₁) ds-lem-inr (HDFst hd) = HDFst (ds-lem-inr hd) ds-lem-inr (HDSnd hd) = HDSnd (ds-lem-inr hd) ds-lem-inr (HDHole x) = HDHole (HNInr x) ds-lem-inr (HDNEHole x hd) = HDNEHole (HNInr x) (ds-lem-inr hd) ds-lem-case : ∀{e3 e x e1 y e2} → holes-disjoint e3 e → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 (case e x e1 y e2) ds-lem-case HDNum HDNum HDNum = HDNum ds-lem-case (HDPlus hd hd₁) (HDPlus ν ν₂) (HDPlus ν₁ ν₃) = HDPlus (ds-lem-case hd ν ν₁) (ds-lem-case hd₁ ν₂ ν₃) ds-lem-case (HDAsc hd) (HDAsc ν) (HDAsc ν₁) = HDAsc (ds-lem-case hd ν ν₁) ds-lem-case HDVar HDVar HDVar = HDVar ds-lem-case (HDLam1 hd) (HDLam1 ν) (HDLam1 ν₁) = HDLam1 (ds-lem-case hd ν ν₁) ds-lem-case (HDLam2 hd) (HDLam2 ν) (HDLam2 ν₁) = HDLam2 (ds-lem-case hd ν ν₁) ds-lem-case (HDAp hd hd₁) (HDAp ν ν₁) (HDAp ν₂ ν₃) = HDAp (ds-lem-case hd ν ν₂) (ds-lem-case hd₁ ν₁ ν₃) ds-lem-case (HDInl hd) (HDInl ν) (HDInl ν₁) = HDInl (ds-lem-case hd ν ν₁) ds-lem-case (HDInr hd) (HDInr ν) (HDInr ν₁) = HDInr (ds-lem-case hd ν ν₁) ds-lem-case (HDCase hd hd₁ hd₂) (HDCase ν ν₁ ν₂) (HDCase ν₃ ν₄ ν₅) = HDCase (ds-lem-case hd ν ν₃) (ds-lem-case hd₁ ν₁ ν₄) (ds-lem-case hd₂ ν₂ ν₅) ds-lem-case (HDPair hd hd₁) (HDPair ν ν₁) (HDPair ν₂ ν₃) = HDPair (ds-lem-case hd ν ν₂) (ds-lem-case hd₁ ν₁ ν₃) ds-lem-case (HDFst hd) (HDFst ν) (HDFst ν₁) = HDFst (ds-lem-case hd ν ν₁) ds-lem-case (HDSnd hd) (HDSnd ν) (HDSnd ν₁) = HDSnd (ds-lem-case hd ν ν₁) ds-lem-case (HDHole x) (HDHole x₁) (HDHole x₂) = HDHole (HNCase x x₁ x₂) ds-lem-case (HDNEHole x hd) (HDNEHole x₁ ν) (HDNEHole x₂ ν₁) = HDNEHole (HNCase x x₁ x₂) (ds-lem-case hd ν ν₁) ds-lem-pair : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 ⟨ e1 , e2 ⟩ ds-lem-pair HDNum HDNum = HDNum ds-lem-pair (HDPlus hd hd₁) (HDPlus ν ν₁) = HDPlus (ds-lem-pair hd ν) (ds-lem-pair hd₁ ν₁) ds-lem-pair (HDAsc hd) (HDAsc ν) = HDAsc (ds-lem-pair hd ν) ds-lem-pair HDVar HDVar = HDVar ds-lem-pair (HDLam1 hd) (HDLam1 ν) = HDLam1 (ds-lem-pair hd ν) ds-lem-pair (HDLam2 hd) (HDLam2 ν) = HDLam2 (ds-lem-pair hd ν) ds-lem-pair (HDAp hd hd₁) (HDAp ν ν₁) = HDAp (ds-lem-pair hd ν) (ds-lem-pair hd₁ ν₁) ds-lem-pair (HDInl hd) (HDInl ν) = HDInl (ds-lem-pair hd ν) ds-lem-pair (HDInr hd) (HDInr ν) = HDInr (ds-lem-pair hd ν) ds-lem-pair (HDCase hd hd₁ hd₂) (HDCase ν ν₁ ν₂) = HDCase (ds-lem-pair hd ν) (ds-lem-pair hd₁ ν₁) (ds-lem-pair hd₂ ν₂) ds-lem-pair (HDPair hd hd₁) (HDPair ν ν₁) = HDPair (ds-lem-pair hd ν) (ds-lem-pair hd₁ ν₁) ds-lem-pair (HDFst hd) (HDFst ν) = HDFst (ds-lem-pair hd ν) ds-lem-pair (HDSnd hd) (HDSnd ν) = HDSnd (ds-lem-pair hd ν) ds-lem-pair (HDHole x) (HDHole x₁) = HDHole (HNPair x x₁) ds-lem-pair (HDNEHole x hd) (HDNEHole x₁ ν) = HDNEHole (HNPair x x₁) (ds-lem-pair hd ν) ds-lem-fst : ∀{e1 e2} → holes-disjoint e2 e1 → holes-disjoint e2 (fst e1) ds-lem-fst HDNum = HDNum ds-lem-fst (HDPlus hd hd₁) = HDPlus (ds-lem-fst hd) (ds-lem-fst hd₁) ds-lem-fst (HDAsc hd) = HDAsc (ds-lem-fst hd) ds-lem-fst HDVar = HDVar ds-lem-fst (HDLam1 hd) = HDLam1 (ds-lem-fst hd) ds-lem-fst (HDLam2 hd) = HDLam2 (ds-lem-fst hd) ds-lem-fst (HDAp hd hd₁) = HDAp (ds-lem-fst hd) (ds-lem-fst hd₁) ds-lem-fst (HDInl hd) = HDInl (ds-lem-fst hd) ds-lem-fst (HDInr hd) = HDInr (ds-lem-fst hd) ds-lem-fst (HDCase hd hd₁ hd₂) = HDCase (ds-lem-fst hd) (ds-lem-fst hd₁) (ds-lem-fst hd₂) ds-lem-fst (HDPair hd hd₁) = HDPair (ds-lem-fst hd) (ds-lem-fst hd₁) ds-lem-fst (HDFst hd) = HDFst (ds-lem-fst hd) ds-lem-fst (HDSnd hd) = HDSnd (ds-lem-fst hd) ds-lem-fst (HDHole x) = HDHole (HNFst x) ds-lem-fst (HDNEHole x hd) = HDNEHole (HNFst x) (ds-lem-fst hd) ds-lem-snd : ∀{e1 e2} → holes-disjoint e2 e1 → holes-disjoint e2 (snd e1) ds-lem-snd HDNum = HDNum ds-lem-snd (HDPlus hd hd₁) = HDPlus (ds-lem-snd hd) (ds-lem-snd hd₁) ds-lem-snd (HDAsc hd) = HDAsc (ds-lem-snd hd) ds-lem-snd HDVar = HDVar ds-lem-snd (HDLam1 hd) = HDLam1 (ds-lem-snd hd) ds-lem-snd (HDLam2 hd) = HDLam2 (ds-lem-snd hd) ds-lem-snd (HDAp hd hd₁) = HDAp (ds-lem-snd hd) (ds-lem-snd hd₁) ds-lem-snd (HDInl hd) = HDInl (ds-lem-snd hd) ds-lem-snd (HDInr hd) = HDInr (ds-lem-snd hd) ds-lem-snd (HDCase hd hd₁ hd₂) = HDCase (ds-lem-snd hd) (ds-lem-snd hd₁) (ds-lem-snd hd₂) ds-lem-snd (HDPair hd hd₁) = HDPair (ds-lem-snd hd) (ds-lem-snd hd₁) ds-lem-snd (HDFst hd) = HDFst (ds-lem-snd hd) ds-lem-snd (HDSnd hd) = HDSnd (ds-lem-snd hd) ds-lem-snd (HDHole x) = HDHole (HNSnd x) ds-lem-snd (HDNEHole x hd) = HDNEHole (HNSnd x) (ds-lem-snd hd) ds-lem-hole : ∀{e u} → hole-name-new e u → holes-disjoint e ⦇-⦈[ u ] ds-lem-hole HNNum = HDNum ds-lem-hole (HNPlus hnn hnn₁) = HDPlus (ds-lem-hole hnn) (ds-lem-hole hnn₁) ds-lem-hole (HNAsc hnn) = HDAsc (ds-lem-hole hnn) ds-lem-hole HNVar = HDVar ds-lem-hole (HNLam1 hnn) = HDLam1 (ds-lem-hole hnn) ds-lem-hole (HNLam2 hnn) = HDLam2 (ds-lem-hole hnn) ds-lem-hole (HNAp hnn hnn₁) = HDAp (ds-lem-hole hnn) (ds-lem-hole hnn₁) ds-lem-hole (HNInl hnn) = HDInl (ds-lem-hole hnn) ds-lem-hole (HNInr hnn) = HDInr (ds-lem-hole hnn) ds-lem-hole (HNCase hnn hnn₁ hnn₂) = HDCase (ds-lem-hole hnn) (ds-lem-hole hnn₁) (ds-lem-hole hnn₂) ds-lem-hole (HNPair hn hn₁) = HDPair (ds-lem-hole hn) (ds-lem-hole hn₁) ds-lem-hole (HNFst hn) = HDFst (ds-lem-hole hn) ds-lem-hole (HNSnd hn) = HDSnd (ds-lem-hole hn) ds-lem-hole (HNHole x) = HDHole (HNHole (flip x)) ds-lem-hole (HNNEHole x hnn) = HDNEHole (HNHole (flip x)) (ds-lem-hole hnn) ds-lem-nehole : ∀{e e1 u} → holes-disjoint e e1 → hole-name-new e u → holes-disjoint e ⦇⌜ e1 ⌟⦈[ u ] ds-lem-nehole HDNum ν = HDNum ds-lem-nehole (HDPlus hd hd₁) (HNPlus ν ν₁) = HDPlus (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁) ds-lem-nehole (HDAsc hd) (HNAsc ν) = HDAsc (ds-lem-nehole hd ν) ds-lem-nehole HDVar ν = HDVar ds-lem-nehole (HDLam1 hd) (HNLam1 ν) = HDLam1 (ds-lem-nehole hd ν) ds-lem-nehole (HDLam2 hd) (HNLam2 ν) = HDLam2 (ds-lem-nehole hd ν) ds-lem-nehole (HDAp hd hd₁) (HNAp ν ν₁) = HDAp (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁) ds-lem-nehole (HDInl hd) (HNInl ν) = HDInl (ds-lem-nehole hd ν) ds-lem-nehole (HDInr hd) (HNInr ν) = HDInr (ds-lem-nehole hd ν) ds-lem-nehole (HDCase hd hd₁ hd₂) (HNCase ν ν₁ ν₂) = HDCase (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁) (ds-lem-nehole hd₂ ν₂) ds-lem-nehole (HDPair hd hd₁) (HNPair ν ν₁) = HDPair (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁) ds-lem-nehole (HDFst hd) (HNFst ν) = HDFst (ds-lem-nehole hd ν) ds-lem-nehole (HDSnd hd) (HNSnd ν) = HDSnd (ds-lem-nehole hd ν) ds-lem-nehole (HDHole x) (HNHole x₁) = HDHole (HNNEHole (flip x₁) x) ds-lem-nehole (HDNEHole x hd) (HNNEHole x₁ ν) = HDNEHole (HNNEHole (flip x₁) x) (ds-lem-nehole hd ν) -- holes-disjoint is symmetric disjoint-sym : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint e2 e1 disjoint-sym HDNum = ds-lem-num disjoint-sym (HDPlus hd hd₁) = ds-lem-plus (disjoint-sym hd) (disjoint-sym hd₁) disjoint-sym (HDAsc hd) = ds-lem-asc (disjoint-sym hd) disjoint-sym HDVar = ds-lem-var disjoint-sym (HDLam1 hd) = ds-lem-lam1 (disjoint-sym hd) disjoint-sym (HDLam2 hd) = ds-lem-lam2 (disjoint-sym hd) disjoint-sym (HDAp hd hd₁) = ds-lem-ap (disjoint-sym hd) (disjoint-sym hd₁) disjoint-sym (HDInl hd) = ds-lem-inl (disjoint-sym hd) disjoint-sym (HDInr hd) = ds-lem-inr (disjoint-sym hd) disjoint-sym (HDCase hd hd₁ hd₂) = ds-lem-case (disjoint-sym hd) (disjoint-sym hd₁) (disjoint-sym hd₂) disjoint-sym (HDPair hd hd₁) = ds-lem-pair (disjoint-sym hd) (disjoint-sym hd₁) disjoint-sym (HDFst hd) = ds-lem-fst (disjoint-sym hd) disjoint-sym (HDSnd hd) = ds-lem-snd (disjoint-sym hd) disjoint-sym (HDHole x) = ds-lem-hole x disjoint-sym (HDNEHole x hd) = ds-lem-nehole (disjoint-sym hd) x -- note that this is false, so holes-disjoint isn't transitive -- disjoint-new : ∀{e1 e2 u} → holes-disjoint e1 e2 → hole-name-new e1 u → hole-name-new e2 u -- it's also not reflexive, because ⦇-⦈[ u ] isn't hole-disjoint with -- itself since refl : u == u; it's also not anti-reflexive, because the -- expression c *is* hole-disjoint with itself (albeit vacuously)
56.461794
147
0.647073
3419cacb308908cff9e6590f9bddf3d1e8ab9290
213
agda
Agda
RW/Data/RTrie.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
16
2015-02-09T15:43:38.000Z
2019-10-24T17:38:20.000Z
RW/Data/RTrie.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
4
2015-02-06T15:03:33.000Z
2015-05-28T14:48:03.000Z
RW/Data/RTrie.agda
VictorCMiraldo/agda-rw
2856afd12b7dbbcc908482975638d99220f38bf2
[ "MIT" ]
null
null
null
module RW.Data.RTrie where open import RW.Data.RTrie.Decl public open import RW.Data.RTrie.Insert using (insertTerm) public open import RW.Data.RTrie.Lookup renaming (lookup to lookupTerm) public
26.625
42
0.751174
38439f46cc834f4870346b0a99e38543303c0a5b
2,239
agda
Agda
MUniverse.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
1
2019-08-08T12:52:30.000Z
2019-08-08T12:52:30.000Z
MUniverse.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
MUniverse.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
module MUniverse where -- This is universe polymorphism and extensional equality module open import Sec2 -- import Data.List data _≃₀_ {A : Set} (a : A) (b : A) : Set where a≃b : (a ≡ b) → a ≃₀ b data _≃₁_ {A : Set} (f : A → A) (g : A → A) : Set where f≃g : ((x y : A) → (x ≃₀ y) → (f x ≃₀ g y)) → f ≃₁ g B==B : 1 ≃₀ 1 B==B = a≃b refl B==B1 : T ≃₀ T B==B1 = a≃b refl -- This is the same as + for natural numbers _⋆_ : (x y : ℕ) → ℕ Z ⋆ y = y (S x) ⋆ y = S (x ⋆ y) -- Proof that + and ⋆ are equivalent functions! +==⋆ : (x : ℕ) → ((_+_) x) ≃₁ ((_⋆_) x) +==⋆ x = f≃g (λ x₁ y x₂ → a≃b (prove x x₁ y x₂)) where fcong : (x y : ℕ) → (p : (x + y) ≡ (x ⋆ y)) → S (x + y) ≡ S (x ⋆ y) fcong x y p with (x + y) | (x ⋆ y) fcong x y refl | m | .m = refl prove' : (x y : ℕ) → (x + y) ≡ (x ⋆ y) prove' Z y = refl prove' (S x) y with (prove' x y) prove' (S x) y | p = fcong x y p prove : (x y z : ℕ) → (p : y ≃₀ z) → (x + y) ≡ (x ⋆ z) prove x y .y (a≃b refl) = prove' x y elim≃₁ : {A : Set} → (f g : A → A) (a : f ≃₁ g) → (x y : A) → (p : x ≃₀ y) → (f x ≃₀ g y) elim≃₁ f g (f≃g a) x .x (a≃b refl) = a x x (a≃b refl) -- Theorem that ≃₁ is a partial equivalence relation ≃₁-symmetric : {A : Set} → {f g : A → A} → (f ≃₁ g) → (g ≃₁ f) ≃₁-symmetric {A} {f} {g} (f≃g x) = f≃g (λ x₁ y x₂ → a≃b (prove x₁ y x₂ (f≃g x))) where prove : (z y : A) → (p : z ≃₀ y) → (f ≃₁ g) → (g z ≡ f y) prove z .z (a≃b refl) (f≃g x) with (x z z (a≃b refl) ) prove z .z (a≃b refl) (f≃g x₁) | a≃b p with (f z) | (g z) prove z .z (a≃b refl) (f≃g x₁) | a≃b refl | m | .m = refl ≃₁-transitive : {A : Set} → {f g h : A → A} → (f ≃₁ g) → (g ≃₁ h) → (f ≃₁ h) ≃₁-transitive {A} {f} {g} {h} (f≃g x) (f≃g y) = f≃g (λ x₁ y₁ x₂ → a≃b (prove x₁ y₁ x₂ (f≃g x) (f≃g y))) where prove : (x y : A) (p : x ≃₀ y) → (f ≃₁ g) → (g ≃₁ h) → (f x ≡ h y) prove x₁ .x₁ (a≃b refl) (f≃g x₂) (f≃g x₃) with (x₂ x₁ x₁ (a≃b refl)) | (x₃ x₁ x₁ (a≃b refl)) prove x₁ .x₁ (a≃b refl) (f≃g x₂) (f≃g x₃) | a≃b x₄ | a≃b x₅ with (f x₁) | (g x₁) | (h x₁) prove x₁ .x₁ (a≃b refl) (f≃g x₂) (f≃g x₃) | a≃b refl | a≃b refl | p1 | .p1 | .p1 = refl
33.41791
103
0.438589
7cc0443a68f0e188c73a726402b46555ed5295ab
9,524
agda
Agda
TotalParserCombinators/ExpressiveStrength.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
TotalParserCombinators/ExpressiveStrength.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
TotalParserCombinators/ExpressiveStrength.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- This module proves that the parser combinators correspond exactly -- to functions of type List Tok → List R (if bag equality is used for -- the lists of results) ------------------------------------------------------------------------ module TotalParserCombinators.ExpressiveStrength where open import Coinduction open import Data.Bool open import Data.List as List open import Data.List.Any open import Data.List.Any.Membership.Propositional import Data.List.Properties as ListProp open import Data.List.Reverse open import Data.Product open import Function open import Function.Inverse using (_↔_) import Function.Related as Related open import Relation.Binary.PropositionalEquality as P using (_≡_; refl) open import Relation.Binary.HeterogeneousEquality using (_≅_; _≇_; refl) open import Relation.Nullary open import TotalParserCombinators.Parser open import TotalParserCombinators.Semantics as S hiding (_≅_; _∼[_]_; token) open import TotalParserCombinators.Lib private open module Tok = Token Bool _≟_ using (tok) open import TotalParserCombinators.BreadthFirst as Backend using (parse) ------------------------------------------------------------------------ -- Expressive strength -- One direction of the correspondence has already been established: -- For every parser there is an equivalent function. parser⇒fun : ∀ {R xs} (p : Parser Bool R xs) {x s} → x ∈ p · s ↔ x ∈ parse p s parser⇒fun p = Backend.parse-correct -- For every function there is a corresponding parser. module Monadic where -- The parser. grammar : ∀ {Tok R} (f : List Tok → List R) → Parser Tok R (f []) grammar f = token >>= (λ t → ♯ grammar (f ∘ _∷_ t)) ∣ return⋆ (f []) -- Correctness proof. grammar-correct : ∀ {Tok R} (f : List Tok → List R) {x s} → x ∈ grammar f · s ↔ x ∈ f s grammar-correct f {s = s} = record { to = P.→-to-⟶ (sound f) ; from = P.→-to-⟶ (complete f s) ; inverse-of = record { left-inverse-of = complete∘sound f ; right-inverse-of = sound∘complete f s } } where sound : ∀ {Tok R x s} (f : List Tok → List R) → x ∈ grammar f · s → x ∈ f s sound f (∣-right ._ x∈) with Return⋆.sound (f []) x∈ ... | (refl , x∈′) = x∈′ sound f (∣-left (S.token {t} >>= x∈)) = sound (f ∘ _∷_ t) x∈ complete : ∀ {Tok R x} (f : List Tok → List R) s → x ∈ f s → x ∈ grammar f · s complete f [] x∈ = ∣-right [] (Return⋆.complete x∈) complete f (t ∷ s) x∈ = ∣-left ([ ○ - ◌ ] S.token >>= complete (f ∘ _∷_ t) s x∈) complete∘sound : ∀ {Tok R x s} (f : List Tok → List R) (x∈pf : x ∈ grammar f · s) → complete f s (sound f x∈pf) ≡ x∈pf complete∘sound f (∣-left (S.token {t} >>= x∈)) rewrite complete∘sound (f ∘ _∷_ t) x∈ = refl complete∘sound f (∣-right .[] x∈) with Return⋆.sound (f []) x∈ | Return⋆.complete∘sound (f []) x∈ complete∘sound f (∣-right .[] .(Return⋆.complete x∈f[])) | (refl , x∈f[]) | refl = refl sound∘complete : ∀ {Tok R x} (f : List Tok → List R) s (x∈fs : x ∈ f s) → sound f (complete f s x∈fs) ≡ x∈fs sound∘complete f (t ∷ s) x∈ = sound∘complete (f ∘ _∷_ t) s x∈ sound∘complete {Tok} f [] x∈ with Return⋆.sound {Tok = Tok} (f []) (Return⋆.complete x∈) | Return⋆.sound∘complete {Tok = Tok} x∈ ... | (refl , .x∈) | refl = refl -- A corollary. maximally-expressive : ∀ {Tok R} (f : List Tok → List R) {s} → parse (grammar f) s ∼[ bag ] f s maximally-expressive f {s} {x} = (x ∈ parse (grammar f) s) ↔⟨ sym Backend.parse-correct ⟩ x ∈ grammar f · s ↔⟨ grammar-correct f ⟩ x ∈ f s ∎ where open Related.EquationalReasoning -- If the token type is finite (in this case Bool), then the result -- above can be established without the use of bind (_>>=_). (The -- definition of tok uses bind, but if bind were removed it would be -- reasonable to either add tok as a primitive combinator, or make it -- possible to define tok using other combinators.) module Applicative where -- A helper function. specialise : {A B : Set} → (List A → B) → A → (List A → B) specialise f x = λ xs → f (xs ∷ʳ x) -- The parser. grammar : ∀ {R} (f : List Bool → List R) → Parser Bool R (f []) grammar f = ♯ (const <$> grammar (specialise f true )) ⊛ tok true ∣ ♯ (const <$> grammar (specialise f false)) ⊛ tok false ∣ return⋆ (f []) -- Correctness proof. grammar-correct : ∀ {R} (f : List Bool → List R) {x s} → x ∈ grammar f · s ↔ x ∈ f s grammar-correct {R} f {s = s} = record { to = P.→-to-⟶ (sound f) ; from = P.→-to-⟶ (complete f (reverseView s)) ; inverse-of = record { right-inverse-of = sound∘complete f (reverseView s) ; left-inverse-of = λ x∈ → complete∘sound f (reverseView s) _ x∈ refl refl } } where sound : ∀ {x : R} {s} f → x ∈ grammar f · s → x ∈ f s sound f (∣-right ._ x∈) with Return⋆.sound (f []) x∈ ... | (refl , x∈′) = x∈′ sound f (∣-left (∣-left (<$> x∈ ⊛ t∈))) with Tok.sound true t∈ ... | (refl , refl) = sound (specialise f true ) x∈ sound f (∣-left (∣-right ._ (<$> x∈ ⊛ t∈))) with Tok.sound false t∈ ... | (refl , refl) = sound (specialise f false) x∈ complete : ∀ {x : R} {s} f → Reverse s → x ∈ f s → x ∈ grammar f · s complete f [] x∈ = ∣-right [] (Return⋆.complete x∈) complete f (bs ∶ rs ∶ʳ true ) x∈ = ∣-left {xs₁ = []} (∣-left ( [ ◌ - ○ ] <$> complete (specialise f true ) rs x∈ ⊛ Tok.complete)) complete f (bs ∶ rs ∶ʳ false) x∈ = ∣-left (∣-right [] ( [ ◌ - ○ ] <$> complete (specialise f false) rs x∈ ⊛ Tok.complete)) sound∘complete : ∀ {x : R} {s} f (rs : Reverse s) (x∈fs : x ∈ f s) → sound f (complete f rs x∈fs) ≡ x∈fs sound∘complete f [] x∈ rewrite Return⋆.sound∘complete {Tok = Bool} x∈ = refl sound∘complete f (bs ∶ rs ∶ʳ true) x∈ = sound∘complete (specialise f true) rs x∈ sound∘complete f (bs ∶ rs ∶ʳ false) x∈ = sound∘complete (specialise f false) rs x∈ complete∘sound : ∀ {x : R} {s s′ : List Bool} f (rs : Reverse s) (rs′ : Reverse s′) (x∈pf : x ∈ grammar f · s) → s ≡ s′ → rs ≅ rs′ → complete f rs (sound f x∈pf) ≡ x∈pf complete∘sound f rs rs′ (∣-right ._ x∈) s≡ rs≅ with Return⋆.sound (f []) x∈ | Return⋆.complete∘sound (f []) x∈ complete∘sound f ._ [] (∣-right ._ .(Return⋆.complete x∈′)) refl refl | (refl , x∈′) | refl = refl complete∘sound f _ ([] ∶ _ ∶ʳ _) (∣-right ._ .(Return⋆.complete x∈′)) () _ | (refl , x∈′) | refl complete∘sound f _ ((_ ∷ _) ∶ _ ∶ʳ _) (∣-right ._ .(Return⋆.complete x∈′)) () _ | (refl , x∈′) | refl complete∘sound f rs rs′ (∣-left (∣-left (<$> x∈ ⊛ t∈))) s≡ rs≅ with Tok.sound true t∈ complete∘sound f rs (bs′ ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) with proj₁ $ ListProp.∷ʳ-injective bs bs′ s≡ complete∘sound f rs (.bs ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl with s≡ | rs≅ complete∘sound f ._ (.bs ∶ rs′ ∶ʳ true) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl | refl | refl rewrite complete∘sound (specialise f true) rs′ rs′ x∈ refl refl | Tok.η t∈ = refl complete∘sound f rs (bs′ ∶ rs′ ∶ʳ false) (∣-left (∣-left (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) with proj₂ $ ListProp.∷ʳ-injective bs bs′ s≡ ... | () complete∘sound f rs [] (∣-left (∣-left (_⊛_ {s₁ = []} (<$> x∈) t∈))) () _ | (refl , refl) complete∘sound f rs [] (∣-left (∣-left (_⊛_ {s₁ = _ ∷ _} (<$> x∈) t∈))) () _ | (refl , refl) complete∘sound f rs rs′ (∣-left (∣-right ._ (<$> x∈ ⊛ t∈))) s≡ rs≅ with Tok.sound false t∈ complete∘sound f rs (bs′ ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) with proj₁ $ ListProp.∷ʳ-injective bs bs′ s≡ complete∘sound f rs (.bs ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl with s≡ | rs≅ complete∘sound f ._ (.bs ∶ rs′ ∶ʳ false) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) | refl | refl | refl rewrite complete∘sound (specialise f false) rs′ rs′ x∈ refl refl | Tok.η t∈ = refl complete∘sound f rs (bs′ ∶ rs′ ∶ʳ true) (∣-left (∣-right ._ (_⊛_ {s₁ = bs} (<$> x∈) t∈))) s≡ rs≅ | (refl , refl) with proj₂ $ ListProp.∷ʳ-injective bs bs′ s≡ ... | () complete∘sound f rs [] (∣-left (∣-right ._ (_⊛_ {s₁ = []} (<$> x∈) t∈))) () _ | (refl , refl) complete∘sound f rs [] (∣-left (∣-right ._ (_⊛_ {s₁ = _ ∷ _} (<$> x∈) t∈))) () _ | (refl , refl) -- A corollary. maximally-expressive : ∀ {R} (f : List Bool → List R) {s} → parse (grammar f) s ∼[ bag ] f s maximally-expressive f {s} {x} = (x ∈ parse (grammar f) s) ↔⟨ sym Backend.parse-correct ⟩ x ∈ grammar f · s ↔⟨ grammar-correct f ⟩ x ∈ f s ∎ where open Related.EquationalReasoning
43.290909
138
0.517745
0d1dfc6f0bd0a10b5af550998d07bb75fed46d33
8,173
agda
Agda
Cubical/HITs/Cylinder/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/Cylinder/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/Cylinder/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Cylinder.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Everything open import Cubical.HITs.PropositionalTruncation import Cubical.Data.Everything as Data open Data hiding (inl; inr) open import Cubical.HITs.Interval -- Cylinder A is a cylinder object in the category of cubical types. -- -- https://ncatlab.org/nlab/show/cylinder+object data Cylinder {ℓ} (A : Type ℓ) : Type ℓ where inl : A → Cylinder A inr : A → Cylinder A cross : ∀ x → inl x ≡ inr x -- Dual to this is the cocylinder or path space object. -- -- https://ncatlab.org/nlab/show/path+space+object Cocylinder : ∀ {ℓ} → Type ℓ → Type ℓ Cocylinder A = Interval → A module _ {ℓ} {A : Type ℓ} where -- The cylinder is part of a factorization of the obvious mapping -- of type A ⊎ A → A into a pair of mappings: -- -- A ⊎ A → Cylinder A ≃ A -- -- include is the first part of the factorization. include : A ⊎ A → Cylinder A include (Data.inl x) = inl x include (Data.inr x) = inr x -- The above inclusion is surjective includeSurjective : ∀ c → ∥ Σ[ s ∈ A ⊎ A ] include s ≡ c ∥ includeSurjective (inl x) = ∣ Data.inl x , refl ∣ includeSurjective (inr x) = ∣ Data.inr x , refl ∣ includeSurjective (cross x i) = squash ∣ Data.inl x , (λ j → cross x (i ∧ j)) ∣ ∣ Data.inr x , (λ j → cross x (i ∨ ~ j)) ∣ i elimCyl : ∀{ℓ'} {B : Cylinder A → Type ℓ'} → (f : (x : A) → B (inl x)) → (g : (x : A) → B (inr x)) → (p : ∀ x → PathP (λ i → B (cross x i)) (f x) (g x)) → (c : Cylinder A) → B c elimCyl f _ _ (inl x) = f x elimCyl _ g _ (inr x) = g x elimCyl _ _ p (cross x i) = p x i private out : Cylinder A → A out (inl x) = x out (inr x) = x out (cross x i) = x inl-out : (c : Cylinder A) → inl (out c) ≡ c inl-out (inl x) = refl inl-out (inr x) = cross x inl-out (cross x i) = λ j → cross x (i ∧ j) out-inl : ∀(x : A) → out (inl x) ≡ x out-inl x = refl -- The second part of the factorization above. CylinderA≃A : Cylinder A ≃ A CylinderA≃A = isoToEquiv (iso out inl out-inl inl-out) -- The cocylinder has a similar equivalence that is part -- of factorizing the diagonal mapping. private inco : A → Cocylinder A inco x _ = x outco : Cocylinder A → A outco f = f zero A→CocylinderA→A : (x : A) → outco (inco x) ≡ x A→CocylinderA→A x = refl CocylinderA→A→CocylinderA : (c : Cocylinder A) → inco (outco c) ≡ c CocylinderA→A→CocylinderA c j zero = c zero CocylinderA→A→CocylinderA c j one = c (seg j) CocylinderA→A→CocylinderA c j (seg i) = c (seg (j ∧ i)) A≃CocylinderA : A ≃ Cocylinder A A≃CocylinderA = isoToEquiv (iso inco outco CocylinderA→A→CocylinderA A→CocylinderA→A) project : Cocylinder A → A × A project c = c zero , c one -- Since we can construct cylinders for every type, Cylinder actually -- constitutes a cylinder functor: -- -- https://ncatlab.org/nlab/show/cylinder+functor -- -- e₀ = inl -- e₁ = inr -- σ = out module Functorial where private variable ℓa ℓb ℓc : Level A : Type ℓa B : Type ℓb C : Type ℓc mapCylinder : (A → B) → Cylinder A → Cylinder B mapCylinder f (inl x) = inl (f x) mapCylinder f (inr x) = inr (f x) mapCylinder f (cross x i) = cross (f x) i mapCylinderId : mapCylinder (λ(x : A) → x) ≡ (λ x → x) mapCylinderId i (inl x) = inl x mapCylinderId i (inr x) = inr x mapCylinderId i (cross x j) = cross x j mapCylinder∘ : (f : A → B) → (g : B → C) → mapCylinder (λ x → g (f x)) ≡ (λ x → mapCylinder g (mapCylinder f x)) mapCylinder∘ f g i (inl x) = inl (g (f x)) mapCylinder∘ f g i (inr x) = inr (g (f x)) mapCylinder∘ f g i (cross x j) = cross (g (f x)) j -- There is an adjunction between the cylinder and coyclinder -- functors. -- -- Cylinder ⊣ Cocylinder adj₁ : (Cylinder A → B) → A → Cocylinder B adj₁ f x zero = f (inl x) adj₁ f x one = f (inr x) adj₁ f x (seg i) = f (cross x i) adj₂ : (A → Cocylinder B) → Cylinder A → B adj₂ g (inl x) = g x zero adj₂ g (inr x) = g x one adj₂ g (cross x i) = g x (seg i) adj₁₂ : (g : A → Cocylinder B) → adj₁ (adj₂ g) ≡ g adj₁₂ g _ x zero = g x zero adj₁₂ g _ x one = g x one adj₁₂ g _ x (seg i) = g x (seg i) adj₂₁ : (f : Cylinder A → B) → adj₂ (adj₁ f) ≡ f adj₂₁ f j (inl x) = f (inl x) adj₂₁ f j (inr x) = f (inr x) adj₂₁ f j (cross x i) = f (cross x i) module IntervalEquiv where -- There is an equivalence between the interval and the -- cylinder over the unit type. Interval→CylinderUnit : Interval → Cylinder Unit Interval→CylinderUnit zero = inl _ Interval→CylinderUnit one = inr _ Interval→CylinderUnit (seg i) = cross _ i CylinderUnit→Interval : Cylinder Unit → Interval CylinderUnit→Interval (inl _) = zero CylinderUnit→Interval (inr _) = one CylinderUnit→Interval (cross _ i) = seg i Interval→CylinderUnit→Interval : ∀ i → CylinderUnit→Interval (Interval→CylinderUnit i) ≡ i Interval→CylinderUnit→Interval zero = refl Interval→CylinderUnit→Interval one = refl Interval→CylinderUnit→Interval (seg i) = refl CylinderUnit→Interval→CylinderUnit : ∀ c → Interval→CylinderUnit (CylinderUnit→Interval c) ≡ c CylinderUnit→Interval→CylinderUnit (inl _) = refl CylinderUnit→Interval→CylinderUnit (inr _) = refl CylinderUnit→Interval→CylinderUnit (cross _ i) = refl CylinderUnit≃Interval : Cylinder Unit ≃ Interval CylinderUnit≃Interval = isoToEquiv (iso CylinderUnit→Interval Interval→CylinderUnit Interval→CylinderUnit→Interval CylinderUnit→Interval→CylinderUnit) -- More generally, there is an equivalence between the cylinder -- over any type A and the product of A and the interval. module _ {ℓ} {A : Type ℓ} where private Cyl : Type ℓ Cyl = A × Interval CylinderA→A×Interval : Cylinder A → Cyl CylinderA→A×Interval (inl x) = x , zero CylinderA→A×Interval (inr x) = x , one CylinderA→A×Interval (cross x i) = x , seg i A×Interval→CylinderA : Cyl → Cylinder A A×Interval→CylinderA (x , zero) = inl x A×Interval→CylinderA (x , one) = inr x A×Interval→CylinderA (x , seg i) = cross x i A×Interval→CylinderA→A×Interval : ∀ c → CylinderA→A×Interval (A×Interval→CylinderA c) ≡ c A×Interval→CylinderA→A×Interval (x , zero) = refl A×Interval→CylinderA→A×Interval (x , one) = refl A×Interval→CylinderA→A×Interval (x , seg i) = refl CylinderA→A×Interval→CylinderA : ∀ c → A×Interval→CylinderA (CylinderA→A×Interval c) ≡ c CylinderA→A×Interval→CylinderA (inl x) = refl CylinderA→A×Interval→CylinderA (inr x) = refl CylinderA→A×Interval→CylinderA (cross x i) = refl CylinderA≃A×Interval : Cylinder A ≃ Cyl CylinderA≃A×Interval = isoToEquiv (iso CylinderA→A×Interval A×Interval→CylinderA A×Interval→CylinderA→A×Interval CylinderA→A×Interval→CylinderA) -- The cylinder is also the pushout of the identity on A with itself. module Push {ℓ} {A : Type ℓ} where open import Cubical.HITs.Pushout private Push : Type ℓ Push = Pushout (λ(x : A) → x) (λ x → x) Cyl : Type ℓ Cyl = Cylinder A Cylinder→Pushout : Cyl → Push Cylinder→Pushout (inl x) = inl x Cylinder→Pushout (inr x) = inr x Cylinder→Pushout (cross x i) = push x i Pushout→Cylinder : Push → Cyl Pushout→Cylinder (inl x) = inl x Pushout→Cylinder (inr x) = inr x Pushout→Cylinder (push x i) = cross x i Pushout→Cylinder→Pushout : ∀ p → Cylinder→Pushout (Pushout→Cylinder p) ≡ p Pushout→Cylinder→Pushout (inl x) = refl Pushout→Cylinder→Pushout (inr x) = refl Pushout→Cylinder→Pushout (push x i) = refl Cylinder→Pushout→Cylinder : ∀ c → Pushout→Cylinder (Cylinder→Pushout c) ≡ c Cylinder→Pushout→Cylinder (inl x) = refl Cylinder→Pushout→Cylinder (inr x) = refl Cylinder→Pushout→Cylinder (cross x i) = refl Pushout≃Cylinder : Push ≃ Cyl Pushout≃Cylinder = isoToEquiv (iso Pushout→Cylinder Cylinder→Pushout Cylinder→Pushout→Cylinder Pushout→Cylinder→Pushout)
30.610487
130
0.637342
1be831a5af1dc2228a38251dc33af1115515885f
1,092
agda
Agda
test/Succeed/Issue899.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue899.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue899.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2013-11-07 -- Instance candidates are now considered modulo judgemental equality. {-# OPTIONS --overlapping-instances #-} module Issue899 where postulate A B : Set f : {{ x : A }} → B instance a : A instance a' : A a' = a test : B test = f {- The previous code fails with the following message: Resolve implicit argument _x_257 : A. Candidates: [a : A, a : A] There are indeed two values in scope of type A (a and a'), but given that they are definitionally equal, Agda should not complain about it but just pick any one of them. -} -- Andreas, 2017-07-28: the other example now also works, thanks to G. Brunerie record Eq (A : Set) : Set₁ where field _==_ : A → A → Set record Ord (A : Set) : Set₁ where field {{eq}} : Eq A _<_ : A → A → Set postulate N : Set eqN : N → N → Set ordN : N → N → Set instance EqN : Eq N EqN = record {_==_ = eqN} OrdN : Ord N OrdN = record {_<_ = ordN} ordToEq : {A : Set} {{_ : Ord A}} → Eq A ordToEq {{o}} = Ord.eq o postulate f2 : (A : Set) {{e : Eq A}} → Set → Set test2 = f2 N N
19.157895
79
0.611722
14273c1781ba60ff2ad06741bb4c21e9c891c9a9
92
agda
Agda
Data/Nat.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Nat.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Nat.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --without-K --safe #-} module Data.Nat where open import Data.Nat.Base public
15.333333
34
0.695652
fddda83d2b6d4d807dfec3b6a272a3786d56cb3c
431
agda
Agda
Utils.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
Utils.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
Utils.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
module Utils where open import Data.Fin using (Fin) import Data.Fin as F open import Data.Nat data Fromℕ (n : ℕ) : ℕ → Set where yes : (m : Fin n) → Fromℕ n (F.toℕ m) no : (m : ℕ) → Fromℕ n (n + m) fromℕ : ∀ n m → Fromℕ n m fromℕ zero m = no m fromℕ (suc n) zero = yes F.zero fromℕ (suc n) (suc m) with fromℕ n m fromℕ (suc n) (suc .(F.toℕ m)) | yes m = yes (F.suc m) fromℕ (suc n) (suc .(n + m)) | no m = no m
25.352941
54
0.570766
22fbb59f4a0166177aa6aac8831a213fb89bcbc2
4,805
agda
Agda
Cubical/HITs/EilenbergMacLane1/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/HITs/EilenbergMacLane1/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/HITs/EilenbergMacLane1/Properties.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{- Eilenberg–Mac Lane type K(G, 1) -} {-# OPTIONS --cubical --no-import-sorts --safe #-} 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.Equiv.HalfAdjoint open import Cubical.Foundations.Univalence open import Cubical.Foundations.Path open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Sigma open import Cubical.Algebra.Group.Base open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥; ∣_∣; squash) open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂) -- Type quotients private variable ℓG ℓ : Level module _ (G : Group {ℓG}) where open Group G elimEq : {B : EM₁ G → Type ℓ} (Bprop : (x : EM₁ G) → isProp (B x)) {x y : EM₁ G} (eq : x ≡ y) (bx : B x) (by : B y) → PathP (λ i → B (eq i)) bx by elimEq {B = B} Bprop {x = x} = J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by) elimProp : {B : EM₁ G → Type ℓ} → ((x : EM₁ G) → isProp (B x)) → B embase → (x : EM₁ G) → B x elimProp Bprop b embase = b elimProp Bprop b (emloop g i) = elimEq Bprop (emloop g) b b i elimProp Bprop b (emcomp g h i j) = isSet→isSetDep (λ x → isProp→isSet (Bprop x)) (emloop g) (emloop (g + h)) (λ j → embase) (emloop h) (emcomp g h) (λ i → elimEq Bprop (emloop g) b b i) (λ i → elimEq Bprop (emloop (g + h)) b b i) (λ j → b) (λ j → elimEq Bprop (emloop h) b b j) i j elimProp Bprop b (emsquash x y p q r s i j k) = isOfHLevel→isOfHLevelDep 3 (λ x → isSet→isGroupoid (isProp→isSet (Bprop 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 = elimProp Bprop b elimProp2 : {C : EM₁ G → EM₁ G → Type ℓ} → ((x y : EM₁ G) → isProp (C x y)) → C embase embase → (x y : EM₁ G) → C x y elimProp2 Cprop c = elimProp (λ x → isPropΠ (λ y → Cprop x y)) (elimProp (λ y → Cprop embase y) c) elimSet : {B : EM₁ G → Type ℓ} → ((x : EM₁ G) → isSet (B x)) → (b : B embase) → ((g : Carrier) → PathP (λ i → B (emloop g i)) b b) → (x : EM₁ G) → 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→isSetDep Bset (emloop g) (emloop (g + h)) (λ j → embase) (emloop h) (emcomp g h) (bloop g) (bloop (g + h)) refl (bloop h) 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 elim : {B : EM₁ G → Type ℓ} → ((x : EM₁ G) → isGroupoid (B x)) → (b : B embase) → (bloop : (g : Carrier) → PathP (λ i → B (emloop g i)) b b) → ((g h : Carrier) → SquareP (λ i j → B (emcomp g h i j)) (bloop g) (bloop (g + h)) (λ j → b) (bloop h)) → (x : EM₁ G) → 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 : Carrier → b ≡ b) → ((g h : Carrier) → Square (bloop g) (bloop (g + h)) refl (bloop h)) → (x : EM₁ G) → B rec Bgpd = elim (λ _ → Bgpd) rec' : {B : Type ℓ} → isGroupoid B → (b : B) → (bloop : Carrier → b ≡ b) → ((g h : Carrier) → (bloop g) ∙ (bloop h) ≡ bloop (g + h)) → (x : EM₁ G) → B rec' Bgpd b bloop p = rec Bgpd b bloop sq where module _ (g h : Carrier) where abstract sq : Square (bloop g) (bloop (g + h)) refl (bloop h) sq = transport (sym (Square≡doubleComp (bloop g) (bloop (g + h)) refl (bloop h))) (refl ∙∙ bloop g ∙∙ bloop h ≡⟨ doubleCompPath-elim refl (bloop g) (bloop h) ⟩ (refl ∙ bloop g) ∙ bloop h ≡⟨ cong (_∙ bloop h) (sym (lUnit (bloop g))) ⟩ bloop g ∙ bloop h ≡⟨ p g h ⟩ bloop (g + h) ∎)
33.368056
90
0.528824
7c1913710ee44a352f8bb38dbc21436c7c4580bc
1,585
agda
Agda
archive/agda-2/Oscar/Data1.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Data1.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Data1.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
{- constructions on ℕ, everything I could think of that seemed interesting -} -- "interesting"=? -- maybe some of these should be discarded. e.g. ⟦⟧ is just an instance of ⟦_⟧, namely ⟦ ⊤ ⟧ -- maybe add a record version of ≤ -- categorise -- what about ≡? module Oscar.Data1 where -- Nat data ⟦⟧ : Set where ∅ : ⟦⟧ ! : ⟦⟧ → ⟦⟧ -- List data ⟦_⟧ {a} (A : Set a) : Set a where ∅ : ⟦ A ⟧ _∷_ : A → ⟦ A ⟧ → ⟦ A ⟧ -- Fin data ⟦⟧[_] : ⟦⟧ → Set where ∅ : ∀ {n} → ⟦⟧[ ! n ] ! : ∀ {n} → ⟦⟧[ n ] → ⟦⟧[ ! n ] -- same, with payload data ⟦_⟧[_] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where ∅ : ∀ {n} → ⟦ A ⟧[ ! n ] _∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ] → ⟦ A ⟧[ ! n ] -- m ≤ n, counting down from n-1 to m data ⟦⟧[_≤↓_] (m : ⟦⟧) : ⟦⟧ → Set where ∅ : ⟦⟧[ m ≤↓ m ] ! : ∀ {n} → ⟦⟧[ m ≤↓ n ] → ⟦⟧[ m ≤↓ ! n ] -- same, with payload data ⟦_⟧[_≤↓_] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where ∅ : ⟦ A ⟧[ m ≤↓ m ] _∷_ : ∀ {n} → A n → ⟦ A ⟧[ m ≤↓ n ] → ⟦ A ⟧[ m ≤↓ ! n ] -- m ≤ n, counting up from m to n-1 data ⟦⟧[_↑≤_] (m : ⟦⟧) : ⟦⟧ → Set where ∅ : ⟦⟧[ m ↑≤ m ] ! : ∀ {n} → ⟦⟧[ ! m ↑≤ n ] → ⟦⟧[ m ↑≤ n ] -- same, with payload data ⟦_⟧[_↑≤_] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where ∅ : ⟦ A ⟧[ m ↑≤ m ] _∷_ : ∀ {n} → A m → ⟦ A ⟧[ ! m ↑≤ n ] → ⟦ A ⟧[ m ↑≤ n ] -- Inj data ⟦⟧[_↓≤↓_] : ⟦⟧ → ⟦⟧ → Set where ∅ : ∀ {n} → ⟦⟧[ ∅ ↓≤↓ n ] ! : ∀ {m n} → ⟦⟧[ m ↓≤↓ n ] → ⟦⟧[ ! m ↓≤↓ ! n ] -- same, with payload data ⟦_⟧[_↓≤↓_] {a} (A : ⟦⟧ → ⟦⟧ → Set a) : ⟦⟧ → ⟦⟧ → Set a where ∅ : ∀ {n} → ⟦ A ⟧[ ∅ ↓≤↓ n ] ! : ∀ {m n} → A m n → ⟦ A ⟧[ m ↓≤↓ n ] → ⟦ A ⟧[ ! m ↓≤↓ ! n ]
27.327586
92
0.364038
142a3d714b26d153dcb9f935e45f86943c1a63be
422
agda
Agda
test/Succeed/RewriteConstructorParsAreGeneral.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/RewriteConstructorParsAreGeneral.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/RewriteConstructorParsAreGeneral.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --rewriting #-} open import Agda.Builtin.Bool open import Agda.Builtin.Equality {-# BUILTIN REWRITE _≡_ #-} data D (A : Set) : Set where c c' : D A module M (A : Set) where postulate rew : c {A} ≡ c' {A} {-# REWRITE rew #-} test : ∀ {B} → c {B} ≡ c' {B} test = refl -- Jesper, 2020-06-17: Parameters are now considered to be fully -- general, so this rewrite rule is now accepted (see #3538).
20.095238
64
0.613744
3757ac8691d8fc5c1b3eab625bf0594c25f518b5
760
agda
Agda
main/Util/DecEq.agda
awswan/nielsenschreier-hott
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
[ "MIT" ]
null
null
null
main/Util/DecEq.agda
awswan/nielsenschreier-hott
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
[ "MIT" ]
null
null
null
main/Util/DecEq.agda
awswan/nielsenschreier-hott
84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Coproduct open import lib.types.Sigma {- Some miscellaneous lemmas for types with decidable equality. -} module Util.DecEq where ×-has-dec-eq : {i j : ULevel} {A : Type i} {B : Type j} → (has-dec-eq A) → (has-dec-eq B) → (has-dec-eq (A × B)) ×-has-dec-eq Adec Bdec (a , b) (a' , b') = ⊔-rec (⊔-rec (λ p q → inl (pair×= q p)) (λ f _ → inr (λ p → f (ap snd p))) (Bdec b b')) (λ f → inr (λ p → f (ap fst p))) (Adec a a') equiv-preserves-dec-eq : {i j : ULevel} {A : Type i} {B : Type j} → (A ≃ B) → (has-dec-eq B) → has-dec-eq A equiv-preserves-dec-eq e Adec a a' = ⊔-rec (λ p → inl (–>-is-inj e a a' p)) (λ f → inr (λ p → f (ap (–> e) p))) (Adec (–> e a) (–> e a'))
33.043478
94
0.543421
d1864ad4b994529771d7eff7363a335305ff1610
12,575
agda
Agda
Cubical/HITs/SetQuotients/Properties.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/HITs/SetQuotients/Properties.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/HITs/SetQuotients/Properties.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{- Set quotients: -} {-# OPTIONS --safe #-} module Cubical.HITs.SetQuotients.Properties where open import Cubical.HITs.SetQuotients.Base open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Univalence open import Cubical.Functions.FunExtEquiv open import Cubical.Data.Sigma open import Cubical.Relation.Nullary open import Cubical.Relation.Binary.Base open import Cubical.HITs.TypeQuotients as TypeQuot using (_/ₜ_ ; [_] ; eq/) open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥ ; ∣_∣ ; squash) open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂ ; ∣_∣₂ ; squash₂ ; isSetSetTrunc) private variable ℓ ℓ' ℓ'' : Level A B C Q : Type ℓ R S T W : A → A → Type ℓ elimProp : {P : A / R → Type ℓ} → (∀ x → isProp (P x)) → (∀ a → P [ a ]) → ∀ x → P x elimProp prop f [ x ] = f x elimProp prop f (squash/ x y p q i j) = isOfHLevel→isOfHLevelDep 2 (λ x → isProp→isSet (prop x)) (g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j where g = elimProp prop f elimProp prop f (eq/ a b r i) = isProp→PathP (λ i → prop (eq/ a b r i)) (f a) (f b) i elimProp2 : {P : A / R → B / S → Type ℓ} → (∀ x y → isProp (P x y)) → (∀ a b → P [ a ] [ b ]) → ∀ x y → P x y elimProp2 prop f = elimProp (λ x → isPropΠ (prop x)) λ a → elimProp (prop [ a ]) (f a) elimProp3 : {P : A / R → B / S → C / T → Type ℓ} → (∀ x y z → isProp (P x y z)) → (∀ a b c → P [ a ] [ b ] [ c ]) → ∀ x y z → P x y z elimProp3 prop f = elimProp (λ x → isPropΠ2 (prop x)) λ a → elimProp2 (prop [ a ]) (f a) elimProp4 : {P : A / R → B / S → C / T → Q / W → Type ℓ} → (∀ x y z t → isProp (P x y z t)) → (∀ a b c d → P [ a ] [ b ] [ c ] [ d ]) → ∀ x y z t → P x y z t elimProp4 prop f = elimProp (λ x → isPropΠ3 (prop x)) λ a → elimProp3 (prop [ a ]) (f a) -- sometimes more convenient: elimContr : {P : A / R → Type ℓ} → (∀ a → isContr (P [ a ])) → ∀ x → P x elimContr contr = elimProp (elimProp (λ _ → isPropIsProp) λ _ → isContr→isProp (contr _)) λ _ → contr _ .fst elimContr2 : {P : A / R → B / S → Type ℓ} → (∀ a b → isContr (P [ a ] [ b ])) → ∀ x y → P x y elimContr2 contr = elimContr λ _ → isOfHLevelΠ 0 (elimContr λ _ → inhProp→isContr (contr _ _) isPropIsContr) -- lemma 6.10.2 in hott book []surjective : (x : A / R) → ∃[ a ∈ A ] [ a ] ≡ x []surjective = elimProp (λ x → squash) (λ a → ∣ a , refl ∣) elim : {P : A / R → Type ℓ} → (∀ x → isSet (P x)) → (f : (a : A) → (P [ a ])) → ((a b : A) (r : R a b) → PathP (λ i → P (eq/ a b r i)) (f a) (f b)) → ∀ x → P x elim set f feq [ a ] = f a elim set f feq (eq/ a b r i) = feq a b r i elim set f feq (squash/ x y p q i j) = isOfHLevel→isOfHLevelDep 2 set (g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j where g = elim set f feq rec : isSet B → (f : A → B) → ((a b : A) (r : R a b) → f a ≡ f b) → A / R → B rec set f feq [ a ] = f a rec set f feq (eq/ a b r i) = feq a b r i rec set f feq (squash/ x y p q i j) = set (g x) (g y) (cong g p) (cong g q) i j where g = rec set f feq rec2 : isSet C → (f : A → B → C) → (∀ a b c → R a b → f a c ≡ f b c) → (∀ a b c → S b c → f a b ≡ f a c) → A / R → B / S → C rec2 set f feql feqr = rec (isSetΠ (λ _ → set)) (λ a → rec set (f a) (feqr a)) (λ a b r → funExt (elimProp (λ _ → set _ _) (λ c → feql a b c r))) -- the recursor for maps into groupoids: -- i.e. for any type A with a binary relation R and groupoid B, -- we can construct a map A / R → B from a map A → B satisfying the conditions -- (i) ∀ (a b : A) → R a b → f a ≡ f b -- (ii) ∀ (a b : A) → isProp (f a ≡ f b) -- We start by proving that we can recover the set-quotient -- by set-truncating the (non-truncated type quotient) typeQuotSetTruncIso : Iso (A / R) ∥ A /ₜ R ∥₂ Iso.fun typeQuotSetTruncIso = rec isSetSetTrunc (λ a → ∣ [ a ] ∣₂) λ a b r → cong ∣_∣₂ (eq/ a b r) Iso.inv typeQuotSetTruncIso = SetTrunc.rec squash/ (TypeQuot.rec [_] eq/) Iso.rightInv typeQuotSetTruncIso = SetTrunc.elim (λ _ → isProp→isSet (squash₂ _ _)) (TypeQuot.elimProp (λ _ → squash₂ _ _) λ _ → refl) Iso.leftInv typeQuotSetTruncIso = elimProp (λ _ → squash/ _ _) λ _ → refl module rec→Gpd {B : Type ℓ''} (Bgpd : isGroupoid B) (f : A → B) (feq : ∀ (a b : A) → R a b → f a ≡ f b) (fprop : ∀ (a b : A) → isProp (f a ≡ f b)) where fun : A / R → B fun = f₁ ∘ f₂ where f₁ : ∥ A /ₜ R ∥₂ → B f₁ = SetTrunc.rec→Gpd.fun Bgpd f/ congF/Const where f/ : A /ₜ R → B f/ = TypeQuot.rec f feq congF/Const : (a b : A /ₜ R) (p q : a ≡ b) → cong f/ p ≡ cong f/ q congF/Const = TypeQuot.elimProp2 (λ _ _ → isPropΠ2 λ _ _ → Bgpd _ _ _ _) (λ a b p q → fprop a b (cong f/ p) (cong f/ q)) f₂ : A / R → ∥ A /ₜ R ∥₂ f₂ = Iso.fun typeQuotSetTruncIso setQuotUniversalIso : isSet B → Iso (A / R → B) (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b)) Iso.fun (setQuotUniversalIso Bset) g = (λ a → g [ a ]) , λ a b r i → g (eq/ a b r i) Iso.inv (setQuotUniversalIso Bset) h = rec Bset (fst h) (snd h) Iso.rightInv (setQuotUniversalIso Bset) h = refl Iso.leftInv (setQuotUniversalIso Bset) g = funExt λ x → PropTrunc.rec (Bset (out (intro g) x) (g x)) (λ sur → cong (out (intro g)) (sym (snd sur)) ∙ (cong g (snd sur))) ([]surjective x) where intro = Iso.fun (setQuotUniversalIso Bset) out = Iso.inv (setQuotUniversalIso Bset) setQuotUniversal : isSet B → (A / R → B) ≃ (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b)) setQuotUniversal Bset = isoToEquiv (setQuotUniversalIso Bset) open BinaryRelation setQuotUnaryOp : (-_ : A → A) → (∀ a a' → R a a' → R (- a) (- a')) → (A / R → A / R) setQuotUnaryOp -_ h = rec squash/ (λ a → [ - a ]) (λ a b x → eq/ _ _ (h _ _ x)) -- characterisation of binary functions/operations on set-quotients setQuotUniversal2Iso : isSet C → isRefl R → isRefl S → Iso (A / R → B / S → C) (Σ[ _∗_ ∈ (A → B → C) ] (∀ a a' b b' → R a a' → S b b' → a ∗ b ≡ a' ∗ b')) Iso.fun (setQuotUniversal2Iso {R = R} {S = S} Bset isReflR isReflS) _∗/_ = _∗_ , h where _∗_ = λ a b → [ a ] ∗/ [ b ] h : ∀ a a' b b' → R a a' → S b b' → a ∗ b ≡ a' ∗ b' h a a' b b' r s = cong (_∗/ [ b ]) (eq/ _ _ r) ∙ cong ([ a' ] ∗/_) (eq/ _ _ s) Iso.inv (setQuotUniversal2Iso {R = R} {S = S} Bset isReflR isReflS) (_∗_ , h) = rec2 Bset _∗_ hleft hright where hleft : ∀ a a' b → R a a' → (a ∗ b) ≡ (a' ∗ b) hleft _ _ b r = h _ _ _ _ r (isReflS b) hright : ∀ a b b' → S b b' → (a ∗ b) ≡ (a ∗ b') hright a _ _ r = h _ _ _ _ (isReflR a) r Iso.rightInv (setQuotUniversal2Iso Bset isReflR isReflS) (_∗_ , h) = Σ≡Prop (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ2 λ _ _ → Bset _ _) refl Iso.leftInv (setQuotUniversal2Iso Bset isReflR isReflS) _∗/_ = funExt₂ (elimProp2 (λ _ _ → Bset _ _) λ _ _ → refl) setQuotUniversal2 : isSet C → isRefl R → isRefl S → (A / R → B / S → C) ≃ (Σ[ _∗_ ∈ (A → B → C) ] (∀ a a' b b' → R a a' → S b b' → a ∗ b ≡ a' ∗ b')) setQuotUniversal2 Bset isReflR isReflS = isoToEquiv (setQuotUniversal2Iso Bset isReflR isReflS) -- corollary for binary operations -- TODO: prove truncated inverse for effective relations setQuotBinOp : isRefl R → isRefl S → (_∗_ : A → B → C) → (∀ a a' b b' → R a a' → S b b' → T (a ∗ b) (a' ∗ b')) → (A / R → B / S → C / T) setQuotBinOp isReflR isReflS _∗_ h = rec2 squash/ (λ a b → [ a ∗ b ]) (λ _ _ _ r → eq/ _ _ (h _ _ _ _ r (isReflS _))) (λ _ _ _ s → eq/ _ _ (h _ _ _ _ (isReflR _) s)) setQuotSymmBinOp : isRefl R → isTrans R → (_∗_ : A → A → A) → (∀ a b → R (a ∗ b) (b ∗ a)) → (∀ a a' b → R a a' → R (a ∗ b) (a' ∗ b)) → (A / R → A / R → A / R) setQuotSymmBinOp {A = A} {R = R} isReflR isTransR _∗_ ∗Rsymm h = setQuotBinOp isReflR isReflR _∗_ h' where h' : ∀ a a' b b' → R a a' → R b b' → R (a ∗ b) (a' ∗ b') h' a a' b b' ra rb = isTransR _ _ _ (h a a' b ra) (isTransR _ _ _ (∗Rsymm a' b) (isTransR _ _ _ (h b b' a' rb) (∗Rsymm b' a'))) effective : (Rprop : isPropValued R) (Requiv : isEquivRel R) → (a b : A) → [ a ] ≡ [ b ] → R a b effective {A = A} {R = R} Rprop (equivRel R/refl R/sym R/trans) a b p = transport aa≡ab (R/refl _) where helper : A / R → hProp _ helper = rec isSetHProp (λ c → (R a c , Rprop a c)) (λ c d cd → Σ≡Prop (λ _ → isPropIsProp) (hPropExt (Rprop a c) (Rprop a d) (λ ac → R/trans _ _ _ ac cd) (λ ad → R/trans _ _ _ ad (R/sym _ _ cd)))) aa≡ab : R a a ≡ R a b aa≡ab i = helper (p i) .fst isEquivRel→effectiveIso : isPropValued R → isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) (R a b) Iso.fun (isEquivRel→effectiveIso {R = R} Rprop Req a b) = effective Rprop Req a b Iso.inv (isEquivRel→effectiveIso {R = R} Rprop Req a b) = eq/ a b Iso.rightInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = Rprop a b _ _ Iso.leftInv (isEquivRel→effectiveIso {R = R} Rprop Req a b) _ = squash/ _ _ _ _ isEquivRel→isEffective : isPropValued R → isEquivRel R → isEffective R isEquivRel→isEffective Rprop Req a b = isoToIsEquiv (invIso (isEquivRel→effectiveIso Rprop Req a b)) discreteSetQuotients : Discrete A → isPropValued R → isEquivRel R → (∀ a₀ a₁ → Dec (R a₀ a₁)) → Discrete (A / R) discreteSetQuotients {A = A} {R = R} Adis Rprop Req Rdec = elim (λ a₀ → isSetΠ (λ a₁ → isProp→isSet (isPropDec (squash/ a₀ a₁)))) discreteSetQuotients' discreteSetQuotients'-eq where discreteSetQuotients' : (a : A) (y : A / R) → Dec ([ a ] ≡ y) discreteSetQuotients' a₀ = elim (λ a₁ → isProp→isSet (isPropDec (squash/ [ a₀ ] a₁))) dis dis-eq where dis : (a₁ : A) → Dec ([ a₀ ] ≡ [ a₁ ]) dis a₁ with Rdec a₀ a₁ ... | (yes p) = yes (eq/ a₀ a₁ p) ... | (no ¬p) = no λ eq → ¬p (effective Rprop Req a₀ a₁ eq ) dis-eq : (a b : A) (r : R a b) → PathP (λ i → Dec ([ a₀ ] ≡ eq/ a b r i)) (dis a) (dis b) dis-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → Dec ([ a₀ ] ≡ ab i)) (dis a) k) (λ k → isPropDec (squash/ _ _) _ _) (eq/ a b ab) (dis b) discreteSetQuotients'-eq : (a b : A) (r : R a b) → PathP (λ i → (y : A / R) → Dec (eq/ a b r i ≡ y)) (discreteSetQuotients' a) (discreteSetQuotients' b) discreteSetQuotients'-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → (y : A / R) → Dec (ab i ≡ y)) (discreteSetQuotients' a) k) (λ k → funExt (λ x → isPropDec (squash/ _ _) _ _)) (eq/ a b ab) (discreteSetQuotients' b) -- Quotienting by the truncated relation is equivalent to quotienting by untruncated relation truncRelIso : Iso (A / R) (A / (λ a b → ∥ R a b ∥)) Iso.fun truncRelIso = rec squash/ [_] λ _ _ r → eq/ _ _ ∣ r ∣ Iso.inv truncRelIso = rec squash/ [_] λ _ _ → PropTrunc.rec (squash/ _ _) λ r → eq/ _ _ r Iso.rightInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl Iso.leftInv truncRelIso = elimProp (λ _ → squash/ _ _) λ _ → refl truncRelEquiv : A / R ≃ A / (λ a b → ∥ R a b ∥) truncRelEquiv = isoToEquiv truncRelIso -- Using this we can obtain a useful characterization of -- path-types for equivalence relations (not prop-valued) -- and their quotients isEquivRel→TruncIso : isEquivRel R → (a b : A) → Iso ([ a ] ≡ [ b ]) ∥ R a b ∥ isEquivRel→TruncIso {A = A} {R = R} Req a b = compIso (isProp→Iso (squash/ _ _) (squash/ _ _) (cong (Iso.fun truncRelIso)) (cong (Iso.inv truncRelIso))) (isEquivRel→effectiveIso (λ _ _ → PropTrunc.isPropPropTrunc) ∥R∥eq a b) where open isEquivRel ∥R∥eq : isEquivRel λ a b → ∥ R a b ∥ reflexive ∥R∥eq a = ∣ reflexive Req a ∣ symmetric ∥R∥eq a b = PropTrunc.map (symmetric Req a b) transitive ∥R∥eq a b c = PropTrunc.map2 (transitive Req a b c) -- quotienting by 'logically equivalent' relations gives the same quotient relBiimpl→TruncIso : ({a b : A} → R a b → S a b) → ({a b : A} → S a b → R a b) → Iso (A / R) (A / S) Iso.fun (relBiimpl→TruncIso R→S S→R) = rec squash/ [_] λ _ _ Rab → eq/ _ _ (R→S Rab) Iso.inv (relBiimpl→TruncIso R→S S→R) = rec squash/ [_] λ _ _ Sab → eq/ _ _ (S→R Sab) Iso.rightInv (relBiimpl→TruncIso R→S S→R) = elimProp (λ _ → squash/ _ _) λ _ → refl Iso.leftInv (relBiimpl→TruncIso R→S S→R) = elimProp (λ _ → squash/ _ _) λ _ → refl
36.661808
100
0.560795
36fbd50dda712bf553063904008c34931aee35d5
1,718
agda
Agda
src/Category/Monad/Monotone/Error.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
10
2017-11-17T17:10:36.000Z
2021-09-24T08:02:33.000Z
src/Category/Monad/Monotone/Error.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2019-01-13T13:03:47.000Z
2020-10-14T13:41:58.000Z
src/Category/Monad/Monotone/Error.agda
metaborg/mj.agda
0c096fea1716d714db0ff204ef2a9450b7a816df
[ "Apache-2.0" ]
1
2021-12-28T17:38:05.000Z
2021-12-28T17:38:05.000Z
open import Relation.Binary hiding (_⇒_) module Category.Monad.Monotone.Error {i}(pre : Preorder i i i)(Exc : Set i) where open Preorder pre renaming (Carrier to I; _∼_ to _≤_; refl to ≤-refl) open import Function open import Level hiding (lift) open import Data.Sum open import Relation.Unary open import Relation.Unary.Monotone pre open import Relation.Unary.PredicateTransformer open import Category.Monad.Monotone pre open import Category.Monad.Monotone.Identity pre pattern left x = inj₁ x pattern right x = inj₂ x ErrorT : Pt I i → Pt I i ErrorT M P = M (λ i → Exc ⊎ P i) Error = ErrorT Identity record ErrorMonad (M : Pt I i) : Set (suc i) where field throw : ∀ {P i} → Exc → M P i try_catch_ : ∀ {P} → M P ⊆ ((const Exc ↗ M P) ⇒ M P) module _ {M} ⦃ Mon : RawMPMonad M ⦄ where private module M = RawMPMonad Mon open RawMPMonad errorT-monad : RawMPMonad (ErrorT M) return errorT-monad px = M.return (right px) _≥=_ errorT-monad {P}{Q} px f = px M.≥= λ where _ (left e) → M.return (left e) w (right x) → f w x open ErrorMonad errorT-monad-ops : ErrorMonad (ErrorT M) throw errorT-monad-ops e = M.return (left e) try_catch_ errorT-monad-ops c f = c M.≥= λ where w (left e) → f w e w (right x) → M.return (right x) lift-error : ∀ {P} → M P ⊆ ErrorT M P lift-error x = x M.>>= (λ z → M.return (right z)) module Instances where -- Defining instances for the transformer -- leads to divergence of instance search, -- because M is on the outside. instance open RawMPMonad error-monad : RawMPMonad Error error-monad = errorT-monad open ErrorMonad error-monad-ops : ErrorMonad Error error-monad-ops = errorT-monad-ops
27.269841
81
0.671129
1427954189f82963b4f6260afc2d351c4e6e6262
2,189
agda
Agda
theorems/cohomology/PtdMapSequence.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cohomology/PtdMapSequence.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cohomology/PtdMapSequence.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.PtdMapSequence open import groups.HomSequence open import cohomology.Theory module cohomology.PtdMapSequence {i} (CT : CohomologyTheory i) where open CohomologyTheory CT -- FIXME maybe this should be named [ap-C-seq], -- but I do not know how to name [C-seq-isemap]. -favonia C-seq : ∀ {X Y : Ptd i} (n : ℤ) → PtdMapSequence X Y → HomSequence (C n Y) (C n X) C-seq n (X ⊙⊣|) = C n X ⊣|ᴳ C-seq n (X ⊙→⟨ f ⟩ seq) = HomSeq-snoc (C-seq n seq) (C-fmap n f) C-comm-square : ∀ (n : ℤ) {X₀ X₁ Y₀ Y₁ : Ptd i} → {f₀ : X₀ ⊙→ Y₀} {f₁ : X₁ ⊙→ Y₁} {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁} → CommSquare (fst f₀) (fst f₁) (fst hX) (fst hY) → CommSquareᴳ (C-fmap n f₁) (C-fmap n f₀) (C-fmap n hY) (C-fmap n hX) C-comm-square n {f₀ = f₀} {f₁} {hX} {hY} (comm-sqr □) = comm-sqrᴳ λ y₁ → ∘-CEl-fmap n hX f₁ y₁ ∙ CEl-fmap-base-indep' n (λ x → ! (□ x)) y₁ ∙ CEl-fmap-∘ n hY f₀ y₁ C-seq-fmap : ∀ {X₀ X₁ Y₀ Y₁ : Ptd i} (n : ℤ) {seq₀ : PtdMapSequence X₀ Y₀} {seq₁ : PtdMapSequence X₁ Y₁} {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁} → PtdMapSeqMap seq₀ seq₁ hX hY → HomSeqMap (C-seq n seq₁) (C-seq n seq₀) (C-fmap n hY) (C-fmap n hX) C-seq-fmap n (hX ⊙↓|) = C-fmap n hX ↓|ᴳ C-seq-fmap n (hX ⊙↓⟨ □ ⟩ seq) = HomSeqMap-snoc (C-seq-fmap n seq) (C-comm-square n □) C-seq-isemap : ∀ {X₀ X₁ Y₀ Y₁ : Ptd i} (n : ℤ) {seq₀ : PtdMapSequence X₀ Y₀} {seq₁ : PtdMapSequence X₁ Y₁} {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁} {seq-map : PtdMapSeqMap seq₀ seq₁ hX hY} → is-⊙seq-equiv seq-map → is-seqᴳ-equiv (C-seq-fmap n seq-map) C-seq-isemap n {seq-map = h ⊙↓|} h-is-equiv = CEl-isemap n h h-is-equiv C-seq-isemap n {seq-map = h ⊙↓⟨ □ ⟩ seq} (h-is-equiv , seq-is-equiv) = is-seqᴳ-equiv-snoc (C-seq-isemap n seq-is-equiv) (CEl-isemap n h h-is-equiv) C-seq-emap : ∀ {X₀ X₁ Y₀ Y₁ : Ptd i} (n : ℤ) {seq₀ : PtdMapSequence X₀ Y₀} {seq₁ : PtdMapSequence X₁ Y₁} {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁} → PtdMapSeqEquiv seq₀ seq₁ hX hY → HomSeqEquiv (C-seq n seq₁) (C-seq n seq₀) (C-fmap n hY) (C-fmap n hX) C-seq-emap n (seq , seq-ise) = C-seq-fmap n seq , C-seq-isemap n seq-ise
42.096154
93
0.583371
4e4c252b795a77fadacc6968bb9cb717bae3fa09
717
agda
Agda
test/Fail/NeedOptionRewriting.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/NeedOptionRewriting.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/NeedOptionRewriting.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-08-26 -- OPTIONS --rewriting needed open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} -- should trigger error data Nat : Set where zero : Nat suc : Nat → Nat _+_ : Nat → Nat → Nat zero + n = n (suc m) + n = suc (m + n) plus0T : Set plus0T = ∀{x} → (x + zero) ≡ x plusSucT = ∀{x y} → (x + (suc y)) ≡ suc (x + y) postulate plus0p : plus0T plusSucp : plusSucT {-# REWRITE plus0p #-} {-# REWRITE plusSucp #-} plus0 : plus0T plus0 = refl data Vec (A : Set) : Nat → Set where [] : Vec A zero _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n) reverseAcc : ∀{A n m} → Vec A n → Vec A m → Vec A (n + m) reverseAcc [] acc = acc reverseAcc (x ∷ xs) acc = reverseAcc xs (x ∷ acc)
18.868421
57
0.567643
36abe0234eb5abf4650d025c1e52c3554d82d951
4,376
agda
Agda
test/Test.agda
andreasabel/S
262b8a87db8ab58aa77f60a749eacb8c49c7471f
[ "MIT" ]
6
2017-05-16T02:28:36.000Z
2021-04-07T19:52:52.000Z
test/Test.agda
andreasabel/Sit
262b8a87db8ab58aa77f60a749eacb8c49c7471f
[ "MIT" ]
null
null
null
test/Test.agda
andreasabel/Sit
262b8a87db8ab58aa77f60a749eacb8c49c7471f
[ "MIT" ]
null
null
null
--- Sample Sit file {-# OPTIONS --experimental-irrelevance #-} {-# OPTIONS --sized-types #-} open import Base --; --- Leibniz-equality Eq : forall (A : Set) (a b : A) -> Set1 --; Eq = \ A a b -> (P : A -> Set) -> (P a) -> P b --; --- Reflexivity refl : forall (A : Set) (a : A) -> Eq A a a --; refl = \ A a P pa -> pa --; --- Symmetry sym : forall (A : Set) (a b : A) -> Eq A a b -> Eq A b a --; sym = \ A a b eq P pb -> eq (\ x -> P x -> P a) (\ pa -> pa) pb --; --- Transitivity trans : forall (A : Set) (a b c : A) -> Eq A a b -> Eq A b c -> Eq A a c --; trans = \ A a b c p q P pa -> q P (p P pa) --; --- Congruence cong : forall (A B : Set) (f : A -> B) (a a' : A) -> Eq A a a' -> Eq B (f a) (f a') --; cong = \ A B f a a' eq P pfa -> eq (\ x -> P (f x)) pfa --; --- Addition plus : forall .i -> Nat i -> Nat oo -> Nat oo --; plus = \ i x y -> fix (\ i x -> Nat oo) (\ _ f -> \ { (zero _) -> y ; (suc _ x) -> suc oo (f x) }) x --; --- Unit tests for plus inc : Nat oo -> Nat oo --; inc = \ x -> suc oo x --; one : Nat oo --; one = inc (zero oo) --; two : Nat oo --; two = inc one --; three : Nat oo --; three = inc two --; four : Nat oo --; four = inc three --; five : Nat oo --; five = inc four --; six : Nat oo --; six = inc five --; plus_one_zero : Eq (Nat oo) (plus oo one (zero oo)) one --; plus_one_zero = refl (Nat oo) one --; plus_one_one : Eq (Nat oo) (plus oo one one) two --; plus_one_one = refl (Nat oo) two --; --; --- Reduction rules for plus plus_red_zero : forall .i (y : Nat oo) -> Eq (Nat oo) (plus (i + 1) (zero i) y) y --; plus_red_zero = \ i y -> refl (Nat oo) y --; plus_red_suc : forall .i (x : Nat i) (y : Nat oo) -> Eq (Nat oo) (plus (i + 1) (suc i x) y) (suc oo (plus i x y)) --; plus_red_suc = \ i x y -> refl (Nat oo) (suc oo (plus i x y)) --; --; --- Law: x + 0 = x plus_zero : forall .i (x : Nat i) -> Eq (Nat oo) (plus i x (zero oo)) x --; plus_zero = \ i x -> fix (\ i x -> Eq (Nat oo) (plus i x (zero oo)) x) (\ j f -> \ { (zero _) -> refl (Nat oo) (zero oo) ; (suc _ y) -> cong (Nat oo) (Nat oo) inc (plus j y (zero oo)) y (f y) }) x --; --- Law: x + suc y = suc x + y plus_suc : forall .i (x : Nat i) (y : Nat oo) -> Eq (Nat oo) (plus i x (inc y)) (inc (plus i x y)) --; plus_suc = \ i x y -> fix (\ i x -> Eq (Nat oo) (plus i x (inc y)) (inc (plus i x y))) (\ j f -> \ { (zero _) -> refl (Nat oo) (inc y) ; (suc _ x') -> cong (Nat oo) (Nat oo) inc (plus j x' (inc y)) (inc (plus j x' y)) (f x') }) x --; --- Another definition of addition plus' : forall .i -> Nat i -> Nat oo -> Nat oo --; plus' = \ i x -> fix (\ i x -> Nat oo -> Nat oo) (\ _ f -> \ { (zero _) -> \ y -> y ; (suc _ x) -> \ y -> suc oo (f x y) }) x --; --- Predecessor pred : forall .i -> Nat i -> Nat i --; pred = \ i n -> fix (\ i _ -> Nat i) (\ i _ -> \{ (zero _) -> zero i ; (suc _ y) -> y }) n --; --- Subtraction sub : forall .j -> Nat j -> forall .i -> Nat i -> Nat i --; sub = \ j y -> fix (\ _ _ -> forall .i -> Nat i -> Nat i) (\ _ f -> \ { (zero _) -> \ i x -> x ; (suc _ y) -> \ i x -> f y i (pred i x) }) --- pred i (f y i x) }) y --; --- Lemma: x - x == 0 sub_diag : forall .i (x : Nat i) -> Eq (Nat oo) (sub i x i x) (zero oo) --; sub_diag = \ i x -> fix (\ i x -> Eq (Nat oo) (sub i x i x) (zero oo)) (\ _ f -> \ { (zero _) -> refl (Nat oo) (zero oo) ; (suc _ y) -> f y }) x --- Large eliminations --; --- Varying arity Fun : forall .i (n : Nat i) (A : Set) (B : Set) -> Set --; Fun = \ i n A B -> fix (\ _ _ -> Set) (\ _ f -> \ { (zero _) -> B ; (suc _ x) -> A -> f x }) n --; --- Type of n-ary Sum function Sum : forall .i (n : Nat i) -> Set --; Sum = \ i n -> Nat oo -> Fun i n (Nat oo) (Nat oo) --; --- n-ary summation function sum : forall .i (n : Nat i) -> Sum i n --; sum = \ _ n -> fix (\ i n -> Sum i n) (\ _ f -> \ { (zero _) -> \ acc -> acc ; (suc _ x) -> \ acc -> \ k -> f x (plus oo k acc) }) n --; --- Testing sum sum123 : Eq (Nat oo) (sum oo three (zero oo) one two three) six --; sum123 = refl (Nat oo) six
24.723164
118
0.433729
58844ba27d132b24de9582a9a0567f30c64e4c2d
1,174
agda
Agda
Cubical/ZCohomology/Base.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Base.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/ZCohomology/Base.agda
jorge-jbs/cubical
ebbe824fda41ab6524b62a42959665be4e67b847
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.ZCohomology.Base where open import Cubical.Data.Int.Base open import Cubical.Data.Nat.Base open import Cubical.Data.Sigma open import Cubical.Foundations.Pointed.Base open import Cubical.HITs.Nullification.Base open import Cubical.HITs.SetTruncation.Base open import Cubical.HITs.Sn.Base open import Cubical.HITs.S1.Base open import Cubical.HITs.Susp.Base open import Cubical.HITs.Truncation.Base private variable ℓ : Level A : Type ℓ --- Cohomology --- {- EM-spaces Kₙ from Brunerie 2016 -} coHomK : (n : ℕ) → Type₀ coHomK zero = Int coHomK (suc n) = ∥ S₊ (suc n) ∥ (2 + suc n) {- Cohomology -} coHom : (n : ℕ) → Type ℓ → Type ℓ coHom n A = ∥ (A → coHomK n) ∥₂ --- Reduced cohomology --- {- Pointed version of Kₙ -} coHomK-ptd : (n : ℕ) → Pointed (ℓ-zero) coHomK-ptd 0 = coHomK 0 , 0 coHomK-ptd 1 = coHomK 1 , ∣ base ∣ coHomK-ptd (suc (suc n)) = coHomK (2 + n) , ∣ north ∣ {- Reduced cohomology -} coHomRed : (n : ℕ) → (A : Pointed ℓ) → Type ℓ coHomRed n A = ∥ A →∙ coHomK-ptd n ∥₂ coHom-pt : (n : ℕ) → coHomK n coHom-pt 0 = 0 coHom-pt 1 = ∣ base ∣ coHom-pt (suc (suc n)) = ∣ north ∣
23.48
53
0.660988
434905d00b2d4b9bc14fc2cb5cf880d9773241b0
1,149
agda
Agda
test/Succeed/LevelMetaLeqNeutralLevel.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/LevelMetaLeqNeutralLevel.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/LevelMetaLeqNeutralLevel.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-09-28, Level meta below neutral level -- Agda previously simplified X <= a to X = a. -- This loses the solution X = lzero. -- {-# OPTIONS -v tc.constr.add:40 #-} open import Common.Level module _ (a : Level) where module WorksWithSwappedDeclarations where mutual X : Level X = _ data E : Set₁ where c : Set X → E -- constraint lsuc X <= 1 solves X = lzero data D : Set (lsuc a) where c : Set X → D -- fine since lzero <= a module WorksWithGivenSolution where mutual X : Level X = lzero data D : Set (lsuc a) where c : Set X → D data E : Set₁ where c : Set X → E module Test where mutual X : Level X = _ data D : Set (lsuc a) where c : Set X → D -- solved X (prematurely) since X <= a implies X = a ?? (Wrong!) data E : Set₁ where c : Set X → E -- constraint X <= 0 became contradictory constraint a <= 0 -- ERROR WAS: -- The type of the constructor does not fit in the sort of the -- datatype, since Set (lsuc a) is not less or equal than Set₁ -- when checking the constructor c in the declaration of E -- should succeed
21.679245
85
0.614447
7c372232f413bb661f42692cb3944709dda4e3b8
1,218
agda
Agda
doc/icfp20/code/Fmmh.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
28
2017-04-21T09:08:52.000Z
2022-03-04T18:04:07.000Z
doc/icfp20/code/Fmmh.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
1
2020-11-13T01:26:20.000Z
2020-11-17T00:58:55.000Z
doc/icfp20/code/Fmmh.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
3
2019-01-12T17:02:36.000Z
2020-11-10T04:04:40.000Z
{-# OPTIONS --without-K #-} module Fmmh where open import Data.List using (List) open import Pitch -- Reconstruction of "Functional Modelling of Musical Harmony" (ICFP 2011) -- using similar notation. Original code: -- https://github.com/chordify/HarmTrace-Base data Mode : Set where maj : Mode min : Mode data ChordQuality : Set where maj : ChordQuality min : ChordQuality dom7 : ChordQuality dim : ChordQuality data Chord : DiatonicDegree → ChordQuality → Set where chord : (d : DiatonicDegree) → (q : ChordQuality) → Chord d q data Ton : Mode → Set where maj : Chord d1 maj → Ton maj min : Chord d1 min → Ton min data SDom : Mode → Set where ii : Chord d2 min → SDom maj iv-maj : Chord d4 maj → SDom maj iii-iv : Chord d3 min → Chord d4 maj → SDom maj iv-min : Chord d4 min → SDom min data Dom (m : Mode) : Set where v7 : Chord d5 dom7 → Dom m v : Chord d5 maj → Dom m vii : Chord d7 dim → Dom m sdom : SDom m → Dom m → Dom m ii-v : Chord d2 dom7 → Chord d5 dom7 → Dom m data Phrase (m : Mode) : Set where i-v-i : Ton m → Dom m → Ton m → Phrase m v-i : Dom m → Ton m → Phrase m data Piece : Set where piece : {m : Mode} → List (Phrase m) → Piece
24.857143
74
0.646962
21f1196d3561e0d31e897f3c05729118caca04c0
925
agda
Agda
examples/SummerSchool07/Solutions/Problem1.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/SummerSchool07/Solutions/Problem1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/SummerSchool07/Solutions/Problem1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Problem1 where -- 1.1 data Nat : Set where zero : Nat suc : Nat -> Nat -- 1.2 infixl 60 _+_ _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) -- 1.3 infixl 70 _*_ _*_ : Nat -> Nat -> Nat zero * m = zero suc n * m = m + n * m -- 1.4 infix 30 _==_ data _==_ {A : Set}(x : A) : A -> Set where refl : x == x cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y cong f refl = refl assoc : (x y z : Nat) -> x + (y + z) == (x + y) + z assoc zero y z = refl assoc (suc x) y z = cong suc (assoc x y z) -- Alternative solution using 'with'. Note that in order -- to be able to pattern match on the induction hypothesis -- we have to abstract (using with) over the left hand side -- of the equation. assoc' : (x y z : Nat) -> x + (y + z) == (x + y) + z assoc' zero y z = refl assoc' (suc x) y z with x + (y + z) | assoc x y z ... | .((x + y) + z) | refl = refl
18.877551
63
0.514595
0dad358e65940419816582c921116983ab3e618e
68
agda
Agda
test/interaction/Issue2487/B.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2487/B.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2487/B.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --safe #-} module Issue2487.B where import Issue2487.A
13.6
24
0.705882
8bf1447374b4bacd3f1fe8ac3241209638c86140
5,668
agda
Agda
BasicIPC/Syntax/Gentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIPC/Syntax/Gentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIPC/Syntax/Gentzen.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
-- Basic intuitionistic propositional calculus, without ∨ or ⊥. -- Gentzen-style formalisation of syntax. -- Simple terms. module BasicIPC.Syntax.Gentzen where open import BasicIPC.Syntax.Common public -- Derivations. infix 3 _⊢_ data _⊢_ (Γ : Cx Ty) : Ty → Set where var : ∀ {A} → A ∈ Γ → Γ ⊢ A lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B unit : Γ ⊢ ⊤ infix 3 _⊢⋆_ _⊢⋆_ : Cx Ty → Cx Ty → Set Γ ⊢⋆ ∅ = 𝟙 Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A -- Monotonicity with respect to context inclusion. mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A mono⊢ η (var i) = var (mono∈ η i) mono⊢ η (lam t) = lam (mono⊢ (keep η) t) mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u) mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u) mono⊢ η (fst t) = fst (mono⊢ η t) mono⊢ η (snd t) = snd (mono⊢ η t) mono⊢ η unit = unit mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ mono⊢⋆ {∅} η ∙ = ∙ mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t -- Shorthand for variables. v₀ : ∀ {A Γ} → Γ , A ⊢ A v₀ = var i₀ v₁ : ∀ {A B Γ} → Γ , A , B ⊢ A v₁ = var i₁ v₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A v₂ = var i₂ -- Reflexivity. refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ refl⊢⋆ {∅} = ∙ refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀ -- Deduction theorem is built-in. lam⋆ : ∀ {Ξ Γ A} → Γ ⧺ Ξ ⊢ A → Γ ⊢ Ξ ▻⋯▻ A lam⋆ {∅} = I lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam lam⋆₀ : ∀ {Γ A} → Γ ⊢ A → ∅ ⊢ Γ ▻⋯▻ A lam⋆₀ {∅} = I lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam -- Detachment theorem. det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B det t = app (mono⊢ weak⊆ t) v₀ det⋆ : ∀ {Ξ Γ A} → Γ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⊢ A det⋆ {∅} = I det⋆ {Ξ , B} = det ∘ det⋆ {Ξ} det⋆₀ : ∀ {Γ A} → ∅ ⊢ Γ ▻⋯▻ A → Γ ⊢ A det⋆₀ {∅} = I det⋆₀ {Γ , B} = det ∘ det⋆₀ -- Cut and multicut. cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B cut t u = app (lam u) t multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A multicut {∅} ∙ u = mono⊢ bot⊆ u multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t -- Transitivity. trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″ trans⊢⋆ {∅} ts ∙ = ∙ trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u -- Contraction. ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B ccont = lam (lam (app (app v₁ v₀) v₀)) cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B cont t = det (app ccont (lam (lam t))) -- Exchange, or Schönfinkel’s C combinator. cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C cexch = lam (lam (lam (app (app v₂ v₀) v₁))) exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C exch t = det (det (app cexch (lam (lam t)))) -- Composition, or Schönfinkel’s B combinator. ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C ccomp = lam (lam (lam (app v₂ (app v₁ v₀)))) comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C comp t u = det (app (app ccomp (lam t)) (lam u)) -- Useful theorems in combinatory form. ci : ∀ {A Γ} → Γ ⊢ A ▻ A ci = lam v₀ ck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ck = lam (lam v₁) cs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀)))) cpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B cpair = lam (lam (pair v₁ v₀)) cfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A cfst = lam (fst v₀) csnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B csnd = lam (snd v₀) -- Closure under context concatenation. concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u) -- Substitution. [_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B [ i ≔ s ] var j with i ≟∈ j [ i ≔ s ] var .i | same = s [ i ≔ s ] var ._ | diff j = var j [ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t) [ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u) [ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u) [ i ≔ s ] fst t = fst ([ i ≔ s ] t) [ i ≔ s ] snd t = snd ([ i ≔ s ] t) [ i ≔ s ] unit = unit [_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ [_≔_]⋆_ {∅} i s ∙ = ∙ [_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t -- Convertibility. data _⋙_ {Γ : Cx Ty} : ∀ {A} → Γ ⊢ A → Γ ⊢ A → Set where refl⋙ : ∀ {A} → {t : Γ ⊢ A} → t ⋙ t trans⋙ : ∀ {A} → {t t′ t″ : Γ ⊢ A} → t ⋙ t′ → t′ ⋙ t″ → t ⋙ t″ sym⋙ : ∀ {A} → {t t′ : Γ ⊢ A} → t ⋙ t′ → t′ ⋙ t conglam⋙ : ∀ {A B} → {t t′ : Γ , A ⊢ B} → t ⋙ t′ → lam t ⋙ lam t′ congapp⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ▻ B} → {u u′ : Γ ⊢ A} → t ⋙ t′ → u ⋙ u′ → app t u ⋙ app t′ u′ congpair⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B} → t ⋙ t′ → u ⋙ u′ → pair t u ⋙ pair t′ u′ congfst⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B} → t ⋙ t′ → fst t ⋙ fst t′ congsnd⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B} → t ⋙ t′ → snd t ⋙ snd t′ beta▻⋙ : ∀ {A B} → {t : Γ , A ⊢ B} → {u : Γ ⊢ A} → app (lam t) u ⋙ ([ top ≔ u ] t) eta▻⋙ : ∀ {A B} → {t : Γ ⊢ A ▻ B} → t ⋙ lam (app (mono⊢ weak⊆ t) v₀) beta∧₁⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B} → fst (pair t u) ⋙ t beta∧₂⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B} → snd (pair t u) ⋙ u eta∧⋙ : ∀ {A B} → {t : Γ ⊢ A ∧ B} → t ⋙ pair (fst t) (snd t) eta⊤⋙ : ∀ {t : Γ ⊢ ⊤} → t ⋙ unit
24.969163
67
0.377558
c7005a40756f7e74078344257c0754bdd5a9c75a
2,029
agda
Agda
Cubical/HITs/Modulo/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/Modulo/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/Modulo/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Modulo.Base where open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Prelude open import Cubical.Data.Empty open import Cubical.Data.Fin open import Cubical.Data.Nat open import Cubical.Data.Unit renaming (Unit to ⊤) open import Cubical.Relation.Nullary NonZero : ℕ → Type₀ NonZero 0 = ⊥ NonZero _ = ⊤ private variable ℓ : Level k : ℕ -- The Modulo type is similar to the Fin type, but instead of being -- inhabited by canonical values, the inhabitants are all naturals, -- and paths are added between numbers that have the same residue. -- -- This representation makes it easier to do certain arithmetic -- without changing the modulus. For instance, we can just add any -- natural to a Modulo k to get another, whereas with Fin k, we must -- calculate the canonical representative. -- -- The reason the path constructor is guarded is to avoid adding -- non-trivial path structure to the k=0 case. If it were not guarded, -- each `Modulo 0` would become like the circle, and guarding the -- constructor is somewhat easier to work with than truncation. -- -- Note also that unlike `Fin 0`, `Modulo 0` is equivalent to the naturals. data Modulo (k : ℕ) : Type₀ where embed : (n : ℕ) → Modulo k pre-step : NonZero k → (n : ℕ) → embed n ≡ embed (k + n) -- When we are working with k = suc k₀, the `step` alias is much -- we can use this alias. pattern step n i = pre-step _ n i -- Helper to avoid having to case on `k` in certain places. ztep : ∀{k} n → Path (Modulo k) (embed n) (embed (k + n)) ztep {0} n = refl ztep {suc k} n = step n -- The standard eliminator for `Modulo`. elim : (P : ∀ k → Modulo k → Type ℓ) → (e : ∀ k n → P k (embed n)) → (st : ∀ k n → PathP (λ i → P (suc k) (step n i)) (e (suc k) n) (e (suc k) (suc k + n))) → (m : Modulo k) → P k m elim P e st (embed n) = e _ n elim {k = suc k} P e st (step n i) = st k n i
32.725806
91
0.685067
367f0a86116fd73ad58591a98ee932835c24329d
2,000
agda
Agda
LibraBFT/Impl/OBM/Crypto.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/Impl/OBM/Crypto.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/Impl/OBM/Crypto.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Encode open import LibraBFT.Base.PKCS as PKCS hiding (sign; verify) open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.Prelude module LibraBFT.Impl.OBM.Crypto where ------------------------------------------------------------------------------ -- keys postulate -- TODO-1 : makePK makePK : SK → PK ------------------------------------------------------------------------------ postulate -- TODO-1: implement obmHashVersion obmHashVersion : Version → HashValue ------------------------------------------------------------------------------ -- sign and verify record CryptoHash (A : Set) : Set where field sign : SK → A → Signature verify : {-Text-} PK → Signature → A → Either ErrLog Unit ⦃ encodeA ⦄ : Encoder A open CryptoHash ⦃ ... ⦄ public instance CryptoHashBlockData : CryptoHash BlockData CryptoHashBlockData = record { sign = λ sk bd → PKCS.sign-raw (encode bd) sk ; verify = λ pk sig bd → if PKCS.verify (encode bd) sig pk then Right unit else Left fakeErr } instance CryptoHashLedgerInfo : CryptoHash LedgerInfo CryptoHashLedgerInfo = record { sign = λ sk li → PKCS.sign-raw (encode li) sk ; verify = λ pk sig li → if PKCS.verify (encode li) sig pk then Right unit else Left fakeErr } instance CryptoHashTimeout : CryptoHash Timeout CryptoHashTimeout = record { sign = λ sk to → PKCS.sign-raw (encode to) sk ; verify = λ pk sig to → if PKCS.verify (encode to) sig pk then Right unit else Left fakeErr }
33.898305
111
0.5485
0d754b6a428fa068e1ab00d6b96a18cdc71a4846
1,567
agda
Agda
src/Categories/Category/Instance/Zero.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Instance/Zero.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Instance/Zero.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Level -- ⊥ is Initial module Categories.Category.Instance.Zero where open import Data.Empty using (⊥; ⊥-elim) open import Function renaming (id to idf) open import Categories.Category open import Categories.Functor open import Categories.Category.Instance.Cats import Categories.Object.Initial as Init -- Unlike for ⊤ being Terminal, Agda can't deduce these, need to be explicit module _ {o ℓ e : Level} where open Init (Cats o ℓ e) Zero : Category o ℓ e Zero = record { Obj = Lift o ⊥ ; _⇒_ = λ _ _ → Lift ℓ ⊥ ; _≈_ = λ _ _ → Lift e ⊥ ; id = λ { { lift () } } ; _∘_ = λ a _ → a -- left-biased rather than strict ; assoc = λ { {lift () } } ; sym-assoc = λ { {lift () } } ; identityˡ = λ { {()} } ; identityʳ = λ { {()} } ; identity² = λ { {()} } ; ∘-resp-≈ = λ { () } ; equiv = record { refl = λ { {()} } ; sym = idf ; trans = λ a _ → a } } Zero-⊥ : Initial Zero-⊥ = record { ⊥ = Zero ; ⊥-is-initial = record { ! = record { F₀ = λ { (lift x) → ⊥-elim x } ; F₁ = λ { (lift ()) } ; identity = λ { {lift ()} } ; homomorphism = λ { {lift ()} } ; F-resp-≈ = λ { () } } ; !-unique = λ f → record { F⇒G = record { η = λ { () } ; commute = λ { () } ; sym-commute = λ { () } } ; F⇐G = record { η = λ { () } ; commute = λ { () } ; sym-commute = λ { () } } ; iso = λ { (lift ()) } } } }
26.559322
85
0.465858
4e3f5bfd55d65e62c09cf80586d0f514dc3c5d16
684
agda
Agda
out/Monoid/Signature.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
out/Monoid/Signature.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
out/Monoid/Signature.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
{- This second-order signature was created from the following second-order syntax description: syntax Monoid | M type * : 0-ary term unit : * | ε add : * * -> * | _⊕_ l20 theory (εU⊕ᴸ) a |> add (unit, a) = a (εU⊕ᴿ) a |> add (a, unit) = a (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c)) -} module Monoid.Signature where open import SOAS.Context open import SOAS.Common open import SOAS.Syntax.Signature *T public open import SOAS.Syntax.Build *T public -- Operator symbols data Mₒ : Set where unitₒ addₒ : Mₒ -- Term signature M:Sig : Signature Mₒ M:Sig = sig λ { unitₒ → ⟼₀ * ; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * } open Signature M:Sig public
16.682927
91
0.609649
1b68b6e9854f17f1d4bf742f00868318c4856593
6,252
agda
Agda
Categories/Diagram/Pullback/Limit.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Diagram/Pullback/Limit.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Diagram/Pullback/Limit.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Diagram.Pullback.Limit {o ℓ e} (C : Category o ℓ e) where open import Data.Product using (∃₂; _,_) open import Function using (_$_) open import Categories.Category.Instance.Span open import Categories.Functor open import Categories.Diagram.Pullback C open import Categories.Morphism.Reasoning C as MR hiding (center) import Relation.Binary.PropositionalEquality as ≡ import Categories.Category.Construction.Cones as Con import Categories.Diagram.Limit as Lim private module C = Category C module Span = Category Span open Category C variable X Y Z : Obj f g h : X ⇒ Y open HomReasoning module _ {F : Functor Span.op C} where open Functor F open Lim F open Con F private W = F₀ center A = F₀ left B = F₀ right A⇒W : A ⇒ W A⇒W = F₁ span-arrˡ B⇒W : B ⇒ W B⇒W = F₁ span-arrʳ limit⇒pullback : Limit → Pullback A⇒W B⇒W limit⇒pullback lim = record { p₁ = proj left ; p₂ = proj right ; commute = trans (limit-commute span-arrˡ) (sym (limit-commute span-arrʳ)) ; universal = universal ; unique = commute′ ; p₁∘universal≈h₁ = commute ; p₂∘universal≈h₂ = commute } where open Limit lim universal : A⇒W ∘ f ≈ B⇒W ∘ g → dom f ⇒ apex universal {f = f} {g = g} eq = rep $ record { apex = record { ψ = λ { center → B⇒W ∘ g ; left → f ; right → g } ; commute = λ { {center} {center} span-id → elimˡ identity ; {left} {center} span-arrˡ → eq ; {left} {left} span-id → elimˡ identity ; {right} {center} span-arrʳ → refl ; {right} {right} span-id → elimˡ identity } } } proj-center : proj center ≈ B⇒W ∘ proj right proj-center = sym (limit-commute span-arrʳ) commute′ : ∀ {eq : A⇒W ∘ f ≈ B⇒W ∘ g} → proj left ∘ h ≈ f → proj right ∘ h ≈ g → h ≈ universal eq commute′ {f = f} {g = g} {h = h} {eq = eq} eq₁ eq₂ = sym $ terminal.!-unique $ record { arr = h ; commute = λ { {center} → begin proj center ∘ h ≈⟨ pushˡ proj-center ⟩ B⇒W ∘ proj right ∘ h ≈⟨ refl⟩∘⟨ eq₂ ⟩ B⇒W ∘ g ∎ ; {left} → eq₁ ; {right} → eq₂ } } module _ (p : Pullback f g) where open Pullback p pullback⇒limit-F : Functor Span.op C pullback⇒limit-F = record { F₀ = λ { center → cod f ; left → dom f ; right → dom g } ; F₁ = λ { {center} {.center} span-id → C.id ; {left} {.left} span-id → C.id ; {right} {.right} span-id → C.id ; {.left} {.center} span-arrˡ → f ; {.right} {.center} span-arrʳ → g } ; identity = λ { {center} → refl ; {left} → refl ; {right} → refl } ; homomorphism = λ { {center} {.center} {.center} {span-id} {span-id} → sym identityˡ ; {left} {.left} {.left} {span-id} {span-id} → sym identityˡ ; {right} {.right} {.right} {span-id} {span-id} → sym identityˡ ; {.left} {.left} {.center} {span-id} {span-arrˡ} → sym identityʳ ; {.right} {.right} {.center} {span-id} {span-arrʳ} → sym identityʳ ; {.left} {.center} {.center} {span-arrˡ} {span-id} → sym identityˡ ; {.right} {.center} {.center} {span-arrʳ} {span-id} → sym identityˡ } ; F-resp-≈ = λ { {center} {.center} {span-id} {.span-id} ≡.refl → refl ; {left} {.left} {span-id} {.span-id} ≡.refl → refl ; {right} {.right} {span-id} {.span-id} ≡.refl → refl ; {.left} {.center} {span-arrˡ} {.span-arrˡ} ≡.refl → refl ; {.right} {.center} {span-arrʳ} {.span-arrʳ} ≡.refl → refl } } open Functor pullback⇒limit-F open Lim pullback⇒limit-F open Con pullback⇒limit-F pullback⇒limit : Limit pullback⇒limit = record { terminal = record { ⊤ = ⊤ ; ! = ! ; !-unique = !-unique } } where ⊤ : Cone ⊤ = record { apex = record { ψ = λ { center → g ∘ p₂ ; left → p₁ ; right → p₂ } ; commute = λ { {center} {.center} span-id → identityˡ ; {left} {.left} span-id → identityˡ ; {right} {.right} span-id → identityˡ ; {.left} {.center} span-arrˡ → commute ; {.right} {.center} span-arrʳ → refl } } } ! : ∀ {A : Cone} → Cone⇒ A ⊤ ! {A} = record { arr = universal commute′ ; commute = λ { {center} → begin (g ∘ p₂) ∘ universal _ ≈⟨ pullʳ p₂∘universal≈h₂ ⟩ g ∘ A.ψ right ≈⟨ A.commute span-arrʳ ⟩ A.ψ center ∎ ; {left} → p₁∘universal≈h₁ ; {right} → p₂∘universal≈h₂ } } where module A = Cone A commute′ = trans (A.commute span-arrˡ) (sym (A.commute span-arrʳ)) !-unique : ∀ {A : Cone} (h : Cone⇒ A ⊤) → Cones [ ! ≈ h ] !-unique {A} h = sym (unique h.commute h.commute) where module h = Cone⇒ h
37.214286
107
0.421465
3458c0585a47c2c48bc58f38b69c35186881410a
794
agda
Agda
Data/Option/Equiv/Path.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Data/Option/Equiv/Path.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Data/Option/Equiv/Path.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical #-} module Data.Option.Equiv.Path where import Lvl open import Data open import Data.Option open import Data.Option.Functions open import Data.Option.Equiv open import Functional open import Structure.Function.Domain open import Structure.Operator open import Structure.Relator open import Type.Cubical.Path.Equality open import Type private variable ℓ : Lvl.Level private variable T : Type{ℓ} instance Some-injectivity : Injective {B = Option(T)} (Some) Injective.proof Some-injectivity {x}{y} = congruence₂ₗ(_or_)(x) instance Path-Option-extensionality : Extensionality{A = T} (Path-equiv) Extensionality.cases-inequality (Path-Option-extensionality {T = T}) {x} p with () ← substitute₁(elim{A = T}{B = λ _ → Type}(Option(T)) (const Empty)) p (Some x)
29.407407
163
0.75063
7c09b81b28b224d88102a9b2bf07bd39038dbc7d
93
agda
Agda
test/Fail/Issue1609a.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1609a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1609a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures A : Set where B = C
23.25
71
0.72043
2e4ce3f711a092e43e091916c9e26d5df2610cea
2,674
agda
Agda
src/Categories/Functor/Instance/01-Truncation.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
src/Categories/Functor/Instance/01-Truncation.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
null
null
null
src/Categories/Functor/Instance/01-Truncation.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Instance.01-Truncation where -- (0,1)-trucation of categories as a functor from Cats to Posets. -- -- This is the right-adjoint of the inclusion functor from Posets to -- Cats (see Categories.Functor.Adjoint.Instance.01-Truncation) open import Level using (_⊔_) open import Function using (flip) open import Data.Product as Prod using (_,_; _×_) open import Relation.Binary.OrderMorphism using (_⇒-Poset_) open import Relation.Binary using (Poset) open import Categories.Category using (Category; _[_≈_]) open import Categories.Functor hiding (id) open import Categories.Category using (Category) open import Categories.Category.Instance.Cats using (Cats) open import Categories.Category.Instance.Posets using (Posets) import Categories.Morphism as Morphism open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_) Trunc : ∀ {o ℓ e} → Functor (Cats o ℓ e) (Posets o ℓ ℓ) Trunc {o} {ℓ} {e} = record { F₀ = Trunc₀ ; F₁ = Trunc₁ ; identity = λ {C} → id C , id C ; homomorphism = λ {_ _ C} → id C , id C ; F-resp-≈ = TruncRespNI } where open Functor -- The choice of _≈_ below may seem a bit arbitrary. The -- rationale is as follows: -- -- Since we are defining an Agda stdlib-style poset, we have to -- pick an equality on the carrier set, i.e. on objects. But -- objects do not come with an equality in this library (that's -- considered evil), so we pick isomorphism. In a poset, any -- pair of morphisms f : X ⇒ Y and g : Y ⇒ X constitute an -- isomorphism between X and Y. Hence the definition of _≈_. Trunc₀ : Category o ℓ e → Poset o ℓ ℓ Trunc₀ C = record { Carrier = Obj ; _≈_ = λ x y → x ⇒ y × y ⇒ x ; _≤_ = _⇒_ ; isPartialOrder = record { isPreorder = record { isEquivalence = record { refl = id , id ; sym = Prod.swap ; trans = Prod.zip (flip _∘_) _∘_ } ; reflexive = Prod.proj₁ ; trans = flip _∘_ } ; antisym = _,_ } } where open Category C Trunc₁ : ∀ {C D} → Functor C D → Trunc₀ C ⇒-Poset Trunc₀ D Trunc₁ F = record { fun = F₀ F ; monotone = F₁ F } TruncRespNI : ∀ {C D : Category o ℓ e} {F G : Functor C D} → F ≃ G → Posets o ℓ ℓ [ Trunc₁ F ≈ Trunc₁ G ] TruncRespNI μ {X} = ⇒.η X , ⇐.η X where open NaturalIsomorphism μ open Category
35.653333
68
0.590501
3064e29e2b9309ab9db3ac3fa5a3edf549a06f00
6,767
agda
Agda
src/STLC/Kovacs/Soundness.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
src/STLC/Kovacs/Soundness.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
src/STLC/Kovacs/Soundness.agda
mietek/coquand-kovacs
bd626509948fbf8503ec2e31c1852e1ac6edcc79
[ "X11" ]
null
null
null
module STLC.Kovacs.Soundness where open import STLC.Kovacs.Convertibility public open import STLC.Kovacs.PresheafRefinement public -------------------------------------------------------------------------------- infix 3 _≈_ _≈_ : ∀ {A Γ} → Γ ⊩ A → Γ ⊩ A → Set _≈_ {⎵} {Γ} M₁ M₂ = M₁ ≡ M₂ _≈_ {A ⇒ B} {Γ} f₁ f₂ = ∀ {Γ′} → (η : Γ′ ⊇ Γ) {a₁ a₂ : Γ′ ⊩ A} → (p : a₁ ≈ a₂) (u₁ : 𝒰 a₁) (u₂ : 𝒰 a₂) → f₁ η a₁ ≈ f₂ η a₂ -- (≈ᶜ ; ∙ ; _,_) infix 3 _≈⋆_ data _≈⋆_ : ∀ {Γ Ξ} → Γ ⊩⋆ Ξ → Γ ⊩⋆ Ξ → Set where ∅ : ∀ {Γ} → ∅ {Γ} ≈⋆ ∅ _,_ : ∀ {Γ Ξ A} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} {M₁ M₂ : Γ ⊩ A} → (χ : ρ₁ ≈⋆ ρ₂) (p : M₁ ≈ M₂) → ρ₁ , M₁ ≈⋆ ρ₂ , M₂ -- (_≈⁻¹) _⁻¹≈ : ∀ {A Γ} → {a₁ a₂ : Γ ⊩ A} → a₁ ≈ a₂ → a₂ ≈ a₁ _⁻¹≈ {⎵} p = p ⁻¹ _⁻¹≈ {A ⇒ B} F = λ η p u₁ u₂ → F η (p ⁻¹≈) u₂ u₁ ⁻¹≈ -- (_≈ᶜ⁻¹) _⁻¹≈⋆ : ∀ {Γ Ξ} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} → ρ₁ ≈⋆ ρ₂ → ρ₂ ≈⋆ ρ₁ ∅ ⁻¹≈⋆ = ∅ (χ , p) ⁻¹≈⋆ = χ ⁻¹≈⋆ , p ⁻¹≈ -- (_≈◾_) _⦙≈_ : ∀ {A Γ} → {a₁ a₂ a₃ : Γ ⊩ A} → a₁ ≈ a₂ → a₂ ≈ a₃ → a₁ ≈ a₃ _⦙≈_ {⎵} p q = p ⦙ q _⦙≈_ {A ⇒ B} F G = λ η p u₁ u₂ → F η (p ⦙≈ (p ⁻¹≈)) u₁ u₁ ⦙≈ G η p u₁ u₂ -- (_≈ᶜ◾_) _⦙≈⋆_ : ∀ {Γ Ξ} → {ρ₁ ρ₂ ρ₃ : Γ ⊩⋆ Ξ} → ρ₁ ≈⋆ ρ₂ → ρ₂ ≈⋆ ρ₃ → ρ₁ ≈⋆ ρ₃ ∅ ⦙≈⋆ ∅ = ∅ (χ₁ , p) ⦙≈⋆ (χ₂ , q) = χ₁ ⦙≈⋆ χ₂ , p ⦙≈ q instance per≈ : ∀ {Γ A} → PER (Γ ⊩ A) _≈_ per≈ = record { _⁻¹ = _⁻¹≈ ; _⦙_ = _⦙≈_ } instance per≈⋆ : ∀ {Γ Ξ} → PER (Γ ⊩⋆ Ξ) _≈⋆_ per≈⋆ = record { _⁻¹ = _⁻¹≈⋆ ; _⦙_ = _⦙≈⋆_ } -------------------------------------------------------------------------------- -- (≈ₑ) acc≈ : ∀ {A Γ Γ′} → {a₁ a₂ : Γ ⊩ A} → (η : Γ′ ⊇ Γ) → a₁ ≈ a₂ → acc η a₁ ≈ acc η a₂ acc≈ {⎵} η p = renⁿᶠ η & p acc≈ {A ⇒ B} η F = λ η′ → F (η ○ η′) -- (≈ᶜₑ) _⬖≈_ : ∀ {Γ Γ′ Ξ} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} → ρ₁ ≈⋆ ρ₂ → (η : Γ′ ⊇ Γ) → ρ₁ ⬖ η ≈⋆ ρ₂ ⬖ η ∅ ⬖≈ η = ∅ (χ , p) ⬖≈ η = χ ⬖≈ η , acc≈ η p -- (∈≈) get≈ : ∀ {Γ Ξ A} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} → ρ₁ ≈⋆ ρ₂ → (i : Ξ ∋ A) → getᵥ ρ₁ i ≈ getᵥ ρ₂ i get≈ (χ , p) zero = p get≈ (χ , p) (suc i) = get≈ χ i -- (Tm≈) eval≈ : ∀ {Γ Ξ A} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} → ρ₁ ≈⋆ ρ₂ → 𝒰⋆ ρ₁ → 𝒰⋆ ρ₂ → (M : Ξ ⊢ A) → eval ρ₁ M ≈ eval ρ₂ M eval≈ χ υ₁ υ₂ (𝓋 i) = get≈ χ i eval≈ χ υ₁ υ₂ (ƛ M) = λ η p u₁ u₂ → eval≈ (χ ⬖≈ η , p) (υ₁ ⬖𝒰 η , u₁) (υ₂ ⬖𝒰 η , u₂) M eval≈ χ υ₁ υ₂ (M ∙ N) = eval≈ χ υ₁ υ₂ M idₑ (eval≈ χ υ₁ υ₂ N) (eval𝒰 υ₁ N) (eval𝒰 υ₂ N) -------------------------------------------------------------------------------- -- (Subᴺᴾ) -- NOTE: _◆𝒰_ = eval𝒰⋆ _◆𝒰_ : ∀ {Γ Ξ Φ} → {ρ : Γ ⊩⋆ Ξ} → (σ : Ξ ⊢⋆ Φ) → 𝒰⋆ ρ → 𝒰⋆ (σ ◆ ρ) ∅ ◆𝒰 υ = ∅ (σ , M) ◆𝒰 υ = σ ◆𝒰 υ , eval𝒰 υ M -- (Subᴺ≈ᶜ) -- NOTE: _◆≈_ = eval≈⋆ _◆≈_ : ∀ {Γ Ξ Φ} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} → (σ : Ξ ⊢⋆ Φ) → ρ₁ ≈⋆ ρ₂ → 𝒰⋆ ρ₁ → 𝒰⋆ ρ₂ → σ ◆ ρ₁ ≈⋆ σ ◆ ρ₂ (∅ ◆≈ χ) υ₁ υ₂ = ∅ ((σ , M) ◆≈ χ) υ₁ υ₂ = (σ ◆≈ χ) υ₁ υ₂ , eval≈ χ υ₁ υ₂ M -------------------------------------------------------------------------------- -- (Tmₛᴺ) eval◆ : ∀ {Γ Ξ Φ A} → {ρ : Γ ⊩⋆ Ξ} → ρ ≈⋆ ρ → 𝒰⋆ ρ → (σ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A) → eval ρ (sub σ M) ≈ eval (σ ◆ ρ) M eval◆ {ρ = ρ} χ υ σ (𝓋 i) rewrite get◆ ρ σ i = eval≈ χ υ υ (getₛ σ i) eval◆ {ρ = ρ} χ υ σ (ƛ M) η {a₁} {a₂} p u₁ u₂ rewrite comp◆⬖ η υ σ = let υ′ = υ ⬖𝒰 η in eval◆ {ρ = ρ ⬖ η , a₁} ((χ ⬖≈ η) , (p ⦙ p ⁻¹)) (υ ⬖𝒰 η , u₁) (liftₛ σ) M ⦙ coe ((λ ρ′ → eval (ρ′ , a₁) M ≈ _) & ( comp◆⬗ (ρ ⬖ η , a₁) (wkₑ idₑ) σ ⦙ (σ ◆_) & lid⬗ (ρ ⬖ η) ) ⁻¹) (eval≈ ((σ ◆≈ (χ ⬖≈ η)) υ′ υ′ , p) (σ ◆𝒰 υ′ , u₁) (σ ◆𝒰 υ′ , u₂) M) eval◆ {ρ = ρ} χ υ σ (M ∙ N) = eval◆ χ υ σ M idₑ (eval◆ χ υ σ N) (eval𝒰 υ (sub σ N)) (eval𝒰 (σ ◆𝒰 υ) N) -------------------------------------------------------------------------------- -- (~≈) eval∼ : ∀ {Γ Ξ A} → {ρ₁ ρ₂ : Γ ⊩⋆ Ξ} {M₁ M₂ : Ξ ⊢ A} → ρ₁ ≈⋆ ρ₂ → 𝒰⋆ ρ₁ → 𝒰⋆ ρ₂ → M₁ ∼ M₂ → eval ρ₁ M₁ ≈ eval ρ₂ M₂ eval∼ {M₁ = M₁} χ υ₁ υ₂ refl∼ = eval≈ χ υ₁ υ₂ M₁ eval∼ χ υ₁ υ₂ (p ⁻¹∼) = eval∼ (χ ⁻¹) υ₂ υ₁ p ⁻¹ eval∼ χ υ₁ υ₂ (p ⦙∼ q) = eval∼ (χ ⦙ χ ⁻¹) υ₁ υ₁ p ⦙ eval∼ χ υ₁ υ₂ q eval∼ χ υ₁ υ₂ (ƛ∼ p) = λ η q u₁ u₂ → eval∼ (χ ⬖≈ η , q) (υ₁ ⬖𝒰 η , u₁) (υ₂ ⬖𝒰 η , u₂) p eval∼ χ υ₁ υ₂ (_∙∼_ {N₁ = N₁} {N₂} p q) = eval∼ χ υ₁ υ₂ p idₑ (eval∼ χ υ₁ υ₂ q) (eval𝒰 υ₁ N₁) (eval𝒰 υ₂ N₂) eval∼ {ρ₁ = ρ₁} {ρ₂} χ υ₁ υ₂ (red⇒ M N) = coe ((λ ρ₁′ ρ₂′ → eval (ρ₁′ , eval ρ₁ N) M ≈ eval (ρ₂′ , eval ρ₂ N) M) & (lid⬖ ρ₁ ⁻¹) ⊗ (lid◆ ρ₂ ⁻¹)) (eval≈ (χ , eval≈ χ υ₁ υ₂ N) (υ₁ , eval𝒰 υ₁ N) (υ₂ , eval𝒰 υ₂ N) M) ⦙ eval◆ (χ ⁻¹ ⦙ χ) υ₂ (idₛ , N) M ⁻¹ eval∼ {ρ₂ = ρ₂} χ υ₁ υ₂ (exp⇒ M) η {a₂ = a₂} p u₁ u₂ rewrite eval⬗ (ρ₂ ⬖ η , a₂) (wkₑ idₑ) M ⁻¹ | lid⬗ (ρ₂ ⬖ η) | eval⬖ η υ₂ M | rid○ η = eval≈ χ υ₁ υ₂ M η p u₁ u₂ -------------------------------------------------------------------------------- mutual -- (q≈) reify≈ : ∀ {A Γ} → {a₁ a₂ : Γ ⊩ A} → a₁ ≈ a₂ → reify a₁ ≡ reify a₂ reify≈ {⎵} p = p reify≈ {A ⇒ B} F = ƛ & reify≈ (F (wkₑ {A = A} idₑ) (reflect≈ refl) (reflect𝒰 0) (reflect𝒰 0)) -- (u≈) reflect≈ : ∀ {A Γ} → {M₁ M₂ : Γ ⊢ⁿᵉ A} → M₁ ≡ M₂ → reflect M₁ ≈ reflect M₂ reflect≈ {⎵} p = ne & p reflect≈ {A ⇒ B} p = λ η q u₁ u₂ → reflect≈ (_∙_ & (renⁿᵉ η & p) ⊗ reify≈ q) -- (uᶜ≈) id≈ : ∀ {Γ} → idᵥ {Γ} ≈⋆ idᵥ id≈ {∅} = ∅ id≈ {Γ , A} = id≈ ⬖≈ wkₑ idₑ , reflect≈ refl sound : ∀ {Γ A} → {M₁ M₂ : Γ ⊢ A} → M₁ ∼ M₂ → nf M₁ ≡ nf M₂ sound p = reify≈ (eval∼ id≈ id𝒰 id𝒰 p) --------------------------------------------------------------------------------
25.25
80
0.279149
368ab9fadc87ddc0cf9b66d84a12ec37c81f680d
3,253
agda
Agda
src/fot/FOTC/Data/Nat/PropertiesByInductionATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Nat/PropertiesByInductionATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Nat/PropertiesByInductionATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Arithmetic properties (using induction on the FOTC natural numbers type) ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Usually our proofs use pattern matching instead of the induction -- principle associated with the FOTC natural numbers. The following -- examples show some proofs using it. module FOTC.Data.Nat.PropertiesByInductionATP where open import FOTC.Base open import FOTC.Data.Nat ------------------------------------------------------------------------------ +-leftIdentity : ∀ n → zero + n ≡ n +-leftIdentity n = +-0x n -- See Issue https://github.com/asr/apia/issues/81 . +-rightIdentityA : D → Set +-rightIdentityA i = i + zero ≡ i {-# ATP definition +-rightIdentityA #-} +-rightIdentity : ∀ {n} → N n → n + zero ≡ n +-rightIdentity Nn = N-ind +-rightIdentityA A0 is Nn where postulate A0 : +-rightIdentityA zero {-# ATP prove A0 #-} postulate is : ∀ {i} → +-rightIdentityA i → +-rightIdentityA (succ₁ i) {-# ATP prove is #-} -- See Issue https://github.com/asr/apia/issues/81 . +-NA : D → D → Set +-NA n i = N (i + n) {-# ATP definition +-NA #-} +-N : ∀ {m n} → N m → N n → N (m + n) +-N {n = n} Nm Nn = N-ind (+-NA n) A0 is Nm where postulate A0 : +-NA n zero {-# ATP prove A0 #-} postulate is : ∀ {i} → +-NA n i → +-NA n (succ₁ i) {-# ATP prove is #-} -- See Issue https://github.com/asr/apia/issues/81 . +-assocA : D → D → D → Set +-assocA n o i = i + n + o ≡ i + (n + o) {-# ATP definition +-assocA #-} +-assoc : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o) +-assoc Nm n o = N-ind (+-assocA n o) A0 is Nm where postulate A0 : +-assocA n o zero {-# ATP prove A0 #-} postulate is : ∀ {i} → +-assocA n o i → +-assocA n o (succ₁ i) {-# ATP prove is #-} -- A proof without use ATPs definitions. +-assoc' : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o) +-assoc' Nm n o = N-ind A A0 is Nm where A : D → Set A i = i + n + o ≡ i + (n + o) postulate A0 : zero + n + o ≡ zero + (n + o) {-# ATP prove A0 #-} postulate is : ∀ {i} → i + n + o ≡ i + (n + o) → succ₁ i + n + o ≡ succ₁ i + (n + o) {-# ATP prove is #-} -- See Issue https://github.com/asr/apia/issues/81 . x+Sy≡S[x+y]A : D → D → Set x+Sy≡S[x+y]A n i = i + succ₁ n ≡ succ₁ (i + n) {-# ATP definition x+Sy≡S[x+y]A #-} x+Sy≡S[x+y] : ∀ {m} → N m → ∀ n → m + succ₁ n ≡ succ₁ (m + n) x+Sy≡S[x+y] Nm n = N-ind (x+Sy≡S[x+y]A n) A0 is Nm where postulate A0 : x+Sy≡S[x+y]A n zero {-# ATP prove A0 #-} postulate is : ∀ {i} → x+Sy≡S[x+y]A n i → x+Sy≡S[x+y]A n (succ₁ i) {-# ATP prove is #-} -- See Issue https://github.com/asr/apia/issues/81 . +-commA : D → D → Set +-commA n i = i + n ≡ n + i {-# ATP definition +-commA #-} +-comm : ∀ {m n} → N m → N n → m + n ≡ n + m +-comm {n = n} Nm Nn = N-ind (+-commA n) A0 is Nm where postulate A0 : +-commA n zero {-# ATP prove A0 +-rightIdentity #-} postulate is : ∀ {i} → +-commA n i → +-commA n (succ₁ i) {-# ATP prove is x+Sy≡S[x+y] #-}
30.12037
78
0.503843
4e75b5209cd6b120e13fa147b8417e4919475c7c
554
agda
Agda
agda-stdlib/src/Data/List/Relation/Lex/NonStrict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Lex/NonStrict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Lex/NonStrict.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Lex.NonStrict directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Lex.NonStrict where open import Data.List.Relation.Binary.Lex.NonStrict public {-# WARNING_ON_IMPORT "Data.List.Relation.Lex.NonStrict was deprecated in v1.0. Use Data.List.Relation.Binary.Lex.NonStrict instead." #-}
30.777778
72
0.559567
34e345c3fa464373d0e926d91f1d956d031e314b
1,374
agda
Agda
agda-stdlib/src/Data/Product/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Product/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Product/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of products ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product.Properties where open import Data.Product open import Function using (_∘_) open import Relation.Binary using (Decidable) open import Relation.Binary.PropositionalEquality open import Relation.Nullary.Product import Relation.Nullary.Decidable as Dec ------------------------------------------------------------------------ -- Equality (dependent) module _ {a b} {A : Set a} {B : A → Set b} where ,-injectiveˡ : ∀ {a c} {b : B a} {d : B c} → (a , b) ≡ (c , d) → a ≡ c ,-injectiveˡ refl = refl -- See also Data.Product.Properties.WithK.,-injectiveʳ. ------------------------------------------------------------------------ -- Equality (non-dependent) module _ {a b} {A : Set a} {B : Set b} where ,-injectiveʳ : ∀ {a c : A} {b d : B} → (a , b) ≡ (c , d) → b ≡ d ,-injectiveʳ refl = refl ,-injective : ∀ {a c : A} {b d : B} → (a , b) ≡ (c , d) → a ≡ c × b ≡ d ,-injective refl = refl , refl ≡-dec : Decidable {A = A} _≡_ → Decidable {A = B} _≡_ → Decidable {A = A × B} _≡_ ≡-dec dec₁ dec₂ (a , b) (c , d) = Dec.map′ (uncurry (cong₂ _,_)) ,-injective (dec₁ a c ×-dec dec₂ b d)
31.953488
73
0.47016
4ef8e9220df2077e6e6f004252d434450d91a61a
744
agda
Agda
Cubical/Data/DescendingList/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/DescendingList/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/DescendingList/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
------------------------------------------------------------------------ -- Descending lists ------------------------------------------------------------------------ {-# OPTIONS --safe #-} open import Cubical.Foundations.Everything module Cubical.Data.DescendingList.Base (A : Type₀) (_≥_ : A → A → Type₀) where ------------------------------------------------------------------------ -- Descending lists -- -- Defined simultaneously with the relation "x ≥ the HEAD of u" data DL : Type₀ data _≥ᴴ_ (x : A) : DL → Type₀ data DL where [] : DL cons : (x : A) (u : DL) → x ≥ᴴ u → DL data _≥ᴴ_ x where ≥ᴴ[] : x ≥ᴴ [] ≥ᴴcons : {y : A} {u : DL} {r : y ≥ᴴ u} → x ≥ y → x ≥ᴴ (cons y u r) [_] : A → DL [ x ] = cons x [] ≥ᴴ[]
21.882353
72
0.385753
0dc5fe99b744a3a328a5be0f68b4bbc4fa60c381
1,533
agda
Agda
Graph/Walk/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Graph/Walk/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Graph/Walk/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Type module Graph.Walk.Proofs {ℓ₁ ℓ₂} {V : Type{ℓ₁}} where open import Lang.Instance open import Logic import Lvl open import Graph{ℓ₁}{ℓ₂}(V) open import Graph.Walk{ℓ₁}{ℓ₂}{V} open import Relator.Equals.Proofs.Equiv import Structure.Relator.Names as Names open import Structure.Relator.Properties open import Type.Properties.Singleton private variable ℓ : Lvl.Level private variable _⟶_ : Graph private variable a b : V private variable _▫_ : V → V → Type{ℓ} -- There is a walk between two vertices when there is one edge between them. instance Walk-super : (_⟶_) ⊆₂ (Walk(_⟶_)) _⊆₂_.proof Walk-super p = prepend p at -- Walk is a "smallest" reflexive-transitive closure Walk-sub : ⦃ _ : Reflexivity(_▫_) ⦄ → ⦃ _ : Transitivity(_▫_) ⦄ → ⦃ _ : (_⟶_) ⊆₂ (_▫_) ⦄ → (Walk(_⟶_)) ⊆₂ (_▫_) Walk-sub {_▫_ = _▫_}{_⟶_ = _⟶_} = intro proof where proof : Names.Subrelation(Walk(_⟶_))(_▫_) proof at = transitivity(_▫_) (reflexivity(_▫_)) (reflexivity(_▫_)) proof (prepend ab1 walkb1b) = transitivity(_▫_) (sub₂(_⟶_)(_▫_) ab1) (proof walkb1b) Walk-transitivity-raw : Names.Transitivity(Walk(_⟶_)) Walk-transitivity-raw at xz = xz Walk-transitivity-raw (prepend xb by) yz = prepend xb (Walk-transitivity-raw by yz) instance -- A walk can be joined/concatenated to form a new walk. Walk-transitivity : Transitivity(Walk(_⟶_)) Transitivity.proof Walk-transitivity = Walk-transitivity-raw instance Walk-reflexivity : Reflexivity(Walk(_⟶_)) Walk-reflexivity = intro at
34.840909
111
0.694716
2164635d8061220e378978ad5cc96e63c0df56ef
5,058
agda
Agda
cohesion/david_jaz_261/PropT.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
6
2021-10-06T17:39:22.000Z
2022-02-13T05:51:12.000Z
cohesion/david_jaz_261/PropT.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
cohesion/david_jaz_261/PropT.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} module PropT where open import Base open import lib.Basics open import lib.types.Sigma open import lib.NType2 open import lib.types.Truncation open import lib.types.Lift _is-contractible : {i : ULevel} (A : Type i) → Type i _is-contractible = is-contr ⊤-is-contr : ⊤ is-contractible ⊤-is-contr = has-level-in (unit , (λ {unit → refl})) contr-≃-⊤ : {i : ULevel} {A : Type i} (c : A is-contractible) → A ≃ ⊤ contr-≃-⊤ {A = A} c = equiv (λ _ → unit) (λ { unit → contr-center c }) (λ {unit → refl}) (λ a → contr-path c a) _is-a-prop : ∀ {i} → (A : Type i) → Type i A is-a-prop = is-prop A PropT : (i : ULevel) → Type _ PropT = hProp PropT₀ = hProp₀ _holds : ∀ {i} (P : PropT i) → Type i _holds = fst _holds-is-a-prop : {i : ULevel} (P : PropT i) → (P holds) is-a-prop _holds-is-a-prop = snd ∥_∥ : ∀ {i} (A : Type i) → Type i ∥_∥ = Trunc -1 True : PropT₀ True = ⊤ , contr-is-prop ⊤-is-contr False : PropT₀ False = ⊥ , has-level-in (λ x → quodlibet x) _And_ : ∀ {i j} → (A : Type i) (B : Type j) → Type (lmax i j) A And B = Σ A (λ _ → B) _And→_ : ∀ {i j k l} {A : Type i} {B : Type j} {C : Type k} {D : Type l} (f : A → C) (g : B → D) → (A And B) → (C And D) f And→ g = λ { (a , b) → f a , g b } infixl 30 _∧_ _∧_ : ∀ {i j} (P : PropT i) (Q : PropT j) → PropT (lmax i j) P ∧ Q = ((P holds) And (Q holds)) , Σ-level (P holds-is-a-prop) (λ _ → Q holds-is-a-prop) infixl 35 _∨_ _∨_ : ∀ {i j} (P : PropT i) (Q : PropT j) → PropT (lmax i j) P ∨ Q = ∥ (P holds) ⊔ (Q holds) ∥ , ⟨⟩ mapping-into-prop-is-a-prop : {i j : ULevel} {A : Type i} {P : A → Type j} (f : (a : A) → ((P a) is-a-prop)) → ((a : A) → P a) is-a-prop mapping-into-prop-is-a-prop f = all-paths-is-prop (λ x y → λ= (λ a → prop-path (f a) (x a) (y a))) _⇒_ : ∀ {i j} (P : PropT i) (Q : PropT j) → PropT (lmax i j) P ⇒ Q = (P holds → Q holds) , mapping-into-prop-is-a-prop (λ _ → Q holds-is-a-prop) not : ∀ {i} (P : PropT i) → PropT i not P = P ⇒ False {- To say ``There exists an a : A such that B a", write ∃ (λ (a : A) → B a) -} ∃ : {i j : ULevel} {A : Type i} (B : A → Type j) → PropT (lmax i j) ∃ {_} {_} {A} B = ∥ (Σ A B) ∥ , ⟨⟩ ∃ₚ : ∀ {i j} {A : Type i} (B : A → PropT j) → PropT (lmax i j) ∃ₚ {A = A} B = ∃ λ (a : A) → (B a) holds ∀ₚ : ∀ {i j} {A : Type i} (P : A → PropT j) → PropT (lmax i j) ∀ₚ P = (∀ a → (P a) holds) , mapping-into-prop-is-a-prop (λ a → (P a) holds-is-a-prop) _holds-implies-dec-eq : {i : ULevel} (P : PropT i) → P holds → (P holds) ≃ (Dec (P holds)) (P holds-implies-dec-eq) p = equiv (λ _ → inl p) ((λ { (inl q) → q ; (inr nq) → quodlibet (nq p) })) (λ { (inl q) → ap inl (prop-path (P holds-is-a-prop) p q) ; (inr nq) → quodlibet (nq p) }) (λ q → prop-path (P holds-is-a-prop) p q) _holds-by_implies-=-True : (P : PropT₀) (p : P holds) → P == True (P , q) holds-by p implies-=-True = pair= left-id right-id where left-id : P == ⊤ left-id = (ua {A = P} {B = True holds} (contr-≃-⊤ {A = P} (inhab-prop-is-contr p {{q}}))) right-id : q == (snd True) [ _is-a-prop ↓ left-id ] right-id = from-transp _is-a-prop left-id (prop-path (has-level-is-prop) (transport _is-a-prop left-id q) (snd True) ) ¬-_holds-by_implies-=-False : (P : PropT₀) (p : ¬ (P holds)) → P == False ¬- (P , q) holds-by np implies-=-False = pair= left-id right-id where left-id : P == ⊥ left-id = ua {A = P} {B = False holds} e where e : P ≃ ⊥ e = equiv np (λ ()) (λ ()) (λ p → quodlibet (np p)) right-id : q == (snd False) [ _is-a-prop ↓ left-id ] right-id = from-transp _is-a-prop left-id (prop-path (has-level-is-prop) (transport _is-a-prop left-id q) (snd False)) iff-to-≃ : ∀ {i j} {P : PropT i} {Q : PropT j} → (P holds → Q holds) → (Q holds → P holds) → (P holds) ≃ (Q holds) iff-to-≃ {P = P} {Q = Q} f g = equiv f g (λ b → prop-path (snd Q) (f (g b)) b) (λ a → prop-path (snd P) (g (f a)) a) -- Propositional Resizing lift-prop : {i j : ULevel} → PropT i → PropT (lmax i j) lift-prop {i} {j} (P , q) = (Lift {i} {j} P) , Lift-level q postulate prop-resize : {i j : ULevel} → (lift-prop {i} {j}) is-an-equiv resize-eq : {i j : ULevel} → PropT i ≃ PropT (lmax i j) resize-eq {i} {j} = (lift-prop {i} {j}) , prop-resize resize₀ : {i : ULevel} → PropT i → PropT₀ resize₀ {i} = <– (resize-eq {lzero} {i}) unresize₀ : {i : ULevel} → PropT₀ → PropT i unresize₀ {i} = –> (resize-eq {lzero} {i})
33.946309
98
0.469355
5eeff306b293cf74a1b1836a42ed5cdd95c2c312
386
agda
Agda
Data/Binary/Definitions.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
1
2019-03-21T21:30:10.000Z
2019-03-21T21:30:10.000Z
Data/Binary/Definitions.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
null
null
null
Data/Binary/Definitions.agda
oisdk/agda-binary
92af4d620febd47a9791d466d747278dc4a417aa
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Data.Binary.Definitions where open import Function open import Data.Binary.Bits public open import Data.List using (_∷_) renaming ([] to 1ᵇ) public open import Data.Maybe open import Data.Product 𝔹⁺ : Set 𝔹⁺ = Data.List.List Bit 𝔹 : Set 𝔹 = Maybe 𝔹⁺ infixr 5 0<_ pattern 0ᵇ = nothing pattern 0<_ x = just x 𝔹± : Set 𝔹± = Maybe (Bit × 𝔹⁺)
16.782609
60
0.69171
5e5db90c8ba503142c58fbeaf7ada8d5adceed2b
2,052
agda
Agda
PointedFrac.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
PointedFrac.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
PointedFrac.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
3
2016-05-29T01:56:33.000Z
2019-09-10T09:47:13.000Z
module PointedFrac where open import Data.Sum open import Data.Product record ∙_ (A : Set) : Set where constructor ⇡ field focus : A open ∙_ -- Paths between values---identical to dynamic semantics? data _⟷_ : {A B : Set} → ∙ A → ∙ B → Set1 where id : {A : Set} → (x : A) → (⇡ x) ⟷ (⇡ x) swap₊₁ : {A B : Set} → {x : A} → _⟷_ {A ⊎ B} {B ⊎ A} (⇡ (inj₁ x)) (⇡ (inj₂ x)) swap₊₂ : {A B : Set} → {y : B} → _⟷_ {A ⊎ B} {B ⊎ A} (⇡ (inj₂ y)) (⇡ (inj₁ y)) swap× : {A B : Set} → {x : A} → {y : B} ‌→ ⇡ (x , y) ⟷ ⇡ (y , x) -- ...and so on -- shorter arrow for a shorter definition! data _↔_ : Set → Set → Set1 where id : {A : Set} → A ↔ A swap₊ : {A B : Set} → (A ⊎ B) ↔ (B ⊎ A) swap× : {A B : Set} → (A × B) ↔ (B × A) -- Theorem, equivalent to stepping: if c : A ↔ B and v : A, then there exists v' : B and c' : (∙ v) ⟷ (∙ v') eval : {A B : Set} → (A ↔ B) → (v : A) → Σ[ v' ∈ B ] ((⇡ v) ⟷ (⇡ v')) eval id v = v , id v eval swap₊ (inj₁ x) = inj₂ x , swap₊₁ eval swap₊ (inj₂ y) = inj₁ y , swap₊₂ eval swap× (x , y) = (y , x) , swap× -- Theorem, equivalent to backwards stepping: -- if c : A ↔ B and v' : B, then there exists v : A and c' : (∙ v) ⟷ (∙ v') evalB : {A B : Set} → (A ↔ B) → (v' : B) → Σ[ v ∈ A ] ((⇡ v) ⟷ (⇡ v')) evalB id v = v , id v evalB swap₊ (inj₁ x) = inj₂ x , swap₊₂ evalB swap₊ (inj₂ y) = inj₁ y , swap₊₁ evalB swap× (x , y) = (y , x) , swap× -- if c : A ↔ B and v : A, then evalB c (eval c v) ⟷ v right-inv : {A B : Set} → (c : A ↔ B) → (v : A) → ⇡ (proj₁ (evalB c (proj₁ (eval c v)))) ⟷ ⇡ v right-inv id v = id v right-inv swap₊ (inj₁ x) = id (inj₁ x) right-inv swap₊ (inj₂ y) = id (inj₂ y) right-inv swap× v = id v -- left-inv should be just as easy. -- we should also be able to make a statement about proj₂ associated with back-and-forth -- and create a function that maps c to its inverse, and 'prove' eval c = evalB @ inverse c -- "forget" the extra structure ↓ : {A B : Set} → {x : A} → {y : B} → (⇡ x) ⟷ (⇡ y) → A ↔ B ↓ {A} {.A} {x} (id .x) = id ↓ swap₊₁ = swap₊ ↓ swap₊₂ = swap₊ ↓ swap× = swap×
33.096774
108
0.508285
398127718c1a2e61790cedf3d18efece03d96b46
4,320
agda
Agda
examples/simple-lib/Lib/Monad.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/simple-lib/Lib/Monad.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/simple-lib/Lib/Monad.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Lib.Monad where open import Lib.Nat open import Lib.List open import Lib.IO hiding (IO; mapM) open import Lib.Maybe open import Lib.Prelude infixr 40 _>>=_ _>>_ infixl 90 _<*>_ _<$>_ -- Wrapper type, used to ensure that ElM is constructor-headed. record IO (A : Set) : Set where constructor io field unIO : Lib.IO.IO A open IO -- State monad transformer data StateT (S : Set)(M : Set -> Set)(A : Set) : Set where stateT : (S -> M (A × S)) -> StateT S M A runStateT : forall {S M A} -> StateT S M A -> S -> M (A × S) runStateT (stateT f) = f -- Reader monad transformer data ReaderT (E : Set)(M : Set -> Set)(A : Set) : Set where readerT : (E -> M A) -> ReaderT E M A runReaderT : forall {E M A} -> ReaderT E M A -> E -> M A runReaderT (readerT f) = f -- The monad class data Monad : Set1 where maybe : Monad list : Monad io : Monad state : Set -> Monad -> Monad reader : Set -> Monad -> Monad ElM : Monad -> Set -> Set ElM maybe = Maybe ElM list = List ElM io = IO ElM (state S m) = StateT S (ElM m) ElM (reader E m) = ReaderT E (ElM m) return : {m : Monad}{A : Set} -> A -> ElM m A return {maybe} x = just x return {list} x = x :: [] return {io} x = io (returnIO x) return {state _ m} x = stateT \s -> return (x , s) return {reader _ m} x = readerT \_ -> return x _>>=_ : {m : Monad}{A B : Set} -> ElM m A -> (A -> ElM m B) -> ElM m B _>>=_ {maybe} nothing k = nothing _>>=_ {maybe} (just x) k = k x _>>=_ {list} xs k = foldr (\x ys -> k x ++ ys) [] xs _>>=_ {io} (io m) k = io (bindIO m (unIO ∘ k)) _>>=_ {state S m} (stateT f) k = stateT \s -> f s >>= rest where rest : _ × _ -> ElM m _ rest (x , s) = runStateT (k x) s _>>=_ {reader E m} (readerT f) k = readerT \e -> f e >>= \x -> runReaderT (k x) e -- State monad class data StateMonad (S : Set) : Set1 where state : Monad -> StateMonad S reader : Set -> StateMonad S -> StateMonad S ElStM : {S : Set} -> StateMonad S -> Monad ElStM {S} (state m) = state S m ElStM (reader E m) = reader E (ElStM m) ElSt : {S : Set} -> StateMonad S -> Set -> Set ElSt m = ElM (ElStM m) get : {S : Set}{m : StateMonad S} -> ElSt m S get {m = state m} = stateT \s -> return (s , s) get {m = reader E m} = readerT \_ -> get put : {S : Set}{m : StateMonad S} -> S -> ElSt m Unit put {m = state m} s = stateT \_ -> return (unit , s) put {m = reader E m} s = readerT \_ -> put s -- Reader monad class data ReaderMonad (E : Set) : Set1 where reader : Monad -> ReaderMonad E state : Set -> ReaderMonad E -> ReaderMonad E ElRdM : {E : Set} -> ReaderMonad E -> Monad ElRdM {E} (reader m) = reader E m ElRdM (state S m) = state S (ElRdM m) ElRd : {E : Set} -> ReaderMonad E -> Set -> Set ElRd m = ElM (ElRdM m) ask : {E : Set}{m : ReaderMonad E} -> ElRd m E ask {m = reader m } = readerT \e -> return e ask {m = state S m} = stateT \s -> ask >>= \e -> return (e , s) local : {E A : Set}{m : ReaderMonad E} -> (E -> E) -> ElRd m A -> ElRd m A local {m = reader _ } f (readerT m) = readerT \e -> m (f e) local {m = state S _} f (stateT m) = stateT \s -> local f (m s) -- Derived functions -- Monad operations _>>_ : {m : Monad}{A B : Set} -> ElM m A -> ElM m B -> ElM m B m₁ >> m₂ = m₁ >>= \_ -> m₂ _<*>_ : {m : Monad}{A B : Set} -> ElM m (A -> B) -> ElM m A -> ElM m B mf <*> mx = mf >>= \f -> mx >>= \x -> return (f x) _<$>_ : {m : Monad}{A B : Set} -> (A -> B) -> ElM m A -> ElM m B f <$> m = return f <*> m mapM : {m : Monad}{A B : Set} -> (A -> ElM m B) -> List A -> ElM m (List B) mapM f [] = return [] mapM f (x :: xs) = _::_ <$> f x <*> mapM f xs -- State monad operations modify : {S : Set}{m : StateMonad S} -> (S -> S) -> ElSt m Unit modify f = get >>= \s -> put (f s) -- Test -- foo : Nat -> Maybe (Nat × Nat) -- foo s = runReaderT (runStateT m s) s -- where -- m₁ : StateT Nat (ReaderT Nat Maybe) Nat -- m₁ = local suc (ask >>= \s -> put (s + 3) >> get) -- The problem: nested injective function don't seem to work -- as well as one could hope. In this case: -- ElM (ElRd ?0) == ReaderT Nat Maybe -- inverts to -- ElRd ?0 == reader Nat ?1 -- ElM ?1 == Maybe -- it seems that the injectivity of ElRd isn't taken into account(?) -- m : ReaderT Nat Maybe Nat -- m = ask
27.870968
81
0.55
03c7f8a9f0344fab0197340c90009500dcde2fe9
567
agda
Agda
test/interaction/Issue2590.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
test/interaction/Issue2590.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/interaction/Issue2590.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2017-05-24, issue #2590 -- Making variables visible by case splitting in with-clauses -- {-# OPTIONS -v interaction.case:20 #-} -- {-# OPTIONS -v reify:100 #-} -- {-# OPTIONS -v tc.display:100 #-} open import Agda.Builtin.Nat test1 : {x : Nat} → Nat test1 with Set ... | q = {!.x!} -- C-c C-c -- Expected result: -- test1 {x} | q = ? data Any (x : Nat) : Set where any : Any x postulate zonk : ∀{x} → Any x → Nat test2 : {x y : Nat} → Any y → Nat test2 p with zonk p ... | q = {!.y!} -- C-c C-c -- Expected result: -- test2 {y = y} p | q = ?
19.551724
61
0.560847
52f02c2ac3e5eb0b0a5482c22fa62ea81893505f
907
agda
Agda
Cubical/Data/Nat/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
Cubical/Data/Nat/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Data/Nat/Base.agda
L-TChen/cubical
60226aacd7b386aef95d43a0c29c4eec996348a8
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.Data.Nat.Base where open import Cubical.Core.Primitives open import Agda.Builtin.Nat public using (zero; suc; _+_) renaming (Nat to ℕ; _-_ to _∸_; _*_ to _·_) open import Cubical.Data.Nat.Literals public predℕ : ℕ → ℕ predℕ zero = zero predℕ (suc n) = n caseNat : ∀ {ℓ} → {A : Type ℓ} → (a0 aS : A) → ℕ → A caseNat a0 aS zero = a0 caseNat a0 aS (suc n) = aS doubleℕ : ℕ → ℕ doubleℕ zero = zero doubleℕ (suc x) = suc (suc (doubleℕ x)) -- doublesℕ n m = 2^n · m doublesℕ : ℕ → ℕ → ℕ doublesℕ zero m = m doublesℕ (suc n) m = doublesℕ n (doubleℕ m) -- iterate iter : ∀ {ℓ} {A : Type ℓ} → ℕ → (A → A) → A → A iter zero f z = z iter (suc n) f z = f (iter n f z) elim : ∀ {ℓ} {A : ℕ → Type ℓ} → A zero → ((n : ℕ) → A n → A (suc n)) → (n : ℕ) → A n elim a₀ _ zero = a₀ elim a₀ f (suc n) = f n (elim a₀ f n)
22.675
67
0.583241
371d71507bc997130f6f0cb2ca67135d3cdbd41a
4,531
agda
Agda
Formalization/PredicateLogic/Classical/NaturalDeduction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Formalization/PredicateLogic/Classical/NaturalDeduction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Formalization/PredicateLogic/Classical/NaturalDeduction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Formalization.PredicateLogic.Signature module Formalization.PredicateLogic.Classical.NaturalDeduction (𝔏 : Signature) where open Signature(𝔏) open import Data.ListSized import Lvl open import Formalization.PredicateLogic.Syntax(𝔏) open import Formalization.PredicateLogic.Syntax.Substitution(𝔏) open import Functional using (_∘_ ; _∘₂_ ; swap) open import Numeral.Finite open import Numeral.Natural open import Relator.Equals.Proofs.Equiv open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to · ; _≡_ to _≡ₛ_) open import Type private variable ℓ : Lvl.Level private variable args vars : ℕ private variable Γ : PredSet{ℓ}(Formula(vars)) data _⊢_ {ℓ} : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ ℓ)} where direct : (Γ ⊆ (Γ ⊢_)) [⊤]-intro : (Γ ⊢ ⊤) [⊥]-elim : ∀{φ} → ((Γ ∪ ·(¬ φ)) ⊢ ⊥) → (Γ ⊢ φ) [∧]-intro : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ ψ) → (Γ ⊢ (φ ∧ ψ)) [∧]-elimₗ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ φ) [∧]-elimᵣ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ ψ) [∨]-introₗ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ∨ ψ)) [∨]-introᵣ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ∨ ψ)) [∨]-elim : ∀{φ ψ χ} → ((Γ ∪ · φ) ⊢ χ) → ((Γ ∪ · ψ) ⊢ χ) → (Γ ⊢ (φ ∨ ψ)) → (Γ ⊢ χ) [⟶]-intro : ∀{φ ψ} → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟶ ψ)) [⟶]-elim : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟶ ψ)) → (Γ ⊢ ψ) [Ɐ]-intro : ∀{φ} → (∀{t} → (Γ ⊢ (substitute0 t φ))) → (Γ ⊢ (Ɐ φ)) [Ɐ]-elim : ∀{φ} → (Γ ⊢ (Ɐ φ)) → ∀{t} → (Γ ⊢ (substitute0 t φ)) [∃]-intro : ∀{φ}{t} → (Γ ⊢ (substitute0 t φ)) → (Γ ⊢ (∃ φ)) [∃]-elim : ∀{φ ψ} → (∀{t} → (Γ ∪ ·(substitute0 t φ)) ⊢ ψ) → (Γ ⊢ (∃ φ)) → (Γ ⊢ ψ) module _ where open import Data.Either as Either import Logic.Propositional as Meta open import Relator.Equals private variable Γ₁ Γ₂ : PredSet{ℓ}(Formula(vars)) private variable φ ψ : Formula(vars) _⊬_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type _⊬_ = Meta.¬_ ∘₂ (_⊢_) [⟵]-intro : ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (ψ ⟵ φ)) [⟵]-intro = [⟶]-intro [⟵]-elim : (Γ ⊢ φ) → (Γ ⊢ (ψ ⟵ φ)) → (Γ ⊢ ψ) [⟵]-elim = [⟶]-elim [¬]-intro : ((Γ ∪ · φ) ⊢ ⊥) → (Γ ⊢ (¬ φ)) [¬]-intro = [⟶]-intro [⟷]-intro : ∀{φ ψ} → ((Γ ∪ · ψ) ⊢ φ) → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ)) [⟷]-intro l r = [∧]-intro ([⟶]-intro l) ([⟶]-intro r) [⟷]-elimₗ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ φ) [⟷]-elimₗ Γψ Γφψ = [⟶]-elim Γψ ([∧]-elimₗ Γφψ) [⟷]-elimᵣ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ ψ) [⟷]-elimᵣ Γφ Γφψ = [⟶]-elim Γφ ([∧]-elimᵣ Γφψ) weaken-union-singleton : (Γ₁ ⊆ Γ₂) → (((Γ₁ ∪ · φ) ⊢_) ⊆ ((Γ₂ ∪ · φ) ⊢_)) weaken : (Γ₁ ⊆ Γ₂) → ((Γ₁ ⊢_) ⊆ (Γ₂ ⊢_)) weaken Γ₁Γ₂ {φ} (direct p) = direct (Γ₁Γ₂ p) weaken Γ₁Γ₂ {.⊤} [⊤]-intro = [⊤]-intro weaken Γ₁Γ₂ {φ} ([⊥]-elim p) = [⊥]-elim (weaken-union-singleton Γ₁Γ₂ p) weaken Γ₁Γ₂ {.(_ ∧ _)} ([∧]-intro p q) = [∧]-intro (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q) weaken Γ₁Γ₂ {φ} ([∧]-elimₗ p) = [∧]-elimₗ (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {φ} ([∧]-elimᵣ p) = [∧]-elimᵣ (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introₗ p) = [∨]-introₗ (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introᵣ p) = [∨]-introᵣ (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {φ} ([∨]-elim p q r) = [∨]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken-union-singleton Γ₁Γ₂ q) (weaken Γ₁Γ₂ r) weaken Γ₁Γ₂ {.(_ ⟶ _)} ([⟶]-intro p) = [⟶]-intro (weaken-union-singleton Γ₁Γ₂ p) weaken Γ₁Γ₂ {φ} ([⟶]-elim p q) = [⟶]-elim (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q) weaken Γ₁Γ₂ {.(Ɐ _)} ([Ɐ]-intro p) = [Ɐ]-intro (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {.(substitute0 _ _)} ([Ɐ]-elim p) = [Ɐ]-elim (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {.(∃ _)} ([∃]-intro p) = [∃]-intro (weaken Γ₁Γ₂ p) weaken Γ₁Γ₂ {φ} ([∃]-elim p q) = [∃]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken Γ₁Γ₂ q) weaken-union-singleton Γ₁Γ₂ p = weaken (Either.mapLeft Γ₁Γ₂) p weaken-union : (Γ₁ ⊢_) ⊆ ((Γ₁ ∪ Γ₂) ⊢_) weaken-union = weaken Left [⊥]-elim-constructive : (Γ ⊢ ⊥) → (Γ ⊢ φ) [⊥]-elim-constructive Γ⊥ = [⊥]-elim (weaken-union Γ⊥) [¬¬]-elim : (Γ ⊢ ¬(¬ φ)) → (Γ ⊢ φ) [¬¬]-elim nnφ = ([⊥]-elim ([⟶]-elim (direct(Right [≡]-intro)) (weaken-union nnφ) ) ) [¬¬]-intro : (Γ ⊢ φ) → (Γ ⊢ ¬(¬ φ)) [¬¬]-intro Γφ = ([¬]-intro ([⟶]-elim (weaken-union Γφ) (direct (Right [≡]-intro)) ) )
38.726496
151
0.472523
fdd0be75c0407b9654129af8538949ee3ce29865
1,325
agda
Agda
Cubical/HITs/Truncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/HITs/Truncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/HITs/Truncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- A simpler definition of truncation ∥ A ∥ n from n ≥ -1 Note that this uses the HoTT book's indexing, so it will be off from `∥_∥_` in HITs.Truncation.Base by -2 -} {-# OPTIONS --safe #-} module Cubical.HITs.Truncation.Base where open import Cubical.Data.NatMinusOne open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Pointed open import Cubical.HITs.Sn.Base open import Cubical.Data.Nat.Base open import Cubical.Data.Unit.Base open import Cubical.Data.Empty -- this definition is off by one. Use hLevelTrunc or ∥_∥ for truncations -- (off by 2 w.r.t. the HoTT-book) data HubAndSpoke {ℓ} (A : Type ℓ) (n : ℕ) : Type ℓ where ∣_∣ : A → HubAndSpoke A n hub : (f : S₊ n → HubAndSpoke A n) → HubAndSpoke A n spoke : (f : S₊ n → HubAndSpoke A n) (x : S₊ n) → hub f ≡ f x hLevelTrunc : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Type ℓ hLevelTrunc zero A = Unit* hLevelTrunc (suc n) A = HubAndSpoke A n ∥_∥_ : ∀ {ℓ} (A : Type ℓ) (n : ℕ) → Type ℓ ∥ A ∥ n = hLevelTrunc n A ∣_∣ₕ : ∀ {ℓ} {A : Type ℓ} {n : ℕ} → A → ∥ A ∥ n ∣_∣ₕ {n = zero} a = tt* ∣_∣ₕ {n = suc n} a = ∣ a ∣ -- Pointed version hLevelTrunc∙ : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Pointed ℓ fst (hLevelTrunc∙ n A) = hLevelTrunc n (typ A) snd (hLevelTrunc∙ zero A) = tt* snd (hLevelTrunc∙ (suc n) A) = ∣ pt A ∣ₕ
30.113636
72
0.645283
4196082f392e87aad6ddb39569e4369356950f3e
713
agda
Agda
test/Fail/Issue543.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/Issue543.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue543.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, bug found 2011-12-31 module Issue543 where import Common.Level import Common.Irrelevance open import Common.Equality data ⊥ : Set where record ⊤ : Set where constructor tt data Bool : Set where true false : Bool T : Bool → Set T true = ⊤ T false = ⊥ record Squash {ℓ}(A : Set ℓ) : Set ℓ where constructor squash field .unsquash : A open Squash -- ok: sqT≡sqF : squash true ≡ squash false sqT≡sqF = refl -- this should not be provable!! .irrT≡F : true ≡ false irrT≡F = subst (λ s → unsquash (squash true) ≡ unsquash s) sqT≡sqF refl -- the rest is easy T≠F : true ≡ false → ⊥ T≠F p = subst T p tt .irr⊥ : ⊥ irr⊥ = T≠F irrT≡F rel⊥ : .⊥ → ⊥ rel⊥ () absurd : ⊥ absurd = rel⊥ irr⊥
15.844444
71
0.643759
4e0d82542dc5df323814877d2b921104addbb8b5
3,241
agda
Agda
Cubical/Foundations/HLevels'.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels'.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels'.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.HLevels' where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Homotopy.Connected open import Cubical.Homotopy.Loopspace open import Cubical.Data.Nat open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Foundations.Structure private variable ℓ : Level isOfHLevel' : HLevel → Type ℓ → Type ℓ isOfHLevel' 0 A = isOfHLevel 0 A isOfHLevel' (suc n) A = (x y : A) → isOfHLevel' n (x ≡ y) isOfHLevel'→ : {n : HLevel} {A : Type ℓ} (l : isOfHLevel' n A) → isOfHLevel n A isOfHLevel'→ {n = 0} l = l isOfHLevel'→ {n = 1} l a b = l a b .fst isOfHLevel'→ {n = suc (suc _)} l a b = isOfHLevel'→ (l a b) isOfHLevel→' : {n : HLevel} {A : Type ℓ} (l : isOfHLevel n A) → isOfHLevel' n A isOfHLevel→' {n = 0} l = l isOfHLevel→' {n = 1} l = isProp→isContrPath l isOfHLevel→' {n = suc (suc _)} l = λ x y → isOfHLevel→' (l x y) isPropIsOfHLevel' : (n : HLevel) {A : Type ℓ} → isProp (isOfHLevel' n A) isPropIsOfHLevel' 0 = isPropIsOfHLevel 0 isPropIsOfHLevel' 1 p q = funExt (λ a → funExt (λ b → isPropIsContr (p a b) (q a b))) isPropIsOfHLevel' (suc (suc n)) f g i a b = isPropIsOfHLevel' (suc n) (f a b) (g a b) i -- isPropIsOfHLevel (suc (suc n)) isOfHLevel≡' : (n : HLevel) {A : Type ℓ} → isOfHLevel n A ≡ isOfHLevel' n A isOfHLevel≡' n = isoToPath (iso isOfHLevel→' isOfHLevel'→ (λ p' → isPropIsOfHLevel' n _ p') λ p → isPropIsOfHLevel n _ p) HL→ = isOfHLevel→' HL← = isOfHLevel'→ module _ {X : Type ℓ} where -- Lemma 7.2.8 in the HoTT book -- For n >= -1, if X being inhabited implies X is an n-type, then X is an n-type inh→ntype→ntype : {n : ℕ} (t : X → isOfHLevel (suc n) X) → isOfHLevel (suc n) X inh→ntype→ntype {n = 0} t = λ x y → t x x y inh→ntype→ntype {n = suc _} t = λ x y → t x x y module _ {X : Type ℓ} where -- Theorem 7.2.7 in the HoTT book -- For n >= -1, X is an (n+1)-type if all its loop spaces are n-types truncSelfId→truncId : {n : ℕ} → ((x : X) → isOfHLevel (suc n) (x ≡ x)) → isOfHLevel (suc (suc n)) X truncSelfId→truncId {n = 0} t = λ x x' → inh→ntype→ntype {n = 0} λ p → J (λ y q → isOfHLevel 1 (x ≡ y)) (t x) p truncSelfId→truncId {n = suc m} t = λ x x' → inh→ntype→ntype {n = suc m} λ p → J (λ y q → isOfHLevel (suc (suc m)) (x ≡ y)) (t x) p EquivPresHLevel : {Y : Type ℓ} → {n : ℕ} → (X≃Y : X ≃ Y) → (hX : isOfHLevel n X) → isOfHLevel n Y EquivPresHLevel {Y} {n} X≃Y hX = subst (λ x → isOfHLevel n x) (ua X≃Y) hX
41.025316
121
0.600123
146d89abb575e8887260e160ba65090b3d4b8647
11,662
agda
Agda
src/Examples/Sorting/Parallel/MergeSort.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
29
2021-07-14T03:18:28.000Z
2022-03-22T20:35:11.000Z
src/Examples/Sorting/Parallel/MergeSort.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
null
null
null
src/Examples/Sorting/Parallel/MergeSort.agda
jonsterling/agda-calf
e51606f9ca18d8b4cf9a63c2d6caa2efc5516146
[ "Apache-2.0" ]
2
2021-10-06T10:28:24.000Z
2022-01-29T08:12:01.000Z
{-# OPTIONS --prop --rewriting #-} open import Examples.Sorting.Parallel.Comparable module Examples.Sorting.Parallel.MergeSort (M : Comparable) where open Comparable M open import Examples.Sorting.Parallel.Core M open import Calf costMonoid open import Calf.ParMetalanguage parCostMonoid open import Calf.Types.Nat open import Calf.Types.List open import Calf.Types.Bounded costMonoid open import Calf.Types.BigO costMonoid open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning) open import Data.Product using (_×_; _,_; ∃; proj₁; proj₂) open import Data.Nat as Nat using (ℕ; zero; suc; z≤n; _+_; _*_; ⌊_/2⌋; ⌈_/2⌉; _⊔_) open import Data.Nat.Properties as N using (module ≤-Reasoning) open import Data.Nat.Log2 open import Examples.Sorting.Parallel.MergeSort.Split M public open import Examples.Sorting.Parallel.MergeSort.Merge M public sort/clocked : cmp (Π nat λ _ → Π (list A) λ _ → F (list A)) sort/clocked zero l = ret l sort/clocked (suc k) l = bind (F (list A)) (split l) λ (l₁ , l₂) → bind (F (list A)) (sort/clocked k l₁ & sort/clocked k l₂) merge sort/clocked/correct : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → SortResult (sort/clocked k) l sort/clocked/correct zero l h u = l , refl , refl , short-sorted (⌈log₂n⌉≡0⇒n≤1 (N.n≤0⇒n≡0 h)) sort/clocked/correct (suc k) l h u = let (l₁ , l₂ , ≡ , length₁ , length₂ , ↭) = split/correct l u in let (l₁' , ≡₁ , ↭₁ , sorted₁) = sort/clocked/correct k l₁ ( let open ≤-Reasoning in begin ⌈log₂ length l₁ ⌉ ≡⟨ Eq.cong ⌈log₂_⌉ length₁ ⟩ ⌈log₂ ⌊ length l /2⌋ ⌉ ≤⟨ log₂-mono (N.⌊n/2⌋≤⌈n/2⌉ (length l)) ⟩ ⌈log₂ ⌈ length l /2⌉ ⌉ ≤⟨ log₂-suc (length l) h ⟩ k ∎ ) u in let (l₂' , ≡₂ , ↭₂ , sorted₂) = sort/clocked/correct k l₂ ( let open ≤-Reasoning in begin ⌈log₂ length l₂ ⌉ ≡⟨ Eq.cong ⌈log₂_⌉ length₂ ⟩ ⌈log₂ ⌈ length l /2⌉ ⌉ ≤⟨ log₂-suc (length l) h ⟩ k ∎ ) u in let (l' , ≡' , h-sorted) = merge/correct l₁' l₂' u (↭' , sorted) = h-sorted sorted₁ sorted₂ in l' , ( let open ≡-Reasoning in begin sort/clocked (suc k) l ≡⟨⟩ (bind (F (list A)) (split l) λ (l₁ , l₂) → bind (F (list A)) (sort/clocked k l₁ & sort/clocked k l₂) merge) ≡⟨ Eq.cong (λ e → bind (F (list A)) e _) ≡ ⟩ bind (F (list A)) (sort/clocked k l₁ & sort/clocked k l₂) merge ≡⟨ Eq.cong (λ e → bind (F (list A)) e merge) (Eq.cong₂ _&_ ≡₁ ≡₂) ⟩ merge (l₁' , l₂') ≡⟨ ≡' ⟩ ret l' ∎ ) , ( let open PermutationReasoning in begin l ↭⟨ ↭ ⟩ l₁ ++ l₂ ↭⟨ ++⁺-↭ ↭₁ ↭₂ ⟩ l₁' ++ l₂' ↭⟨ ↭' ⟩ l' ∎ ) , sorted sort/clocked/cost : cmp (Π nat λ _ → Π (list A) λ _ → cost) sort/clocked/cost zero l = 𝟘 sort/clocked/cost (suc k) l = bind cost (split l) λ (l₁ , l₂) → split/cost l ⊕ bind cost (sort/clocked k l₁ & sort/clocked k l₂) λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂') sort/clocked/cost/closed : cmp (Π nat λ _ → Π (list A) λ _ → cost) sort/clocked/cost/closed k l = k * length l , 2 * length l + k sort/clocked/cost≤sort/clocked/cost/closed : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → ◯ (sort/clocked/cost k l ≤ₚ sort/clocked/cost/closed k l) sort/clocked/cost≤sort/clocked/cost/closed zero l h u = z≤n , z≤n sort/clocked/cost≤sort/clocked/cost/closed (suc k) l h u = let (l₁ , l₂ , ≡ , length₁ , length₂ , ↭) = split/correct l u in let h₁ : ⌈log₂ length l₁ ⌉ Nat.≤ k h₁ = let open ≤-Reasoning in begin ⌈log₂ length l₁ ⌉ ≡⟨ Eq.cong ⌈log₂_⌉ length₁ ⟩ ⌈log₂ ⌊ length l /2⌋ ⌉ ≤⟨ log₂-mono (N.⌊n/2⌋≤⌈n/2⌉ (length l)) ⟩ ⌈log₂ ⌈ length l /2⌉ ⌉ ≤⟨ log₂-suc (length l) h ⟩ k ∎ h₂ : ⌈log₂ length l₂ ⌉ Nat.≤ k h₂ = let open ≤-Reasoning in begin ⌈log₂ length l₂ ⌉ ≡⟨ Eq.cong ⌈log₂_⌉ length₂ ⟩ ⌈log₂ ⌈ length l /2⌉ ⌉ ≤⟨ log₂-suc (length l) h ⟩ k ∎ in let (l₁' , ≡₁ , ↭₁ , sorted₁) = sort/clocked/correct k l₁ h₁ u in let (l₂' , ≡₂ , ↭₂ , sorted₂) = sort/clocked/correct k l₂ h₂ u in let open ≤ₚ-Reasoning in begin sort/clocked/cost (suc k) l ≡⟨⟩ (bind cost (split l) λ (l₁ , l₂) → split/cost l ⊕ bind cost (sort/clocked k l₁ & sort/clocked k l₂) λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂')) ≡⟨ Eq.cong (λ e → bind cost e _) (≡) ⟩ (split/cost l ⊕ bind cost (sort/clocked k l₁ & sort/clocked k l₂) λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂')) ≡⟨⟩ (𝟘 ⊕ bind cost (sort/clocked k l₁ & sort/clocked k l₂) λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂')) ≡⟨ ⊕-identityˡ _ ⟩ (bind cost (sort/clocked k l₁ & sort/clocked k l₂) λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂')) ≡⟨ Eq.cong (λ e → bind cost e λ (l₁' , l₂') → (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂')) (Eq.cong₂ _&_ ≡₁ ≡₂) ⟩ (sort/clocked/cost k l₁ ⊗ sort/clocked/cost k l₂) ⊕ merge/cost/closed (l₁' , l₂') ≤⟨ ⊕-monoˡ-≤ (merge/cost/closed (l₁' , l₂')) ( ⊗-mono-≤ (sort/clocked/cost≤sort/clocked/cost/closed k l₁ h₁ u) (sort/clocked/cost≤sort/clocked/cost/closed k l₂ h₂ u) ) ⟩ (sort/clocked/cost/closed k l₁ ⊗ sort/clocked/cost/closed k l₂) ⊕ merge/cost/closed (l₁' , l₂') ≡⟨⟩ (sort/clocked/cost/closed k l₁ ⊗ sort/clocked/cost/closed k l₂) ⊕ (length l₁' + length l₂' , length l₁' + length l₂') ≡˘⟨ Eq.cong ((sort/clocked/cost/closed k l₁ ⊗ sort/clocked/cost/closed k l₂) ⊕_) ( Eq.cong₂ (λ n₁ n₂ → (n₁ + n₂ , n₁ + n₂)) (↭-length ↭₁) (↭-length ↭₂) ) ⟩ (sort/clocked/cost/closed k l₁ ⊗ sort/clocked/cost/closed k l₂) ⊕ (length l₁ + length l₂ , length l₁ + length l₂) ≡⟨⟩ ((k * length l₁ , 2 * length l₁ + k) ⊗ (k * length l₂ , 2 * length l₂ + k)) ⊕ (length l₁ + length l₂ , length l₁ + length l₂) ≡⟨ Eq.cong₂ (λ n₁ n₂ → ((k * n₁ , 2 * n₁ + k) ⊗ (k * n₂ , 2 * n₂ + k)) ⊕ (n₁ + n₂ , n₁ + n₂)) length₁ length₂ ⟩ ((k * ⌊ length l /2⌋ , 2 * ⌊ length l /2⌋ + k) ⊗ (k * ⌈ length l /2⌉ , 2 * ⌈ length l /2⌉ + k)) ⊕ (⌊ length l /2⌋ + ⌈ length l /2⌉ , ⌊ length l /2⌋ + ⌈ length l /2⌉) ≡⟨ Eq.cong (((k * ⌊ length l /2⌋ , 2 * ⌊ length l /2⌋ + k) ⊗ (k * ⌈ length l /2⌉ , 2 * ⌈ length l /2⌉ + k)) ⊕_) ( Eq.cong₂ _,_ (N.⌊n/2⌋+⌈n/2⌉≡n (length l)) (N.⌊n/2⌋+⌈n/2⌉≡n (length l)) ) ⟩ ((k * ⌊ length l /2⌋ , 2 * ⌊ length l /2⌋ + k) ⊗ (k * ⌈ length l /2⌉ , 2 * ⌈ length l /2⌉ + k)) ⊕ (length l , length l) ≤⟨ arithmetic/work (length l) , arithmetic/span (length l) ⟩ suc k * length l , 2 * length l + suc k ≡⟨⟩ sort/clocked/cost/closed (suc k) l ∎ where arithmetic/work : ∀ n → k * ⌊ n /2⌋ + k * ⌈ n /2⌉ + n Nat.≤ suc k * n arithmetic/work n = begin k * ⌊ n /2⌋ + k * ⌈ n /2⌉ + n ≡⟨ N.+-comm _ n ⟩ n + (k * ⌊ n /2⌋ + k * ⌈ n /2⌉) ≡˘⟨ Eq.cong (n +_) (N.*-distribˡ-+ k _ _) ⟩ n + k * (⌊ n /2⌋ + ⌈ n /2⌉) ≡⟨ Eq.cong (λ m → n + k * m) (N.⌊n/2⌋+⌈n/2⌉≡n n) ⟩ n + k * n ≡⟨⟩ suc k * n ∎ where open ≤-Reasoning lemma/2n≡n+n : ∀ n → 2 * n ≡ n + n lemma/2n≡n+n n = Eq.cong (λ m → n + m) (N.+-identityʳ n) arithmetic/span : ∀ n → (2 * ⌊ n /2⌋ + k) ⊔ (2 * ⌈ n /2⌉ + k) + n Nat.≤ 2 * n + suc k arithmetic/span n = begin (2 * ⌊ n /2⌋ + k) ⊔ (2 * ⌈ n /2⌉ + k) + n ≤⟨ N.+-monoˡ-≤ n (N.⊔-monoˡ-≤ (2 * ⌈ n /2⌉ + k) (N.+-monoˡ-≤ k (N.*-monoʳ-≤ 2 (N.⌊n/2⌋≤⌈n/2⌉ n)))) ⟩ (2 * ⌈ n /2⌉ + k) ⊔ (2 * ⌈ n /2⌉ + k) + n ≡⟨ Eq.cong (_+ n) (N.⊔-idem _) ⟩ 2 * ⌈ n /2⌉ + k + n ≡⟨ N.+-assoc (2 * ⌈ n /2⌉) k n ⟩ 2 * ⌈ n /2⌉ + (k + n) ≡⟨ Eq.cong (_+ (k + n)) (lemma/2n≡n+n ⌈ n /2⌉) ⟩ (⌈ n /2⌉ + ⌈ n /2⌉) + (k + n) ≡⟨⟩ (⌊ suc n /2⌋ + ⌈ n /2⌉) + (k + n) ≤⟨ N.+-monoˡ-≤ (k + n) (N.+-monoʳ-≤ ⌊ suc n /2⌋ (N.⌈n/2⌉-mono (N.n≤1+n n))) ⟩ (⌊ suc n /2⌋ + ⌈ suc n /2⌉) + (k + n) ≡⟨ Eq.cong (_+ (k + n)) (N.⌊n/2⌋+⌈n/2⌉≡n (suc n)) ⟩ suc n + (k + n) ≡⟨⟩ suc (n + (k + n)) ≡⟨ Eq.cong (λ m → suc (n + m)) (N.+-comm k n) ⟩ suc (n + (n + k)) ≡˘⟨ Eq.cong suc (N.+-assoc n n k) ⟩ suc ((n + n) + k) ≡˘⟨ N.+-suc (n + n) k ⟩ (n + n) + suc k ≡˘⟨ Eq.cong (_+ suc k) (lemma/2n≡n+n n) ⟩ 2 * n + suc k ∎ where open ≤-Reasoning sort/clocked≤sort/clocked/cost : ∀ k l → IsBounded (list A) (sort/clocked k l) (sort/clocked/cost k l) sort/clocked≤sort/clocked/cost zero l = bound/ret sort/clocked≤sort/clocked/cost (suc k) l = bound/bind _ _ (split≤split/cost l) λ (l₁ , l₂) → bound/bind _ _ (bound/par (sort/clocked≤sort/clocked/cost k l₁) (sort/clocked≤sort/clocked/cost k l₂)) λ (l₁' , l₂') → merge≤merge/cost/closed (l₁' , l₂') sort/clocked≤sort/clocked/cost/closed : ∀ k l → ⌈log₂ length l ⌉ Nat.≤ k → IsBounded (list A) (sort/clocked k l) (sort/clocked/cost/closed k l) sort/clocked≤sort/clocked/cost/closed k l h = bound/relax (sort/clocked/cost≤sort/clocked/cost/closed k l h) (sort/clocked≤sort/clocked/cost k l) sort/depth : cmp (Π (list A) λ _ → meta ℕ) sort/depth l = ⌈log₂ length l ⌉ sort : cmp (Π (list A) λ _ → F (list A)) sort l = sort/clocked (sort/depth l) l sort/correct : IsSort sort sort/correct l = sort/clocked/correct (sort/depth l) l N.≤-refl sort/cost : cmp (Π (list A) λ _ → cost) sort/cost l = sort/clocked/cost (sort/depth l) l sort/cost/closed : cmp (Π (list A) λ _ → cost) sort/cost/closed l = sort/clocked/cost/closed (sort/depth l) l sort≤sort/cost : ∀ l → IsBounded (list A) (sort l) (sort/cost l) sort≤sort/cost l = sort/clocked≤sort/clocked/cost (sort/depth l) l sort≤sort/cost/closed : ∀ l → IsBounded (list A) (sort l) (sort/cost/closed l) sort≤sort/cost/closed l = sort/clocked≤sort/clocked/cost/closed (sort/depth l) l N.≤-refl sort/asymptotic : given (list A) measured-via length , sort ∈𝓞(λ n → n * ⌈log₂ n ⌉ , n) sort/asymptotic = 0 ≤n⇒f[n]≤ 3 g[n]via λ l _ → bound/relax (λ u → let open ≤-Reasoning in ( begin ⌈log₂ length l ⌉ * length l ≡⟨ N.*-comm ⌈log₂ length l ⌉ (length l) ⟩ length l * ⌈log₂ length l ⌉ ≤⟨ N.m≤m+n (length l * ⌈log₂ length l ⌉) _ ⟩ 3 * (length l * ⌈log₂ length l ⌉) ∎ ) , ( begin 2 * length l + ⌈log₂ length l ⌉ ≤⟨ N.+-monoʳ-≤ (2 * length l) (⌈log₂n⌉≤n (length l)) ⟩ 2 * length l + length l ≡⟨ N.+-comm (2 * length l) (length l) ⟩ 3 * length l ∎ ) ) (sort≤sort/cost/closed l)
39.398649
153
0.495455
d1a5817102e8910886514a654a000e1e24c11f0e
934
agda
Agda
benchmark/ac/Vec.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
benchmark/ac/Vec.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
benchmark/ac/Vec.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Vec where import Nat import Fin open Nat hiding (_==_; _<_) open Fin data Nil : Set where vnil : Nil data Cons (A As : Set) : Set where vcons : A -> As -> Cons A As mutual Vec' : Nat -> Set -> Set Vec' zero A = Nil Vec' (suc n) A = Cons A (Vec n A) data Vec (n : Nat)(A : Set) : Set where vec : Vec' n A -> Vec n A ε : {A : Set} -> Vec zero A ε = vec vnil _∷_ : {A : Set}{n : Nat} -> A -> Vec n A -> Vec (suc n) A x ∷ xs = vec (vcons x xs) _!_ : {n : Nat}{A : Set} -> Vec n A -> Fin n -> A _!_ {zero} _ (fin ()) _!_ {suc n} (vec (vcons x xs)) (fin fz) = x _!_ {suc n} (vec (vcons x xs)) (fin (fs i)) = xs ! i map : {n : Nat}{A B : Set} -> (A -> B) -> Vec n A -> Vec n B map {zero} f (vec vnil) = ε map {suc n} f (vec (vcons x xs)) = f x ∷ map f xs fzeroToN-1 : (n : Nat) -> Vec n (Fin n) fzeroToN-1 zero = ε fzeroToN-1 (suc n) = fzero ∷ map fsuc (fzeroToN-1 n)
21.72093
60
0.506424
4e1730484d2911ef6c502ad8d9816882a266b1f0
2,492
agda
Agda
agda-stdlib/src/Codata/Musical/Conat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Codata/Musical/Conat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Codata/Musical/Conat.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Coinductive "natural" numbers ------------------------------------------------------------------------ {-# OPTIONS --without-K --guardedness --sized-types #-} module Codata.Musical.Conat where open import Codata.Musical.Notation open import Data.Nat.Base using (ℕ; zero; suc) open import Function open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) ------------------------------------------------------------------------ -- The type data Coℕ : Set where zero : Coℕ suc : (n : ∞ Coℕ) → Coℕ module Coℕ-injective where suc-injective : ∀ {m n} → (Coℕ ∋ suc m) ≡ suc n → m ≡ n suc-injective P.refl = P.refl ------------------------------------------------------------------------ -- Some operations pred : Coℕ → Coℕ pred zero = zero pred (suc n) = ♭ n fromℕ : ℕ → Coℕ fromℕ zero = zero fromℕ (suc n) = suc (♯ fromℕ n) fromℕ-injective : ∀ {m n} → fromℕ m ≡ fromℕ n → m ≡ n fromℕ-injective {zero} {zero} eq = P.refl fromℕ-injective {suc m} {suc n} eq = P.cong suc (fromℕ-injective (P.cong pred eq)) ∞ℕ : Coℕ ∞ℕ = suc (♯ ∞ℕ) infixl 6 _+_ _+_ : Coℕ → Coℕ → Coℕ zero + n = n suc m + n = suc (♯ (♭ m + n)) ------------------------------------------------------------------------ -- Equality data _≈_ : Coℕ → Coℕ → Set where zero : zero ≈ zero suc : ∀ {m n} (m≈n : ∞ (♭ m ≈ ♭ n)) → suc m ≈ suc n module ≈-injective where suc-injective : ∀ {m n p q} → (suc m ≈ suc n ∋ suc p) ≡ suc q → p ≡ q suc-injective P.refl = P.refl setoid : Setoid _ _ setoid = record { Carrier = Coℕ ; _≈_ = _≈_ ; isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } where refl : Reflexive _≈_ refl {zero} = zero refl {suc n} = suc (♯ refl) sym : Symmetric _≈_ sym zero = zero sym (suc m≈n) = suc (♯ sym (♭ m≈n)) trans : Transitive _≈_ trans zero zero = zero trans (suc m≈n) (suc n≈k) = suc (♯ trans (♭ m≈n) (♭ n≈k)) ------------------------------------------------------------------------ -- Legacy import Codata.Conat as C open import Codata.Thunk import Size fromMusical : ∀ {i} → Coℕ → C.Conat i fromMusical zero = C.zero fromMusical (suc n) = C.suc λ where .force → fromMusical (♭ n) toMusical : C.Conat Size.∞ → Coℕ toMusical C.zero = zero toMusical (C.suc n) = suc (♯ toMusical (n .force))
24.431373
82
0.485152
3793650724b634bd9a31da3ed16951da3dab53cc
105
agda
Agda
test/Fail/Issue3163.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue3163.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue3163.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where module Inner where private variable A : Set open Inner fail : A → A fail x = x
8.076923
20
0.647619
4bd709efb9d55ffb7d305e7561d897a7530e2f1d
903
agda
Agda
Numeral/Finite/Oper/Comparisons.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Finite/Oper/Comparisons.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Finite/Oper/Comparisons.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Finite.Oper.Comparisons where import Lvl open import Data.Boolean import Data.Boolean.Operators open Data.Boolean.Operators.Programming open import Functional open import Numeral.Finite open import Numeral.Sign -- Compare _⋚?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → (−|0|+) 𝟎 ⋚? 𝟎 = 𝟎 𝟎 ⋚? 𝐒(b) = ➖ 𝐒(a) ⋚? 𝟎 = ➕ 𝐒(a) ⋚? 𝐒(b) = a ⋚? b -- Equality check _≡?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _≡?_ = elim₃ 𝐹 𝑇 𝐹 ∘₂ (_⋚?_) -- Non-equality check _≢?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _≢?_ = elim₃ 𝑇 𝐹 𝑇 ∘₂ (_⋚?_) -- Lesser-than check _<?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _<?_ = elim₃ 𝑇 𝐹 𝐹 ∘₂ (_⋚?_) -- Lesser-than or equals check _≤?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _≤?_ = elim₃ 𝑇 𝑇 𝐹 ∘₂ (_⋚?_) -- Greater-than check _>?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _>?_ = elim₃ 𝐹 𝐹 𝑇 ∘₂ (_⋚?_) -- Greater-than or equals check _≥?_ : ∀{a b} → 𝕟(a) → 𝕟(b) → Bool _≥?_ = elim₃ 𝐹 𝑇 𝑇 ∘₂ (_⋚?_)
22.02439
46
0.533776
4e52b42c49dcdea0d70e3cf214bcf710bef0be9c
814
agda
Agda
test/Fail/Issue2480false.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2480false.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2480false.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-03-01 issue #2480, reported by nad, discovered by simonhu -- Exploit by Jesper Cockx -- {-# OPTIONS -v tc.lhs.split:60 #-} open import Agda.Builtin.Equality data Bool : Set where tt ff : Bool const : Bool → (Bool → Bool) const = λ x _ → x ap : {A : Set} {B : Set} (f : A → B) {a b : A} (p : a ≡ b) → f a ≡ f b ap f refl = refl mutual -- Type of constant boolean functions, using @UnusedArg@ Bool→cBool : Set Bool→cBool = _ accepted : (p : const tt ≡ const ff) → ap (λ f → f tt) p ≡ ap (λ f → f ff) p accepted p = refl {x = ap {A = Bool→cBool} (λ f → f tt) p} constant : (f : Bool→cBool) (x y : Bool) → f x ≡ f y constant f x y = refl swap : Bool→cBool swap tt = ff swap ff = tt -- swap is definitely not constant, should be rejected BOOM : tt ≡ ff BOOM = constant swap ff tt
23.257143
78
0.608108
36c93b078c070a9aba26091abf0ba180c5ec925c
12,922
agda
Agda
lib/NConnected.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
lib/NConnected.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
null
null
null
lib/NConnected.agda
UlrikBuchholtz/HoTT-Agda
f8fa68bf753d64d7f45556ca09d0da7976709afa
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NType2 open import lib.Equivalences2 open import lib.types.Unit open import lib.types.Nat open import lib.types.Pi open import lib.types.Sigma open import lib.types.Paths open import lib.types.TLevel open import lib.types.Truncation open import lib.types.Suspension module lib.NConnected where is-connected : ∀ {i} → ℕ₋₂ → Type i → Type i is-connected n A = is-contr (Trunc n A) has-conn-fibers : ∀ {i j} {A : Type i} {B : Type j} → ℕ₋₂ → (A → B) → Type (lmax i j) has-conn-fibers {A = A} {B = B} n f = Π B (λ b → is-connected n (hfiber f b)) {- all types are ⟨-2⟩-connected -} -2-conn : ∀ {i} (A : Type i) → is-connected ⟨-2⟩ A -2-conn A = Trunc-level {- all inhabited types are ⟨-1⟩-connected -} inhab-conn : ∀ {i} (A : Type i) (a : A) → is-connected ⟨-1⟩ A inhab-conn A a = ([ a ] , prop-has-all-paths Trunc-level [ a ]) {- connectedness is a prop -} is-connected-is-prop : ∀ {i} {n : ℕ₋₂} {A : Type i} → is-prop (is-connected n A) is-connected-is-prop = is-contr-is-prop {- "induction principle" for n-connected maps (where codomain is n-type) -} abstract conn-elim-eqv : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} → {h : A → B} → has-conn-fibers n h → (∀ {k} (P : B → n -Type k) → is-equiv (λ (s : Π B (fst ∘ P)) → s ∘ h)) conn-elim-eqv {A = A} {B = B} {n = n} {h = h} c P = is-eq f g f-g g-f where f : Π B (fst ∘ P) → Π A (fst ∘ P ∘ h) f k a = k (h a) helper : Π A (fst ∘ P ∘ h) → (b : B) → Trunc n (Σ A (λ a → h a == b)) → (fst (P b)) helper t b r = Trunc-rec (snd (P b)) (λ x → transport (λ y → fst (P y)) (snd x) (t (fst x))) r g : Π A (fst ∘ P ∘ h) → Π B (fst ∘ P) g t b = helper t b (fst (c b)) f-g : ∀ t → f (g t) == t f-g t = λ= $ λ a → transport (λ r → Trunc-rec (snd (P (h a))) _ r == t a) (! (snd (c (h a)) [ (a , idp) ])) idp g-f : ∀ k → g (f k) == k g-f k = λ= $ λ (b : B) → Trunc-elim (λ r → =-preserves-level _ {helper (k ∘ h) b r} (snd (P b))) (λ x → lemma (fst x) b (snd x)) (fst (c b)) where lemma : ∀ xl → ∀ b → (p : h xl == b) → helper (k ∘ h) b [ (xl , p) ] == k b lemma xl ._ idp = idp conn-elim : ∀ {i j k} {A : Type i} {B : Type j} {n : ℕ₋₂} → {h : A → B} → has-conn-fibers n h → (P : B → n -Type k) → Π A (fst ∘ P ∘ h) → Π B (fst ∘ P) conn-elim c P f = is-equiv.g (conn-elim-eqv c P) f conn-elim-β : ∀ {i j k} {A : Type i} {B : Type j} {n : ℕ₋₂} {h : A → B} (c : has-conn-fibers n h) (P : B → n -Type k) (f : Π A (fst ∘ P ∘ h)) → ∀ a → (conn-elim c P f (h a)) == f a conn-elim-β c P f = app= (is-equiv.f-g (conn-elim-eqv c P) f) {- generalized "almost induction principle" for maps into ≥n-types TODO: rearrange this to use ≤T? -} conn-elim-general : ∀ {i j} {A : Type i} {B : Type j} {n k : ℕ₋₂} → {f : A → B} → has-conn-fibers n f → ∀ {l} (P : B → (k +2+ n) -Type l) → ∀ t → has-level k (Σ (Π B (fst ∘ P)) (λ s → (s ∘ f) == t)) conn-elim-general {k = ⟨-2⟩} c P t = equiv-is-contr-map (conn-elim-eqv c P) t conn-elim-general {B = B} {n = n} {k = S k'} {f = f} c P t = λ {(g , p) (h , q) → equiv-preserves-level (e g h p q) $ conn-elim-general {k = k'} c (Q g h) (app= (p ∙ ! q))} where Q : (g h : Π B (fst ∘ P)) → B → (k' +2+ n) -Type _ Q g h b = ((g b == h b) , snd (P b) _ _) app=-ap : ∀ {i j k} {A : Type i} {B : Type j} {C : B → Type k} (f : A → B) {g h : Π B C} (p : g == h) → app= (ap (λ k → k ∘ f) p) == (app= p ∘ f) app=-ap f idp = idp move-right-on-right-eqv : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : x == z) (r : y == z) → (p == q ∙ ! r) ≃ (p ∙ r == q) move-right-on-right-eqv {x = x} p idp idp = (_ , pre∙-is-equiv (∙-unit-r p)) lemma : ∀ g h p q → (H : ∀ x → g x == h x) → ((H ∘ f) == app= (p ∙ ! q)) ≃ (ap (λ v → v ∘ f) (λ= H) ∙ q == p) lemma g h p q H = move-right-on-right-eqv (ap (λ v → v ∘ f) (λ= H)) p q ∘e transport (λ w → (w == app= (p ∙ ! q)) ≃ (ap (λ v → v ∘ f) (λ= H) == p ∙ ! q)) (app=-ap f (λ= H) ∙ ap (λ k → k ∘ f) (λ= $ app=-β H)) ((equiv-ap app=-equiv _ _)⁻¹) e : ∀ g h p q → (Σ (∀ x → g x == h x) (λ r → (r ∘ f) == app= (p ∙ ! q))) ≃ ((g , p) == (h , q)) e g h p q = ((=Σ-eqv _ _ ∘e equiv-Σ-snd (λ u → ↓-app=cst-eqv ∘e !-equiv)) ∘e (equiv-Σ-fst _ (snd λ=-equiv))) ∘e equiv-Σ-snd (lemma g h p q) conn-intro : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} {h : A → B} → (∀ (P : B → n -Type (lmax i j)) → Σ (Π A (fst ∘ P ∘ h) → Π B (fst ∘ P)) (λ u → ∀ (t : Π A (fst ∘ P ∘ h)) → ∀ x → (u t ∘ h) x == t x)) → has-conn-fibers n h conn-intro {A = A} {B = B} {h = h} sec b = let s = sec (λ b → (Trunc _ (hfiber h b) , Trunc-level)) in (fst s (λ a → [ a , idp ]) b , λ kt → Trunc-elim (λ kt → =-preserves-level _ {_} {kt} Trunc-level) (λ k → transport (λ v → fst s (λ a → [ a , idp ]) (fst v) == [ fst k , snd v ]) (snd (pathfrom-is-contr (h (fst k))) (b , snd k)) (snd s (λ a → [ a , idp ]) (fst k))) kt) abstract pointed-conn-in : ∀ {i} {n : ℕ₋₂} (A : Type i) (a₀ : A) → has-conn-fibers {A = ⊤} n (cst a₀) → is-connected (S n) A pointed-conn-in {n = n} A a₀ c = ([ a₀ ] , Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ a → Trunc-rec (Trunc-level {n = S n} _ _) (λ x → ap [_] (snd x)) (fst $ c a))) abstract pointed-conn-out : ∀ {i} {n : ℕ₋₂} (A : Type i) (a₀ : A) → is-connected (S n) A → has-conn-fibers {A = ⊤} n (cst a₀) pointed-conn-out {n = n} A a₀ c a = (point , λ y → ! (cancel point) ∙ (ap out $ contr-has-all-paths (=-preserves-level ⟨-2⟩ c) (into point) (into y)) ∙ cancel y) where into-aux : Trunc n (Σ ⊤ (λ _ → a₀ == a)) → Trunc n (a₀ == a) into-aux = Trunc-fmap snd into : Trunc n (Σ ⊤ (λ _ → a₀ == a)) → [_] {n = S n} a₀ == [ a ] into = <– (Trunc=-equiv [ a₀ ] [ a ]) ∘ into-aux out-aux : Trunc n (a₀ == a) → Trunc n (Σ ⊤ (λ _ → a₀ == a)) out-aux = Trunc-fmap (λ p → (tt , p)) out : [_] {n = S n} a₀ == [ a ] → Trunc n (Σ ⊤ (λ _ → a₀ == a)) out = out-aux ∘ –> (Trunc=-equiv [ a₀ ] [ a ]) cancel : (x : Trunc n (Σ ⊤ (λ _ → a₀ == a))) → out (into x) == x cancel x = out (into x) =⟨ ap out-aux (<–-inv-r (Trunc=-equiv [ a₀ ] [ a ]) (into-aux x)) ⟩ out-aux (into-aux x) =⟨ Trunc-fmap-∘ _ _ x ⟩ Trunc-fmap (λ q → (tt , (snd q))) x =⟨ Trunc-elim {P = λ x → Trunc-fmap (λ q → (tt , snd q)) x == x} (λ _ → =-preserves-level n Trunc-level) (λ _ → idp) x ⟩ x ∎ point : Trunc n (Σ ⊤ (λ _ → a₀ == a)) point = out $ contr-has-all-paths c [ a₀ ] [ a ] prop-over-connected : ∀ {i j} {A : Type i} {a : A} (p : is-connected ⟨0⟩ A) → (P : A → hProp j) → fst (P a) → Π A (fst ∘ P) prop-over-connected p P x = conn-elim (pointed-conn-out _ _ p) P (λ _ → x) {- Connectedness of a truncated type -} Trunc-preserves-conn : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂) → is-connected n A → is-connected n (Trunc m A) Trunc-preserves-conn {n = ⟨-2⟩} m c = Trunc-level Trunc-preserves-conn {A = A} {n = S n} m c = lemma (fst c) (snd c) where lemma : (x₀ : Trunc (S n) A) → (∀ x → x₀ == x) → is-connected (S n) (Trunc m A) lemma = Trunc-elim (λ _ → Π-level (λ _ → Σ-level Trunc-level (λ _ → Π-level (λ _ → =-preserves-level _ Trunc-level)))) (λ a → λ p → ([ [ a ] ] , Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (Trunc-elim (λ _ → =-preserves-level _ (Trunc-preserves-level (S n) Trunc-level)) (λ x → <– (Trunc=-equiv [ [ a ] ] [ [ x ] ]) (Trunc-fmap (ap [_]) (–> (Trunc=-equiv [ a ] [ x ]) (p [ x ]))))))) {- Connectedness of a Σ-type -} abstract Σ-conn : ∀ {i} {j} {A : Type i} {B : A → Type j} {n : ℕ₋₂} → is-connected n A → (∀ a → is-connected n (B a)) → is-connected n (Σ A B) Σ-conn {A = A} {B = B} {n = ⟨-2⟩} cA cB = -2-conn (Σ A B) Σ-conn {A = A} {B = B} {n = S m} cA cB = Trunc-elim {P = λ ta → (∀ tx → ta == tx) → is-connected (S m) (Σ A B)} (λ _ → Π-level (λ _ → prop-has-level-S is-contr-is-prop)) (λ a₀ pA → Trunc-elim {P = λ tb → (∀ ty → tb == ty) → is-connected (S m) (Σ A B)} (λ _ → Π-level (λ _ → prop-has-level-S is-contr-is-prop)) (λ b₀ pB → ([ a₀ , b₀ ] , Trunc-elim {P = λ tp → [ a₀ , b₀ ] == tp} (λ _ → =-preserves-level _ Trunc-level) (λ {(r , s) → Trunc-rec (Trunc-level {n = S m} _ _) (λ pa → Trunc-rec (Trunc-level {n = S m} _ _) (λ pb → ap [_] (pair= pa (from-transp! B pa pb))) (–> (Trunc=-equiv [ b₀ ] [ transport! B pa s ]) (pB [ transport! B pa s ]))) (–> (Trunc=-equiv [ a₀ ] [ r ]) (pA [ r ]))}))) (fst (cB a₀)) (snd (cB a₀))) (fst cA) (snd cA) ×-conn : ∀ {i} {j} {A : Type i} {B : Type j} {n : ℕ₋₂} → is-connected n A → is-connected n B → is-connected n (A × B) ×-conn cA cB = Σ-conn cA (λ _ → cB) {- Suspension of an n-connected space is n+1-connected what is the best place for this? -} abstract Susp-conn : ∀ {i} {A : Type i} {n : ℕ₋₂} → is-connected n A → is-connected (S n) (Suspension A) Susp-conn {A = A} {n = n} cA = ([ north A ] , Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (Suspension-elim A idp (Trunc-rec (Trunc-level {n = S n} _ _) (λ a → ap [_] (merid A a)) (fst cA)) (λ x → Trunc-elim {P = λ y → idp == Trunc-rec (Trunc-level {n = S n} _ _) (λ a → ap [_] (merid A a)) y [ (λ z → [ north A ] == [ z ]) ↓ (merid A x) ]} (λ _ → ↓-preserves-level _ (λ _ → Trunc-level {n = S n} _ _)) (λ x' → ↓-cst=app-in (∙'-unit-l _ ∙ mers-eq n cA x x')) (fst cA)))) where mers-eq : ∀ {i} {A : Type i} (n : ℕ₋₂) → is-connected n A → (x x' : A) → ap ([_] {n = S n}) (merid A x) == Trunc-rec (Trunc-level {n = S n} _ _) (λ a → ap [_] (merid A a)) [ x' ] mers-eq ⟨-2⟩ cA x x' = contr-has-all-paths (Trunc-level {n = ⟨-1⟩} _ _) _ _ mers-eq {A = A} (S n) cA x x' = conn-elim (pointed-conn-out A x cA) (λ y → ((ap [_] (merid A x) == ap [_] (merid A y)) , Trunc-level {n = S (S n)} _ _ _ _)) (λ _ → idp) x' {- connectedness of a path space -} abstract path-conn : ∀ {i} {A : Type i} {x y : A} {n : ℕ₋₂} → is-connected (S n) A → is-connected n (x == y) path-conn {x = x} {y = y} cA = equiv-preserves-level (Trunc=-equiv [ x ] [ y ]) (contr-is-prop cA [ x ] [ y ]) {- an n-Type which is n-connected is contractible -} connected-at-level-is-contr : ∀ {i} {A : Type i} {n : ℕ₋₂} → has-level n A → is-connected n A → is-contr A connected-at-level-is-contr pA cA = equiv-preserves-level (unTrunc-equiv _ pA) cA {- if A is n-connected and m ≤ n, then A is m-connected -} connected-≤T : ∀ {i} {m n : ℕ₋₂} {A : Type i} → m ≤T n → is-connected n A → is-connected m A connected-≤T {m = m} {n = n} {A = A} leq cA = transport (λ B → is-contr B) (ua (fuse-Trunc A m n) ∙ ap (λ k → Trunc k A) (minT-out-l leq)) (Trunc-preserves-level m cA) {- Equivalent types have the same connectedness -} equiv-preserves-conn : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} (e : A ≃ B) → (is-connected n A → is-connected n B) equiv-preserves-conn {n = n} e = equiv-preserves-level (equiv-Trunc n e) {- Composite of two connected functions is connected -} ∘-conn : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} → {n : ℕ₋₂} → (f : A → B) → (g : B → C) → has-conn-fibers n f → has-conn-fibers n g → has-conn-fibers n (g ∘ f) ∘-conn {n = n} f g cf cg = conn-intro (λ P → conn-elim cg P ∘ conn-elim cf (P ∘ g) , lemma P) where lemma : ∀ P h x → conn-elim cg P (conn-elim cf (P ∘ g) h) (g (f x)) == h x lemma P h x = conn-elim cg P (conn-elim cf (P ∘ g) h) (g (f x)) =⟨ conn-elim-β cg P (conn-elim cf (P ∘ g) h) (f x) ⟩ conn-elim cf (P ∘ g) h (f x) =⟨ conn-elim-β cf (P ∘ g) h x ⟩ h x ∎
39.76
85
0.447299
4ed3de585ac35d4362ebbba301bc024ba4e1bfa7
18,837
agda
Agda
formalization/silica.agda
ishantheperson/Obsidian
b5fc75b137cf86251c03709c58f940286d730e86
[ "BSD-3-Clause" ]
79
2017-08-19T16:24:10.000Z
2022-03-27T10:34:28.000Z
formalization/silica.agda
ishantheperson/Obsidian
b5fc75b137cf86251c03709c58f940286d730e86
[ "BSD-3-Clause" ]
259
2017-08-18T19:50:41.000Z
2022-03-29T18:20:05.000Z
formalization/silica.agda
ishantheperson/Obsidian
b5fc75b137cf86251c03709c58f940286d730e86
[ "BSD-3-Clause" ]
11
2018-05-24T08:20:52.000Z
2021-06-09T18:40:19.000Z
module Silica where open import Agda.Builtin.Bool public open import Data.Bool using (true; false) public open import Prelude public open import Data.Nat public open import Data.List public open import Data.Nat.Properties public open import Relation.Nullary using (¬_; Dec; yes; no) public open import Relation.Binary using (module StrictTotalOrder; DecSetoid; IsDecEquivalence) public open import Data.Maybe using (just) public import Relation.Binary.PropositionalEquality as Eq import Relation.Binary.Core import Relation.Binary.HeterogeneousEquality open Eq using (_≡_; _≢_; refl; cong; sym) public open Eq.≡-Reasoning public open import Data.Product using (_×_; proj₁; proj₂; ∃-syntax; ∃) renaming (_,_ to ⟨_,_⟩) public import Context open import Data.List.Membership.DecSetoid ≡-decSetoid import Data.List.Membership.DecSetoid import Data.List.Relation.Binary.Subset.Setoid using (_⊆_) import Data.List.Relation.Binary.Equality.DecPropositional using (_≡?_) open import Data.List.Relation.Unary.Any open import Data.List.All open import Data.Empty open import Data.Sum open import Level import Data.Fin -------------- Syntax ------------ Id : Set Id = ℕ -- State sets σ : Set σ = List ℕ -- List of ℕ subset _⊆_ : σ → σ → Set _⊆_ = Data.List.Relation.Binary.Subset.Setoid._⊆_ (DecSetoid.setoid ≡-decSetoid) -- List of ℕ decidable equality _≟l_ : Relation.Binary.Core.Decidable {A = σ} _≡_ _≟l_ = Data.List.Relation.Binary.Equality.DecPropositional._≡?_ _≟_ data Perm : Set where Owned : Perm Unowned : Perm Shared : Perm S : σ → Perm record Tc : Set where constructor tc field contractName : Id perm : Perm data Tbase : Set where Void : Tbase Boolean : Tbase data Type : Set where base : Tbase -> Type contractType : Tc -> Type SInjective : (l₁ l₂ : σ) → l₁ ≢ l₂ → S l₁ ≢ S l₂ SInjective l₁ .l₁ lsEq refl = lsEq refl TCInjectiveContractName : ∀ {p₁ p₂} → (cn₁ cn₂ : Id) → cn₁ ≢ cn₂ → tc cn₁ p₁ ≢ tc cn₂ p₂ TCInjectiveContractName cn₁ cn₂ nEq refl = nEq refl TCInjectivePermission : ∀ {cn₁ cn₂} → (p₁ p₂ : Perm) → p₁ ≢ p₂ → tc cn₁ p₁ ≢ tc cn₂ p₂ TCInjectivePermission cn₁ cn₂ nEq refl = nEq refl contractTypeInjective : ∀ {tc₁ tc₂} → tc₁ ≢ tc₂ → contractType tc₁ ≢ contractType tc₂ contractTypeInjective nEq refl = nEq refl -- Decidable equality for permissions infix 4 _≟p_ _≟p_ : Relation.Binary.Core.Decidable {A = Perm} _≡_ Owned ≟p Owned = yes refl Owned ≟p Unowned = no (λ ()) Owned ≟p Shared = no (λ ()) Owned ≟p S x = no (λ ()) Unowned ≟p Owned = no (λ ()) Unowned ≟p Unowned = yes refl Unowned ≟p Shared = no (λ ()) Unowned ≟p S x = no (λ ()) Shared ≟p Owned = no (λ ()) Shared ≟p Unowned = no (λ ()) Shared ≟p Shared = yes refl Shared ≟p S x = no (λ ()) S x ≟p Owned = no (λ ()) S x ≟p Unowned = no (λ ()) S x ≟p Shared = no (λ ()) S s1 ≟p S s2 with s1 ≟l s2 ... | yes eq = yes (Eq.cong S eq) ... | no nEq = no λ sEq → SInjective s1 s2 nEq sEq -- Decidable equality for types infix 4 _≟t_ _≟t_ : Relation.Binary.Core.Decidable {A = Type} _≡_ base Void ≟t base Void = yes refl base Void ≟t base Boolean = no (λ ()) base Boolean ≟t base Void = no (λ ()) base Boolean ≟t base Boolean = yes refl base x ≟t contractType x₁ = no (λ ()) contractType x ≟t base x₁ = no (λ ()) contractType (tc contractName p₁) ≟t contractType (tc contractName₁ p₂) with contractName ≟ contractName₁ | p₁ ≟p p₂ ... | yes eqNames | yes eqPerms = yes (Eq.cong₂ (λ a → λ b → contractType (tc a b)) eqNames eqPerms) ... | no nEqNames | _ = no (contractTypeInjective (TCInjectiveContractName contractName contractName₁ nEqNames)) ... | _ | no nEqPerms = no (contractTypeInjective (TCInjectivePermission p₁ p₂ nEqPerms)) ≟tIsEquivalence : Relation.Binary.IsEquivalence {A = Type} _≡_ -- _≟t_ ≟tIsEquivalence = Eq.isEquivalence ≡t-isDecEquivalence : IsDecEquivalence (_≡_ {A = Type}) ≡t-isDecEquivalence = record { isEquivalence = ≟tIsEquivalence ; _≟_ = _≟t_ } ≡t-decSetoid : DecSetoid 0ℓ 0ℓ ≡t-decSetoid = record { Carrier = Type ; _≈_ = _≡_ ; isDecEquivalence = ≡t-isDecEquivalence } module tDecSetoid = Data.List.Membership.DecSetoid ≡t-decSetoid _∈ₜ_ : Type → List Type → Set _∈ₜ_ = tDecSetoid._∈_ isShared : Type → Bool isShared (contractType (record {contractName = _ ; perm = Shared})) = true isShared _ = false eqContractTypes : ∀ {t₁ : Tc} → ∀ {t₂ : Tc} → Tc.perm t₁ ≡ Tc.perm t₂ → Tc.contractName t₁ ≡ Tc.contractName t₂ → t₁ ≡ t₂ eqContractTypes {t₁} {t₂} refl refl = refl record State : Set where field field₁ : Tc field₂ : Tc isAsset : Bool data Targ : Set where arg-trans : Tc -> Perm -> Targ base : Tbase -> Targ IndirectRef : Set IndirectRef = Id ObjectRef : Set ObjectRef = Id data SimpleExpr : Set where var : Id -> SimpleExpr loc : IndirectRef -> SimpleExpr record Object : Set where field contractName : Id stateName : Id x₁ : SimpleExpr x₂ : SimpleExpr data Value : Set where boolVal : (b : Bool) ------------ → Value voidVal : Value objVal : ∀ (o : ObjectRef) -------------- → Value data Expr : Set where valExpr : Value → Expr simpleExpr : SimpleExpr → Expr fieldAccess : Id → Expr -- All field accesses are to 'this', so the field name suffices. assertₓ : Id → σ → Expr assertₗ : IndirectRef → σ → Expr new : Id → Id → SimpleExpr → SimpleExpr → Expr -- Contract, state, field values (always two of them). -- TODO: add the rest of the expressions objValInjective : ∀ {o o'} → o ≢ o' → objVal o ≢ objVal o' objValInjective {o} {.o} oNeqo' refl = oNeqo' refl objValInjectiveContrapositive : ∀ {o o'} → objVal o ≡ objVal o' → o ≡ o' objValInjectiveContrapositive {o} {o'} refl = refl record PublicTransaction : Set where constructor publicTransaction field retType : Type name : Id argType : Targ argName : Id initialState : Perm finalState : Perm expr : Expr -- TODO: add private transactions record Contract : Set where constructor contract field isAsset : Bool name : Id states : List State transactions : List PublicTransaction data Program : Set where program : List Contract -> Expr -> Program --============= Utilities ================ data FreeLocations : Expr → List IndirectRef → Set where boolFL : ∀ {b : Bool} → FreeLocations (valExpr (boolVal b)) [] varFL : ∀ {x : Id} → FreeLocations (simpleExpr (var x)) [] voidFL : FreeLocations (valExpr voidVal) [] objValFL : ∀ {o : ObjectRef} → FreeLocations (valExpr (objVal o)) [] locFL : ∀ (l : IndirectRef) → FreeLocations (simpleExpr (loc l)) [ l ] freeLocationsOfSimpleExpr : SimpleExpr → List IndirectRef freeLocationsOfSimpleExpr (var x) = [] freeLocationsOfSimpleExpr (loc l) = [ l ] freeLocations : Expr → List IndirectRef freeLocations (valExpr (boolVal b)) = [] freeLocations (simpleExpr (se)) = freeLocationsOfSimpleExpr se freeLocations (valExpr voidVal) = [] freeLocations (valExpr (objVal o)) = [] freeLocations (fieldAccess x) = [] freeLocations (assertₓ x x₁) = [] freeLocations (assertₗ l x₁) = [ l ] freeLocations (new _ _ f₁ f₂) = (freeLocationsOfSimpleExpr f₁) ++ (freeLocationsOfSimpleExpr f₂) data FreeVariables : Expr → List Id → Set where boolFL : ∀ {b : Bool} → FreeVariables (valExpr (boolVal b)) [] varFL : ∀ {x : Id} → FreeVariables (simpleExpr (var x)) [ x ] voidFL : FreeVariables (valExpr voidVal) [] objValFL : ∀ {o : ObjectRef} → FreeVariables (valExpr (objVal o)) [] locFL : ∀ (l : IndirectRef) → FreeVariables (simpleExpr (loc l)) [] data Closed : Expr → Set where closed : ∀ (e : Expr) → FreeVariables e [] -------------------- → Closed e freeVariablesOfSimpleExpr : SimpleExpr → List IndirectRef freeVariablesOfSimpleExpr (var x) = [ x ] freeVariablesOfSimpleExpr (loc l) = [] freeVariables : Expr → List IndirectRef freeVariables (valExpr (boolVal b)) = [] freeVariables (simpleExpr se) = freeVariablesOfSimpleExpr se freeVariables (valExpr voidVal) = [] freeVariables (valExpr (objVal o)) = [] freeVariables (fieldAccess x) = [] freeVariables (assertₓ x x₁) = [ x ] freeVariables (assertₗ l x₁) = [] freeVariables (new _ _ f₁ f₂) = (freeVariablesOfSimpleExpr f₁) ++ (freeVariablesOfSimpleExpr f₂) --=============== Static Semantics ================ -- A ContractEnv (written Γ) maps from Ids to contract definitions. module ContractEnv = Context Contract module TypeEnvContext = Context Type TypeEnv = TypeEnvContext.ctx open TypeEnvContext record StaticEnv : Set where constructor se field varEnv : TypeEnv locEnv : TypeEnv objEnv : TypeEnv _,ₓ_⦂_ : StaticEnv → Id → Type → StaticEnv Δ ,ₓ x ⦂ T = record Δ {varEnv = (StaticEnv.varEnv Δ) , x ⦂ T} _,ₗ_⦂_ : StaticEnv → Id → Type → StaticEnv Δ ,ₗ l ⦂ T = record Δ {locEnv = (StaticEnv.locEnv Δ) , l ⦂ T} _,ₒ_⦂_ : StaticEnv → Id → Type → StaticEnv Δ ,ₒ o ⦂ T = record Δ {objEnv = (StaticEnv.objEnv Δ) , o ⦂ T} -- Subtyping -- data _<:_ : Type → Type → Set where <:-refl : ∀ {T : Type} ---------------- → T <: T -- TODO: add more subtyping judgments -- Helper judgments -- --data _⊢_NotAsset : ContractEnv.ctx → Id → Set where data NotAsset : ContractEnv.ctx → Id → Set where inContext : {Γ : ContractEnv.ctx} → {id : Id} → (contr : Contract) → (p : Contract.isAsset contr ≡ false) → (q : (Γ ContractEnv.∋ id ⦂ contr)) ------------- → NotAsset Γ id -- Context strength -- data _<ₗ_ : TypeEnv → TypeEnv → Set where empty< : ∀ { Δ Δ' : TypeEnv} → (Δ' ≡ ∅) -------------- → Δ <ₗ Δ' nonempty< : ∀ {Δ Δ' Δ'' Δ''' : TypeEnv} → ∀ {l : ℕ} → ∀ {T T' : Type} → Δ' ≡ (Δ'' , l ⦂ T') → Δ ≡ (Δ''' , l ⦂ T) → T <: T' → Δ''' <ₗ Δ'' ------------- → Δ <ₗ Δ' data _<*_ : StaticEnv → StaticEnv → Set where * : ∀ {Δ Δ'} → (StaticEnv.locEnv Δ) <ₗ (StaticEnv.locEnv Δ') ----------------------------------------------- → Δ <* Δ' <ₗ-refl : ∀ {Δ : TypeEnv} → Δ <ₗ Δ <ₗ-refl {Context.∅} = empty< refl <ₗ-refl {Δ , x ⦂ x₁} = nonempty< refl refl (<:-refl) (<ₗ-refl {Δ}) <*-refl : ∀ {Δ : StaticEnv} → Δ <* Δ <*-refl = * <ₗ-refl <*-o-extension : ∀ {Δ o T} → (Δ ,ₒ o ⦂ T) <* Δ <*-o-extension {Δ} {o} {T} = * <ₗ-refl -- Splitting -- record SplitType : Set where constructor _⇛_/_ field t₁ : Type t₂ : Type t₃ : Type infix 4 _⊢_ data _⊢_ : ContractEnv.ctx -> SplitType -> Set where voidSplit : ∀ {Γ : ContractEnv.ctx} --------------- → Γ ⊢ (base Void) ⇛ (base Void) / (base Void) booleanSplit : ∀ {Γ : ContractEnv.ctx} -------------- → Γ ⊢ base Boolean ⇛ base Boolean / base Boolean -- split Unowned off of anything. unownedSplit : ∀ {Γ : ContractEnv.ctx} → ∀ {t1 t2 t3 : Tc} → (Tc.contractName t1) ≡ (Tc.contractName t2) → Tc.contractName t1 ≡ Tc.contractName t3 → (Tc.perm t1) ≡ (Tc.perm t2) → Tc.perm t3 ≡ Unowned -------------- → Γ ⊢ contractType t1 ⇛ contractType t2 / contractType t3 shared-shared-shared : ∀ {Γ : ContractEnv.ctx} → ∀ {t : Tc} → Tc.perm t ≡ Shared -------------------------------------------------------- → Γ ⊢ contractType t ⇛ contractType t / contractType t owned-shared : ∀ {c : Id} → ∀ {Γ : ContractEnv.ctx} → NotAsset Γ c -------------- → Γ ⊢ contractType (tc c Owned) ⇛ contractType (tc c Shared) / contractType (tc c Shared) states-shared : ∀ {s : σ} → ∀ {c : Id} → ∀ {Γ : ContractEnv.ctx} → NotAsset Γ c -------------- → Γ ⊢ contractType ( record {perm = S s ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} ) splitType : ∀ {Γ : ContractEnv.ctx} → ∀ {t1 t2 t3 : Type} → Γ ⊢ t1 ⇛ t2 / t3 → SplitType splitType voidSplit = (base Void) ⇛ (base Void) / (base Void) splitType booleanSplit = base Boolean ⇛ base Boolean / base Boolean splitType (unownedSplit {Γ} {t1} {t2} {t3} eqNames1 eqNames2 eqPerms eqUnownedPerm) = contractType t1 ⇛ contractType t2 / contractType t3 splitType (shared-shared-shared {Γ} {t} _) = contractType t ⇛ contractType t / contractType t splitType (owned-shared {c} x) = contractType ( record {perm = Owned ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} ) splitType (states-shared {s} {c} x) = contractType ( record {perm = S s ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} ) splitTypeCorrect : ∀ {Γ} → ∀ {t1 t2 t3 : Type} → ∀ (p : Γ ⊢ t1 ⇛ t2 / t3) → splitType p ≡ t1 ⇛ t2 / t3 splitTypeCorrect voidSplit = refl splitTypeCorrect booleanSplit = refl splitTypeCorrect (unownedSplit x _ _ _) = refl splitTypeCorrect (shared-shared-shared _) = refl splitTypeCorrect (owned-shared x) = refl splitTypeCorrect (states-shared x) = refl ------------ Type judgments ---------------- data _⊢_⦂_⊣_ : StaticEnv → Expr → Type → StaticEnv → Set where varTy : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ {T₁ T₂ T₃ : Type} → ∀ (x : Id) → Γ ⊢ T₁ ⇛ T₂ / T₃ ----------------------------------- → (Δ ,ₓ x ⦂ T₁) ⊢ (simpleExpr (var x)) ⦂ T₂ ⊣ (Δ ,ₓ x ⦂ T₃) locTy : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ {T₁ T₂ T₃ : Type} → ∀ (l : IndirectRef) → Γ ⊢ T₁ ⇛ T₂ / T₃ ------------------------------------ → (Δ ,ₗ l ⦂ T₁) ⊢ (simpleExpr (loc l)) ⦂ T₂ ⊣ (Δ ,ₗ l ⦂ T₃) objTy : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ {T₁ T₂ T₃ : Type} → ∀ (o : ObjectRef) → Γ ⊢ T₁ ⇛ T₂ / T₃ ------------------------------------ → (Δ ,ₒ o ⦂ T₁) ⊢ (valExpr (objVal o)) ⦂ T₂ ⊣ (Δ ,ₒ o ⦂ T₃) boolTy : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ (b : Bool) ------------------------------------ → Δ ⊢ (valExpr (boolVal b)) ⦂ (base Boolean) ⊣ Δ voidTy : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} -------------------- → Δ ⊢ (valExpr voidVal) ⦂ base Void ⊣ Δ assertTyₓ : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ {s₁ s₂ : σ} → ∀ {tc : Tc} → ∀ {x : Id} → Tc.perm tc ≡ S s₁ → s₁ ⊆ s₂ -------------------------- → (Δ ,ₓ x ⦂ (contractType tc)) ⊢ assertₓ x s₁ ⦂ base Void ⊣ (Δ ,ₓ x ⦂ (contractType tc)) assertTyₗ : ∀ {Γ : ContractEnv.ctx} → ∀ {Δ : StaticEnv} → ∀ {s₁ s₂ : σ} → ∀ {tc : Tc} → ∀ {l : IndirectRef} → Tc.perm tc ≡ S s₁ → s₁ ⊆ s₂ -------------------------- → (Δ ,ₗ l ⦂ (contractType tc)) ⊢ assertₗ l s₁ ⦂ base Void ⊣ (Δ ,ₗ l ⦂ (contractType tc)) newTy : ∀ {Γ Δ Δ' Δ''} → {states : List State} → {C st : Id} → {x₁ x₂ : SimpleExpr} → {T₁ T₂ Tf₁ Tf₂ : Tc} → ∀ {isCAsset isSAsset transactions} → (stOK : st < (length states)) → Δ ⊢ simpleExpr x₁ ⦂ (contractType T₁) ⊣ Δ' → Δ' ⊢ simpleExpr x₂ ⦂ (contractType T₂) ⊣ Δ'' → Γ ContractEnv.∋ C ⦂ (contract isCAsset C states transactions) → (Data.List.lookup states (Data.Fin.fromℕ≤ stOK)) ≡ record {field₁ = Tf₁ ; field₂ = Tf₂ ; isAsset = isSAsset} -------------------------- → Δ ⊢ new C st x₁ x₂ ⦂ (contractType (tc C (S [ st ]))) ⊣ Δ'' ------------ DYNAMIC SEMANTICS -------------- -- μ module ObjectRefContext = Context Object ObjectRefEnv = ObjectRefContext.ctx -- ρ module IndirectRefContext = Context Value -- TODO: require that these are all values IndirectRefEnv = IndirectRefContext.ctx -- φ module StateLockingContext = Context Bool StateLockingEnv = StateLockingContext.ctx -- ψ module ReentrancyContext = Context Bool ReentrancyEnv = ReentrancyContext.ctx record RuntimeEnv : Set where constructor re field μ : ObjectRefEnv ρ : IndirectRefEnv φ : StateLockingEnv ψ : ReentrancyEnv ----------- Reduction Rules ------------ data _,_⟶_,_ : RuntimeEnv → Expr → RuntimeEnv → Expr → Set where SElookup : -- of locations (i.e. let-bound variables) ∀ {Σ : RuntimeEnv} → ∀ {Δ Δ' : StaticEnv} → ∀ {T : Type} → ∀ {l : IndirectRef} → ∀ {v : Value} → Δ ⊢ (simpleExpr (loc l)) ⦂ T ⊣ Δ' → RuntimeEnv.ρ Σ IndirectRefContext.∋ l ⦂ v ----------------------------------------------------------- → (Σ , (simpleExpr (loc l)) ⟶ Σ , valExpr v) SEassertₓ : ∀ {Σ : RuntimeEnv} → ∀ (x : Id) → ∀ (s : σ) -------------- → (Σ , assertₓ x s ⟶ Σ , valExpr voidVal) SEassertₗ : ∀ {Σ : RuntimeEnv} → ∀ (l : IndirectRef) → ∀ (s : σ) -------------- → (Σ , assertₗ l s ⟶ Σ , valExpr voidVal) SEnew : ∀ {Σ μ' Σ' C st x₁ x₂ o} → o ObjectRefContext.∉dom (RuntimeEnv.μ Σ) → μ' ≡ (RuntimeEnv.μ Σ) ObjectRefContext., o ⦂ record { contractName = C ; stateName = st ; x₁ = x₁ ; x₂ = x₂ } → Σ' ≡ record Σ {μ = μ'} ------------- → (Σ , new C st x₁ x₂ ⟶ Σ' , valExpr (objVal o))
32.2
218
0.534586
a039fb91e964e207a94c8979a0b6a77874945aa2
5,144
agda
Agda
Cubical/Data/Sigma/Properties.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Properties.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Properties.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- Basic properties about Σ-types - Characterization of equality in Σ-types using transport ([pathSigma≡sigmaPath]) -} {-# OPTIONS --cubical --safe #-} module Cubical.Data.Sigma.Properties where open import Cubical.Data.Sigma.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.Univalence open import Cubical.Foundations.CartesianKanOps open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq open import Cubical.Data.Nat private variable ℓ : Level A : Type ℓ B : (a : A) → Type ℓ ΣPathP : ∀ {x y} → Σ (fst x ≡ fst y) (λ a≡ → PathP (λ i → B (a≡ i)) (snd x) (snd y)) → x ≡ y ΣPathP eq = λ i → (fst eq i) , (snd eq i) Σ≡ : {x y : Σ A B} → Σ (fst x ≡ fst y) (λ a≡ → PathP (λ i → B (a≡ i)) (snd x) (snd y)) ≃ (x ≡ y) Σ≡ {A = A} {B = B} {x} {y} = isoToEquiv (iso intro elim intro-elim elim-intro) where intro = ΣPathP elim : x ≡ y → Σ (fst x ≡ fst y) (λ a≡ → PathP (λ i → B (a≡ i)) (snd x) (snd y )) elim eq = (λ i → fst (eq i)) , λ i → snd (eq i) intro-elim : ∀ eq → intro (elim eq) ≡ eq intro-elim eq = refl elim-intro : ∀ eq → elim (intro eq) ≡ eq elim-intro eq = refl -- Alternative version for path in Σ-types, as in the HoTT book sigmaPathTransport : (a b : Σ A B) → Type _ sigmaPathTransport {B = B} a b = Σ (fst a ≡ fst b) (λ p → transport (λ i → B (p i)) (snd a) ≡ snd b) _Σ≡T_ : (a b : Σ A B) → Type _ a Σ≡T b = sigmaPathTransport a b -- now we prove that the alternative path space a Σ≡ b is equal to the usual path space a ≡ b -- forward direction private pathSigma-π1 : {a b : Σ A B} → a ≡ b → fst a ≡ fst b pathSigma-π1 p i = fst (p i) filler-π2 : {a b : Σ A B} → (p : a ≡ b) → I → (i : I) → B (fst (p i)) filler-π2 {B = B} {a = a} p i = fill (λ i → B (fst (p i))) (λ t → λ { (i = i0) → coe0→i (λ j → B (fst (p j))) t (snd a) ; (i = i1) → snd (p t) }) (inS (snd a)) pathSigma-π2 : {a b : Σ A B} → (p : a ≡ b) → subst B (pathSigma-π1 p) (snd a) ≡ snd b pathSigma-π2 p i = filler-π2 p i i1 pathSigma→sigmaPath : (a b : Σ A B) → a ≡ b → a Σ≡T b pathSigma→sigmaPath _ _ p = (pathSigma-π1 p , pathSigma-π2 p) -- backward direction private filler-comp : (a b : Σ A B) → a Σ≡T b → I → I → Σ A B filler-comp {B = B} a b (p , q) i = hfill (λ t → λ { (i = i0) → a ; (i = i1) → (p i1 , q t) }) (inS (p i , coe0→i (λ j → B (p j)) i (snd a))) sigmaPath→pathSigma : (a b : Σ A B) → a Σ≡T b → (a ≡ b) sigmaPath→pathSigma a b x i = filler-comp a b x i i1 -- first homotopy private homotopy-π1 : (a b : Σ A B) → ∀ (x : a Σ≡T b) → pathSigma-π1 (sigmaPath→pathSigma a b x) ≡ fst x homotopy-π1 a b x i j = fst (filler-comp a b x j (~ i)) homotopy-π2 : (a b : Σ A B) → (p : a Σ≡T b) → (i : I) → (transport (λ j → B (fst (filler-comp a b p j i))) (snd a) ≡ snd b) homotopy-π2 {B = B} a b p i j = comp (λ t → B (fst (filler-comp a b p t (i ∨ j)))) (λ t → λ { (j = i0) → coe0→i (λ t → B (fst (filler-comp a b p t i))) t (snd a) ; (j = i1) → snd (sigmaPath→pathSigma a b p t) ; (i = i0) → snd (filler-comp a b p t j) ; (i = i1) → filler-π2 (sigmaPath→pathSigma a b p) j t }) (snd a) pathSigma→sigmaPath→pathSigma : {a b : Σ A B} → ∀ (x : a Σ≡T b) → pathSigma→sigmaPath _ _ (sigmaPath→pathSigma a b x) ≡ x pathSigma→sigmaPath→pathSigma {a = a} p i = (homotopy-π1 a _ p i , homotopy-π2 a _ p (~ i)) -- second homotopy sigmaPath→pathSigma→sigmaPath : {a b : Σ A B} → ∀ (x : a ≡ b) → sigmaPath→pathSigma a b (pathSigma→sigmaPath _ _ x) ≡ x sigmaPath→pathSigma→sigmaPath {B = B} {a = a} {b = b} p i j = hcomp (λ t → λ { (i = i1) → (fst (p j) , filler-π2 p t j) ; (i = i0) → filler-comp a b (pathSigma→sigmaPath _ _ p) j t ; (j = i0) → (fst a , snd a) ; (j = i1) → (fst b , filler-π2 p t i1) }) (fst (p j) , coe0→i (λ k → B (fst (p k))) j (snd a)) pathSigma≡sigmaPath : (a b : Σ A B) → (a ≡ b) ≡ (a Σ≡T b) pathSigma≡sigmaPath a b = isoToPath (iso (pathSigma→sigmaPath a b) (sigmaPath→pathSigma a b) (pathSigma→sigmaPath→pathSigma {a = a}) sigmaPath→pathSigma→sigmaPath) discreteΣ : Discrete A → ((a : A) → Discrete (B a)) → Discrete (Σ A B) discreteΣ {B = B} Adis Bdis (a0 , b0) (a1 , b1) = discreteΣ' (Adis a0 a1) where discreteΣ' : Dec (a0 ≡ a1) → Dec ((a0 , b0) ≡ (a1 , b1)) discreteΣ' (yes p) = J (λ a1 p → ∀ b1 → Dec ((a0 , b0) ≡ (a1 , b1))) (discreteΣ'') p b1 where discreteΣ'' : (b1 : B a0) → Dec ((a0 , b0) ≡ (a0 , b1)) discreteΣ'' b1 with Bdis a0 b0 b1 ... | (yes q) = yes (transport (ua Σ≡) (refl , q)) ... | (no ¬q) = no (λ r → ¬q (subst (λ X → PathP (λ i → B (X i)) b0 b1) (Discrete→isSet Adis a0 a0 (cong fst r) refl) (cong snd r))) discreteΣ' (no ¬p) = no (λ r → ¬p (cong fst r))
34.756757
140
0.533826
8b4ad2904d59c3d7a46a0caae4b5268322b3cdfd
1,749
agda
Agda
src/Parse/MultiChar.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
src/Parse/MultiChar.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
src/Parse/MultiChar.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
-------------------------------------------------------------------------------- -- White or blacklisting of characters -------------------------------------------------------------------------------- module Parse.MultiChar where import Data.List.NonEmpty as NE open import Data.String hiding (show) open import Prelude -- TODO: Groups of characters, such as digits or lower case letters MultiCharGroup : Set MultiCharGroup = ⊥ matchCharGroup : MultiCharGroup → Char → Bool matchCharGroup () data CharMatcher : Set where Single : Char → CharMatcher Group : MultiCharGroup → CharMatcher instance CharMatcher-Show : Show CharMatcher CharMatcher-Show = record { show = helper } where helper : CharMatcher → String helper (Single c) = fromChar c parseCharMatcher : String → Maybe CharMatcher parseCharMatcher s with uncons s ... | just (c , "") = just (Single c) ... | _ = nothing matchCharMatcher : CharMatcher → Char → Bool matchCharMatcher (Single x) c = x ≣ c matchCharMatcher (Group g) c = matchCharGroup g c record MultiChar : Set where field matches : List CharMatcher negated : Bool instance MultiChar-Show : Show MultiChar MultiChar-Show = record { show = helper } where helper : MultiChar → String helper m = (if negated then "!" else "") + show matches where open MultiChar m parseMultiChar : Bool → List String → MultiChar parseMultiChar b l = record { matches = mapMaybe parseCharMatcher l ; negated = b } parseMultiCharNE : Bool → NE.List⁺ String → MultiChar parseMultiCharNE b l = parseMultiChar b (NE.toList l) matchMulti : MultiChar → Char → Bool matchMulti m c = negated xor (or $ map (flip matchCharMatcher c) matches) where open MultiChar m
28.672131
83
0.647227
7cef038a31f13d10b2c1c20558ae23fc0d886e2c
1,615
agda
Agda
nicolai/anonymousExistence/library/types/Types.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/anonymousExistence/library/types/Types.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/anonymousExistence/library/types/Types.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module library.types.Types where open import library.Basics open import library.types.Empty public open import library.types.Unit public open import library.types.Bool public open import library.types.Nat public open import library.types.Int public open import library.types.TLevel public open import library.types.Paths public open import library.types.Sigma public open import library.types.Pi public open import library.types.Coproduct public open import library.types.Lift public open import library.types.Circle public open import library.types.Span public open import library.types.Pushout public open import library.types.PushoutFlattening public open import library.types.Suspension public open import library.types.Join public open import library.types.Torus public open import library.types.Truncation public open import library.types.Cospan public open import library.types.Pullback public open import library.types.Group public open import library.types.Groupoid public open import library.types.GroupSet public open import library.types.KG1 public open import library.types.Pointed public open import library.types.LoopSpace public open import library.types.HomotopyGroup public open import library.types.PathSet public open import library.types.FundamentalGroupoid public open import library.types.Cover public open import library.types.OneSkeleton public open import library.types.PathSeq public -- This should probably not be exported -- module Generic1HIT {i j} (A : Type i) (B : Type j) (f g : B → A) where -- open import library.types.Generic1HIT A B f g public
36.704545
73
0.825387
1930e7cb9ebc424d1c618f54f6029ed095a5d0e2
147
agda
Agda
problems/DeMorgan/Verifier.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
1
2021-05-17T12:07:03.000Z
2021-05-17T12:07:03.000Z
problems/DeMorgan/Verifier.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
null
null
null
problems/DeMorgan/Verifier.agda
danr/agder
ece25bed081a24f02e9f85056d05933eae2afabf
[ "BSD-3-Clause" ]
null
null
null
module Verifier where open import Definitions open import DeMorgan using (deMorgan) check : {A B : Set} → ¬ A ∧ ¬ B → ¬ (A ∨ B) check = deMorgan
18.375
43
0.666667
c77fdda429d89d17552c233a88814cb61fd3be8b
2,285
agda
Agda
src/function/extensionality/computation.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/function/extensionality/computation.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/function/extensionality/computation.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T12:17:00.000Z
2019-05-04T19:31:00.000Z
{-# OPTIONS --without-K #-} module function.extensionality.computation where open import equality open import function.isomorphism.core open import function.core open import function.extensionality.core open import function.extensionality.proof open import function.extensionality.strong funext-inv-hom : ∀ {i j}{X : Set i}{Y : X → Set j} → {f₁ f₂ f₃ : (x : X) → Y x} → (p₁ : f₁ ≡ f₂) → (p₂ : f₂ ≡ f₃) → funext-inv (p₁ · p₂) ≡ (λ x → funext-inv p₁ x · funext-inv p₂ x) funext-inv-hom refl p₂ = refl funext-hom : ∀ {i j}{X : Set i}{Y : X → Set j} → {f₁ f₂ f₃ : (x : X) → Y x} → (h₁ : (x : X) → f₁ x ≡ f₂ x) → (h₂ : (x : X) → f₂ x ≡ f₃ x) → funext (λ x → h₁ x · h₂ x) ≡ funext h₁ · funext h₂ funext-hom h₁ h₂ = begin funext (λ x → h₁ x · h₂ x) ≡⟨ sym (ap funext (ap₂ (λ u v x → u x · v x) (_≅_.iso₁ strong-funext-iso h₁) (_≅_.iso₁ strong-funext-iso h₂))) ⟩ funext (λ x → funext-inv (funext h₁) x · funext-inv (funext h₂) x) ≡⟨ sym (ap funext (funext-inv-hom (funext h₁) (funext h₂))) ⟩ funext (funext-inv (funext h₁ · funext h₂)) ≡⟨ _≅_.iso₂ strong-funext-iso (funext h₁ · funext h₂) ⟩ funext h₁ · funext h₂ ∎ where open ≡-Reasoning funext-inv-ap : ∀ {i j k}{X : Set i}{Y : X → Set j}{Z : X → Set k} → (g : {x : X} → Y x → Z x) → {f₁ f₂ : (x : X) → Y x} → (p : f₁ ≡ f₂) → funext-inv (ap (_∘'_ g) p) ≡ ((λ x → ap g (funext-inv p x))) funext-inv-ap g refl = refl funext-ap : ∀ {i j k}{X : Set i}{Y : X → Set j}{Z : X → Set k} → (g : {x : X} → Y x → Z x) → {f₁ f₂ : (x : X) → Y x} → (h : (x : X) → f₁ x ≡ f₂ x) → funext (λ x → ap g (h x)) ≡ ap (_∘'_ g) (funext h) funext-ap g h = begin funext (λ x → ap g (h x)) ≡⟨ sym (ap funext (ap (λ h x → ap g (h x)) (_≅_.iso₁ strong-funext-iso h))) ⟩ funext (λ x → ap g (funext-inv (funext h) x)) ≡⟨ ap funext (sym (funext-inv-ap g (funext h))) ⟩ funext (funext-inv (ap (_∘'_ g) (funext h))) ≡⟨ _≅_.iso₂ strong-funext-iso _ ⟩ ap (_∘'_ g) (funext h) ∎ where open ≡-Reasoning
36.269841
70
0.483589
14bb42cbf9ef7b3fc5a355d7d6f437779eb57a20
1,185
agda
Agda
test/Fail/Issue765.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue765.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue765.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K #-} module Issue765 where infixr 1 _⊎_ infixr 4 _,_ infix 4 _≡_ data ⊥ : Set where ⊥-elim : {A : Set} → ⊥ → A ⊥-elim () data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data _⊎_ (A : Set) (B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,_]₁ : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set₁} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ]₁ (inj₁ x) = f x [ f , g ]₁ (inj₂ y) = g y record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public infix 5 _◃_ infixr 1 _⊎C_ record Container : Set₁ where constructor _◃_ field Shape : Set Position : Shape → Set open Container public constC : Set → Container constC X = X ◃ λ _ → ⊥ _⊎C_ : Container → Container → Container S ◃ P ⊎C S′ ◃ P′ = (S ⊎ S′) ◃ [ P , P′ ]₁ data μ (C : Container) : Set where sup : (s : Shape C) (k : Position C s → μ C) → μ C _⋆_ : Container → Set → Set C ⋆ X = μ (constC X ⊎C C) to : ∀ {C X} → C ⋆ X → C ⋆ (C ⋆ X) to m = sup (inj₁ m) ⊥-elim injective : ∀ {C X}{m n : C ⋆ X} → to m ≡ to n → m ≡ n injective refl = refl
18.515625
57
0.498734
14d11b5ef187f67caeaca439012a5944f7df96c4
1,951
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Propositional.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- An inductive definition of the sublist relation. This is commonly -- known as Order Preserving Embeddings (OPE). ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Sublist.Propositional {a} {A : Set a} where open import Data.List.Relation.Binary.Equality.Propositional using (≋⇒≡) import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist open import Data.List.Relation.Unary.Any using (Any) open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Relation.Unary using (Pred) ------------------------------------------------------------------------ -- Re-export definition and operations from setoid sublists open SetoidSublist (setoid A) public hiding (lookup; ⊆-reflexive; ⊆-antisym ; ⊆-isPreorder; ⊆-isPartialOrder ; ⊆-preorder; ⊆-poset ) ------------------------------------------------------------------------ -- Additional operations module _ {p} {P : Pred A p} where lookup : ∀ {xs ys} → xs ⊆ ys → Any P xs → Any P ys lookup = SetoidSublist.lookup (setoid A) (subst _) ------------------------------------------------------------------------ -- Relational properties ⊆-reflexive : _≡_ ⇒ _⊆_ ⊆-reflexive refl = ⊆-refl ⊆-antisym : Antisymmetric _≡_ _⊆_ ⊆-antisym xs⊆ys ys⊆xs = ≋⇒≡ (SetoidSublist.⊆-antisym (setoid A) xs⊆ys ys⊆xs) ⊆-isPreorder : IsPreorder _≡_ _⊆_ ⊆-isPreorder = record { isEquivalence = isEquivalence ; reflexive = ⊆-reflexive ; trans = ⊆-trans } ⊆-isPartialOrder : IsPartialOrder _≡_ _⊆_ ⊆-isPartialOrder = record { isPreorder = ⊆-isPreorder ; antisym = ⊆-antisym } ⊆-preorder : Preorder a a a ⊆-preorder = record { isPreorder = ⊆-isPreorder } ⊆-poset : Poset a a a ⊆-poset = record { isPartialOrder = ⊆-isPartialOrder }
28.275362
76
0.565864
14f6201c2104d4d0750bc04aebd601794065c0f0
1,486
agda
Agda
test/Succeed/QuotePatternLambda.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/QuotePatternLambda.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/QuotePatternLambda.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Agda.Builtin.Reflection renaming (bindTC to _>>=_) open import Agda.Builtin.Unit open import Agda.Builtin.List open import Agda.Builtin.Nat open import Agda.Builtin.Equality open import Agda.Builtin.Bool _>>_ : {A B : Set} → TC A → TC B → TC B m >> m₁ = m >>= λ _ → m₁ data Fin : Nat → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) macro reflectAndCheck : ∀ {a} {A : Set a} → A → Term → TC ⊤ reflectAndCheck {A = A} x hole = withNormalisation true do `x ← quoteTC x `A ← quoteTC A ``x ← checkType `x `A >>= quoteTC unify hole ``x quoteUnquote : ∀ {a} {A : Set a} → A → Term → TC ⊤ quoteUnquote x hole = withNormalisation true do `x ← quoteTC x unify hole `x module _ (n : Nat) (A : Set) (m : Nat) (j : Fin m) where plam₁ : Fin n → Fin m plam₁ = λ where zero → j; (suc i) → j `plam₁ : Term `plam₁ = reflectAndCheck plam₁ plam₁′ : Fin n → Fin m plam₁′ = quoteUnquote plam₁ refined₁ : n ≡ suc m → Nat refined₁ refl = 0 where plam : Fin n → Fin m plam = λ where zero → j; (suc i) → i `plam : Term `plam = reflectAndCheck plam plam′ : Fin n → Fin m plam′ = quoteUnquote plam refined₂ : m ≡ suc n → Nat refined₂ refl = 0 where plam : Fin n → Fin m plam = λ where zero → j; (suc i) → suc (suc i) `plam : Term `plam = reflectAndCheck plam plam′ : Fin n → Fin m plam′ = quoteUnquote plam
22.861538
62
0.580754
36d0c4fe0620f95e938317285c441e114b0a95b8
13,331
agda
Agda
Cubical/Categories/DistLatticeSheaf/Diagram.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Categories/DistLatticeSheaf/Diagram.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Categories/DistLatticeSheaf/Diagram.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- The sheaf property of a presheaf on a distributive lattice or a basis thereof can be expressed as preservation of limits over diagrams defined in this file. -} {-# OPTIONS --safe #-} module Cubical.Categories.DistLatticeSheaf.Diagram where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.Data.Empty open import Cubical.Data.Sigma open import Cubical.Data.FinData open import Cubical.Data.FinData.Order open import Cubical.Data.Sum open import Cubical.Relation.Nullary open import Cubical.Relation.Binary.Poset open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.Limits.Limits open import Cubical.Categories.Limits.Pullback open import Cubical.Categories.Instances.DistLattice open import Cubical.Algebra.DistLattice open import Cubical.Algebra.Lattice open import Cubical.Algebra.Semilattice open import Cubical.Algebra.DistLattice.BigOps private variable ℓ ℓ' ℓ'' : Level data DLShfDiagOb (n : ℕ) : Type where sing : Fin n → DLShfDiagOb n pair : (i j : Fin n) → i <'Fin j → DLShfDiagOb n data DLShfDiagHom (n : ℕ) : DLShfDiagOb n → DLShfDiagOb n → Type where idAr : {x : DLShfDiagOb n} → DLShfDiagHom n x x singPairL : {i j : Fin n} {i<j : i <'Fin j} → DLShfDiagHom n (sing i) (pair i j i<j) singPairR : {i j : Fin n} {i<j : i <'Fin j}→ DLShfDiagHom n (sing j) (pair i j i<j) module DLShfDiagHomPath where variable n : ℕ -- DLShfDiagHom n x y is a retract of Code x y Code : (x y : DLShfDiagOb n) → Type Code (sing i) (sing j) = i ≡ j Code (sing i) (pair j k j<k) = (Σ[ p ∈ (i ≡ j) ] Σ[ i<k ∈ i <'Fin k ] PathP (λ ι → p ι <'Fin k) i<k j<k) ⊎ (Σ[ p ∈ (i ≡ k) ] Σ[ j<i ∈ j <'Fin i ] PathP (λ ι → j <'Fin p ι) j<i j<k) Code (pair i j i<j) (sing k) = ⊥ Code (pair i j i<j) (pair k l k<l) = Σ[ p ∈ (i ≡ k) × (j ≡ l) ] PathP (λ ι → fst p ι <'Fin snd p ι) i<j k<l isSetCode : ∀ (x y : DLShfDiagOb n) → isSet (Code x y) isSetCode (sing _) (sing _) = isProp→isSet (isSetFin _ _) isSetCode (sing i) (pair j k j<k) = isSet⊎ (isSetΣ (isProp→isSet (isSetFin _ _)) λ _ → isSetΣ (isProp→isSet (≤'FinIsPropValued _ _)) λ _ → isOfHLevelPathP 2 (isProp→isSet (≤'FinIsPropValued _ _)) _ _) (isSetΣ (isProp→isSet (isSetFin _ _)) λ _ → isSetΣ (isProp→isSet (≤'FinIsPropValued _ _)) λ _ → isOfHLevelPathP 2 (isProp→isSet (≤'FinIsPropValued _ _)) _ _) isSetCode (pair _ _ _) (sing _) = isProp→isSet isProp⊥ isSetCode (pair _ _ _) (pair _ _ _) = isSetΣ (isSet× (isProp→isSet (isSetFin _ _)) (isProp→isSet (isSetFin _ _))) λ _ → isOfHLevelPathP 2 (isProp→isSet (≤'FinIsPropValued _ _)) _ _ encode : (x y : DLShfDiagOb n) → DLShfDiagHom n x y → Code x y encode (sing i) (sing .i) idAr = refl encode (sing i) (pair .i j i<j) singPairL = inl (refl , i<j , refl) encode (sing j) (pair i .j i<j) singPairR = inr (refl , i<j , refl) encode (pair i j i<j) (pair .i .j .i<j) idAr = (refl , refl) , refl decode : (x y : DLShfDiagOb n) → Code x y → DLShfDiagHom n x y decode (sing i) (sing j) p = subst (λ k → DLShfDiagHom _ (sing i) (sing k)) p idAr decode (sing i) (pair j k j<k) (inl (p , i<k , q)) = transport (λ ι → DLShfDiagHom _ (sing i) (pair (p ι) k (q ι))) singPairL decode (sing i) (pair k j k<j) (inr (p , k<i , q)) = transport (λ ι → DLShfDiagHom _ (sing i) (pair k (p ι) (q ι))) singPairR decode (pair i j i<j) (pair k l k<l) (_ , p) = transport (λ ι → DLShfDiagHom _ (pair _ _ i<j) (pair _ _ (p ι))) idAr codeRetract : ∀ (x y : DLShfDiagOb n) (f : DLShfDiagHom n x y) → decode x y (encode x y f) ≡ f codeRetract (sing i) (sing .i) idAr = transportRefl idAr codeRetract (sing i) (pair .i k i<k) singPairL = transportRefl singPairL codeRetract (sing i) (pair j .i j<i) singPairR = transportRefl singPairR codeRetract (pair i j i<j) (pair .i .j .i<j) idAr = transportRefl idAr isSetDLShfDiagHom : ∀ (x y : DLShfDiagOb n) → isSet (DLShfDiagHom n x y) isSetDLShfDiagHom x y = isSetRetract (encode x y) (decode x y) (codeRetract x y) (isSetCode x y) open Category DLShfDiag : ℕ → Category ℓ-zero ℓ-zero ob (DLShfDiag n) = DLShfDiagOb n Hom[_,_] (DLShfDiag n) = DLShfDiagHom n id (DLShfDiag n) = idAr _⋆_ (DLShfDiag n) idAr f = f _⋆_ (DLShfDiag n) singPairL idAr = singPairL _⋆_ (DLShfDiag n) singPairR idAr = singPairR ⋆IdL (DLShfDiag n) _ = refl ⋆IdR (DLShfDiag n) idAr = refl ⋆IdR (DLShfDiag n) singPairL = refl ⋆IdR (DLShfDiag n) singPairR = refl ⋆Assoc (DLShfDiag n) idAr _ _ = refl ⋆Assoc (DLShfDiag n) singPairL idAr _ = refl ⋆Assoc (DLShfDiag n) singPairR idAr _ = refl isSetHom (DLShfDiag n) = let open DLShfDiagHomPath in (isSetDLShfDiagHom _ _) module _ (L' : DistLattice ℓ) where private L = fst L' LCat = (DistLatticeCategory L') ^op instance _ = snd L' open DistLatticeStr ⦃...⦄ open Join L' open JoinSemilattice (Lattice→JoinSemilattice (DistLattice→Lattice L')) open PosetStr (IndPoset .snd) hiding (_≤_) open MeetSemilattice (Lattice→MeetSemilattice (DistLattice→Lattice L')) using (∧≤RCancel ; ∧≤LCancel) open Order (DistLattice→Lattice L') open Category LCat open Functor open Cone FinVec→Diag : {n : ℕ} → FinVec L n → Functor (DLShfDiag n) LCat F-ob (FinVec→Diag α) (sing i) = α i F-ob (FinVec→Diag α) (pair i j _) = α i ∧l α j F-hom (FinVec→Diag α) idAr = is-refl _ F-hom (FinVec→Diag α) singPairL = ≤m→≤j _ _ (∧≤RCancel _ _) F-hom (FinVec→Diag α) singPairR = ≤m→≤j _ _ (∧≤LCancel _ _) F-id (FinVec→Diag α) = is-prop-valued _ _ _ _ F-seq (FinVec→Diag α) _ _ = is-prop-valued _ _ _ _ ⋁Cone : {n : ℕ} (α : FinVec L n) → Cone (FinVec→Diag α) (⋁ α) coneOut (⋁Cone α) (sing i) = ind≤⋁ α i coneOut (⋁Cone α) (pair i _ _) = is-trans _ (α i) _ (≤m→≤j _ _ (∧≤RCancel _ _)) (ind≤⋁ α i) coneOutCommutes (⋁Cone α) _ = is-prop-valued _ _ _ _ isLimCone⋁Cone : {n : ℕ} (α : FinVec L n) → isLimCone (FinVec→Diag α) (⋁ α) (⋁Cone α) fst (fst (isLimCone⋁Cone α u uCone)) = ⋁IsMax α _ λ i → uCone .coneOut (sing i) snd (fst (isLimCone⋁Cone α u uCone)) _ = is-prop-valued _ _ _ _ snd (isLimCone⋁Cone α _ uCone) _ = Σ≡Prop (λ _ → isPropIsConeMor uCone (⋁Cone α) _) (is-prop-valued _ _ _ _) module PullbacksAsDLShfDiags (C : Category ℓ ℓ') (cspan : Cospan C) (pback : Pullback C cspan) where open Functor open Cone open Cospan ⦃...⦄ open Pullback ⦃...⦄ instance _ = cspan _ = pback cospanAsDiag : Functor (DLShfDiag 2) C F-ob cospanAsDiag (sing zero) = l F-ob cospanAsDiag (sing (suc zero)) = r F-ob cospanAsDiag (pair _ _ _) = m F-hom cospanAsDiag idAr = id C F-hom cospanAsDiag {x = sing zero} singPairL = s₁ F-hom cospanAsDiag {x = sing (suc zero)} singPairL = s₂ F-hom cospanAsDiag {x = sing zero} singPairR = s₁ F-hom cospanAsDiag {x = sing (suc zero)} singPairR = s₂ F-id cospanAsDiag = refl F-seq cospanAsDiag idAr idAr = sym (⋆IdL C _) F-seq cospanAsDiag idAr singPairL = sym (⋆IdL C _) F-seq cospanAsDiag idAr singPairR = sym (⋆IdL C _) F-seq cospanAsDiag singPairL idAr = sym (⋆IdR C _) F-seq cospanAsDiag singPairR idAr = sym (⋆IdR C _) pbPrAsCone : Cone cospanAsDiag pbOb coneOut pbPrAsCone (sing zero) = pbPr₁ coneOut pbPrAsCone (sing (suc zero)) = pbPr₂ coneOut pbPrAsCone (pair _ _ _) = pbPr₁ ⋆⟨ C ⟩ s₁ coneOutCommutes pbPrAsCone idAr = ⋆IdR C _ coneOutCommutes pbPrAsCone (singPairL {zero}) = refl coneOutCommutes pbPrAsCone (singPairL {suc zero}) = sym pbCommutes coneOutCommutes pbPrAsCone (singPairR {zero} {zero}) = refl coneOutCommutes pbPrAsCone (singPairR {zero} {suc zero}) = sym pbCommutes coneOutCommutes pbPrAsCone (singPairR {suc zero} {zero}) = refl coneOutCommutes pbPrAsCone (singPairR {suc zero} {suc zero}) = sym pbCommutes pbAsLimit : isLimCone cospanAsDiag pbOb pbPrAsCone pbAsLimit c cc = uniqueExists (fromPBUnivProp .fst .fst) toConeMor (λ _ → isPropIsConeMor cc pbPrAsCone _) (λ f cf → cong fst (fromPBUnivProp .snd (f , fromConeMor cf))) where fromPBUnivProp : ∃![ hk ∈ C [ c , Pullback.pbOb pback ] ] (coneOut cc (sing zero) ≡ hk ⋆⟨ C ⟩ pbPr₁) × (coneOut cc (sing (suc zero)) ≡ hk ⋆⟨ C ⟩ pbPr₂) fromPBUnivProp = univProp (cc .coneOut (sing zero)) (cc .coneOut (sing (suc zero))) (cc .coneOutCommutes (singPairL {i<j = s≤s z≤}) ∙ sym (cc .coneOutCommutes singPairR)) toConeMor : isConeMor cc pbPrAsCone (fromPBUnivProp .fst .fst) toConeMor (sing zero) = sym (fromPBUnivProp .fst .snd .fst) toConeMor (sing (suc zero)) = sym (fromPBUnivProp .fst .snd .snd) toConeMor (pair zero j _) = path where path : fromPBUnivProp .fst .fst ⋆⟨ C ⟩ (pbPr₁ ⋆⟨ C ⟩ s₁) ≡ cc .coneOut (pair zero j _) path = fromPBUnivProp .fst .fst ⋆⟨ C ⟩ (pbPr₁ ⋆⟨ C ⟩ s₁) ≡⟨ sym (⋆Assoc C _ _ _) ⟩ (fromPBUnivProp .fst .fst ⋆⟨ C ⟩ pbPr₁) ⋆⟨ C ⟩ s₁ ≡⟨ cong (λ f → f ⋆⟨ C ⟩ s₁) (sym (fromPBUnivProp .fst .snd .fst)) ⟩ cc .coneOut (sing zero) ⋆⟨ C ⟩ s₁ ≡⟨ cc .coneOutCommutes singPairL ⟩ cc .coneOut (pair zero j _) ∎ toConeMor (pair (suc zero) j _) = path where path : fromPBUnivProp .fst .fst ⋆⟨ C ⟩ (pbPr₁ ⋆⟨ C ⟩ s₁) ≡ cc .coneOut (pair (suc zero) j _) path = fromPBUnivProp .fst .fst ⋆⟨ C ⟩ (pbPr₁ ⋆⟨ C ⟩ s₁) ≡⟨ cong (λ f → fromPBUnivProp .fst .fst ⋆⟨ C ⟩ f) pbCommutes ⟩ fromPBUnivProp .fst .fst ⋆⟨ C ⟩ (pbPr₂ ⋆⟨ C ⟩ s₂) ≡⟨ sym (⋆Assoc C _ _ _) ⟩ (fromPBUnivProp .fst .fst ⋆⟨ C ⟩ pbPr₂) ⋆⟨ C ⟩ s₂ ≡⟨ cong (λ f → f ⋆⟨ C ⟩ s₂) (sym (fromPBUnivProp .fst .snd .snd)) ⟩ cc .coneOut (sing (suc zero)) ⋆⟨ C ⟩ s₂ ≡⟨ cc .coneOutCommutes singPairL ⟩ cc .coneOut (pair (suc zero) j _) ∎ fromConeMor : {f : C [ c , pbOb ]} → isConeMor cc pbPrAsCone f → (coneOut cc (sing zero) ≡ f ⋆⟨ C ⟩ pbPr₁) × (coneOut cc (sing (suc zero)) ≡ f ⋆⟨ C ⟩ pbPr₂) fst (fromConeMor cf) = sym (cf (sing zero)) snd (fromConeMor cf) = sym (cf (sing (suc zero))) module DLShfDiagsAsPullbacks (C : Category ℓ ℓ') (F : Functor (DLShfDiag 2) C) (limF : LimCone F) where open Cospan open Pullback open Functor ⦃...⦄ open Cone ⦃...⦄ open LimCone ⦃...⦄ instance _ = F _ = limF _ = limF .limCone DiagAsCospan : Cospan C l DiagAsCospan = F-ob (sing zero) m DiagAsCospan = F-ob (pair zero (suc zero) (s≤s z≤)) r DiagAsCospan = F-ob (sing (suc zero)) s₁ DiagAsCospan = F-hom singPairL s₂ DiagAsCospan = F-hom singPairR LimAsPullback : Pullback C DiagAsCospan pbOb LimAsPullback = lim pbPr₁ LimAsPullback = coneOut (sing zero) pbPr₂ LimAsPullback = coneOut (sing (suc zero)) pbCommutes LimAsPullback = coneOutCommutes singPairL ∙ sym (coneOutCommutes singPairR) univProp LimAsPullback {d = d} f g cSq = uniqueExists (fromUnivProp .fst .fst) (sym (fromUnivProp .fst .snd (sing zero)) , sym (fromUnivProp .fst .snd (sing (suc zero)))) (λ _ → isProp× (isSetHom C _ _) (isSetHom C _ _)) λ h' trs → cong fst (fromUnivProp .snd (h' , toConeMor h' trs)) where theCone : Cone F d Cone.coneOut theCone (sing zero) = f Cone.coneOut theCone (sing (suc zero)) = g Cone.coneOut theCone (pair zero zero ()) Cone.coneOut theCone (pair zero (suc zero) (s≤s z≤)) = f ⋆⟨ C ⟩ DiagAsCospan .s₁ Cone.coneOut theCone (pair (suc zero) zero ()) Cone.coneOut theCone (pair (suc zero) (suc zero) (s≤s ())) Cone.coneOutCommutes theCone {u} idAr = cong (seq' C (Cone.coneOut theCone u)) F-id ∙ ⋆IdR C (Cone.coneOut theCone u) Cone.coneOutCommutes theCone {sing zero} {pair ._ (suc zero) (s≤s z≤)} singPairL = refl Cone.coneOutCommutes theCone {sing (suc zero)} {pair ._ (suc zero) (s≤s ())} singPairL Cone.coneOutCommutes theCone {sing (suc zero)} {pair zero ._ (s≤s z≤)} singPairR = sym cSq Cone.coneOutCommutes theCone {sing (suc zero)} {pair (suc zero) ._ (s≤s ())} singPairR fromUnivProp : ∃![ h ∈ C [ d , lim ] ] isConeMor theCone limCone h fromUnivProp = LimCone.univProp limF d theCone toConeMor : ∀ (h' : C [ d , lim ]) → (f ≡ h' ⋆⟨ C ⟩ coneOut (sing zero)) × (g ≡ h' ⋆⟨ C ⟩ coneOut (sing (suc zero))) → isConeMor theCone limCone h' toConeMor h' (tr₁ , tr₂) (sing zero) = sym tr₁ toConeMor h' (tr₁ , tr₂) (sing (suc zero)) = sym tr₂ toConeMor h' (tr₁ , tr₂) (pair zero (suc zero) (s≤s z≤)) = path where path : h' ⋆⟨ C ⟩ coneOut (pair zero (suc zero) (s≤s z≤)) ≡ f ⋆⟨ C ⟩ F-hom singPairL path = h' ⋆⟨ C ⟩ coneOut (pair zero (suc zero) (s≤s z≤)) ≡⟨ cong (seq' C h') (sym (coneOutCommutes singPairL)) ⟩ h' ⋆⟨ C ⟩ (coneOut (sing zero) ⋆⟨ C ⟩ F-hom singPairL) ≡⟨ sym (⋆Assoc C _ _ _) ⟩ (h' ⋆⟨ C ⟩ coneOut (sing zero)) ⋆⟨ C ⟩ F-hom singPairL ≡⟨ cong (λ x → seq' C x (F-hom singPairL)) (sym tr₁) ⟩ f ⋆⟨ C ⟩ F-hom singPairL ∎ toConeMor h' (tr₁ , tr₂) (pair (suc zero) (suc zero) (s≤s ()))
40.767584
97
0.621859
0d3a54dcf8c3ad5bd0f4d8913d15554cea69317a
745
agda
Agda
src/Categories/Category/Dagger/Instance/Rels.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Dagger/Instance/Rels.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Dagger/Instance/Rels.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Category.Dagger.Instance.Rels where open import Data.Product open import Function open import Relation.Binary.PropositionalEquality open import Level open import Categories.Category.Dagger open import Categories.Category.Instance.Rels RelsHasDagger : ∀ {o ℓ} → HasDagger (Rels o ℓ) RelsHasDagger = record { _† = flip ; †-identity = (lift ∘ sym ∘ lower) , (lift ∘ sym ∘ lower) ; †-homomorphism = (map₂ swap) , (map₂ swap) ; †-resp-≈ = λ p → (proj₁ p) , (proj₂ p) -- it's the implicits that need flipped ; †-involutive = λ _ → id , id } RelsDagger : ∀ o ℓ → DaggerCategory (suc o) (suc (o ⊔ ℓ)) (o ⊔ ℓ) RelsDagger o ℓ = record { C = Rels o ℓ ; hasDagger = RelsHasDagger }
28.653846
82
0.672483
8b9da05a701dd7e75f911e0d16fa84453396b849
21,362
agda
Agda
Cubical/ZCohomology/Groups/KleinBottle.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/KleinBottle.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/KleinBottle.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.ZCohomology.Groups.KleinBottle where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Properties open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Function open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2) open import Cubical.Data.Nat hiding (+-assoc) open import Cubical.Algebra.Group renaming (Int to IntGroup ; Bool to BoolGroup ; Unit to UnitGroup) open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Transport open import Cubical.ZCohomology.Groups.Unit open import Cubical.ZCohomology.Groups.Sn open import Cubical.Data.Sigma open import Cubical.Foundations.Isomorphism open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.Equiv open import Cubical.Homotopy.Connected open import Cubical.Data.Empty renaming (rec to ⊥-rec) open import Cubical.Data.Bool open import Cubical.Data.Int renaming (+-comm to +-commℤ ; _+_ to _+ℤ_) open import Cubical.HITs.KleinBottle open import Cubical.Data.Empty open import Cubical.Foundations.Path open import Cubical.Homotopy.Loopspace open IsGroupHom open Iso characFunSpace𝕂² : ∀ {ℓ} (A : Type ℓ) → Iso (KleinBottle → A) (Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) fun (characFunSpace𝕂² A) f = (f point) , ((cong f line1) , (cong f line2 , fst (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)))) inv (characFunSpace𝕂² A) (x , p , q , sq) point = x inv (characFunSpace𝕂² A) (x , p , q , sq) (line1 i) = p i inv (characFunSpace𝕂² A) (x , p , q , sq) (line2 i) = q i inv (characFunSpace𝕂² A) (x , p , q , sq) (square i j) = invEq (Square≃doubleComp q q (sym p) p) sq i j rightInv (characFunSpace𝕂² A) (x , (p , (q , sq))) = ΣPathP (refl , (ΣPathP (refl , (ΣPathP (refl , secEq (Square≃doubleComp q q (sym p) p) sq))))) leftInv (characFunSpace𝕂² A) f _ point = f point leftInv (characFunSpace𝕂² A) f _ (line1 i) = f (line1 i) leftInv (characFunSpace𝕂² A) f _ (line2 i) = f (line2 i) leftInv (characFunSpace𝕂² A) f z (square i j) = retEq (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)) z i j private movePathLem : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → (p ∙∙ q ∙∙ p ≡ q) ≡ ((p ∙ p) ∙ q ≡ q) movePathLem p q comm = cong (_≡ q) (doubleCompPath-elim' p q p ∙∙ cong (p ∙_) (comm q p) ∙∙ assoc _ _ _) movePathLem2 : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → (((p ∙ p) ∙ q) ∙ sym q ≡ q ∙ sym q) ≡ (p ∙ p ≡ refl) movePathLem2 p q = cong₂ _≡_ (sym (assoc (p ∙ p) q (sym q)) ∙∙ cong ((p ∙ p) ∙_) (rCancel q) ∙∙ sym (rUnit (p ∙ p))) (rCancel q) movePathIso : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → Iso (p ∙∙ q ∙∙ p ≡ q) (p ∙ p ≡ refl) movePathIso {x = x} p q comm = compIso (pathToIso (movePathLem p q comm)) (compIso (helper (p ∙ p)) (pathToIso (movePathLem2 p q))) where helper : (p : x ≡ x) → Iso (p ∙ q ≡ q) ((p ∙ q) ∙ sym q ≡ q ∙ sym q) helper p = congIso (equivToIso (_ , compPathr-isEquiv (sym q))) ------ H¹(𝕂²) ≅ 0 -------------- H⁰-𝕂² : GroupIso (coHomGr 0 KleinBottle) IntGroup fun (fst H⁰-𝕂²) = sRec isSetInt λ f → f point inv (fst H⁰-𝕂²) x = ∣ (λ _ → x) ∣₂ rightInv (fst H⁰-𝕂²) _ = refl leftInv (fst H⁰-𝕂²) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → cong ∣_∣₂ (funExt (λ {point → refl ; (line1 i) j → isSetInt (f point) (f point) refl (cong f line1) j i ; (line2 i) j → isSetInt (f point) (f point) refl (cong f line2) j i ; (square i j) z → helper f i j z})) where helper : (f : KleinBottle → Int) → Cube (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z (~ i)) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z i) refl λ i j → f (square i j) helper f = isGroupoid→isGroupoid' (isOfHLevelSuc 2 isSetInt) _ _ _ _ _ _ snd H⁰-𝕂² = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _) λ _ _ → refl) ------ H¹(𝕂¹) ≅ ℤ ------------ {- Step one : H¹(𝕂²) := ∥ 𝕂² → K₁ ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ x ∈ K₁ ] (x ≡ x) ∥₂ (p ∙ p ≡ refl forces p ≡ refl. Also, p ∙ p ≡ refl is an hProp) -} nilpotent→≡0 : (x : Int) → x +ℤ x ≡ 0 → x ≡ 0 nilpotent→≡0 (pos zero) p = refl nilpotent→≡0 (pos (suc n)) p = ⊥-rec (negsucNotpos _ _ (sym (cong (_- 1) (cong sucInt (sym (helper2 n)) ∙ p)))) where helper2 : (n : ℕ) → pos (suc n) +pos n ≡ pos (suc (n + n)) helper2 zero = refl helper2 (suc n) = cong sucInt (sym (sucInt+pos n (pos (suc n)))) ∙∙ cong (sucInt ∘ sucInt) (helper2 n) ∙∙ cong (pos ∘ suc ∘ suc) (sym (+-suc n n)) nilpotent→≡0 (negsuc n) p = ⊥-rec (negsucNotpos _ _ (helper2 n p)) where helper2 : (n : ℕ) → (negsuc n +negsuc n) ≡ pos 0 → negsuc n ≡ pos (suc n) helper2 n p = cong (negsuc n +ℤ_) (sym (helper3 n)) ∙ +-assoc (negsuc n) (negsuc n) (pos (suc n)) ∙∙ cong (_+ℤ (pos (suc n))) p ∙∙ cong sucInt (+-commℤ (pos 0) (pos n)) where helper3 : (n : ℕ) → negsuc n +pos (suc n) ≡ 0 helper3 zero = refl helper3 (suc n) = cong sucInt (sucInt+pos n (negsuc (suc n))) ∙ helper3 n nilpotent→≡refl : (x : coHomK 1) (p : x ≡ x) → p ∙ p ≡ refl → p ≡ refl nilpotent→≡refl = trElim (λ _ → isGroupoidΠ2 λ _ _ → isOfHLevelPlus {n = 1} 2 (isOfHLevelTrunc 3 _ _ _ _)) (toPropElim (λ _ → isPropΠ2 λ _ _ → isOfHLevelTrunc 3 _ _ _ _) λ p pId → sym (rightInv (Iso-Kn-ΩKn+1 0) p) ∙∙ cong (Kn→ΩKn+1 0) (nilpotent→≡0 (ΩKn+1→Kn 0 p) (sym (ΩKn+1→Kn-hom 0 p p) ∙ cong (ΩKn+1→Kn 0) pId)) ∙∙ Kn→ΩKn+10ₖ 0) Iso-H¹-𝕂²₁ : Iso (Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl) (Σ[ x ∈ coHomK 1 ] x ≡ x) fun Iso-H¹-𝕂²₁ (x , (_ , (q , _))) = x , q inv Iso-H¹-𝕂²₁ (x , q) = x , (refl , (q , (sym (rUnit refl)))) rightInv Iso-H¹-𝕂²₁ _ = refl leftInv Iso-H¹-𝕂²₁ (x , (p , (q , P))) = ΣPathP (refl , (ΣPathP (sym (nilpotent→≡refl x p P) , toPathP (Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _) (transportRefl q))))) {- But this is precisely the type (minus set-truncation) of H¹(S¹) -} Iso-H¹-𝕂²₂ : Iso (Σ[ x ∈ coHomK 1 ] x ≡ x) (S¹ → coHomK 1) Iso-H¹-𝕂²₂ = invIso IsoFunSpaceS¹ H¹-𝕂²≅ℤ : GroupIso (coHomGr 1 KleinBottle) IntGroup H¹-𝕂²≅ℤ = compGroupIso theGroupIso (Hⁿ-Sⁿ≅ℤ 0) where theIso : Iso (coHom 1 KleinBottle) (coHom 1 S¹) theIso = setTruncIso ( compIso (characFunSpace𝕂² (coHomK 1)) (compIso (Σ-cong-iso-snd (λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → movePathIso p q (isCommΩK-based 1 x))) (compIso Iso-H¹-𝕂²₁ Iso-H¹-𝕂²₂))) is-hom : IsGroupHom (coHomGr 1 KleinBottle .snd) (fun theIso) (coHomGr 1 S¹ .snd) is-hom = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f g → cong ∣_∣₂ (funExt λ {base → refl ; (loop i) → refl})) theGroupIso : GroupIso (coHomGr 1 KleinBottle) (coHomGr 1 S¹) theGroupIso = (theIso , is-hom) ------ H²(𝕂²) ≅ ℤ/2ℤ (represented here by BoolGroup) ------- -- It suffices to show that H²(Klein) is equivalent to Bool as types {- Step one : H²(𝕂²) := ∥ 𝕂² → K₂ ∥₂ ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (connectedness of K₂) -} Iso-H²-𝕂²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl ∥₂ fun Iso-H²-𝕂²₁ = sRec setTruncIsSet (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet) (sphereElim _ (λ _ → isSetΠ λ _ → setTruncIsSet) λ y → ∣ fst y , snd (snd y) ∣₂))) inv Iso-H²-𝕂²₁ = sMap λ p → (0ₖ 2) , ((fst p) , (refl , (snd p))) rightInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ p → refl leftInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ λ _ → setTruncIsSet _ _) λ {(p , (q , sq)) → trRec (setTruncIsSet _ _) (λ qid → cong ∣_∣₂ (ΣPathP (refl , (ΣPathP (refl , (ΣPathP (sym qid , refl))))))) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPathKn 1 (0ₖ 2) (0ₖ 2)) ∣ q ∣ ∣ refl ∣))}))) {- Step two : ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ -} Iso-H²-𝕂²₂ : Iso ∥ (Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl) ∥₂ ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Iso-H²-𝕂²₂ = setTruncIso (Σ-cong-iso {B' = λ x → x +ₖ x ≡ 0ₖ 1} (invIso (Iso-Kn-ΩKn+1 1)) λ p → compIso (congIso (invIso (Iso-Kn-ΩKn+1 1))) (pathToIso λ i → ΩKn+1→Kn-hom 1 p p i ≡ 0ₖ 1)) {- Step three : ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ ≡ Bool We begin by defining the a map Σ[ x ∈ K₁ ] x + x ≡ 0 → Bool. For a point (0 , p) we map it to true if winding(p) is even and false if winding(p) is odd. We also have to show that this map respects the loop -} ΣKₙNilpot→Bool : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool ΣKₙNilpot→Bool = uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool) λ {base p → isEven (ΩKn+1→Kn 0 p) ; (loop i) p → hcomp (λ k → λ { (i = i0) → respectsLoop p k ; (i = i1) → isEven (ΩKn+1→Kn 0 p)}) (isEven (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i p)))}) where isEven-2 : (x : Int) → isEven (-2 +ℤ x) ≡ isEven x isEven-2 (pos zero) = refl isEven-2 (pos (suc zero)) = refl isEven-2 (pos (suc (suc n))) = cong isEven (cong sucInt (sucInt+pos _ _) ∙∙ sucInt+pos _ _ ∙∙ +-commℤ 0 (pos n)) ∙ lossy n where lossy : (n : ℕ) → isEven (pos n) ≡ isEven (pos n) lossy n = refl isEven-2 (negsuc zero) = refl isEven-2 (negsuc (suc n)) = cong isEven (predInt+negsuc n _ ∙ +-commℤ -3 (negsuc n)) ∙ lossy2 n where lossy2 : (n : ℕ) → isEven (negsuc (suc (suc (suc n)))) ≡ isEven (pos n) lossy2 n = refl respectsLoop : (p : 0ₖ 1 ≡ 0ₖ 1) → isEven (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p)) ≡ isEven (ΩKn+1→Kn 0 p) respectsLoop p = cong isEven (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1)) (lUnit p))) ∙∙ cong isEven (cong (ΩKn+1→Kn 0) λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j ((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p)) ∙∙ cong isEven (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p) ∙ isEven-2 (ΩKn+1→Kn 0 p) {- We show that for any x : Int we have ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , refl) ∣₂ when x is even and ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ when x is odd This is done by induction on x. For the inductive step we define a multiplication _*_ on ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ which is just ∣ (0 , p) ∣₂ * ∣ (0 , q) ∣₂ ≡ ∣ (0 , p ∙ q) ∣₂ when x is 0 -} private _*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ _*_ = sRec (isSetΠ (λ _ → setTruncIsSet)) λ a → sRec setTruncIsSet λ b → *' (fst a) (fst b) (snd a) (snd b) where *' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ *' = trElim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 setTruncIsSet) (wedgeconFun _ _ (λ _ _ → isSetΠ2 λ _ _ → setTruncIsSet) (λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂) (λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂) (funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _)))))) *=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂ *=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q))) isEvenNegsuc : (n : ℕ) → isEven (pos (suc n)) ≡ true → isEven (negsuc n) ≡ true isEvenNegsuc zero p = ⊥-rec (true≢false (sym p)) isEvenNegsuc (suc n) p = p ¬isEvenNegSuc : (n : ℕ) → isEven (pos (suc n)) ≡ false → isEven (negsuc n) ≡ false ¬isEvenNegSuc zero p = refl ¬isEvenNegSuc (suc n) p = p evenCharac : (x : Int) → isEven x ≡ true → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , refl) ∣₂ evenCharac (pos zero) isisEven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂ evenCharac (pos (suc zero)) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (pos (suc (suc zero))) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i)) ∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣))) evenCharac (pos (suc (suc (suc n)))) isisEven = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2))) ∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) isisEven) (evenCharac 2 refl)) evenCharac (negsuc zero) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (negsuc (suc zero)) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁) (inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i)) ∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣)) evenCharac (negsuc (suc (suc n))) isisEven = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (evenCharac (negsuc n) (isEvenNegsuc n isisEven)) (evenCharac -2 refl) oddCharac : (x : Int) → isEven x ≡ false → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ oddCharac (pos zero) isOdd = ⊥-rec (true≢false isOdd) oddCharac (pos (suc zero)) isOdd i = ∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j) (inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂ oddCharac (pos (suc (suc n))) isOdd = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2)) ∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl) oddCharac (negsuc zero) isOdd = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i)) ∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k) ; (i = i1) → loop j ; (j = i1) → base}) (loop (j ∨ ~ i)) ∣)) oddCharac (negsuc (suc zero)) isOdd = ⊥-rec (true≢false isOdd) oddCharac (negsuc (suc (suc n))) isOdd = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (oddCharac (negsuc n) (¬isEvenNegSuc n isOdd)) (evenCharac (negsuc 1) refl) {- We now have all we need to establish the Iso -} Bool→ΣKₙNilpot : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool→ΣKₙNilpot false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂ Bool→ΣKₙNilpot true = ∣ 0ₖ 1 , refl ∣₂ testIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool fun testIso = sRec isSetBool ΣKₙNilpot→Bool inv testIso = Bool→ΣKₙNilpot rightInv testIso false = refl rightInv testIso true = refl leftInv testIso = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _)) (toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _)) (λ p → path p (isEven (ΩKn+1→Kn 0 p)) refl)))) where path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (isEven (ΩKn+1→Kn 0 p) ≡ b) → Bool→ΣKₙNilpot (ΣKₙNilpot→Bool (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂ path p false q = (cong Bool→ΣKₙNilpot q) ∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i path p true q = cong Bool→ΣKₙNilpot q ∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i H²-𝕂²≅Bool : GroupIso (coHomGr 2 KleinBottle) BoolGroup H²-𝕂²≅Bool = invGroupIso (≅Bool theIso) where theIso : Iso _ _ theIso = compIso (setTruncIso (compIso (characFunSpace𝕂² (coHomK 2)) (Σ-cong-iso-snd λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → (movePathIso p q (isCommΩK-based 2 x))))) (compIso Iso-H²-𝕂²₁ (compIso Iso-H²-𝕂²₂ testIso)) ------ Hⁿ(𝕂²) ≅ 0 , n ≥ 3 ------ isContrHⁿ-𝕂² : (n : ℕ) → isContr (coHom (3 + n) KleinBottle) isContrHⁿ-𝕂² n = isOfHLevelRetractFromIso 0 (setTruncIso (characFunSpace𝕂² (coHomK _))) isContrΣ-help where helper : (x : coHomK (3 + n))(p : x ≡ x) → (refl ≡ p) → (q : x ≡ x) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ x , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ helper = trElim (λ _ → isProp→isOfHLevelSuc (4 + n) (isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _) λ p → J (λ p _ → (q : 0ₖ _ ≡ 0ₖ _) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ q → J (λ q _ → (P : refl ∙∙ q ∙∙ refl ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , refl , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ P → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _)) (λ P≡rUnitrefl i → ∣ 0ₖ (3 + n) , refl , refl , P≡rUnitrefl i ∣₂) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPath _ (isConnectedPathKn (2 + n) _ _) (refl ∙∙ refl ∙∙ refl) refl) ∣ P ∣ ∣ sym (rUnit refl) ∣))) isContrΣ-help : isContr ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ fst isContrΣ-help = ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ snd isContrΣ-help = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(x , p , q , P) → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ pId → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ qId → sym (helper x p pId q qId P)) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ q ∣))) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ p ∣))} Hⁿ⁺³-𝕂²≅0 : (n : ℕ) → GroupIso (coHomGr (3 + n) KleinBottle) UnitGroup Hⁿ⁺³-𝕂²≅0 n = contrGroupIsoUnit (isContrHⁿ-𝕂² n)
46.949451
141
0.50529
21e012461f41b8c2a58b56ea9a616b9f20e3cd44
1,665
agda
Agda
lib/types/Types.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/Types.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/types/Types.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} module lib.types.Types where open import lib.Basics open import lib.types.Empty public open import lib.types.Unit public open import lib.types.Bool public open import lib.types.Nat public open import lib.types.Int public open import lib.types.TLevel public open import lib.types.Paths public open import lib.types.Sigma public open import lib.types.Pi public open import lib.types.Coproduct public open import lib.types.Lift public open import lib.types.Circle public open import lib.types.Span public open import lib.types.Pushout public open import lib.types.PushoutFlattening public open import lib.types.Suspension public open import lib.types.IteratedSuspension public open import lib.types.Cofiber public open import lib.types.Wedge public open import lib.types.BigWedge public open import lib.types.Smash public open import lib.types.Join public open import lib.types.Torus public open import lib.types.Truncation public open import lib.types.Cospan public open import lib.types.Pullback public open import lib.types.Group public open import lib.types.Groupoid public open import lib.types.GroupSet public open import lib.types.EilenbergMacLane1 public open import lib.types.Pointed public open import lib.types.LoopSpace public open import lib.types.PathSet public open import lib.types.FundamentalGroupoid public open import lib.types.Cover public open import lib.types.PathSeq public open import lib.types.List public open import lib.types.NatColim public -- This should probably not be exported -- module Generic1HIT {i j} (A : Type i) (B : Type j) (f g : B → A) where -- open import lib.types.Generic1HIT A B f g public
34.6875
73
0.813213
ad8b49778bd94ee29220b037c06ce9e394928a80
156
agda
Agda
test/interaction/ImportedDisplayForms.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/ImportedDisplayForms.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/ImportedDisplayForms.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Agda.Builtin.Nat open import Imports.ImportedDisplayForms postulate T : Nat → Set foo : (a : Nat) → T (a + a) foo a = {!!}
13
40
0.660256
1459192c3d9b502cd363c953dc819efec7c6c86e
4,681
agda
Agda
src/Categories/Bicategory/Opposite.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Bicategory/Opposite.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Bicategory/Opposite.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Bicategory using (Bicategory) -- The 1-cell dual (op) and 2-cell dual (co) of a given bicategory. module Categories.Bicategory.Opposite where open import Data.Product using (_,_) import Categories.Bicategory.Extras as BicategoryExtras open import Categories.Category using (Category) import Categories.Category.Cartesian as Cartesian import Categories.Morphism as Morphism import Categories.Morphism.Reasoning as MorphismReasoning open import Categories.Category.Product using (Swap) open import Categories.Functor using (Functor; _∘F_) open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; niHelper) -- There several ways to dualize a bicategory: -- -- * flip the 1-cells (op C), or -- * flip the 2-cells (co C). -- * flip both (coop C). -- -- We implement all three. module _ {o ℓ e t} (C : Bicategory o ℓ e t) where open BicategoryExtras C open Shorthands private module MR {A} {B} where open Morphism (hom A B) public using (module ≅) open MorphismReasoning (hom A B) public using (switch-tofromʳ) open MR -- The 1-cell dual of C. -- -- NOTE. The definition here is specialized to the particular choice -- of tensor product (cartesian) and braiding (swap) used in the -- definition of Bicategories. We could instead have defined the -- `enriched' field using the generic `op' operation defined in -- Categories.Enriched.Category.Opposite, but that would have resulted -- in much more complicated proofs of the triangle and pentagon -- identities. That's because the definition of associativity and the -- unit laws in the generic opposite enriched category has to work for -- any choice of braiding and is therefore more involved. When these -- laws become natural isomorphism in the definition of Bicategories, -- they turn into long chains consisting of mostly identity morphisms -- that make the types of the triangle and pentagon identities -- enormous. We can avoid this by specializing the definitions of the -- associators and unitors below. -- -- Note also that this version of `op' is almost a (definitional) -- involution. The problematic fields are the triangle and pentagon -- identities which are not involutive on the nose. This could be -- fixed by adding additional fields (in the style of `sym-assoc' in -- Category). To also support `co` and `coop` would require two more -- variants of each equation, so there would be quite a lot of -- redundancy in the end. op : Bicategory o ℓ e t op = record { enriched = record { Obj = Obj ; hom = λ A B → hom B A ; id = id ; ⊚ = ⊚ ∘F Swap ; ⊚-assoc = niHelper (record { η = λ{ ((f , g) , h) → ⊚-assoc.⇐.η ((h , g) , f) } ; η⁻¹ = λ{ ((f , g) , h) → ⊚-assoc.⇒.η ((h , g) , f) } ; commute = λ{ ((α , β) , γ) → ⊚-assoc.⇐.commute ((γ , β) , α) } ; iso = λ _ → record { isoˡ = ⊚-assoc.iso.isoʳ _ ; isoʳ = ⊚-assoc.iso.isoˡ _ } }) ; unitˡ = niHelper (record { η = λ{ (_ , g) → unitʳ.⇒.η (g , _) } ; η⁻¹ = λ{ (_ , g) → unitʳ.⇐.η (g , _) } ; commute = λ{ (_ , β) → unitʳ.⇒.commute (β , _) } ; iso = λ{ (_ , g) → record { isoˡ = unitʳ.iso.isoˡ (g , _) ; isoʳ = unitʳ.iso.isoʳ (g , _) } } }) ; unitʳ = niHelper (record { η = λ{ (f , _) → unitˡ.⇒.η (_ , f) } ; η⁻¹ = λ{ (f , _) → unitˡ.⇐.η (_ , f) } ; commute = λ{ (α , _) → unitˡ.⇒.commute (_ , α) } ; iso = λ{ (f , _) → record { isoˡ = unitˡ.iso.isoˡ (_ , f) ; isoʳ = unitˡ.iso.isoʳ (_ , f) } } }) } ; triangle = λ {_ _ _ f g} → begin ρ⇒ ◁ g ∘ᵥ α⇐ ≈˘⟨ switch-tofromʳ (≅.sym associator) triangle ⟩ f ▷ λ⇒ ∎ ; pentagon = λ {_ _ _ _ _ f g h i} → begin α⇐ ◁ i ∘ᵥ α⇐ ∘ᵥ f ▷ α⇐ ≈˘⟨ hom.assoc ⟩ (α⇐ ◁ i ∘ᵥ α⇐) ∘ᵥ f ▷ α⇐ ≈⟨ pentagon-inv ⟩ α⇐ ∘ᵥ α⇐ ∎ } where open hom.HomReasoning -- The 2-cell dual of C. co : Bicategory o ℓ e t co = record { enriched = record { Obj = Obj ; hom = λ A B → Category.op (hom A B) ; id = Functor.op id ; ⊚ = Functor.op ⊚ ; ⊚-assoc = NaturalIsomorphism.op′ ⊚-assoc ; unitˡ = NaturalIsomorphism.op′ unitˡ ; unitʳ = NaturalIsomorphism.op′ unitʳ } ; triangle = triangle-inv ; pentagon = pentagon-inv } -- The combined 1- and 2-cell dual of C. coop : ∀ {o ℓ e t} → Bicategory o ℓ e t → Bicategory o ℓ e t coop C = co (op C)
37.75
77
0.591968
3f0750f19f6c352e6483988b562e887487b0a4cc
2,452
agda
Agda
src/Data/PropFormula/Theorems/Mixies.agda
jonaprieto/agda-prop
a1730062a6aaced2bb74878c1071db06477044ae
[ "MIT" ]
13
2017-05-01T16:45:41.000Z
2022-01-17T03:33:12.000Z
src/Data/PropFormula/Theorems/Mixies.agda
jonaprieto/agda-prop
a1730062a6aaced2bb74878c1071db06477044ae
[ "MIT" ]
18
2017-03-08T14:33:10.000Z
2017-12-18T16:34:21.000Z
src/Data/PropFormula/Theorems/Mixies.agda
jonaprieto/agda-prop
a1730062a6aaced2bb74878c1071db06477044ae
[ "MIT" ]
2
2017-03-30T16:41:56.000Z
2017-12-01T17:01:25.000Z
------------------------------------------------------------------------------ -- Agda-Prop Library. -- Theorems with different connectives. ------------------------------------------------------------------------------ open import Data.Nat using ( ℕ ) module Data.PropFormula.Theorems.Mixies ( n : ℕ ) where ------------------------------------------------------------------------------ open import Data.PropFormula.Syntax n open import Data.PropFormula.Theorems.Classical n open import Data.PropFormula.Theorems.Biimplication n using ( ⇔-¬-to-¬; ⊃-⇔-¬∨ ) open import Data.PropFormula.Theorems.Disjunction n using ( ∨-dmorgan; ∨-dmorgan₁ ) open import Data.PropFormula.Theorems.Implication n using ( vanDalen244e; ⊃-equiv ) open import Data.PropFormula.Theorems.Weakening n open import Function using ( _$_ ; _∘_ ) ------------------------------------------------------------------------------ -- Theorem. e245b : ∀ {Γ Δ} {φ ψ} → Γ ⊢ φ → Δ , φ ⊢ ψ → Γ ⨆ Δ ⊢ ψ -- Proof. e245b {Γ}{Δ} Γ⊢φ Δ,φ⊢ψ = ⊃-elim (weaken-Δ₂ Γ $ ⊃-intro Δ,φ⊢ψ) (weaken-Δ₁ Δ Γ⊢φ) -------------------------------------------------------------------------- ∎ -- Theorem. ¬⊃-to-∧¬ : ∀ {Γ} {φ ψ} → Γ ⊢ ¬ (φ ⊃ ψ) → Γ ⊢ φ ∧ ¬ ψ -- Proof. ¬⊃-to-∧¬ {Γ}{φ}{ψ} Γ⊢¬⟪φ⊃ψ⟫ = ∧-intro (⊃-elim vanDalen244e (∧-proj₁ p2)) (∧-proj₂ p2) where p1 : Γ ⊢ ¬ (¬ φ ∨ ψ) p1 = ⇔-¬-to-¬ ⊃-⇔-¬∨ Γ⊢¬⟪φ⊃ψ⟫ p2 : Γ ⊢ ¬ (¬ φ) ∧ ¬ ψ p2 = ∨-dmorgan₁ p1 -------------------------------------------------------------------------- ∎ -- Theorem. ⊃¬∧¬⊃-to-¬⇔ : ∀ {Γ} {φ ψ} → Γ ⊢ (φ ⊃ ¬ ψ) ∧ (¬ ψ ⊃ φ) → Γ ⊢ ¬ (φ ⇔ ψ) -- Proof. ⊃¬∧¬⊃-to-¬⇔ {Γ}{φ}{ψ} thm = ¬-intro (¬-elim (¬-intro (¬-elim (⊃-elim (weaken ψ (weaken (φ ⇔ ψ) (∧-proj₁ thm))) (⇔-elim₂ (assume {Γ = Γ , φ ⇔ ψ} ψ) (weaken ψ (assume (φ ⇔ ψ))))) (assume {Γ = Γ , φ ⇔ ψ} ψ))) (RAA (¬-elim (¬-intro (¬-elim (⊃-elim (weaken φ (weaken (¬ ψ ) (weaken (φ ⇔ ψ) (∧-proj₁ thm)))) (assume {Γ = Γ , φ ⇔ ψ , ¬ ψ} φ)) (⇔-elim₁ (assume {Γ = Γ , φ ⇔ ψ , ¬ ψ} φ) (weaken φ (weaken (¬ ψ) (assume (φ ⇔ ψ))))))) (⊃-elim (weaken (¬ ψ) (weaken (φ ⇔ ψ) (∧-proj₂ thm))) (assume {Γ = Γ , φ ⇔ ψ} (¬ ψ)))))) -------------------------------------------------------------------------- ∎
27.244444
78
0.356852
43afe6e0f6fc243d68fb7e09c1171877385a56ca
3,522
agda
Agda
Cubical/Algebra/Group/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/Group/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/Group/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- This file contains basic theory about groups -} {-# OPTIONS --safe #-} module Cubical.Algebra.Group.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Foundations.GroupoidLaws hiding (assoc) open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Group.Base private variable ℓ : Level G : Type ℓ isPropIsGroup : (0g : G) (_+_ : G → G → G) (-_ : G → G) → isProp (IsGroup 0g _+_ -_) IsGroup.isMonoid (isPropIsGroup 0g _+_ -_ g1 g2 i) = isPropIsMonoid _ _ (IsGroup.isMonoid g1) (IsGroup.isMonoid g2) i IsGroup.inverse (isPropIsGroup 0g _+_ -_ g1 g2 i) = isPropInv (IsGroup.inverse g1) (IsGroup.inverse g2) i where isSetG : isSet _ isSetG = IsSemigroup.is-set (IsMonoid.isSemigroup (IsGroup.isMonoid g1)) isPropInv : isProp ((x : _) → ((x + (- x)) ≡ 0g) × (((- x) + x) ≡ 0g)) isPropInv = isPropΠ λ _ → isProp× (isSetG _ _) (isSetG _ _) module GroupTheory (G : Group ℓ) where open GroupStr (snd G) abstract ·CancelL : (a : ⟨ G ⟩) {b c : ⟨ G ⟩} → a · b ≡ a · c → b ≡ c ·CancelL a {b} {c} p = b ≡⟨ sym (lid b) ∙ cong (_· b) (sym (invl a)) ∙ sym (assoc _ _ _) ⟩ inv a · (a · b) ≡⟨ cong (inv a ·_) p ⟩ inv a · (a · c) ≡⟨ assoc _ _ _ ∙ cong (_· c) (invl a) ∙ lid c ⟩ c ∎ ·CancelR : {a b : ⟨ G ⟩} (c : ⟨ G ⟩) → a · c ≡ b · c → a ≡ b ·CancelR {a} {b} c p = a ≡⟨ sym (rid a) ∙ cong (a ·_) (sym (invr c)) ∙ assoc _ _ _ ⟩ (a · c) · inv c ≡⟨ cong (_· inv c) p ⟩ (b · c) · inv c ≡⟨ sym (assoc _ _ _) ∙ cong (b ·_) (invr c) ∙ rid b ⟩ b ∎ invInv : (a : ⟨ G ⟩) → inv (inv a) ≡ a invInv a = ·CancelL (inv a) (invr (inv a) ∙ sym (invl a)) inv1g : inv 1g ≡ 1g inv1g = ·CancelL 1g (invr 1g ∙ sym (lid 1g)) 1gUniqueL : {e : ⟨ G ⟩} (x : ⟨ G ⟩) → e · x ≡ x → e ≡ 1g 1gUniqueL {e} x p = ·CancelR x (p ∙ sym (lid _)) 1gUniqueR : (x : ⟨ G ⟩) {e : ⟨ G ⟩} → x · e ≡ x → e ≡ 1g 1gUniqueR x {e} p = ·CancelL x (p ∙ sym (rid _)) invUniqueL : {g h : ⟨ G ⟩} → g · h ≡ 1g → g ≡ inv h invUniqueL {g} {h} p = ·CancelR h (p ∙ sym (invl h)) invUniqueR : {g h : ⟨ G ⟩} → g · h ≡ 1g → h ≡ inv g invUniqueR {g} {h} p = ·CancelL g (p ∙ sym (invr g)) invDistr : (a b : ⟨ G ⟩) → inv (a · b) ≡ inv b · inv a invDistr a b = sym (invUniqueR γ) where γ : (a · b) · (inv b · inv a) ≡ 1g γ = (a · b) · (inv b · inv a) ≡⟨ sym (assoc _ _ _) ⟩ a · b · (inv b) · (inv a) ≡⟨ cong (a ·_) (assoc _ _ _ ∙ cong (_· (inv a)) (invr b)) ⟩ a · (1g · inv a) ≡⟨ cong (a ·_) (lid (inv a)) ∙ invr a ⟩ 1g ∎ congIdLeft≡congIdRight : (_·G_ : G → G → G) (-G_ : G → G) (0G : G) (rUnitG : (x : G) → x ·G 0G ≡ x) (lUnitG : (x : G) → 0G ·G x ≡ x) → (r≡l : rUnitG 0G ≡ lUnitG 0G) → (p : 0G ≡ 0G) → cong (0G ·G_) p ≡ cong (_·G 0G) p congIdLeft≡congIdRight _·G_ -G_ 0G rUnitG lUnitG r≡l p = rUnit (cong (0G ·G_) p) ∙∙ ((λ i → (λ j → lUnitG 0G (i ∧ j)) ∙∙ cong (λ x → lUnitG x i) p ∙∙ λ j → lUnitG 0G (i ∧ ~ j)) ∙∙ cong₂ (λ x y → x ∙∙ p ∙∙ y) (sym r≡l) (cong sym (sym r≡l)) ∙∙ λ i → (λ j → rUnitG 0G (~ i ∧ j)) ∙∙ cong (λ x → rUnitG x (~ i)) p ∙∙ λ j → rUnitG 0G (~ i ∧ ~ j)) ∙∙ sym (rUnit (cong (_·G 0G) p))
35.938776
110
0.494321
30fea146a6d6e5903ddecb82df959621a9086c13
17,849
agda
Agda
src/Generic/Lib/Reflection/Core.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
30
2016-07-19T21:10:54.000Z
2022-02-05T10:19:38.000Z
src/Generic/Lib/Reflection/Core.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
9
2017-04-06T18:58:09.000Z
2022-01-04T15:43:14.000Z
src/Generic/Lib/Reflection/Core.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
4
2017-07-17T07:23:39.000Z
2021-01-27T12:57:09.000Z
module Generic.Lib.Reflection.Core where open import Agda.Builtin.Reflection using (withNormalisation; Relevance; Visibility; clause) public open import Reflection renaming (visible to expl; hidden to impl; instance′ to inst; relevant to rel; irrelevant to irr; pi to absPi; lam to absLam; def to appDef) hiding (Arg-info; var; con; meta; visibility; relevance; _≟_; return; _>>=_; _>>_) public open import Reflection.Argument.Information using (ArgInfo; visibility; relevance) public import Reflection.Name open Term using () renaming (var to appVar; con to appCon; meta to appMeta) public open Pattern using () renaming (var to patVar; con to patCon) public open Literal using () renaming (meta to litMeta) public open Sort public open import Generic.Lib.Intro open import Generic.Lib.Equality.Propositional open import Generic.Lib.Decidable open import Generic.Lib.Category open import Generic.Lib.Data.Nat open import Generic.Lib.Data.String open import Generic.Lib.Data.Maybe open import Generic.Lib.Data.Product open import Generic.Lib.Data.List open import Data.Vec using (toList) open import Data.Vec.N-ary using (N-ary; curryⁿ) infixr 5 _‵→_ infixl 3 _·_ listCurryⁿ : ∀ {α β} {A : Set α} {B : Set β} n -> (List A -> B) -> N-ary n A B listCurryⁿ n f = curryⁿ {n = n} (f ∘ toList) named : String -> String named s = if s == "_" then "x" else s record Reify {α} (A : Set α) : Set α where field reify : A -> Term macro reflect : A -> Term -> TC _ reflect = unify ∘ reify open Reify {{...}} public pattern pureVar n = appVar n [] pattern pureCon c = appCon c [] pattern pureDef f = appDef f [] pattern pureMeta m = appMeta m [] {-# DISPLAY appVar i [] = pureVar i #-} {-# DISPLAY appCon c [] = pureCon c #-} {-# DISPLAY appDef f [] = pureDef f #-} {-# DISPLAY appMeta m [] = pureMeta m #-} pattern explInfo r = arg-info expl r pattern implInfo r = arg-info impl r pattern instInfo r = arg-info inst r {-# DISPLAY arg-info expl r = explInfo r #-} {-# DISPLAY arg-info impl r = implInfo r #-} {-# DISPLAY arg-info inst r = instInfo r #-} pattern explRelInfo = explInfo rel pattern explIrrInfo = explInfo irr pattern implRelInfo = implInfo rel pattern implIrrInfo = implInfo irr pattern instRelInfo = instInfo rel pattern instIrrInfo = instInfo irr {-# DISPLAY explInfo rel = explRelInfo #-} {-# DISPLAY explInfo irr = explIrrInfo #-} {-# DISPLAY implInfo rel = implRelInfo #-} {-# DISPLAY implInfo irr = implIrrInfo #-} {-# DISPLAY instInfo rel = instRelInfo #-} {-# DISPLAY instInfo irr = instIrrInfo #-} pattern explArg r x = arg (explInfo r) x pattern implArg r x = arg (implInfo r) x pattern instArg r x = arg (instInfo r) x {-# DISPLAY arg (explInfo r) = explArg r #-} {-# DISPLAY arg (implInfo r) = implArg r #-} {-# DISPLAY arg (instInfo r) = instArg r #-} pattern explRelArg x = explArg rel x pattern implRelArg x = implArg rel x pattern instRelArg x = instArg rel x {-# DISPLAY explArg rel x = explRelArg x #-} {-# DISPLAY implArg rel x = implRelArg x #-} {-# DISPLAY instArg rel x = instRelArg x #-} pattern pi s a b = absPi a (abs s b) {-# DISPLAY absPi a (abs s b) = pi s a b #-} pattern explPi r s a b = pi s (explArg r a) b pattern implPi r s a b = pi s (implArg r a) b pattern instPi r s a b = pi s (instArg r a) b {-# DISPLAY pi (explArg r a) s b = explPi r s a b #-} {-# DISPLAY pi (implArg r a) s b = implPi r s a b #-} {-# DISPLAY pi (instArg r a) s b = instPi r s a b #-} pattern explRelPi s a b = explPi rel a s b pattern explIrrPi s a b = explPi irr a s b pattern implRelPi s a b = implPi rel a s b pattern implIrrPi s a b = implPi irr a s b pattern instRelPi s a b = instPi rel a s b pattern instIrrPi s a b = instPi irr a s b {-# DISPLAY explPi rel a s b = explRelPi s a b #-} {-# DISPLAY explPi irr a s b = explIrrPi s a b #-} {-# DISPLAY implPi rel a s b = implRelPi s a b #-} {-# DISPLAY implPi irr a s b = implIrrPi s a b #-} {-# DISPLAY instPi rel a s b = instRelPi s a b #-} {-# DISPLAY instPi irr a s b = instIrrPi s a b #-} pattern lam v s t = absLam v (abs s t) {-# DISPLAY absLam v (abs s t) = lam v s t #-} pattern explLam s t = lam expl s t pattern implLam s t = lam impl s t pattern instLam s t = lam inst s t {-# DISPLAY lam expl s t = explLam s t #-} {-# DISPLAY lam impl s t = implLam s t #-} {-# DISPLAY lam inst s t = instLam s t #-} pattern _‵→_ a b = pi "_" (explRelArg a) b -- No longer parses for whatever reason. -- {-# DISPLAY pi "_" (explRelArg a) b = a ‵→ b #-} mutual <_>_ : ∀ {α} -> Relevance -> Set α -> Set α <_>_ = flip RelValue data RelValue {α} (A : Set α) : Relevance -> Set α where relv : A -> < rel > A irrv : .A -> < irr > A elimRelValue : ∀ {r α π} {A : Set α} -> (P : ∀ {r} -> < r > A -> Set π) -> (∀ x -> P (relv x)) -> (∀ .x -> P (irrv x)) -> (x : < r > A) -> P x elimRelValue P f g (relv x) = f x elimRelValue P f g (irrv x) = g x unrelv : ∀ {α} {A : Set α} -> < rel > A -> A unrelv (relv x) = x -- Is it possible to handle this in some other way that doesn't require a postulate? -- See the `appRel` function below. Or is the postulate fine? postulate .unirrv : ∀ {α} {A : Set α} -> < irr > A -> A <_>_~>_ : ∀ {α β} -> Relevance -> Set α -> Set β -> Set (α ⊔ β) < rel > A ~> B = A -> B < irr > A ~> B = .A -> B lamRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A -> B) -> < r > A ~> B lamRel {rel} f = λ x -> f (relv x) lamRel {irr} f = λ x -> f (irrv x) -- The laziness is intentional. appRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A ~> B) -> < r > A -> B appRel {rel} f rx = f (unrelv rx) appRel {irr} f rx = f (unirrv rx) Pi : ∀ {α β} i -> (A : Set α) -> (< relevance i > A -> Set β) -> Set (α ⊔ β) Pi explRelInfo A B = (x : A) -> B (relv x) Pi explIrrInfo A B = . (x : A) -> B (irrv x) Pi implRelInfo A B = {x : A} -> B (relv x) Pi implIrrInfo A B = . {x : A} -> B (irrv x) Pi instRelInfo A B = {{x : A}} -> B (relv x) Pi instIrrInfo A B = .{{x : A}} -> B (irrv x) lamPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> (∀ x -> B x) -> Pi i A B lamPi explRelInfo f = λ x -> f (relv x) lamPi explIrrInfo f = λ x -> f (irrv x) lamPi implRelInfo f = f _ lamPi implIrrInfo f = f _ lamPi instRelInfo f = f _ lamPi instIrrInfo f = f _ appPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> Pi i A B -> ∀ x -> B x appPi explRelInfo f (relv x) = f x appPi explIrrInfo f (irrv x) = f x appPi implRelInfo y (relv x) = y appPi implIrrInfo y (irrv x) = y appPi instRelInfo y (relv x) = y {{x}} appPi instIrrInfo y (irrv x) = y {{x}} RelEq : ∀ {α} -> Relevance -> Set α -> Set α RelEq rel A = Eq A RelEq irr A = ⊤ vis : {A : Set} -> (A -> List (Arg Term) -> Term) -> A -> List Term -> Term vis k x = k x ∘ map explRelArg vis# : ∀ {A : Set} n -> (A -> List (Arg Term) -> Term) -> A -> N-ary n Term Term vis# n k = listCurryⁿ n ∘ vis k isRelevant : Relevance -> Bool isRelevant rel = true isRelevant irr = false argInfo : ∀ {α} {A : Set α} -> Arg A -> _ argInfo (arg i x) = i argVal : ∀ {α} {A : Set α} -> Arg A -> A argVal (arg i x) = x unExpl : ∀ {α} {A : Set α} -> Arg A -> Maybe A unExpl (explArg r x) = just x unExpl _ = nothing absName : ∀ {α} {A : Set α} -> Abs A -> String absName (abs s x) = s absVal : ∀ {α} {A : Set α} -> Abs A -> A absVal (abs s x) = x patVars : List String -> List (Arg Pattern) patVars = map (explRelArg ∘ patVar ∘ named) record Data {α} (A : Set α) : Set α where no-eta-equality constructor packData field dataName : Name parsTele : Type indsTele : Type consTypes : List A consNames : All (const Name) consTypes open Data public instance NameEq : Eq Name NameEq = viaBase Reflection.Name._≟_ EqRelValue : ∀ {α r} {A : Set α} {{aEq : RelEq r A}} -> Eq (< r > A) EqRelValue {A = A} {{aEq}} = record { _≟_ = go } where relv-inj : {x y : A} -> relv x ≡ relv y -> x ≡ y relv-inj refl = refl go : ∀ {r} {{aEq : RelEq r A}} -> IsSet (< r > A) go (relv x) (relv y) = dcong relv relv-inj (x ≟ y) go (irrv x) (irrv y) = yes refl ArgFunctor : ∀ {α} -> RawFunctor {α} Arg ArgFunctor = record { _<$>_ = λ{ f (arg i x) -> arg i (f x) } } AbsFunctor : ∀ {α} -> RawFunctor {α} Abs AbsFunctor = record { _<$>_ = λ{ f (abs s x) -> abs s (f x) } } TCMonad : ∀ {α} -> RawMonad {α} TC TCMonad = record { return = Reflection.return ; _>>=_ = Reflection._>>=_ } TCApplicative : ∀ {α} -> RawApplicative {α} TC TCApplicative = rawIApplicative TCFunctor : ∀ {α} -> RawFunctor {α} TC TCFunctor = rawFunctor keep : (ℕ -> ℕ) -> ℕ -> ℕ keep ι 0 = 0 keep ι (suc n) = suc (ι n) {-# TERMINATING #-} mutual ren : (ℕ -> ℕ) -> Term -> Term ren ι (appVar v xs) = appVar (ι v) (rens ι xs) ren ι (appCon c xs) = appCon c (rens ι xs) ren ι (appDef f xs) = appDef f (rens ι xs) ren ι (lam v s t) = lam v s (ren (keep ι) t) ren ι (pat-lam cs xs) = undefined where postulate undefined : _ ren ι (pi s a b) = pi s (ren ι <$> a) (ren (keep ι) b) ren ι (agda-sort s) = agda-sort (renSort ι s) ren ι (lit l) = lit l ren ι (appMeta x xs) = appMeta x (rens ι xs) ren ι unknown = unknown rens : (ℕ -> ℕ) -> List (Arg Term) -> List (Arg Term) rens ι = map (fmap (ren ι)) renSort : (ℕ -> ℕ) -> Sort -> Sort renSort ι (set t) = set (ren ι t) renSort ι (lit n) = lit n renSort ι unknown = unknown shiftBy : ℕ -> Term -> Term shiftBy = ren ∘ _+_ shift : Term -> Term shift = shiftBy 1 unshiftBy : ℕ -> Term -> Term unshiftBy n = ren (_∸ n) isSomeName : Name -> Term -> Bool isSomeName n (appDef m _) = n == m isSomeName n (appCon m _) = n == m isSomeName n t = false {-# TERMINATING #-} mutual mapName : (ℕ -> List (Arg Term) -> Term) -> Name -> Term -> Term mapName f n (appVar v xs) = appVar v (mapNames f n xs) mapName f n (appCon m xs) = (if n == m then f 0 else appCon m) (mapNames f n xs) mapName f n (appDef m xs) = (if n == m then f 0 else appDef m) (mapNames f n xs) mapName f n (lam v s t) = lam v s (mapName (f ∘ suc) n t) mapName f n (pat-lam cs xs) = undefined where postulate undefined : _ mapName f n (pi s a b) = pi s (mapName f n <$> a) (mapName (f ∘ suc) n b) mapName f n (agda-sort s) = agda-sort (mapNameSort f n s) mapName f n (lit l) = lit l mapName f n (appMeta x xs) = appMeta x (mapNames f n xs) mapName f n unknown = unknown mapNames : (ℕ -> List (Arg Term) -> Term) -> Name -> List (Arg Term) -> List (Arg Term) mapNames f n = map (fmap (mapName f n)) mapNameSort : (ℕ -> List (Arg Term) -> Term) -> Name -> Sort -> Sort mapNameSort f n (set t) = set (mapName f n t) mapNameSort f n (lit l) = lit l mapNameSort f n unknown = unknown explsOnly : List (Arg Term) -> List Term explsOnly = mapMaybe unExpl initType : Type -> Type initType (pi s a b) = pi s a (initType b) initType b = unknown lastType : Type -> Type lastType (pi s a b) = lastType b lastType b = b -- These two should return just `Type` like everything else. takePis : ℕ -> Type -> Maybe Type takePis 0 a = just unknown takePis (suc n) (pi s a b) = pi s a <$> takePis n b takePis _ _ = nothing dropPis : ℕ -> Type -> Maybe Type dropPis 0 a = just a dropPis (suc n) (pi s a b) = dropPis n b dropPis _ _ = nothing monoLastType : Type -> Type monoLastType = go 0 where go : ℕ -> Type -> Type go n (pi s a b) = go (suc n) b go n b = unshiftBy n b appendType : Type -> Type -> Type appendType (pi s a b) c = pi s a (appendType b c) appendType b c = c explLamsBy : Type -> Term -> Term explLamsBy (explPi r s a b) t = explLam s (explLamsBy b t) explLamsBy (pi s a b) t = explLamsBy b t explLamsBy b t = t implicitize : Type -> Type implicitize (explPi r s a b) = implPi r s a (implicitize b) implicitize (pi s a b) = pi s a (implicitize b) implicitize b = b leadImpls : Type -> List (Abs Term) leadImpls (implPi r s a b) = abs s a ∷ leadImpls b leadImpls b = [] pisToAbsArgTypes : Type -> List (Abs (Arg Type)) pisToAbsArgTypes (pi s a b) = abs s a ∷ pisToAbsArgTypes b pisToAbsArgTypes b = [] explPisToAbsTypes : Type -> List (Abs Type) explPisToAbsTypes (explPi r s a b) = abs s a ∷ explPisToAbsTypes b explPisToAbsTypes (pi s a b) = explPisToAbsTypes b explPisToAbsTypes b = [] explPisToNames : Type -> List String explPisToNames = map absName ∘ explPisToAbsTypes countPis : Type -> ℕ countPis = length ∘ pisToAbsArgTypes countExplPis : Type -> ℕ countExplPis = length ∘ explPisToAbsTypes pisToAbsArgVars : ℕ -> Type -> List (Abs (Arg Term)) pisToAbsArgVars (suc n) (pi s (arg i a) b) = abs s (arg i (pureVar n)) ∷ pisToAbsArgVars n b pisToAbsArgVars n b = [] pisToArgVars : ℕ -> Type -> List (Arg Term) pisToArgVars = map absVal % ∘ pisToAbsArgVars explPisToAbsVars : ℕ -> Type -> List (Abs Term) explPisToAbsVars (suc n) (explPi r s a b) = abs s (pureVar n) ∷ explPisToAbsVars n b explPisToAbsVars (suc n) (pi s a b) = explPisToAbsVars n b explPisToAbsVars n b = [] throw : ∀ {α} {A : Set α} -> String -> TC A throw s = typeError (strErr s ∷ []) panic : ∀ {α} {A : Set α} -> String -> TC A panic s = throw $ "panic: " ++ˢ s -- I'll merge these later. macro sate : Name -> Term -> TC _ sate f ?r = getType f >>= λ a -> let res = λ app -> quoteTC (vis# (countExplPis a) app f) >>= unify ?r in getDefinition f >>= λ { (data-cons _) -> res appCon ; _ -> res appDef } sateMacro : Name -> Term -> TC _ sateMacro f ?r = getType f >>= λ a -> quoteTC (vis# (pred (countExplPis a)) appDef f) >>= unify ?r _·_ : Term -> Term -> Term _·_ = sate _$_ unshift′ : Term -> Term unshift′ t = explLam "_" t · sate tt₀ -- A note for myself: `foldℕ (sate lsuc) (sate lzero) n` is not `reify n`: -- it's damn `lsuc` -- not `suc`. termLevelOf : Term -> Maybe Term termLevelOf (agda-sort (set t)) = just t termLevelOf (agda-sort (lit n)) = just (foldℕ (sate lsuc) (sate lzero) n) termLevelOf (agda-sort unknown) = just unknown termLevelOf _ = nothing instance TermReify : Reify Term TermReify = record { reify = id } NameReify : Reify Name NameReify = record { reify = lit ∘′ name } VisibilityReify : Reify Visibility VisibilityReify = record { reify = λ { expl -> sate expl ; impl -> sate impl ; inst -> sate inst } } RelevanceReify : Reify Relevance RelevanceReify = record { reify = λ { rel -> sate rel ; irr -> sate irr } } ArgInfoReify : Reify ArgInfo ArgInfoReify = record { reify = λ{ (arg-info v r) -> sate arg-info (reify v) (reify r) } } ProdReify : ∀ {α β} {A : Set α} {B : A -> Set β} {{aReify : Reify A}} {{bReify : ∀ {x} -> Reify (B x)}} -> Reify (Σ A B) ProdReify = record { reify = uncurry λ x y -> sate _,_ (reify x) (reify y) } ℕReify : Reify ℕ ℕReify = record { reify = foldℕ (sate suc) (sate zero) } ListReify : ∀ {α} {A : Set α} {{aReify : Reify A}} -> Reify (List A) ListReify = record { reify = foldr (sate _∷_ ∘ reify) (sate []) } AllReify : ∀ {α β} {A : Set α} {B : A -> Set β} {xs} {{bReify : ∀ {x} -> Reify (B x)}} -> Reify (All B xs) AllReify {B = B} {{bReify}} = record { reify = go _ } where go : ∀ xs -> All B xs -> Term go [] tt = sate tt₀ go (x ∷ xs) (y , ys) = sate _,_ (reify {{bReify}} y) (go xs ys) toTuple : List Term -> Term toTuple = foldr₁ (sate _,_) (sate tt₀) curryBy : Type -> Term -> Term curryBy = go 0 where go : ℕ -> Type -> Term -> Term go n (pi s (arg (arg-info v r) a) b) t = lam v s $ go (suc n) b t go n _ t = shiftBy n t · toTuple (map pureVar (downFrom n)) explUncurryBy : Type -> Term -> Term explUncurryBy a f = explLam "x" $ appDef (quote id) (explArg rel (shift f) ∷ go a (pureVar 0)) where go : Term -> Term -> List (Arg Term) go (explPi r s a b@(pi _ _ _)) p = explArg r (sate proj₁ p) ∷ go b (sate proj₂ p) go (pi s a b@(pi _ _ _)) p = go b (sate proj₂ p) go (explPi r s a b) x = explArg r x ∷ [] go _ t = [] defineTerm : Name -> Term -> TC _ defineTerm n t = getType n >>= λ a -> defineFun n (clause (map (implRelArg ∘ patVar ∘ named ∘ absName) (leadImpls a)) t ∷ []) -- Able to normalize a Setω. normalize : Term -> TC Term normalize (pi s (arg i a) b) = pi s ∘ arg i <$> normalize a <*> extendContext (arg i a) (normalize b) normalize t = normalise t getNormType : Name -> TC Type getNormType = getType >=> normalize inferNormType : Term -> TC Type inferNormType = inferType >=> normalize getData : Name -> TC (Data Type) getData d = getNormType d >>= λ ab -> getDefinition d >>= λ { (data-type p cs) -> mapM (λ c -> _,_ c ∘ dropPis p <$> getNormType c) cs >>= λ mans -> case takePis p ab ⊗ (dropPis p ab ⊗ (mapM (uncurry λ c ma -> flip _,_ c <$> ma) mans)) of λ { nothing -> panic "getData: data" ; (just (a , b , acs)) -> return ∘ uncurry (packData d a b) $ splitList acs } ; (record-type c _) -> getNormType c >>= dropPis (countPis ab) >>> λ { nothing -> panic "getData: record" ; (just a′) -> return $ packData d (initType ab) (lastType ab) (a′ ∷ []) (c , tt) } ; _ -> throw "not a data" } macro TypeOf : Term -> Term -> TC _ TypeOf t ?r = inferNormType t >>= unify ?r runTC : ∀ {α} {A : Set α} -> TC A -> Term -> TC _ runTC a ?r = bindTC a quoteTC >>= unify ?r
31.535336
100
0.58345
0d5dbffadfdb04a496f586936efa74b9cc8259f2
622
agda
Agda
test/Succeed/Issue2606.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2606.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2606.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- 2017-06-16, reported by Ambrus Kaposi on the Agda mailing list -- WAS: -- β is not a legal rewrite rule, since the left-hand side -- f a reduces to f a -- when checking the pragma REWRITE β -- SHOULD: succeed {-# OPTIONS --rewriting --confluence-check #-} module _ where module a where postulate _~_ : {A : Set} → A → A → Set {-# BUILTIN REWRITE _~_ #-} module m1 (X : Set) where postulate A B : Set a : A b : B f : A → B module m2 (X : Set) where open m1 X postulate β : f a ~ b {-# REWRITE β #-} postulate refl : {A : Set}{a : A} → a ~ a p : f a ~ b p = refl
14.465116
65
0.57074
14df2b2f099cc1a4ffc4d57f4cb590d8fd2d896e
1,211
agda
Agda
test/Succeed/SolveConstraints.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Succeed/SolveConstraints.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/SolveConstraints.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2021-04-01T18:30:09.000Z
2021-04-01T18:30:09.000Z
module _ where open import Agda.Builtin.Bool open import Agda.Builtin.List open import Agda.Builtin.Reflection open import Agda.Builtin.Unit record R : Set₁ where field _≡_ : {A : Set} → A → A → Set refl : {A : Set} (x : A) → x ≡ x record R′ (_ : Set) : Set where module _ (r : R) (_ : {A : Set} → R′ A) where open R r macro m : Term → TC ⊤ m goal = bindTC (unify (def (quote refl) (arg (arg-info visible relevant) unknown ∷ [])) goal) λ _ → bindTC solveConstraints λ _ → bindTC (reduce goal) λ where (meta m _) → typeError (strErr "Meta" ∷ []) _ → returnTC _ test : true ≡ true test = m macro m′ : Term → TC ⊤ m′ goal = bindTC (unify (def (quote refl) (arg (arg-info visible relevant) unknown ∷ [])) goal) λ _ → bindTC (reduce goal) λ where goal@(meta m _) → bindTC (solveConstraintsMentioning (m ∷ [])) λ _ → bindTC (reduce goal) λ where (meta _ _) → typeError (strErr "Meta" ∷ []) _ → returnTC _ _ → returnTC _ test′ : true ≡ true test′ = m′
23.745098
72
0.506193
4e4ced04cc5aa491099b5fd5327a89bd76b5bc56
3,071
agda
Agda
Cats/Category/Arrow.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
24
2017-11-03T15:18:57.000Z
2021-08-06T05:00:46.000Z
Cats/Category/Arrow.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
null
null
null
Cats/Category/Arrow.agda
JLimperg/cats
1ad7b243acb622d46731e9ae7029408db6e561f1
[ "MIT" ]
1
2019-03-18T15:35:07.000Z
2019-03-18T15:35:07.000Z
{-# OPTIONS --without-K --safe #-} module Cats.Category.Arrow where open import Level open import Relation.Binary using (IsEquivalence ; _Preserves₂_⟶_⟶_) open import Cats.Category module _ {lo la l≈} (C : Category lo la l≈) where infixr 9 _∘_ infixr 4 _≈_ private module C = Category C module ≈ = C.≈ record Obj : Set (lo ⊔ la) where field Dom : C.Obj Cod : C.Obj arr : Dom C.⇒ Cod open Obj record _⇒_ (f g : Obj) : Set (la ⊔ l≈) where field dom : Dom f C.⇒ Dom g cod : Cod f C.⇒ Cod g commute : arr g C.∘ dom C.≈ cod C.∘ arr f open _⇒_ record _≈_ {A B} (F G : A ⇒ B) : Set l≈ where field dom : dom F C.≈ dom G cod : cod F C.≈ cod G id : ∀ {A} → A ⇒ A id {record { Dom = Dom ; Cod = Cod ; arr = arr }} = record { dom = C.id ; cod = C.id ; commute = ≈.trans C.id-r (≈.sym C.id-l) } _∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C) _∘_ {F} {G} {H} record { dom = F-dom ; cod = F-cod ; commute = F-commute } record { dom = G-dom ; cod = G-cod ; commute = G-commute } = record { dom = F-dom C.∘ G-dom ; cod = F-cod C.∘ G-cod ; commute = begin arr H C.∘ F-dom C.∘ G-dom ≈⟨ C.unassoc ⟩ (arr H C.∘ F-dom) C.∘ G-dom ≈⟨ C.∘-resp-l F-commute ⟩ (F-cod C.∘ arr G) C.∘ G-dom ≈⟨ C.assoc ⟩ F-cod C.∘ arr G C.∘ G-dom ≈⟨ C.∘-resp-r G-commute ⟩ F-cod C.∘ G-cod C.∘ arr F ≈⟨ C.unassoc ⟩ (F-cod C.∘ G-cod) C.∘ arr F ∎ } where open C.≈-Reasoning equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B}) equiv = record { refl = record { dom = ≈.refl ; cod = ≈.refl } ; sym = λ where record { dom = dom ; cod = cod } → record { dom = ≈.sym dom ; cod = ≈.sym cod } ; trans = λ where record { dom = dom₁ ; cod = cod₁ } record { dom = dom₂ ; cod = cod₂ } → record { dom = ≈.trans dom₁ dom₂ ; cod = ≈.trans cod₁ cod₂ } } ∘-resp : ∀ {A B C} → (_∘_ {A} {B} {C}) Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_ ∘-resp record { dom = dom-FG ; cod = cod-FG } record { dom = dom-HI ; cod = cod-HI } = record { dom = C.∘-resp dom-FG dom-HI ; cod = C.∘-resp cod-FG cod-HI } id-r : ∀ {A B} {F : A ⇒ B} → F ∘ id ≈ F id-r = record { dom = C.id-r ; cod = C.id-r } id-l : ∀ {A B} {F : A ⇒ B} → id ∘ F ≈ F id-l = record { dom = C.id-l ; cod = C.id-l } assoc : ∀ {A B C D} {F : C ⇒ D} {G : B ⇒ C} {H : A ⇒ B} → (F ∘ G) ∘ H ≈ F ∘ (G ∘ H) assoc = record { dom = C.assoc ; cod = C.assoc } _⃗ : Category (la ⊔ lo) (l≈ ⊔ la) l≈ _⃗ = record { Obj = Obj ; _⇒_ = _⇒_ ; _≈_ = _≈_ ; id = id ; _∘_ = _∘_ ; equiv = equiv ; ∘-resp = ∘-resp ; id-r = id-r ; id-l = id-l ; assoc = assoc }
21.780142
79
0.420059
52975067253129e7853ba5c0b677fabfef4cf0e2
7,751
agda
Agda
src/Categories/Yoneda.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Yoneda.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Yoneda.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Yoneda where -- Yoneda Lemma. In total, provides: -- * the Yoneda Embedding (called embed here) from any Category C into Presheaves C -- Worth noticing that there is no 'locally small' condition here; however, if one looks at -- the levels involved, there is indeed a raise from that of C to that of Presheaves C. -- * The traditional Yoneda lemma (yoneda-inverse) which says that for any object a of C, and -- any Presheaf F over C (where our presheaves are over Setoids), then -- Hom[ Presheaves C] (Functor.F₀ embed a , F) ≅ Functor.F₀ F a -- as Setoids. In addition, Yoneda (yoneda) also says that this isomorphism is natural in a and F. open import Level open import Function.Base using (_$_) open import Function.Bundles using (Inverse) open import Function.Equality using (Π; _⟨$⟩_; cong) open import Relation.Binary.Bundles using (module Setoid) import Relation.Binary.Reasoning.Setoid as SetoidR open import Data.Product using (_,_; Σ) open import Categories.Category using (Category; _[_,_]) open import Categories.Category.Product using (πʳ; πˡ; _※_) open import Categories.Category.Construction.Presheaves using (Presheaves) open import Categories.Category.Construction.Functors using (eval) open import Categories.Category.Instance.Setoids using (Setoids) open import Categories.Functor using (Functor; _∘F_) renaming (id to idF) open import Categories.Functor.Hom using (module Hom; Hom[_][-,_]; Hom[_][-,-]) open import Categories.Functor.Bifunctor using (Bifunctor) open import Categories.Functor.Presheaf using (Presheaf) open import Categories.Functor.Construction.LiftSetoids using (LiftSetoids) open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN) open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism) import Categories.Morphism as Mor import Categories.Morphism.Reasoning as MR import Categories.NaturalTransformation.Hom as NT-Hom private variable o ℓ e : Level module Yoneda (C : Category o ℓ e) where open Category C hiding (op) -- uses lots open HomReasoning using (_○_; ⟺) open MR C using (id-comm) open NaturalTransformation using (η; commute) open NT-Hom C using (Hom[A,C]⇒Hom[B,C]) private module CE = Category.Equiv C using (refl) module C = Category C using (op) -- The Yoneda embedding functor embed : Functor C (Presheaves C) embed = record { F₀ = Hom[ C ][-,_] ; F₁ = Hom[A,C]⇒Hom[B,C] -- A⇒B induces a NatTrans on the Homs. ; identity = identityˡ ○_ ; homomorphism = λ h₁≈h₂ → ∘-resp-≈ʳ h₁≈h₂ ○ assoc ; F-resp-≈ = λ f≈g h≈i → ∘-resp-≈ f≈g h≈i } -- Using the adjunction between product and product, we get a kind of contravariant Bifunctor yoneda-inverse : (a : Obj) (F : Presheaf C (Setoids ℓ e)) → Inverse (Category.hom-setoid (Presheaves C) {Functor.F₀ embed a} {F}) (Functor.F₀ F a) yoneda-inverse a F = record { f = λ nat → η nat a ⟨$⟩ id ; f⁻¹ = λ x → ntHelper record { η = λ X → record { _⟨$⟩_ = λ X⇒a → F.₁ X⇒a ⟨$⟩ x ; cong = λ i≈j → F.F-resp-≈ i≈j SE.refl } ; commute = λ {X} {Y} Y⇒X {f} {g} f≈g → let module SR = SetoidR (F.₀ Y) in SR.begin F.₁ (id ∘ f ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ F.F-resp-≈ (identityˡ ○ ∘-resp-≈ˡ f≈g) (SE.refl {x}) ⟩ F.₁ (g ∘ Y⇒X) ⟨$⟩ x SR.≈⟨ F.homomorphism SE.refl ⟩ F.₁ Y⇒X ⟨$⟩ (F.₁ g ⟨$⟩ x) SR.∎ } ; cong₁ = λ i≈j → i≈j CE.refl ; cong₂ = λ i≈j y≈z → F.F-resp-≈ y≈z i≈j ; inverse = (λ Fa → F.identity SE.refl) , λ nat {x} {z} z≈y → let module S = Setoid (F.₀ x) in S.trans (S.sym (commute nat z CE.refl)) (cong (η nat x) (identityˡ ○ identityˡ ○ z≈y)) } where module F = Functor F using (₀; ₁; F-resp-≈; homomorphism; identity) module SE = Setoid (F.₀ a) using (refl) private -- in this bifunctor, a presheaf from Presheaves C goes from C to Setoids ℓ e, -- but the over Setoids has higher level than the hom setoids. Nat[Hom[C][-,c],F] : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _) Nat[Hom[C][-,c],F] = Hom[ Presheaves C ][-,-] ∘F (Functor.op embed ∘F πʳ ※ πˡ) -- in this bifunctor, it needs to go from Presheaves which maps C to Setoids ℓ e, -- so the universe level needs to be lifted. FC : Bifunctor (Presheaves C) (Category.op C) (Setoids _ _) FC = LiftSetoids (o ⊔ ℓ ⊔ e) (o ⊔ ℓ) ∘F eval {C = Category.op C} {D = Setoids ℓ e} module yoneda-inverse {a} {F} = Inverse (yoneda-inverse a F) -- the two bifunctors above are naturally isomorphic. -- it is easy to show yoneda-inverse first then to yoneda. yoneda : NaturalIsomorphism Nat[Hom[C][-,c],F] FC yoneda = record { F⇒G = ntHelper record { η = λ where (F , A) → record { _⟨$⟩_ = λ α → lift (yoneda-inverse.f α) ; cong = λ i≈j → lift (i≈j CE.refl) } ; commute = λ where {_} {G , B} (α , f) {β} {γ} β≈γ → lift $ cong (η α B) (helper f β γ β≈γ) } ; F⇐G = ntHelper record { η = λ (F , A) → record { _⟨$⟩_ = λ x → yoneda-inverse.f⁻¹ (lower x) ; cong = λ i≈j y≈z → Functor.F-resp-≈ F y≈z (lower i≈j) } ; commute = λ (α , f) eq eq′ → helper′ α f (lower eq) eq′ } ; iso = λ (F , A) → record { isoˡ = λ {α β} i≈j {X} y≈z → Setoid.trans (Functor.F₀ F X) ( yoneda-inverse.inverseʳ α {x = X} y≈z) (i≈j CE.refl) ; isoʳ = λ eq → lift (Setoid.trans (Functor.F₀ F A) ( yoneda-inverse.inverseˡ {F = F} _) (lower eq)) } } where helper : {F : Functor C.op (Setoids ℓ e)} {A B : Obj} (f : B ⇒ A) (β γ : NaturalTransformation Hom[ C ][-, A ] F) → Setoid._≈_ (Functor.F₀ Nat[Hom[C][-,c],F] (F , A)) β γ → Setoid._≈_ (Functor.F₀ F B) (η β B ⟨$⟩ f ∘ id) (Functor.F₁ F f ⟨$⟩ (η γ A ⟨$⟩ id)) helper {F} {A} {B} f β γ β≈γ = S.begin η β B ⟨$⟩ f ∘ id S.≈⟨ cong (η β B) (id-comm ○ (⟺ identityˡ)) ⟩ η β B ⟨$⟩ id ∘ id ∘ f S.≈⟨ commute β f CE.refl ⟩ F.₁ f ⟨$⟩ (η β A ⟨$⟩ id) S.≈⟨ cong (F.₁ f) (β≈γ CE.refl) ⟩ F.₁ f ⟨$⟩ (η γ A ⟨$⟩ id) S.∎ where module F = Functor F using (₀;₁) module S = SetoidR (F.₀ B) helper′ : ∀ {F G : Functor (Category.op C) (Setoids ℓ e)} {A B Z : Obj} {h i : Z ⇒ B} {X Y : Setoid.Carrier (Functor.F₀ F A)} (α : NaturalTransformation F G) (f : B ⇒ A) → Setoid._≈_ (Functor.F₀ F A) X Y → h ≈ i → Setoid._≈_ (Functor.F₀ G Z) (Functor.F₁ G h ⟨$⟩ (η α B ⟨$⟩ (Functor.F₁ F f ⟨$⟩ X))) (η α Z ⟨$⟩ (Functor.F₁ F (f ∘ i) ⟨$⟩ Y)) helper′ {F} {G} {A} {B} {Z} {h} {i} {X} {Y} α f eq eq′ = S.begin G.₁ h ⟨$⟩ (η α B ⟨$⟩ (F.₁ f ⟨$⟩ X)) S.≈˘⟨ commute α h (S′.sym (cong (F.₁ f) eq)) ⟩ η α Z ⟨$⟩ (F.₁ h ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈⟨ cong (η α Z) (F.F-resp-≈ eq′ S′.refl) ⟩ η α Z ⟨$⟩ (F.₁ i ⟨$⟩ (F.₁ f ⟨$⟩ Y)) S.≈˘⟨ cong (η α Z) (F.homomorphism (Setoid.refl (F.₀ A))) ⟩ η α Z ⟨$⟩ (F.₁ (f ∘ i) ⟨$⟩ Y) S.∎ where module F = Functor F using (₀; ₁; homomorphism; F-resp-≈) module G = Functor G using (₀; ₁) module S = SetoidR (G.₀ Z) module S′ = Setoid (F.₀ B) using (refl; sym) module yoneda = NaturalIsomorphism yoneda
46.975758
108
0.555541
437410a9de72894de6267d0a268e473c33df4407
115
agda
Agda
test/Fail/Issue3207.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue3207.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue3207.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2018-09-03, issue #3207 -- -- Error message for disabled Prop. {-# OPTIONS --no-prop #-} test = Prop
14.375
35
0.626087
3784129bb6eda5bde67c6cbb3fdf7ddf71af0133
4,878
agda
Agda
Cubical/Algebra/AbGroup/Instances/Hom.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/AbGroup/Instances/Hom.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/AbGroup/Instances/Hom.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
-- Given two abelian groups A, B -- the set of all group homomorphisms from A to B -- is itself an abelian group. -- In other words, Ab is cartesian closed. -- This is needed to show Ab is an abelian category. {-# OPTIONS --safe #-} module Cubical.Algebra.AbGroup.Instances.Hom where open import Cubical.Algebra.AbGroup.Base open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Properties open import Cubical.Foundations.Prelude private variable ℓ ℓ' : Level module _ (A : AbGroup ℓ) (B : AbGroup ℓ') where -- These names are useful for the proofs private open IsGroupHom open AbGroupStr (A .snd) using () renaming (0g to 0A; _+_ to _⋆_; -_ to inv) open AbGroupStr (B .snd) using (_+_; -_; +Comm; +Assoc; +IdR ; +InvR) renaming (0g to 0B) open GroupTheory (AbGroup→Group B) using (invDistr) renaming (inv1g to inv0B) -- Some lemmas idrB : (b : B .fst) → b + 0B ≡ b idrB b = +IdR b invrB : (b : B .fst) → b + (- b) ≡ 0B invrB b = +InvR b hom0AB : (f : AbGroupHom A B) → f .fst 0A ≡ 0B hom0AB f = hom1g (AbGroupStr→GroupStr (A .snd)) (f .fst) (AbGroupStr→GroupStr (B .snd)) (f .snd .pres·) homInvAB : (f : AbGroupHom A B) → (a : A .fst) → f .fst (inv a) ≡ (- f .fst a) homInvAB f a = homInv (AbGroupStr→GroupStr (A .snd)) (f .fst) (AbGroupStr→GroupStr (B .snd)) (f .snd .pres·) a -- Zero morphism zero : AbGroupHom A B zero .fst a = 0B zero .snd .pres· a a' = sym (idrB _) zero .snd .pres1 = refl zero .snd .presinv a = sym (inv0B) -- Pointwise addition of morphisms module _ (f* g* : AbGroupHom A B) where private f = f* .fst g = g* .fst HomAdd : AbGroupHom A B HomAdd .fst = λ a → f a + g a HomAdd .snd .pres· a a' = f (a ⋆ a') + g (a ⋆ a') ≡⟨ cong (_+ g(a ⋆ a')) (f* .snd .pres· _ _) ⟩ (f a + f a') + g (a ⋆ a') ≡⟨ cong ((f a + f a') +_) (g* .snd .pres· _ _) ⟩ (f a + f a') + (g a + g a') ≡⟨ sym (+Assoc _ _ _) ⟩ f a + (f a' + (g a + g a')) ≡⟨ cong (f a +_) (+Assoc _ _ _) ⟩ f a + ((f a' + g a) + g a') ≡⟨ cong (λ b → (f a + b + g a')) (+Comm _ _) ⟩ f a + ((g a + f a') + g a') ≡⟨ cong (f a +_) (sym (+Assoc _ _ _)) ⟩ f a + (g a + (f a' + g a')) ≡⟨ +Assoc _ _ _ ⟩ (f a + g a) + (f a' + g a') ∎ HomAdd .snd .pres1 = f 0A + g 0A ≡⟨ cong (_+ g 0A) (hom0AB f*) ⟩ 0B + g 0A ≡⟨ cong (0B +_) (hom0AB g*) ⟩ 0B + 0B ≡⟨ idrB _ ⟩ 0B ∎ HomAdd .snd .presinv a = f (inv a) + g (inv a) ≡⟨ cong (_+ g (inv a)) (homInvAB f* _) ⟩ (- f a) + g (inv a) ≡⟨ cong ((- f a) +_) (homInvAB g* _) ⟩ (- f a) + (- g a) ≡⟨ +Comm _ _ ⟩ (- g a) + (- f a) ≡⟨ sym (invDistr _ _) ⟩ - (f a + g a) ∎ -- Pointwise inverse of morphism module _ (f* : AbGroupHom A B) where private f = f* .fst HomInv : AbGroupHom A B HomInv .fst = λ a → - f a HomInv .snd .pres· a a' = - f (a ⋆ a') ≡⟨ cong -_ (f* .snd .pres· _ _) ⟩ - (f a + f a') ≡⟨ invDistr _ _ ⟩ (- f a') + (- f a) ≡⟨ +Comm _ _ ⟩ (- f a) + (- f a') ∎ HomInv .snd .pres1 = - (f 0A) ≡⟨ cong -_ (f* .snd .pres1) ⟩ - 0B ≡⟨ inv0B ⟩ 0B ∎ HomInv .snd .presinv a = - f (inv a) ≡⟨ cong -_ (homInvAB f* _) ⟩ - (- f a) ∎ -- Group laws for morphisms private 0ₕ = zero _+ₕ_ = HomAdd -ₕ_ = HomInv -- Morphism addition is associative HomAdd-assoc : (f g h : AbGroupHom A B) → (f +ₕ (g +ₕ h)) ≡ ((f +ₕ g) +ₕ h) HomAdd-assoc f g h = GroupHom≡ (funExt λ a → +Assoc _ _ _) -- Morphism addition is commutative HomAdd-comm : (f g : AbGroupHom A B) → (f +ₕ g) ≡ (g +ₕ f) HomAdd-comm f g = GroupHom≡ (funExt λ a → +Comm _ _) -- zero is right identity HomAdd-zero : (f : AbGroupHom A B) → (f +ₕ zero) ≡ f HomAdd-zero f = GroupHom≡ (funExt λ a → idrB _) -- -ₕ is right inverse HomInv-invr : (f : AbGroupHom A B) → (f +ₕ (-ₕ f)) ≡ zero HomInv-invr f = GroupHom≡ (funExt λ a → invrB _) -- Abelian group structure on AbGroupHom A B open AbGroupStr HomAbGroupStr : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroupStr (AbGroupHom A B) HomAbGroupStr A B .0g = zero A B HomAbGroupStr A B ._+_ = HomAdd A B HomAbGroupStr A B .-_ = HomInv A B HomAbGroupStr A B .isAbGroup = makeIsAbGroup isSetGroupHom (HomAdd-assoc A B) (HomAdd-zero A B) (HomInv-invr A B) (HomAdd-comm A B) HomAbGroup : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroup (ℓ-max ℓ ℓ') HomAbGroup A B = AbGroupHom A B , HomAbGroupStr A B
33.410959
90
0.508405