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
2fb55752ef43288906af32a8a8e237784ef727e6
14,572
agda
Agda
Cubical/Categories/Constructions/Slice.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Categories/Constructions/Slice.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Categories/Constructions/Slice.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} open import Cubical.Categories.Category open import Cubical.Categories.Morphism renaming (isIso to isIsoC) open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open Iso open import Cubical.Foundations.HLevels open Precategory open import Cubical.Core.Glue open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport using (transpFill) module Cubical.Categories.Constructions.Slice {ℓ ℓ' : Level} (C : Precategory ℓ ℓ') (c : C .ob) {{isC : isCategory C}} where open import Cubical.Data.Sigma -- just a helper to prevent redundency TypeC : Type (ℓ-suc (ℓ-max ℓ ℓ')) TypeC = Type (ℓ-max ℓ ℓ') -- Components of a slice category record SliceOb : TypeC where constructor sliceob field {S-ob} : C .ob S-arr : C [ S-ob , c ] open SliceOb public record SliceHom (a b : SliceOb) : Type ℓ' where constructor slicehom field S-hom : C [ S-ob a , S-ob b ] -- commutative diagram S-comm : S-hom ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a open SliceHom public -- Helpers for working with equality -- can probably replace these by showing that SliceOb is isomorphic to Sigma and -- that paths are isomorphic to Sigma? But sounds like that would need a lot of transp SliceOb-≡-intro : ∀ {a b} {f g} → (p : a ≡ b) → PathP (λ i → C [ p i , c ]) f g → sliceob {a} f ≡ sliceob {b} g SliceOb-≡-intro p q = λ i → sliceob {p i} (q i) module _ {xf yg : SliceOb} where private x = xf .S-ob f = xf .S-arr y = yg .S-ob g = yg .S-arr -- a path between slice objects is the "same" as a pair of paths between C obs and C arrows SOPathIsoPathΣ : Iso (xf ≡ yg) (Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g) SOPathIsoPathΣ .fun p = (λ i → (p i) .S-ob) , (λ i → (p i) .S-arr) SOPathIsoPathΣ .inv (p , q) i = sliceob {p i} (q i) SOPathIsoPathΣ .rightInv _ = refl SOPathIsoPathΣ .leftInv _ = refl SOPath≃PathΣ = isoToEquiv SOPathIsoPathΣ SOPath≡PathΣ = ua (isoToEquiv SOPathIsoPathΣ) -- intro and elim for working with SliceHom equalities (is there a better way to do this?) SliceHom-≡-intro : ∀ {a b} {f g} {c₁} {c₂} → (p : f ≡ g) → PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂ → slicehom f c₁ ≡ slicehom g c₂ SliceHom-≡-intro p q = λ i → slicehom (p i) (q i) SliceHom-≡-elim : ∀ {a b} {f g} {c₁} {c₂} → slicehom f c₁ ≡ slicehom g c₂ → Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂ SliceHom-≡-elim r = (λ i → S-hom (r i)) , λ i → S-comm (r i) SliceHom-≡-intro' : ∀ {a b} {f g : C [ a .S-ob , b .S-ob ]} {c₁} {c₂} → (p : f ≡ g) → slicehom f c₁ ≡ slicehom g c₂ SliceHom-≡-intro' {a} {b} {f} {g} {c₁} {c₂} p i = slicehom (p i) (c₁≡c₂ i) where c₁≡c₂ : PathP (λ i → (p i) ⋆⟨ C ⟩ (b .S-arr) ≡ a .S-arr) c₁ c₂ c₁≡c₂ = isOfHLevel→isOfHLevelDep 1 (λ _ → isC .isSetHom _ _) c₁ c₂ p -- SliceHom is isomorphic to the Sigma type with the same components SliceHom-Σ-Iso : ∀ {a b} → Iso (SliceHom a b) (Σ[ h ∈ C [ S-ob a , S-ob b ] ] h ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) SliceHom-Σ-Iso .fun (slicehom h c) = h , c SliceHom-Σ-Iso .inv (h , c) = slicehom h c SliceHom-Σ-Iso .rightInv = λ x → refl SliceHom-Σ-Iso .leftInv = λ x → refl -- Precategory definition SliceCat : Precategory _ _ SliceCat .ob = SliceOb SliceCat .Hom[_,_] = SliceHom SliceCat .id (sliceob {x} f) = slicehom (C .id x) (C .⋆IdL _) SliceCat ._⋆_ {sliceob j} {sliceob k} {sliceob l} (slicehom f p) (slicehom g p') = slicehom (f ⋆⟨ C ⟩ g) ( f ⋆⟨ C ⟩ g ⋆⟨ C ⟩ l ≡⟨ C .⋆Assoc _ _ _ ⟩ f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ l) ≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) p' ⟩ f ⋆⟨ C ⟩ k ≡⟨ p ⟩ j ∎) SliceCat .⋆IdL (slicehom S-hom S-comm) = SliceHom-≡-intro (⋆IdL C _) (toPathP (isC .isSetHom _ _ _ _)) SliceCat .⋆IdR (slicehom S-hom S-comm) = SliceHom-≡-intro (⋆IdR C _) (toPathP (isC .isSetHom _ _ _ _)) SliceCat .⋆Assoc f g h = SliceHom-≡-intro (⋆Assoc C _ _ _) (toPathP (isC .isSetHom _ _ _ _)) -- SliceCat is a Category instance isCatSlice : isCategory SliceCat isCatSlice .isSetHom {a} {b} (slicehom f c₁) (slicehom g c₂) p q = cong isoP p'≡q' where -- paths between SliceHoms are equivalent to the projection paths p' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂ p' = SliceHom-≡-elim p q' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂ q' = SliceHom-≡-elim q -- we want all paths between (dependent) paths of this type to be equal B = λ v → v ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a -- need the groupoidness for dependent paths isGroupoidDepHom : isOfHLevelDep 2 B isGroupoidDepHom = isOfHLevel→isOfHLevelDep 2 (λ v x y → isSet→isGroupoid (isC .isSetHom) _ _ x y) -- we first prove that the projected paths are equal p'≡q' : p' ≡ q' p'≡q' = ΣPathP ((isC .isSetHom _ _ _ _) , toPathP (isGroupoidDepHom _ _ _ _ _)) -- and then we can use equivalence to lift these paths up -- to actual SliceHom paths isoP = λ g → cong (inv SliceHom-Σ-Iso) (fun (ΣPathIsoPathΣ) g) -- SliceCat is univalent if C is univalent module _ ⦃ isU : isUnivalent C ⦄ where open CatIso open Iso module _ { xf yg : SliceOb } where private x = xf .S-ob y = yg .S-ob -- names for the equivalences/isos pathIsoEquiv : (x ≡ y) ≃ (CatIso x y) pathIsoEquiv = univEquiv isU x y isoPathEquiv : (CatIso x y) ≃ (x ≡ y) isoPathEquiv = invEquiv pathIsoEquiv pToIIso' : Iso (x ≡ y) (CatIso x y) pToIIso' = equivToIso pathIsoEquiv -- the iso in SliceCat we're given induces an iso in C between x and y module _ ( cIso@(catiso kc lc s r) : CatIso {C = SliceCat} xf yg ) where extractIso' : CatIso {C = C} x y extractIso' .mor = kc .S-hom extractIso' .inv = lc .S-hom extractIso' .sec i = (s i) .S-hom extractIso' .ret i = (r i) .S-hom instance preservesUnivalenceSlice : isUnivalent SliceCat -- we prove the equivalence by going through Iso preservesUnivalenceSlice .univ xf@(sliceob {x} f) yg@(sliceob {y} g) = isoToIsEquiv sIso where -- this is just here because the type checker can't seem to infer xf and yg pToIIso : Iso (x ≡ y) (CatIso x y) pToIIso = pToIIso' {xf = xf} {yg} -- the meat of the proof sIso : Iso (xf ≡ yg) (CatIso xf yg) sIso .fun p = pathToIso xf yg p -- we use the normal pathToIso via path induction to get an isomorphism sIso .inv is@(catiso kc lc s r) = SliceOb-≡-intro x≡y (symP (sym (lc .S-comm) ◁ lf≡f)) where -- we get a path between xf and yg by combining paths between -- x and y, and f and g -- 1. x≡y follows from univalence of C -- 2. f≡g is more tricky; by commutativity, we know that g ≡ l ⋆ f -- so we want l to be id; we get this by showing: id ≡ pathToIso x y x≡y ≡ l -- where the first step follows from path induction, and the second from univalence of C -- morphisms in C from kc and lc k = kc .S-hom l = lc .S-hom -- extract out the iso between x and y extractIso : CatIso {C = C} x y extractIso = extractIso' is -- and we can use univalence of C to get x ≡ y x≡y : x ≡ y x≡y = pToIIso .inv extractIso -- to show that f ≡ g, we show that l ≡ id -- by using C's isomorphism pToI≡id : PathP (λ i → C [ x≡y (~ i) , x ]) (pathToIso {C = C} x y x≡y .inv) (C .id x) pToI≡id = J (λ y p → PathP (λ i → C [ p (~ i) , x ]) (pathToIso {C = C} x y p .inv) (C .id x)) (λ j → JRefl pToIFam pToIBase j .inv) x≡y where idx = C .id x pToIFam = (λ z _ → CatIso {C = C} x z) pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx) l≡pToI : l ≡ pathToIso {C = C} x y x≡y .inv l≡pToI i = pToIIso .rightInv extractIso (~ i) .inv l≡id : PathP (λ i → C [ x≡y (~ i) , x ]) l (C .id x) l≡id = l≡pToI ◁ pToI≡id lf≡f : PathP (λ i → C [ x≡y (~ i) , c ]) (l ⋆⟨ C ⟩ f) f lf≡f = (λ i → (l≡id i) ⋆⟨ C ⟩ f) ▷ C .⋆IdL _ sIso .rightInv is@(catiso kc lc s r) i = catiso (kc'≡kc i) (lc'≡lc i) (s'≡s i) (r'≡r i) -- we prove rightInv using a combination of univalence and the fact that homs are an h-set where kc' = (sIso .fun) (sIso .inv is) .mor lc' = (sIso .fun) (sIso .inv is) .inv k' = kc' .S-hom l' = lc' .S-hom k = kc .S-hom l = lc .S-hom extractIso : CatIso {C = C} x y extractIso = extractIso' is -- we do the equality component wise -- mor k'≡k : k' ≡ k k'≡k i = (pToIIso .rightInv extractIso) i .mor kcom'≡kcom : PathP (λ j → (k'≡k j) ⋆⟨ C ⟩ g ≡ f) (kc' .S-comm) (kc .S-comm) kcom'≡kcom = isSetHomP1 _ _ λ i → (k'≡k i) ⋆⟨ C ⟩ g kc'≡kc : kc' ≡ kc kc'≡kc i = slicehom (k'≡k i) (kcom'≡kcom i) -- inv l'≡l : l' ≡ l l'≡l i = (pToIIso .rightInv extractIso) i .inv lcom'≡lcom : PathP (λ j → (l'≡l j) ⋆⟨ C ⟩ f ≡ g) (lc' .S-comm) (lc .S-comm) lcom'≡lcom = isSetHomP1 _ _ λ i → (l'≡l i) ⋆⟨ C ⟩ f lc'≡lc : lc' ≡ lc lc'≡lc i = slicehom (l'≡l i) (lcom'≡lcom i) -- sec s' = (sIso .fun) (sIso .inv is) .sec s'≡s : PathP (λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i ≡ SliceCat .id _) s' s s'≡s = isSetHomP1 _ _ λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i -- ret r' = (sIso .fun) (sIso .inv is) .ret r'≡r : PathP (λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i ≡ SliceCat .id _) r' r r'≡r = isSetHomP1 _ _ λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i sIso .leftInv p = p'≡p -- to show that the round trip is equivalent to the identity -- we show that this is true for each component (S-ob, S-arr) -- and then combine -- specifically, we show that p'Ob≡pOb and p'Mor≡pMor -- and it follows that p'≡p where p' = (sIso .inv) (sIso .fun p) pOb : x ≡ y pOb i = (p i) .S-ob p'Ob : x ≡ y p'Ob i = (p' i) .S-ob pMor : PathP (λ i → C [ pOb i , c ]) f g pMor i = (p i) .S-arr p'Mor : PathP (λ i → C [ p'Ob i , c ]) f g p'Mor i = (p' i) .S-arr -- we first show that it's equivalent to use sIso first then extract, or to extract first than use pToIIso extractCom : extractIso' (sIso .fun p) ≡ pToIIso .fun pOb extractCom = J (λ yg' p̃ → extractIso' (pathToIso xf yg' p̃) ≡ pToIIso' {xf = xf} {yg'} .fun (λ i → (p̃ i) .S-ob)) (cong extractIso' (JRefl pToIFam' pToIBase') ∙ sym (JRefl pToIFam pToIBase)) p where idx = C .id x pToIFam = (λ z _ → CatIso {C = C} x z) pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx) idxf = SliceCat .id xf pToIFam' = (λ z _ → CatIso {C = SliceCat} xf z) pToIBase' = catiso (SliceCat .id xf) idxf (SliceCat .⋆IdL idxf) (SliceCat .⋆IdL idxf) -- why does this not follow definitionally? -- from extractCom, we get that performing the roundtrip on pOb gives us back p'Ob ppp : p'Ob ≡ (pToIIso .inv) (pToIIso .fun pOb) ppp = cong (pToIIso .inv) extractCom -- apply univalence of C -- this gives us the first component that we want p'Ob≡pOb : p'Ob ≡ pOb p'Ob≡pOb = ppp ∙ pToIIso .leftInv pOb -- isSetHom gives us the second component, path between morphisms p'Mor≡pMor : PathP (λ j → PathP (λ i → C [ (p'Ob≡pOb j) i , c ]) f g) p'Mor pMor p'Mor≡pMor = isSetHomP2l _ _ p'Mor pMor p'Ob≡pOb -- we can use the above paths to show that p' ≡ p p'≡p : p' ≡ p p'≡p i = comp (λ i' → SOPath≡PathΣ {xf = xf} {yg} (~ i')) (λ j → λ { (i = i0) → left (~ j) ; (i = i1) → right (~ j) }) (p'Σ≡pΣ i) where -- we break up p' and p into their constituent paths -- first via transport and then via our component definitions from before -- we show that p'ΣT ≡ p'Σ (and same for p) via univalence -- and p'Σ≡pΣ follows from our work from above p'ΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g p'ΣT = transport SOPath≡PathΣ p' p'Σ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g p'Σ = (p'Ob , p'Mor) pΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g pΣT = transport SOPath≡PathΣ p pΣ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g pΣ = (pOb , pMor)-- transport SOPathP≡PathPSO p -- using the computation rule to ua p'ΣT≡p'Σ : p'ΣT ≡ p'Σ p'ΣT≡p'Σ = uaβ SOPath≃PathΣ p' pΣT≡pΣ : pΣT ≡ pΣ pΣT≡pΣ = uaβ SOPath≃PathΣ p p'Σ≡pΣ : p'Σ ≡ pΣ p'Σ≡pΣ = ΣPathP (p'Ob≡pOb , p'Mor≡pMor) -- two sides of the square we're connecting left : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p' p'Σ left = transport-filler SOPath≡PathΣ p' ▷ p'ΣT≡p'Σ right : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p pΣ right = transport-filler SOPath≡PathΣ p ▷ pΣT≡pΣ -- properties -- TODO: move to own file open isIsoC renaming (inv to invC) -- make a slice isomorphism from just the hom sliceIso : ∀ {a b} (f : C [ a .S-ob , b .S-ob ]) (c : (f ⋆⟨ C ⟩ b .S-arr) ≡ a .S-arr) → isIsoC {C = C} f → isIsoC {C = SliceCat} (slicehom f c) sliceIso f c isof .invC = slicehom (isof .invC) (sym (invMoveL (isIso→areInv isof) c)) sliceIso f c isof .sec = SliceHom-≡-intro' (isof .sec) sliceIso f c isof .ret = SliceHom-≡-intro' (isof .ret)
37.947917
126
0.522372
ad1536d6068466fd2e07f1ba9fd74a31365ce2d0
4,152
agda
Agda
Categories/Object/BinaryProducts/N-ary.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
1
2018-12-29T21:51:57.000Z
2018-12-29T21:51:57.000Z
Categories/Object/BinaryProducts/N-ary.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
Categories/Object/BinaryProducts/N-ary.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} open import Categories.Category open import Categories.Object.BinaryProducts module Categories.Object.BinaryProducts.N-ary {o ℓ e} (C : Category o ℓ e) (BP : BinaryProducts C) where open Category C open BinaryProducts BP open Equiv import Categories.Object.Product open Categories.Object.Product C open import Data.Nat using (ℕ; zero; suc) open import Data.Vec open import Data.Product.N-ary hiding ([]) Prod : {n : ℕ} → Vec Obj (suc n) → Obj Prod { zero} (A ∷ []) = A Prod {suc n} (A ∷ As) = A × Prod {n} As πˡ : {n m : ℕ} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → Prod (As ++ Bs) ⇒ Prod As πˡ { zero} (A ∷ []) Bs = π₁ πˡ {suc n} (A ∷ As) Bs = ⟨ π₁ , πˡ {n} As Bs ∘ π₂ ⟩ πʳ : {n m : ℕ} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → Prod (As ++ Bs) ⇒ Prod Bs πʳ { zero} (A ∷ []) Bs = π₂ πʳ {suc n} (A ∷ As) Bs = πʳ {n} As Bs ∘ π₂ glue : {n m : ℕ}{X : Obj} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → (f : X ⇒ Prod As) → (g : X ⇒ Prod Bs) → X ⇒ Prod (As ++ Bs) glue { zero}{m} (A ∷ []) Bs f g = ⟨ f , g ⟩ glue {suc n}{m} (A ∷ As) Bs f g = ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ open HomReasoning .commuteˡ : {n m : ℕ}{X : Obj} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → {f : X ⇒ Prod As} → {g : X ⇒ Prod Bs} → πˡ As Bs ∘ glue As Bs f g ≡ f commuteˡ { zero} (A ∷ []) Bs {f}{g} = commute₁ commuteˡ {suc n} (A ∷ As) Bs {f}{g} = begin ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ↓⟨ ⟨⟩∘ ⟩ ⟨ π₁ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ , (πˡ As Bs ∘ π₂) ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ⟩ ↓⟨ ⟨⟩-cong₂ commute₁ assoc ⟩ ⟨ π₁ ∘ f , πˡ As Bs ∘ π₂ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ⟩ ↓⟨ ⟨⟩-congʳ (refl ⟩∘⟨ commute₂) ⟩ ⟨ π₁ ∘ f , πˡ As Bs ∘ glue As Bs (π₂ ∘ f) g ⟩ ↓⟨ ⟨⟩-congʳ (commuteˡ As Bs) ⟩ ⟨ π₁ ∘ f , π₂ ∘ f ⟩ ↓⟨ g-η ⟩ f ∎ .commuteʳ : {n m : ℕ}{X : Obj} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → {f : X ⇒ Prod As} → {g : X ⇒ Prod Bs} → πʳ As Bs ∘ glue As Bs f g ≡ g commuteʳ { zero} (A ∷ []) Bs {f}{g} = commute₂ commuteʳ {suc n} (A ∷ As) Bs {f}{g} = begin (πʳ As Bs ∘ π₂) ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ↓⟨ assoc ⟩ πʳ As Bs ∘ π₂ ∘ ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ↓⟨ refl ⟩∘⟨ commute₂ ⟩ πʳ As Bs ∘ glue As Bs (π₂ ∘ f) g ↓⟨ commuteʳ As Bs ⟩ g ∎ .N-universal : {n m : ℕ}{X : Obj} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → {f : X ⇒ Prod As} → {g : X ⇒ Prod Bs} → {h : X ⇒ Prod (As ++ Bs) } → πˡ As Bs ∘ h ≡ f → πʳ As Bs ∘ h ≡ g → glue As Bs f g ≡ h N-universal { zero} (A ∷ []) Bs {f}{g}{h} h-commuteˡ h-commuteʳ = universal h-commuteˡ h-commuteʳ N-universal {suc n} (A ∷ As) Bs {f}{g}{h} h-commuteˡ h-commuteʳ = begin ⟨ π₁ ∘ f , glue As Bs (π₂ ∘ f) g ⟩ ↓⟨ ⟨⟩-congʳ (N-universal As Bs π₂∘h-commuteˡ π₂∘h-commuteʳ) ⟩ ⟨ π₁ ∘ f , π₂ ∘ h ⟩ ↑⟨ ⟨⟩-congˡ π₁∘h-commuteˡ ⟩ ⟨ π₁ ∘ h , π₂ ∘ h ⟩ ↓⟨ g-η ⟩ h ∎ where -- h-commuteˡ : ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h ≡ f -- h-commuteʳ : (πʳ As Bs ∘ π₂) ∘ h ≡ g π₁∘h-commuteˡ : π₁ ∘ h ≡ π₁ ∘ f π₁∘h-commuteˡ = begin π₁ ∘ h ↑⟨ commute₁ ⟩∘⟨ refl ⟩ (π₁ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩) ∘ h ↓⟨ assoc ⟩ π₁ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h ↓⟨ refl ⟩∘⟨ h-commuteˡ ⟩ π₁ ∘ f ∎ π₂∘h-commuteˡ : πˡ As Bs ∘ π₂ ∘ h ≡ π₂ ∘ f π₂∘h-commuteˡ = begin πˡ As Bs ∘ π₂ ∘ h ↑⟨ assoc ⟩ (πˡ As Bs ∘ π₂) ∘ h ↑⟨ commute₂ ⟩∘⟨ refl ⟩ (π₂ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩) ∘ h ↓⟨ assoc ⟩ π₂ ∘ ⟨ π₁ , πˡ As Bs ∘ π₂ ⟩ ∘ h ↓⟨ refl ⟩∘⟨ h-commuteˡ ⟩ π₂ ∘ f ∎ π₂∘h-commuteʳ : πʳ As Bs ∘ π₂ ∘ h ≡ g π₂∘h-commuteʳ = trans (sym assoc) h-commuteʳ isProduct : {n m : ℕ} → (As : Vec Obj (suc n)) → (Bs : Vec Obj (suc m)) → Product (Prod As) (Prod Bs) isProduct {n}{m} As Bs = record { A×B = Prod (As ++ Bs) ; π₁ = πˡ As Bs ; π₂ = πʳ As Bs ; ⟨_,_⟩ = glue As Bs ; commute₁ = commuteˡ As Bs ; commute₂ = commuteʳ As Bs ; universal = N-universal As Bs }
25.95
97
0.472062
221bb494bd8f86f5e1c2c742c8475bb449ebee36
9,156
agda
Agda
agda-stdlib/src/Data/List/Kleene/Base.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Kleene/Base.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Kleene/Base.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Lists, based on the Kleene star and plus, basic types and operations. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Kleene.Base where open import Data.Product as Product using (_×_; _,_; map₂; map₁; proj₁; proj₂) open import Data.Nat as ℕ using (ℕ; suc; zero) open import Data.Maybe as Maybe using (Maybe; just; nothing) open import Data.Sum as Sum using (_⊎_; inj₁; inj₂) open import Level as Level using (Level) open import Algebra.Core using (Op₂) open import Function.Base private variable a b c : Level A : Set a B : Set b C : Set c ------------------------------------------------------------------------ -- Definitions -- -- These lists are exactly equivalent to normal lists, except the "cons" -- case is split into its own data type. This lets us write all the same -- functions as before, but it has 2 advantages: -- -- * Some functions are easier to express on the non-empty type. Head, -- for instance, has a natural safe implementation. Having the -- non-empty type be defined mutually with the normal type makes the -- use of this non-empty type occasionally more ergonomic. -- * It can make some proofs easier. By using the non-empty type where -- possible, we can avoid an extra pattern match, which can really -- simplify certain proofs. infixr 5 _&_ ∹_ record _+ {a} (A : Set a) : Set a data _* {a} (A : Set a) : Set a -- Non-Empty Lists record _+ A where inductive constructor _&_ field head : A tail : A * -- Possibly Empty Lists data _* A where [] : A * ∹_ : A + → A * open _+ public ------------------------------------------------------------------------ -- Uncons uncons : A * → Maybe (A +) uncons [] = nothing uncons (∹ xs) = just xs ------------------------------------------------------------------------ -- FoldMap foldMap+ : Op₂ B → (A → B) → A + → B foldMap+ _∙_ f (x & []) = f x foldMap+ _∙_ f (x & ∹ xs) = f x ∙ foldMap+ _∙_ f xs foldMap* : Op₂ B → B → (A → B) → A * → B foldMap* _∙_ ε f [] = ε foldMap* _∙_ ε f (∹ xs) = foldMap+ _∙_ f xs ------------------------------------------------------------------------ -- Folds module _ (f : A → B → B) (b : B) where foldr+ : A + → B foldr* : A * → B foldr+ (x & xs) = f x (foldr* xs) foldr* [] = b foldr* (∹ xs) = foldr+ xs module _ (f : B → A → B) where foldl+ : B → A + → B foldl* : B → A * → B foldl+ b (x & xs) = foldl* (f b x) xs foldl* b [] = b foldl* b (∹ xs) = foldl+ b xs ------------------------------------------------------------------------ -- Concatenation module Concat where _++++_ : A + → A + → A + _+++*_ : A + → A * → A + _*+++_ : A * → A + → A + _*++*_ : A * → A * → A * head (xs +++* ys) = head xs tail (xs +++* ys) = tail xs *++* ys xs *++* ys = foldr* (λ x zs → ∹ x & zs) ys xs xs ++++ ys = foldr+ (λ x zs → x & ∹ zs) ys xs [] *+++ ys = ys (∹ xs) *+++ ys = xs ++++ ys open Concat public using () renaming (_++++_ to _+++_; _*++*_ to _++*_) ------------------------------------------------------------------------ -- Mapping module _ (f : A → B) where map+ : A + → B + map* : A * → B * head (map+ xs) = f (head xs) tail (map+ xs) = map* (tail xs) map* [] = [] map* (∹ xs) = ∹ map+ xs module _ (f : A → Maybe B) where mapMaybe+ : A + → B * mapMaybe* : A * → B * mapMaybe+ (x & xs) with f x ... | just y = ∹ y & mapMaybe* xs ... | nothing = mapMaybe* xs mapMaybe* [] = [] mapMaybe* (∹ xs) = mapMaybe+ xs ------------------------------------------------------------------------ -- Applicative Operations pure+ : A → A + head (pure+ x) = x tail (pure+ x) = [] pure* : A → A * pure* x = ∹ pure+ x module Apply where _*<*>*_ : (A → B) * → A * → B * _+<*>*_ : (A → B) + → A * → B * _*<*>+_ : (A → B) * → A + → B * _+<*>+_ : (A → B) + → A + → B + [] *<*>* xs = [] (∹ fs) *<*>* xs = fs +<*>* xs fs +<*>* xs = map* (head fs) xs ++* (tail fs *<*>* xs) [] *<*>+ xs = [] (∹ fs) *<*>+ xs = ∹ fs +<*>+ xs fs +<*>+ xs = map+ (head fs) xs Concat.+++* (tail fs *<*>+ xs) open Apply public using () renaming (_*<*>*_ to _<*>*_; _+<*>+_ to _<*>+_) ------------------------------------------------------------------------ -- Monadic Operations module Bind where _+>>=+_ : A + → (A → B +) → B + _+>>=*_ : A + → (A → B *) → B * _*>>=+_ : A * → (A → B +) → B * _*>>=*_ : A * → (A → B *) → B * (x & xs) +>>=+ k = k x Concat.+++* (xs *>>=+ k) (x & xs) +>>=* k = k x Concat.*++* (xs *>>=* k) [] *>>=* k = [] (∹ xs) *>>=* k = xs +>>=* k [] *>>=+ k = [] (∹ xs) *>>=+ k = ∹ xs +>>=+ k open Bind public using () renaming (_*>>=*_ to _>>=*_; _+>>=+_ to _>>=+_) ------------------------------------------------------------------------ -- Scans module Scanr (f : A → B → B) (b : B) where cons : A → B + → B + head (cons x xs) = f x (head xs) tail (cons x xs) = ∹ xs scanr+ : A + → B + scanr* : A * → B + scanr* = foldr* cons (b & []) scanr+ = foldr+ cons (b & []) open Scanr public using (scanr+; scanr*) module _ (f : B → A → B) where scanl* : B → A * → B + head (scanl* b xs) = b tail (scanl* b []) = [] tail (scanl* b (∹ xs)) = ∹ scanl* (f b (head xs)) (tail xs) scanl+ : B → A + → B + head (scanl+ b xs) = b tail (scanl+ b xs) = ∹ scanl* (f b (head xs)) (tail xs) scanl₁ : B → A + → B + scanl₁ b xs = scanl* (f b (head xs)) (tail xs) ------------------------------------------------------------------------ -- Accumulating maps module _ (f : B → A → (B × C)) where mapAccumˡ* : B → A * → (B × C *) mapAccumˡ+ : B → A + → (B × C +) mapAccumˡ* b [] = b , [] mapAccumˡ* b (∹ xs) = map₂ ∹_ (mapAccumˡ+ b xs) mapAccumˡ+ b (x & xs) = let y , ys = f b x z , zs = mapAccumˡ* y xs in z , ys & zs module _ (f : A → B → (C × B)) (b : B) where mapAccumʳ* : A * → (C * × B) mapAccumʳ+ : A + → (C + × B) mapAccumʳ* [] = [] , b mapAccumʳ* (∹ xs) = map₁ ∹_ (mapAccumʳ+ xs) mapAccumʳ+ (x & xs) = let ys , y = mapAccumʳ* xs zs , z = f x y in zs & ys , z ------------------------------------------------------------------------ -- Non-Empty Folds last : A + → A last (x & []) = x last (_ & ∹ xs) = last xs module _ (f : A → A → A) where foldr₁ : A + → A foldr₁ (x & []) = x foldr₁ (x & ∹ xs) = f x (foldr₁ xs) foldl₁ : A + → A foldl₁ (x & xs) = foldl* f x xs module _ (f : A → Maybe B → B) where foldrMaybe* : A * → Maybe B foldrMaybe+ : A + → B foldrMaybe* [] = nothing foldrMaybe* (∹ xs) = just (foldrMaybe+ xs) foldrMaybe+ xs = f (head xs) (foldrMaybe* (tail xs)) ------------------------------------------------------------------------ -- Indexing _[_]* : A * → ℕ → Maybe A _[_]+ : A + → ℕ → Maybe A [] [ _ ]* = nothing (∹ xs) [ i ]* = xs [ i ]+ xs [ zero ]+ = just (head xs) xs [ suc i ]+ = tail xs [ i ]* applyUpTo* : (ℕ → A) → ℕ → A * applyUpTo+ : (ℕ → A) → ℕ → A + applyUpTo* f zero = [] applyUpTo* f (suc n) = ∹ applyUpTo+ f n head (applyUpTo+ f n) = f zero tail (applyUpTo+ f n) = applyUpTo* (f ∘ suc) n upTo* : ℕ → ℕ * upTo* = applyUpTo* id upTo+ : ℕ → ℕ + upTo+ = applyUpTo+ id ------------------------------------------------------------------------ -- Manipulation module ZipWith (f : A → B → C) where +zipWith+ : A + → B + → C + *zipWith+ : A * → B + → C * +zipWith* : A + → B * → C * *zipWith* : A * → B * → C * head (+zipWith+ xs ys) = f (head xs) (head ys) tail (+zipWith+ xs ys) = *zipWith* (tail xs) (tail ys) *zipWith+ [] ys = [] *zipWith+ (∹ xs) ys = ∹ +zipWith+ xs ys +zipWith* xs [] = [] +zipWith* xs (∹ ys) = ∹ +zipWith+ xs ys *zipWith* [] ys = [] *zipWith* (∹ xs) ys = +zipWith* xs ys open ZipWith public renaming (+zipWith+ to zipWith+; *zipWith* to zipWith*) module Unzip (f : A → B × C) where cons : B × C → B * × C * → B + × C + cons = Product.zip′ _&_ _&_ unzipWith* : A * → B * × C * unzipWith+ : A + → B + × C + unzipWith* = foldr* (λ x xs → Product.map ∹_ ∹_ (cons (f x) xs)) ([] , []) unzipWith+ xs = cons (f (head xs)) (unzipWith* (tail xs)) open Unzip using (unzipWith+; unzipWith*) public module Partition (f : A → B ⊎ C) where cons : B ⊎ C → B * × C * → B * × C * proj₁ (cons (inj₁ x) xs) = ∹ x & proj₁ xs proj₂ (cons (inj₁ x) xs) = proj₂ xs proj₂ (cons (inj₂ x) xs) = ∹ x & proj₂ xs proj₁ (cons (inj₂ x) xs) = proj₁ xs partitionSumsWith* : A * → B * × C * partitionSumsWith+ : A + → B * × C * partitionSumsWith* = foldr* (cons ∘ f) ([] , []) partitionSumsWith+ = foldr+ (cons ∘ f) ([] , []) open Partition using (partitionSumsWith+; partitionSumsWith*) public tails* : A * → (A +) * tails+ : A + → (A +) + head (tails+ xs) = xs tail (tails+ xs) = tails* (tail xs) tails* [] = [] tails* (∹ xs) = ∹ tails+ xs reverse* : A * → A * reverse* = foldl* (λ xs x → ∹ x & xs) [] reverse+ : A + → A + reverse+ (x & xs) = foldl* (λ ys y → y & ∹ ys) (x & []) xs
25.433333
78
0.437746
8b1e9ebbe70f566fc36de46c0bc9772cc48fb5eb
19,162
agda
Agda
explore/typecheck/UntypingCons.agda
TristanCacqueray/disco
bb5b6773584253cfa84adf2111e39c9359506019
[ "BSD-3-Clause" ]
138
2016-12-10T08:10:03.000Z
2022-01-22T22:56:45.000Z
explore/typecheck/UntypingCons.agda
Boarders/disco
7abce0acde1b0bbc993c76adc18b5b09230bf030
[ "BSD-3-Clause" ]
282
2016-11-19T18:05:42.000Z
2022-03-28T21:43:15.000Z
explore/typecheck/UntypingCons.agda
Boarders/disco
7abce0acde1b0bbc993c76adc18b5b09230bf030
[ "BSD-3-Clause" ]
20
2017-02-18T20:36:05.000Z
2021-07-30T05:37:45.000Z
module UntypingCons where open import Relation.Binary.PropositionalEquality open import Function using (id) open import Data.Empty open import Data.Unit open import Relation.Nullary open import Data.Nat open import Data.Fin open import Data.Vec open import Data.Sum open import Data.Product open import Data.List open import Data.Maybe ------------------------------------------------------------ -- Types ------------------------------------------------------------ data Cons : Set where NatC : Cons ⇒C : Cons ⊗C : Cons arity : Cons → ℕ arity NatC = 0 arity ⇒C = 2 arity ⇒⊗ = 2 -- A universe of types for STLC + natural numbers + pairs. data Type : Set where cons : (c : Cons) → Vec Type (arity c) → Type _⇒_ : Type → Type → Type σ ⇒ τ = cons ⇒C (σ ∷ τ ∷ []) _⊗_ : Type → Type → Type σ ⊗ τ = cons ⊗C (σ ∷ τ ∷ []) infixr 80 _⇒_ infixr 90 _⊗_ -- Constructors are injective. cons-inj : ∀ {c : Cons} → -- -- The function type constructor is injective. -- ⇒-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≡ τ₃ ⇒ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄) -- ⇒-inj refl = refl , refl -- ⊗-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≡ τ₃ ⊗ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄) -- ⊗-inj refl = refl , refl -- -- Equality of types is decidable. -- _≡?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≢ τ₂) -- Nat ≡? Nat = inj₁ refl -- Nat ≡? (_ ⇒ _) = inj₂ (λ ()) -- Nat ≡? (_ ⊗ _) = inj₂ (λ ()) -- (_ ⇒ _) ≡? Nat = inj₂ (λ ()) -- (_ ⇒ _) ≡? (_ ⊗ _) = inj₂ (λ ()) -- (_ ⊗ _) ≡? Nat = inj₂ (λ ()) -- (_ ⊗ _) ≡? (_ ⇒ _) = inj₂ (λ ()) -- (τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄ -- (τ₁ ⇒ τ₂) ≡? (.τ₁ ⇒ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl -- (τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ eq → τ₁≢τ₃ (proj₁ (⇒-inj eq))) -- (τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⇒-inj eq))) -- (τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄ -- (τ₁ ⊗ τ₂) ≡? (.τ₁ ⊗ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl -- (τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ x → τ₁≢τ₃ (proj₁ (⊗-inj x))) -- (τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⊗-inj eq))) -- ≢-cong-⇒ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≢ τ₃ ⇒ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄) -- ≢-cong-⇒ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄ -- ≢-cong-⇒ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃ -- ≢-cong-⇒ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄ -- ≢-cong-⇒ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl) -- ≢-cong-⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≢ τ₃ ⊗ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄) -- ≢-cong-⊗ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄ -- ≢-cong-⊗ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃ -- ≢-cong-⊗ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄ -- ≢-cong-⊗ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl) -- -- A type of explicit evidence explaining *why* two types are unequal. -- data _≁_ : Type → Type → Set where -- Nat≁⇒ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⇒ τ₂) -- Nat≁⊗ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⊗ τ₂) -- ⇒≁⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂) ≁ (τ₃ ⊗ τ₄) -- ⇒ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄) -- ⇒ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄) -- ⊗ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄) -- ⊗ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄) -- ≁-sym : ∀ {τ₁ τ₂} → τ₁ ≁ τ₂ → τ₂ ≁ τ₁ -- -- Given such a proof we can show the types are unequal. -- ≁-≢ : ∀ {τ₁ τ₂} → (τ₁ ≁ τ₂) → (τ₁ ≢ τ₂) -- ≁-≢ Nat≁⇒ = λ () -- ≁-≢ Nat≁⊗ = λ () -- ≁-≢ ⇒≁⊗ = λ () -- ≁-≢ (⇒ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl -- ≁-≢ (⇒ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl -- ≁-≢ (⊗ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl -- ≁-≢ (⊗ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl -- ≁-≢ (≁-sym τ₂≁τ₁) refl = ≁-≢ τ₂≁τ₁ refl -- -- Since our universe of types is closed, we can actually go the other -- -- way too. That is, ≢ is equivalent to ≁ ; the point is that the -- -- latter is more immediately informative (by pattern-matching etc.) -- -- which can be used to produce error messages and so on. -- -- -- -- Note, however, that there might be *multiple* terms of type τ₁ ≁ -- -- τ₂: each corresponds to a different explanation of why the types -- -- are not equal. We might actually care which one we have. -- -- Round-tripping through (τ₁ ≢ τ₂) is not the identity. -- ≢-≁ : ∀ {τ₁ τ₂} → (τ₁ ≢ τ₂) → (τ₁ ≁ τ₂) -- ≢-≁ {Nat} {Nat} τ₁≢τ₂ with τ₁≢τ₂ refl -- ... | () -- ≢-≁ {Nat} {τ₂ ⇒ τ₃} _ = Nat≁⇒ -- ≢-≁ {Nat} {τ₂ ⊗ τ₃} _ = Nat≁⊗ -- ≢-≁ {τ₁ ⇒ τ₂} {Nat} _ = ≁-sym Nat≁⇒ -- ≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⊗ τ₄} _ = ⇒≁⊗ -- ≢-≁ {τ₁ ⊗ τ₂} {Nat} _ = ≁-sym Nat≁⊗ -- ≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⇒ τ₄} _ = ≁-sym ⇒≁⊗ -- ≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ with ≢-cong-⇒ τ₁⇒τ₂≢τ₃⇒τ₄ -- ≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₁ τ₁≢τ₃ = ⇒ˡ-≁ (≢-≁ τ₁≢τ₃) -- ≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₂ τ₂≢τ₄ = ⇒ʳ-≁ (≢-≁ τ₂≢τ₄) -- ≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ with ≢-cong-⊗ τ₁⊗τ₂≢τ₃⊗τ₄ -- ≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₁ τ₁≢τ₃ = ⊗ˡ-≁ (≢-≁ τ₁≢τ₃) -- ≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₂ τ₂≢τ₄ = ⊗ʳ-≁ (≢-≁ τ₂≢τ₄) -- -- Sometimes it's convenient to decide equality of types using ≁ in place of ≢. -- _∼?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≁ τ₂) -- τ₁ ∼? τ₂ = Data.Sum.map id ≢-≁ (τ₁ ≡? τ₂) -- -- Evidence that a type is not an arrow type. -- data not⇒_ : Type → Set where -- not⇒Nat : not⇒ Nat -- not⇒⊗ : ∀ {τ₁ τ₂} → not⇒ (τ₁ ⊗ τ₂) -- data not⊗_ : Type → Set where -- not⊗Nat : not⊗ Nat -- not⊗⇒ : ∀ {τ₁ τ₂} → not⊗ (τ₁ ⇒ τ₂) -- ⇒? : (τ : Type) → (Σ[ τ₁ ∈ Type ] Σ[ τ₂ ∈ Type ] τ ≡ τ₁ ⇒ τ₂) ⊎ (not⇒ τ) -- ⇒? Nat = inj₂ not⇒Nat -- ⇒? (_ ⊗ _) = inj₂ not⇒⊗ -- ⇒? (τ₁ ⇒ τ₂) = inj₁ (τ₁ , τ₂ , refl) -- ------------------------------------------------------------ -- -- Expressions -- ------------------------------------------------------------ -- -- (Untyped) expressions of STLC + arithmetic + pairs. -- data Expr (n : ℕ) : Set where -- lit : ℕ → Expr n -- _⊕_ : Expr n → Expr n → Expr n -- ⟨_,_⟩ : Expr n → Expr n → Expr n -- π₁ : Expr n -- π₂ : Expr n -- var : Fin n → Expr n -- ƛ : Type → Expr (suc n) → Expr n -- _·_ : Expr n → Expr n → Expr n -- Ctx : ℕ → Set -- Ctx n = Vec Type n -- ------------------------------------------------------------ -- -- Typing -- ------------------------------------------------------------ -- -- Typing derivations. -- data _⊢_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where -- lit : ∀ {n} {Γ : Ctx n} {m} -- → Γ ⊢ lit m ∶ Nat -- _⊕_ : ∀ {n} {Γ : Ctx n} {t₁ t₂} -- → Γ ⊢ t₁ ∶ Nat -- → Γ ⊢ t₂ ∶ Nat -- → Γ ⊢ (t₁ ⊕ t₂) ∶ Nat -- ⟨_,_⟩ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂} -- → Γ ⊢ t₁ ∶ τ₁ -- → Γ ⊢ t₂ ∶ τ₂ -- → Γ ⊢ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂ -- π₁ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂} -- → Γ ⊢ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₁ -- π₂ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂} -- → Γ ⊢ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₂ -- var : ∀ {n} {Γ : Ctx n} {i} -- → Γ ⊢ var i ∶ lookup i Γ -- ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂} -- → (τ₁ ∷ Γ) ⊢ t ∶ τ₂ -- → Γ ⊢ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂) -- _·_ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂} -- → Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂ -- → Γ ⊢ t₂ ∶ τ₁ -- → Γ ⊢ t₁ · t₂ ∶ τ₂ -- -- Explicit, constructive evidence for the *untypability* of a term. -- data _⊬_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where -- -- Explicitly build in uniqueness of typing as an axiom. t is not -- -- typeable at type τ₂ if t is typeable at some different type. -- mismatch : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂} -- → Γ ⊢ t ∶ τ₁ -- → τ₁ ≁ τ₂ -- → Γ ⊬ t ∶ τ₂ -- -- There are three ways for a + term to fail to have a given type τ: -- -- either the left or right sides do not have type Nat, or the type -- -- τ itself is not Nat. -- ⊕ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ} -- → Γ ⊬ t₁ ∶ Nat -- → Γ ⊬ (t₁ ⊕ t₂) ∶ τ -- ⊕ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ} -- → Γ ⊬ t₂ ∶ Nat -- → Γ ⊬ (t₁ ⊕ t₂) ∶ τ -- ⊕≁Nat : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ} -- → τ ≁ Nat → Γ ⊬ (t₁ ⊕ t₂) ∶ τ -- ⟨⟩-ty : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ} -- → not⊗ τ → Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ -- ⟨⟩ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂} -- → Γ ⊬ t₁ ∶ τ₁ -- → Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂ -- ⟨⟩ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂} -- → Γ ⊬ t₂ ∶ τ₂ -- → Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂ -- π₁-⇒ : ∀ {n} {Γ : Ctx n} {τ} -- → not⇒ τ -- → Γ ⊬ π₁ ∶ τ -- π₁-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂} -- → not⊗ τ₁ -- → Γ ⊬ π₁ ∶ τ₁ ⇒ τ₂ -- π₁-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃} -- → τ₁ ≁ τ₃ -- → Γ ⊬ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃ -- π₂-⇒ : ∀ {n} {Γ : Ctx n} {τ} -- → not⇒ τ -- → Γ ⊬ π₂ ∶ τ -- π₂-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂} -- → not⊗ τ₁ -- → Γ ⊬ π₂ ∶ τ₁ ⇒ τ₂ -- π₂-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃} -- → τ₂ ≁ τ₃ -- → Γ ⊬ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃ -- -- ƛ-funty holds if τ is not a function type at all, or if it is a -- -- function type whose input type is not τ₁. -- ƛ-funty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ} -- → (∀ {τ₂} → τ ≁ τ₁ ⇒ τ₂) -- → Γ ⊬ ƛ τ₁ t ∶ τ -- -- Otherwise, τ is of the form (τ₁ ⇒ τ₂) but the body t does not -- -- have type τ₂. Note this could be either because t is not typable -- -- at all, or because it has some type other than τ₂. -- ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂} -- → (τ₁ ∷ Γ) ⊬ t ∶ τ₂ -- → Γ ⊬ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂) -- -- Had this ƛ-resty constructor, but it turns out we don't need it: -- -- it is not used in inference or checking, and isn't needed to -- -- prove equivalence of ⊬ and ¬ ⊢ . It handles *only* the case -- -- where t is typable but has a type different than the output type -- -- of the whole expression; but the ƛ constructor handles this case -- -- as well as the case where t is not typeable at all. -- -- ƛ-resty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ₃} -- -- → (τ₁ ∷ Γ) ⊢ t ∶ τ₂ -- -- → τ₂ ≁ τ₃ -- -- → Γ ⊬ ƛ τ₁ t ∶ τ₁ ⇒ τ₃ -- -- Finally, there are two cases when an application is not typeable. -- -- Either the function does not have an appropriate function type, -- -- or the argument does not have a type that matches the function's -- -- input type. -- ·-fun : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₂} -- → (∀ {τ₁} → Γ ⊬ t₁ ∶ τ₁ ⇒ τ₂) -- → Γ ⊬ t₁ · t₂ ∶ τ₂ -- ·-arg : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂} -- → Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂ -- → Γ ⊬ t₂ ∶ τ₁ -- → Γ ⊬ t₁ · t₂ ∶ τ₂ -- -- ------------------------------------------------------------ -- -- -- Type inference and checking -- -- ------------------------------------------------------------ -- -- -- Type inference for a term in a given context returns either a type -- -- -- and a valid typing derivation, or a constructive proof that the -- -- -- term has no type. Note that in this system, ALL terms can be -- -- -- inferred. In a bidirectional system we would have to restrict this -- -- -- to only take inferrable terms as inputs. -- -- infer : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (∃ λ τ → Γ ⊢ t ∶ τ) ⊎ (∀ τ → Γ ⊬ t ∶ τ) -- -- infer Γ (lit n) = inj₁ (Nat , lit) -- -- infer Γ (t₁ ⊕ t₂) with infer Γ t₁ | infer Γ t₂ -- -- infer Γ (t₁ ⊕ t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | inj₁ (Nat , Γ⊢t₂∶Nat) = inj₁ (Nat , (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat)) -- -- infer Γ (t₁ ⊕ t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ _ = inj₂ (λ _ → ⊕ˡ (mismatch Γ⊢t₁∶τ₁⇒τ₂ (≁-sym Nat≁⇒))) -- -- infer Γ (t₁ ⊕ t₂) | inj₁ _ | inj₁ (τ₃ ⇒ τ₄ , Γ⊢t₂∶τ₃⇒τ₄) = inj₂ (λ _ → ⊕ʳ (mismatch Γ⊢t₂∶τ₃⇒τ₄ (≁-sym Nat≁⇒))) -- -- infer Γ (t₁ ⊕ t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ _ → ⊕ˡ (Γ⊬t₁∶ Nat)) -- -- infer Γ (t₁ ⊕ t₂) | _ | inj₂ Γ⊬t₂∶ = inj₂ (λ _ → ⊕ʳ (Γ⊬t₂∶ Nat)) -- -- infer Γ (var i) = inj₁ (lookup i Γ , var) -- -- infer Γ (ƛ τ₁ t) with infer (τ₁ ∷ Γ) t -- -- infer Γ (ƛ τ₁ t) | inj₁ (τ₂ , τ₁∷Γ⊢t∶τ₂) = inj₁ (τ₁ ⇒ τ₂ , ƛ τ₁∷Γ⊢t∶τ₂) -- -- infer Γ (ƛ τ₁ t) | inj₂ τ₁∷Γ⊬t∶ = inj₂ lemma -- -- where -- -- lemma : (τ : Type) → Γ ⊬ ƛ τ₁ t ∶ τ -- -- lemma Nat = ƛ-funty Nat≁⇒ -- -- lemma (τ₁′ ⇒ τ₂) with τ₁′ ∼? τ₁ -- -- lemma (.τ₁ ⇒ τ₂) | inj₁ refl = ƛ (τ₁∷Γ⊬t∶ τ₂) -- -- lemma (τ₁′ ⇒ τ₂) | inj₂ τ₁′≁τ₁ = ƛ-funty (λ {τ₃} → ⇒ˡ-≁ τ₁′≁τ₁) -- -- infer Γ (t₁ · t₂) with infer Γ t₁ | infer Γ t₂ -- -- infer Γ (t₁ · t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | _ = inj₂ (λ _ → ·-fun (mismatch Γ⊢t₁∶Nat Nat≁⇒)) -- -- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) with τ₁ ∼? τ₁′ -- -- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (.τ₁ , Γ⊢t₂∶τ₁ ) | inj₁ refl = inj₁ (τ₂ , (Γ⊢t₁∶τ₁⇒τ₂ · Γ⊢t₂∶τ₁)) -- -- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) | inj₂ τ₁≁τ₁′ = inj₂ lemma2 -- -- where -- -- lemma2 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ -- -- lemma2 τ with τ ∼? τ₂ -- -- lemma2 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (mismatch Γ⊢t₂∶τ₁′ (≁-sym τ₁≁τ₁′)) -- -- lemma2 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂))) -- -- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₂ Γ⊬t₂ = inj₂ lemma3 -- -- where -- -- lemma3 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ -- -- lemma3 τ with τ ∼? τ₂ -- -- lemma3 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (Γ⊬t₂ τ₁) -- -- lemma3 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂))) -- -- infer Γ (t₁ · t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ τ₂ → ·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ₂))) -- -- -- Check whether a given term has a *given* type. -- -- check : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (τ : Type) → (Γ ⊢ t ∶ τ) ⊎ (Γ ⊬ t ∶ τ) -- -- check Γ (lit _) (τ ⇒ τ₁) = inj₂ (mismatch lit Nat≁⇒) -- -- check Γ (lit _) Nat = inj₁ lit -- -- check Γ (_ ⊕ _ ) (τ ⇒ τ₁) = inj₂ (⊕≁Nat (≁-sym Nat≁⇒)) -- -- check Γ (t₁ ⊕ t₂) Nat with check Γ t₁ Nat | check Γ t₂ Nat -- -- check Γ (t₁ ⊕ t₂) Nat | inj₁ Γ⊢t₁∶Nat | inj₁ Γ⊢t₂∶Nat = inj₁ (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat) -- -- check Γ (t₁ ⊕ t₂) Nat | inj₂ Γ⊬t₁∶Nat | _ = inj₂ (⊕ˡ Γ⊬t₁∶Nat) -- -- check Γ (t₁ ⊕ t₂) Nat | _ | inj₂ Γ⊬t₂∶Nat = inj₂ (⊕ʳ Γ⊬t₂∶Nat) -- -- check Γ (var i) τ with τ ∼? lookup i Γ -- -- check Γ (var i) τ | inj₁ τ≡iΓ rewrite τ≡iΓ = inj₁ var -- -- check Γ (var i) τ | inj₂ τ≁iΓ = inj₂ (mismatch var (≁-sym τ≁iΓ)) -- -- check Γ (ƛ τ₁ t) Nat = inj₂ (ƛ-funty Nat≁⇒) -- -- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) with τ ∼? τ₁ | check (τ₁ ∷ Γ) t τ₂ -- -- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) | inj₂ τ≁τ₁ | _ = inj₂ (ƛ-funty (⇒ˡ-≁ τ≁τ₁)) -- -- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₂ τ₁∷Γ⊬t∶τ₂ = inj₂ (ƛ τ₁∷Γ⊬t∶τ₂) -- -- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₁ τ₁∷Γ⊢t∶τ₂ = inj₁ (ƛ τ₁∷Γ⊢t∶τ₂) -- -- --- Note that in order to check an application we have to use type inference on t₁. -- -- check Γ (t₁ · t₂) τ with infer Γ t₁ -- -- check Γ (t₁ · t₂) τ | inj₂ Γ⊬t₁∶ = inj₂ (·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ))) -- -- check Γ (t₁ · t₂) τ | inj₁ (Nat , Γ⊢t₁∶τ₁) = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ Nat≁⇒)) -- -- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) with τ ∼? τ₂ -- -- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₂ τ≁τ₂ = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ (⇒ʳ-≁ (≁-sym τ≁τ₂)))) -- -- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ rewrite τ≡τ₂ with check Γ t₂ τ₁ -- -- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₂ Γ⊬t₂∶τ₁ = inj₂ (·-arg Γ⊢t₁∶τ₁ Γ⊬t₂∶τ₁) -- -- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₁ Γ⊢t₂∶τ₁ = inj₁ (Γ⊢t₁∶τ₁ · Γ⊢t₂∶τ₁) -- -- ------------------------------------------------------------ -- -- -- Correctness -- -- ------------------------------------------------------------ -- -- -- The whole idea is that ⊬ is a more explicit/constructive, yet -- -- -- equivalent, way to represent the negation of ⊢ . We can actually -- -- -- prove the equivalence. -- -- -- First, straightforward induction on typing derivations shows that -- -- -- we really do have unique types, as assumed by the 'mismatch' -- -- -- constructor. -- -- ⊢-unique : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ₁ τ₂ : Type} → (Γ ⊢ t ∶ τ₁) → (Γ ⊢ t ∶ τ₂) → (τ₁ ≡ τ₂) -- -- ⊢-unique lit lit = refl -- -- ⊢-unique (_ ⊕ _) (_ ⊕ _) = refl -- -- ⊢-unique var var = refl -- -- ⊢-unique (ƛ Γ⊢t∶τ₁) (ƛ Γ⊢t∶τ₂) rewrite ⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂ = refl -- -- ⊢-unique (Γ⊢t∶τ₁ · _) (Γ⊢t∶τ₂ · _) = proj₂ (⇒-inj (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂)) -- -- -- Now we can do one direction of the equivalence. This direction is -- -- -- just induction over derivations, making use of uniqueness of -- -- -- typing. -- -- ⊬-¬⊢ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (Γ ⊬ t ∶ τ) → (¬ (Γ ⊢ t ∶ τ)) -- -- ⊬-¬⊢ (mismatch Γ⊢t∶τ₁ τ₁≁τ) Γ⊢t∶τ = ≁-≢ τ₁≁τ (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ) -- -- ⊬-¬⊢ (⊕ˡ Γ⊬t₁∶N) (Γ⊢t₁∶N ⊕ _ ) = ⊬-¬⊢ Γ⊬t₁∶N Γ⊢t₁∶N -- -- ⊬-¬⊢ (⊕ʳ Γ⊬t₂∶N) (_ ⊕ Γ⊢t₂∶N) = ⊬-¬⊢ Γ⊬t₂∶N Γ⊢t₂∶N -- -- ⊬-¬⊢ (⊕≁Nat τ≁N) (_ ⊕ _ ) = ≁-≢ τ≁N refl -- -- ⊬-¬⊢ (ƛ-funty τ≁τ₁⇒) (ƛ _) = ≁-≢ τ≁τ₁⇒ refl -- -- ⊬-¬⊢ (ƛ Γ⊬t∶τ₂) (ƛ Γ⊢t∶τ₂) = ⊬-¬⊢ Γ⊬t∶τ₂ Γ⊢t∶τ₂ -- -- ⊬-¬⊢ (·-fun Γ⊬t₁) (Γ⊢t₁ · _) = ⊬-¬⊢ Γ⊬t₁ Γ⊢t₁ -- -- ⊬-¬⊢ (·-arg Γ⊢t₁∶τ₁⇒τ Γ⊬t₂∶τ) (Γ⊢t₁∶τ₂⇒τ · Γ⊢t₂) -- -- rewrite proj₁ (⇒-inj (⊢-unique Γ⊢t₁∶τ₁⇒τ Γ⊢t₁∶τ₂⇒τ)) = ⊬-¬⊢ Γ⊬t₂∶τ Γ⊢t₂ -- -- -- The other direction follows straightforwardly from type checking. -- -- ¬⊢-⊬ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (¬ (Γ ⊢ t ∶ τ)) → (Γ ⊬ t ∶ τ) -- -- ¬⊢-⊬ {_} {Γ} {t} {τ} ¬Γ⊢t∶τ with check Γ t τ -- -- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₁ Γ⊢t∶τ = ⊥-elim (¬Γ⊢t∶τ Γ⊢t∶τ) -- -- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₂ Γ⊬t∶τ = Γ⊬t∶τ -- -- ------------------------------------------------------------ -- -- -- Take 2 -- -- ------------------------------------------------------------ -- -- -- XXX these need to be dependent somehow? e.g. consider the ƛ case -- -- -- below. If τ is not an arrow type the whole thing fails; but if it -- -- -- does, we need to know what τ₁ and τ₂ are in order to refer to them -- -- -- in the rest of the conditions. -- -- data many : List (Set × Set) → Set where -- -- empty : many [] -- -- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts) -- -- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts) -- -- data some : List (Set × Set) → Set where -- -- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → some ((Tₗ , Tᵣ) ∷ Ts) -- -- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → some Ts → some ((Tₗ , Tᵣ) ∷ Ts) -- -- -- Unique untypability; gives *every* possible reason that something -- -- -- is not typeable. There is no 'mismatch' constructor. -- -- {-# NO_POSITIVITY_CHECK #-} -- -- data _⊬₂_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where -- -- lit : ∀ {n} {Γ : Ctx n} {m} {τ} → τ ≁ Nat → Γ ⊬₂ lit m ∶ τ -- -- -- For t₁ ⊕ t₂ to be untypeable, at least one of three things must be wrong: -- -- ⊕ : ∀ {n} {Γ : Ctx n} {t₁ t₂ τ} -- -- → some -- -- ( (Γ ⊬₂ t₁ ∶ Nat , Γ ⊢ t₁ ∶ Nat) -- Either t₁ is well-typed or not -- -- ∷ (Γ ⊬₂ t₂ ∶ Nat , Γ ⊢ t₂ ∶ Nat) -- Either t₂ is well-typed or not -- -- ∷ ((τ ≁ Nat) , (τ ≡ Nat)) -- τ is Nat or not -- -- ∷ [] -- -- ) -- -- → Γ ⊬₂ t₁ ⊕ t₂ ∶ τ -- -- var : ∀ {n} {Γ : Ctx n} {i τ} -- -- → τ ≁ lookup i Γ -- -- → Γ ⊬₂ var i ∶ τ -- -- -- ƛ τ₁ t does not have type τ if -- -- -- - τ is not an arrow type -- -- -- ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ} -- -- -- → some -- -- -- ( (τ ≁
42.487805
126
0.443482
19cf2d498547b1ba9b506a5a8e5a4bb9c0dcc7a6
12,822
agda
Agda
agda-stdlib-0.9/src/Data/Integer/Properties.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/Integer/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Integer/Properties.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Some properties about integers ------------------------------------------------------------------------ module Data.Integer.Properties where open import Algebra import Algebra.FunctionProperties import Algebra.Morphism as Morphism import Algebra.Properties.AbelianGroup open import Algebra.Structures open import Data.Integer hiding (suc; _≤?_) import Data.Integer.Addition.Properties as Add import Data.Integer.Multiplication.Properties as Mul open import Data.Nat using (ℕ; suc; zero; _∸_; _≤?_; _<_; _≥_; _≱_; s≤s; z≤n; ≤-pred) renaming (_+_ to _ℕ+_; _*_ to _ℕ*_) open import Data.Nat.Properties as ℕ using (_*-mono_) open import Data.Product using (proj₁; proj₂; _,_) open import Data.Sign as Sign using () renaming (_*_ to _S*_) import Data.Sign.Properties as SignProp open import Function using (_∘_; _$_) open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Relation.Nullary using (yes; no) open import Relation.Nullary.Negation using (contradiction) open Algebra.FunctionProperties (_≡_ {A = ℤ}) open CommutativeMonoid Add.commutativeMonoid using () renaming ( assoc to +-assoc; comm to +-comm; identity to +-identity ; isCommutativeMonoid to +-isCommutativeMonoid ; isMonoid to +-isMonoid ) open CommutativeMonoid Mul.commutativeMonoid using () renaming ( assoc to *-assoc; comm to *-comm; identity to *-identity ; isCommutativeMonoid to *-isCommutativeMonoid ; isMonoid to *-isMonoid ) open CommutativeSemiring ℕ.commutativeSemiring using () renaming (zero to *-zero; distrib to *-distrib) open DecTotalOrder Data.Nat.decTotalOrder using () renaming (refl to ≤-refl) open Morphism.Definitions ℤ ℕ _≡_ open ℕ.SemiringSolver open ≡-Reasoning ------------------------------------------------------------------------ -- Miscellaneous properties -- Some properties relating sign and ∣_∣ to _◃_. sign-◃ : ∀ s n → sign (s ◃ suc n) ≡ s sign-◃ Sign.- _ = refl sign-◃ Sign.+ _ = refl sign-cong : ∀ {s₁ s₂ n₁ n₂} → s₁ ◃ suc n₁ ≡ s₂ ◃ suc n₂ → s₁ ≡ s₂ sign-cong {s₁} {s₂} {n₁} {n₂} eq = begin s₁ ≡⟨ sym $ sign-◃ s₁ n₁ ⟩ sign (s₁ ◃ suc n₁) ≡⟨ cong sign eq ⟩ sign (s₂ ◃ suc n₂) ≡⟨ sign-◃ s₂ n₂ ⟩ s₂ ∎ abs-◃ : ∀ s n → ∣ s ◃ n ∣ ≡ n abs-◃ _ zero = refl abs-◃ Sign.- (suc n) = refl abs-◃ Sign.+ (suc n) = refl abs-cong : ∀ {s₁ s₂ n₁ n₂} → s₁ ◃ n₁ ≡ s₂ ◃ n₂ → n₁ ≡ n₂ abs-cong {s₁} {s₂} {n₁} {n₂} eq = begin n₁ ≡⟨ sym $ abs-◃ s₁ n₁ ⟩ ∣ s₁ ◃ n₁ ∣ ≡⟨ cong ∣_∣ eq ⟩ ∣ s₂ ◃ n₂ ∣ ≡⟨ abs-◃ s₂ n₂ ⟩ n₂ ∎ -- ∣_∣ commutes with multiplication. abs-*-commute : Homomorphic₂ ∣_∣ _*_ _ℕ*_ abs-*-commute i j = abs-◃ _ _ -- If you subtract a natural from itself, then you get zero. n⊖n≡0 : ∀ n → n ⊖ n ≡ + 0 n⊖n≡0 zero = refl n⊖n≡0 (suc n) = n⊖n≡0 n ------------------------------------------------------------------------ -- The integers form a commutative ring private ---------------------------------------------------------------------- -- Additive abelian group. inverseˡ : LeftInverse (+ 0) -_ _+_ inverseˡ -[1+ n ] = n⊖n≡0 n inverseˡ (+ zero) = refl inverseˡ (+ suc n) = n⊖n≡0 n inverseʳ : RightInverse (+ 0) -_ _+_ inverseʳ i = begin i + - i ≡⟨ +-comm i (- i) ⟩ - i + i ≡⟨ inverseˡ i ⟩ + 0 ∎ +-isAbelianGroup : IsAbelianGroup _≡_ _+_ (+ 0) -_ +-isAbelianGroup = record { isGroup = record { isMonoid = +-isMonoid ; inverse = inverseˡ , inverseʳ ; ⁻¹-cong = cong -_ } ; comm = +-comm } open Algebra.Properties.AbelianGroup (record { isAbelianGroup = +-isAbelianGroup }) using () renaming (⁻¹-involutive to -‿involutive) ---------------------------------------------------------------------- -- Distributivity -- Various lemmas used to prove distributivity. sign-⊖-< : ∀ {m n} → m < n → sign (m ⊖ n) ≡ Sign.- sign-⊖-< {zero} (s≤s z≤n) = refl sign-⊖-< {suc n} (s≤s m<n) = sign-⊖-< m<n sign-⊖-≱ : ∀ {m n} → m ≱ n → sign (m ⊖ n) ≡ Sign.- sign-⊖-≱ = sign-⊖-< ∘ ℕ.≰⇒> +-⊖-left-cancel : ∀ a b c → (a ℕ+ b) ⊖ (a ℕ+ c) ≡ b ⊖ c +-⊖-left-cancel zero b c = refl +-⊖-left-cancel (suc a) b c = +-⊖-left-cancel a b c ⊖-swap : ∀ a b → a ⊖ b ≡ - (b ⊖ a) ⊖-swap zero zero = refl ⊖-swap (suc _) zero = refl ⊖-swap zero (suc _) = refl ⊖-swap (suc a) (suc b) = ⊖-swap a b -- Lemmas relating _⊖_ and _∸_. ∣⊖∣-< : ∀ {m n} → m < n → ∣ m ⊖ n ∣ ≡ n ∸ m ∣⊖∣-< {zero} (s≤s z≤n) = refl ∣⊖∣-< {suc n} (s≤s m<n) = ∣⊖∣-< m<n ∣⊖∣-≱ : ∀ {m n} → m ≱ n → ∣ m ⊖ n ∣ ≡ n ∸ m ∣⊖∣-≱ = ∣⊖∣-< ∘ ℕ.≰⇒> ⊖-≥ : ∀ {m n} → m ≥ n → m ⊖ n ≡ + (m ∸ n) ⊖-≥ z≤n = refl ⊖-≥ (s≤s n≤m) = ⊖-≥ n≤m ⊖-< : ∀ {m n} → m < n → m ⊖ n ≡ - + (n ∸ m) ⊖-< {zero} (s≤s z≤n) = refl ⊖-< {suc m} (s≤s m<n) = ⊖-< m<n ⊖-≱ : ∀ {m n} → m ≱ n → m ⊖ n ≡ - + (n ∸ m) ⊖-≱ = ⊖-< ∘ ℕ.≰⇒> -- Lemmas working around the fact that _◃_ pattern matches on its -- second argument before its first. +‿◃ : ∀ n → Sign.+ ◃ n ≡ + n +‿◃ zero = refl +‿◃ (suc _) = refl -‿◃ : ∀ n → Sign.- ◃ n ≡ - + n -‿◃ zero = refl -‿◃ (suc _) = refl -- The main distributivity proof. distrib-lemma : ∀ a b c → (c ⊖ b) * -[1+ a ] ≡ a ℕ+ b ℕ* suc a ⊖ (a ℕ+ c ℕ* suc a) distrib-lemma a b c rewrite +-⊖-left-cancel a (b ℕ* suc a) (c ℕ* suc a) | ⊖-swap (b ℕ* suc a) (c ℕ* suc a) with b ≤? c ... | yes b≤c rewrite ⊖-≥ b≤c | ⊖-≥ (b≤c *-mono (≤-refl {x = suc a})) | -‿◃ ((c ∸ b) ℕ* suc a) | ℕ.*-distrib-∸ʳ (suc a) c b = refl ... | no b≰c rewrite sign-⊖-≱ b≰c | ∣⊖∣-≱ b≰c | +‿◃ ((b ∸ c) ℕ* suc a) | ⊖-≱ (b≰c ∘ ℕ.cancel-*-right-≤ b c a) | -‿involutive (+ (b ℕ* suc a ∸ c ℕ* suc a)) | ℕ.*-distrib-∸ʳ (suc a) b c = refl distribʳ : _*_ DistributesOverʳ _+_ distribʳ (+ zero) y z rewrite proj₂ *-zero ∣ y ∣ | proj₂ *-zero ∣ z ∣ | proj₂ *-zero ∣ y + z ∣ = refl distribʳ x (+ zero) z rewrite proj₁ +-identity z | proj₁ +-identity (sign z S* sign x ◃ ∣ z ∣ ℕ* ∣ x ∣) = refl distribʳ x y (+ zero) rewrite proj₂ +-identity y | proj₂ +-identity (sign y S* sign x ◃ ∣ y ∣ ℕ* ∣ x ∣) = refl distribʳ -[1+ a ] -[1+ b ] -[1+ c ] = cong +_ $ solve 3 (λ a b c → (con 2 :+ b :+ c) :* (con 1 :+ a) := (con 1 :+ b) :* (con 1 :+ a) :+ (con 1 :+ c) :* (con 1 :+ a)) refl a b c distribʳ (+ suc a) (+ suc b) (+ suc c) = cong +_ $ solve 3 (λ a b c → (con 1 :+ b :+ (con 1 :+ c)) :* (con 1 :+ a) := (con 1 :+ b) :* (con 1 :+ a) :+ (con 1 :+ c) :* (con 1 :+ a)) refl a b c distribʳ -[1+ a ] (+ suc b) (+ suc c) = cong -[1+_] $ solve 3 (λ a b c → a :+ (b :+ (con 1 :+ c)) :* (con 1 :+ a) := (con 1 :+ b) :* (con 1 :+ a) :+ (a :+ c :* (con 1 :+ a))) refl a b c distribʳ (+ suc a) -[1+ b ] -[1+ c ] = cong -[1+_] $ solve 3 (λ a b c → a :+ (con 1 :+ a :+ (b :+ c) :* (con 1 :+ a)) := (con 1 :+ b) :* (con 1 :+ a) :+ (a :+ c :* (con 1 :+ a))) refl a b c distribʳ -[1+ a ] -[1+ b ] (+ suc c) = distrib-lemma a b c distribʳ -[1+ a ] (+ suc b) -[1+ c ] = distrib-lemma a c b distribʳ (+ suc a) -[1+ b ] (+ suc c) rewrite +-⊖-left-cancel a (c ℕ* suc a) (b ℕ* suc a) with b ≤? c ... | yes b≤c rewrite ⊖-≥ b≤c | +-comm (- (+ (a ℕ+ b ℕ* suc a))) (+ (a ℕ+ c ℕ* suc a)) | ⊖-≥ (b≤c *-mono ≤-refl {x = suc a}) | ℕ.*-distrib-∸ʳ (suc a) c b | +‿◃ (c ℕ* suc a ∸ b ℕ* suc a) = refl ... | no b≰c rewrite sign-⊖-≱ b≰c | ∣⊖∣-≱ b≰c | -‿◃ ((b ∸ c) ℕ* suc a) | ⊖-≱ (b≰c ∘ ℕ.cancel-*-right-≤ b c a) | ℕ.*-distrib-∸ʳ (suc a) b c = refl distribʳ (+ suc c) (+ suc a) -[1+ b ] rewrite +-⊖-left-cancel c (a ℕ* suc c) (b ℕ* suc c) with b ≤? a ... | yes b≤a rewrite ⊖-≥ b≤a | ⊖-≥ (b≤a *-mono ≤-refl {x = suc c}) | +‿◃ ((a ∸ b) ℕ* suc c) | ℕ.*-distrib-∸ʳ (suc c) a b = refl ... | no b≰a rewrite sign-⊖-≱ b≰a | ∣⊖∣-≱ b≰a | ⊖-≱ (b≰a ∘ ℕ.cancel-*-right-≤ b a c) | -‿◃ ((b ∸ a) ℕ* suc c) | ℕ.*-distrib-∸ʳ (suc c) b a = refl -- The IsCommutativeSemiring module contains a proof of -- distributivity which is used below. isCommutativeSemiring : IsCommutativeSemiring _≡_ _+_ _*_ (+ 0) (+ 1) isCommutativeSemiring = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isCommutativeMonoid = *-isCommutativeMonoid ; distribʳ = distribʳ ; zeroˡ = λ _ → refl } commutativeRing : CommutativeRing _ _ commutativeRing = record { Carrier = ℤ ; _≈_ = _≡_ ; _+_ = _+_ ; _*_ = _*_ ; -_ = -_ ; 0# = + 0 ; 1# = + 1 ; isCommutativeRing = record { isRing = record { +-isAbelianGroup = +-isAbelianGroup ; *-isMonoid = *-isMonoid ; distrib = IsCommutativeSemiring.distrib isCommutativeSemiring } ; *-comm = *-comm } } import Algebra.RingSolver.Simple as Solver import Algebra.RingSolver.AlmostCommutativeRing as ACR module RingSolver = Solver (ACR.fromCommutativeRing commutativeRing) _≟_ ------------------------------------------------------------------------ -- More properties -- Multiplication is right cancellative for non-zero integers. cancel-*-right : ∀ i j k → k ≢ + 0 → i * k ≡ j * k → i ≡ j cancel-*-right i j k ≢0 eq with signAbs k cancel-*-right i j .(+ 0) ≢0 eq | s ◂ zero = contradiction refl ≢0 cancel-*-right i j .(s ◃ suc n) ≢0 eq | s ◂ suc n with ∣ s ◃ suc n ∣ | abs-◃ s (suc n) | sign (s ◃ suc n) | sign-◃ s n ... | .(suc n) | refl | .s | refl = ◃-cong (sign-i≡sign-j i j eq) $ ℕ.cancel-*-right ∣ i ∣ ∣ j ∣ $ abs-cong eq where sign-i≡sign-j : ∀ i j → sign i S* s ◃ ∣ i ∣ ℕ* suc n ≡ sign j S* s ◃ ∣ j ∣ ℕ* suc n → sign i ≡ sign j sign-i≡sign-j i j eq with signAbs i | signAbs j sign-i≡sign-j .(+ 0) .(+ 0) eq | s₁ ◂ zero | s₂ ◂ zero = refl sign-i≡sign-j .(+ 0) .(s₂ ◃ suc n₂) eq | s₁ ◂ zero | s₂ ◂ suc n₂ with ∣ s₂ ◃ suc n₂ ∣ | abs-◃ s₂ (suc n₂) ... | .(suc n₂) | refl with abs-cong {s₁} {sign (s₂ ◃ suc n₂) S* s} {0} {suc n₂ ℕ* suc n} eq ... | () sign-i≡sign-j .(s₁ ◃ suc n₁) .(+ 0) eq | s₁ ◂ suc n₁ | s₂ ◂ zero with ∣ s₁ ◃ suc n₁ ∣ | abs-◃ s₁ (suc n₁) ... | .(suc n₁) | refl with abs-cong {sign (s₁ ◃ suc n₁) S* s} {s₁} {suc n₁ ℕ* suc n} {0} eq ... | () sign-i≡sign-j .(s₁ ◃ suc n₁) .(s₂ ◃ suc n₂) eq | s₁ ◂ suc n₁ | s₂ ◂ suc n₂ with ∣ s₁ ◃ suc n₁ ∣ | abs-◃ s₁ (suc n₁) | sign (s₁ ◃ suc n₁) | sign-◃ s₁ n₁ | ∣ s₂ ◃ suc n₂ ∣ | abs-◃ s₂ (suc n₂) | sign (s₂ ◃ suc n₂) | sign-◃ s₂ n₂ ... | .(suc n₁) | refl | .s₁ | refl | .(suc n₂) | refl | .s₂ | refl = SignProp.cancel-*-right s₁ s₂ (sign-cong eq) -- Multiplication with a positive number is right cancellative (for -- _≤_). cancel-*-+-right-≤ : ∀ m n o → m * + suc o ≤ n * + suc o → m ≤ n cancel-*-+-right-≤ (-[1+ m ]) (-[1+ n ]) o (-≤- n≤m) = -≤- (≤-pred (ℕ.cancel-*-right-≤ (suc n) (suc m) o (s≤s n≤m))) cancel-*-+-right-≤ ℤ.-[1+ _ ] (+ _) _ _ = -≤+ cancel-*-+-right-≤ (+ 0) ℤ.-[1+ _ ] _ () cancel-*-+-right-≤ (+ suc _) ℤ.-[1+ _ ] _ () cancel-*-+-right-≤ (+ 0) (+ 0) _ _ = +≤+ z≤n cancel-*-+-right-≤ (+ 0) (+ suc _) _ _ = +≤+ z≤n cancel-*-+-right-≤ (+ suc _) (+ 0) _ (+≤+ ()) cancel-*-+-right-≤ (+ suc m) (+ suc n) o (+≤+ m≤n) = +≤+ (ℕ.cancel-*-right-≤ (suc m) (suc n) o m≤n) -- Multiplication with a positive number is monotone. *-+-right-mono : ∀ n → (λ x → x * + suc n) Preserves _≤_ ⟶ _≤_ *-+-right-mono _ (-≤+ {n = 0}) = -≤+ *-+-right-mono _ (-≤+ {n = suc _}) = -≤+ *-+-right-mono x (-≤- n≤m) = -≤- (≤-pred (s≤s n≤m *-mono ≤-refl {x = suc x})) *-+-right-mono _ (+≤+ {m = 0} {n = 0} m≤n) = +≤+ m≤n *-+-right-mono _ (+≤+ {m = 0} {n = suc _} m≤n) = +≤+ z≤n *-+-right-mono _ (+≤+ {m = suc _} {n = 0} ()) *-+-right-mono x (+≤+ {m = suc _} {n = suc _} m≤n) = +≤+ (m≤n *-mono ≤-refl {x = suc x})
33.390625
83
0.452893
cbe61913d82833189df3f3392c87b8f791b84e1b
10,746
agda
Agda
src/Dodo/Binary/Equality.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
src/Dodo/Binary/Equality.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
src/Dodo/Binary/Equality.agda
sourcedennis/agda-dodo
376f0ccee1e1aa31470890e494bcb534324f598a
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Dodo.Binary.Equality where -- Stdlib imports import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open import Level using (Level; _⊔_) open import Function using (_∘_) open import Relation.Unary using (Pred) open import Relation.Binary using (Rel; REL) open import Relation.Binary using (Symmetric) -- Local imports open import Dodo.Unary.Equality infix 4 _⊆₂'_ _⊆₂_ _⇔₂_ _⊇₂_ -- | Binary relation subset helper. Generally, use `_⊆₂_` (below). -- -- -- # Design decision: Explicit variables -- -- `x` and `y` are passed /explicitly/. If they were implicit, Agda tries (and often fails) to -- instantiate them at inappropriate applications. _⊆₂'_ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} → (P : REL A B ℓ₁) → (R : REL A B ℓ₂) → Set _ _⊆₂'_ {A = A} {B = B} P R = ∀ (x : A) (y : B) → P x y → R x y -- | Binary relation subset -- -- Note that this does /not/ describe structural equality between inhabitants, only -- "(directed) co-inhabitation". -- `P ⊆₂ Q` denotes: If `P x y` is inhabited, then `Q x y` is inhabited. -- -- Whatever these inhabitants are, is irrelevant w.r.t. the subset constraint. -- -- -- # Design decision: Include P and R in the type -- -- Somehow, Agda cannot infer P and R from `P ⇒ R`, and requires them explicitly passed. -- For proof convenience, wrap the proof in this structure, which explicitly conveys P and R -- to the type-checker. data _⊆₂_ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where ⊆: : P ⊆₂' R → P ⊆₂ R -- | Binary relation equality -- -- Note that this does /not/ describe structural equality between inhabitants, only -- "co-inhabitation". -- `P ⇔₂ Q` denotes: `P x y` is inhabited iff `Q x y` is inhabited. -- -- Whatever these inhabitants are, is irrelevant w.r.t. the equality constraint. -- -- -- # Design decision: Include P and R in the type -- -- Somehow, Agda cannot infer P and R from `P ⇔ R`, and requires them explicitly passed. -- For proof convenience, wrap the proof in this structure, which explicitly conveys P and R -- to the type-checker. data _⇔₂_ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where ⇔: : P ⊆₂' R → R ⊆₂' P → P ⇔₂ R -- | Binary relation superset _⊇₂_ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) → Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) P ⊇₂ R = R ⊆₂ P -- # Helpers -- | Unwraps the `⊆:` constructor un-⊆₂ : ∀ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {R : REL A B ℓ₂} → P ⊆₂ R ------- → P ⊆₂' R un-⊆₂ (⊆: P⊆R) = P⊆R -- | Unlifts a function over `⊆₂` to its unwrapped variant over `⊆₂'`. unlift-⊆₂ : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂ Q → R ⊆₂ S ) --------------------- → ( P ⊆₂' Q → R ⊆₂' S ) unlift-⊆₂ f P⊆Q = un-⊆₂ (f (⊆: P⊆Q)) -- | Lifts a function over `⊆₂'` to its wrapped variant over `⊆₂`. lift-⊆₂ : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂' Q → R ⊆₂' S ) --------------------- → ( P ⊆₂ Q → R ⊆₂ S ) lift-⊆₂ f (⊆: P⊆Q) = ⊆: (f P⊆Q) -- | Introduces an equality `⇔₂` from both bi-directional components. ⇔₂-intro : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} → {P : REL A B ℓ₁} {R : REL A B ℓ₂} → P ⊆₂ R → R ⊆₂ P ------ → P ⇔₂ R ⇔₂-intro (⊆: P⊆R) (⊆: R⊆P) = ⇔: P⊆R R⊆P -- | Construct an equality `⇔₂` from a mapping over both bi-directional components. ⇔₂-compose : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂ Q → R ⊆₂ S ) → ( Q ⊆₂ P → S ⊆₂ R ) → P ⇔₂ Q ------------------- → R ⇔₂ S ⇔₂-compose ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₂-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- | Construct a /binary/ equality `⇔₂` from a mapping over both bi-directional components of a /unary/ relation. ⇔₂-compose-⇔₁ : ∀ {a b c ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : REL B C ℓ₃} {S : REL B C ℓ₄} → ( P ⊆₁ Q → R ⊆₂ S ) → ( Q ⊆₁ P → S ⊆₂ R ) → P ⇔₁ Q ------------------- → R ⇔₂ S ⇔₂-compose-⇔₁ ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₂-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- | Construct a /unary/ equalty `⇔₁` from a mapping over both bi-directional components of a /binary/ relation. ⇔₁-compose-⇔₂ : ∀ {a b c ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : Pred C ℓ₃} {S : Pred C ℓ₄} → ( P ⊆₂ Q → R ⊆₁ S ) → ( Q ⊆₂ P → S ⊆₁ R ) → P ⇔₂ Q ------------------- → R ⇔₁ S ⇔₁-compose-⇔₂ ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₁-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- # Properties -- ## Properties: ⊆₂ module _ {a b ℓ : Level} {A : Set a} {B : Set b} {R : REL A B ℓ} where ⊆₂-refl : R ⊆₂ R ⊆₂-refl = ⊆: (λ _ _ Rxy → Rxy) module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} where ⊆₂-trans : P ⊆₂ Q → Q ⊆₂ R → P ⊆₂ R ⊆₂-trans (⊆: P⊆Q) (⊆: Q⊆R) = ⊆: (λ x y Pxy → Q⊆R x y (P⊆Q x y Pxy)) -- ## Properties: ⇔₂ module _ {a b ℓ : Level} {A : Set a} {B : Set b} {R : REL A B ℓ} where ⇔₂-refl : R ⇔₂ R ⇔₂-refl = ⇔₂-intro ⊆₂-refl ⊆₂-refl module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {Q : REL A B ℓ₁} {R : REL A B ℓ₂} where -- | Symmetry of the `_⇔₂_` operation. -- -- -- # Design decision: No Symmetric -- -- Do /not/ use `Symmetric _⇔₂_` as its type. It messes up the universe levels. ⇔₂-sym : Q ⇔₂ R → R ⇔₂ Q ⇔₂-sym (⇔: Q⊆R R⊆Q) = ⇔: R⊆Q Q⊆R module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} where ⇔₂-trans : P ⇔₂ Q → Q ⇔₂ R → P ⇔₂ R ⇔₂-trans (⇔: P⊆Q Q⊆P) (⇔: Q⊆R R⊆Q) = ⇔₂-intro (⊆₂-trans (⊆: P⊆Q) (⊆: Q⊆R)) (⊆₂-trans (⊆: R⊆Q) (⊆: Q⊆P)) -- # Operations -- ## Operations: ⇔₂ and ⊆₂ conversion ⇔₂-to-⊆₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q ------ → P ⊆₂ Q ⇔₂-to-⊆₂ (⇔: P⊆Q _) = ⊆: P⊆Q ⇔₂-to-⊇₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q ------ → Q ⊆₂ P ⇔₂-to-⊇₂ (⇔: _ Q⊆P) = ⊆: Q⊆P -- ## Operations: ⊆₂ ⊆₂-apply : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⊆₂ Q → {x : A} {y : B} → P x y --------------- → Q x y ⊆₂-apply (⊆: P⊆Q) {x} {y} = P⊆Q x y -- | Substitute an equal relation (under `⇔₂`) for the left-hand side of a subset definition. ⊆₂-substˡ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} → P ⇔₂ Q → P ⊆₂ R ------ → Q ⊆₂ R ⊆₂-substˡ (⇔: _ Q⊆P) P⊆R = ⊆₂-trans (⊆: Q⊆P) P⊆R -- | Substitute an equal relation (under `⇔₂`) for the right-hand side of a subset definition. ⊆₂-substʳ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} → Q ⇔₂ R → P ⊆₂ Q ------ → P ⊆₂ R ⊆₂-substʳ (⇔: Q⊆R _) P⊆Q = ⊆₂-trans P⊆Q (⊆: Q⊆R) -- | Weaken intentional equality of relations to their subset `⊆₂` definition. ≡-to-⊆₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → P ⊆₂ Q ≡-to-⊆₂ refl = ⊆: (λ _ _ Pxy → Pxy) -- | Weaken intentional equality of relations to their superset definition (inverted `⊆₂`). ≡-to-⊇₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → Q ⊆₂ P ≡-to-⊇₂ refl = ⊆: (λ _ _ Qxy → Qxy) -- | Substitute both elements of the relation's instantiation. subst-rel : {a b ℓ : Level} → {A : Set a} {B : Set b} → (R : REL A B ℓ) → {x₁ x₂ : A} → x₁ ≡ x₂ → {y₁ y₂ : B} → y₁ ≡ y₂ → R x₁ y₁ ----------------------- → R x₂ y₂ subst-rel _ refl refl Rxy = Rxy -- ## Operations: ⇔₂ ⇔₂-apply-⊆₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → {x : A} {y : B} → P x y --------------- → Q x y ⇔₂-apply-⊆₂ = ⊆₂-apply ∘ ⇔₂-to-⊆₂ ⇔₂-apply-⊇₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → {x : A} {y : B} → Q x y --------------- → P x y ⇔₂-apply-⊇₂ = ⊆₂-apply ∘ ⇔₂-to-⊇₂ ≡-to-⇔₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → P ⇔₂ Q ≡-to-⇔₂ refl = ⇔₂-intro ⊆₂-refl ⊆₂-refl -- # Reasoning -- ## Reasoning: ⊆₂ -- | A collection of functions for writing subset proofs over binary relations. -- -- -- # Example -- -- ``` -- proof P Q R S = -- begin⊆₂ -- (P ⨾ Q) ⨾ (R ⨾ S) -- ⊆₂⟨ ⇔₂-to-⊇₂ ⨾-assoc ⟩ -- ((P ⨾ Q) ⨾ R) ⨾ S -- ⊆₂⟨ ⨾-substˡ-⊆₂ (⇔₂-to-⊆₂ ⨾-assoc) ⟩ -- P ⨾ (Q ⨾ R) ⨾ S -- ⊆₂∎ -- ``` module ⊆₂-Reasoning {a b ℓ₁ : Level} {A : Set a} {B : Set b} where infix 3 _⊆₂∎ infixr 2 step-⊆₂ infix 1 begin⊆₂_ begin⊆₂_ : {ℓ₂ : Level} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⊆₂ Q → P ⊆₂ Q begin⊆₂_ P⊆Q = P⊆Q step-⊆₂ : ∀ {ℓ₂ ℓ₃ : Level} → (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → {R : REL A B ℓ₃} → Q ⊆₂ R → P ⊆₂ Q → P ⊆₂ R step-⊆₂ P Q⊆R P⊆Q = ⊆₂-trans P⊆Q Q⊆R _⊆₂∎ : ∀ (P : REL A B ℓ₁) → P ⊆₂ P _⊆₂∎ P = ⊆: (λ _ _ z → z) syntax step-⊆₂ P Q⊆R P⊆Q = P ⊆₂⟨ P⊆Q ⟩ Q⊆R -- ## Reasoning: ⇔₂ -- | A collection of functions for writing equality proofs over binary relations. -- -- -- # Example -- -- ``` -- proof P Q R S = -- begin⇔₂ -- (P ⨾ Q) ⨾ (R ⨾ S) -- ⇔₂⟨ ⇔₂-sym ⨾-assoc ⟩ -- ((P ⨾ Q) ⨾ R) ⨾ S -- ⇔₂⟨ ⨾-substˡ ⨾-assoc ⟩ -- P ⨾ (Q ⨾ R) ⨾ S -- ⇔₂∎ -- ``` module ⇔₂-Reasoning {a b ℓ₁ : Level} {A : Set a} {B : Set b} where infix 3 _⇔₂∎ infixr 2 _⇔₂⟨⟩_ step-⇔₂ infix 1 begin⇔₂_ begin⇔₂_ : {ℓ₂ : Level} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → P ⇔₂ Q begin⇔₂_ P⇔Q = P⇔Q _⇔₂⟨⟩_ : {ℓ₂ : Level} (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → P ⇔₂ Q → P ⇔₂ Q _ ⇔₂⟨⟩ x≡y = x≡y step-⇔₂ : ∀ {ℓ₂ ℓ₃ : Level} → (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → {R : REL A B ℓ₃} → Q ⇔₂ R → P ⇔₂ Q → P ⇔₂ R step-⇔₂ _ Q⇔R P⇔Q = ⇔₂-trans P⇔Q Q⇔R _⇔₂∎ : ∀ (P : REL A B ℓ₁) → P ⇔₂ P _⇔₂∎ _ = ⇔₂-refl syntax step-⇔₂ P Q⇔R P⇔Q = P ⇔₂⟨ P⇔Q ⟩ Q⇔R
28.579787
118
0.479527
1ae06100f2389d3b0d94f5d54df0f804372a73b3
2,350
agda
Agda
src/Integer.agda
iblech/agda-quotients
1b51e83acf193a556a61d44a4585a6467a383fa3
[ "MIT" ]
1
2021-04-29T13:10:27.000Z
2021-04-29T13:10:27.000Z
src/Integer.agda
iblech/agda-quotients
1b51e83acf193a556a61d44a4585a6467a383fa3
[ "MIT" ]
null
null
null
src/Integer.agda
iblech/agda-quotients
1b51e83acf193a556a61d44a4585a6467a383fa3
[ "MIT" ]
1
2021-04-28T12:49:47.000Z
2021-04-28T12:49:47.000Z
module Integer where open import Data.Nat open import Data.Nat.Properties open import Data.Empty open import Relation.Binary.PropositionalEquality data ℤ₃ : Set where ℤ₊ : ℕ → ℤ₃ ℤ₀ : ℤ₃ ℤ₋ : ℕ → ℤ₃ ℤ₊-injective : ∀ {m n} → ℤ₊ m ≡ ℤ₊ n → m ≡ n ℤ₊-injective refl = refl ℤ₋-injective : ∀ {m n} → ℤ₋ m ≡ ℤ₋ n → m ≡ n ℤ₋-injective refl = refl data ℕ² : Set where _─_ : ℕ → ℕ → ℕ² ℕ²-≡₊ : ∀ {a₊ a₋ b₊ b₋} → (a₊ ─ a₋) ≡ (b₊ ─ b₋) → a₊ ≡ b₊ ℕ²-≡₊ refl = refl ℕ²-≡₋ : ∀ {a₊ a₋ b₊ b₋} → (a₊ ─ a₋) ≡ (b₊ ─ b₋) → a₋ ≡ b₋ ℕ²-≡₋ refl = refl toℕ² : ℤ₃ → ℕ² toℕ² (ℤ₊ n) = suc n ─ zero toℕ² ℤ₀ = zero ─ zero toℕ² (ℤ₋ n) = zero ─ suc n toℤ₃ : ℕ² → ℤ₃ toℤ₃ (zero ─ zero) = ℤ₀ toℤ₃ (zero ─ suc n₋) = ℤ₋ n₋ toℤ₃ (suc n₊ ─ zero) = ℤ₊ n₊ toℤ₃ (suc n₊ ─ suc n₋) = toℤ₃ (n₊ ─ n₋) data Dec (A : Set) : Set where yes : A → Dec A no : (A → ⊥) → Dec A ℕ≡? : (m n : ℕ) → Dec (m ≡ n) ℕ≡? zero zero = yes refl ℕ≡? zero (suc n) = no (λ ()) ℕ≡? (suc m) zero = no (λ ()) ℕ≡? (suc m) (suc n) with ℕ≡? m n ... | yes m≡n = yes (cong suc m≡n) ... | no ¬m≡n = no λ sm≡sn → ¬m≡n (suc-injective sm≡sn) ℤ₃≡? : (a b : ℤ₃) → Dec (a ≡ b) ℤ₃≡? (ℤ₊ m) (ℤ₊ n) with ℕ≡? m n ... | yes m≡n = yes (cong ℤ₊ m≡n) ... | no ¬m≡n = no λ ℤ₊m≡ℤ₊n → ¬m≡n (ℤ₊-injective ℤ₊m≡ℤ₊n) ℤ₃≡? (ℤ₊ _) ℤ₀ = no (λ ()) ℤ₃≡? (ℤ₊ _) (ℤ₋ _) = no (λ ()) ℤ₃≡? ℤ₀ (ℤ₊ _) = no (λ ()) ℤ₃≡? ℤ₀ ℤ₀ = yes refl ℤ₃≡? ℤ₀ (ℤ₋ _) = no (λ ()) ℤ₃≡? (ℤ₋ _) (ℤ₊ _) = no (λ ()) ℤ₃≡? (ℤ₋ _) ℤ₀ = no (λ ()) ℤ₃≡? (ℤ₋ m) (ℤ₋ n) with ℕ≡? m n ... | yes m≡n = yes (cong ℤ₋ m≡n) ... | no ¬m≡n = no λ ℤ₋m≡ℤ₋n → ¬m≡n (ℤ₋-injective ℤ₋m≡ℤ₋n) ℕ²≡? : (a b : ℕ²) → Dec (a ≡ b) ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) with ℕ≡? a₊ b₊ ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl with ℕ≡? a₋ b₋ ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl | yes refl = yes refl ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | yes refl | no ¬a₋≡b₋ = no (λ a≡b → ¬a₋≡b₋ (ℕ²-≡₋ a≡b)) ℕ²≡? (a₊ ─ a₋) (b₊ ─ b₋) | no ¬a₊≡b₊ = no λ a≡b → ¬a₊≡b₊ (ℕ²-≡₊ a≡b) _≃_ : ℕ² → ℕ² → Set (a₊ ─ a₋) ≃ (b₊ ─ b₋) = a₊ + b₋ ≡ a₋ + b₊ ≃? : (a b : ℕ²) → Dec (a ≃ b) ≃? (a₊ ─ a₋) (b₊ ─ b₋) = ℕ≡? (a₊ + b₋) (a₋ + b₊) _+₂_ : ℕ² → ℕ² → ℕ² (a₊ ─ a₋) +₂ (b₊ ─ b₋) = (a₊ + b₊) ─ (a₋ + b₋) {- ≃-cong : {A : Set} {a b : ℕ²} (f : ℕ² → ℕ²) → a ≃ b → f a ≃ f b ≃-cong f a≃b = {!!} -} drop-neg : ℕ² → ℕ² drop-neg (a₊ ─ _) = (a₊ ─ zero) 3-5≃2-4 : (3 ─ 5) ≃ (2 ─ 4) 3-5≃2-4 = refl _+₃_ : ℤ₃ → ℤ₃ → ℤ₃ a +₃ b = toℤ₃ (toℕ² a +₂ toℕ² b)
23.979592
63
0.429787
9adc90b1de6c4cbc7aa350504c770d5912987b96
1,912
agda
Agda
old/Tests/Numeral.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
old/Tests/Numeral.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
old/Tests/Numeral.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Test.Numeral where import Lvl open import Relator.Equals{Lvl.𝟎} module One where test0 : (0 mod 1) ≡ 0 test0 = [≡]-intro test1 : (1 mod 1) ≡ 0 test1 = [≡]-intro test2 : (2 mod 1) ≡ 0 test2 = [≡]-intro test3 : (3 mod 1) ≡ 0 test3 = [≡]-intro test4 : (4 mod 1) ≡ 0 test4 = [≡]-intro test5 : (5 mod 1) ≡ 0 test5 = [≡]-intro test6 : (6 mod 1) ≡ 0 test6 = [≡]-intro test7 : (7 mod 1) ≡ 0 test7 = [≡]-intro test8 : (8 mod 1) ≡ 0 test8 = [≡]-intro test9 : (9 mod 1) ≡ 0 test9 = [≡]-intro test10 : (10 mod 1) ≡ 0 test10 = [≡]-intro test11 : (11 mod 1) ≡ 0 test11 = [≡]-intro module Two where test0 : (0 mod 2) ≡ 0 test0 = [≡]-intro test1 : (1 mod 2) ≡ 1 test1 = [≡]-intro test2 : (2 mod 2) ≡ 0 test2 = [≡]-intro test3 : (3 mod 2) ≡ 1 test3 = [≡]-intro test4 : (4 mod 2) ≡ 0 test4 = [≡]-intro test5 : (5 mod 2) ≡ 1 test5 = [≡]-intro test6 : (6 mod 2) ≡ 0 test6 = [≡]-intro test7 : (7 mod 2) ≡ 1 test7 = [≡]-intro test8 : (8 mod 2) ≡ 0 test8 = [≡]-intro test9 : (9 mod 2) ≡ 1 test9 = [≡]-intro test10 : (10 mod 2) ≡ 0 test10 = [≡]-intro test11 : (11 mod 2) ≡ 1 test11 = [≡]-intro module Three where test0 : (0 mod 3) ≡ 0 test0 = [≡]-intro test1 : (1 mod 3) ≡ 1 test1 = [≡]-intro test2 : (2 mod 3) ≡ 2 test2 = [≡]-intro test3 : (3 mod 3) ≡ 0 test3 = [≡]-intro test4 : (4 mod 3) ≡ 1 test4 = [≡]-intro test5 : (5 mod 3) ≡ 2 test5 = [≡]-intro test6 : (6 mod 3) ≡ 0 test6 = [≡]-intro test7 : (7 mod 3) ≡ 1 test7 = [≡]-intro test8 : (8 mod 3) ≡ 2 test8 = [≡]-intro test9 : (9 mod 3) ≡ 0 test9 = [≡]-intro test10 : (10 mod 3) ≡ 1 test10 = [≡]-intro test11 : (11 mod 3) ≡ 2 test11 = [≡]-intro
16.626087
33
0.458159
1ab007ec17c1357084d8815f7a93e76c4b88ab9f
784
agda
Agda
test/epic/Prelude/Nat.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/epic/Prelude/Nat.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/epic/Prelude/Nat.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module Prelude.Nat where open import Prelude.Bool {-# IMPORT PrimNat #-} data Nat : Set where Z : Nat S : Nat -> Nat {-# BUILTIN NATURAL Nat #-} {-# BUILTIN ZERO Z #-} {-# BUILTIN SUC S #-} {-# COMPILED_DATA Nat PrimNat.N PrimNat.Z PrimNat.S #-} infixl 30 _+_ _+_ : Nat -> Nat -> Nat Z + m = m S n + m = S (n + m) _*_ : Nat -> Nat -> Nat Z * m = Z S n * m = (n * m) + m _-_ : Nat -> Nat -> Nat n - Z = n (S n) - (S m) = n - m Z - _ = Z _<_ : Nat -> Nat -> Bool _ < Z = false Z < S _ = true S n < S m = n < m Nid : Nat -> Bool -> Bool Nid Z true = true Nid Z false = false Nid (S n) m = (Nid n ( m)) {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATTIMES _*_ #-} {-# BUILTIN NATMINUS _-_ #-} -- {-# BUILTIN NATLESS _<_ #-} -- {-# BUILTIN NATEQUALS __ #-}
17.043478
55
0.51148
9a25c54e74a887e41bfcb5c6c97565ff919f26b4
3,064
agda
Agda
lib/groups/PropSubgroup.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
lib/groups/PropSubgroup.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
lib/groups/PropSubgroup.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NType2 open import lib.types.Group open import lib.types.Sigma open import lib.types.Truncation open import lib.groups.Homomorphisms module lib.groups.PropSubgroup where module _ {i} (G : Group i) where private module G = Group G module PropSubgroup {j} (P : G.El → Type j) (P-level : ∀ g → has-level ⟨-1⟩ (P g)) (P-ident : P G.ident) (P-inv : ∀ {g} → P g → P (G.inv g)) (P-comp : ∀ {g₁ g₂} → P g₁ → P g₂ → P (G.comp g₁ g₂)) where struct : GroupStructure (Σ G.El P) struct = record { ident = (G.ident , P-ident); inv = λ {(g , p) → (G.inv g , P-inv p)}; comp = λ {(g₁ , p₁) (g₂ , p₂) → (G.comp g₁ g₂ , P-comp p₁ p₂)}; unitl = λ {(g , _) → pair= (G.unitl g) (prop-has-all-paths-↓ (P-level _))}; unitr = λ {(g , _) → pair= (G.unitr g) (prop-has-all-paths-↓ (P-level _))}; assoc = λ {(g₁ , _) (g₂ , _) (g₃ , _) → pair= (G.assoc g₁ g₂ g₃) (prop-has-all-paths-↓ (P-level _))}; invl = λ {(g , _) → pair= (G.invl g) (prop-has-all-paths-↓ (P-level _))}; invr = λ {(g , _) → pair= (G.invr g) (prop-has-all-paths-↓ (P-level _))}} Subgroup : Group (lmax i j) Subgroup = group _ (Σ-level G.El-level (raise-level _ ∘ P-level)) struct inj : Subgroup →ᴳ G inj = record { f = λ {(g , _) → g}; pres-comp = λ _ _ → idp} module _ {j} {H : Group j} (φ : H →ᴳ G) where private module H = Group H module φ = GroupHom φ prop-hom : Π H.El (P ∘ φ.f) → (H →ᴳ Subgroup) prop-hom p = record { f = λ g → (φ.f g , p g); pres-comp = λ g₁ g₂ → pair= (φ.pres-comp g₁ g₂) (prop-has-all-paths-↓ (P-level _))} module _ {i} {j} {G : Group i} {H : Group j} (φ : G →ᴳ H) where private module G = Group G module H = Group H module φ = GroupHom φ module Ker = PropSubgroup G (λ g → φ.f g == H.ident) (λ g → H.El-level _ _) φ.pres-ident (λ p → φ.pres-inv _ ∙ ap H.inv p ∙ group-inv-ident H) (λ p₁ p₂ → φ.pres-comp _ _ ∙ ap2 H.comp p₁ p₂ ∙ H.unitl _) module Im = PropSubgroup H (λ h → Trunc ⟨-1⟩ (Σ G.El (λ g → φ.f g == h))) (λ h → Trunc-level) ([ G.ident , φ.pres-ident ]) (Trunc-fmap (λ {(g , p) → (G.inv g , φ.pres-inv g ∙ ap H.inv p)})) (Trunc-fmap2 (λ {(g₁ , p₁) (g₂ , p₂) → (G.comp g₁ g₂ , φ.pres-comp g₁ g₂ ∙ ap2 H.comp p₁ p₂)})) open Ker public renaming (struct to ker-struct; Subgroup to Ker; inj to ker-inj; prop-hom to ker-hom) open Im public renaming (struct to im-struct; Subgroup to Im; inj to im-inj; prop-hom to im-out-hom) im-in-hom : G →ᴳ Im im-in-hom = record { f = λ g → (φ.f g , [ g , idp ]); pres-comp = λ g₁ g₂ → pair= (φ.pres-comp g₁ g₂) (prop-has-all-paths-↓ Trunc-level)} im-in-surj : (h : Group.El Im) → Trunc ⟨-1⟩ (Σ G.El (λ g → GroupHom.f im-in-hom g == h)) im-in-surj (_ , s) = Trunc-fmap (λ {(g , p) → (g , pair= p (prop-has-all-paths-↓ Trunc-level))}) s
31.916667
77
0.527089
8b16b8ac024729d3b450378d5f98d0334945af97
9,246
agda
Agda
src/StateSizedIO/GUI/WxBindingsFFI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
2
2020-07-31T15:37:39.000Z
2020-07-31T17:20:59.000Z
src/StateSizedIO/GUI/WxBindingsFFI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
null
null
null
src/StateSizedIO/GUI/WxBindingsFFI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
null
null
null
module StateSizedIO.GUI.WxBindingsFFI where open import Data.Bool.Base open import Data.Integer open import Data.Nat open import Data.Product hiding (map) open import NativeIO {-# FOREIGN GHC import qualified GHC.Conc.Sync #-} {-# FOREIGN GHC import qualified Control.Concurrent #-} {-# FOREIGN GHC import qualified Data.IORef #-} {-# FOREIGN GHC import qualified Graphics.UI.WX #-} {-# FOREIGN GHC import qualified Graphics.UI.WX.Timer #-} {-# FOREIGN GHC import qualified Graphics.UI.WXCore #-} {-# FOREIGN GHC import qualified Graphics.UI.WXCore.Events #-} postulate Frame : Set {-# COMPILE GHC Frame = type (Graphics.UI.WX.Frame ()) #-} postulate Button : Set {-# COMPILE GHC Button = type (Graphics.UI.WX.Button ()) #-} postulate TextCtrl : Set {-# COMPILE GHC TextCtrl = type (Graphics.UI.WX.TextCtrl ()) #-} postulate Timer : Set {-# COMPILE GHC Timer = type Graphics.UI.WX.Timer.Timer #-} postulate nativeNewFrame : String -> NativeIO Frame {-# COMPILE GHC nativeNewFrame = (\s -> Graphics.UI.WX.frame [Graphics.UI.WX.text Graphics.UI.WX.:= "Window"]) #-} -- -- Frame Layout -- {-# FOREIGN GHC setChildrenLayout' :: Graphics.UI.WX.Frame () -> Integer -> Integer -> Integer -> Integer -> IO () setChildrenLayout' win rowWidth' marginWidth' vspa' hspa' = do let rowWidth = fromIntegral rowWidth' let marginWidth = fromIntegral marginWidth' let vspa = fromIntegral vspa' let hspa = fromIntegral hspa' let list2Matrix n xs = map (\(x ,y)-> (take n) $ (drop (n*x)) y) $ zip [0..] $ replicate (div (length xs) n) xs blist <- Graphics.UI.WXCore.windowChildren win putStrLn ("Layout of frame, got " ++ (show $ length $ blist) ++ "children") let blist' = list2Matrix rowWidth blist let blist'' = (map . map) Graphics.UI.WX.widget blist' Graphics.UI.WX.set win [ Graphics.UI.WX.layout Graphics.UI.WX.:= Graphics.UI.WX.margin marginWidth $ Graphics.UI.WX.dynamic $ Graphics.UI.WX.grid vspa hspa $ blist''] #-} postulate nativeSetChildredLayout : Frame → ℕ → ℕ → ℕ → ℕ → NativeIO Unit {-# COMPILE GHC nativeSetChildredLayout = setChildrenLayout' #-} postulate nativeDoThreadDelay : NativeIO Bool {-# COMPILE GHC nativeDoThreadDelay = ((Control.Concurrent.threadDelay 100) >>= (\x -> return True)) #-} postulate nativeSetIdle : Frame -> NativeIO Bool -> NativeIO Unit {-# COMPILE GHC nativeSetIdle = (\fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.idle Graphics.UI.WX.:= prog]) #-} nativeCreateFrame : NativeIO Frame nativeCreateFrame = nativeNewFrame "Start Text" native>>= (\f -> nativeSetIdle f nativeDoThreadDelay native>>= (\x -> nativeReturn f)) postulate nativeMakeButton : Frame → String → NativeIO Button {-# COMPILE GHC nativeMakeButton = (\myFrame str -> Graphics.UI.WX.button myFrame [Graphics.UI.WX.text Graphics.UI.WX.:= (Data.Text.unpack str)]) #-} postulate nativeMakeTextCtrl : Frame → String → NativeIO TextCtrl {-# COMPILE GHC nativeMakeTextCtrl = (\myFrame str -> Graphics.UI.WX.entry myFrame [Graphics.UI.WX.text Graphics.UI.WX.:= (Data.Text.unpack str)]) #-} postulate nativeAddButton : Frame → Button → NativeIO Unit {-# COMPILE GHC nativeAddButton = (\myFrame bt -> Graphics.UI.WX.set myFrame [Graphics.UI.WX.layout Graphics.UI.WX.:= Graphics.UI.WX.minsize (Graphics.UI.WX.sz 500 400) $ Graphics.UI.WX.column 1 [Graphics.UI.WX.hfill (Graphics.UI.WX.widget bt)]]) #-} postulate WxColor : Set {-# COMPILE GHC WxColor = type Graphics.UI.WX.Color #-} postulate nativeSetColorButton : Button → WxColor → NativeIO Unit {-# COMPILE GHC nativeSetColorButton = (\ bt co -> Graphics.UI.WX.set bt [ Graphics.UI.WX.color Graphics.UI.WX.:= co] ) #-} postulate nativeSetColorTextCtrl : TextCtrl → WxColor → NativeIO Unit {-# COMPILE GHC nativeSetColorTextCtrl = (\ txt co -> Graphics.UI.WX.set txt [ Graphics.UI.WX.color Graphics.UI.WX.:= co] ) #-} postulate rgb : ℕ → ℕ → ℕ → WxColor {-# COMPILE GHC rgb = (\ r b g -> Graphics.UI.WX.rgb r g b) #-} postulate TVar : Set → Set {-# COMPILE GHC TVar = type Control.Concurrent.STM.TVar.TVar #-} postulate MVar : Set → Set {-# COMPILE GHC MVar = type Control.Concurrent.MVar #-} Var : Set → Set Var = MVar postulate nativeNewVar : {A : Set} → A → NativeIO (Var A) nativeTakeVar : {A : Set} → Var A → NativeIO A nativePutVar : {A : Set} → Var A → A → NativeIO Unit {-# COMPILE GHC nativeNewVar = (\ _ -> Control.Concurrent.newMVar ) #-} {-# COMPILE GHC nativeTakeVar = (\ _ -> Control.Concurrent.takeMVar ) #-} {-# COMPILE GHC nativePutVar = (\ _ -> Control.Concurrent.putMVar ) #-} -- Fire Custom Event -- postulate nativeFireCustomEvent : Frame → NativeIO Unit {-# COMPILE GHC nativeFireCustomEvent = (\f -> Graphics.UI.WXCore.commandEventCreate Graphics.UI.WXCore.wxEVT_COMMAND_MENU_SELECTED (Graphics.UI.WXCore.wxID_HIGHEST+1) >>= (\ev -> fmap (\x -> ()) (Graphics.UI.WXCore.evtHandlerProcessEvent f ev))) #-} postulate nativeRegisterCustomEvent : Frame → NativeIO Unit → NativeIO Unit {-# COMPILE GHC nativeRegisterCustomEvent = (\win prog -> Graphics.UI.WXCore.evtHandlerOnMenuCommand win (Graphics.UI.WXCore.wxID_HIGHEST+1) (putStrLn " >>> CUSTOM EVENT FIRED <<<" >> Control.Concurrent.forkIO prog >> return ())) #-} {- for debugging postulate nativeRegisterDummyCustomEvent : Frame → NativeIO Unit {-# COMPILE GHC nativeRegisterDummyCustomEvent = (\win -> Graphics.UI.WXCore.evtHandlerOnMenuCommand win (Graphics.UI.WXCore.wxID_HIGHEST+1) (putStrLn " >>> CUSTOM EVENT FIRED <<<")) #-} -} postulate nativeSetButtonHandler : Button → NativeIO Unit → NativeIO Unit {-# COMPILE GHC nativeSetButtonHandler = (\ bt prog -> Graphics.UI.WX.set bt [Graphics.UI.WX.on Graphics.UI.WX.command Graphics.UI.WX.:= prog ]) #-} postulate prog : NativeIO Unit {-# COMPILE GHC prog = (putStrLn "timer goes off!") #-} postulate nativeSetTimer : Frame → ℤ → NativeIO Unit → NativeIO Timer {-# COMPILE GHC nativeSetTimer = (\ fra x prog -> Graphics.UI.WX.timer fra [ Graphics.UI.WX.interval Graphics.UI.WX.:= (fromInteger x) , Graphics.UI.WX.on Graphics.UI.WX.command Graphics.UI.WX.:= prog ]) #-} postulate ThreadId : Set {-# COMPILE GHC ThreadId = type GHC.Conc.Sync.ThreadId #-} postulate forkIO : NativeIO Unit → NativeIO ThreadId {-# COMPILE GHC forkIO = GHC.Conc.Sync.forkIO #-} postulate Bitmap : Set {-# COMPILE GHC Bitmap = type (Graphics.UI.WXCore.Bitmap ()) #-} postulate bitmap : String → Bitmap {-# COMPILE GHC bitmap = (\s -> Graphics.UI.WX.bitmap (Data.Text.unpack s)) #-} postulate DC : Set {-# COMPILE GHC DC = type (Graphics.UI.WXCore.DC ()) #-} postulate Rect : Set {-# COMPILE GHC Rect = type Graphics.UI.WXCore.Rect #-} postulate nativeSetClickRight : Frame → NativeIO Unit → NativeIO Unit {-# COMPILE GHC nativeSetClickRight = (\ fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.clickRight Graphics.UI.WX.:= (\x -> prog)]) #-} postulate nativeSetOnPaint : Frame → (DC → Rect → NativeIO Unit) → NativeIO Unit {-# COMPILE GHC nativeSetOnPaint = (\ fra prog -> Graphics.UI.WX.set fra [Graphics.UI.WX.on Graphics.UI.WX.paint Graphics.UI.WX.:= prog]) #-} postulate nativeRepaint : Frame → NativeIO Unit {-# COMPILE GHC nativeRepaint = Graphics.UI.WX.repaint #-} Point : Set Point = (ℤ × ℤ) postulate NativePoint : Set {-# COMPILE GHC NativePoint = type Graphics.UI.WXCore.Point #-} postulate nativePoint : ℤ → ℤ → NativePoint {-# COMPILE GHC nativePoint = (\ x y -> Graphics.UI.WXCore.point (fromInteger x) (fromInteger y)) #-} postulate nativeDrawBitmapNativePoint : DC → Bitmap → NativePoint → Bool → NativeIO Unit {-# COMPILE GHC nativeDrawBitmapNativePoint = (\ d bi p bo -> Graphics.UI.WX.drawBitmap d bi p bo [] ) #-} nativeDrawBitmap : DC → Bitmap → Point → Bool → NativeIO Unit nativeDrawBitmap d bi (x , y) bo = nativeDrawBitmapNativePoint d bi (nativePoint x y) bo {-# FOREIGN GHC import Graphics.UI.WXCore.WxcClassesAL #-} postulate nativeBitmapGetWidth : Bitmap → NativeIO ℤ {-# COMPILE GHC nativeBitmapGetWidth = (\ b -> fmap fromIntegral (Graphics.UI.WXCore.WxcClassesAL.bitmapGetWidth b)) #-} postulate start : NativeIO Unit → NativeIO Unit {-# COMPILE GHC start = Graphics.UI.WX.start #-} -- -- Note: we add the "key pressed" event to a button -- and not to a frame, because of a bug in wxHaskell that prevents -- adding a key pressed event to a frame (at least on linux plattforms). -- postulate Key : Set showKey : Key -> String nativeSetKeyHandler : Button → (Key → NativeIO Unit) → NativeIO Unit {-# COMPILE GHC Key = type Graphics.UI.WXCore.Events.Key #-} {-# COMPILE GHC showKey = (\ k -> (Data.Text.pack (Graphics.UI.WXCore.Events.showKey k))) #-} {-# COMPILE GHC nativeSetKeyHandler = (\bt prog -> Graphics.UI.WX.set bt [Graphics.UI.WX.on Graphics.UI.WX.anyKey Graphics.UI.WX.:= prog]) #-} -- -- Delete Objects -- -- note: can be solved with instance arguments in the future postulate objectDeleteFrame : Frame → NativeIO Unit {-# COMPILE GHC objectDeleteFrame = (\f -> Graphics.UI.WX.objectDelete f) #-} postulate nativeDeleteButton : Button → NativeIO Unit {-# COMPILE GHC nativeDeleteButton = (\f -> Graphics.UI.WX.objectDelete f) #-} postulate nativeDeleteTextCtrl : TextCtrl → NativeIO Unit {-# COMPILE GHC nativeDeleteTextCtrl = (\f -> Graphics.UI.WX.objectDelete f) #-}
37.282258
250
0.706576
1e2955d7e51f659cfa8a842b35c6c6c81c96b3fe
681
agda
Agda
src/Categories/Category/Restriction/Construction/Trivial.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Restriction/Construction/Trivial.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Restriction/Construction/Trivial.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} -- Any category can be made into a trivial restriction category module Categories.Category.Restriction.Construction.Trivial where open import Level using (Level) open import Categories.Category.Core using (Category) open import Categories.Category.Restriction using (Restriction) open import Categories.Morphism.Reasoning.Core using (id-comm-sym) private variable o ℓ e : Level Trivial : (C : Category o ℓ e) → Restriction C Trivial C = record { _↓ = λ _ → id ; pidʳ = identityʳ ; ↓-comm = Equiv.refl ; ↓-denestʳ = Equiv.sym identity² ; ↓-skew-comm = id-comm-sym C ; ↓-cong = λ _ → Equiv.refl } where open Category C
25.222222
66
0.709251
0391b6a15c96ffba4646463b46b2509fb1d4e05a
479
agda
Agda
test/Fail/Issue676.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue676.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue676.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue676 where data Bool : Set where true false : Bool data ⊥ : Set where data Silly A : Set where [_] : A → Silly A fail : ⊥ → Silly A -- This shouldn't be projection-like since the second clause won't reduce. unsillify : ∀ {A} → Silly A → A unsillify [ x ] = x unsillify (fail ()) data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x -- Triggers an __IMPOSSIBLE__ if unsillify is projection like. bad : (x : ⊥) → unsillify (fail x) ≡ true bad x = refl
19.958333
74
0.632568
59239d2bfb4590f3c574c14326a4560a522bf7c8
1,028
agda
Agda
test/asset/agda-stdlib-1.0/Data/Bool/Solver.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Bool/Solver.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Bool/Solver.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Automatic solvers for equations over booleans ------------------------------------------------------------------------ -- See README.Nat for examples of how to use similar solvers {-# OPTIONS --without-K --safe #-} module Data.Bool.Solver where import Algebra.Solver.Ring.Simple as Solver import Algebra.Solver.Ring.AlmostCommutativeRing as ACR open import Data.Bool using (_≟_) open import Data.Bool.Properties ------------------------------------------------------------------------ -- A module for automatically solving propositional equivalences -- containing _∨_ and _∧_ module ∨-∧-Solver = Solver (ACR.fromCommutativeSemiring ∨-∧-commutativeSemiring) _≟_ ------------------------------------------------------------------------ -- A module for automatically solving propositional equivalences -- containing _xor_ and _∧_ module xor-∧-Solver = Solver (ACR.fromCommutativeRing xor-∧-commutativeRing) _≟_
33.16129
72
0.551556
1378e360fc9a88c54845b45e122a2e7cc8c54b14
5,337
agda
Agda
Cubical/Experiments/ZCohomology/Benchmarks.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomology/Benchmarks.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Experiments/ZCohomology/Benchmarks.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
{- Please do not move this file. Changes should only be made if necessary. This file contains benchmarks for the paper: Synthetic Cohomology Theory in Cubical Agda Command to run the benchmarks and get timings: agda -v profile.definitions:10 Benchmarks.agda This assumes that there is no Benchmarks.agdai file. If there is one, then it should be removed before the above command is run. -} {-# OPTIONS --no-exact-split --safe #-} module Cubical.Experiments.ZCohomology.Benchmarks where open import Cubical.Foundations.Everything open import Cubical.Data.Nat open import Cubical.Data.Bool open import Cubical.Data.Int open import Cubical.HITs.Sn open import Cubical.Algebra.Group hiding (ℤ ; Bool) open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.Properties open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Groups.Sn open import Cubical.ZCohomology.Groups.Wedge open import Cubical.ZCohomology.Groups.Torus open import Cubical.ZCohomology.Groups.KleinBottle open import Cubical.ZCohomology.Groups.WedgeOfSpheres open import Cubical.ZCohomology.Groups.RP2 open import Cubical.Data.Sigma open import Cubical.HITs.KleinBottle open import Cubical.HITs.RPn.Base open IsGroupHom open Iso -- S¹ (everything fast) module S1-tests where ϕ : coHom 1 (S₊ 1) → ℤ ϕ = fun (fst (Hⁿ-Sⁿ≅ℤ 0)) ϕ⁻¹ : ℤ → coHom 1 (S₊ 1) ϕ⁻¹ = inv (fst (Hⁿ-Sⁿ≅ℤ 0)) test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 30ms test₁ = refl test₂ : ϕ (ϕ⁻¹ 1) ≡ 1 -- <10ms test₂ = refl test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- <10ms test₃ = refl test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 10ms test₄ = refl test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- 11ms test₅ = refl test₆ : ϕ (ϕ⁻¹ -3 +ₕ ϕ⁻¹ 4) ≡ 1 -- 29ms test₆ = refl test₇ : ϕ (ϕ⁻¹ -5 +ₕ ϕ⁻¹ -2) ≡ -7 -- 28ms test₇ = refl -- S² module S2-tests where ϕ : coHom 2 (S₊ 2) → ℤ ϕ = fun (fst (Hⁿ-Sⁿ≅ℤ 1)) ϕ⁻¹ : ℤ → coHom 2 (S₊ 2) ϕ⁻¹ = inv (fst (Hⁿ-Sⁿ≅ℤ 1)) test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 13ms test₁ = refl test₂ : ϕ (ϕ⁻¹ 1) ≡ 1 -- 16ms test₂ = refl test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 278ms test₃ = refl test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 290ms test₄ = refl {- test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- nope test₅ = refl test₆ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 1) ≡ 2 -- nope test₆ = refl test₇ : ϕ (ϕ⁻¹ 2 +ₕ ϕ⁻¹ 4) ≡ 6 -- nope test₇ = refl -} module S1∨S1∨S2-tests₁ where -- everything fast ϕ : coHom 1 S²⋁S¹⋁S¹ → ℤ × ℤ ϕ = fun (fst H¹-S²⋁S¹⋁S¹) ϕ⁻¹ : ℤ × ℤ → coHom 1 S²⋁S¹⋁S¹ ϕ⁻¹ = inv (fst H¹-S²⋁S¹⋁S¹) test₁ : ϕ (ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- <10ms test₁ = refl test₂ : ϕ (ϕ⁻¹ (3 , 1)) ≡ (3 , 1) -- 21ms test₂ = refl test₃ : ϕ (ϕ⁻¹ (0 , 0) +ₕ ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- 15ms test₃ = refl test₄ : ϕ (ϕ⁻¹ (0 , 1) +ₕ ϕ⁻¹ (1 , 0)) ≡ (1 , 1) -- 21ms test₄ = refl test₅ : ϕ (ϕ⁻¹ (3 , 2) +ₕ ϕ⁻¹ (-1 , 5)) ≡ (2 , 7) -- 47ms test₅ = refl module S1∨S1∨S2-tests₂ where ϕ : coHom 2 S²⋁S¹⋁S¹ → ℤ ϕ = fun (fst H²-S²⋁S¹⋁S¹) ϕ⁻¹ : ℤ → coHom 2 S²⋁S¹⋁S¹ ϕ⁻¹ = inv (fst H²-S²⋁S¹⋁S¹) test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 157ms test₁ = refl test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 119ms test₂ = refl test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 1,820ms test₃ = refl module Torus-test₁ where -- fast ϕ : coHom 1 (S₊ 1 × S₊ 1) → ℤ × ℤ ϕ = fun (fst H¹-T²≅ℤ×ℤ) ϕ⁻¹ : ℤ × ℤ → coHom 1 (S₊ 1 × S₊ 1) ϕ⁻¹ = inv (fst H¹-T²≅ℤ×ℤ) test₁ : ϕ (ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- <10ms test₁ = refl test₂ : ϕ (ϕ⁻¹ (3 , 1)) ≡ (3 , 1) -- 18ms test₂ = refl test₃ : ϕ (ϕ⁻¹ (0 , 0) +ₕ ϕ⁻¹ (0 , 0)) ≡ (0 , 0) -- 15ms test₃ = refl test₄ : ϕ (ϕ⁻¹ (0 , 1) +ₕ ϕ⁻¹ (1 , 0)) ≡ (1 , 1) -- 20ms test₄ = refl test₅ : ϕ (ϕ⁻¹ (-3 , 2) +ₕ ϕ⁻¹ (-1 , 5)) ≡ (-4 , 7) -- 44ms test₅ = refl module Torus-test₂ where ϕ : coHom 2 (S₊ 1 × S₊ 1) → ℤ ϕ = fun (fst H²-T²≅ℤ) ϕ⁻¹ : ℤ → coHom 2 (S₊ 1 × S₊ 1) ϕ⁻¹ = inv (fst H²-T²≅ℤ) test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- 121ms test₁ = refl test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 142ms test₂ = refl test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- 3,674ms test₃ = refl test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 3,772ms test₄ = refl {- test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- nope test₅ = refl -} module Klein-test₁ where -- fast ϕ : coHom 1 KleinBottle → ℤ ϕ = fun (fst H¹-𝕂²≅ℤ) ϕ⁻¹ : ℤ → coHom 1 KleinBottle ϕ⁻¹ = inv (fst H¹-𝕂²≅ℤ) test₁ : ϕ (ϕ⁻¹ 0) ≡ 0 -- <10ms test₁ = refl test₂ : ϕ (ϕ⁻¹ 3) ≡ 3 -- 12ms test₂ = refl test₃ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 0) ≡ 0 -- <10ms test₃ = refl test₄ : ϕ (ϕ⁻¹ 0 +ₕ ϕ⁻¹ 1) ≡ 1 -- 11ms test₄ = refl test₅ : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 0) ≡ 1 -- 12ms test₅ = refl test₆ : ϕ (ϕ⁻¹ -3 +ₕ ϕ⁻¹ 4) ≡ 1 -- 29ms test₆ = refl test₇ : ϕ (ϕ⁻¹ -5 +ₕ ϕ⁻¹ -2) ≡ -7 -- 29ms test₇ = refl -- The example in the paper: test : ϕ (ϕ⁻¹ 1 +ₕ ϕ⁻¹ 2) ≡ 3 -- 15ms test = refl module Klein-test₂ where ϕ : coHom 2 KleinBottle → Bool ϕ = fun (fst H²-𝕂²≅Bool) ϕ⁻¹ : Bool → coHom 2 KleinBottle ϕ⁻¹ = inv (fst H²-𝕂²≅Bool) {- test₀ : ϕ (0ₕ _) ≡ true -- fails already here... test₀ = refl -} module RP2-test₂ where ϕ : coHom 2 RP² → Bool ϕ = fun (fst H²-RP²≅Bool) ϕ⁻¹ : Bool → coHom 2 RP² ϕ⁻¹ = inv (fst H²-RP²≅Bool) test₀ : ϕ (0ₕ _) ≡ true -- 1,210ms (unlike for Klein, this works) test₀ = refl {- test₁ : ϕ (ϕ⁻¹ true) ≡ true -- nope test₁ = refl -}
20.526923
70
0.556118
22126a4f61bb9a222a6faad8dd19f4057b84543d
16,785
agda
Agda
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/UniversalProperty.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
-- We define what it means to satisfy the universal property -- of localisation and show that the localisation in Base satisfies -- it. We will also show that the localisation is uniquely determined -- by the universal property, and give sufficient criteria for -- satisfying the universal property. {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.CommRing.Localisation.UniversalProperty where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Foundations.Transport open import Cubical.Functions.FunExtEquiv open import Cubical.Functions.Surjection open import Cubical.Functions.Embedding import Cubical.Data.Empty as ⊥ open import Cubical.Data.Bool open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.Vec open import Cubical.Data.Sigma.Base open import Cubical.Data.Sigma.Properties open import Cubical.Data.FinData open import Cubical.Relation.Nullary open import Cubical.Relation.Binary open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Localisation.Base open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT open Iso private variable ℓ ℓ' : Level module _ (R' : CommRing {ℓ}) (S' : ℙ (R' .fst)) (SMultClosedSubset : isMultClosedSubset R' S') where open isMultClosedSubset private R = R' .fst open CommRingStr (R' .snd) hiding (is-set) open Theory (CommRing→Ring R') open RingHom hasLocUniversalProp : (A : CommRing {ℓ}) (φ : CommRingHom R' A) → (∀ s → s ∈ S' → f φ s ∈ A ˣ) → Type (ℓ-suc ℓ) hasLocUniversalProp A φ _ = (B : CommRing {ℓ}) (ψ : CommRingHom R' B) → (∀ s → s ∈ S' → f ψ s ∈ B ˣ) → ∃![ χ ∈ CommRingHom A B ] (f χ) ∘ (f φ) ≡ (f ψ) UniversalPropIsProp : (A : CommRing {ℓ}) (φ : CommRingHom R' A) → (φS⊆Aˣ : ∀ s → s ∈ S' → f φ s ∈ A ˣ) → isProp (hasLocUniversalProp A φ φS⊆Aˣ) UniversalPropIsProp A φ φS⊆Aˣ = isPropΠ3 (λ _ _ _ → isPropIsContr) -- S⁻¹R has the universal property module S⁻¹RUniversalProp where open Loc R' S' SMultClosedSubset _/1 : R → S⁻¹R r /1 = [ r , 1r , SMultClosedSubset .containsOne ] /1AsCommRingHom : CommRingHom R' S⁻¹RAsCommRing f /1AsCommRingHom = _/1 pres1 /1AsCommRingHom = refl isHom+ /1AsCommRingHom r r' = cong [_] (≡-× (cong₂ (_+_) (sym (·-rid r)) (sym (·-rid r'))) (Σ≡Prop (λ x → S' x .snd) (sym (·-lid 1r)))) isHom· /1AsCommRingHom r r' = cong [_] (≡-× refl (Σ≡Prop (λ x → S' x .snd) (sym (·-lid 1r)))) S⁻¹Rˣ = S⁻¹RAsCommRing ˣ S/1⊆S⁻¹Rˣ : ∀ s → s ∈ S' → (s /1) ∈ S⁻¹Rˣ S/1⊆S⁻¹Rˣ s s∈S' = [ 1r , s , s∈S' ] , eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path) where path : 1r · (s · 1r) · 1r ≡ 1r · 1r · (1r · s) path = 1r · (s · 1r) · 1r ≡⟨ (λ i → ·-rid (·-lid (·-rid s i) i) i) ⟩ s ≡⟨ (λ i → ·-lid (·-lid s (~ i)) (~ i)) ⟩ 1r · (1r · s) ≡⟨ cong (_· (1r · s)) (sym (·-lid _)) ⟩ 1r · 1r · (1r · s) ∎ S⁻¹RHasUniversalProp : hasLocUniversalProp S⁻¹RAsCommRing /1AsCommRingHom S/1⊆S⁻¹Rˣ S⁻¹RHasUniversalProp B' ψ ψS⊆Bˣ = (χ , funExt χcomp) , χunique where B = B' .fst open CommRingStr (B' .snd) renaming ( is-set to Bset ; _·_ to _·B_ ; 1r to 1b ; _+_ to _+B_ ; ·-assoc to ·B-assoc ; ·-comm to ·B-comm ; ·-lid to ·B-lid ; ·-rid to ·B-rid ; ·-ldist-+ to ·B-ldist-+) open Units B' renaming (Rˣ to Bˣ ; RˣMultClosed to BˣMultClosed ; RˣContainsOne to BˣContainsOne) open Theory (CommRing→Ring B') renaming (·-assoc2 to ·B-assoc2) open CommTheory B' renaming (·-commAssocl to ·B-commAssocl ; ·-commAssocSwap to ·B-commAssocSwap) χ : CommRingHom S⁻¹RAsCommRing B' f χ = SQ.rec Bset fχ fχcoh where fχ : R × S → B fχ (r , s , s∈S') = (f ψ r) ·B ((f ψ s) ⁻¹) ⦃ ψS⊆Bˣ s s∈S' ⦄ fχcoh : (a b : R × S) → a ≈ b → fχ a ≡ fχ b fχcoh (r , s , s∈S') (r' , s' , s'∈S') ((u , u∈S') , p) = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (u · s · s') (SMultClosedSubset .multClosed (SMultClosedSubset .multClosed u∈S' s∈S') s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ (u · s) (SMultClosedSubset .multClosed u∈S' s∈S') ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ ⦃ ψS⊆Bˣ (u · s) (SMultClosedSubset .multClosed u∈S' s∈S') ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s) ·B f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (u · s) ∈ Bˣ ⦄ → f ψ r ·B f ψ s ⁻¹ ≡ f ψ r' ·B f ψ s' ⁻¹ instancepath = f ψ r ·B f ψ s ⁻¹ ≡⟨ sym (·B-rid _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B 1b ≡⟨ cong (f ψ r ·B f ψ s ⁻¹ ·B_) (sym (·-rinv _)) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ (u · s · s') ·B f ψ (u · s · s') ⁻¹) ≡⟨ ·B-assoc _ _ _ ⟩ f ψ r ·B f ψ s ⁻¹ ·B f ψ (u · s · s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r ·B f ψ s ⁻¹ ·B x ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ (u · s) ·B f ψ s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (·B-assoc _ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B f ψ (u · s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r ·B f ψ s ⁻¹ ·B x ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ u ·B f ψ s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → x ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) (·B-commAssocSwap _ _ _ _) ⟩ f ψ r ·B f ψ u ·B (f ψ s ⁻¹ ·B f ψ s) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ (λ i → ·B-comm (f ψ r) (f ψ u) i ·B (·-linv (f ψ s) i) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) ⟩ f ψ u ·B f ψ r ·B 1b ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ (λ i → (·B-rid (sym (isHom· ψ u r) i) i) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹) ⟩ f ψ (u · r) ·B f ψ s' ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (sym (isHom· ψ _ _)) ⟩ f ψ (u · r · s') ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ x ·B f ψ (u · s · s') ⁻¹) p ⟩ f ψ (u · r' · s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ (u · r') ·B f ψ s ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → x ·B f ψ s ·B f ψ (u · s · s') ⁻¹) (isHom· ψ _ _) ⟩ f ψ u ·B f ψ r' ·B f ψ s ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (sym (·B-assoc _ _ _)) ⟩ f ψ u ·B (f ψ r' ·B f ψ s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (_·B f ψ (u · s · s') ⁻¹) (·B-commAssocl _ _ _) ⟩ f ψ r' ·B (f ψ u ·B f ψ s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (λ x → f ψ r' ·B x ·B f ψ (u · s · s') ⁻¹) (sym (isHom· ψ _ _)) ⟩ f ψ r' ·B f ψ (u · s) ·B f ψ (u · s · s') ⁻¹ ≡⟨ cong (f ψ r' ·B f ψ (u · s) ·B_) (unitCong (isHom· ψ _ _)) ⟩ f ψ r' ·B f ψ (u · s) ·B (f ψ (u · s) ·B f ψ s') ⁻¹ ≡⟨ cong (f ψ r' ·B f ψ (u · s) ·B_) (⁻¹-dist-· _ _) ⟩ f ψ r' ·B f ψ (u · s) ·B (f ψ (u · s) ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-assoc2 _ _ _ _ ⟩ f ψ r' ·B (f ψ (u · s) ·B f ψ (u · s) ⁻¹) ·B f ψ s' ⁻¹ ≡⟨ cong (λ x → f ψ r' ·B x ·B f ψ s' ⁻¹) (·-rinv _) ⟩ f ψ r' ·B 1b ·B f ψ s' ⁻¹ ≡⟨ cong (_·B f ψ s' ⁻¹) (·B-rid _) ⟩ f ψ r' ·B f ψ s' ⁻¹ ∎ pres1 χ = instancepres1χ ⦃ ψS⊆Bˣ 1r (SMultClosedSubset .containsOne) ⦄ ⦃ BˣContainsOne ⦄ where instancepres1χ : ⦃ _ : f ψ 1r ∈ Bˣ ⦄ ⦃ _ : 1b ∈ Bˣ ⦄ → f ψ 1r ·B (f ψ 1r) ⁻¹ ≡ 1b instancepres1χ = (λ i → (pres1 ψ i) ·B (unitCong (pres1 ψ) i)) ∙ (λ i → ·B-lid (1⁻¹≡1 i) i) isHom+ χ = elimProp2 (λ _ _ _ _ → Bset _ _ _ _) isHom+[] where isHom+[] : (a b : R × S) → f χ ([ a ] +ₗ [ b ]) ≡ (f χ [ a ]) +B (f χ [ b ]) isHom+[] (r , s , s∈S') (r' , s' , s'∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (s · s') (SMultClosedSubset .multClosed s∈S' s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ s ·B f ψ s' ∈ Bˣ ⦄ → f ψ (r · s' + r' · s) ·B f ψ (s · s') ⁻¹ ≡ f ψ r ·B f ψ s ⁻¹ +B f ψ r' ·B f ψ s' ⁻¹ instancepath = f ψ (r · s' + r' · s) ·B f ψ (s · s') ⁻¹ ≡⟨ (λ i → isHom+ ψ (r · s') (r' · s) i ·B unitCong (isHom· ψ s s') i) ⟩ (f ψ (r · s') +B f ψ (r' · s)) ·B (f ψ s ·B f ψ s') ⁻¹ ≡⟨ (λ i → (isHom· ψ r s' i +B isHom· ψ r' s i) ·B ⁻¹-dist-· (f ψ s) (f ψ s') i) ⟩ (f ψ r ·B f ψ s' +B f ψ r' ·B f ψ s) ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-ldist-+ _ _ _ ⟩ f ψ r ·B f ψ s' ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) +B f ψ r' ·B f ψ s ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ (λ i → ·B-commAssocSwap (f ψ r) (f ψ s') (f ψ s ⁻¹) (f ψ s' ⁻¹) i +B ·B-assoc2 (f ψ r') (f ψ s) (f ψ s ⁻¹) (f ψ s' ⁻¹) i) ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ s' ·B f ψ s' ⁻¹) +B f ψ r' ·B (f ψ s ·B f ψ s ⁻¹) ·B f ψ s' ⁻¹ ≡⟨ (λ i → f ψ r ·B f ψ s ⁻¹ ·B (·-rinv (f ψ s') i) +B f ψ r' ·B (·-rinv (f ψ s) i) ·B f ψ s' ⁻¹) ⟩ f ψ r ·B f ψ s ⁻¹ ·B 1b +B f ψ r' ·B 1b ·B f ψ s' ⁻¹ ≡⟨ (λ i → ·B-rid (f ψ r ·B f ψ s ⁻¹) i +B ·B-rid (f ψ r') i ·B f ψ s' ⁻¹) ⟩ f ψ r ·B f ψ s ⁻¹ +B f ψ r' ·B f ψ s' ⁻¹ ∎ isHom· χ = elimProp2 (λ _ _ _ _ → Bset _ _ _ _) isHom·[] where isHom·[] : (a b : R × S) → f χ ([ a ] ·ₗ [ b ]) ≡ (f χ [ a ]) ·B (f χ [ b ]) isHom·[] (r , s , s∈S') (r' , s' , s'∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦃ ψS⊆Bˣ (s · s') (SMultClosedSubset .multClosed s∈S' s'∈S') ⦄ ⦃ BˣMultClosed _ _ ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ ψS⊆Bˣ s' s'∈S' ⦄ ⦄ where instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : f ψ s' ∈ Bˣ ⦄ ⦃ _ : f ψ (s · s') ∈ Bˣ ⦄ ⦃ _ : f ψ s ·B f ψ s' ∈ Bˣ ⦄ → f ψ (r · r') ·B f ψ (s · s') ⁻¹ ≡ (f ψ r ·B f ψ s ⁻¹) ·B (f ψ r' ·B f ψ s' ⁻¹) instancepath = f ψ (r · r') ·B f ψ (s · s') ⁻¹ ≡⟨ (λ i → isHom· ψ r r' i ·B unitCong (isHom· ψ s s') i) ⟩ f ψ r ·B f ψ r' ·B (f ψ s ·B f ψ s') ⁻¹ ≡⟨ cong (f ψ r ·B f ψ r' ·B_) (⁻¹-dist-· _ _) ⟩ f ψ r ·B f ψ r' ·B (f ψ s ⁻¹ ·B f ψ s' ⁻¹) ≡⟨ ·B-commAssocSwap _ _ _ _ ⟩ f ψ r ·B f ψ s ⁻¹ ·B (f ψ r' ·B f ψ s' ⁻¹) ∎ χcomp : (r : R) → f χ (r /1) ≡ f ψ r χcomp = instanceχcomp ⦃ ψS⊆Bˣ 1r (SMultClosedSubset .containsOne) ⦄ ⦃ Units.RˣContainsOne B' ⦄ where instanceχcomp : ⦃ _ : f ψ 1r ∈ Bˣ ⦄ ⦃ _ : 1b ∈ Bˣ ⦄ (r : R) → f ψ r ·B (f ψ 1r) ⁻¹ ≡ f ψ r instanceχcomp r = f ψ r ·B (f ψ 1r) ⁻¹ ≡⟨ cong (f ψ r ·B_) (unitCong (pres1 ψ)) ⟩ f ψ r ·B 1b ⁻¹ ≡⟨ cong (f ψ r ·B_) 1⁻¹≡1 ⟩ f ψ r ·B 1b ≡⟨ ·B-rid _ ⟩ f ψ r ∎ χunique : (y : Σ[ χ' ∈ CommRingHom S⁻¹RAsCommRing B' ] f χ' ∘ _/1 ≡ f ψ) → (χ , funExt χcomp) ≡ y χunique (χ' , χ'/1≡ψ) = Σ≡Prop (λ x → isSetΠ (λ _ → Bset) _ _) (RingHom≡f _ _ fχ≡fχ') where open RingHomRespUnits {A' = S⁻¹RAsCommRing} {B' = B'} χ' renaming (φ[x⁻¹]≡φ[x]⁻¹ to χ'[x⁻¹]≡χ'[x]⁻¹) []-path : (a : R × S) → f χ [ a ] ≡ f χ' [ a ] []-path (r , s , s∈S') = instancepath ⦃ ψS⊆Bˣ s s∈S' ⦄ ⦃ S/1⊆S⁻¹Rˣ s s∈S' ⦄ ⦃ RingHomRespInv _ ⦃ S/1⊆S⁻¹Rˣ s s∈S' ⦄ ⦄ where open Units S⁻¹RAsCommRing renaming (_⁻¹ to _⁻¹ˡ ; inverseUniqueness to S⁻¹RInverseUniqueness) hiding (unitCong) s-inv : ⦃ s/1∈S⁻¹Rˣ : s /1 ∈ S⁻¹Rˣ ⦄ → s /1 ⁻¹ˡ ≡ [ 1r , s , s∈S' ] s-inv ⦃ s/1∈S⁻¹Rˣ ⦄ = PathPΣ (S⁻¹RInverseUniqueness (s /1) s/1∈S⁻¹Rˣ (_ , eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path))) .fst where path : 1r · (s · 1r) · 1r ≡ 1r · 1r · (1r · s) path = 1r · (s · 1r) · 1r ≡⟨ (λ i → ·-rid (·-lid (·-rid s i) i) i) ⟩ s ≡⟨ (λ i → ·-lid (·-lid s (~ i)) (~ i)) ⟩ 1r · (1r · s) ≡⟨ cong (_· (1r · s)) (sym (·-lid _)) ⟩ 1r · 1r · (1r · s) ∎ ·ₗ-path : [ r , s , s∈S' ] ≡ [ r , 1r , SMultClosedSubset .containsOne ] ·ₗ [ 1r , s , s∈S' ] ·ₗ-path = cong [_] (≡-× (sym (·-rid r)) (Σ≡Prop (λ x → S' x .snd) (sym (·-lid s)))) instancepath : ⦃ _ : f ψ s ∈ Bˣ ⦄ ⦃ _ : s /1 ∈ S⁻¹Rˣ ⦄ ⦃ _ : f χ' (s /1) ∈ Bˣ ⦄ → f ψ r ·B f ψ s ⁻¹ ≡ f χ' [ r , s , s∈S' ] instancepath = f ψ r ·B f ψ s ⁻¹ ≡⟨ cong (f ψ r ·B_) (unitCong (cong (λ φ → φ s) (sym χ'/1≡ψ))) ⟩ f ψ r ·B f χ' (s /1) ⁻¹ ≡⟨ cong (f ψ r ·B_) (sym (χ'[x⁻¹]≡χ'[x]⁻¹ _)) ⟩ f ψ r ·B f χ' (s /1 ⁻¹ˡ) ≡⟨ cong (λ x → f ψ r ·B f χ' x) s-inv ⟩ f ψ r ·B f χ' [ 1r , s , s∈S' ] ≡⟨ cong (_·B f χ' [ 1r , s , s∈S' ]) (cong (λ φ → φ r) (sym χ'/1≡ψ)) ⟩ f χ' [ r , 1r , SMultClosedSubset .containsOne ] ·B f χ' [ 1r , s , s∈S' ] ≡⟨ sym (isHom· χ' _ _) ⟩ f χ' ([ r , 1r , SMultClosedSubset .containsOne ] ·ₗ [ 1r , s , s∈S' ]) ≡⟨ cong (f χ') (sym ·ₗ-path) ⟩ f χ' [ r , s , s∈S' ] ∎ fχ≡fχ' : f χ ≡ f χ' fχ≡fχ' = funExt (SQ.elimProp (λ _ → Bset _ _) []-path) -- sufficient conditions for having the universal property -- used as API in the leanprover-community/mathlib -- Corollary 3.2 in Atiyah-McDonald open S⁻¹RUniversalProp record PathToS⁻¹R (A' : CommRing {ℓ}) (φ : CommRingHom R' A') : Type ℓ where constructor pathtoS⁻¹R open Units A' renaming (Rˣ to Aˣ) open CommRingStr (A' .snd) renaming (is-set to Aset ; 0r to 0a ; _·_ to _·A_) field φS⊆Aˣ : ∀ s → s ∈ S' → f φ s ∈ Aˣ kerφ⊆annS : ∀ r → f φ r ≡ 0a → ∃[ s ∈ S ] (s .fst) · r ≡ 0r surχ : ∀ a → ∃[ x ∈ R × S ] f φ (x .fst) ·A (f φ (x .snd .fst) ⁻¹) ⦃ φS⊆Aˣ _ (x .snd .snd) ⦄ ≡ a S⁻¹RChar : (A' : CommRing {ℓ}) (φ : CommRingHom R' A') → PathToS⁻¹R A' φ → S⁻¹RAsCommRing ≡ A' S⁻¹RChar A' φ cond = CommRingPath S⁻¹RAsCommRing A' .fst (S⁻¹R≃A , record { pres1 = pres1 χ ; isHom+ = isHom+ χ ; isHom· = isHom· χ }) where open CommRingStr (A' .snd) renaming ( is-set to Aset ; 0r to 0a ; _·_ to _·A_ ; 1r to 1a ; ·-rid to ·A-rid) open Units A' renaming (Rˣ to Aˣ ; RˣInvClosed to AˣInvClosed) open PathToS⁻¹R ⦃...⦄ private A = A' .fst instance _ = cond χ = (S⁻¹RHasUniversalProp A' φ φS⊆Aˣ .fst .fst) open HomTheory χ S⁻¹R≃A : S⁻¹R ≃ A S⁻¹R≃A = f χ , isEmbedding×isSurjection→isEquiv (Embχ , Surχ) where Embχ : isEmbedding (f χ) Embχ = injEmbedding squash/ Aset (ker≡0→inj λ {x} → kerχ≡0 x) where kerχ≡0 : (r/s : S⁻¹R) → f χ r/s ≡ 0a → r/s ≡ 0ₗ kerχ≡0 = SQ.elimProp (λ _ → isPropΠ λ _ → squash/ _ _) kerχ≡[] where kerχ≡[] : (a : R × S) → f χ [ a ] ≡ 0a → [ a ] ≡ 0ₗ kerχ≡[] (r , s , s∈S') p = PT.rec (squash/ _ _) Σhelper (kerφ⊆annS r (UnitsAreNotZeroDivisors _ _ p)) where instance _ : f φ s ∈ Aˣ _ = φS⊆Aˣ s s∈S' _ : f φ s ⁻¹ ∈ Aˣ _ = AˣInvClosed _ Σhelper : Σ[ s ∈ S ] (s .fst) · r ≡ 0r → [ r , s , s∈S' ] ≡ 0ₗ Σhelper ((u , u∈S') , q) = eq/ _ _ ((u , u∈S') , path) where path : u · r · 1r ≡ u · 0r · s path = (λ i → ·-rid (q i) i) ∙∙ sym (0-leftNullifies _) ∙∙ cong (_· s) (sym (0-rightNullifies _)) Surχ : isSurjection (f χ) Surχ a = PT.rec propTruncIsProp (λ x → ∣ [ x .fst ] , x .snd ∣) (surχ a)
48.93586
101
0.444683
a0d9ecaab474f10660b3b714584589b226bebbe1
8,632
agda
Agda
Cubical/Algebra/CommAlgebra/Localisation.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/CommAlgebra/Localisation.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
Cubical/Algebra/CommAlgebra/Localisation.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommAlgebra.Localisation where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.SIP open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Reflection.StrictEquiv open import Cubical.Structures.Axioms open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.CommRing.Base open import Cubical.Algebra.CommRing.Properties open import Cubical.Algebra.CommRing.Localisation.Base open import Cubical.Algebra.CommRing.Localisation.UniversalProperty open import Cubical.Algebra.Ring open import Cubical.Algebra.Algebra open import Cubical.Algebra.CommAlgebra.Base open import Cubical.Algebra.CommAlgebra.Properties open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT private variable ℓ ℓ′ : Level module AlgLoc (R' : CommRing ℓ) (S' : ℙ (fst R')) (SMultClosedSubset : isMultClosedSubset R' S') where open isMultClosedSubset private R = fst R' open CommAlgebraStr open IsAlgebraHom open CommRingStr (snd R') renaming (_+_ to _+r_ ; _·_ to _·r_ ; ·Rid to ·rRid) open RingTheory (CommRing→Ring R') open CommRingTheory R' open Loc R' S' SMultClosedSubset open S⁻¹RUniversalProp R' S' SMultClosedSubset open CommAlgChar R' S⁻¹RAsCommAlg : CommAlgebra R' ℓ S⁻¹RAsCommAlg = toCommAlg (S⁻¹RAsCommRing , /1AsCommRingHom) hasLocAlgUniversalProp : (A : CommAlgebra R' ℓ) → (∀ s → s ∈ S' → _⋆_ (snd A) s (1a (snd A)) ∈ (CommAlgebra→CommRing A) ˣ) → Type (ℓ-suc ℓ) hasLocAlgUniversalProp A _ = (B : CommAlgebra R' ℓ) → (∀ s → s ∈ S' → _⋆_ (snd B) s (1a (snd B)) ∈ (CommAlgebra→CommRing B) ˣ) → isContr (CommAlgebraHom A B) S⋆1⊆S⁻¹Rˣ : ∀ s → s ∈ S' → _⋆_ (snd S⁻¹RAsCommAlg) s (1a (snd S⁻¹RAsCommAlg)) ∈ S⁻¹Rˣ S⋆1⊆S⁻¹Rˣ s s∈S' = subst-∈ S⁻¹Rˣ (cong [_] (≡-× (sym (·rRid s)) (Σ≡Prop (λ x → S' x .snd) (sym (·rRid _))))) (S/1⊆S⁻¹Rˣ s s∈S') S⁻¹RHasAlgUniversalProp : hasLocAlgUniversalProp S⁻¹RAsCommAlg S⋆1⊆S⁻¹Rˣ S⁻¹RHasAlgUniversalProp B' S⋆1⊆Bˣ = χᴬ , χᴬuniqueness where B = fromCommAlg B' .fst φ = fromCommAlg B' .snd open CommRingStr (snd B) renaming (_·_ to _·b_ ; 1r to 1b ; ·Lid to ·bLid) χ : CommRingHom S⁻¹RAsCommRing B χ = S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .fst .fst χcomp : ∀ r → fst χ (r /1) ≡ fst φ r χcomp = funExt⁻ (S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .fst .snd) χᴬ : CommAlgebraHom S⁻¹RAsCommAlg B' fst χᴬ = fst χ pres0 (snd χᴬ) = IsRingHom.pres0 (snd χ) pres1 (snd χᴬ) = IsRingHom.pres1 (snd χ) pres+ (snd χᴬ) = IsRingHom.pres+ (snd χ) pres· (snd χᴬ) = IsRingHom.pres· (snd χ) pres- (snd χᴬ) = IsRingHom.pres- (snd χ) pres⋆ (snd χᴬ) r x = path where path : fst χ ((r /1) ·ₗ x) ≡ _⋆_ (snd B') r (fst χ x) path = fst χ ((r /1) ·ₗ x) ≡⟨ IsRingHom.pres· (snd χ) _ _ ⟩ fst χ (r /1) ·b fst χ x ≡⟨ cong (_·b fst χ x) (χcomp r) ⟩ fst φ r ·b fst χ x ≡⟨ refl ⟩ _⋆_ (snd B') r 1b ·b fst χ x ≡⟨ ⋆-lassoc (snd B') _ _ _ ⟩ _⋆_ (snd B') r (1b ·b fst χ x) ≡⟨ cong (_⋆_ (snd B') r) (·bLid _) ⟩ _⋆_ (snd B') r (fst χ x) ∎ χᴬuniqueness : (ψ : CommAlgebraHom S⁻¹RAsCommAlg B') → χᴬ ≡ ψ χᴬuniqueness ψ = Σ≡Prop (λ _ → isPropIsAlgebraHom _ _ _ _) (cong (fst ∘ fst) (χuniqueness (ψ' , funExt ψ'r/1≡φr))) where χuniqueness = S⁻¹RHasUniversalProp B φ S⋆1⊆Bˣ .snd ψ' : CommRingHom S⁻¹RAsCommRing B fst ψ' = fst ψ IsRingHom.pres0 (snd ψ') = pres0 (snd ψ) IsRingHom.pres1 (snd ψ') = pres1 (snd ψ) IsRingHom.pres+ (snd ψ') = pres+ (snd ψ) IsRingHom.pres· (snd ψ') = pres· (snd ψ) IsRingHom.pres- (snd ψ') = pres- (snd ψ) ψ'r/1≡φr : ∀ r → fst ψ (r /1) ≡ fst φ r ψ'r/1≡φr r = fst ψ (r /1) ≡⟨ cong (fst ψ) (sym (·ₗ-rid _)) ⟩ fst ψ (_⋆_ (snd S⁻¹RAsCommAlg) r (1a (snd S⁻¹RAsCommAlg))) ≡⟨ pres⋆ (snd ψ) _ _ ⟩ _⋆_ (snd B') r (fst ψ (1a (snd S⁻¹RAsCommAlg))) ≡⟨ cong (_⋆_ (snd B') r) (pres1 (snd ψ)) ⟩ _⋆_ (snd B') r 1b ∎ -- an immediate corollary: isContrHomS⁻¹RS⁻¹R : isContr (CommAlgebraHom S⁻¹RAsCommAlg S⁻¹RAsCommAlg) isContrHomS⁻¹RS⁻¹R = S⁻¹RHasAlgUniversalProp S⁻¹RAsCommAlg S⋆1⊆S⁻¹Rˣ module AlgLocTwoSubsets (R' : CommRing ℓ) (S₁ : ℙ (fst R')) (S₁MultClosedSubset : isMultClosedSubset R' S₁) (S₂ : ℙ (fst R')) (S₂MultClosedSubset : isMultClosedSubset R' S₂) where open isMultClosedSubset open CommRingStr (snd R') hiding (is-set) open RingTheory (CommRing→Ring R') open Loc R' S₁ S₁MultClosedSubset renaming (S⁻¹R to S₁⁻¹R ; S⁻¹RAsCommRing to S₁⁻¹RAsCommRing) open Loc R' S₂ S₂MultClosedSubset renaming (S⁻¹R to S₂⁻¹R ; S⁻¹RAsCommRing to S₂⁻¹RAsCommRing) open AlgLoc R' S₁ S₁MultClosedSubset renaming ( S⁻¹RAsCommAlg to S₁⁻¹RAsCommAlg ; S⋆1⊆S⁻¹Rˣ to S₁⋆1⊆S₁⁻¹Rˣ ; S⁻¹RHasAlgUniversalProp to S₁⁻¹RHasAlgUniversalProp ; isContrHomS⁻¹RS⁻¹R to isContrHomS₁⁻¹RS₁⁻¹R) open AlgLoc R' S₂ S₂MultClosedSubset renaming ( S⁻¹RAsCommAlg to S₂⁻¹RAsCommAlg ; S⋆1⊆S⁻¹Rˣ to S₂⋆1⊆S₂⁻¹Rˣ ; S⁻¹RHasAlgUniversalProp to S₂⁻¹RHasAlgUniversalProp ; isContrHomS⁻¹RS⁻¹R to isContrHomS₂⁻¹RS₂⁻¹R) open IsAlgebraHom open CommAlgebraStr ⦃...⦄ private R = fst R' S₁⁻¹Rˣ = S₁⁻¹RAsCommRing ˣ S₂⁻¹Rˣ = S₂⁻¹RAsCommRing ˣ instance _ = snd S₁⁻¹RAsCommAlg _ = snd S₂⁻¹RAsCommAlg isContrS₁⁻¹R≡S₂⁻¹R : (∀ s₁ → s₁ ∈ S₁ → s₁ ⋆ 1a ∈ S₂⁻¹Rˣ) → (∀ s₂ → s₂ ∈ S₂ → s₂ ⋆ 1a ∈ S₁⁻¹Rˣ) → isContr (S₁⁻¹RAsCommAlg ≡ S₂⁻¹RAsCommAlg) isContrS₁⁻¹R≡S₂⁻¹R S₁⊆S₂⁻¹Rˣ S₂⊆S₁⁻¹Rˣ = isOfHLevelRetractFromIso 0 (equivToIso (invEquiv (CommAlgebraPath _ _ _))) isContrS₁⁻¹R≅S₂⁻¹R where χ₁ : CommAlgebraHom S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg χ₁ = S₁⁻¹RHasAlgUniversalProp S₂⁻¹RAsCommAlg S₁⊆S₂⁻¹Rˣ .fst χ₂ : CommAlgebraHom S₂⁻¹RAsCommAlg S₁⁻¹RAsCommAlg χ₂ = S₂⁻¹RHasAlgUniversalProp S₁⁻¹RAsCommAlg S₂⊆S₁⁻¹Rˣ .fst χ₁∘χ₂≡id : χ₁ ∘a χ₂ ≡ idAlgHom χ₁∘χ₂≡id = isContr→isProp isContrHomS₂⁻¹RS₂⁻¹R _ _ χ₂∘χ₁≡id : χ₂ ∘a χ₁ ≡ idAlgHom χ₂∘χ₁≡id = isContr→isProp isContrHomS₁⁻¹RS₁⁻¹R _ _ IsoS₁⁻¹RS₂⁻¹R : Iso S₁⁻¹R S₂⁻¹R Iso.fun IsoS₁⁻¹RS₂⁻¹R = fst χ₁ Iso.inv IsoS₁⁻¹RS₂⁻¹R = fst χ₂ Iso.rightInv IsoS₁⁻¹RS₂⁻¹R = funExt⁻ (cong fst χ₁∘χ₂≡id) Iso.leftInv IsoS₁⁻¹RS₂⁻¹R = funExt⁻ (cong fst χ₂∘χ₁≡id) isContrS₁⁻¹R≅S₂⁻¹R : isContr (CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg) isContrS₁⁻¹R≅S₂⁻¹R = center , uniqueness where center : CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg fst center = isoToEquiv IsoS₁⁻¹RS₂⁻¹R pres0 (snd center) = pres0 (snd χ₁) pres1 (snd center) = pres1 (snd χ₁) pres+ (snd center) = pres+ (snd χ₁) pres· (snd center) = pres· (snd χ₁) pres- (snd center) = pres- (snd χ₁) pres⋆ (snd center) = pres⋆ (snd χ₁) uniqueness : (φ : CommAlgebraEquiv S₁⁻¹RAsCommAlg S₂⁻¹RAsCommAlg) → center ≡ φ uniqueness φ = Σ≡Prop (λ _ → isPropIsAlgebraHom _ _ _ _) (equivEq (cong fst (S₁⁻¹RHasAlgUniversalProp S₂⁻¹RAsCommAlg S₁⊆S₂⁻¹Rˣ .snd (AlgebraEquiv→AlgebraHom φ)))) isPropS₁⁻¹R≡S₂⁻¹R : isProp (S₁⁻¹RAsCommAlg ≡ S₂⁻¹RAsCommAlg) isPropS₁⁻¹R≡S₂⁻¹R S₁⁻¹R≡S₂⁻¹R = isContr→isProp (isContrS₁⁻¹R≡S₂⁻¹R S₁⊆S₂⁻¹Rˣ S₂⊆S₁⁻¹Rˣ) S₁⁻¹R≡S₂⁻¹R where S₁⊆S₂⁻¹Rˣ : ∀ s₁ → s₁ ∈ S₁ → s₁ ⋆ 1a ∈ S₂⁻¹Rˣ S₁⊆S₂⁻¹Rˣ s₁ s₁∈S₁ = transport (λ i → _⋆_ ⦃ S₁⁻¹R≡S₂⁻¹R i .snd ⦄ s₁ (1a ⦃ S₁⁻¹R≡S₂⁻¹R i .snd ⦄) ∈ (CommAlgebra→CommRing (S₁⁻¹R≡S₂⁻¹R i)) ˣ) (S₁⋆1⊆S₁⁻¹Rˣ s₁ s₁∈S₁) S₂⊆S₁⁻¹Rˣ : ∀ s₂ → s₂ ∈ S₂ → s₂ ⋆ 1a ∈ S₁⁻¹Rˣ S₂⊆S₁⁻¹Rˣ s₂ s₂∈S₂ = transport (λ i → _⋆_ ⦃ (sym S₁⁻¹R≡S₂⁻¹R) i .snd ⦄ s₂ (1a ⦃ (sym S₁⁻¹R≡S₂⁻¹R) i .snd ⦄) ∈ (CommAlgebra→CommRing ((sym S₁⁻¹R≡S₂⁻¹R) i)) ˣ) (S₂⋆1⊆S₂⁻¹Rˣ s₂ s₂∈S₂)
39.59633
100
0.607275
2e7cba479487febaec9e01db6e7e91d2c875745c
13,045
agda
Agda
src/LibraBFT/Abstract/RecordChain/Properties.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Abstract/RecordChain/Properties.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Abstract/RecordChain/Properties.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Abstract.Types open import LibraBFT.Abstract.Types.EpochConfig open import Util.Lemmas open import Util.Prelude open WithAbsVote -- This module contains properties about RecordChains, culminating in -- theorem S5, which is the main per-epoch correctness condition. The -- properties are based on the original version of the LibraBFT paper, -- which was current when they were developed: -- https://developers.diem.com/docs/assets/papers/diem-consensus-state-machine-replication-in-the-diem-blockchain/2019-06-28.pdf -- Even though the implementation has changed since that version of the -- paper, we do not need to redo these proofs because that affects only -- the concrete implementation. This demonstrates one advantage of -- separating these proofs into abstract and concrete pieces. module LibraBFT.Abstract.RecordChain.Properties (UID : Set) (_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁)) (NodeId : Set) (𝓔 : EpochConfig UID NodeId) (𝓥 : VoteEvidence UID NodeId 𝓔) where open import LibraBFT.Abstract.Types UID NodeId 𝓔 open import LibraBFT.Abstract.System UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.Records UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.Records.Extends UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.RecordChain UID _≟UID_ NodeId 𝓔 𝓥 open import LibraBFT.Abstract.RecordChain.Assumptions UID _≟UID_ NodeId 𝓔 𝓥 open EpochConfig 𝓔 module WithInvariants {ℓ} (InSys : Record → Set ℓ) (votes-only-once : VotesOnlyOnceRule InSys) (preferred-round-rule : PreferredRoundRule InSys) where open All-InSys-props InSys ---------------------- -- Lemma 2 -- Lemma 2 states that there can be at most one certified block per -- round. If two blocks have a quorum certificate for the same round, -- then they are equal or their unique identifier is not -- injective. This is required because, on the concrete side, this bId -- will be a hash function which might yield collisions. lemmaS2 : {b₀ b₁ : Block}{q₀ q₁ : QC} → InSys (Q q₀) → InSys (Q q₁) → (p₀ : B b₀ ← Q q₀) → (p₁ : B b₁ ← Q q₁) → getRound b₀ ≡ getRound b₁ → b₀ ≢ b₁ × bId b₀ ≡ bId b₁ ⊎ b₀ ≡ b₁ lemmaS2 {b₀} {b₁} {q₀} {q₁} ex₀ ex₁ (B←Q refl h₀) (B←Q refl h₁) refl with b₀ ≟Block b₁ ...| yes done = inj₂ done ...| no imp with bft-property (qVotes-C1 q₀) (qVotes-C1 q₁) ...| (a , (a∈q₀mem , a∈q₁mem , honest)) with Any-sym (Any-map⁻ a∈q₀mem) | Any-sym (Any-map⁻ a∈q₁mem) ...| a∈q₀ | a∈q₁ with All-lookup (qVotes-C3 q₀) (∈QC-Vote-correct q₀ a∈q₀) | All-lookup (qVotes-C3 q₁) (∈QC-Vote-correct q₁ a∈q₁) ...| a∈q₀rnd≡ | a∈q₁rnd≡ with <-cmp (abs-vRound (∈QC-Vote q₀ a∈q₀)) (abs-vRound (∈QC-Vote q₁ a∈q₁)) ...| tri< va<va' _ _ = ⊥-elim (<⇒≢ (subst₂ _<_ a∈q₀rnd≡ a∈q₁rnd≡ va<va') refl) ...| tri> _ _ va'<va = ⊥-elim (<⇒≢ (subst₂ _≤_ (cong suc a∈q₁rnd≡) a∈q₀rnd≡ va'<va) refl) ...| tri≈ _ v₀≡v₁ _ = let v₀∈q₀ = ∈QC-Vote-correct q₀ a∈q₀ v₁∈q₁ = ∈QC-Vote-correct q₁ a∈q₁ ppp = trans h₀ (trans (vote≡⇒QPrevId≡ {q₀} {q₁} v₀∈q₀ v₁∈q₁ (votes-only-once a honest ex₀ ex₁ a∈q₀ a∈q₁ v₀≡v₁)) (sym h₁)) in inj₁ (imp , ppp) ---------------- -- Lemma S3 lemmaS3 : ∀{r₂ q'} {rc : RecordChain r₂} → All-InSys rc → (rc' : RecordChain (Q q')) → All-InSys rc' -- Immediately before a (Q q), we have the certified block (B b), which is the 'B' in S3 → (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S3 → round r₂ < getRound q' → NonInjective-≡-pred (InSys ∘ B) bId ⊎ (getRound (kchainBlock (suc (suc zero)) c3) ≤ prevRound rc') lemmaS3 {r₂} {q'} ais₀ (step rc' b←q') ais₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ _ b₂←q₂ c2) hyp with All-InSys⇒last-InSys ais₀ | All-InSys⇒last-InSys ais₁ ...| ex₀ | ex₁ with bft-property (qVotes-C1 q₂) (qVotes-C1 q') ...| (a , (a∈q₂mem , a∈q'mem , honest)) with Any-sym (Any-map⁻ a∈q₂mem) | Any-sym (Any-map⁻ a∈q'mem) ...| a∈q₂ | a∈q' -- TODO-1: We have done similar reasoning on the order of votes for -- lemmaS2. We should factor out a predicate that analyzes the rounds -- of QC's and returns us a judgement about the order of the votes. with All-lookup (qVotes-C3 q') (∈QC-Vote-correct q' a∈q') | All-lookup (qVotes-C3 q₂) (∈QC-Vote-correct q₂ a∈q₂) ...| a∈q'rnd≡ | a∈q₂rnd≡ with <-cmp (round r₂) (abs-vRound (∈QC-Vote q' a∈q')) ...| tri> _ _ va'<va₂ with subst₂ _<_ a∈q'rnd≡ a∈q₂rnd≡ (≤-trans va'<va₂ (≤-reflexive (sym a∈q₂rnd≡))) ...| res = ⊥-elim (n≮n (getRound q') (≤-trans res (≤-unstep hyp))) lemmaS3 {q' = q'} ais₀ (step rc' b←q') ais₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ P b₂←q₂ c2) hyp | ex₀ | ex₁ | (a , (a∈q₂mem , a∈q'mem , honest)) | a∈q₂ | a∈q' | a∈q'rnd≡ | a∈q₂rnd≡ | tri≈ _ v₂≡v' _ = let v₂∈q₂ = ∈QC-Vote-correct q₂ a∈q₂ v'∈q' = ∈QC-Vote-correct q' a∈q' in ⊥-elim (<⇒≢ hyp (vote≡⇒QRound≡ {q₂} {q'} v₂∈q₂ v'∈q' (votes-only-once a honest {q₂} {q'} ex₀ ex₁ a∈q₂ a∈q' (trans a∈q₂rnd≡ v₂≡v')))) lemmaS3 {r} {q'} ais₀ (step rc' b←q') ais₁ (s-chain {rc = rc} {b = b₂} {q₂} r←b₂ P b₂←q₂ c2) hyp | ex₀ | ex₁ | (a , (a∈q₂mem , a∈q'mem , honest)) | a∈q₂ | a∈q' | a∈q'rnd≡ | a∈q₂rnd≡ | tri< va₂<va' _ _ with b←q' ...| B←Q rrr xxx = preferred-round-rule a honest {q₂} {q'} ais₀ (s-chain r←b₂ P b₂←q₂ c2) a∈q₂ {step rc' (B←Q rrr xxx)} ais₁ a∈q' (≤-trans (≤-reflexive (cong suc a∈q₂rnd≡)) va₂<va') ------------------ -- Proposition S4 -- The base case for lemma S4 resorts to a pretty simple -- arithmetic statement. propS4-base-arith : ∀ n r → n ≤ r → r ≤ (suc (suc n)) → r ∈ (suc (suc n) ∷ suc n ∷ n ∷ []) propS4-base-arith .0 .0 z≤n z≤n = there (there (here refl)) propS4-base-arith .0 .1 z≤n (s≤s z≤n) = there (here refl) propS4-base-arith .0 .2 z≤n (s≤s (s≤s z≤n)) = here refl propS4-base-arith (suc r) (suc n) (s≤s h0) (s≤s h1) = ∈-cong suc (propS4-base-arith r n h0 h1) -- Which is then translated to LibraBFT lingo propS4-base-lemma-1 : ∀{q}{rc : RecordChain (Q q)} → (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4 → (r : ℕ) → getRound (c3 b⟦ suc (suc zero) ⟧) ≤ r → r ≤ getRound (c3 b⟦ zero ⟧) → r ∈ ( getRound (c3 b⟦ zero ⟧) ∷ getRound (c3 b⟦ (suc zero) ⟧) ∷ getRound (c3 b⟦ (suc (suc zero)) ⟧) ∷ []) propS4-base-lemma-1 (s-chain {b = b0} _ p0 (B←Q refl b←q0) (s-chain {b = b1} r←b1 p1 (B←Q refl b←q1) (s-chain {r = R} {b = b2} r←b2 p2 (B←Q refl b←q2) 0-chain))) r hyp0 hyp1 rewrite p0 | p1 = propS4-base-arith (bRound b2) r hyp0 hyp1 propS4-base-lemma-2 : ∀{k r} {rc : RecordChain r} → All-InSys rc → (q' : QC) → InSys (Q q') → {b' : Block} → (rc' : RecordChain (B b')) → All-InSys rc' → (ext : (B b') ← (Q q')) → (c : 𝕂-chain Contig k rc) → (ix : Fin k) → getRound (kchainBlock ix c) ≡ getRound b' → NonInjective-≡-pred (InSys ∘ B) bId ⊎ (kchainBlock ix c ≡ b') propS4-base-lemma-2 {rc = rc} prev∈sys q' q'∈sys {b'} rc' rc'All∈sys ext (s-chain {b = b} r←b prf b←q c) zero hyp with lemmaS2 (All-InSys⇒last-InSys prev∈sys) q'∈sys b←q ext hyp ... | Left (b≢b' , bIds≡) = inj₁ (((b , b') , b≢b' , bIds≡) , All-InSys-unstep prev∈sys here , rc'All∈sys here) ... | Right y = Right y propS4-base-lemma-2 prev∈sys q' q'∈sys rc' rc'All∈sys ext (s-chain r←b prf b←q c) (suc ix) = propS4-base-lemma-2 (All-InSys-unstep (All-InSys-unstep prev∈sys)) q' q'∈sys rc' rc'All∈sys ext c ix propS4-base : ∀{q q'} → {rc : RecordChain (Q q)} → All-InSys rc → (rc' : RecordChain (Q q')) → All-InSys rc' → (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4 → getRound (c3 b⟦ suc (suc zero) ⟧) ≤ getRound q' → getRound q' ≤ getRound (c3 b⟦ zero ⟧) → NonInjective-≡-pred (InSys ∘ B) bId ⊎ B (c3 b⟦ suc (suc zero) ⟧) ∈RC rc' propS4-base {q' = q'} prev∈sys rc0@(step {B b} rc'@(step rc'' q←b) b←q@(B←Q refl _)) rc'All∈sys c3 hyp0 hyp1 with propS4-base-lemma-1 c3 (getRound b) hyp0 hyp1 ...| here r with propS4-base-lemma-2 prev∈sys q' (All-InSys⇒last-InSys rc'All∈sys) rc' (All-InSys-unstep rc'All∈sys) b←q c3 zero (sym r) ...| inj₁ hb = inj₁ hb ...| inj₂ res with 𝕂-chain-∈RC c3 zero (suc (suc zero)) z≤n res rc' ...| inj₁ (hb , (p1 , p2)) = inj₁ (hb , (prev∈sys p1 , rc'All∈sys (there b←q p2))) ...| inj₂ res' = inj₂ (there b←q res') propS4-base {q} {q'} prev∈sys rc0@(step rc' b←q@(B←Q refl x₀)) rc'All∈sys c3 hyp0 hyp1 | there (here r) with propS4-base-lemma-2 prev∈sys q' (All-InSys⇒last-InSys rc'All∈sys) rc' (All-InSys-unstep rc'All∈sys) (B←Q refl x₀) c3 (suc zero) (sym r) ...| inj₁ hb = inj₁ hb ...| inj₂ res with 𝕂-chain-∈RC c3 (suc zero) (suc (suc zero)) (s≤s z≤n) res rc' ...| inj₁ (hb , (p1 , p2)) = inj₁ (hb , ((prev∈sys p1) , (rc'All∈sys (there b←q p2)))) ...| inj₂ res' = inj₂ (there (B←Q refl x₀) res') propS4-base {q' = q'} prev∈sys rc0@(step rc' (B←Q refl x₀)) rc'All∈sys c3 hyp0 hyp1 | there (there (here r)) with propS4-base-lemma-2 prev∈sys q' (All-InSys⇒last-InSys rc'All∈sys) rc' (All-InSys-unstep rc'All∈sys) (B←Q refl x₀) c3 (suc (suc zero)) (sym r) ...| inj₁ hb = inj₁ hb ...| inj₂ res with 𝕂-chain-∈RC c3 (suc (suc zero)) (suc (suc zero)) (s≤s (s≤s z≤n)) res rc' ...| inj₁ (hb , (p1 , p2)) = inj₁ (hb , (prev∈sys p1 , rc'All∈sys (there (B←Q refl x₀) p2))) ...| inj₂ res' = inj₂ (there (B←Q refl x₀) res') propS4 : ∀{q q'} → {rc : RecordChain (Q q)} → All-InSys rc → (rc' : RecordChain (Q q')) → All-InSys rc' → (c3 : 𝕂-chain Contig 3 rc) -- This is B₀ ← C₀ ← B₁ ← C₁ ← B₂ ← C₂ in S4 → getRound (c3 b⟦ suc (suc zero) ⟧) ≤ getRound q' -- In the paper, the proposition states that B₀ ←⋆ B, yet, B is the block preceding -- C, which in our case is 'prevBlock rc''. Hence, to say that B₀ ←⋆ B is -- to say that B₀ is a block in the RecordChain that goes all the way to C. → NonInjective-≡-pred (InSys ∘ B) bId ⊎ B (c3 b⟦ suc (suc zero) ⟧) ∈RC rc' propS4 {q' = q'} {rc} prev∈sys (step rc' b←q') prev∈sys' c3 hyp with getRound q' ≤?ℕ getRound (c3 b⟦ zero ⟧) ...| yes rq≤rb₂ = propS4-base {q' = q'} prev∈sys (step rc' b←q') prev∈sys' c3 hyp rq≤rb₂ propS4 {q' = q'} prev∈sys (step rc' b←q') all∈sys c3 hyp | no rb₂<rq with lemmaS3 prev∈sys (step rc' b←q') all∈sys c3 (subst (_< getRound q') (kchainBlockRoundZero-lemma c3) (≰⇒> rb₂<rq)) ...| inj₁ hb = inj₁ hb ...| inj₂ ls3 with rc' | b←q' ...| step rc'' q←b | (B←Q {b} rx x) with rc'' | q←b ...| empty | (I←B _ _) = contradiction (n≤0⇒n≡0 ls3) (¬bRound≡0 (kchain-to-RecordChain-at-b⟦⟧ c3 (suc (suc zero)))) ...| step {r = r} rc''' (B←Q {q = q''} refl bid≡) | (Q←B ry y) with propS4 {q' = q''} prev∈sys (step rc''' (B←Q refl bid≡)) (All-InSys-unstep (All-InSys-unstep all∈sys)) c3 ls3 ...| inj₁ hb' = inj₁ hb' ...| inj₂ final = inj₂ (there (B←Q rx x) (there (Q←B ry y) final)) ------------------- -- Theorem S5 thmS5 : ∀{q q'} → {rc : RecordChain (Q q )} → All-InSys rc → {rc' : RecordChain (Q q')} → All-InSys rc' → {b b' : Block} → CommitRule rc b → CommitRule rc' b' → NonInjective-≡-pred (InSys ∘ B) bId ⊎ ((B b) ∈RC rc' ⊎ (B b') ∈RC rc) -- Not conflicting means one extends the other. thmS5 {rc = rc} prev∈sys {rc'} prev∈sys' (commit-rule c3 refl) (commit-rule c3' refl) with <-cmp (getRound (c3 b⟦ suc (suc zero) ⟧)) (getRound (c3' b⟦ suc (suc zero) ⟧)) ...| tri≈ _ r≡r' _ = inj₁ <⊎$> (propS4 prev∈sys rc' prev∈sys' c3 (≤-trans (≡⇒≤ r≡r') (kchain-round-≤-lemma' c3' (suc (suc zero))))) ...| tri< r<r' _ _ = inj₁ <⊎$> (propS4 prev∈sys rc' prev∈sys' c3 (≤-trans (≤-unstep r<r') (kchain-round-≤-lemma' c3' (suc (suc zero))))) ...| tri> _ _ r'<r = inj₂ <⊎$> (propS4 prev∈sys' rc prev∈sys c3' (≤-trans (≤-unstep r'<r) (kchain-round-≤-lemma' c3 (suc (suc zero)))))
50.758755
151
0.549713
a08bbc5afaae60cc6bce3a0d22b1f99a8eb9c58d
1,407
agda
Agda
stdlib-exts/Monads/StateT.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
stdlib-exts/Monads/StateT.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
stdlib-exts/Monads/StateT.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
module Monads.StateT where open import Class.Monad open import Class.Functor open import Class.MonadTrans open import Class.Monad.State open import Class.Monad.Writer open import Data.Product open import Data.Unit.Polymorphic open import Function open import Level private variable a : Level S : Set a StateT : (Set a → Set a) → Set a → Set a → Set (a) StateT M S A = S → M (A × S) module _ {M : Set a → Set a} {{_ : Monad M}} {S} where instance StateT-Monad : Monad (StateT M S) StateT-Monad = record { _>>=_ = helper ; return = λ a → λ s → return (a , s) } where helper : ∀ {A B} → StateT M S A → (A → StateT M S B) → StateT M S B helper x f = λ s → do (a' , s') ← x s f a' s' StateT-MonadState : MonadState (StateT M S) S MonadState.get StateT-MonadState s = return (s , s) MonadState.put StateT-MonadState s = λ s' → return (tt , s) instance StateT-MonadTrans : MonadTrans (λ M → StateT M S) StateT-MonadTrans = record { embed = λ x s → (_, s) <$> x } StateT-MonadWriter : ∀ {M W} {{_ : Monad M}} {{_ : MonadWriter M W}} → MonadWriter (StateT M S) W StateT-MonadWriter = record { tell = λ w s → tell w >>= λ _ → return (tt , s) ; listen = λ x s → listen (x s) >>= λ { ((a , s') , w) → return ((a , w) , s') } ; pass = λ x s → x s >>= λ { (x' , s') → pass (return x') >>= λ a → return (a , s') } }
30.586957
91
0.577825
03b5f493d6768cb91346a6c499d81ad58c483516
957
agda
Agda
test/Succeed/Issue286.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue286.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue286.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module Issue286 where open import Common.Level data Bool : Set where true false : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} data _≡_ {ℓ : Level} {A : Set ℓ} : A → A → Set ℓ where refl : {a : A} → a ≡ a {-# BUILTIN EQUALITY _≡_ #-} primitive primEraseEquality : ∀ {a} {A : Set a} {x y : A} → x ≡ y → x ≡ y {-# BUILTIN STRING String #-} primitive primStringEquality : String → String → Bool data Maybe (A : Set) : Set where just : A → Maybe A nothing : Maybe A _≟_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂) s₁ ≟ s₂ with primStringEquality s₁ s₂ ... | true = just (primEraseEquality trustMe) where postulate trustMe : _ ≡ _ ... | false = nothing _≟′_ : (s₁ s₂ : String) → Maybe (s₁ ≡ s₂) s₁ ≟′ s₂ with s₁ ≟ s₂ s ≟′ .s | just refl = just refl _ ≟′ _ | nothing = nothing test : Maybe ("" ≡ "") test = "" ≟′ "" ok : test ≡ just refl ok = refl
20.361702
65
0.585162
9a277d5f3f42cfdbd15bcf2de6159d6a0e0eca9f
369
agda
Agda
src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- 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 Util.Prelude module LibraBFT.Impl.OBM.ECP-LBFT-OBM-Diff.ECP-LBFT-OBM-Diff-0 where enabled : Bool enabled = true
28.384615
111
0.766938
236953fc00934b841d3f9565f5685b76230e1ff8
1,721
agda
Agda
test/Compiler/simple/WfRec.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/WfRec.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/WfRec.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 Common.Prelude renaming (_∸_ to _-_) -- work-around for #1855 data Acc {a} {A : Set a} (_<_ : A → A → Set) (x : A) : Set a where acc : (∀ y → y < x → Acc _<_ y) → Acc _<_ x data _<_ : Nat → Nat → Set where zero : ∀ {n} → zero < suc n suc : ∀ {n m} → n < m → suc n < suc m _≤_ : Nat → Nat → Set n ≤ m = n < suc m data LeqView (n : Nat) : Nat → Set where less : ∀ {m} → n < m → LeqView n m equal : LeqView n n leqView : ∀ {n m} → n ≤ m → LeqView n m leqView {m = zero} zero = equal leqView {m = suc m} zero = less zero leqView {m = zero} (suc ()) leqView {m = suc m} (suc leq) with leqView leq leqView {._} {suc m} (suc leq) | less lt = less (suc lt) leqView {.(suc m)} {suc m} (suc lt) | equal = equal case_of_ : ∀ {A B : Set} → A → (A → B) → B case x of f = f x wfAux : ∀ {n y} → (∀ z → z < n → Acc _<_ z) → y ≤ n → Acc _<_ y wfAux f leq with leqView leq wfAux f leq | less lt = f _ lt wfAux f leq | equal = acc f wfNat : ∀ n → Acc _<_ n wfNat zero = acc λ _ () wfNat (suc n) with wfNat n ... | acc f = acc (λ y lt → wfAux f lt) ≤-refl : ∀ n → n ≤ n ≤-refl zero = zero ≤-refl (suc n) = suc (≤-refl n) wk< : ∀ {n m} → n < m → n < suc m wk< zero = zero wk< (suc lt) = suc (wk< lt) less-minus : ∀ n m → (suc n - suc m) ≤ n less-minus n zero = ≤-refl n less-minus zero (suc m) = zero less-minus (suc n) (suc m) = wk< (less-minus n m) NonZero : Nat → Set NonZero zero = ⊥ NonZero (suc _) = ⊤ divsuc : ∀ n → Nat → Acc _<_ n → Nat divsuc 0 _ _ = 0 divsuc (suc n) m (acc f) = suc (divsuc (n - m) m (f _ (less-minus n m))) div : Nat → (m : Nat) → {_ : NonZero m} → Nat div n zero {} div n (suc m) = divsuc n m (wfNat n) main : IO Unit main = printNat (div 1000000 1000)
24.942029
73
0.545613
ad242c6b465c42620b2b265b6dc5329a3f1853d0
2,385
agda
Agda
theorems/homotopy/WedgeExtension.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/homotopy/WedgeExtension.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/homotopy/WedgeExtension.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT module homotopy.WedgeExtension {i j} {A : Type i} {a₀ : A} {B : Type j} {b₀ : B} where -- easier to keep track of than a long list of arguments record args : Type (lmax (lsucc i) (lsucc j)) where field n m : ℕ₋₂ {{cA}} : is-connected (S n) A {{cB}} : is-connected (S m) B P : A → B → (n +2+ m) -Type (lmax i j) f : (a : A) → fst (P a b₀) g : (b : B) → fst (P a₀ b) p : f a₀ == g b₀ module WedgeExt (r : args) where private module _ (r : args) where open args r Q : A → n -Type (lmax i j) Q a = ((Σ (∀ b → fst (P a b)) (λ k → (k ∘ cst b₀) == cst (f a)) , conn-extend-general (pointed-conn-out B b₀) (P a) (cst (f a)))) l : Π A (fst ∘ Q) l = conn-extend (pointed-conn-out A a₀) Q (λ (_ : Unit) → (g , ap cst (! p))) open args r ext : ∀ a → ∀ b → fst (P a b) ext a = fst (l r a) abstract β-l : ∀ a → ext a b₀ == f a β-l a = ap (λ t → t unit) (snd (l r a)) private abstract β-r-aux : fst (l r a₀) == g β-r-aux = fst= (conn-extend-β (pointed-conn-out A a₀) (Q r) (λ (_ : Unit) → (g , ap cst (! p))) unit) abstract β-r : ∀ b → ext a₀ b == g b β-r = app= β-r-aux abstract coh : ! (β-l a₀) ∙ β-r b₀ == p coh = ! (β-l a₀) ∙ β-r b₀ =⟨ ! lemma₂ |in-ctx (λ w → ! w ∙ β-r b₀) ⟩ ! (β-r b₀ ∙ ! p) ∙ β-r b₀ =⟨ !-∙ (β-r b₀) (! p) |in-ctx (λ w → w ∙ β-r b₀) ⟩ (! (! p) ∙ ! (β-r b₀)) ∙ β-r b₀ =⟨ ∙-assoc (! (! p)) (! (β-r b₀)) (β-r b₀) ⟩ ! (! p) ∙ (! (β-r b₀) ∙ β-r b₀) =⟨ ap2 _∙_ (!-! p) (!-inv-l (β-r b₀)) ⟩ p ∙ idp =⟨ ∙-unit-r p ⟩ p =∎ where lemma₁ : β-l a₀ == ap (λ s → s unit) (ap cst (! p)) [ (λ k → k b₀ == f a₀) ↓ β-r-aux ] lemma₁ = ap↓ (ap (λ s → s unit)) $ snd= (conn-extend-β (pointed-conn-out A a₀) (Q r) (λ (_ : Unit) → (g , ap cst (! p))) unit) lemma₂ : β-r b₀ ∙ ! p == β-l a₀ lemma₂ = ap (λ w → β-r b₀ ∙ w) (! (ap-idf (! p)) ∙ ap-∘ (λ s → s unit) cst (! p)) ∙ (! (↓-app=cst-out lemma₁))
30.189873
74
0.386164
4ac8448d0daba9dfbdaa92a6758934084d184977
1,864
agda
Agda
agda-stdlib-0.9/src/Data/List/All.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/List/All.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/List/All.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Lists where all elements satisfy a given property ------------------------------------------------------------------------ module Data.List.All where open import Data.List as List hiding (map; all) open import Data.List.Any as Any using (here; there) open Any.Membership-≡ using (_∈_; _⊆_) open import Function open import Level open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Unary using (Decidable) renaming (_⊆_ to _⋐_) open import Relation.Binary.PropositionalEquality -- All P xs means that all elements in xs satisfy P. infixr 5 _∷_ data All {a p} {A : Set a} (P : A → Set p) : List A → Set (p ⊔ a) where [] : All P [] _∷_ : ∀ {x xs} (px : P x) (pxs : All P xs) → All P (x ∷ xs) head : ∀ {a p} {A : Set a} {P : A → Set p} {x xs} → All P (x ∷ xs) → P x head (px ∷ pxs) = px tail : ∀ {a p} {A : Set a} {P : A → Set p} {x xs} → All P (x ∷ xs) → All P xs tail (px ∷ pxs) = pxs lookup : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A} → All P xs → (∀ {x : A} → x ∈ xs → P x) lookup [] () lookup (px ∷ pxs) (here refl) = px lookup (px ∷ pxs) (there x∈xs) = lookup pxs x∈xs tabulate : ∀ {a p} {A : Set a} {P : A → Set p} {xs} → (∀ {x} → x ∈ xs → P x) → All P xs tabulate {xs = []} hyp = [] tabulate {xs = x ∷ xs} hyp = hyp (here refl) ∷ tabulate (hyp ∘ there) map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} → P ⋐ Q → All P ⋐ All Q map g [] = [] map g (px ∷ pxs) = g px ∷ map g pxs all : ∀ {a p} {A : Set a} {P : A → Set p} → Decidable P → Decidable (All P) all p [] = yes [] all p (x ∷ xs) with p x all p (x ∷ xs) | yes px = Dec.map′ (_∷_ px) tail (all p xs) all p (x ∷ xs) | no ¬px = no (¬px ∘ head)
32.137931
72
0.497318
59d9e95076388ea3e5bc8c654e9d9c395d0fbcf3
2,105
agda
Agda
src/Implicits/Resolution/Finite/Expressiveness.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Implicits/Resolution/Finite/Expressiveness.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Implicits/Resolution/Finite/Expressiveness.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
open import Prelude module Implicits.Resolution.Finite.Expressiveness where open import Coinduction open import Data.Fin.Substitution open import Implicits.Syntax open import Implicits.Substitutions open import Implicits.Resolution.Deterministic.Resolution as D open import Implicits.Resolution.Ambiguous.Resolution as A open import Implicits.Resolution.Finite.Resolution as F open import Implicits.Resolution.Infinite.Resolution as ∞ open import Implicits.Resolution.Termination module Finite⊆Infinite where p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ ∞.⊢ᵣ a p (r-simp a a↓τ) = r-simp a (lem a↓τ) where lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ ∞.⊢ a ↓ τ lem (i-simp τ) = i-simp τ lem (i-iabs _ ⊢ᵣa b↓τ) = i-iabs (p ⊢ᵣa) (lem b↓τ) lem (i-tabs b a[/b]↓τ) = i-tabs b (lem a[/b]↓τ) p (r-iabs x) = r-iabs (p x) p (r-tabs x) = r-tabs (p x) module Finite⊆Ambiguous where p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ A.⊢ᵣ a p (r-simp a a↓τ) = lem a↓τ (r-ivar a) where lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ A.⊢ᵣ a → Δ A.⊢ᵣ simpl τ lem (i-simp τ) K⊢ᵣτ = K⊢ᵣτ lem (i-iabs _ ⊢ᵣa b↓τ) K⊢ᵣa⇒b = lem b↓τ (r-iapp K⊢ᵣa⇒b (p ⊢ᵣa)) lem (i-tabs b a[/b]↓τ) K⊢ᵣ∀a = lem a[/b]↓τ (r-tapp b K⊢ᵣ∀a) p (r-iabs x) = r-iabs (p x) p (r-tabs x) = r-tabs (p x) module Deterministic⊆Finite where open import Extensions.ListFirst -- Oliveira's termination condition is part of the well-formdness of types -- So we assume here that ⊢term x holds for all types x p : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → (∀ {ν} (a : Type ν) → ⊢term a) → Δ D.⊢ᵣ a → Δ F.⊢ᵣ a p term (r-simp {ρ = r} x r↓a) = r-simp (proj₁ $ first⟶∈ x) (lem r↓a) where lem : ∀ {ν} {Δ : ICtx ν} {a r} → Δ D.⊢ r ↓ a → Δ F.⊢ r ↓ a lem (i-simp a) = i-simp a lem (i-iabs {ρ₁ = ρ₁} {ρ₂ = ρ₂} ⊢ᵣρ₁ ρ₂↓τ) with term (ρ₁ ⇒ ρ₂) lem (i-iabs ⊢ᵣρ₁ ρ₂↓τ) | term-iabs _ _ a-ρ<-b _ = i-iabs a-ρ<-b (p term ⊢ᵣρ₁) (lem ρ₂↓τ) lem (i-tabs b x₁) = i-tabs b (lem x₁) p term (r-iabs ρ₁ {ρ₂ = ρ₂} x) = r-iabs (p term x) p term (r-tabs x) = r-tabs (p term x)
37.589286
94
0.581473
addcb729e997b5c8ce690a2f1e9378ba337dd512
8,033
agda
Agda
theorems/stash/cohomology/MayerVietorisExact.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/stash/cohomology/MayerVietorisExact.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/stash/cohomology/MayerVietorisExact.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import groups.ExactSequence open import homotopy.FunctionOver open import homotopy.PtdAdjoint open import homotopy.SuspAdjointLoop open import cohomology.MayerVietoris open import cohomology.Theory {- Standard Mayer-Vietoris exact sequence (algebraic) derived from - the result in cohomology.MayerVietoris (topological). - This is a whole bunch of algebra which is not very interesting. -} module cohomology.MayerVietorisExact {i} (CT : CohomologyTheory i) (n : ℤ) (ps : ⊙Span {i} {i} {i}) where open MayerVietorisFunctions ps module MV = MayerVietoris ps open ⊙Span ps open CohomologyTheory CT open import cohomology.BaseIndependence CT open import cohomology.Functor CT open import cohomology.InverseInSusp CT open import cohomology.LongExactSequence CT n ⊙reglue open import cohomology.Wedge CT mayer-vietoris-seq : HomSequence _ _ mayer-vietoris-seq = C n (⊙Pushout ps) ⟨ ×ᴳ-fanout (CF-hom n (⊙left ps)) (CF-hom n (⊙right ps)) ⟩→ C n X ×ᴳ C n Y ⟨ ×ᴳ-fanin (C-is-abelian _ _) (CF-hom n f) (inv-hom _ (C-is-abelian _ _) ∘ᴳ (CF-hom n g)) ⟩→ C n Z ⟨ CF-hom (succ n) ⊙extract-glue ∘ᴳ fst ((C-Susp n Z)⁻¹ᴳ) ⟩→ C (succ n) (⊙Pushout ps) ⟨ ×ᴳ-fanout (CF-hom _ (⊙left ps)) (CF-hom _ (⊙right ps)) ⟩→ C (succ n) X ×ᴳ C (succ n) Y ⊣| mayer-vietoris-exact : is-exact-seq mayer-vietoris-seq mayer-vietoris-exact = transport (λ {(r , s) → is-exact-seq s}) (pair= _ $ sequence= _ _ $ idp ∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙Wedge-rec-over n X Y _ _) ⟩∥ CWedge.path n X Y ∥⟨ ↓-over-×-in' _→ᴳ_ (ap↓ (λ φ → φ ∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-↓cod= (succ n) MV.ext-over) ∙ᵈ codomain-over-iso {χ = diff'} (codomain-over-equiv _ _)) (CWedge.Wedge-hom-η n X Y _ ▹ ap2 (×ᴳ-fanin (C-is-abelian n Z)) inl-lemma inr-lemma) ⟩∥ ap (C (succ n)) MV.⊙path ∙ uaᴳ (C-Susp n Z) ∥⟨ ↓-over-×-in _→ᴳ_ (CF-↓dom= (succ n) MV.cfcod-over ∙ᵈ domain-over-iso (! (ap (λ h → CF _ ⊙extract-glue ∘ h) (λ= (is-equiv.g-f (snd (C-Susp n Z))))) ◃ domain-over-equiv _ _)) idp ⟩∥ idp ∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙Wedge-rec-over (succ n) X Y _ _) ⟩∥ CWedge.path (succ n) X Y ∥⊣|) long-cofiber-exact where {- shorthand -} diff' = fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ) {- Variations on suspension axiom naturality -} natural-lemma₁ : {X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y) → (fst (C-Susp n X) ∘ᴳ CF-hom _ (⊙Susp-fmap f)) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ) == CF-hom n f natural-lemma₁ {X} {Y} n f = ap (λ φ → φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (C-SuspF n f) ∙ group-hom= (λ= (ap (CF n f) ∘ is-equiv.f-g (snd (C-Susp n Y)))) natural-lemma₂ : {X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y) → CF-hom _ (⊙Susp-fmap f) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ) == fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ CF-hom n f natural-lemma₂ {X} {Y} n f = group-hom= (λ= (! ∘ is-equiv.g-f (snd (C-Susp n X)) ∘ CF _ (⊙Susp-fmap f) ∘ GroupHom.f (fst (C-Susp n Y ⁻¹ᴳ)))) ∙ ap (λ φ → fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ φ) (natural-lemma₁ n f) {- Associativity lemmas -} assoc-lemma : ∀ {i} {G H K L J : Group i} (φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H) → (φ ∘ᴳ ψ) ∘ᴳ χ ∘ᴳ ξ == φ ∘ᴳ ((ψ ∘ᴳ χ) ∘ᴳ ξ) assoc-lemma _ _ _ _ = group-hom= idp assoc-lemma₂ : ∀ {i} {G H K L J : Group i} (φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H) → (φ ∘ᴳ ψ ∘ᴳ χ) ∘ᴳ ξ == φ ∘ᴳ ψ ∘ᴳ χ ∘ᴳ ξ assoc-lemma₂ _ _ _ _ = group-hom= idp inl-lemma : diff' ∘ᴳ CF-hom n (⊙projl X Y) == CF-hom n f inl-lemma = assoc-lemma₂ (fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff) (fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projl X Y)) ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ) (! (natural-lemma₂ n (⊙projl X Y))) ∙ ! (assoc-lemma₂ (fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff) (CF-hom _ (⊙Susp-fmap (⊙projl X Y))) (fst (C-Susp n X ⁻¹ᴳ))) ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ)) (! (CF-comp _ (⊙Susp-fmap (⊙projl X Y)) MV.⊙mv-diff)) ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ)) (CF-λ= (succ n) projl-mv-diff) ∙ natural-lemma₁ n f where {- Compute the left projection of mv-diff -} projl-mv-diff : (σz : fst (⊙Susp Z)) → Susp-fmap (projl X Y) (MV.mv-diff σz) == Susp-fmap (fst f) σz projl-mv-diff = Susp-elim idp (merid (pt X)) $ ↓-='-from-square ∘ λ z → (ap-∘ (Susp-fmap (projl X Y)) MV.mv-diff (merid z) ∙ ap (ap (Susp-fmap (projl X Y))) (MV.MVDiff.merid-β z) ∙ ap-∙ (Susp-fmap (projl X Y)) (merid (winl (fst f z))) (! (merid (winr (fst g z)))) ∙ (SuspFmap.merid-β (projl X Y) (winl (fst f z)) ∙2 (ap-! (Susp-fmap _) (merid (winr (fst g z))) ∙ ap ! (SuspFmap.merid-β (projl X Y) (winr (fst g z)))))) ∙v⊡ (vid-square {p = merid (fst f z)} ⊡h rt-square (merid (pt X))) ⊡v∙ (∙-unit-r _ ∙ ! (SuspFmap.merid-β (fst f) z)) inr-lemma : diff' ∘ᴳ CF-hom n (⊙projr X Y) == inv-hom _ (C-is-abelian n Z) ∘ᴳ CF-hom n g inr-lemma = assoc-lemma₂ (fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff) (fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projr X Y)) ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ) (! (natural-lemma₂ n (⊙projr X Y))) ∙ ! (assoc-lemma₂ (fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff) (CF-hom _ (⊙Susp-fmap (⊙projr X Y))) (fst (C-Susp n Y ⁻¹ᴳ))) ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (! (CF-comp _ (⊙Susp-fmap (⊙projr X Y)) MV.⊙mv-diff)) ∙ ∘ᴳ-assoc (fst (C-Susp n Z)) (CF-hom _ (⊙Susp-fmap (⊙projr X Y) ⊙∘ MV.⊙mv-diff)) (fst (C-Susp n Y ⁻¹ᴳ)) ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (CF-λ= (succ n) projr-mv-diff) ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (CF-comp _ (⊙Susp-fmap g) (⊙Susp-flip Z)) ∙ ! (assoc-lemma (fst (C-Susp n Z)) (CF-hom _ (⊙Susp-flip Z)) (CF-hom _ (⊙Susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ))) ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ CF-hom _ (⊙Susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (C-Susp-flip-is-inv (succ n)) ∙ ap (λ φ → φ ∘ᴳ CF-hom _ (⊙Susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (inv-hom-natural (C-is-abelian _ _) (C-is-abelian _ _) (fst (C-Susp n Z))) ∙ assoc-lemma (inv-hom _ (C-is-abelian n Z)) (fst (C-Susp n Z)) (CF-hom _ (⊙Susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ)) ∙ ap (λ φ → inv-hom _ (C-is-abelian n Z) ∘ᴳ φ) (natural-lemma₁ n g) where {- Compute the right projection of mv-diff -} projr-mv-diff : (σz : fst (⊙Susp Z)) → Susp-fmap (projr X Y) (MV.mv-diff σz) == Susp-fmap (fst g) (Susp-flip σz) projr-mv-diff = Susp-elim (merid (pt Y)) idp $ ↓-='-from-square ∘ λ z → (ap-∘ (Susp-fmap (projr X Y)) MV.mv-diff (merid z) ∙ ap (ap (Susp-fmap (projr X Y))) (MV.MVDiff.merid-β z) ∙ ap-∙ (Susp-fmap (projr X Y)) (merid (winl (fst f z))) (! (merid (winr (fst g z)))) ∙ (SuspFmap.merid-β (projr X Y) (winl (fst f z)) ∙2 (ap-! (Susp-fmap (projr X Y)) (merid (winr (fst g z))) ∙ ap ! (SuspFmap.merid-β (projr X Y) (winr (fst g z)))))) ∙v⊡ ((lt-square (merid (pt Y)) ⊡h vid-square {p = ! (merid (fst g z))})) ⊡v∙ ! (ap-∘ (Susp-fmap (fst g)) Susp-flip (merid z) ∙ ap (ap (Susp-fmap (fst g))) (FlipSusp.merid-β z) ∙ ap-! (Susp-fmap (fst g)) (merid z) ∙ ap ! (SuspFmap.merid-β (fst g) z))
42.728723
76
0.506038
1e931feb0ec9853e2cc5073b649647bcde9b647b
3,668
agda
Agda
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.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.NaturalTransformation.NaturalIsomorphism.Properties where open import Level open import Categories.Category open import Categories.Category.Instance.Setoids open import Categories.Functor renaming (id to idF) open import Categories.Functor.Construction.LiftSetoids open import Categories.NaturalTransformation.NaturalIsomorphism open import Categories.NaturalTransformation.Properties import Categories.Morphism as Mor import Categories.Morphism.Properties as Morₚ import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D : Category o ℓ e module _ {F G : Functor C D} where private module C = Category C module F = Functor F module G = Functor G open Category D open Mor D open _≅_ -- We can construct a natural isomorphism from a pointwise isomorphism, provided that we can show naturality in one direction. pointwise-iso : (iso : ∀ X → F.F₀ X ≅ G.F₀ X) → (∀ {X Y} → (f : C [ X , Y ]) → from (iso Y) ∘ F.F₁ f ≈ G.F₁ f ∘ from (iso X)) → NaturalIsomorphism F G pointwise-iso iso commute = niHelper record { η = λ X → from (iso X) ; η⁻¹ = λ X → to (iso X) ; commute = commute ; iso = λ X → record { isoˡ = isoˡ (iso X) ; isoʳ = isoʳ (iso X) } } module _ {F G : Functor C D} (α : NaturalIsomorphism F G) where private module C = Category C open Category D open Mor D open Functor F open Functor G renaming (F₀ to G₀; F₁ to G₁) open NaturalIsomorphism α -- We can move equations along natural isomorphism. module _ {A B} {f g : A C.⇒ B} where push-eq : F₁ f ≈ F₁ g → G₁ f ≈ G₁ g push-eq hyp = MR.push-eq D FX≅GX (⇒.commute f) (⇒.commute g) hyp pull-eq : G₁ f ≈ G₁ g → F₁ f ≈ F₁ g pull-eq hyp = MR.push-eq D (≅.sym FX≅GX) (⇐.commute f) (⇐.commute g) hyp -- properties of natural isomorphisms over an endofunctor module _ {F : Endofunctor C} where private module C = Category C module F = Functor F module MC = Mor C module _ (α : F ≃ idF) where open C open HomReasoning open F open MC open MR C open Mor C open Morₚ C open NaturalIsomorphism α F≃id-comm₁ : ∀ {A} → ⇒.η (F₀ A) ≈ F₁ (⇒.η A) F≃id-comm₁ {A} = begin ⇒.η (F₀ A) ≈⟨ introʳ (F-resp-≈ (iso.isoˡ _) ○ identity) ⟩ ⇒.η (F₀ A) ∘ F₁ (⇐.η A ∘ ⇒.η A) ≈⟨ refl⟩∘⟨ homomorphism ⟩ ⇒.η (F₀ A) ∘ F₁ (⇐.η A) ∘ F₁ (⇒.η A) ≈⟨ cancelˡ (⇒.commute _ ○ iso.isoˡ _) ⟩ F₁ (⇒.η A) ∎ F≃id-comm₂ : ∀ {A} → ⇐.η (F₀ A) ≈ F₁ (⇐.η A) F≃id-comm₂ {A} = begin ⇐.η (F₀ A) ≈⟨ introˡ (F-resp-≈ (iso.isoˡ _) ○ identity) ⟩ F₁ (⇐.η A ∘ ⇒.η A) ∘ ⇐.η (F₀ A) ≈⟨ homomorphism ⟩∘⟨refl ⟩ (F₁ (⇐.η A) ∘ F₁ (⇒.η A)) ∘ ⇐.η (F₀ A) ≈⟨ cancelʳ (⟺ (⇐.commute _) ○ iso.isoˡ _) ⟩ F₁ (⇐.η A) ∎ F≃id⇒id : ∀ {A} {f : A ⇒ A} → F₁ f ≈ id → f ≈ id F≃id⇒id {A} {f} eq = Iso⇒Mono (Iso-swap (iso A)) _ _ helper where helper : ⇐.η A ∘ f ≈ ⇐.η A ∘ id helper = begin ⇐.η A ∘ f ≈⟨ ⇐.commute f ⟩ F₁ f ∘ ⇐.η A ≈⟨ eq ⟩∘⟨refl ⟩ id ∘ ⇐.η A ≈˘⟨ id-comm ⟩ ⇐.η A ∘ id ∎ -- unlift universe level module _ {c ℓ ℓ′ e} {F G : Functor C (Setoids c ℓ)} (α : LiftSetoids ℓ′ e ∘F F ≃ LiftSetoids ℓ′ e ∘F G) where open NaturalIsomorphism α unlift-≃ : F ≃ G unlift-≃ = record { F⇒G = unlift-nat F⇒G ; F⇐G = unlift-nat F⇐G ; iso = λ X → record { isoˡ = λ eq → lower (iso.isoˡ X (lift eq)) ; isoʳ = λ eq → lower (iso.isoʳ X (lift eq)) } }
31.350427
152
0.558342
5e49b17025b2d5d88d1cf64eae36fe2330b4a37c
915
agda
Agda
test/Fail/PolarityProjectionLike.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/PolarityProjectionLike.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/PolarityProjectionLike.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2015-06-29 polarity handling is broken -- See also issue 1592 -- {-# OPTIONS -v tc.polarity:20 -v tc.proj.like:100 #-} -- {-# OPTIONS -v tc.conv.elim:25 --show-implicit #-} {-# OPTIONS --sized-types #-} open import Common.Size open import Common.Prelude data D : Size → Set where c : ∀ i → D (↑ i) record Type (a : Bool) : Set1 where constructor mkType field type : Set open Type Opp : Set → Set Opp X = X → ⊥ -- projection-like contravariant function which does not unfold abstract Contra : ∀ a (T : Type a) → Set Contra a (mkType A) = Opp A -- Subtyping is broken for projection(-like) things. -- This is exploitable as Contra true (mkType X) does not reduce to Opp X here. cast : ∀{i} → Contra true (mkType (D i)) → Contra true (mkType (D (↑ i))) cast x = x -- Here it, does reduce. abstract loop : ∀{i} → D i → ⊥ loop (c i) = cast loop (c i) absurd : ⊥ absurd = loop (c ∞)
22.875
81
0.636066
8b92e07337915ff1c4d51e441817208a7dd4e36e
3,195
agda
Agda
RecursiveTypes.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
1
2021-02-13T14:48:45.000Z
2021-02-13T14:48:45.000Z
RecursiveTypes.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
RecursiveTypes.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Formalisation of subtyping for recursive types -- -- Nils Anders Danielsson ------------------------------------------------------------------------ -- This formalisation is explained in "Subtyping, Declaratively—An -- Exercise in Mixed Induction and Coinduction" (coauthored with -- Thorsten Altenkirch). The code is partly based on "Coinductive -- Axiomatization of Recursive Type Equality and Subtyping" by Michael -- Brandt and Fritz Henglein. module RecursiveTypes where -- Recursive types and potentially infinite trees. import RecursiveTypes.Syntax -- Substitutions. import RecursiveTypes.Substitution -- The semantics of recursive types, defined in terms of the trees -- that you get when unfolding them. import RecursiveTypes.Semantics -- The definition of subtyping which, in my eyes, is the most obvious. -- Some people may dislike coinductive definitions, though. import RecursiveTypes.Subtyping.Semantic.Coinductive -- An example. import RecursiveTypes.Subtyping.Example -- Another definition of subtyping, this time in terms of finite -- approximations. According to Brandt and Henglein this definition is -- due to Amadio and Cardelli. import RecursiveTypes.Subtyping.Semantic.Inductive -- The two semantical definitions of subtyping above can easily be -- proved equivalent. import RecursiveTypes.Subtyping.Semantic.Equivalence -- An axiomatisation of subtyping which is inspired by Brandt and -- Henglein's. The main difference is that their axiomatisation is -- inductive, using explicit hypotheses to get a coinductive flavour, -- whereas mine is mixed inductive/coinductive, using no explicit -- hypotheses. The axiomatisation is proved equivalent to the -- coinductive semantic definition of subtyping. The proof is a lot -- simpler than Brandt and Henglein's, but their proof includes a -- decision procedure for subtyping. import RecursiveTypes.Subtyping.Axiomatic.Coinductive -- Brandt and Henglein's axiomatisation, plus some proofs: -- • A proof showing that the axiomatisation is sound with respect to -- the ones above. The soundness proof is different from the one -- given by Brandt and Henglein: it is cyclic (but productive). -- • Proofs of decidability and completeness, based on Brandt and -- Henglein's algorithm. import RecursiveTypes.Subtyping.Axiomatic.Inductive -- Some modules containing supporting code for the proof of -- decidability, including Brandt and Henglein's subterm relation. import RecursiveTypes.Subterm import RecursiveTypes.Subterm.RestrictedHypothesis import RecursiveTypes.Syntax.UnfoldedOrFixpoint -- An incorrect "subtyping" relation which illustrates the fact that -- taking the transitive closure of a coinductively defined relation -- is not in general equivalent to adding an inductive transitivity -- constructor to it. import RecursiveTypes.Subtyping.Axiomatic.Incorrect -- Finally some code which is not directly related to subtyping or -- recursive types: an example which shows that, in a coinductive -- setting, it is not always sound to postulate admissible rules -- (inductively). import AdmissibleButNotPostulable
36.306818
72
0.763693
a0b061ac96fbc68c7fa4c941c3fe6a7bbe96ecb3
1,674
agda
Agda
bool-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
29
2019-02-06T13:09:31.000Z
2022-03-04T15:05:12.000Z
bool-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
8
2018-07-09T22:53:38.000Z
2022-03-22T03:43:34.000Z
bool-thms.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
17
2018-12-03T22:38:15.000Z
2021-11-28T20:13:21.000Z
module bool-thms where open import bool open import eq open import sum ~~-elim : ∀ (b : 𝔹) → ~ ~ b ≡ b ~~-elim tt = refl ~~-elim ff = refl &&-idem : ∀ {b} → b && b ≡ b &&-idem{tt} = refl &&-idem{ff} = refl ||-idem : ∀{b} → b || b ≡ b ||-idem{tt} = refl ||-idem{ff} = refl ||≡ff₁ : ∀ {b1 b2} → b1 || b2 ≡ ff → ff ≡ b1 ||≡ff₁ {ff} p = refl ||≡ff₁ {tt} p = sym p ||≡ff₂ : ∀ {b1 b2} → b1 || b2 ≡ ff → b2 ≡ ff ||≡ff₂ {tt} () ||≡ff₂ {ff}{tt} () ||≡ff₂ {ff}{ff} p = refl ||-tt : ∀ (b : 𝔹) → b || tt ≡ tt ||-tt tt = refl ||-tt ff = refl ||-cong₁ : ∀ {b1 b1' b2} → b1 ≡ b1' → b1 || b2 ≡ b1' || b2 ||-cong₁ refl = refl ||-cong₂ : ∀ {b1 b2 b2'} → b2 ≡ b2' → b1 || b2 ≡ b1 || b2' ||-cong₂ p rewrite p = refl ite-same : ∀{ℓ}{A : Set ℓ} → ∀(b : 𝔹) (x : A) → (if b then x else x) ≡ x ite-same tt x = refl ite-same ff x = refl ite-arg : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (f : A → B)(b : 𝔹)(x y : A) → (f (if b then x else y)) ≡ (if b then f x else f y) ite-arg f tt x y = refl ite-arg f ff x y = refl 𝔹-contra : ff ≡ tt → ∀{ℓ} {P : Set ℓ} → P 𝔹-contra () ||-split : ∀ {b b' : 𝔹} → b || b' ≡ tt → b ≡ tt ⊎ b' ≡ tt ||-split{tt}{tt} p = inj₁ refl ||-split{tt}{ff} p = inj₁ refl ||-split{ff}{tt} p = inj₂ refl ||-split{ff}{ff} () 𝔹-dec : ∀ (b : 𝔹) → b ≡ tt ⊎ b ≡ ff 𝔹-dec tt = inj₁ refl 𝔹-dec ff = inj₂ refl &&-snd : {p1 p2 : 𝔹} → p1 && p2 ≡ tt → p2 ≡ tt &&-snd{tt} p = p &&-snd{ff} () &&-fst : {p1 p2 : 𝔹} → p1 && p2 ≡ tt → p1 ≡ tt &&-fst{tt} p = refl &&-fst{ff} () &&-combo : {p1 p2 : 𝔹} → p1 ≡ tt → p2 ≡ tt → p1 && p2 ≡ tt &&-combo{tt} pr1 pr2 = pr2 &&-combo{ff} pr1 pr2 = 𝔹-contra pr1 &&-ff : ∀(b : 𝔹) → b && ff ≡ ff &&-ff tt = refl &&-ff ff = refl
22.026316
124
0.455795
38b3fe861795096d1526687381a6df87120113f9
175
agda
Agda
Agda/cubical-circle.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
333
2018-09-26T08:33:30.000Z
2022-03-22T23:50:15.000Z
Agda/cubical-circle.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
8
2019-06-18T04:16:04.000Z
2020-10-16T15:27:01.000Z
Agda/cubical-circle.agda
UlrikBuchholtz/HoTT-Intro
1e1f8def50f9359928e52ebb2ee53ed1166487d9
[ "CC-BY-4.0" ]
30
2018-09-26T09:08:57.000Z
2022-03-16T00:33:50.000Z
{-# OPTIONS --cubical #-} open import 10-number-theory open import Cubical.Core.Everything data circle-C : UU lzero where base : circle-C loop : Path circle-C base base
19.444444
35
0.72
039b02d025e27497dd30943a1165c94683df3075
627
agda
Agda
test/interaction/Issue2621.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2621.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2621.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Nat renaming (Nat to ℕ) open import Agda.Builtin.Equality data Vec (A : Set) : ℕ → Set where [] : Vec A zero _∷_ : ∀{n} (x : A) (xs : Vec A n) → Vec A (suc n) data All₂ {A : Set} {B : Set} (R : A → B → Set) : ∀ {k} → Vec A k → Vec B k → Set where [] : All₂ R [] [] _∷_ : ∀ {k x y} {xs : Vec A k} {ys : Vec B k} (r : R x y) (rs : All₂ R xs ys) → All₂ R (x ∷ xs) (y ∷ ys) Det : ∀ {A : Set} {B : Set} (R : A → B → Set) → Set Det R = ∀{a b c} → R a b → R a c → b ≡ c detAll₂ : ∀ {A : Set} {B : Set} (R : A → B → Set) (h : Det R) → Det (All₂ R) detAll₂ R h rab rac = {!rab!}
34.833333
87
0.467305
3d79f2765581142d3f85746e4d092c74e3b02c58
238
agda
Agda
Cubical/Foundations/Pointed.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Foundations/Pointed.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Foundations/Pointed.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Foundations.Pointed where open import Cubical.Foundations.Pointed.Base public open import Cubical.Foundations.Pointed.Properties public open import Cubical.Foundations.Pointed.Homogeneous
29.75
57
0.823529
8bcd4a048cbdbdc78a389358652a51bd81b96587
7,247
agda
Agda
src/Integer/Signed.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
9
2019-05-20T01:29:41.000Z
2020-01-16T07:16:26.000Z
src/Integer/Signed.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
null
null
null
src/Integer/Signed.agda
kcsmnt0/numbers
67ea7b96228c592daf79e800ebe4a7c12ed7221e
[ "MIT" ]
null
null
null
module Integer.Signed where open import Data.Empty as ⊥ open import Data.Product as Σ open import Data.Product.Relation.Pointwise.NonDependent open import Data.Sum as ⊎ open import Data.Unit as ⊤ open import Equality open import Function open import Natural as ℕ open import Quotient as / open import Relation.Binary open import Syntax open Equality.FunctionProperties ⟦ℤ⟧ = ℕ ⊎ ℕ ⟦ℤ²⟧ = ⟦ℤ⟧ × ⟦ℤ⟧ infix 10 +1*_ -1*_ pattern +1*_ x = inj₁ x pattern -1*_ x = inj₂ x infix 1 _≈_ _≈_ : ⟦ℤ⟧ → ⟦ℤ⟧ → Set +1* x ≈ +1* y = x ≡ y +1* x ≈ -1* y = x ≡ 0 × y ≡ 0 -1* x ≈ +1* y = x ≡ 0 × y ≡ 0 -1* x ≈ -1* y = x ≡ y ≈-refl : ∀ {x} → x ≈ x ≈-refl {+1* x} = refl ≈-refl { -1* x} = refl ≈-sym : ∀ {x y} → x ≈ y → y ≈ x ≈-sym {+1* x} {+1* y} = sym ≈-sym {+1* x} { -1* y} = Σ.swap ≈-sym { -1* x} {+1* y} = Σ.swap ≈-sym { -1* x} { -1* y} = sym ≈-trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z ≈-trans {+1* x} {+1* y} {+1* z} p q = compPath p q ≈-trans {+1* x} {+1* y} { -1* z} p (q , r) = p ≫ q , r ≈-trans {+1* x} { -1* y} {+1* z} (p , q) (r , s) = p ≫ sym s ≈-trans {+1* x} { -1* y} { -1* z} (p , q) r = p , sym r ≫ q ≈-trans { -1* x} {+1* y} {+1* z} (p , q) r = p , sym r ≫ q ≈-trans { -1* x} {+1* y} { -1* z} (p , q) (r , s) = p ≫ sym s ≈-trans { -1* x} { -1* y} {+1* z} p (q , r) = p ≫ q , r ≈-trans { -1* x} { -1* y} { -1* z} p q = compPath p q ℤ = ⟦ℤ⟧ / _≈_ ℤ² = ⟦ℤ²⟧ / Pointwise _≈_ _≈_ instance ⟦ℤ⟧-Number : Number ⟦ℤ⟧ ⟦ℤ⟧-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ n → +1* n } ℤ-Number : Number ℤ ℤ-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ n → ⟦ fromNat n ⟧ } ⟦ℤ⟧-Negative : Negative ⟦ℤ⟧ ⟦ℤ⟧-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ n → -1* n } ℤ-Negative : Negative ℤ ℤ-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ n → ⟦ fromNeg n ⟧ } ⟦negate⟧ : ⟦ℤ⟧ → ⟦ℤ⟧ ⟦negate⟧ (+1* n) = -1* n ⟦negate⟧ (-1* n) = +1* n negate : ℤ → ℤ negate = ⟦negate⟧ // λ where (+1* x) (+1* y) → id (+1* x) (-1* y) → id (-1* x) (+1* y) → id (-1* x) (-1* y) → id ℕ-minus : ℕ → ℕ → ⟦ℤ⟧ ℕ-minus zero n = -1* n ℕ-minus m zero = +1* m ℕ-minus (suc m) (suc n) = ℕ-minus m n instance ℕ-minus-syntax : minus-syntax-simple ℕ ℕ ⟦ℤ⟧ ℕ-minus-syntax = λ where ._-_ → ℕ-minus ℕ-minus-identityˡ : ∀ a → ℕ-minus 0 a ≈ -1* a ℕ-minus-identityˡ a = refl ℕ-minus-identityʳ : ∀ a → ℕ-minus a 0 ≈ +1* a ℕ-minus-identityʳ zero = refl , refl ℕ-minus-identityʳ (suc a) = refl ⟦plus⟧ : ⟦ℤ²⟧ → ⟦ℤ⟧ ⟦plus⟧ (+1* a , +1* b) = +1* (a + b) ⟦plus⟧ (+1* a , -1* b) = a - b ⟦plus⟧ (-1* a , +1* b) = b - a ⟦plus⟧ (-1* a , -1* b) = -1* (a + b) plus : ℤ² → ℤ plus = ⟦plus⟧ // λ where (+1* a , +1* b) (+1* c , +1* d) (p , q) → cong₂ _+_ p q (+1* a , +1* b) (+1* c , -1* d) (p , (q , r)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → ≈-trans (⟨ ℕ.+-identityʳ a ⟩) (≈-sym (ℕ-minus-identityʳ a)) (+1* a , +1* b) (-1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → ≈-sym (ℕ-minus-identityʳ b) (+1* a , +1* b) (-1* c , -1* d) ((p , q) , (r , s)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ ,′ ⟪ s ⟫ of λ where (♥ , ♥ , ♥ , ♥) → refl , refl (+1* a , -1* b) (+1* c , +1* d) (p , (q , r)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → ≈-trans {ℕ-minus a 0} {+1* a} {+1* (a + 0)} (ℕ-minus-identityʳ a) (sym ⟨ ℕ.+-identityʳ a ⟩) (+1* a , -1* b) (+1* c , -1* d) (p , q) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → ≈-refl (+1* a , -1* b) (-1* c , +1* d) ((p , q) , (r , s)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ ,′ ⟪ s ⟫ of λ where (♥ , ♥ , ♥ , ♥) → refl (+1* a , -1* b) (-1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → refl (-1* a , +1* b) (+1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → ℕ-minus-identityʳ b (-1* a , +1* b) (+1* c , -1* d) ((p , q) , (r , s)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ ,′ ⟪ s ⟫ of λ where (♥ , ♥ , ♥ , ♥) → refl (-1* a , +1* b) (-1* c , +1* d) (p , q) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → ≈-refl (-1* a , +1* b) (-1* c , -1* d) (p , (q , r)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → sym ⟨ ℕ.+-identityʳ a ⟩ (-1* a , -1* b) (+1* c , +1* d) ((p , q) , (r , s)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ ,′ ⟪ s ⟫ of λ where (♥ , ♥ , ♥ , ♥) → refl , refl (-1* a , -1* b) (+1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → refl (-1* a , -1* b) (-1* c , +1* d) (p , (q , r)) → case ⟪ p ⟫ ,′ ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥ , ♥) → ⟨ ℕ.+-identityʳ a ⟩ (-1* a , -1* b) (-1* c , -1* d) (p , q) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl ⟦times⟧ : ⟦ℤ²⟧ → ⟦ℤ⟧ ⟦times⟧ (+1* a , +1* b) = +1* (a * b) ⟦times⟧ (+1* a , -1* b) = -1* (a * b) ⟦times⟧ (-1* a , +1* b) = -1* (a * b) ⟦times⟧ (-1* a , -1* b) = +1* (a * b) times : ℤ² → ℤ times = ⟦times⟧ // λ where (+1* a , +1* b) (+1* c , +1* d) (p , q) → cong₂ _*_ p q (+1* a , -1* b) (+1* c , -1* d) (p , q) → cong₂ _*_ p q (-1* a , +1* b) (-1* c , +1* d) (p , q) → cong₂ _*_ p q (-1* a , -1* b) (-1* c , -1* d) (p , q) → cong₂ _*_ p q (+1* a , +1* b) (+1* c , -1* d) (p , q , r) → case ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥) → ⟨ *-zeroʳ a ⟩ , ⟨ *-zeroʳ c ⟩ (+1* a , -1* b) (+1* c , +1* d) (p , (q , r)) → case ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥) → ⟨ *-zeroʳ a ⟩ , ⟨ *-zeroʳ c ⟩ (-1* a , +1* b) (-1* c , -1* d) (p , (q , r)) → case ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥) → ⟨ *-zeroʳ a ⟩ , ⟨ *-zeroʳ c ⟩ (-1* a , -1* b) (-1* c , +1* d) (p , (q , r)) → case ⟪ q ⟫ ,′ ⟪ r ⟫ of λ where (♥ , ♥) → ⟨ *-zeroʳ a ⟩ , ⟨ *-zeroʳ c ⟩ (+1* a , +1* b) (-1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl , refl (+1* a , -1* b) (-1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl , refl (-1* a , +1* b) (+1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl , refl (-1* a , -1* b) (+1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl , refl (+1* a , +1* b) (-1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl (+1* a , -1* b) (-1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl (-1* a , +1* b) (+1* c , -1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl (-1* a , -1* b) (+1* c , +1* d) ((p , q) , r) → case ⟪ p ⟫ ,′ ⟪ q ⟫ of λ where (♥ , ♥) → refl instance ℤ-plus-syntax : plus-syntax-simple ℤ ℤ ℤ ℤ-plus-syntax = λ where ._+_ → /.uncurry ≈-refl ≈-refl plus ℤ-minus-syntax : minus-syntax-simple ℤ ℤ ℤ ℤ-minus-syntax = λ where ._-_ x y → x + negate y ℤ-times-syntax : times-syntax-simple ℤ ℤ ℤ ℤ-times-syntax = λ where ._*_ → /.uncurry ≈-refl ≈-refl times
31.646288
78
0.366358
8b35a27899976da424bc9f8a70980fb0b668359e
11,169
agda
Agda
Cubical/Foundations/Equiv.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:00.000Z
2022-03-05T00:29:00.000Z
Cubical/Foundations/Equiv.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- Theory about equivalences Definitions are in Core/Glue.agda but re-exported by this module - isEquiv is a proposition ([isPropIsEquiv]) - Any isomorphism is an equivalence ([isoToEquiv]) There are more statements about equivalences in Equiv/Properties.agda: - if f is an equivalence then (cong f) is an equivalence - if f is an equivalence then precomposition with f is an equivalence - if f is an equivalence then postcomposition with f is an equivalence -} {-# OPTIONS --safe #-} module Cubical.Foundations.Equiv where open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv.Base public open import Cubical.Data.Sigma.Base private variable ℓ ℓ' ℓ'' : Level A B C D : Type ℓ equivIsEquiv : (e : A ≃ B) → isEquiv (equivFun e) equivIsEquiv e = snd e equivCtr : (e : A ≃ B) (y : B) → fiber (equivFun e) y equivCtr e y = e .snd .equiv-proof y .fst equivCtrPath : (e : A ≃ B) (y : B) → (v : fiber (equivFun e) y) → Path _ (equivCtr e y) v equivCtrPath e y = e .snd .equiv-proof y .snd -- Proof using isPropIsContr. This is slow and the direct proof below is better isPropIsEquiv' : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv' f u0 u1 i) y = isPropIsContr (u0 .equiv-proof y) (u1 .equiv-proof y) i -- Direct proof that computes quite ok (can be optimized further if -- necessary, see: -- https://github.com/mortberg/cubicaltt/blob/pi4s3_dimclosures/examples/brunerie2.ctt#L562 isPropIsEquiv : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv f p q i) y = let p2 = p .equiv-proof y .snd q2 = q .equiv-proof y .snd in p2 (q .equiv-proof y .fst) i , λ w j → hcomp (λ k → λ { (i = i0) → p2 w j ; (i = i1) → q2 w (j ∨ ~ k) ; (j = i0) → p2 (q2 w (~ k)) i ; (j = i1) → w }) (p2 w (i ∨ j)) equivEq : {e f : A ≃ B} → (h : e .fst ≡ f .fst) → e ≡ f equivEq {e = e} {f = f} h = λ i → (h i) , isProp→PathP (λ i → isPropIsEquiv (h i)) (e .snd) (f .snd) i module _ {f : A → B} (equivF : isEquiv f) where funIsEq : A → B funIsEq = f invIsEq : B → A invIsEq y = equivF .equiv-proof y .fst .fst secIsEq : section f invIsEq secIsEq y = equivF .equiv-proof y .fst .snd retIsEq : retract f invIsEq retIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .fst commSqIsEq : ∀ a → Square (secIsEq (f a)) refl (cong f (retIsEq a)) refl commSqIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .snd commPathIsEq : ∀ a → secIsEq (f a) ≡ cong f (retIsEq a) commPathIsEq a i j = hcomp (λ k → λ { (i = i0) → secIsEq (f a) j ; (i = i1) → f (retIsEq a (j ∨ ~ k)) ; (j = i0) → f (retIsEq a (i ∧ ~ k)) ; (j = i1) → f a }) (commSqIsEq a i j) module _ (w : A ≃ B) where invEq : B → A invEq = invIsEq (snd w) retEq : retract (w .fst) invEq retEq = retIsEq (snd w) secEq : section (w .fst) invEq secEq = secIsEq (snd w) open Iso equivToIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → Iso A B fun (equivToIso e) = e .fst inv (equivToIso e) = invEq e rightInv (equivToIso e) = secEq e leftInv (equivToIso e) = retEq e -- TODO: there should be a direct proof of this that doesn't use equivToIso invEquiv : A ≃ B → B ≃ A invEquiv e = isoToEquiv (invIso (equivToIso e)) invEquivIdEquiv : (A : Type ℓ) → invEquiv (idEquiv A) ≡ idEquiv A invEquivIdEquiv _ = equivEq refl compEquiv : A ≃ B → B ≃ C → A ≃ C compEquiv f g .fst = g .fst ∘ f .fst compEquiv {A = A} {C = C} f g .snd .equiv-proof c = contr where contractG = g .snd .equiv-proof c .snd secFiller : (a : A) (p : g .fst (f .fst a) ≡ c) → _ {- square in A -} secFiller a p = compPath-filler (cong (invEq f ∘ fst) (contractG (_ , p))) (retEq f a) contr : isContr (fiber (g .fst ∘ f .fst) c) contr .fst .fst = invEq f (invEq g c) contr .fst .snd = cong (g .fst) (secEq f (invEq g c)) ∙ secEq g c contr .snd (a , p) i .fst = secFiller a p i1 i contr .snd (a , p) i .snd j = hcomp (λ k → λ { (i = i1) → fSquare k ; (j = i0) → g .fst (f .fst (secFiller a p k i)) ; (j = i1) → contractG (_ , p) i .snd k }) (g .fst (secEq f (contractG (_ , p) i .fst) j)) where fSquare : I → C fSquare k = hcomp (λ l → λ { (j = i0) → g .fst (f .fst (retEq f a k)) ; (j = i1) → p (k ∧ l) ; (k = i0) → g .fst (secEq f (f .fst a) j) ; (k = i1) → p (j ∧ l) }) (g .fst (f .snd .equiv-proof (f .fst a) .snd (a , refl) k .snd j)) compEquivIdEquiv : (e : A ≃ B) → compEquiv (idEquiv A) e ≡ e compEquivIdEquiv e = equivEq refl compEquivEquivId : (e : A ≃ B) → compEquiv e (idEquiv B) ≡ e compEquivEquivId e = equivEq refl invEquiv-is-rinv : (e : A ≃ B) → compEquiv e (invEquiv e) ≡ idEquiv A invEquiv-is-rinv e = equivEq (funExt (retEq e)) invEquiv-is-linv : (e : A ≃ B) → compEquiv (invEquiv e) e ≡ idEquiv B invEquiv-is-linv e = equivEq (funExt (secEq e)) compEquiv-assoc : (f : A ≃ B) (g : B ≃ C) (h : C ≃ D) → compEquiv f (compEquiv g h) ≡ compEquiv (compEquiv f g) h compEquiv-assoc f g h = equivEq refl LiftEquiv : A ≃ Lift {i = ℓ} {j = ℓ'} A LiftEquiv .fst a .lower = a LiftEquiv .snd .equiv-proof = strictContrFibers lower Lift≃Lift : (e : A ≃ B) → Lift {j = ℓ'} A ≃ Lift {j = ℓ''} B Lift≃Lift e .fst a .lower = e .fst (a .lower) Lift≃Lift e .snd .equiv-proof b .fst .fst .lower = invEq e (b .lower) Lift≃Lift e .snd .equiv-proof b .fst .snd i .lower = e .snd .equiv-proof (b .lower) .fst .snd i Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .fst .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .fst Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .snd j .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .snd j isContr→Equiv : isContr A → isContr B → A ≃ B isContr→Equiv Actr Bctr = isoToEquiv (isContr→Iso Actr Bctr) propBiimpl→Equiv : (Aprop : isProp A) (Bprop : isProp B) (f : A → B) (g : B → A) → A ≃ B propBiimpl→Equiv Aprop Bprop f g = f , hf where hf : isEquiv f hf .equiv-proof y .fst = (g y , Bprop (f (g y)) y) hf .equiv-proof y .snd h i .fst = Aprop (g y) (h .fst) i hf .equiv-proof y .snd h i .snd = isProp→isSet' Bprop (Bprop (f (g y)) y) (h .snd) (cong f (Aprop (g y) (h .fst))) refl i isEquivPropBiimpl→Equiv : isProp A → isProp B → ((A → B) × (B → A)) ≃ (A ≃ B) isEquivPropBiimpl→Equiv {A = A} {B = B} Aprop Bprop = isoToEquiv isom where isom : Iso (Σ (A → B) (λ _ → B → A)) (A ≃ B) isom .fun (f , g) = propBiimpl→Equiv Aprop Bprop f g isom .inv e = equivFun e , invEq e isom .rightInv e = equivEq refl isom .leftInv _ = refl equivΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ((x : A) → F x ≃ G x) → ((x : A) → F x) ≃ ((x : A) → G x) equivΠCod k .fst f x = k x .fst (f x) equivΠCod k .snd .equiv-proof f .fst .fst x = equivCtr (k x) (f x) .fst equivΠCod k .snd .equiv-proof f .fst .snd i x = equivCtr (k x) (f x) .snd i equivΠCod k .snd .equiv-proof f .snd (g , p) i .fst x = equivCtrPath (k x) (f x) (g x , λ j → p j x) i .fst equivΠCod k .snd .equiv-proof f .snd (g , p) i .snd j x = equivCtrPath (k x) (f x) (g x , λ k → p k x) i .snd j equivImplicitΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ({x : A} → F x ≃ G x) → ({x : A} → F x) ≃ ({x : A} → G x) equivImplicitΠCod k .fst f {x} = k {x} .fst (f {x}) equivImplicitΠCod k .snd .equiv-proof f .fst .fst {x} = equivCtr (k {x}) (f {x}) .fst equivImplicitΠCod k .snd .equiv-proof f .fst .snd i {x} = equivCtr (k {x}) (f {x}) .snd i equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .fst {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ j → p j {x}) i .fst equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .snd j {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ k → p k {x}) i .snd j equiv→Iso : (A ≃ B) → (C ≃ D) → Iso (A → C) (B → D) equiv→Iso h k .Iso.fun f b = equivFun k (f (invEq h b)) equiv→Iso h k .Iso.inv g a = invEq k (g (equivFun h a)) equiv→Iso h k .Iso.rightInv g = funExt λ b → secEq k _ ∙ cong g (secEq h b) equiv→Iso h k .Iso.leftInv f = funExt λ a → retEq k _ ∙ cong f (retEq h a) equiv→ : (A ≃ B) → (C ≃ D) → (A → C) ≃ (B → D) equiv→ h k = isoToEquiv (equiv→Iso h k) equivΠ' : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'} {B : A → Type ℓB} {B' : A' → Type ℓB'} (eA : A ≃ A') (eB : {a : A} {a' : A'} → eA .fst a ≡ a' → B a ≃ B' a') → ((a : A) → B a) ≃ ((a' : A') → B' a') equivΠ' {B' = B'} eA eB = isoToEquiv isom where open Iso isom : Iso _ _ isom .fun f a' = eB (secEq eA a') .fst (f (invEq eA a')) isom .inv f' a = invEq (eB refl) (f' (eA .fst a)) isom .rightInv f' = funExt λ a' → J (λ a'' p → eB p .fst (invEq (eB refl) (f' (p i0))) ≡ f' a'') (secEq (eB refl) (f' (eA .fst (invEq eA a')))) (secEq eA a') isom .leftInv f = funExt λ a → subst (λ p → invEq (eB refl) (eB p .fst (f (invEq eA (eA .fst a)))) ≡ f a) (sym (commPathIsEq (eA .snd) a)) (J (λ a'' p → invEq (eB refl) (eB (cong (eA .fst) p) .fst (f (invEq eA (eA .fst a)))) ≡ f a'') (retEq (eB refl) (f (invEq eA (eA .fst a)))) (retEq eA a)) equivΠ : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'} {B : A → Type ℓB} {B' : A' → Type ℓB'} (eA : A ≃ A') (eB : (a : A) → B a ≃ B' (eA .fst a)) → ((a : A) → B a) ≃ ((a' : A') → B' a') equivΠ {B = B} {B' = B'} eA eB = equivΠ' eA (λ {a = a} p → J (λ a' p → B a ≃ B' a') (eB a) p) equivCompIso : (A ≃ B) → (C ≃ D) → Iso (A ≃ C) (B ≃ D) equivCompIso h k .Iso.fun f = compEquiv (compEquiv (invEquiv h) f) k equivCompIso h k .Iso.inv g = compEquiv (compEquiv h g) (invEquiv k) equivCompIso h k .Iso.rightInv g = equivEq (equiv→Iso h k .Iso.rightInv (equivFun g)) equivCompIso h k .Iso.leftInv f = equivEq (equiv→Iso h k .Iso.leftInv (equivFun f)) equivComp : (A ≃ B) → (C ≃ D) → (A ≃ C) ≃ (B ≃ D) equivComp h k = isoToEquiv (equivCompIso h k) -- Some helpful notation: _≃⟨_⟩_ : (X : Type ℓ) → (X ≃ B) → (B ≃ C) → (X ≃ C) _ ≃⟨ f ⟩ g = compEquiv f g _■ : (X : Type ℓ) → (X ≃ X) _■ = idEquiv infixr 0 _≃⟨_⟩_ infix 1 _■ composesToId→Equiv : (f : A → B) (g : B → A) → f ∘ g ≡ idfun B → isEquiv f → isEquiv g composesToId→Equiv f g id iseqf = isoToIsEquiv (iso g f (λ b → (λ i → equiv-proof iseqf (f b) .snd (g (f b) , cong (λ h → h (f b)) id) (~ i) .fst) ∙∙ cong (λ x → equiv-proof iseqf (f b) .fst .fst) id ∙∙ λ i → equiv-proof iseqf (f b) .snd (b , refl) i .fst) λ a i → id i a) -- equivalence between isEquiv and isEquiv' isEquiv-isEquiv'-Iso : (f : A → B) → Iso (isEquiv f) (isEquiv' f) isEquiv-isEquiv'-Iso f .fun p = p .equiv-proof isEquiv-isEquiv'-Iso f .inv q .equiv-proof = q isEquiv-isEquiv'-Iso f .rightInv q = refl isEquiv-isEquiv'-Iso f .leftInv p i .equiv-proof = p .equiv-proof isEquiv≃isEquiv' : (f : A → B) → isEquiv f ≃ isEquiv' f isEquiv≃isEquiv' f = isoToEquiv (isEquiv-isEquiv'-Iso f)
36.262987
102
0.561017
045a43f0e89183494dec1ee68b67db7ff2aec7fa
41
agda
Agda
Categories/Functor/Monoidal.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Functor/Monoidal.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Functor/Monoidal.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
module Categories.Functor.Monoidal where
20.5
40
0.878049
c7c5288e328ecb1f7caeba9e77b8f227be261f82
10,734
agda
Agda
src/Auto/Core.agda
wenkokke/AutoInAgda
f384b5c236645fcf8ab93179723a7355383a8716
[ "MIT" ]
22
2017-07-18T18:14:09.000Z
2021-03-20T15:04:47.000Z
src/Auto/Core.agda
wenkokke/AutoInAgda
f384b5c236645fcf8ab93179723a7355383a8716
[ "MIT" ]
1
2017-11-03T09:46:19.000Z
2017-11-06T16:49:27.000Z
src/Auto/Core.agda
wenkokke/AutoInAgda
f384b5c236645fcf8ab93179723a7355383a8716
[ "MIT" ]
2
2018-07-10T10:47:30.000Z
2019-07-07T07:37:07.000Z
open import Level using (Level) open import Function using (_∘_; id; flip) open import Data.Fin as Fin using (fromℕ) open import Data.Nat as Nat using (ℕ; suc; zero; pred; _+_; _⊔_) open import Data.Nat.Properties using (≤-decTotalOrder) open import Data.List as List using (List; []; _∷_; [_]; concatMap; _++_; length; map) open import Data.Vec as Vec using (Vec; []; _∷_; _∷ʳ_; reverse; initLast; toList) open import Data.Product as Prod using (∃; _×_; _,_; proj₁; proj₂) open import Data.Maybe as Maybe using (Maybe; just; nothing; maybe) open import Data.Sum as Sum using (_⊎_; inj₁; inj₂) open import Data.Integer as Int using (ℤ; -[1+_]; +_) renaming (_≟_ to _≟-Int_) open import Relation.Nullary using (Dec; yes; no) open import Relation.Nullary.Decidable using (map′) open import Relation.Binary using (module DecTotalOrder) open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym) open import Reflection renaming (Term to AgTerm; _≟_ to _≟-AgTerm_) module Auto.Core where open DecTotalOrder ≤-decTotalOrder using (total) private ∃-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (b Level.⊔ a) ∃-syntax = ∃ syntax ∃-syntax (λ x → B) = ∃[ x ] B -- define error messages that may occur when the `auto` function is -- called. data Message : Set where searchSpaceExhausted : Message unsupportedSyntax : Message -- define our own instance of the error functor based on the either -- monad, and use it to propagate one of several error messages private Error : ∀ {a} (A : Set a) → Set a Error A = Message ⊎ A _⟨$⟩_ : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → Error A → Error B f ⟨$⟩ inj₁ x = inj₁ x f ⟨$⟩ inj₂ y = inj₂ (f y) -- define term names for the term language we'll be using for proof -- search; we use standard Agda names, together with term-variables -- and Agda implications/function types. data TermName : Set₀ where name : (n : Name) → TermName var : (i : ℤ) → TermName impl : TermName tname-injective : ∀ {x y} → TermName.name x ≡ TermName.name y → x ≡ y tname-injective refl = refl tvar-injective : ∀ {i j} → TermName.var i ≡ TermName.var j → i ≡ j tvar-injective refl = refl _≟-TermName_ : (x y : TermName) → Dec (x ≡ y) (name x) ≟-TermName (name y) with x ≟-Name y (name x) ≟-TermName (name .x) | yes refl = yes refl (name x) ≟-TermName (name y) | no x≠y = no (x≠y ∘ tname-injective) (name _) ≟-TermName (var _) = no (λ ()) (name _) ≟-TermName (impl ) = no (λ ()) (var _) ≟-TermName (name _) = no (λ ()) (var i) ≟-TermName (var j) with i ≟-Int j (var i) ≟-TermName (var .i) | yes refl = yes refl (var i) ≟-TermName (var j) | no i≠j = no (i≠j ∘ tvar-injective) (var _) ≟-TermName (impl ) = no (λ ()) (impl ) ≟-TermName (name _) = no (λ ()) (impl ) ≟-TermName (var _) = no (λ ()) (impl ) ≟-TermName (impl ) = yes refl -- define rule names for the proof terms/rules that our proof search will -- return/use; we'll use standard Agda names, together with rule-variables. data RuleName : Set where name : Name → RuleName var : ℕ → RuleName name-injective : ∀ {x y} → RuleName.name x ≡ name y → x ≡ y name-injective refl = refl rvar-injective : ∀ {x y} → RuleName.var x ≡ var y → x ≡ y rvar-injective refl = refl _≟-RuleName_ : (x y : RuleName) → Dec (x ≡ y) name x ≟-RuleName name y = map′ (cong name) name-injective (x ≟-Name y) name x ≟-RuleName var y = no (λ ()) var x ≟-RuleName name y = no (λ ()) var x ≟-RuleName var y = map′ (cong var) rvar-injective (x Nat.≟ y) -- now we can load the definitions from proof search open import ProofSearch RuleName TermName _≟-TermName_ Literal _≟-Lit_ as PS public renaming (Term to PsTerm; module Extensible to PsExtensible) -- next up, converting the terms returned by Agda's reflection -- mechanism to terms in our proof search's language! -- dictionary for the treatment of variables in conversion from Agda -- terms to terms to be used in proof search. ConvertVar : Set ConvertVar = (depth index : ℕ) → ∃ PsTerm -- conversion dictionary for rule-terms, which turns every variable -- that is within the scope of the term (i.e. is defined within the -- term by lambda abstraction) into a variable, and every variable -- which is defined out of scope into a Skolem constant (which -- blocks unification). convertVar4Term : ConvertVar convertVar4Term = fromVar where fromVar : (depth index : ℕ) → ∃ PsTerm fromVar d i with total i d fromVar d i | inj₁ i≤d = (suc (Δ i≤d) , var (fromℕ (Δ i≤d))) fromVar d i | inj₂ i>d = (0 , con (var (-[1+ Δ i>d ])) []) -- conversion dictionary for goal-terms, which turns all variables -- into Skolem constants which blocks all unification. convertVar4Goal : ConvertVar convertVar4Goal = fromVar where fromVar : (depth index : ℕ) → ∃ PsTerm fromVar d i with total i d fromVar d i | inj₁ i≤d = (0 , con (var (+ Δ i≤d)) []) fromVar d i | inj₂ i>d = (0 , con (var (-[1+ Δ i>d ])) []) -- helper function for converting definitions or constructors to -- proof terms. fromDefOrCon : (s : Name) → ∃[ n ] List (PsTerm n) → ∃ PsTerm fromDefOrCon f (n , ts) = n , con (name f) ts -- specialised function to convert literals of natural numbers -- (since they have a representation using Agda names) convertℕ : ∀ {k} → ℕ → PsTerm k convertℕ zero = con (name (quote zero)) [] convertℕ (suc n) = con (name (quote suc)) (convertℕ n ∷ []) -- convert an Agda term to a term, abstracting over the treatment of -- variables with an explicit dictionary of the type `ConvertVar`--- -- passing in `ConvertVar4Term` or `ConvertVar4Goal` will result in -- rule-terms or goal-terms, respectively. convert : ConvertVar → (depth : ℕ) → AgTerm → Error (∃ PsTerm) convertChildren : ConvertVar → ℕ → List (Arg AgTerm) → Error (∃[ n ] List (PsTerm n)) convert cv d (lit (nat n)) = inj₂ (0 , convertℕ n) convert cv d (lit l) = inj₂ (0 , lit l) convert cv d (var i []) = inj₂ (cv d i) convert cv d (var i args) = inj₁ unsupportedSyntax convert cv d (con c args) = fromDefOrCon c ⟨$⟩ convertChildren cv d args convert cv d (def f args) = fromDefOrCon f ⟨$⟩ convertChildren cv d args convert cv d (pi (arg (arg-info visible _) t₁) (abs _ t₂)) with convert cv d t₁ | convert cv (suc d) t₂ ... | inj₁ msg | _ = inj₁ msg ... | _ | inj₁ msg = inj₁ msg ... | inj₂ (n₁ , p₁) | inj₂ (n₂ , p₂) with match p₁ p₂ ... | (p₁′ , p₂′) = inj₂ (n₁ ⊔ n₂ , con impl (p₁′ ∷ p₂′ ∷ [])) convert cv d (pi (arg _ _) (abs _ t₂)) = convert cv (suc d) t₂ convert cv d (lam _ _) = inj₁ unsupportedSyntax convert cv d (pat-lam _ _) = inj₁ unsupportedSyntax convert cv d (sort _) = inj₁ unsupportedSyntax convert cv d unknown = inj₁ unsupportedSyntax convert cv d (meta x args) = inj₁ unsupportedSyntax convertChildren cv d [] = inj₂ (0 , []) convertChildren cv d (arg (arg-info visible _) t ∷ ts) with convert cv d t | convertChildren cv d ts ... | inj₁ msg | _ = inj₁ msg ... | _ | inj₁ msg = inj₁ msg ... | inj₂ (m , p) | inj₂ (n , ps) with match p ps ... | (p′ , ps′) = inj₂ (m ⊔ n , p′ ∷ ps′) convertChildren cv d (arg _ _ ∷ ts) = convertChildren cv d ts -- convert an Agda term to a rule-term. agda2term : AgTerm → Error (∃ PsTerm) agda2term t = convert convertVar4Term 0 t -- split a term at every occurrence of the `impl` constructor--- -- equivalent to splitting at every occurrence of the _→_ symbol in -- an Agda term. split : ∀ {n} → PsTerm n → ∃[ k ] Vec (PsTerm n) (suc k) split (con impl (t₁ ∷ t₂ ∷ [])) = Prod.map suc (λ ts → t₁ ∷ ts) (split t₂) split t = zero , t ∷ [] -- convert an Agda term to a goal-term, together with a `HintDB` -- representing the premises of the rule---this means that for a -- term of the type `A → B` this function will generate a goal of -- type `B` and a premise of type `A`. agda2goal×premises : AgTerm → Error (∃ PsTerm × Rules) agda2goal×premises t with convert convertVar4Goal 0 t ... | inj₁ msg = inj₁ msg ... | inj₂ (n , p) with split p ... | (k , ts) with initLast ts ... | (prems , goal , _) = inj₂ ((n , goal) , toPremises (pred k) prems) where toPremises : ∀ {k} → ℕ → Vec (PsTerm n) k → Rules toPremises i [] = [] toPremises i (t ∷ ts) = (n , rule (var i) t []) ∷ toPremises (pred i) ts -- convert an Agda name to an rule-term. name2term : Name → TC (Error (∃ PsTerm)) name2term nm = bindTC (getType nm) (λ tp → returnTC (agda2term tp)) -- convert an Agda name to a rule. name2ruleHelper : Name → (Error (∃ PsTerm)) → TC (Error (∃ Rule)) name2ruleHelper nm name2term_nm with name2term_nm ... | inj₁ msg = returnTC (inj₁ msg) ... | inj₂ (n , t) with split t ... | (k , ts) with initLast ts ... | (prems , concl , _) = returnTC (inj₂ (n , rule (name nm) concl (toList prems))) -- convert an Agda name to a rule. name2rule : Name → TC (Error (∃ Rule)) name2rule nm = bindTC (name2term nm) (name2ruleHelper nm) -- function which reifies untyped proof terms (from the -- `ProofSearch` module) to untyped Agda terms. reify : Proof → TC AgTerm reifyChildren : List Proof → TC (List (Arg AgTerm)) reify (con (var i) ps) = returnTC ((var i [])) reify (con (name n) ps) = bindTC (getDefinition n) (λ { (function x) → bindTC (reifyChildren ps) (λ rc → returnTC (def n rc)) ; (data-type pars cs) → bindTC (reifyChildren ps) ((λ rc → returnTC (con n rc))) ; (record′ c _) → returnTC unknown ; (constructor′ d ) → returnTC unknown ; axiom → returnTC unknown ; primitive′ → returnTC unknown} ) reifyChildren [] = returnTC [] reifyChildren (p ∷ ps) = bindTC (reify p) (λ rp → bindTC (reifyChildren ps) (λ rcps → returnTC (toArg rp ∷ rcps))) where toArg : AgTerm → Arg AgTerm toArg = arg (arg-info visible relevant) -- data-type `Exception` which is used to unquote error messages to -- the type-level so that `auto` can generate descriptive type-errors. data Exception : Message → Set where throw : (msg : Message) → Exception msg quoteError : Message → AgTerm quoteError (searchSpaceExhausted) = quoteTerm (throw searchSpaceExhausted) quoteError (unsupportedSyntax) = quoteTerm (throw unsupportedSyntax)
39.318681
105
0.616732
037a20bed0c14b2746ab07dfcc570458fa4a0fa7
4,745
agda
Agda
Cubical/Displayed/Properties.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Displayed/Properties.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Displayed/Properties.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Displayed.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence using (pathToEquiv; univalence; ua-ungluePath-Equiv) open import Cubical.Data.Unit open import Cubical.Data.Sigma open import Cubical.Relation.Binary open BinaryRelation open import Cubical.Displayed.Base private variable ℓ ℓA ℓA' ℓP ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓ≅B' ℓC ℓ≅C : Level -- induction principles module _ {A : Type ℓA} {ℓ≅A : Level} (𝒮-A : UARel A ℓ≅A) where open UARel 𝒮-A 𝒮-J : {a : A} (P : (a' : A) → (p : a ≡ a') → Type ℓ) (d : P a refl) {a' : A} (p : a ≅ a') → P a' (≅→≡ p) 𝒮-J {a} P d {a'} p = J (λ y q → P y q) d (≅→≡ p) 𝒮-J-2 : {a : A} (P : (a' : A) → (p : a ≅ a') → Type ℓ) (d : P a (ρ a)) {a' : A} (p : a ≅ a') → P a' p 𝒮-J-2 {a = a} P d {a'} p = subst (λ r → P a' r) (Iso.leftInv (uaIso a a') p) g where g : P a' (≡→≅ (≅→≡ p)) g = J (λ y q → P y (≡→≅ q)) d (≅→≡ p) -- constructors module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} (_≅ᴰ⟨_⟩_ : {a a' : A} → B a → UARel._≅_ 𝒮-A a a' → B a' → Type ℓ≅B) where open UARel 𝒮-A -- constructor that reduces ua to the case where p = ρ a by induction on p private 𝒮ᴰ-make-aux : (uni : {a : A} (b b' : B a) → b ≅ᴰ⟨ ρ a ⟩ b' ≃ (b ≡ b')) → ({a a' : A} (b : B a) (p : a ≅ a') (b' : B a') → (b ≅ᴰ⟨ p ⟩ b') ≃ PathP (λ i → B (≅→≡ p i)) b b') 𝒮ᴰ-make-aux uni {a} {a'} b p = 𝒮-J-2 𝒮-A (λ y q → (b' : B y) → (b ≅ᴰ⟨ q ⟩ b') ≃ PathP (λ i → B (≅→≡ q i)) b b') (λ b' → uni' b') p where g : (b' : B a) → (b ≡ b') ≡ PathP (λ i → B (≅→≡ (ρ a) i)) b b' g b' = subst (λ r → (b ≡ b') ≡ PathP (λ i → B (r i)) b b') (sym (Iso.rightInv (uaIso a a) refl)) refl uni' : (b' : B a) → b ≅ᴰ⟨ ρ a ⟩ b' ≃ PathP (λ i → B (≅→≡ (ρ a) i)) b b' uni' b' = compEquiv (uni b b') (pathToEquiv (g b')) 𝒮ᴰ-make-1 : (uni : {a : A} (b b' : B a) → b ≅ᴰ⟨ ρ a ⟩ b' ≃ (b ≡ b')) → DUARel 𝒮-A B ℓ≅B DUARel._≅ᴰ⟨_⟩_ (𝒮ᴰ-make-1 uni) = _≅ᴰ⟨_⟩_ DUARel.uaᴰ (𝒮ᴰ-make-1 uni) = 𝒮ᴰ-make-aux uni -- constructor that reduces univalence further to contractibility of relational singletons 𝒮ᴰ-make-2 : (ρᴰ : {a : A} → isRefl _≅ᴰ⟨ ρ a ⟩_) (contrTotal : (a : A) → contrRelSingl _≅ᴰ⟨ UARel.ρ 𝒮-A a ⟩_) → DUARel 𝒮-A B ℓ≅B DUARel._≅ᴰ⟨_⟩_ (𝒮ᴰ-make-2 ρᴰ contrTotal) = _≅ᴰ⟨_⟩_ DUARel.uaᴰ (𝒮ᴰ-make-2 ρᴰ contrTotal) = 𝒮ᴰ-make-aux (contrRelSingl→isUnivalent _ ρᴰ (contrTotal _)) -- relational isomorphisms 𝒮-iso→iso : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : Type ℓB} (𝒮-B : UARel B ℓ≅B) (F : RelIso (UARel._≅_ 𝒮-A) (UARel._≅_ 𝒮-B)) → Iso A B 𝒮-iso→iso 𝒮-A 𝒮-B F = RelIso→Iso (UARel._≅_ 𝒮-A) (UARel._≅_ 𝒮-B) (UARel.≅→≡ 𝒮-A) (UARel.≅→≡ 𝒮-B) F -- fiberwise relational isomorphisms module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {A' : Type ℓA'} {𝒮-A' : UARel A' ℓ≅A'} (F : Iso A A') {B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) {B' : A' → Type ℓB'} (𝒮ᴰ-B' : DUARel 𝒮-A' B' ℓ≅B') where open UARel 𝒮-A open DUARel 𝒮ᴰ-B renaming (_≅ᴰ⟨_⟩_ to _≅B⟨_⟩_ ; uaᴰ to uaB ; fiberRel to fiberRelB ; uaᴰρ to uaᴰρB) open DUARel 𝒮ᴰ-B' renaming (_≅ᴰ⟨_⟩_ to _≅B'⟨_⟩_ ; uaᴰ to uaB' ; fiberRel to fiberRelB' ; uaᴰρ to uaᴰρB') private f = Iso.fun F -- the following can of course be done slightly more generally -- for fiberwise binary relations F*fiberRelB' : (a : A) → Rel (B' (f a)) (B' (f a)) ℓ≅B' F*fiberRelB' a = fiberRelB' (f a) module _ (G : (a : A) → RelIso (fiberRelB a) (F*fiberRelB' a)) where private fiberIsoOver : (a : A) → Iso (B a) (B' (f a)) fiberIsoOver a = RelIso→Iso (fiberRelB a) (F*fiberRelB' a) (equivFun (uaᴰρB _ _)) (equivFun (uaᴰρB' _ _)) (G a) -- DUARelFiberIsoOver→TotalIso produces an isomorphism of total spaces -- from a relational isomorphism between B a and (F * B) a 𝒮ᴰ-fiberIsoOver→totalIso : Iso (Σ A B) (Σ A' B') 𝒮ᴰ-fiberIsoOver→totalIso = Σ-cong-iso F fiberIsoOver
32.951389
119
0.474605
1e1d60e8f2af70b0b80f70ae0909908f74476641
589
agda
Agda
ExPathInduction.agda
guillaumebrunerie/JamesConstruction
89fbc29473d2d1ed1a45c3c0e56288cdcf77050b
[ "MIT" ]
5
2016-12-07T04:34:52.000Z
2018-11-16T22:10:16.000Z
ExPathInduction.agda
guillaumebrunerie/JamesConstruction
89fbc29473d2d1ed1a45c3c0e56288cdcf77050b
[ "MIT" ]
null
null
null
ExPathInduction.agda
guillaumebrunerie/JamesConstruction
89fbc29473d2d1ed1a45c3c0e56288cdcf77050b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} open import PathInduction using (Type; _==_; idp; Square; !; _∙_; Coh; path-induction) module ExPathInduction {i} where {-<excoh>-} coh : {A : Type i} {a : A} → Coh ({b : A} (p : a == b) {d : A} {s : d == b} {c : A} {r : b == c} {f : A} {u : f == c} {e : A} {t : e == c} {w : f == e} (ν : Square w idp t u) {v : d == e} (α : Square v s t r) {vw : d == f} (vw= : vw == v ∙ ! w) → Square (p ∙ ! s) p vw (r ∙ ! u)) coh = path-induction {-</>-}
29.45
86
0.382003
19393d2c5efe3ed53309d6a23a277252eff11cd9
3,849
agda
Agda
Cubical/ZCohomology/KcompPrelims.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
Cubical/ZCohomology/KcompPrelims.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
Cubical/ZCohomology/KcompPrelims.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.ZCohomology.KcompPrelims where open import Cubical.ZCohomology.Base open import Cubical.Homotopy.Connected open import Cubical.HITs.Hopf open import Cubical.Homotopy.Freudenthal hiding (encode) open import Cubical.HITs.Sn open import Cubical.HITs.S1 open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; map to trMap) open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Data.Int renaming (_+_ to +Int) open import Cubical.Data.Nat hiding (_·_) open import Cubical.Data.Unit open import Cubical.HITs.Susp open import Cubical.HITs.Nullification open import Cubical.Data.Prod.Base open import Cubical.Homotopy.Loopspace open import Cubical.Data.Bool open import Cubical.Data.Sum.Base open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Foundations.Function open import Cubical.Foundations.Pointed open import Cubical.HITs.S3 private variable ℓ : Level A : Type ℓ {- We want to prove that Kn≃ΩKn+1. For this we use the map ϕ-} ϕ : (pt a : A) → typ (Ω (Susp A , north)) ϕ pt a = (merid a) ∙ sym (merid pt) private Kn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n))) Kn→ΩKn+1 zero x i = ∣ intLoop x i ∣ Kn→ΩKn+1 (suc zero) = trRec (isOfHLevelTrunc 4 ∣ north ∣ ∣ north ∣) λ a i → ∣ ϕ base a i ∣ Kn→ΩKn+1 (suc (suc n)) = trRec (isOfHLevelTrunc (2 + (3 + n)) ∣ north ∣ ∣ north ∣) λ a i → ∣ ϕ north a i ∣ d-map : typ (Ω ((Susp S¹) , north)) → S¹ d-map p = subst HopfSuspS¹ p base d-mapId : (r : S¹) → d-map (ϕ base r) ≡ r d-mapId r = substComposite HopfSuspS¹ (merid r) (sym (merid base)) base ∙ rotLemma r where rotLemma : (r : S¹) → r · base ≡ r rotLemma base = refl rotLemma (loop i) = refl sphereConnectedSpecCase : isConnected 4 (Susp (Susp S¹)) sphereConnectedSpecCase = sphereConnected 3 d-mapComp : Iso (fiber d-map base) (Path (S₊ 3) north north) d-mapComp = compIso (IsoΣPathTransportPathΣ {B = HopfSuspS¹} _ _) (congIso (invIso IsoS³TotalHopf)) is1Connected-dmap : isConnectedFun 3 d-map is1Connected-dmap = toPropElim (λ _ → isPropIsOfHLevel 0) (isConnectedRetractFromIso 3 d-mapComp (isOfHLevelRetractFromIso 0 (invIso (PathIdTruncIso 3)) contrHelper)) where contrHelper : isContr (Path (∥ Susp (Susp S¹) ∥ 4) ∣ north ∣ ∣ north ∣) fst contrHelper = refl snd contrHelper = isOfHLevelPlus {n = 0} 2 (sphereConnected 3) ∣ north ∣ ∣ north ∣ refl d-Iso : Iso (∥ Path (S₊ 2) north north ∥ 3) (coHomK 1) d-Iso = connectedTruncIso _ d-map is1Connected-dmap d-mapId2 : Iso.fun d-Iso ∘ trMap (ϕ base) ≡ idfun (coHomK 1) d-mapId2 = funExt (trElim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) λ a i → ∣ d-mapId a i ∣) Iso∥ϕ₁∥ : Iso (coHomK 1) (∥ Path (S₊ 2) north north ∥ 3) Iso∥ϕ₁∥ = composesToId→Iso d-Iso (trMap (ϕ base)) d-mapId2 Iso-Kn-ΩKn+1 : (n : HLevel) → Iso (coHomK n) (typ (Ω (coHomK-ptd (suc n)))) Iso-Kn-ΩKn+1 zero = invIso (compIso (congIso (truncIdempotentIso _ isGroupoidS¹)) ΩS¹IsoInt) Iso-Kn-ΩKn+1 (suc zero) = compIso Iso∥ϕ₁∥ (invIso (PathIdTruncIso 3)) Iso-Kn-ΩKn+1 (suc (suc n)) = compIso (stabSpheres-n≥2 n) (invIso (PathIdTruncIso (4 + n))) where helper : n + (4 + n) ≡ 2 + (n + (2 + n)) helper = +-suc n (3 + n) ∙ (λ i → suc (+-suc n (2 + n) i))
38.49
99
0.660951
8bf8897455e67ecd2e636e9fa2a85e2274f830bb
508
agda
Agda
Data/Fin/Indexed/Literals.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Fin/Indexed/Literals.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Fin/Indexed/Literals.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.Fin.Indexed.Literals where -- import Data.Nat as ℕ -- import Data.Nat.Properties as ℕ open import Data.Fin.Indexed.Base open import Literals.Number -- open import Relation.Nullary open import Agda.Builtin.Nat renaming (_<_ to _<ᵇ_) open import Data.Bool open import Agda.Builtin.Nat using (_<_) instance numberFin : ∀ {n} → Number (Fin n) numberFin {n} = record { Constraint = λ m → T (m <ᵇ n) ; fromNat = λ m {{pr}} → FinFromℕ {n} m pr }
25.4
51
0.673228
1a746bd12b5fa645db3f6bf9770d2510e65a7105
4,601
agda
Agda
src/Similarity/Weak.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
src/Similarity/Weak.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
src/Similarity/Weak.agda
nad/up-to
b936ff85411baf3401ad85ce85d5ff2e9aa0ca14
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A coinductive definition of weak similarity ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Labelled-transition-system module Similarity.Weak {ℓ} (lts : LTS ℓ) where open import Equality.Propositional open import Prelude open import Prelude.Size open import Bisimilarity.Weak lts as WB using ([_]_≈_; [_]_≈′_) open import Expansion lts as E using ([_]_≳_; [_]_≳′_) open import Indexed-container hiding (⟨_⟩) open import Relation open import Similarity lts as S using ([_]_≤_; [_]_≤′_) import Similarity.General open LTS lts private module General = Similarity.General lts _[_]⇒̂_ ⟶→⇒̂ open General public using (module StepC; ⟨_⟩; challenge; force; [_]_≡_; [_]_≡′_; []≡↔; Extensionality; extensionality) renaming ( reflexive-≤ to reflexive-≼ ; reflexive-≤′ to reflexive-≼′ ; ≡⇒≤ to ≡⇒≼ ; ≤:_ to ≼:_ ; ≤′:_ to ≼′:_ ) -- StepC is given in the following way, rather than via open public, -- to make hyperlinks to it more informative. StepC : Container (Proc × Proc) (Proc × Proc) StepC = General.StepC -- The following definitions are given explicitly, in order to make -- the code easier to follow. Weak-similarity : Size → Rel₂ ℓ Proc Weak-similarity = ν StepC Weak-similarity′ : Size → Rel₂ ℓ Proc Weak-similarity′ = ν′ StepC infix 4 [_]_≼_ [_]_≼′_ _≼_ _≼′_ [_]_≼_ : Size → Proc → Proc → Type ℓ [ i ] p ≼ q = ν StepC i (p , q) [_]_≼′_ : Size → Proc → Proc → Type ℓ [ i ] p ≼′ q = ν′ StepC i (p , q) _≼_ : Proc → Proc → Type ℓ _≼_ = [ ∞ ]_≼_ _≼′_ : Proc → Proc → Type ℓ _≼′_ = [ ∞ ]_≼′_ private -- However, these definitions are definitionally equivalent to -- corresponding definitions in General. indirect-Weak-similarity : Weak-similarity ≡ General.Similarity indirect-Weak-similarity = refl indirect-Weak-similarity′ : Weak-similarity′ ≡ General.Similarity′ indirect-Weak-similarity′ = refl indirect-[]≼ : [_]_≼_ ≡ General.[_]_≤_ indirect-[]≼ = refl indirect-[]≼′ : [_]_≼′_ ≡ General.[_]_≤′_ indirect-[]≼′ = refl indirect-≼ : _≼_ ≡ General._≤_ indirect-≼ = refl indirect-≼′ : _≼′_ ≡ General._≤′_ indirect-≼′ = refl mutual -- Weak bisimilarity is contained in weak similarity. ≈⇒≼ : ∀ {i p q} → [ i ] p ≈ q → [ i ] p ≼ q ≈⇒≼ = λ p≈q → ⟨ (λ q⟶q′ → let p′ , p⇒̂p′ , p′≈′q′ = WB.left-to-right p≈q q⟶q′ in p′ , p⇒̂p′ , ≈⇒≼′ p′≈′q′) ⟩ ≈⇒≼′ : ∀ {i p q} → [ i ] p ≈′ q → [ i ] p ≼′ q force (≈⇒≼′ p≳′q) = ≈⇒≼ (S.force p≳′q) mutual -- Similarity is contained in weak similarity. ≤⇒≼ : ∀ {i p q} → [ i ] p ≤ q → [ i ] p ≼ q ≤⇒≼ = λ p≤q → ⟨ (λ q⟶q′ → let p′ , p⟶p′ , p′≤′q′ = S.challenge p≤q q⟶q′ in p′ , ⟶→⇒̂ p⟶p′ , ≤⇒≼′ p′≤′q′) ⟩ ≤⇒≼′ : ∀ {i p q} → [ i ] p ≤′ q → [ i ] p ≼′ q force (≤⇒≼′ p≳′q) = ≤⇒≼ (S.force p≳′q) -- Weak similarity is a weak simulation (of a certain kind). weak-is-weak⇒̂ : ∀ {p p′ q μ} → p ≼ q → p [ μ ]⇒̂ p′ → ∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ≼ q′ weak-is-weak⇒̂ = is-weak⇒̂ challenge (λ p≼′q → force p≼′q) ⇒̂→⇒ id mutual -- Weak similarity is transitive. -- -- Note that the size of the second argument is not preserved. -- -- TODO: Can one prove that the size cannot be preserved? transitive-≼ : ∀ {i p q r} → [ i ] p ≼ q → q ≼ r → [ i ] p ≼ r transitive-≼ p≼q q≼r = ⟨ (λ p⟶p′ → let q′ , q⇒̂q′ , p′≼q′ = challenge p≼q p⟶p′ r′ , r⇒̂r′ , q′≼r′ = weak-is-weak⇒̂ q≼r q⇒̂q′ in r′ , r⇒̂r′ , transitive-≼′ p′≼q′ q′≼r′) ⟩ transitive-≼′ : ∀ {i p q r} → [ i ] p ≼′ q → q ≼ r → [ i ] p ≼′ r force (transitive-≼′ p≼q q≼r) = transitive-≼ (force p≼q) q≼r mutual -- A fully size-preserving transitivity-like lemma. -- -- Note that expansion could be replaced by a kind of one-sided -- expansion. transitive-≳≼ : ∀ {i p q r} → [ i ] p ≳ q → [ i ] q ≼ r → [ i ] p ≼ r transitive-≳≼ p≳q q≼r = ⟨ (λ p⟶p′ → case E.left-to-right p≳q p⟶p′ of λ where (_ , done s , p′≳q) → _ , silent s done , transitive-≳≼′ p′≳q (record { force = λ { {_} → q≼r } }) (q′ , step q⟶q′ , p′≳q′) → let r′ , r⇒̂r′ , q′≼r′ = challenge q≼r q⟶q′ in r′ , r⇒̂r′ , transitive-≳≼′ p′≳q′ q′≼r′) ⟩ transitive-≳≼′ : ∀ {i p q r} → [ i ] p ≳′ q → [ i ] q ≼′ r → [ i ] p ≼′ r force (transitive-≳≼′ p≼q q≼r) = transitive-≳≼ (force p≼q) (force q≼r)
27.224852
72
0.506194
38824577a5afd371153d283b10f894c5d8f383bc
2,897
agda
Agda
src/Semantics/Bind.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
4
2018-05-31T20:37:04.000Z
2022-01-04T09:33:48.000Z
src/Semantics/Bind.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
null
null
null
src/Semantics/Bind.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
null
null
null
{-# OPTIONS --allow-unsolved-metas #-} module Semantics.Bind where open import Syntax.Types open import Syntax.Context renaming (_,_ to _,,_) open import Syntax.Terms open import Syntax.Substitution.Kits open import Syntax.Substitution.Instances open import Syntax.Substitution.Lemmas open import Semantics.Types open import Semantics.Terms open import Semantics.Context open import Semantics.Substitution.Kits open import Semantics.Substitution.Traversal open import Semantics.Substitution.Instances open import CategoryTheory.Categories using (Category ; ext) open import CategoryTheory.Functor open import CategoryTheory.NatTrans open import CategoryTheory.Monad open import CategoryTheory.Comonad open import CategoryTheory.CartesianStrength open import CategoryTheory.Instances.Reactive renaming (top to ⊤) open import TemporalOps.Diamond open import TemporalOps.Delay open import TemporalOps.Box open import TemporalOps.OtherOps open import TemporalOps.StrongMonad open import Data.Sum open import Data.Product using (_,_) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; refl ; sym ; trans ; cong ; cong₂ ; subst) open ≡.≡-Reasoning open import Holes.Term using (⌞_⌟) open import Holes.Cong.Propositional open Comonad W-□ open Monad M-◇ private module F-◇ = Functor F-◇ private module F-□ = Functor F-□ open Functor F-□ renaming (fmap to □-f) open Functor F-◇ renaming (fmap to ◇-f) private module ▹ᵏ-C k = CartesianFunctor (F-cart-delay k) private module ▹ᵏ-F k = Functor (F-delay k) private module □-▹ᵏ k = _⟹_ (□-to-▹ᵏ k) bind-to->>= : ∀ Γ {⟦A⟧ ⟦B⟧} -> (⟦E⟧ : ⟦ Γ ⟧ₓ ⇴ ◇ ⟦A⟧) (⟦C⟧ : ⟦ Γ ˢ ⟧ₓ ⊗ ⟦A⟧ ⇴ ◇ ⟦B⟧) -> (n : ℕ) (⟦Γ⟧ : ⟦ Γ ⟧ₓ n) -> bindEvent Γ ⟦E⟧ ⟦C⟧ n ⟦Γ⟧ ≡ (⟦E⟧ n ⟦Γ⟧ >>= λ l ⟦A⟧ → ⟦C⟧ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) bind-to->>= Γ {⟦A⟧} {⟦B⟧} ⟦E⟧ ⟦C⟧ n ⟦Γ⟧ = begin bindEvent Γ ⟦E⟧ ⟦C⟧ n ⟦Γ⟧ ≡⟨⟩ μ.at ⟦B⟧ n (F-◇.fmap (⟦C⟧ ∘ ε.at ⟦ Γ ˢ ⟧ₓ * id) n (st ⟦ Γ ˢ ⟧ₓ ⟦A⟧ n (⟦ Γ ˢ⟧□ n ⟦Γ⟧ , ⟦E⟧ n ⟦Γ⟧))) ≡⟨ cong (μ.at ⟦B⟧ n) (lemma (⟦E⟧ n ⟦Γ⟧)) ⟩ μ.at ⟦B⟧ n (F-◇.fmap (⟦C⟧ ∘ ⟨ (λ l _ → ⟦ Γ ˢ⟧□ n ⟦Γ⟧ l) , id ⟩) n (⟦E⟧ n ⟦Γ⟧)) ≡⟨⟩ (⟦E⟧ n ⟦Γ⟧ >>= (λ l ⟦A⟧ → ⟦C⟧ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧))) ∎ where lemma : ∀ ◇⟦A⟧ -> F-◇.fmap (⟦C⟧ ∘ ε.at ⟦ Γ ˢ ⟧ₓ * id) n (st ⟦ Γ ˢ ⟧ₓ ⟦A⟧ n (⟦ Γ ˢ⟧□ n ⟦Γ⟧ , ◇⟦A⟧)) ≡ F-◇.fmap (⟦C⟧ ∘ ⟨ (λ l _ → ⟦ Γ ˢ⟧□ n ⟦Γ⟧ l) , id ⟩) n ◇⟦A⟧ lemma (k , a) = begin F-◇.fmap (⟦C⟧ ∘ ε.at ⟦ Γ ˢ ⟧ₓ * id) n (st ⟦ Γ ˢ ⟧ₓ ⟦A⟧ n (⟦ Γ ˢ⟧□ n ⟦Γ⟧ , (k , a))) ≡⟨⟩ k , ▹ᵏ-F.fmap k (⟦C⟧ ∘ ε.at ⟦ Γ ˢ ⟧ₓ * id) n (▹ᵏ-C.m k (□ ⟦ Γ ˢ ⟧ₓ) ⟦A⟧ n (□-▹ᵏ.at k (□ ⟦ Γ ˢ ⟧ₓ) n (δ.at ⟦ Γ ˢ ⟧ₓ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧)) , a)) ≡⟨ {! !} ⟩ k , ▹ᵏ-F.fmap k (⟦C⟧ ∘ ⟨ (λ l _ → ⟦ Γ ˢ⟧□ n ⟦Γ⟧ l) , id ⟩) n a ≡⟨⟩ F-◇.fmap (⟦C⟧ ∘ ⟨ (λ l _ → ⟦ Γ ˢ⟧□ n ⟦Γ⟧ l) , id ⟩) n (k , a) ∎
36.2125
110
0.550224
032d4de150f454c79483c1ccc5d9d3941476805c
3,115
agda
Agda
notes/FOT/Common/FOL/Existential/Elimination.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/Common/FOL/Existential/Elimination.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/Common/FOL/Existential/Elimination.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
----------------------------------------------------------------------------- -- Existential elimination ----------------------------------------------------------------------------- {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.Common.FOL.Existential.Elimination where ----------------------------------------------------------------------------- postulate D : Set module ∃₁ where -- Type theoretical version -- We add 3 to the fixities of the Agda standard library 0.8.1 (see -- Data/Product.agda). infixr 7 _,_ -- The existential quantifier type on D. data ∃ (A : D → Set) : Set where _,_ : (x : D) → A x → ∃ A -- Sugar syntax for the existential quantifier. syntax ∃ (λ x → e) = ∃[ x ] e -- The existential proyections. ∃-proj₁ : ∀ {A} → ∃ A → D ∃-proj₁ (x , _) = x ∃-proj₂ : ∀ {A} → (h : ∃ A) → A (∃-proj₁ h) ∃-proj₂ (_ , Ax) = Ax -- Some examples -- The order of quantifiers of the same sort is irrelevant. ∃-ord : {A² : D → D → Set} → (∃[ x ] ∃[ y ] A² x y) → (∃[ y ] ∃[ x ] A² x y) ∃-ord (x , y , h) = y , x , h ----------------------------------------------------------------------------- module ∃₂ where -- First-order logic version -- We add 3 to the fixities of the Agda standard library 0.8.1 (see -- Data/Product.agda). infixr 7 _,_ -- The existential quantifier type on D. data ∃ (A : D → Set) : Set where _,_ : (x : D) → A x → ∃ A -- Sugar syntax for the existential quantifier. syntax ∃ (λ x → e) = ∃[ x ] e -- Existential elimination -- ∃x.A(x) A(x) → B -- ------------------------ -- B -- NB. We do not use the usual type theory elimination with two -- projections because we are working in first-order logic where we -- do need extract a witness from an existence proof. ∃-elim : {A : D → Set}{B : Set} → ∃ A → ((x : D) → A x → B) → B ∃-elim (x , Ax) h = h x Ax -- Some examples -- The order of quantifiers of the same sort is irrelevant. ∃-ord : {A² : D → D → Set} → (∃[ x ] ∃[ y ] A² x y) → (∃[ y ] ∃[ x ] A² x y) ∃-ord h = ∃-elim h (λ x h₁ → ∃-elim h₁ (λ y prf → y , x , prf)) -- A proof non-FOL valid non-FOL : {A : D → Set} → ∃ A → D non-FOL h = ∃-elim h (λ x _ → x) ----------------------------------------------------------------------------- module ∃₃ where -- First-order logic version -- A different version from the existential introduction -- A(x) -- ------------ -- ∃x.A(x) -- The existential quantifier type on D. data ∃ (A : D → Set) : Set where ∃-intro : ((x : D) → A x) → ∃ A -- Sugar syntax for the existential quantifier. syntax ∃ (λ x → e) = ∃[ x ] e postulate d : D -- Existential elimination. -- NB. It is neccesary that D ≢ ∅. ∃-elim : {A : D → Set}{B : Set} → ∃ A → ((x : D) → A x → B) → B ∃-elim (∃-intro h₁) h₂ = h₂ d (h₁ d) -- Some examples -- Impossible -- thm : {A : D → Set} → ∃[ x ] A x → ∃[ y ] A y -- thm h = ∃-elim h (λ x prf → {!!})
28.577982
78
0.45939
5e37eb1d9c791b710707b0dc6a6ac10651099ec8
1,124
agda
Agda
sum.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
src/sum.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
sum.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
4
2015-04-11T17:19:12.000Z
2019-02-26T06:17:38.000Z
{-# OPTIONS --without-K #-} module sum where open import level using (Level; _⊔_) open import function.core infixr 4 _,_ infixr 2 _×_ infixr 1 _⊎_ record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public _×_ : {l k : Level} (A : Set l) (B : Set k) → Set (l ⊔ k) A × B = Σ A λ _ → B uncurry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : (x : A) → (B x) → Set c} → ((x : A) → (y : B x) → C x y) → ((xy : Σ A B) → C (proj₁ xy) (proj₂ xy)) uncurry f (a , b) = f a b uncurry' : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k} → (X → Y → Z) → (X × Y) → Z uncurry' f (x , y) = f x y data _⊎_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,⊎_] : ∀ {i i' j}{A : Set i}{A' : Set i'}{B : Set j} → (A → B) → (A' → B) → A ⊎ A' → B [ f ,⊎ f' ] (inj₁ a) = f a [ f ,⊎ f' ] (inj₂ a') = f' a' map-⊎ : ∀ {i i' j j'}{A : Set i}{A' : Set i'} → {B : Set j}{B' : Set j'} → (A → B) → (A' → B') → A ⊎ A' → B ⊎ B' map-⊎ g g' = [ inj₁ ∘' g ,⊎ inj₂ ∘' g' ]
24.434783
82
0.414591
1e2fddf3d258456942a79b2f494dd2bfb061d0b3
3,334
agda
Agda
old/Type/Univalence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
old/Type/Univalence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
old/Type/Univalence.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
import Lvl open import Type module Type.Univalence where open import Functional import Logic.Predicate import Relator.Equals import Relator.Equals.Proofs import Type.Cardinality import Type.Cardinality.Proofs import Type.Functions import Type.Functions.Inverse module _ {ℓₗ ℓₒ : Lvl.Level} where open Logic.Predicate open Relator.Equals{ℓₗ Lvl.⊔ ℓₒ}{Lvl.𝐒(ℓₒ)} open Type.Cardinality {ℓₗ} open Type.Cardinality.Proofs {ℓₗ} open Type.Functions UnivalenceAxiom : Type{ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ)} UnivalenceAxiom = ∀{X Y : Type{ℓₒ}} → Bijective{ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ)} ([≡]-to-[≍] {ℓₒ} {X}{Y}) module _ {ℓₗ ℓₒ : Lvl.Level} {univalence : UnivalenceAxiom} where open Logic.Predicate open Relator.Equals open Relator.Equals.Proofs open Type.Cardinality open Type.Cardinality.Proofs open Type.Functions.Inverse instance [≡][≍]-bijection : ∀{X Y} → ((X ≡ Y) ≍ (X ≍ Y)) [≡][≍]-bijection {X}{Y} = [∃]-intro ([≡]-to-[≍] {ℓₗ}{ℓₒ} {X}{Y}) ⦃ univalence{X}{Y} ⦄ [≍]-to-[≡] : ∀{X Y : Type{ℓₒ}} → (X ≍ Y) → (X ≡ Y) [≍]-to-[≡] {X}{Y} = inv([≡]-to-[≍] {ℓₗ}{ℓₒ} {X}{Y}) ⦃ univalence {X}{Y} ⦄ module _ {ℓₗ ℓₒ₁ ℓₒ₂ : Lvl.Level} {univalence : UnivalenceAxiom {ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₁)}{ℓₒ₁}} where open Logic.Predicate open Relator.Equals open Relator.Equals.Proofs open Type.Cardinality {ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₁)} open Type.Cardinality.Proofs {ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₁)} open Type.Functions _≡₂_ = _≡_ {ℓₗ}{ℓₒ₂} _≡ₗ_ = _≡_ {ℓₗ} -- For any type function P from an universe Type{ℓₒ₁} to Type{ℓₒ₂} -- where subst, a substitution for P holds using (_≍_) -- and where the substitution by reflexivity using (_≍_) gives the exact same proof (is a identity function), -- then this substitution will give the same results as the standard substitution rule for equalities (_≡_) for this P. postulate transport-theorem : ∀{P : Type{ℓₒ₁} → Type{ℓₒ₂}} → (subst : (∀{X Y} → (X ≍ Y) → P(X) → P(Y))) → (subst-id : (∀{X} → (px : P(X)) → (subst([≍]-reflexivity) (px) ≡₂ px))) → ∀{X Y} → (xy : (X ≍ Y)) → (px : P(X)) → (subst(xy) (px) ≡₂ [≡]-substitutionᵣ {ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₁)}{Lvl.𝐒(ℓₒ₁)} ([≍]-to-[≡] {ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₁)}{ℓₒ₁} {univalence} (xy)) {P} px) -- transport-theorem {P} (subst) (subst-id) ([∃]-intro bijection ⦃ bijective ⦄) px = -- subst(xy) (px) -- = subst(inv bijection (bijection xy)) (px) -- = [≡]-substitutionᵣ (bijection xy) {P} (px) postulate substitution-is-bijective : ∀{P : Type{ℓₒ₁} → Type{ℓₒ₂}} → (subst : (∀{X Y} → (X ≍ Y) → P(X) → P(Y))) → (subst-id : (∀{X} → (px : P(X)) → (subst([≍]-reflexivity) (px) ≡₂ px))) → ∀{X Y}{xy : (X ≍ Y)} → Bijective{ℓₗ Lvl.⊔ Lvl.𝐒(ℓₒ₂)} (subst(xy)) -- TODO: univalence should probably have other level parameters from this point on postulate [∘]ₗ-bijective : ∀{ℓₒ₃}{X : Type{ℓₒ₁}}{Y : Type{ℓₒ₂}}{Z : Type{ℓₒ₃}}{g : X → Y} → Bijective{ℓₗ}(g) → Bijective{ℓₗ}(\(f : Y → Z) → f ∘ g) postulate [∘]ₗ-cancellationᵣ : ∀{ℓₒ₃}{X : Type{ℓₒ₁}}{Y : Type{ℓₒ₂}}{Z : Type{ℓₒ₃}}{f g : Y → Z}{h : X → Y} → Bijective{ℓₗ}(h) → (f ∘ h ≡ₗ g ∘ h) → (f ≡ₗ g) -- subst{T} P {x}{y} xy fx = [≡]-substitutionᵣ{T}{x}{y} (xy) {P} fx
42.202532
160
0.564487
227b9eca4a1844031ef1029d34b836dc36b477c5
180
agda
Agda
test/Fail/Issue3289.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Fail/Issue3289.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/Issue3289.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
open import Agda.Builtin.Nat record R : Set where field x : Nat open R {{...}} f₁ f₂ : R -- This is fine. x ⦃ f₁ ⦄ = 0 -- THIS WORKS BUT MAKES NO SENSE!!! f₂ ⦃ .x ⦄ = 0
11.25
35
0.555556
197cf60640f11c3f68b2886efe402b5af1f6bfd1
4,412
agda
Agda
cohomology/ProductRepr.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
cohomology/ProductRepr.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
cohomology/ProductRepr.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.Exactness open import cohomology.FunctionOver module cohomology.ProductRepr where {- Given the following commutative diagram of homomorphisms, H₁ i₁ i₂ H₂ ↘ ↙ id ↓ G ↓ id ↙ ↘ H₁ j₁ j₂ H₂ - there exists an isomorphism G == H₁ × H₂ such that i₁,i₂ correspond - to the natural injections and j₁,j₂ correspond to the natural - projections. -} module ProductRepr {i j} {G : Group (lmax i j)} {H₁ : Group i} {H₂ : Group j} (i₁ : H₁ →ᴳ G) (i₂ : H₂ →ᴳ G) (j₁ : G →ᴳ H₁) (j₂ : G →ᴳ H₂) (p₁ : ∀ h₁ → GroupHom.f j₁ (GroupHom.f i₁ h₁) == h₁) (p₂ : ∀ h₂ → GroupHom.f j₂ (GroupHom.f i₂ h₂) == h₂) (ex₁ : is-exact (GroupHom.⊙f i₁) (GroupHom.⊙f j₂)) (ex₂ : is-exact (GroupHom.⊙f i₂) (GroupHom.⊙f j₁)) where zero-ker : (g : Group.El G) → GroupHom.f (×ᴳ-hom-in j₁ j₂) g == Group.ident (H₁ ×ᴳ H₂) → g == Group.ident G zero-ker g q = Trunc-rec (Group.El-level G _ _) (lemma g (fst×= q)) (ktoi ex₁ g (snd×= q)) where lemma : (g : Group.El G) (r : GroupHom.f j₁ g == Group.ident H₁) → Σ (Group.El H₁) (λ h → GroupHom.f i₁ h == g) → g == Group.ident G lemma ._ r (h , idp) = ap (GroupHom.f i₁) (! (p₁ h) ∙ r) ∙ GroupHom.pres-ident i₁ β₁ : (h₁ : Group.El H₁) (h₂ : Group.El H₂) → GroupHom.f j₁ (Group.comp G (GroupHom.f i₁ h₁) (GroupHom.f i₂ h₂)) == h₁ β₁ h₁ h₂ = GroupHom.pres-comp j₁ (GroupHom.f i₁ h₁) (GroupHom.f i₂ h₂) ∙ ap2 (Group.comp H₁) (p₁ h₁) (itok ex₂ _ [ h₂ , idp ]) ∙ Group.unitr H₁ h₁ β₂ : (h₁ : Group.El H₁) (h₂ : Group.El H₂) → GroupHom.f j₂ (Group.comp G (GroupHom.f i₁ h₁) (GroupHom.f i₂ h₂)) == h₂ β₂ h₁ h₂ = GroupHom.pres-comp j₂ (GroupHom.f i₁ h₁) (GroupHom.f i₂ h₂) ∙ ap2 (Group.comp H₂) (itok ex₁ _ [ h₁ , idp ]) (p₂ h₂) ∙ Group.unitl H₂ h₂ iso : G == H₁ ×ᴳ H₂ iso = surj-inj-= (×ᴳ-hom-in j₁ j₂) (zero-kernel-injective (×ᴳ-hom-in j₁ j₂) zero-ker) (λ {(h₁ , h₂) → [ Group.comp G (GroupHom.f i₁ h₁) (GroupHom.f i₂ h₂) , pair×= (β₁ h₁ h₂) (β₂ h₁ h₂) ]}) fst-over : j₁ == ×ᴳ-fst [ (λ U → U →ᴳ H₁) ↓ iso ] fst-over = domain-over-iso _ _ _ _ $ domain-over-equiv fst _ snd-over : j₂ == ×ᴳ-snd {G = H₁} [ (λ U → U →ᴳ H₂) ↓ iso ] snd-over = domain-over-iso _ _ _ _ $ domain-over-equiv snd _ inl-over : i₁ == ×ᴳ-inl [ (λ V → H₁ →ᴳ V) ↓ iso ] inl-over = codomain-over-iso _ _ _ _ $ codomain-over-equiv (GroupHom.f i₁) _ ▹ λ= (λ h₁ → pair×= (p₁ h₁) (itok ex₁ _ [ h₁ , idp ])) inr-over : i₂ == ×ᴳ-inr {G = H₁} [ (λ V → H₂ →ᴳ V) ↓ iso ] inr-over = codomain-over-iso _ _ _ _ $ codomain-over-equiv (GroupHom.f i₂) _ ▹ λ= (λ h₂ → pair×= (itok ex₂ _ [ h₂ , idp ]) (p₂ h₂)) {- Given additionally maps i₀ j₀ K –––→ G ––→ L - such that j₀∘i₀ = 0, we have j₀(i₁(j₁(i₀ k)))⁻¹ = j₀(i₂(j₂(i₀ k))). - (This is called the hexagon lemma in Eilenberg & Steenrod's book. - The hexagon is not visible in this presentation.) -} module HexagonLemma {k l} {K : Group k} {L : Group l} (i₀ : K →ᴳ G) (j₀ : G →ᴳ L) (ex₀ : ∀ g → GroupHom.f j₀ (GroupHom.f i₀ g) == Group.ident L) where decomp : ∀ g → Group.comp G (GroupHom.f i₁ (GroupHom.f j₁ g)) (GroupHom.f i₂ (GroupHom.f j₂ g)) == g decomp = transport (λ {(G' , i₁' , i₂' , j₁' , j₂') → ∀ g → Group.comp G' (GroupHom.f i₁' (GroupHom.f j₁' g)) (GroupHom.f i₂' (GroupHom.f j₂' g)) == g}) (! (pair= iso (↓-×-in inl-over (↓-×-in inr-over (↓-×-in fst-over snd-over))))) (λ {(h₁ , h₂) → pair×= (Group.unitr H₁ h₁) (Group.unitl H₂ h₂)}) cancel : ∀ k → Group.comp L (GroupHom.f (j₀ ∘ᴳ i₁ ∘ᴳ j₁ ∘ᴳ i₀) k) (GroupHom.f (j₀ ∘ᴳ i₂ ∘ᴳ j₂ ∘ᴳ i₀) k) == Group.ident L cancel k = ! (GroupHom.pres-comp j₀ _ _) ∙ ap (GroupHom.f j₀) (decomp (GroupHom.f i₀ k)) ∙ ex₀ k inv₁ : ∀ k → Group.inv L (GroupHom.f (j₀ ∘ᴳ i₁ ∘ᴳ j₁ ∘ᴳ i₀) k) == GroupHom.f (j₀ ∘ᴳ i₂ ∘ᴳ j₂ ∘ᴳ i₀) k inv₁ k = group-inv-unique-r L _ _ (cancel k) inv₂ : ∀ k → Group.inv L (GroupHom.f (j₀ ∘ᴳ i₂ ∘ᴳ j₂ ∘ᴳ i₀) k) == GroupHom.f (j₀ ∘ᴳ i₁ ∘ᴳ j₁ ∘ᴳ i₀) k inv₂ k = group-inv-unique-l L _ _ (cancel k)
35.869919
78
0.526292
2ea3d39da1cb8f97d098087b01917ca7fe270fb3
1,604
agda
Agda
test/Compiler/simple/Issue2821.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Issue2821.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/Issue2821.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Note: out of order true and false. Confuses the -- values if we mess up and compile it to a fresh -- datatype instead of Haskell Bool. data Two : Set where tt ff : Two {-# BUILTIN BOOL Two #-} {-# BUILTIN FALSE ff #-} {-# BUILTIN TRUE tt #-} -- Note: out of order nil and cons. Causes segfault -- if we mess up and compile it to a fresh datatype -- instead of Haskell lists. data List {a} (A : Set a) : Set a where _∷_ : A → List A → List A [] : List A {-# BUILTIN LIST List #-} postulate String : Set Char : Set {-# BUILTIN STRING String #-} {-# BUILTIN CHAR Char #-} primitive primStringToList : String → List Char primStringFromList : List Char → String primStringEquality : String → String → Two drop1 : {A : Set} → List A → List A drop1 (x ∷ xs) = xs drop1 [] = [] postulate drop1' : List Char → List Char {-# COMPILE GHC drop1' = drop 1 #-} onList : (List Char → List Char) → String → String onList f s = primStringFromList (f (primStringToList s)) postulate _==_ : String → String → Two {-# COMPILE GHC _==_ = (==) #-} show : Two → String show tt = onList drop1 "TRUE" show ff = onList drop1' "FALSE" record One : Set where {-# COMPILE GHC One = data () (()) #-} postulate IO : Set → Set {-# BUILTIN IO IO #-} {-# COMPILE GHC IO = type IO #-} {-# FOREIGN GHC import qualified Data.Text.IO #-} postulate putStrLn : String → IO One {-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-} postulate _>>_ : IO One → IO One → IO One {-# COMPILE GHC _>>_ = (>>) #-} main : IO One main = do putStrLn (show ("foo" == "bar")) putStrLn (show ("foo" == "foo"))
22.914286
56
0.625935
c7714897031aaba84ff545c2f767fe743ae22651
507
agda
Agda
test/Succeed/Issue942.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue942.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue942.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --copatterns --allow-unsolved-metas #-} module Issue942 where record Sigma (A : Set)(P : A → Set) : Set where constructor _,_ field fst : A snd : P fst open Sigma postulate A : Set x : A P Q : A → Set Px : P x f : ∀ {x} → P x → Q x ex : Sigma A Q ex = record { fst = x ; snd = f {!!} -- goal: P x } ex' : Sigma A Q ex' = x , f {!!} -- goal: P x ex'' : Sigma A Q fst ex'' = x snd ex'' = f {!!} -- goal: P (fst ex'') -- should termination check
15.363636
51
0.500986
579a48bc15183e94fae6de5be020964d2021d6df
20,074
agda
Agda
extra/extra/Everything.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
1,003
2018-07-05T18:15:14.000Z
2022-03-27T07:03:28.000Z
extra/extra/Everything.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
323
2018-07-05T22:34:34.000Z
2022-03-30T07:42:57.000Z
extra/extra/Everything.agda
krzygorz/plfa.github.io
10a3203624f2ea937b3892176db5de825d0c46b4
[ "CC-BY-4.0" ]
304
2018-07-16T18:24:59.000Z
2022-03-28T11:35:02.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- All library modules, along with short descriptions ------------------------------------------------------------------------ -- Note that core modules are not included. module Everything where -- Definitions of algebraic structures like monoids and rings -- (packed in records together with sets, operations, etc.) open import Algebra -- Solver for equations in commutative monoids open import Algebra.CommutativeMonoidSolver -- An example of how Algebra.CommutativeMonoidSolver can be used open import Algebra.CommutativeMonoidSolver.Example -- Properties of functions, such as associativity and commutativity open import Algebra.FunctionProperties -- Relations between properties of functions, such as associativity and -- commutativity open import Algebra.FunctionProperties.Consequences -- Solver for equations in commutative monoids open import Algebra.IdempotentCommutativeMonoidSolver -- An example of how Algebra.IdempotentCommutativeMonoidSolver can be -- used open import Algebra.IdempotentCommutativeMonoidSolver.Example -- Solver for monoid equalities open import Algebra.Monoid-solver -- Morphisms between algebraic structures open import Algebra.Morphism -- Some defined operations (multiplication by natural number and -- exponentiation) open import Algebra.Operations -- Some derivable properties open import Algebra.Properties.AbelianGroup -- Some derivable properties open import Algebra.Properties.BooleanAlgebra -- Boolean algebra expressions open import Algebra.Properties.BooleanAlgebra.Expression -- Some derivable properties open import Algebra.Properties.DistributiveLattice -- Some derivable properties open import Algebra.Properties.Group -- Some derivable properties open import Algebra.Properties.Lattice -- Some derivable properties open import Algebra.Properties.Ring -- Solver for commutative ring or semiring equalities open import Algebra.RingSolver -- Commutative semirings with some additional structure ("almost" -- commutative rings), used by the ring solver open import Algebra.RingSolver.AlmostCommutativeRing -- Some boring lemmas used by the ring solver open import Algebra.RingSolver.Lemmas -- Instantiates the ring solver, using the natural numbers as the -- coefficient "ring" open import Algebra.RingSolver.Natural-coefficients -- Instantiates the ring solver with two copies of the same ring with -- decidable equality open import Algebra.RingSolver.Simple -- Some algebraic structures (not packed up with sets, operations, -- etc.) open import Algebra.Structures -- Applicative functors open import Category.Applicative -- Indexed applicative functors open import Category.Applicative.Indexed -- Applicative functors on indexed sets (predicates) open import Category.Applicative.Predicate -- Functors open import Category.Functor -- The identity functor open import Category.Functor.Identity -- Functors on indexed sets (predicates) open import Category.Functor.Predicate -- Monads open import Category.Monad -- A delimited continuation monad open import Category.Monad.Continuation -- The identity monad open import Category.Monad.Identity -- Indexed monads open import Category.Monad.Indexed -- The partiality monad open import Category.Monad.Partiality -- An All predicate for the partiality monad open import Category.Monad.Partiality.All -- Monads on indexed sets (predicates) open import Category.Monad.Predicate -- The state monad open import Category.Monad.State -- Basic types related to coinduction open import Coinduction -- AVL trees open import Data.AVL -- Types and functions which are used to keep track of height -- invariants in AVL Trees open import Data.AVL.Height -- Indexed AVL trees open import Data.AVL.Indexed -- Finite maps with indexed keys and values, based on AVL trees open import Data.AVL.IndexedMap -- Keys for AVL trees -- The key type extended with a new minimum and maximum. open import Data.AVL.Key -- Finite sets, based on AVL trees open import Data.AVL.Sets -- A binary representation of natural numbers open import Data.Bin -- Properties of the binary representation of natural numbers open import Data.Bin.Properties -- Booleans open import Data.Bool -- The type for booleans and some operations open import Data.Bool.Base -- A bunch of properties open import Data.Bool.Properties -- Showing booleans open import Data.Bool.Show -- Bounded vectors open import Data.BoundedVec -- Bounded vectors (inefficient, concrete implementation) open import Data.BoundedVec.Inefficient -- Characters open import Data.Char -- Basic definitions for Characters open import Data.Char.Base -- "Finite" sets indexed on coinductive "natural" numbers open import Data.Cofin -- Coinductive lists open import Data.Colist -- Infinite merge operation for coinductive lists open import Data.Colist.Infinite-merge -- Coinductive "natural" numbers open import Data.Conat -- Containers, based on the work of Abbott and others open import Data.Container -- Properties related to ◇ open import Data.Container.Any -- Container combinators open import Data.Container.Combinator -- The free monad construction on containers open import Data.Container.FreeMonad -- Indexed containers aka interaction structures aka polynomial -- functors. The notation and presentation here is closest to that of -- Hancock and Hyvernat in "Programming interfaces and basic topology" -- (2006/9). open import Data.Container.Indexed -- Indexed container combinators open import Data.Container.Indexed.Combinator -- The free monad construction on indexed containers open import Data.Container.Indexed.FreeMonad -- Coinductive vectors open import Data.Covec -- Lists with fast append open import Data.DifferenceList -- Natural numbers with fast addition (for use together with -- DifferenceVec) open import Data.DifferenceNat -- Vectors with fast append open import Data.DifferenceVec -- Digits and digit expansions open import Data.Digit -- Empty type open import Data.Empty -- An irrelevant version of ⊥-elim open import Data.Empty.Irrelevant -- Finite sets open import Data.Fin -- Decision procedures for finite sets and subsets of finite sets open import Data.Fin.Dec -- Properties related to Fin, and operations making use of these -- properties (or other properties not available in Data.Fin) open import Data.Fin.Properties -- Subsets of finite sets open import Data.Fin.Subset -- Some properties about subsets open import Data.Fin.Subset.Properties -- Substitutions open import Data.Fin.Substitution -- An example of how Data.Fin.Substitution can be used: a definition -- of substitution for the untyped λ-calculus, along with some lemmas open import Data.Fin.Substitution.Example -- Substitution lemmas open import Data.Fin.Substitution.Lemmas -- Application of substitutions to lists, along with various lemmas open import Data.Fin.Substitution.List -- Floats open import Data.Float -- Directed acyclic multigraphs open import Data.Graph.Acyclic -- Integers open import Data.Integer -- Properties related to addition of integers open import Data.Integer.Addition.Properties -- Integers, basic types and operations open import Data.Integer.Base -- Divisibility and coprimality open import Data.Integer.Divisibility -- Properties related to multiplication of integers open import Data.Integer.Multiplication.Properties -- Some properties about integers open import Data.Integer.Properties -- Lists open import Data.List -- Lists where all elements satisfy a given property open import Data.List.All -- Properties related to All open import Data.List.All.Properties -- Lists where at least one element satisfies a given property open import Data.List.Any -- Properties related to bag and set equality open import Data.List.Any.BagAndSetEquality -- List membership and some related definitions open import Data.List.Any.Membership -- Properties related to propositional list membership open import Data.List.Any.Membership.Properties -- Data.List.Any.Membership instantiated with propositional equality, -- along with some additional definitions. open import Data.List.Any.Membership.Propositional -- Properties related to propositional list membership open import Data.List.Any.Membership.Propositional.Properties -- Properties related to Any open import Data.List.Any.Properties -- Lists, basic types and operations open import Data.List.Base -- A categorical view of List open import Data.List.Categorical -- A data structure which keeps track of an upper bound on the number -- of elements /not/ in a given list open import Data.List.Countdown -- Non-empty lists open import Data.List.NonEmpty -- Properties of non-empty lists open import Data.List.NonEmpty.Properties -- List-related properties open import Data.List.Properties -- Lexicographic ordering of lists open import Data.List.Relation.NonStrictLex -- Pointwise lifting of relations to lists open import Data.List.Relation.Pointwise -- Lexicographic ordering of lists open import Data.List.Relation.StrictLex -- Reverse view open import Data.List.Reverse -- M-types (the dual of W-types) open import Data.M -- Indexed M-types (the dual of indexed W-types aka Petersson-Synek -- trees). open import Data.M.Indexed -- The Maybe type open import Data.Maybe -- The Maybe type and some operations open import Data.Maybe.Base -- Natural numbers open import Data.Nat -- Natural numbers, basic types and operations open import Data.Nat.Base -- Coprimality open import Data.Nat.Coprimality -- Integer division open import Data.Nat.DivMod -- Divisibility open import Data.Nat.Divisibility -- Greatest common divisor open import Data.Nat.GCD -- Boring lemmas used in Data.Nat.GCD and Data.Nat.Coprimality open import Data.Nat.GCD.Lemmas -- A generalisation of the arithmetic operations open import Data.Nat.GeneralisedArithmetic -- Definition of and lemmas related to "true infinitely often" open import Data.Nat.InfinitelyOften -- Least common multiple open import Data.Nat.LCM -- Primality open import Data.Nat.Primality -- A bunch of properties about natural number operations open import Data.Nat.Properties -- A bunch of properties about natural number operations open import Data.Nat.Properties.Simple -- Showing natural numbers open import Data.Nat.Show -- Transitive closures open import Data.Plus -- Products open import Data.Product -- N-ary products open import Data.Product.N-ary -- Properties of products open import Data.Product.Properties -- Lexicographic products of binary relations open import Data.Product.Relation.NonStrictLex -- Pointwise products of binary relations open import Data.Product.Relation.Pointwise -- Pointwise lifting of binary relations to sigma types open import Data.Product.Relation.SigmaPointwise -- Lexicographic products of binary relations open import Data.Product.Relation.StrictLex -- Rational numbers open import Data.Rational -- Properties of Rational numbers open import Data.Rational.Properties -- Reflexive closures open import Data.ReflexiveClosure -- Signs open import Data.Sign -- Some properties about signs open import Data.Sign.Properties -- The reflexive transitive closures of McBride, Norell and Jansson open import Data.Star -- Bounded vectors (inefficient implementation) open import Data.Star.BoundedVec -- Decorated star-lists open import Data.Star.Decoration -- Environments (heterogeneous collections) open import Data.Star.Environment -- Finite sets defined in terms of Data.Star open import Data.Star.Fin -- Lists defined in terms of Data.Star open import Data.Star.List -- Natural numbers defined in terms of Data.Star open import Data.Star.Nat -- Pointers into star-lists open import Data.Star.Pointer -- Some properties related to Data.Star open import Data.Star.Properties -- Vectors defined in terms of Data.Star open import Data.Star.Vec -- Streams open import Data.Stream -- Strings open import Data.String -- Strings open import Data.String.Base -- Sums (disjoint unions) open import Data.Sum -- Properties of sums (disjoint unions) open import Data.Sum.Properties -- Sums of binary relations open import Data.Sum.Relation.General -- Fixed-size tables of values, implemented as functions from 'Fin n'. -- Similar to 'Data.Vec', but focusing on ease of retrieval instead of -- ease of adding and removing elements. open import Data.Table -- Tables, basic types and operations open import Data.Table.Base -- Table-related properties open import Data.Table.Properties -- Pointwise table equality open import Data.Table.Relation.Equality -- Some unit types open import Data.Unit -- The unit type and the total relation on unit open import Data.Unit.Base -- Some unit types open import Data.Unit.NonEta -- Vectors open import Data.Vec -- Vectors where all elements satisfy a given property open import Data.Vec.All -- Properties related to All open import Data.Vec.All.Properties -- A categorical view of Vec open import Data.Vec.Categorical -- Code for converting Vec A n → B to and from n-ary functions open import Data.Vec.N-ary -- Some Vec-related properties open import Data.Vec.Properties -- Semi-heterogeneous vector equality open import Data.Vec.Relation.Equality -- Extensional pointwise lifting of relations to vectors open import Data.Vec.Relation.ExtensionalPointwise -- Inductive pointwise lifting of relations to vectors open import Data.Vec.Relation.InductivePointwise -- W-types open import Data.W -- Indexed W-types aka Petersson-Synek trees open import Data.W.Indexed -- Machine words open import Data.Word -- Type(s) used (only) when calling out to Haskell via the FFI open import Foreign.Haskell -- Simple combinators working solely on and with functions open import Function -- Bijections open import Function.Bijection -- Function setoids and related constructions open import Function.Equality -- Equivalence (coinhabitance) open import Function.Equivalence -- Injections open import Function.Injection -- Inverses open import Function.Inverse -- Left inverses open import Function.LeftInverse -- A universe which includes several kinds of "relatedness" for sets, -- such as equivalences, surjections and bijections open import Function.Related -- Basic lemmas showing that various types are related (isomorphic or -- equivalent or…) open import Function.Related.TypeIsomorphisms -- Surjections open import Function.Surjection -- IO open import IO -- Primitive IO: simple bindings to Haskell types and functions open import IO.Primitive -- An abstraction of various forms of recursion/induction open import Induction -- Lexicographic induction open import Induction.Lexicographic -- Various forms of induction for natural numbers open import Induction.Nat -- Well-founded induction open import Induction.WellFounded -- Universe levels open import Level -- Record types with manifest fields and "with", based on Randy -- Pollack's "Dependently Typed Records in Type Theory" open import Record -- Support for reflection open import Reflection -- Properties of homogeneous binary relations open import Relation.Binary -- Some properties imply others open import Relation.Binary.Consequences -- Convenient syntax for equational reasoning open import Relation.Binary.EqReasoning -- Equivalence closures of binary relations open import Relation.Binary.EquivalenceClosure -- Many properties which hold for _∼_ also hold for flip _∼_ open import Relation.Binary.Flip -- Heterogeneous equality open import Relation.Binary.HeterogeneousEquality -- Quotients for Heterogeneous equality open import Relation.Binary.HeterogeneousEquality.Quotients -- Example of a Quotient: ℤ as (ℕ × ℕ / ~) open import Relation.Binary.HeterogeneousEquality.Quotients.Examples -- Indexed binary relations open import Relation.Binary.Indexed -- Induced preorders open import Relation.Binary.InducedPreorders -- Order-theoretic lattices open import Relation.Binary.Lattice -- Lexicographic ordering of lists open import Relation.Binary.List.NonStrictLex -- Pointwise lifting of relations to lists open import Relation.Binary.List.Pointwise -- Lexicographic ordering of lists open import Relation.Binary.List.StrictLex -- Conversion of ≤ to <, along with a number of properties open import Relation.Binary.NonStrictToStrict -- Many properties which hold for _∼_ also hold for _∼_ on f open import Relation.Binary.On -- Order morphisms open import Relation.Binary.OrderMorphism -- Convenient syntax for "equational reasoning" using a partial order open import Relation.Binary.PartialOrderReasoning -- Convenient syntax for "equational reasoning" using a preorder open import Relation.Binary.PreorderReasoning -- Lexicographic products of binary relations open import Relation.Binary.Product.NonStrictLex -- Pointwise products of binary relations open import Relation.Binary.Product.Pointwise -- Lexicographic products of binary relations open import Relation.Binary.Product.StrictLex -- Properties satisfied by bounded join semilattices open import Relation.Binary.Properties.BoundedJoinSemilattice -- Properties satisfied by bounded meet semilattices open import Relation.Binary.Properties.BoundedMeetSemilattice -- Properties satisfied by decidable total orders open import Relation.Binary.Properties.DecTotalOrder -- Properties satisfied by join semilattices open import Relation.Binary.Properties.JoinSemilattice -- Properties satisfied by lattices open import Relation.Binary.Properties.Lattice -- Properties satisfied by meet semilattices open import Relation.Binary.Properties.MeetSemilattice -- Properties satisfied by posets open import Relation.Binary.Properties.Poset -- Properties satisfied by preorders open import Relation.Binary.Properties.Preorder -- Properties satisfied by strict partial orders open import Relation.Binary.Properties.StrictPartialOrder -- Properties satisfied by strict partial orders open import Relation.Binary.Properties.StrictTotalOrder -- Properties satisfied by total orders open import Relation.Binary.Properties.TotalOrder -- Propositional (intensional) equality open import Relation.Binary.PropositionalEquality -- An equality postulate which evaluates open import Relation.Binary.PropositionalEquality.TrustMe -- Helpers intended to ease the development of "tactics" which use -- proof by reflection open import Relation.Binary.Reflection -- Convenient syntax for "equational reasoning" in multiple Setoids open import Relation.Binary.SetoidReasoning -- Pointwise lifting of binary relations to sigma types open import Relation.Binary.Sigma.Pointwise -- Some simple binary relations open import Relation.Binary.Simple -- Convenient syntax for "equational reasoning" using a strict partial -- order open import Relation.Binary.StrictPartialOrderReasoning -- Conversion of < to ≤, along with a number of properties open import Relation.Binary.StrictToNonStrict -- Sums of binary relations open import Relation.Binary.Sum -- Symmetric closures of binary relations open import Relation.Binary.SymmetricClosure -- Pointwise lifting of relations to vectors open import Relation.Binary.Vec.Pointwise -- Operations on nullary relations (like negation and decidability) open import Relation.Nullary -- Operations on and properties of decidable relations open import Relation.Nullary.Decidable -- Implications of nullary relations open import Relation.Nullary.Implication -- Properties related to negation open import Relation.Nullary.Negation -- Products of nullary relations open import Relation.Nullary.Product -- Sums of nullary relations open import Relation.Nullary.Sum -- A universe of proposition functors, along with some properties open import Relation.Nullary.Universe -- Unary relations open import Relation.Unary -- Predicate transformers open import Relation.Unary.PredicateTransformer -- Sizes for Agda's sized types open import Size -- Strictness combinators open import Strict -- Universes open import Universe
25.410127
72
0.798496
1d76f8089a1a15ebc78ebfd5c77a31b78f357420
40
agda
Agda
test/Succeed/WarningOnImport.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/WarningOnImport.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/WarningOnImport.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import WarningOnImport.Impo C = A
10
32
0.775
3d550a39f2e9b007a4215d6e1a5c27a27be4b80f
2,777
agda
Agda
Cubical/Experiments/FunExtFromUA.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Experiments/FunExtFromUA.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
Cubical/Experiments/FunExtFromUA.agda
borsiemir/cubical
cefeb3669ffdaea7b88ae0e9dd258378418819ca
[ "MIT" ]
null
null
null
{- Voevodsky's proof that univalence implies funext -} {-# OPTIONS --cubical --safe #-} module Cubical.Experiments.FunExtFromUA where open import Cubical.Foundations.Everything variable ℓ ℓ' : Level _∼_ : {X : Type ℓ} {A : X → Type ℓ'} → (f g : (x : X) → A x) → Type (ℓ-max ℓ ℓ') f ∼ g = ∀ x → f x ≡ g x funext : ∀ ℓ ℓ' → Type (ℓ-suc(ℓ-max ℓ ℓ')) funext ℓ ℓ' = {X : Type ℓ} {Y : Type ℓ'} {f g : X → Y} → f ∼ g → f ≡ g pre-comp-is-equiv : (X Y : Type ℓ) (f : X → Y) (Z : Type ℓ) → isEquiv f → isEquiv (λ (g : Y → Z) → g ∘ f) pre-comp-is-equiv {ℓ} X Y f Z e = elimEquivFun P r (f , e) where P : (X : Type ℓ) → (X → Y) → Type ℓ P X f = isEquiv (λ (g : Y → Z) → g ∘ f) r : P Y (λ x → x) r = idIsEquiv (Y → Z) leftCancellable : {X : Type ℓ} {Y : Type ℓ'} → (X → Y) → Type (ℓ-max ℓ ℓ') leftCancellable f = ∀ {x x'} → f x ≡ f x' → x ≡ x' equivLC : {X : Type ℓ} {Y : Type ℓ'} (f : X → Y) → isEquiv f → leftCancellable f equivLC f e {x} {x'} p i = hcomp (λ j → \ {(i = i0) → secEq (f , e) x j ; (i = i1) → secEq (f , e) x' j}) (invEq (f , e) (p i)) univalence-gives-funext : funext ℓ' ℓ univalence-gives-funext {ℓ'} {ℓ} {X} {Y} {f₀} {f₁} = γ where Δ = Σ[ y₀ ∈ Y ] Σ[ y₁ ∈ Y ] y₀ ≡ y₁ δ : Y → Δ δ y = (y , y , refl) π₀ π₁ : Δ → Y π₀ (y₀ , y₁ , p) = y₀ π₁ (y₀ , y₁ , p) = y₁ δ-is-equiv : isEquiv δ δ-is-equiv = isoToIsEquiv (iso δ π₀ ε η) where η : (y : Y) → π₀ (δ y) ≡ y η y = refl ε : (d : Δ) → δ (π₀ d) ≡ d ε (y₀ , y₁ , p) i = y₀ , p i , λ j → p (i ∧ j) φ : (Δ → Y) → (Y → Y) φ π = π ∘ δ e : isEquiv φ e = pre-comp-is-equiv Y Δ δ Y δ-is-equiv p : φ π₀ ≡ φ π₁ p = refl q : π₀ ≡ π₁ q = equivLC φ e p g : (h : f₀ ∼ f₁) (π : Δ → Y) (x : X) → Y g = λ h π x → π (f₀ x , f₁ x , h x) γ : f₀ ∼ f₁ → f₀ ≡ f₁ γ h = cong (g h) q γ' : f₀ ∼ f₁ → f₀ ≡ f₁ γ' h = f₀ ≡⟨ refl ⟩ (λ x → f₀ x) ≡⟨ refl ⟩ (λ x → π₀ (f₀ x , f₁ x , h x)) ≡⟨ cong (g h) q ⟩ (λ x → π₁ (f₀ x , f₁ x , h x)) ≡⟨ refl ⟩ (λ x → f₁ x) ≡⟨ refl ⟩ f₁ ∎ {- Experiment testing univalence via funext -} private data ℕ : Type₀ where zero : ℕ succ : ℕ → ℕ f g : ℕ → ℕ f n = n g zero = zero g (succ n) = succ (g n) h : (n : ℕ) → f n ≡ g n h zero = refl h (succ n) = cong succ (h n) p : f ≡ g p = univalence-gives-funext h five : ℕ five = succ (succ (succ (succ (succ zero)))) a : Σ ℕ (λ n → f n ≡ five) a = five , refl b : Σ ℕ (λ n → g n ≡ five) b = subst (λ - → Σ ℕ (λ n → - n ≡ five)) p a c : fst b ≡ five c = refl {- It works, fast. -}
23.735043
80
0.42996
38b9c99d43b89335e56640828f68aea3c221b943
474
agda
Agda
test/Succeed/Issue959.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue959.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue959.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --copatterns #-} open import Common.Equality open import Common.Product id : {A : Set} → A → A id x = x record Functor (F : Set → Set) : Set₁ where field map : ∀ {A B} → (A → B) → F A → F B map-id : ∀ {A}{x : F A} → map id x ≡ x open Functor test : {C : Set} → Functor (_×_ C) map test f (c , a) = c , f a map-id test = refl -- : map test id x ≡ x -- needs to match against record constructor -- x/(c,a) = proj₁ x / c, proj₂ x / a
23.7
51
0.540084
4bfd3802ece27bf20cfa771c5245b7a500d26310
1,108
agda
Agda
test/Succeed/Issue481.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue481.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue481.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2012-10-18 wish granted module Issue481 where -- Use case: open import Common.Issue481ParametrizedModule Set using () renaming (id to idSet) open import Common.Issue481ParametrizedModule (Set → Set) using () renaming (id to idSetToSet) open import Common.Issue481ParametrizedModule -- With 'as' clause: open import Common.Issue481ParametrizedModule Set as PSet using (id) {- MEANS: import Common.Issue481ParametrizedModule private open module PSet = Common.Issue481ParametrizedModule Set using (id) -} -- Abuse case: as = Set open import Common.Issue481ParametrizedModule as as as module M = as -- Test case: module Test where -- should succeed: open import Issue481Record as Rec open Issue481Record {- Note: this is NOT equivalent to the following, failing sequence import Issue481Record open module Rec = Issue481Record open Issue481Record -- Ambiguous module name Issue481Record. It could refer to any one of -- Rec.Issue481Record -- Issue481Record It is equivalent to: -} module Test2 where import Issue481Record private open module Rec = Issue481Record
20.145455
94
0.771661
19a56226a0cacb5dd6acc715a9d13570be3ba4ea
404
agda
Agda
test/fail/Test2.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
test/fail/Test2.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
test/fail/Test2.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import lib.Base module fail.Test2 where module _ where private data #I-aux : Type₀ where #zero : #I-aux #one : #I-aux data #I : Type₀ where #i : #I-aux → (Unit → Unit) → #I I : Type₀ I = #I zero : I zero = #i #zero _ one : I one = #i #one _ -- postulate -- seg : zero == one absurd : zero ≠ one absurd () -- fails
13.032258
38
0.522277
387e27e1928d21c0eee73943e8dce18c06d74a0b
152
agda
Agda
test/Fail/TupleTerm.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
55
2020-10-20T13:36:25.000Z
2022-03-26T21:57:56.000Z
test/Fail/TupleTerm.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
63
2020-10-22T05:19:27.000Z
2022-02-25T15:47:30.000Z
test/Fail/TupleTerm.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
18
2020-10-21T22:19:09.000Z
2022-03-12T11:42:52.000Z
module Fail.TupleTerm where open import Haskell.Prelude pair2trip : a → b × c → a × b × c pair2trip x xs = x ∷ xs {-# COMPILE AGDA2HS pair2trip #-}
15.2
33
0.664474
19c97ea31ef76b20a904aeeb89e318a475315945
1,282
agda
Agda
src/Delay-monad/Alternative.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
2
2020-05-21T22:59:18.000Z
2020-07-03T08:56:08.000Z
src/Delay-monad/Alternative.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
src/Delay-monad/Alternative.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The delay monad, defined using increasing sequences of potential -- values ------------------------------------------------------------------------ {-# OPTIONS --safe #-} module Delay-monad.Alternative where open import Equality.Propositional open import Prelude hiding (↑) ------------------------------------------------------------------------ -- _↓_ and _↑ module _ {a} {A : Type a} where infix 4 _↑ _↓_ -- x ↓ y means that the computation x has the value y. _↓_ : Maybe A → A → Type a x ↓ y = x ≡ just y -- x ↑ means that the computation x does not have a value. _↑ : Maybe A → Type a x ↑ = x ≡ nothing ------------------------------------------------------------------------ -- An alternative definition of the delay monad module _ {a} {A : Type a} where -- The property of being an increasing sequence. LE : Maybe A → Maybe A → Type a LE x y = x ≡ y ⊎ (x ↑ × ¬ y ↑) Increasing-at : ℕ → (ℕ → Maybe A) → Type a Increasing-at n f = LE (f n) (f (suc n)) Increasing : (ℕ → Maybe A) → Type a Increasing f = ∀ n → Increasing-at n f -- An alternative definition of the delay monad. Delay : ∀ {a} → Type a → Type a Delay A = ∃ λ (f : ℕ → Maybe A) → Increasing f
25.64
72
0.478159
4bb182a70bafad623e18c24a7e8d861855197ab1
495
agda
Agda
test/Succeed/Issue376-irrelevant-projections.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue376-irrelevant-projections.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue376-irrelevant-projections.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v tc.meta:50 #-} -- Andreas 2012-03-27, record pattern unification {-# OPTIONS --irrelevant-projections #-} module Issue376-irrelevant-projections where open import Common.Equality open import Common.Irrelevance bla4 : (A : Set) -> let A' = Squash (Squash A) in let X : .(z : A') -> (C : .A' -> Set) -> (.(z : A') -> C z) -> C z X = _ in (a : A)(C : .A' -> Set)(k : .(z : A') -> C z) -> X (squash (squash a)) C k ≡ k (squash (squash a)) bla4 A a C k = refl
29.117647
68
0.557576
0b7ad9d0e08db6644c93d9717ede5e5ea9efab85
4,045
agda
Agda
Functional.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Functional.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Functional.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Functional where import Lvl open import Type infixl 10000 _∘_ infixl 10000 _⩺_ infixl 10000 _⩹_ infixl 30 _→ᶠ_ _←_ _←ᶠ_ infixr 0 _$_ private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable T X X₁ X₂ X₃ X₄ Y Y₁ Y₂ Y₃ Y₄ Z : Type{ℓ} -- Converse of a function type _←_ : Type{ℓ₁} → Type{ℓ₂} → Type{ℓ₁ Lvl.⊔ ℓ₂} Y ← X = X → Y -- Function type as a function _→ᶠ_ : Type{ℓ₁} → Type{ℓ₂} → Type{ℓ₁ Lvl.⊔ ℓ₂} X →ᶠ Y = X → Y -- Converse function type as a function _←ᶠ_ : Type{ℓ₁} → Type{ℓ₂} → Type{ℓ₁ Lvl.⊔ ℓ₂} Y ←ᶠ X = Y ← X -- The identity function. -- Returns the applied argument. id : T → T id(x) = x {-# INLINE id #-} -- The constant function. -- Returns the first argument independent of the second. const : let _ = X in Y → (X → Y) const(x)(_) = x -- Function application as a function. -- Applies the first argument on the function on the second argument. apply : X → (X → Y) → Y apply(x)(f) = f(x) {-# INLINE apply #-} -- Function application as an operator _$_ : (X → Y) → X → Y _$_ = id {-# INLINE _$_ #-} _$ᵢₘₚₗ_ : ({ _ : X } → Y) → (X → Y) f $ᵢₘₚₗ x = f{x} {-# INLINE _$ᵢₘₚₗ_ #-} _$ᵢₙₛₜ_ : (⦃ _ : X ⦄ → Y) → (X → Y) f $ᵢₙₛₜ x = f ⦃ x ⦄ {-# INLINE _$ᵢₙₛₜ_ #-} -- Function application as an operator. Function to the left, value to the right. _⩹_ : (X → Y) → X → Y f ⩹ x = f(x) {-# INLINE _⩹_ #-} -- Function application as an operator. Value to the left, function to the right. _⩺_ : X → (X → Y) → Y x ⩺ f = f(x) {-# INLINE _⩺_ #-} -- Swapping the arguments of a binary operation swap : (X → Y → Z) → (Y → X → Z) swap f(y)(x) = f(x)(y) {-# INLINE swap #-} -- Function composition _∘_ : let _ = X in (Y → Z) → (X → Y) → (X → Z) (f ∘ g)(x) = f(g(x)) -- Function composition on implicit argument _∘ᵢₘₚₗ_ : let _ = X in ({Y} → Z) → ({X} → Y) → ({X} → Z) (f ∘ᵢₘₚₗ g){x} = f{g{x}} -- Function composition on instance argument _∘ᵢₙₛₜ_ : let _ = X in (⦃ Y ⦄ → Z) → (⦃ X ⦄ → Y) → (⦃ X ⦄ → Z) (f ∘ᵢₙₛₜ g) ⦃ x ⦄ = f ⦃ g ⦃ x ⦄ ⦄ -- The S-combinator from combinatory logic. -- It is sometimes described as a generalized version of the application operator or the composition operator. -- Note: TODO: Applicative instance _∘ₛ_ : (X → Y → Z) → (X → Y) → (X → Z) (f ∘ₛ g)(x) = (f x) (g x) _on₀_ : let _ = X in Z → (X → Y) → Z ((▫) on₀ f) = ▫ -- const _on₁_ : let _ = X in (Y → Z) → (X → Y) → (X → Z) ((_▫) on₁ f)(y₁) = (f(y₁) ▫) on₀ f -- f(y₁) ▫ -- Function composition on a binary operator -- A function is composed on every argument of the binary operator. _on₂_ : let _ = X in (Y → Y → Z) → (X → Y) → (X → X → Z) ((_▫_) on₂ f)(y₁) = (f(y₁) ▫_) on₁ f -- f(y₁) ▫ f(y₂) _on₃_ : let _ = X in (Y → Y → Y → Z) → (X → Y) → (X → X → X → Z) ((_▫_▫_) on₃ f)(y₁) = (f(y₁) ▫_▫_) on₂ f -- f(y₁) ▫ f(y₂) ▫ f(y₃) -- TODO: Move these to Function.Multi _∘₀_ : (Y → Z) → Y → Z _∘₀_ = id _∘₁_ : let _ = X₁ in (Y → Z) → (X₁ → Y) → (X₁ → Z) _∘₁_ f = (f ∘₀_) ∘_ -- (f ∘₂ g)(x)(y) = f(g(x)(y)) _∘₂_ : let _ = X₁ ; _ = X₂ in (Y → Z) → (X₁ → X₂ → Y) → (X₁ → X₂ → Z) _∘₂_ f = (f ∘₁_) ∘_ -- (f ∘₃ g)(x)(y)(z) = f(g(x)(y)(z)) _∘₃_ : let _ = X₁ ; _ = X₂ ; _ = X₃ in (Y → Z) → (X₁ → X₂ → X₃ → Y) → (X₁ → X₂ → X₃ → Z) _∘₃_ f = (f ∘₂_) ∘_ -- (f ∘₄ g)(x)(y)(z)(w) = f(g(x)(y)(z)(w)) _∘₄_ : let _ = X₁ ; _ = X₂ ; _ = X₃ ; _ = X₄ in (Y → Z) → (X₁ → X₂ → X₃ → X₄ → Y) → (X₁ → X₂ → X₃ → X₄ → Z) _∘₄_ f = (f ∘₃_) ∘_ -- map₂Arg₁ : let _ = X in (Y₁ → Y₂ → Z) → (X → Y₁) → (X → Y₂) → (X → Z) -- map₂Arg₁ f g₁ g₂ x = f(g₁ x)(g₂ x) -- map₂Arg₂ : let _ = X₁ ; _ = X₂ in (Y₁ → Y₂ → Z) → (X₁ → Y₁) → (X₂ → Y₂) → (X₁ → X₂ → Z) -- map₂Arg₂ f g₁ g₂ x₁ x₂ = f(g₁ x₁)(g₂ x₂) -- Function lifting //TODO: Consider removing because it is the same as _∘_ liftₗ : (X → Y) → ((Z → X) → (Z → Y)) liftₗ = _∘_ -- liftₗ(f) = f ∘_ liftᵣ : (X → Y) → ((Y → Z) → (X → Z)) liftᵣ = swap(_∘_) -- liftᵣ(f) = _∘ f -- Applies an argument to two arguments of a binary function. _$₂_ : (X → X → Y) → (X → Y) f $₂ x = f x x apply₂ : X → (X → X → Y) → Y apply₂ x f = f x x proj₂ₗ : X → Y → X proj₂ₗ = const proj₂ᵣ : X → Y → Y proj₂ᵣ = const id open import Syntax.Function public
26.611842
110
0.52707
1ed8be0a5411baf29cc448583077420589503cfb
6,247
agda
Agda
list.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
29
2019-02-06T13:09:31.000Z
2022-03-04T15:05:12.000Z
list.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
8
2018-07-09T22:53:38.000Z
2022-03-22T03:43:34.000Z
list.agda
rfindler/ial
f3f0261904577e930bd7646934f756679a6cbba6
[ "MIT" ]
17
2018-12-03T22:38:15.000Z
2021-11-28T20:13:21.000Z
module list where open import level open import bool open import eq open import maybe open import nat open import unit open import product open import empty open import sum ---------------------------------------------------------------------- -- datatypes ---------------------------------------------------------------------- data 𝕃 {ℓ} (A : Set ℓ) : Set ℓ where [] : 𝕃 A _::_ : (x : A) (xs : 𝕃 A) → 𝕃 A {-# BUILTIN LIST 𝕃 #-} list = 𝕃 ---------------------------------------------------------------------- -- syntax ---------------------------------------------------------------------- infixr 6 _::_ _++_ infixr 5 _shorter_ _longer_ ---------------------------------------------------------------------- -- operations ---------------------------------------------------------------------- [_] : ∀ {ℓ} {A : Set ℓ} → A → 𝕃 A [ x ] = x :: [] is-empty : ∀{ℓ}{A : Set ℓ} → 𝕃 A → 𝔹 is-empty [] = tt is-empty (_ :: _) = ff tail : ∀ {ℓ} {A : Set ℓ} → 𝕃 A → 𝕃 A tail [] = [] tail (x :: xs) = xs head : ∀{ℓ}{A : Set ℓ} → (l : 𝕃 A) → .(is-empty l ≡ ff) → A head [] () head (x :: xs) _ = x head2 : ∀{ℓ}{A : Set ℓ} → (l : 𝕃 A) → maybe A head2 [] = nothing head2 (a :: _) = just a last : ∀{ℓ}{A : Set ℓ} → (l : 𝕃 A) → is-empty l ≡ ff → A last [] () last (x :: []) _ = x last (x :: (y :: xs)) _ = last (y :: xs) refl _++_ : ∀ {ℓ} {A : Set ℓ} → 𝕃 A → 𝕃 A → 𝕃 A [] ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) concat : ∀{ℓ}{A : Set ℓ} → 𝕃 (𝕃 A) → 𝕃 A concat [] = [] concat (l :: ls) = l ++ concat ls repeat : ∀{ℓ}{A : Set ℓ} → ℕ → A → 𝕃 A repeat 0 a = [] repeat (suc n) a = a :: (repeat n a) map : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A → B) → 𝕃 A → 𝕃 B map f [] = [] map f (x :: xs) = f x :: map f xs -- The hom part of the list functor. list-funct : {A B : Set} → (A → B) → (𝕃 A → 𝕃 B) list-funct f l = map f l {- (maybe-map f xs) returns (just ys) if f returns (just y_i) for each x_i in the list xs. Otherwise, (maybe-map f xs) returns nothing. -} 𝕃maybe-map : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A → maybe B) → 𝕃 A → maybe (𝕃 B) 𝕃maybe-map f [] = just [] 𝕃maybe-map f (x :: xs) with f x 𝕃maybe-map f (x :: xs) | nothing = nothing 𝕃maybe-map f (x :: xs) | just y with 𝕃maybe-map f xs 𝕃maybe-map f (x :: xs) | just y | nothing = nothing 𝕃maybe-map f (x :: xs) | just y | just ys = just (y :: ys) foldr : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (A → B → B) → B → 𝕃 A → B foldr f b [] = b foldr f b (a :: as) = f a (foldr f b as) length : ∀{ℓ}{A : Set ℓ} → 𝕃 A → ℕ length [] = 0 length (x :: xs) = suc (length xs) reverse-helper : ∀ {ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A → 𝕃 A reverse-helper h [] = h reverse-helper h (x :: xs) = reverse-helper (x :: h) xs reverse : ∀ {ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A reverse l = reverse-helper [] l list-member : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l : 𝕃 A) → 𝔹 list-member eq a [] = ff list-member eq a (x :: xs) = eq a x || list-member eq a xs list-minus : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(l1 l2 : 𝕃 A) → 𝕃 A list-minus eq [] l2 = [] list-minus eq (x :: xs) l2 = let r = list-minus eq xs l2 in if list-member eq x l2 then r else x :: r _longer_ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → 𝔹 [] longer y = ff (x :: xs) longer [] = tt (x :: xs) longer (y :: ys) = xs longer ys _shorter_ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) → 𝔹 x shorter y = y longer x -- return tt iff all elements in the list satisfy the given predicate pred. list-all : ∀{ℓ}{A : Set ℓ}(pred : A → 𝔹)(l : 𝕃 A) → 𝔹 list-all pred [] = tt list-all pred (x :: xs) = pred x && list-all pred xs all-pred : {X : Set} → (X → Set) → 𝕃 X → Set all-pred f [] = ⊤ all-pred f (x₁ :: xs) = (f x₁) ∧ (all-pred f xs) -- return tt iff at least one element in the list satisfies the given predicate pred. list-any : ∀{ℓ}{A : Set ℓ}(pred : A → 𝔹)(l : 𝕃 A) → 𝔹 list-any pred [] = ff list-any pred (x :: xs) = pred x || list-any pred xs list-and : (l : 𝕃 𝔹) → 𝔹 list-and [] = tt list-and (x :: xs) = x && (list-and xs) list-or : (l : 𝕃 𝔹) → 𝔹 list-or [] = ff list-or (x :: l) = x || list-or l list-max : ∀{ℓ}{A : Set ℓ} (lt : A → A → 𝔹) → 𝕃 A → A → A list-max lt [] x = x list-max lt (y :: ys) x = list-max lt ys (if lt y x then x else y) isSublist : ∀{ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A → (A → A → 𝔹) → 𝔹 isSublist l1 l2 eq = list-all (λ a → list-member eq a l2) l1 =𝕃 : ∀{ℓ}{A : Set ℓ} → (A → A → 𝔹) → (l1 : 𝕃 A) → (l2 : 𝕃 A) → 𝔹 =𝕃 eq (a :: as) (b :: bs) = eq a b && =𝕃 eq as bs =𝕃 eq [] [] = tt =𝕃 eq _ _ = ff filter : ∀{ℓ}{A : Set ℓ} → (A → 𝔹) → 𝕃 A → 𝕃 A filter p [] = [] filter p (x :: xs) = let r = filter p xs in if p x then x :: r else r -- remove all elements equal to the given one remove : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l : 𝕃 A) → 𝕃 A remove eq a l = filter (λ x → ~ (eq a x)) l {- nthTail n l returns the part of the list after the first n elements, or [] if the list has fewer than n elements -} nthTail : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → 𝕃 A nthTail 0 l = l nthTail n [] = [] nthTail (suc n) (x :: l) = nthTail n l nth : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → maybe A nth _ [] = nothing nth 0 (x :: xs) = just x nth (suc n) (x :: xs) = nth n xs -- nats-down N returns N :: (N-1) :: ... :: 0 :: [] nats-down : ℕ → 𝕃 ℕ nats-down 0 = [ 0 ] nats-down (suc x) = suc x :: nats-down x zip : ∀{ℓ₁ ℓ₂}{A : Set ℓ₁}{B : Set ℓ₂} → 𝕃 A → 𝕃 B → 𝕃 (A × B) zip [] [] = [] zip [] (x :: l₂) = [] zip (x :: l₁) [] = [] zip (x :: l₁) (y :: l₂) = (x , y) :: zip l₁ l₂ unzip : ∀{ℓ₁ ℓ₂}{A : Set ℓ₁}{B : Set ℓ₂} → 𝕃 (A × B) → (𝕃 A × 𝕃 B) unzip [] = ([] , []) unzip ((x , y) :: ps) with unzip ps ... | (xs , ys) = x :: xs , y :: ys map-⊎ : {ℓ₁ ℓ₂ ℓ₃ : Level} → {A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃} → (A → C) → (B → C) → 𝕃 (A ⊎ B) → 𝕃 C map-⊎ f g [] = [] map-⊎ f g (inj₁ x :: l) = f x :: map-⊎ f g l map-⊎ f g (inj₂ y :: l) = g y :: map-⊎ f g l proj-⊎₁ : {ℓ ℓ' : Level}{A : Set ℓ}{B : Set ℓ'} → 𝕃 (A ⊎ B) → (𝕃 A) proj-⊎₁ [] = [] proj-⊎₁ (inj₁ x :: l) = x :: proj-⊎₁ l proj-⊎₁ (inj₂ y :: l) = proj-⊎₁ l proj-⊎₂ : {ℓ ℓ' : Level}{A : Set ℓ}{B : Set ℓ'} → 𝕃 (A ⊎ B) → (𝕃 B) proj-⊎₂ [] = [] proj-⊎₂ (inj₁ x :: l) = proj-⊎₂ l proj-⊎₂ (inj₂ y :: l) = y :: proj-⊎₂ l drop-nothing : ∀{ℓ}{A : Set ℓ} → 𝕃 (maybe A) → 𝕃 A drop-nothing [] = [] drop-nothing (nothing :: aa) = drop-nothing aa drop-nothing (just a :: aa) = a :: drop-nothing aa
29.328638
103
0.463262
1963a36f916ffad8db10dd62740155796e67deee
1,882
agda
Agda
SOAS/Families/Linear.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
SOAS/Families/Linear.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
SOAS/Families/Linear.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Linear monoidal closed structure for families module SOAS.Families.Linear {T : Set} where open import SOAS.Common open import SOAS.Context {T} open import SOAS.Sorting {T} open import SOAS.Families.Core {T} open import SOAS.Families.Isomorphism {T} open import Categories.Category.Monoidal open import Categories.Category.Monoidal.Closed open import Categories.Functor.Bifunctor -- | Monoidal tensor and unit -- Linear tensor product that combines two families with two disjoint contexts data _⊗_ (X Y : Family) : Ctx → Set where merge : (Γ Δ : Ctx) → X Γ → Y Δ → (X ⊗ Y) (Δ ∔ Γ) infixr 20 _⊗_ pattern _⊹_ {Γ}{Δ} t s = merge Γ Δ t s infix 30 _⊹_ -- ⊗ is a bifunctor ⊗F : Bifunctor 𝔽amilies 𝔽amilies 𝔽amilies ⊗F = record { F₀ = λ (X , Y) → X ⊗ Y ; F₁ = λ{ {X , Y}{X′ , Y′} (f , g) (x ⊹ y) → (f x) ⊹ (g y)} ; identity = λ{ {X , Y}{Γ}{x ⊹ y} → refl } ; homomorphism = λ{ {X , Y}{X′ , Y′}{X″ , Y″}{f , g}{f′ , g′}{Γ}{x ⊹ y} → refl } ; F-resp-≈ = λ{ (p₁ , p₂) {.(Δ ∔ Γ)} {merge Γ Δ t s} → cong₂ (merge Γ Δ) p₁ p₂ } } _⊗̣_ : Familyₛ → Familyₛ → Familyₛ _⊗̣_ = sorted₂ _⊗_ 𝒚 : Ctx → Family 𝒚 Γ Δ = Γ ≡ Δ -- Family which is only inhabited at the empty context E : Family E = 𝒚 ∅ -- Sorted family which is only inhabited at a singleton context N : Familyₛ N α = 𝒚 ⌈ α ⌋ -- | Monoidal exponential -- Linear exponential between families _⊸_ : Family → Family → Family (X ⊸ Y) Γ = {Δ : Ctx} → X Δ → Y (Δ ∔ Γ) infixr 15 _⊸_ -- Linear exponential between sorted families _⊸∙_ : Familyₛ → Familyₛ → Familyₛ _⊸∙_ = sorted₂ _⊸_ infixr 15 _⊸∙_ -- ⊸ is a bifunctor ⊸F : Bifunctor 𝔽am.op 𝔽amilies 𝔽amilies ⊸F = record { F₀ = λ (X , Y) → X ⊸ Y ; F₁ = λ{ {X , Y}{X′ , Y′} (f , g) e x → g (e (f x))} ; identity = refl ; homomorphism = refl ; F-resp-≈ = λ{ {X , Y}{X′ , Y′}{f , g} (p₁ , p₂) {Γ}{e} → dext′ (trans (cong (g ∘ e) p₁) p₂) } }
26.138889
82
0.594049
387dd55b5b46723697f5ef166c9f7f649b577c1c
6,856
agda
Agda
Cubical/Algebra/Polynomials/Multivariate/Equiv/Comp-Poly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/Polynomials/Multivariate/Equiv/Comp-Poly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Algebra/Polynomials/Multivariate/Equiv/Comp-Poly.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.Polynomials.Multivariate.Equiv.Comp-Poly where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_) open import Cubical.Data.Vec open import Cubical.Data.Sigma open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.Polynomials.Univariate.Base open import Cubical.Algebra.Polynomials.Multivariate.Base open import Cubical.Algebra.Polynomials.Multivariate.Properties open import Cubical.Algebra.CommRing.Instances.MultivariatePoly private variable ℓ ℓ' : Level module Comp-Poly-nm (A' : CommRing ℓ) (n m : ℕ) where private A = fst A' open CommRingStr (snd A') module Mr = Nth-Poly-structure A' m module N+Mr = Nth-Poly-structure A' (n +n m) module N∘Mr = Nth-Poly-structure (PolyCommRing A' m) n ----------------------------------------------------------------------------- -- direct sens N∘M→N+M-b : (v : Vec ℕ n) → Poly A' m → Poly A' (n +n m) N∘M→N+M-b v = Poly-Rec-Set.f A' m (Poly A' (n +n m)) trunc 0P (λ v' a → base (v ++ v') a) _Poly+_ Poly+-assoc Poly+-Rid Poly+-comm (λ v' → base-0P (v ++ v')) (λ v' a b → base-Poly+ (v ++ v') a b) N∘M→N+M : Poly (PolyCommRing A' m) n → Poly A' (n +n m) N∘M→N+M = Poly-Rec-Set.f (PolyCommRing A' m) n (Poly A' (n +n m)) trunc 0P N∘M→N+M-b _Poly+_ Poly+-assoc Poly+-Rid Poly+-comm (λ _ → refl) (λ v a b → refl) -- ----------------------------------------------------------------------------- -- -- Converse sens N+M→N∘M : Poly A' (n +n m) → Poly (PolyCommRing A' m) n N+M→N∘M = Poly-Rec-Set.f A' (n +n m) (Poly (PolyCommRing A' m) n) trunc 0P (λ v a → let v , v' = sep-vec n m v in base v (base v' a)) _Poly+_ Poly+-assoc Poly+-Rid Poly+-comm (λ v → (cong (base (fst (sep-vec n m v))) (base-0P (snd (sep-vec n m v)))) ∙ (base-0P (fst (sep-vec n m v)))) λ v a b → base-Poly+ (fst (sep-vec n m v)) (base (snd (sep-vec n m v)) a) (base (snd (sep-vec n m v)) b) ∙ cong (base (fst (sep-vec n m v))) (base-Poly+ (snd (sep-vec n m v)) a b) ----------------------------------------------------------------------------- -- Section e-sect : (P : Poly A' (n +n m)) → N∘M→N+M (N+M→N∘M P) ≡ P e-sect = Poly-Ind-Prop.f A' (n +n m) (λ P → N∘M→N+M (N+M→N∘M P) ≡ P) (λ _ → trunc _ _) refl (λ v a → cong (λ X → base X a) (sep-vec-id n m v)) (λ {U V} ind-U ind-V → cong₂ _Poly+_ ind-U ind-V) ----------------------------------------------------------------------------- -- Retraction e-retr : (P : Poly (PolyCommRing A' m) n) → N+M→N∘M (N∘M→N+M P) ≡ P e-retr = Poly-Ind-Prop.f (PolyCommRing A' m) n (λ P → N+M→N∘M (N∘M→N+M P) ≡ P) (λ _ → trunc _ _) refl (λ v → Poly-Ind-Prop.f A' m (λ P → N+M→N∘M (N∘M→N+M (base v P)) ≡ base v P) (λ _ → trunc _ _) (sym (base-0P v)) (λ v' a → cong₂ base (sep-vec-fst n m v v') (cong (λ X → base X a) (sep-vec-snd n m v v'))) (λ {U V} ind-U ind-V → (cong₂ _Poly+_ ind-U ind-V) ∙ (base-Poly+ v U V))) (λ {U V} ind-U ind-V → cong₂ _Poly+_ ind-U ind-V ) ----------------------------------------------------------------------------- -- Morphism of ring map-0P : N∘M→N+M (0P) ≡ 0P map-0P = refl N∘M→N+M-gmorph : (P Q : Poly (PolyCommRing A' m) n) → N∘M→N+M ( P Poly+ Q) ≡ N∘M→N+M P Poly+ N∘M→N+M Q N∘M→N+M-gmorph = λ P Q → refl map-1P : N∘M→N+M (N∘Mr.1P) ≡ N+Mr.1P map-1P = cong (λ X → base X 1r) (rep-concat n m 0 ) N∘M→N+M-rmorph : (P Q : Poly (PolyCommRing A' m) n) → N∘M→N+M ( P N∘Mr.Poly* Q) ≡ N∘M→N+M P N+Mr.Poly* N∘M→N+M Q N∘M→N+M-rmorph = -- Ind P Poly-Ind-Prop.f (PolyCommRing A' m) n (λ P → (Q : Poly (PolyCommRing A' m) n) → N∘M→N+M (P N∘Mr.Poly* Q) ≡ (N∘M→N+M P N+Mr.Poly* N∘M→N+M Q)) (λ P p q i Q j → trunc _ _ (p Q) (q Q) i j) (λ Q → refl) (λ v → -- Ind Base P Poly-Ind-Prop.f A' m (λ P → (Q : Poly (PolyCommRing A' m) n) → N∘M→N+M (base v P N∘Mr.Poly* Q) ≡ (N∘M→N+M (base v P) N+Mr.Poly* N∘M→N+M Q)) (λ P p q i Q j → trunc _ _ (p Q) (q Q) i j) (λ Q → cong (λ X → N∘M→N+M (X N∘Mr.Poly* Q)) (base-0P v)) (λ v' a → -- Ind Q Poly-Ind-Prop.f (PolyCommRing A' m) n (λ Q → N∘M→N+M (base v (base v' a) N∘Mr.Poly* Q) ≡ (N∘M→N+M (base v (base v' a)) N+Mr.Poly* N∘M→N+M Q)) (λ _ → trunc _ _) (sym (N+Mr.0PRightAnnihilatesPoly (N∘M→N+M (base v (base v' a))))) (λ w → -- Ind base Q Poly-Ind-Prop.f A' m _ (λ _ → trunc _ _) (sym (N+Mr.0PRightAnnihilatesPoly (N∘M→N+M (base v (base v' a))))) (λ w' b → cong (λ X → base X (a · b)) (+n-vec-concat n m v w v' w')) λ {U V} ind-U ind-V → cong (λ X → N∘M→N+M (base v (base v' a) N∘Mr.Poly* X)) (sym (base-Poly+ w U V)) ∙ cong₂ (_Poly+_ ) ind-U ind-V ∙ sym (cong (λ X → N∘M→N+M (base v (base v' a)) N+Mr.Poly* N∘M→N+M X) (base-Poly+ w U V)) ) -- End Ind base Q λ {U V} ind-U ind-V → cong₂ _Poly+_ ind-U ind-V) -- End Ind Q λ {U V} ind-U ind-V Q → cong (λ X → N∘M→N+M (X N∘Mr.Poly* Q)) (sym (base-Poly+ v U V)) ∙ cong₂ _Poly+_ (ind-U Q) (ind-V Q) ∙ sym (cong (λ X → (N∘M→N+M X) N+Mr.Poly* (N∘M→N+M Q)) (sym (base-Poly+ v U V)) )) -- End Ind base P λ {U V} ind-U ind-V Q → cong₂ _Poly+_ (ind-U Q) (ind-V Q) -- End Ind P ----------------------------------------------------------------------------- -- Ring Equivalence module _ (A' : CommRing ℓ) (n m : ℕ) where open Comp-Poly-nm A' n m CRE-PolyN∘M-PolyN+M : CommRingEquiv (PolyCommRing (PolyCommRing A' m) n) (PolyCommRing A' (n +n m)) fst CRE-PolyN∘M-PolyN+M = isoToEquiv is where is : Iso _ _ Iso.fun is = N∘M→N+M Iso.inv is = N+M→N∘M Iso.rightInv is = e-sect Iso.leftInv is = e-retr snd CRE-PolyN∘M-PolyN+M = makeIsRingHom map-1P N∘M→N+M-gmorph N∘M→N+M-rmorph
40.093567
144
0.442386
59b2b1141b2fd7eae19feadaa5a058eb0463b101
5,419
agda
Agda
examples/outdated-and-incorrect/iird/IIRD.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
examples/outdated-and-incorrect/iird/IIRD.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/iird/IIRD.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module IIRD where open import LF -- A code for an IIRD (captures both general and restricted IIRDs) -- I - index set -- D - return type of the recursive component -- E - generalised return type of the recursive component (including the index) -- for restricted IIRD E = D i for an external i -- and for general IIRD E = (i : I) × D i -- The intuition is that restricted IIRD are parameterised over the index, -- whereas general IIRD compute their indices. data OP (I : Set)(D : I -> Set1)(E : Set1) : Set1 where -- Nullary constructor, contains the result of the recursive component ι : E -> OP I D E -- Non-recursive argument A, following arguments may depend on this argument. -- To code multi-constructor datatypes, the first argument is the name of the -- constructor and γ does the appropriate case-split on the name. σ : (A : Set)(γ : A -> OP I D E) -> OP I D E -- Recursive argument -- A - assumptions, for instance lim : (Nat -> Ord) -> Ord, where A = Nat -- i - the index of the inductive occurrence -- γ - the rest of the arguments, may depend on the result of calling the -- recursive function on the inductive argument δ : (A : Set)(i : A -> I)(γ : ((a : A) -> D (i a)) -> OP I D E) -> OP I D E -- Helper function. The definition is simple, but the type is not. _«_×_» : {A B : Set}{C : B -> Set}{D : B -> Set1} (f : (b : B) -> C b -> D b) (g : A -> B)(h : (a : A) -> C (g a)) -> (a : A) -> D (g a) f « g × h » = \a -> f (g a) (h a) -- The type of constructor arguments. Parameterised over -- U - the inductive type -- T - the recursive function -- This is the F of the simple polynomial type μF Ku : {I : Set}{D : I -> Set1}{E : Set1} -> OP I D E -> (U : I -> Set)(T : (i : I) -> U i -> D i) -> Set Ku (ι e) U T = One Ku (σ A γ) U T = A × \a -> Ku (γ a) U T Ku (δ A i γ) U T = ((a : A) -> U (i a)) × \g -> Ku (γ (T « i × g »)) U T -- The recursive function. As with Ku this is only the top-level structure. -- To get the real function there is a recursive knot to be tied. Kt : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> Ku γ U T -> E Kt (ι e) U T ★ = e Kt (σ A γ) U T < a | b > = Kt (γ a) U T b Kt (δ A i γ) U T < g | b > = Kt (γ (T « i × g »)) U T b -- The assumptions of a particular inductive occurrence in a value. KIArg : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> Ku γ U T -> Set KIArg (ι e) U T ★ = Zero KIArg (σ A γ) U T < a | b > = KIArg (γ a) U T b KIArg (δ A i γ) U T < g | b > = A + KIArg (γ (T « i × g »)) U T b -- Given the assumptions of an inductive occurence in a value we can compute -- its index. KIArg→I : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> (a : Ku γ U T) -> KIArg γ U T a -> I KIArg→I (ι e) U T ★ () KIArg→I (σ A γ) U T < a | b > c = KIArg→I (γ a) U T b c KIArg→I (δ A i γ) U T < g | b > (inl a) = i a KIArg→I (δ A i γ) U T < g | b > (inr a) = KIArg→I (γ (T « i × g »)) U T b a -- Given the assumptions of an inductive occurrence in a value we can compute -- its value. KIArg→U : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> (a : Ku γ U T)(v : KIArg γ U T a) -> U (KIArg→I γ U T a v) KIArg→U (ι e) U T ★ () KIArg→U (σ A γ) U T < a | b > c = KIArg→U (γ a) U T b c KIArg→U (δ A i γ) U T < g | b > (inl a) = g a KIArg→U (δ A i γ) U T < g | b > (inr a) = KIArg→U (γ (T « i × g »)) U T b a -- The type of induction hypotheses. Basically -- forall assumptions, the predicate holds for an inductive occurrence with -- those assumptions KIH : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> (F : (i : I) -> U i -> Set1)(a : Ku γ U T) -> Set1 KIH γ U T F a = (v : KIArg γ U T a) -> F (KIArg→I γ U T a v) (KIArg→U γ U T a v) -- If we can prove a predicate F for any values, we can construct the inductive -- hypotheses for a given value. -- Termination note: g will only be applied to values smaller than a Kmap : {I : Set}{D : I -> Set1}{E : Set1} (γ : OP I D E)(U : I -> Set)(T : (i : I) -> U i -> D i) -> (F : (i : I) -> U i -> Set1) (g : (i : I)(u : U i) -> F i u) (a : Ku γ U T) -> KIH γ U T F a Kmap γ U T F g a = \v -> g (KIArg→I γ U T a v) (KIArg→U γ U T a v) -- Things needed for general IIRD OPg : (I : Set)(D : I -> Set1) -> Set1 OPg I D = OP I D (I ×' D) Gu : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) -> Set Gu γ U T = Ku γ U T Gi : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (a : Gu γ U T) -> I Gi γ U T a = π₀' (Kt γ U T a) Gt : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (a : Gu γ U T) -> D (Gi γ U T a) Gt γ U T a = π₁' (Kt γ U T a) -- Things needed for restricted IIRD OPr : (I : Set)(D : I -> Set1) -> Set1 OPr I D = (i : I) -> OP I D (D i) Hu : {I : Set}{D : I -> Set1} (γ : OPr I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I) -> Set Hu γ U T i = Ku (γ i) U T Ht : {I : Set}{D : I -> Set1} (γ : OPr I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(a : Hu γ U T i) -> D i Ht γ U T i a = Kt (γ i) U T a
40.440299
90
0.505997
a02940c02320ae6d607341b17ebc7e1664851aba
1,884
agda
Agda
Cubical/Data/FinSet/FiniteChoice.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Data/FinSet/FiniteChoice.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Data/FinSet/FiniteChoice.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- Axiom of Finite Choice - Yep, it's a theorem actually. -} {-# OPTIONS --safe #-} module Cubical.Data.FinSet.FiniteChoice where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_) open import Cubical.HITs.PropositionalTruncation as Prop open import Cubical.Data.Nat open import Cubical.Data.Unit open import Cubical.Data.Empty open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Data.SumFin open import Cubical.Data.FinSet.Base open import Cubical.Data.FinSet.Properties private variable ℓ ℓ' : Level choice≃Fin : {n : ℕ}(Y : Fin n → Type ℓ) → ((x : Fin n) → ∥ Y x ∥₁) ≃ ∥ ((x : Fin n) → Y x) ∥₁ choice≃Fin {n = 0} Y = isContr→≃Unit (isContrΠ⊥) ⋆ Unit≃Unit* ⋆ invEquiv (propTruncIdempotent≃ isPropUnit*) ⋆ propTrunc≃ (invEquiv (isContr→≃Unit* (isContrΠ⊥ {A = Y}))) choice≃Fin {n = suc n} Y = Π⊎≃ ⋆ Σ-cong-equiv-fst (ΠUnit (λ x → ∥ Y (inl x) ∥₁)) ⋆ Σ-cong-equiv-snd (λ _ → choice≃Fin {n = n} (λ x → Y (inr x))) ⋆ Σ-cong-equiv-fst (propTrunc≃ (invEquiv (ΠUnit (λ x → Y (inl x))))) ⋆ ∥∥-×-≃ ⋆ propTrunc≃ (invEquiv (Π⊎≃ {E = Y})) module _ (X : Type ℓ)(p : isFinOrd X) (Y : X → Type ℓ') where private e = p .snd choice≃' : ((x : X) → ∥ Y x ∥₁) ≃ ∥ ((x : X) → Y x) ∥₁ choice≃' = equivΠ {B' = λ x → ∥ Y (invEq e x) ∥₁} e (transpFamily p) ⋆ choice≃Fin _ ⋆ propTrunc≃ (invEquiv (equivΠ {B' = λ x → Y (invEq e x)} e (transpFamily p))) module _ (X : FinSet ℓ) (Y : X .fst → Type ℓ') where choice≃ : ((x : X .fst) → ∥ Y x ∥₁) ≃ ∥ ((x : X .fst) → Y x) ∥₁ choice≃ = Prop.rec (isOfHLevel≃ 1 (isPropΠ (λ x → isPropPropTrunc)) isPropPropTrunc) (λ p → choice≃' (X .fst) (_ , p) Y) (X .snd .snd) choice : ((x : X .fst) → ∥ Y x ∥₁) → ∥ ((x : X .fst) → Y x) ∥₁ choice = choice≃ .fst
26.535211
83
0.596072
1cc3ce4f061a7fd8f8a810e2926b49111a7037a2
2,836
agda
Agda
Cubical/Codata/M/AsLimit/M/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Codata/M/AsLimit/M/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Codata/M/AsLimit/M/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --guardedness --safe #-} module Cubical.Codata.M.AsLimit.M.Properties where open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv using (_≃_) open import Cubical.Foundations.Function using (_∘_) open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Functions.Embedding open import Cubical.Codata.M.AsLimit.helper open import Cubical.Codata.M.AsLimit.M.Base open import Cubical.Codata.M.AsLimit.Container -- in-fun and out-fun are inverse open Iso in-inverse-out : ∀ {ℓ} {S : Container ℓ} → (in-fun {S = S} ∘ out-fun {S = S}) ≡ idfun (M S) in-inverse-out {S = S} = subst (λ inv → in-fun {S = S} ∘ inv ≡ idfun (M S)) idpath def where -- substituting refl makes type-checking work a lot faster, but introduces a transport -- TODO (2020-05-23): revisit this at some point to see if it's still needed in future versions of agda def : (in-fun {S = S} ∘ inv (shift-iso S)) ≡ idfun (M S) def = funExt (rightInv (shift-iso S)) idpath : inv (shift-iso S) ≡ out-fun {S = S} idpath = refl out-inverse-in : ∀ {ℓ} {S : Container ℓ} → (out-fun {S = S} ∘ in-fun {S = S}) ≡ idfun (P₀ S (M S)) out-inverse-in {S = S} = subst (λ fun → out-fun {S = S} ∘ fun ≡ idfun (P₀ S (M S))) idpath def where def : (out-fun {S = S} ∘ fun (shift-iso S)) ≡ idfun (P₀ S (M S)) def = funExt (leftInv (shift-iso S)) idpath : fun (shift-iso S) ≡ in-fun {S = S} idpath = refl in-out-id : ∀ {ℓ} {S : Container ℓ} -> ∀ {x y : M S} → (in-fun (out-fun x) ≡ in-fun (out-fun y)) ≡ (x ≡ y) in-out-id {x = x} {y} i = (in-inverse-out i x) ≡ (in-inverse-out i y) -- constructor properties in-inj : ∀ {ℓ} {S : Container ℓ} {Z : Type ℓ} → ∀ {f g : Z → P₀ S (M S)} → (in-fun ∘ f ≡ in-fun ∘ g) ≡ (f ≡ g) in-inj {ℓ} {S = S} {Z = Z} {f = f} {g = g} = iso→fun-Injection-Path {ℓ = ℓ} {A = P₀ S (M S)} {B = M S} {C = Z} (shift-iso S) {f = f} {g = g} out-inj : ∀ {ℓ} {S : Container ℓ} {Z : Type ℓ} → ∀ {f g : Z → M S} → (out-fun ∘ f ≡ out-fun ∘ g) ≡ (f ≡ g) out-inj {ℓ} {S = S} {Z = Z} {f = f} {g = g} = iso→inv-Injection-Path {ℓ = ℓ} {A = P₀ S (M S)} {B = M S} {C = Z} (shift-iso S) {f = f} {g = g} in-inj-x : ∀ {ℓ} {S : Container ℓ} → ∀ {x y : P₀ S (M S)} → (in-fun x ≡ in-fun y) ≡ (x ≡ y) in-inj-x {ℓ} {S = S} {x = x} {y} = iso→fun-Injection-Path-x (shift-iso S) {x} {y} out-inj-x : ∀ {ℓ} {S : Container ℓ} → ∀ {x y : M S} → (out-fun x ≡ out-fun y) ≡ (x ≡ y) out-inj-x {ℓ} {S = S} {x = x} {y} = iso→inv-Injection-Path-x (shift-iso S) {x} {y}
45.741935
141
0.607898
04fae8237fdf64d45838c89ebeaacaba30948b04
687
agda
Agda
test/Common/String.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Common/String.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Common/String.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible #-} module Common.String where open import Agda.Builtin.String public open import Common.Bool open import Common.Char open import Common.List open import Common.Nat open import Common.Integer strEq : (x y : String) -> Bool strEq = primStringEquality infixr 30 _+S+_ _+S+_ : (x y : String) -> String _+S+_ = primStringAppend fromList : List Char -> String fromList = primStringFromList stringToList : String -> List Char stringToList = primStringToList charToStr : Char → String charToStr c = primStringFromList (c ∷ []) intToString : Integer → String intToString = primShowInteger natToString : Nat -> String natToString n = intToString (pos n)
20.818182
41
0.751092
0335351996fb313017d0013157f90455a4e20326
657
agda
Agda
agda/io/placeholder.agda
piyush-kurur/hott
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
[ "BSD-3-Clause" ]
null
null
null
agda/io/placeholder.agda
piyush-kurur/hott
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
[ "BSD-3-Clause" ]
null
null
null
agda/io/placeholder.agda
piyush-kurur/hott
876ecdcfddca1abf499e8f00db321c6dc3d5b2bc
[ "BSD-3-Clause" ]
null
null
null
-- A placeholder module so that we can write a main. Agda compilation -- does not work without a main so batch compilation is bound to give -- errors. For travis builds, we want batch compilation and this is -- module can be imported to serve that purpose. There is nothing -- useful that can be achieved from this module though. module io.placeholder where open import hott.core.universe postulate Unit : Type₀ IO : Type₀ → Type₀ dummyMain : IO Unit {-# COMPILED_TYPE Unit () #-} {-# COMPILED_TYPE IO IO #-} {-# COMPILED dummyMain (return ()) #-} {-# BUILTIN IO IO #-}
32.85
69
0.634703
389c5d9288523a6f6e9c8a244ad54f8b6d6ce5be
13,894
agda
Agda
Cubical/HITs/Hopf.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/HITs/Hopf.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
Cubical/HITs/Hopf.agda
Rotsor/cubical
d55cd4834ca1f171f58b4a0c46b804ea6d18191f
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Hopf where open import Cubical.Core.Glue open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Data.Int open import Cubical.Data.Prod open import Cubical.HITs.S1 open import Cubical.HITs.S2 open import Cubical.HITs.S3 open import Cubical.HITs.Susp open import Cubical.HITs.Join open import Cubical.HITs.Interval renaming ( zero to I0 ; one to I1 ) Border : (x : S¹) → (j : I) → Partial (j ∨ ~ j) (Σ Type₀ (λ T → T ≃ S¹)) Border x j (j = i0) = S¹ , rot x , rotIsEquiv x Border x j (j = i1) = S¹ , idEquiv S¹ -- Hopf fibration using SuspS¹ HopfSuspS¹ : SuspS¹ → Type₀ HopfSuspS¹ north = S¹ HopfSuspS¹ south = S¹ HopfSuspS¹ (merid x j) = Glue S¹ (Border x j) -- Hopf fibration using S² -- TODO : prove that it is equivalent to HopfSuspS¹ HopfS² : S² → Type₀ HopfS² base = S¹ HopfS² (surf i j) = Glue S¹ (λ { (i = i0) → _ , idEquiv S¹ ; (i = i1) → _ , idEquiv S¹ ; (j = i0) → _ , idEquiv S¹ ; (j = i1) → _ , _ , rotIsEquiv (loop i) } ) -- Hopf fibration using more direct definition of the rot equivalence -- TODO : prove that it is equivalent to HopfSuspS¹ HopfS²' : S² → Type₀ HopfS²' base = S¹ HopfS²' (surf i j) = Glue S¹ (λ { (i = i0) → _ , rotLoopEquiv i0 ; (i = i1) → _ , rotLoopEquiv i0 ; (j = i0) → _ , rotLoopEquiv i0 ; (j = i1) → _ , rotLoopEquiv i } ) -- Total space of the fibration TotalHopf : Type₀ TotalHopf = Σ SuspS¹ HopfSuspS¹ -- Forward direction filler-1 : I → (j : I) → (y : S¹) → Glue S¹ (Border y j) → join S¹ S¹ filler-1 i j y x = hfill (λ t → λ { (j = i0) → inl (rotInv-1 x y t) ; (j = i1) → inr x }) (inS (push ((unglue (j ∨ ~ j) x) * inv y) (unglue (j ∨ ~ j) x) j)) i TotalHopf→JoinS¹S¹ : TotalHopf → join S¹ S¹ TotalHopf→JoinS¹S¹ (north , x) = inl x TotalHopf→JoinS¹S¹ (south , x) = inr x TotalHopf→JoinS¹S¹ (merid y j , x) = filler-1 i1 j y x -- Backward direction JoinS¹S¹→TotalHopf : join S¹ S¹ → TotalHopf JoinS¹S¹→TotalHopf (inl x) = (north , x) JoinS¹S¹→TotalHopf (inr x) = (south , x) JoinS¹S¹→TotalHopf (push y x j) = (merid (inv y * x) j , glue (λ { (j = i0) → y ; (j = i1) → x }) (rotInv-2 x y j)) -- Now for the homotopies, we will need to fill squares indexed by x y : S¹ with value in S¹ -- Some will be extremeley tough, but happen to be easy when x = y = base -- therefore, we fill them for x = y = base and then use the connectedness of S¹ × S¹ and -- the discreteness of ΩS¹ to get general fillers. -- To proceed with that strategy, we first need a lemma : -- the sections of the trivial fibration λ (_ : S¹) (_ : S¹) → Int are constant -- this should be generalized to a constant fibration over a connected space with -- discrete fiber fibInt : S¹ → S¹ → Type₀ fibInt _ _ = Int S¹→HSet : (A : Type₀) (p : isSet A) (F : S¹ → A) (x : S¹) → F base ≡ F x S¹→HSet A p F base = refl {x = F base} S¹→HSet A p F (loop i) = f' i where f : PathP (λ i → F base ≡ F (loop i)) refl (cong F loop) f i = λ j → F (loop (i ∧ j)) L : cong F loop ≡ refl L = p (F base) (F base) (f i1) refl f' : PathP (λ i → F base ≡ F (loop i)) (refl {x = F base}) (refl {x = F base}) f' = transport (λ i → PathP (λ j → F base ≡ F (loop j)) refl (L i)) f constant-loop : (F : S¹ → S¹ → Int) → (x y : S¹) → F base base ≡ F x y constant-loop F x y = L0 ∙ L1 where p : isSet (S¹ → Int) p = hLevelPi 2 (λ _ → isSetInt) L : F base ≡ F x L = S¹→HSet (S¹ → Int) p F x L0 : F base base ≡ F x base L0 i = L i base L1 : F x base ≡ F x y L1 = S¹→HSet Int isSetInt (F x) y discretefib : (F : S¹ → S¹ → Type₀) → Type₀ discretefib F = (a : (x y : S¹) → F x y) → (b : (x y : S¹) → F x y) → (a base base ≡ b base base) → (x y : S¹) → a x y ≡ b x y discretefib-fibInt : discretefib fibInt discretefib-fibInt a b h x y i = hcomp (λ t → λ { (i = i0) → constant-loop a x y t ; (i = i1) → constant-loop b x y t }) (h i) -- first homotopy assocFiller-3-aux : I → I → I → I → S¹ assocFiller-3-aux x y j i = hfill (λ t → λ { (i = i0) → rotInv-1 (loop y) (loop (~ y) * loop x) t ; (i = i1) → rotInv-3 (loop y) (loop x) t ; (x = i0) (y = i0) → base ; (x = i0) (y = i1) → base ; (x = i1) (y = i0) → base ; (x = i1) (y = i1) → base }) (inS ((rotInv-2 (loop x) (loop y) i) * (inv (loop (~ y) * loop x)))) j -- assocFiller-3-endpoint is used only in the type of the next function, to specify the -- second endpoint. -- However, I only need the first endpoint, but I cannot specify only one of them as is. -- TODO : use cubical extension types when available to remove assocFiller-3-endpoint assocFiller-3-endpoint : (x : S¹) → (y : S¹) → y ≡ y assocFiller-3-endpoint base base i = base assocFiller-3-endpoint (loop x) base i = assocFiller-3-aux x i0 i1 i assocFiller-3-endpoint base (loop y) i = assocFiller-3-aux i0 y i1 i assocFiller-3-endpoint (loop x) (loop y) i = assocFiller-3-aux x y i1 i assocFiller-3 : (x : S¹) → (y : S¹) → PathP (λ j → rotInv-1 y (inv y * x) j ≡ rotInv-3 y x j) (λ i → ((rotInv-2 x y i) * (inv (inv y * x)))) (assocFiller-3-endpoint x y) assocFiller-3 base base j i = base assocFiller-3 (loop x) base j i = assocFiller-3-aux x i0 j i assocFiller-3 base (loop y) j i = assocFiller-3-aux i0 y j i assocFiller-3 (loop x) (loop y) j i = assocFiller-3-aux x y j i assoc-3 : (_ y : S¹) → basedΩS¹ y assoc-3 x y i = assocFiller-3 x y i1 i fibInt≡fibAssoc-3 : fibInt ≡ (λ _ y → basedΩS¹ y) fibInt≡fibAssoc-3 i = λ x y → basedΩS¹≡Int y (~ i) discretefib-fibAssoc-3 : discretefib (λ _ y → basedΩS¹ y) discretefib-fibAssoc-3 = transp (λ i → discretefib (fibInt≡fibAssoc-3 i)) i0 discretefib-fibInt assocConst-3 : (x y : S¹) → assoc-3 x y ≡ refl assocConst-3 x y = discretefib-fibAssoc-3 assoc-3 (λ _ _ → refl) refl x y assocSquare-3 : I → I → S¹ → S¹ → S¹ assocSquare-3 i j x y = hcomp (λ t → λ { (i = i0) → assocFiller-3 x y j i0 ; (i = i1) → assocFiller-3 x y j i1 ; (j = i0) → assocFiller-3 x y i0 i ; (j = i1) → assocConst-3 x y t i }) (assocFiller-3 x y j i) filler-3 : I → I → S¹ → S¹ → join S¹ S¹ filler-3 i j y x = hcomp (λ t → λ { (i = i0) → filler-1 t j (inv y * x) (glue (λ { (j = i0) → y ; (j = i1) → x }) (rotInv-2 x y j)) ; (i = i1) → push (rotInv-3 y x t) x j ; (j = i0) → inl (assocSquare-3 i t x y) ; (j = i1) → inr x }) (push ((rotInv-2 x y (i ∨ j)) * (inv (inv y * x))) (rotInv-2 x y (i ∨ j)) j) JoinS¹S¹→TotalHopf→JoinS¹S¹ : ∀ x → TotalHopf→JoinS¹S¹ (JoinS¹S¹→TotalHopf x) ≡ x JoinS¹S¹→TotalHopf→JoinS¹S¹ (inl x) i = inl x JoinS¹S¹→TotalHopf→JoinS¹S¹ (inr x) i = inr x JoinS¹S¹→TotalHopf→JoinS¹S¹ (push y x j) i = filler-3 i j y x -- Second homotopy -- This HIT is the total space of the Hopf fibration but the ends of SuspS¹ have not been -- glued together yet — which makes it into a cylinder. -- This allows to write compositions that do not properly match at the endpoints. However, -- I suspect it is unnecessary. TODO : do without PseudoHopf PseudoHopf : Type₀ PseudoHopf = (S¹ × Interval) × S¹ PseudoHopf-π1 : PseudoHopf → S¹ PseudoHopf-π1 ((y , _) , _) = y PseudoHopf-π2 : PseudoHopf → S¹ PseudoHopf-π2 (_ , x) = x assocFiller-4-aux : I → I → I → I → S¹ assocFiller-4-aux x y j i = hfill (λ t → λ { (i = i0) → ((inv (loop y * loop x * loop (~ y))) * (loop y * loop x)) * (rotInv-1 (loop x) (loop y) t) ; (i = i1) → (rotInv-4 (loop y) (loop y * loop x) (~ t)) * loop x ; (x = i0) (y = i0) → base ; (x = i0) (y = i1) → base ; (x = i1) (y = i0) → base ; (x = i1) (y = i1) → base }) (inS (rotInv-2 (loop y * loop x) (loop y * loop x * loop (~ y)) i)) j -- See assocFiller-3-endpoint -- TODO : use cubical extension types when available to remove assocFiller-4-endpoint assocFiller-4-endpoint : (x y : S¹) → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x) assocFiller-4-endpoint base base i = base assocFiller-4-endpoint (loop x) base i = assocFiller-4-aux x i0 i1 i assocFiller-4-endpoint base (loop y) i = assocFiller-4-aux i0 y i1 i assocFiller-4-endpoint (loop x) (loop y) i = assocFiller-4-aux x y i1 i assocFiller-4 : (x y : S¹) → PathP (λ j → ((inv (y * x * inv y)) * (y * x)) * (rotInv-1 x y j) ≡ (rotInv-4 y (y * x) (~ j)) * x) (λ i → (rotInv-2 (y * x) (y * x * inv y) i)) (assocFiller-4-endpoint x y) assocFiller-4 base base j i = base assocFiller-4 (loop x) base j i = assocFiller-4-aux x i0 j i assocFiller-4 base (loop y) j i = assocFiller-4-aux i0 y j i assocFiller-4 (loop x) (loop y) j i = assocFiller-4-aux x y j i assoc-4 : (x y : S¹) → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x) assoc-4 x y i = assocFiller-4 x y i1 i fibInt≡fibAssoc-4 : fibInt ≡ (λ x y → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x)) fibInt≡fibAssoc-4 i = λ x y → basedΩS¹≡Int (((inv (y * x * inv y)) * (y * x)) * x) (~ i) discretefib-fibAssoc-4 : discretefib (λ x y → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x)) discretefib-fibAssoc-4 = transp (λ i → discretefib (fibInt≡fibAssoc-4 i)) i0 discretefib-fibInt assocConst-4 : (x y : S¹) → assoc-4 x y ≡ refl assocConst-4 x y = discretefib-fibAssoc-4 assoc-4 (λ _ _ → refl) refl x y assocSquare-4 : I → I → S¹ → S¹ → S¹ assocSquare-4 i j x y = hcomp (λ t → λ { (i = i0) → assocFiller-4 x y j i0 ; (i = i1) → assocFiller-4 x y j i1 ; (j = i0) → assocFiller-4 x y i0 i ; (j = i1) → assocConst-4 x y t i }) (assocFiller-4 x y j i) filler-4-0 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf filler-4-0 i j y x = let x' = unglue (j ∨ ~ j) x in hfill (λ t → λ { (j = i0) → ((inv (y * x * inv y) * (y * x) , I0) , inv (y * x * inv y) * (y * x) * (rotInv-1 x y t)) ; (j = i1) → ((inv (x * inv y) * x , I1) , x) }) (inS ((inv (x' * inv y) * x' , seg j) , rotInv-2 x' (x' * inv y) j)) i filler-4-1 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf filler-4-1 i j y x = let x' = unglue (j ∨ ~ j) x in hfill (λ t → λ { (j = i0) → ((inv (y * x * inv y) * (y * x) , I0) , (rotInv-4 y (y * x) (~ t)) * x) ; (j = i1) → ((inv (x * inv y) * x , I1) , x) }) (inS ((inv (x' * inv y) * x' , seg j) , unglue (j ∨ ~ j) x)) i filler-4-2 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → TotalHopf filler-4-2 i j y x = let x' = unglue (j ∨ ~ j) x in hcomp (λ t → λ { (i = i0) → JoinS¹S¹→TotalHopf (filler-1 t j y x) ; (i = i1) → (merid (PseudoHopf-π1 (filler-4-0 t j y x)) j , glue (λ { (j = i0) → rotInv-1 x y t ; (j = i1) → x }) (PseudoHopf-π2 (filler-4-0 t j y x))) ; (j = i0) → (north , rotInv-1 x y t) ; (j = i1) → (south , x) }) (merid (inv (x' * inv y) * x') j , glue (λ { (j = i0) → y * x * inv y ; (j = i1) → x }) (rotInv-2 x' (x' * inv y) j)) filler-4-3 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf filler-4-3 i j y x = let x' = unglue (j ∨ ~ j) x in hcomp (λ t → λ { (i = i0) → filler-4-0 t j y x ; (i = i1) → filler-4-1 t j y x ; (j = i0) → ((inv (y * x * inv y) * (y * x) , I0) , assocSquare-4 i t x y) ; (j = i1) → ((inv (x * inv y) * x , I1) , x) }) ((inv (x' * inv y) * x' , seg j) , rotInv-2 x' (x' * inv y) (i ∨ j)) filler-4-4 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf filler-4-4 i j y x = let x' = unglue (j ∨ ~ j) x in hcomp (λ t → λ { (i = i0) → filler-4-1 t j y x ; (i = i1) → ((y , seg j) , unglue (j ∨ ~ j) x) ; (j = i0) → ((rotInv-4 y (y * x) i , I0) , (rotInv-4 y (y * x) (i ∨ ~ t)) * x) ; (j = i1) → ((rotInv-4 y x i , I1) , x) }) ((rotInv-4 y x' i , seg j) , x') filler-4-5 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → TotalHopf filler-4-5 i j y x = hcomp (λ t → λ { (i = i0) → filler-4-2 (~ t) j y x ; (i = i1) → (merid (PseudoHopf-π1 (filler-4-4 t j y x)) j , glue (λ { (j = i0) → x ; (j = i1) → x }) (PseudoHopf-π2 (filler-4-4 t j y x))) ; (j = i0) → (north , x) ; (j = i1) → (south , x) }) (merid (PseudoHopf-π1 (filler-4-3 i j y x)) j , glue (λ { (j = i0) → x ; (j = i1) → x }) (PseudoHopf-π2 (filler-4-3 i j y x))) TotalHopf→JoinS¹S¹→TotalHopf : ∀ x → JoinS¹S¹→TotalHopf (TotalHopf→JoinS¹S¹ x) ≡ x TotalHopf→JoinS¹S¹→TotalHopf (north , x) i = (north , x) TotalHopf→JoinS¹S¹→TotalHopf (south , x) i = (south , x) TotalHopf→JoinS¹S¹→TotalHopf (merid y j , x) i = filler-4-5 i j y x JoinS¹S¹≡TotalHopf : join S¹ S¹ ≡ TotalHopf JoinS¹S¹≡TotalHopf = isoToPath (iso JoinS¹S¹→TotalHopf TotalHopf→JoinS¹S¹ TotalHopf→JoinS¹S¹→TotalHopf JoinS¹S¹→TotalHopf→JoinS¹S¹) S³≡TotalHopf : S³ ≡ TotalHopf S³≡TotalHopf = S³≡joinS¹S¹ ∙ JoinS¹S¹≡TotalHopf
42.882716
115
0.523032
2e2df15bc99760ee9792c7cb918bf9c13f3e8098
5,629
agda
Agda
Qsort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
1
2019-08-08T12:52:30.000Z
2019-08-08T12:52:30.000Z
Qsort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
Qsort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
module Qsort where open import Sec4 -- The module with definition of propositions import Sec2 -- postulate needed for ≤ on A postulate leq : {A : Set} → A → A → Prop postulate geq : {A : Set} → A → A → Prop postulate tot-list : {A : Set} → (a b : A) → (leq a b) ∨ (leq b a) postulate trans-list : {A : Set} → (a b c : A) → (leq a b) → (leq b c) → (leq a c) {- Definition of a list -} data List (A : Set) : Set where [] : List A -- Empty list _∷_ : A → List A → List A -- Cons -- Proposition stating what is a non empty list nelist : {A : Set} → (List A) → Prop nelist [] = ⊥ nelist (x ∷ x₁) = ⊤ -- Head function that only works on non empty list head : {A : Set} → (l : List A) → (p : nelist l) → A head [] () -- This can never happen head (x ∷ _) ⋆ = x -- This is the head of the list -- The tail of the list only works on non empty list tail : {A : Set} → (l : List A) → (p : nelist l) → (List A) tail [] () tail (_ ∷ l) ⋆ = l data Bool : Set where True : Bool False : Bool data ℕ : Set where Z : ℕ S : ℕ → ℕ -- Addition of natural numbers _+_ : ℕ → ℕ → ℕ Z + y = y S x + y = S (x + y) -- Relation on natural numbers _≤_ : ℕ → ℕ → Prop Z ≤ Z = ⊤ Z ≤ (S y) = ⊤ S x ≤ Z = ⊥ S x ≤ S y = x ≤ y -- {-# BUILTIN NATURAL ℕ #-} -- {-# BUILTIN BOOL Bool #-} -- ≤ is reflexive ≤-ref : ∀ (x : ℕ) → (x ≤ x) → (x ≤ x) ≤-ref _ y = y -- ≤ is not symmetric -- ≤-sym : ∀ (x y : ℕ) → (x ≤ y) → (y ≤ x) -- ≤-sym Z Z p = ⋆ -- ≤-sym Z (S y) ⋆ = {!!} -- ≤-sym (S x) Z () -- ≤-sym (S x) (S y) p = ≤-sym x y p -- ≤ is transitive ≤-trans : ∀ (x y z : ℕ) → (x ≤ y) → (y ≤ z) → (x ≤ z) ≤-trans Z Z Z p1 p2 = ⋆ ≤-trans Z Z (S z) p1 p2 = ⋆ ≤-trans Z (S y) Z p1 p2 = ⋆ ≤-trans Z (S y) (S z) p1 p2 = ⋆ ≤-trans (S x) Z z () p2 ≤-trans (S x) (S y) Z p1 () ≤-trans (S x) (S y) (S z) p1 p2 = ≤-trans x y z p1 p2 -- length of a list length : {A : Set} → (List A) → ℕ length [] = Z length (x ∷ l) = (S Z) + (length l) -- filter' on a list filter' : {A : Set} → (A → Bool) → (l : List A) → List A filter' f [] = [] filter' f (x ∷ l) with (f x) filter' f (x ∷ l) | True = (x ∷ (filter' f l)) filter' f (x ∷ l) | False = filter' f l ≤-cong : ∀ (x y : ℕ) → (x ≤ y) → (x ≤ (S y)) ≤-cong Z y p = ⋆ ≤-cong (S x) Z () ≤-cong (S x) (S y) p = ≤-cong x y p thm-filter' : {A : Set} → (l : List A) → (f : A → Bool) → length (filter' f l) ≤ S (length l) thm-filter' [] f = ⋆ thm-filter' (x ∷ l) f with (f x) thm-filter' (x ∷ l) f | True = thm-filter' l f thm-filter' (x ∷ l) f | False = ≤-cong (length (filter' f l)) (S (length l)) (thm-filter' l f) filter : {A : Set} → (A → Bool) → (l : List A) → Exists (List A) (λ l' → (length l') ≤ (length l)) filter f [] = [ [] , ⋆ ] filter f (x ∷ l) = [ filter' f l , thm-filter' l f ] -- append two lists _++_ : {A : Set} → (l : List A) → (l' : List A) → (List A) [] ++ l' = l' (x ∷ l) ++ l' = (x ∷ (l ++ l')) leq-nat : ℕ → ℕ → Bool leq-nat Z _ = True leq-nat (S n) Z = False leq-nat (S n) (S m) = leq-nat n m _<_ : ℕ → ℕ → Bool Z < (S _) = True Z < Z = False (S n) < (S m) = n < m (S n) < Z = False _>_ : ℕ → ℕ → Bool m > n = n < m -- The sorting algorithm -- The trick here is that we are reducing qsort on "n" qsort' : ∀ (n : ℕ) → ∀ (l : List ℕ) → (p : (length l) ≤ n) → (List ℕ) qsort' Z [] p = [] qsort' Z (x ∷ l) () qsort' (S n) [] p = [] qsort' (S n) (x ∷ l) p = let ll = (filter (leq-nat x) l) rr = (filter ((_>_) x) l) pl = elim2-exists ll pr = elim2-exists rr left = qsort' n (elim1-exists ll) (≤-trans (length (elim1-exists ll)) (length l) n pl p) right = qsort' n (elim1-exists rr) (≤-trans (length (elim1-exists rr)) (length l) n pr p) in (left ++ (x ∷ [])) ++ right l' : {A : Set} → (l : List A) → (length l ≤ length l) l' [] = ⋆ l' (x ∷ l) = l' l qsort : ∀ (l : List ℕ) → List ℕ qsort l = qsort' (length l) l (l' l) -- XXX: definition of an sorted list all-sorted-list : {A : Set} → (a : A) → (l : List A) → Prop all-sorted-list a [] = ⊤ all-sorted-list a (x ∷ l) = leq a x ∧ (all-sorted-list a l) sorted-list : {A : Set} → List A → Prop sorted-list [] = ⊤ sorted-list (x ∷ l) = (all-sorted-list x l) ∧ (sorted-list l) lem-qsort' : (x₁ : ℕ) → (l : List ℕ) → sorted-list ((qsort' (S (length l)) (filter' (leq-nat x₁) l) (≤-trans (length (filter' (leq-nat x₁) l)) (S (length l)) (S (length l)) (thm-filter' l (leq-nat x₁)) (l' l)) ++ (x₁ ∷ [])) ++ qsort' (S (length l)) (filter' (_>_ x₁) l) (≤-trans (length (filter' (_>_ x₁) l)) (S (length l)) (S (length l)) (thm-filter' l (_>_ x₁)) (l' l))) lem-qsort' x [] = and ⋆ ⋆ lem-qsort' x (x₁ ∷ l) = {!!} lem-qsort : (l : List ℕ) → (x : ℕ) → sorted-list ((qsort' (length l) (elim1-exists (filter (leq-nat x) l)) (≤-trans (length (elim1-exists (filter (leq-nat x) l))) (length l) (length l) (elim2-exists (filter (leq-nat x) l)) (l' l)) ++ (x ∷ [])) ++ qsort' (length l) (elim1-exists (filter (_>_ x) l)) (≤-trans (length (elim1-exists (filter (_>_ x) l))) (length l) (length l) (elim2-exists (filter (_>_ x) l)) (l' l))) lem-qsort [] x = and ⋆ ⋆ lem-qsort (x ∷ l) x₁ = lem-qsort' x₁ l -- Theorem that given a list, qsort will actually sort the list thm-qsort : ∀ (l : List ℕ) → sorted-list (qsort l) thm-qsort [] = ⋆ thm-qsort (x ∷ l) = lem-qsort l x
28.429293
114
0.473974
1ea1053198fbbda4e42a6ada3aee20604950487e
4,034
agda
Agda
equality/calculus.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
equality/calculus.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
2
2015-02-11T11:14:59.000Z
2015-02-11T15:20:34.000Z
equality/calculus.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
4
2015-04-11T17:19:12.000Z
2019-02-26T06:17:38.000Z
{-# OPTIONS --without-K #-} module equality.calculus where open import sum using (Σ ; _,_ ; proj₁; proj₂) open import equality.core open import equality.groupoid public open import function.core ap' : ∀ {i j} {X : Set i}{Y : X → Set j} {x x' : X}(f : (x : X) → Y x)(p : x ≡ x') → subst Y p (f x) ≡ f x' ap' _ refl = refl subst-naturality : ∀ {i i' j} {X : Set i} {Y : Set i'} {x x' : X} (P : Y → Set j) (f : X → Y)(p : x ≡ x')(u : P (f x)) → subst (P ∘ f) p u ≡ subst P (ap f p) u subst-naturality _ _ refl _ = refl subst-hom : ∀ {i j}{X : Set i}(P : X → Set j){x y z : X} → (p : x ≡ y)(q : y ≡ z)(u : P x) → subst P q (subst P p u) ≡ subst P (p · q) u subst-hom _ refl q u = refl subst-eq : ∀ {i} {X : Set i}{x y z : X} → (p : y ≡ x)(q : y ≡ z) → subst (λ y → y ≡ z) p q ≡ sym p · q subst-eq refl _ = refl subst-eq₂ : ∀ {i} {X : Set i}{x y : X} → (p : x ≡ y) → (q : x ≡ x) → subst (λ z → z ≡ z) p q ≡ sym p · q · p subst-eq₂ refl q = sym (left-unit _) subst-const : ∀ {i j} {A : Set i}{X : Set j} → {a a' : A}(p : a ≡ a')(x : X) → subst (λ _ → X) p x ≡ x subst-const refl x = refl subst-const-ap : ∀ {i j} {A : Set i}{X : Set j} → {a a' : A}(f : A → X)(p : a ≡ a') → ap' f p ≡ subst-const p (f a) · ap f p subst-const-ap f refl = refl apΣ : ∀ {i j}{A : Set i}{B : A → Set j} {x x' : Σ A B} → (p : x ≡ x') → Σ (proj₁ x ≡ proj₁ x') λ q → subst B q (proj₂ x) ≡ proj₂ x' apΣ {B = B} p = J (λ x x' p → Σ (proj₁ x ≡ proj₁ x') λ q → subst B q (proj₂ x) ≡ proj₂ x') (λ x → refl , refl) _ _ p unapΣ : ∀ {i j}{A : Set i}{B : A → Set j} {a a' : A}{b : B a}{b' : B a'} → (Σ (a ≡ a') λ q → subst B q b ≡ b') → (a , b) ≡ (a' , b') unapΣ (refl , refl) = refl pair≡ : ∀ {i j}{A : Set i}{B : Set j} {a a' : A}{b b' : B} → (a ≡ a') → (b ≡ b') → (a , b) ≡ (a' , b') pair≡ refl refl = refl apΣ-proj : ∀ {i j}{A : Set i}{B : A → Set j} {a a' : A}{b : B a}{b' : B a'} (p : (a , b) ≡ (a' , b')) → proj₁ (apΣ p) ≡ ap proj₁ p apΣ-proj = J (λ _ _ p → proj₁ (apΣ p) ≡ ap proj₁ p) (λ x → refl) _ _ apΣ-sym : ∀ {i j}{A : Set i}{B : A → Set j} {a a' : A}{b : B a}{b' : B a'} (p : (a , b) ≡ (a' , b')) → proj₁ (apΣ (sym p)) ≡ sym (proj₁ (apΣ p)) apΣ-sym = J (λ _ _ p → proj₁ (apΣ (sym p)) ≡ sym (proj₁ (apΣ p))) (λ x → refl) _ _ subst-ap : ∀ {i j}{A : Set i}{B : Set j}{a a' : A} → (f : A → B) → (p : a ≡ a') → ap f (sym p) ≡ subst (λ x → f x ≡ f a) p refl subst-ap f refl = refl ap-map-id : ∀ {i j}{X : Set i}{Y : Set j}{x : X} → (f : X → Y) → ap f (refl {x = x}) ≡ refl {x = f x} ap-map-id f = refl ap-map-hom : ∀ {i j}{X : Set i}{Y : Set j}{x y z : X} → (f : X → Y)(p : x ≡ y)(q : y ≡ z) → ap f (p · q) ≡ ap f p · ap f q ap-map-hom f refl _ = refl ap-id : ∀ {l} {A : Set l}{x y : A}(p : x ≡ y) → ap id p ≡ p ap-id refl = refl ap-hom : ∀ {l m n} {A : Set l}{B : Set m}{C : Set n} {x y : A}(f : A → B)(g : B → C)(p : x ≡ y) → ap g (ap f p) ≡ ap (g ∘ f) p ap-hom f g refl = refl ap-inv : ∀ {i j} {X : Set i} {Y : Set j} → {x x' : X} → (f : X → Y)(p : x ≡ x') → ap f (sym p) ≡ sym (ap f p) ap-inv f refl = refl double-inverse : ∀ {i} {X : Set i} {x y : X} (p : x ≡ y) → sym (sym p) ≡ p double-inverse refl = refl inverse-comp : ∀ {i} {X : Set i} {x y z : X} (p : x ≡ y)(q : y ≡ z) → sym (p · q) ≡ sym q · sym p inverse-comp refl q = sym (left-unit (sym q)) inverse-unique : ∀ {i} {X : Set i} {x y : X} (p : x ≡ y)(q : y ≡ x) → p · q ≡ refl → sym p ≡ q inverse-unique refl q t = sym t
29.881481
57
0.385226
5735375786a40032d8bf170b2e33fab1c2179425
4,817
agda
Agda
04-cubical-type-theory/material/Part4.agda
tomdjong/EPIT-2020
54b18e4adf890b3533bbefda373912423be7f490
[ "MIT" ]
null
null
null
04-cubical-type-theory/material/Part4.agda
tomdjong/EPIT-2020
54b18e4adf890b3533bbefda373912423be7f490
[ "MIT" ]
null
null
null
04-cubical-type-theory/material/Part4.agda
tomdjong/EPIT-2020
54b18e4adf890b3533bbefda373912423be7f490
[ "MIT" ]
null
null
null
{- Part 4: Higher inductive types - Quotients via HITs - Propositional truncation for logic? - CS example using quotients (maybe finite multisets or queues) - Synthetic homotopy theory (probably Torus = S^1 * S^1, pi_1(S^1) = Z, pi_1(Torus) = Z * Z) -} {-# OPTIONS --cubical #-} module Part4 where open import Cubical.Foundations.Prelude hiding (refl ; cong ; subst ; sym) open import Cubical.Foundations.Isomorphism open import Cubical.Data.Int open import Cubical.Data.Prod open import Part3 ----------------------------------------------------------------------------- -- Higher inductive types -- The following definition of finite multisets is due to Vikraman -- Choudhury and Marcelo Fiore. infixr 5 _∷_ data FMSet (A : Type ℓ) : Type ℓ where [] : FMSet A _∷_ : (x : A) → (xs : FMSet A) → FMSet A comm : (x y : A) (xs : FMSet A) → x ∷ y ∷ xs ≡ y ∷ x ∷ xs -- trunc : (xs ys : FMSet A) (p q : xs ≡ ys) → p ≡ q -- We need to add the trunc constructor for FMSets to be sets, omitted -- here for simplicity. _++_ : ∀ {A : Type ℓ} (xs ys : FMSet A) → FMSet A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ xs ++ ys comm x y xs i ++ ys = comm x y (xs ++ ys) i -- trunc xs zs p q i j ++ ys = -- trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j unitr-++ : {A : Type ℓ} (xs : FMSet A) → xs ++ [] ≡ xs unitr-++ [] = refl unitr-++ (x ∷ xs) = cong (x ∷_) (unitr-++ xs) unitr-++ (comm x y xs i) j = comm x y (unitr-++ xs j) i -- unitr-++ (trunc xs ys x y i j) = {!!} -- This is a special case of set quotients! Very useful for -- programming and set level mathematics data _/_ (A : Type ℓ) (R : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where [_] : A → A / R eq/ : (a b : A) → R a b → [ a ] ≡ [ b ] trunc : (a b : A / R) (p q : a ≡ b) → p ≡ q -- Proving that they are effective ((a b : A) → [ a ] ≡ [ b ] → R a b) -- requires univalence for propositions. ------------------------------------------------------------------------- -- Topological examples of things that are not sets -- We can define the circle as the following simple data declaration: data S¹ : Type₀ where base : S¹ loop : base ≡ base -- We can write functions on S¹ using pattern-matching equations: double : S¹ → S¹ double base = base double (loop i) = (loop ∙ loop) i helix : S¹ → Type₀ helix base = Int helix (loop i) = sucPathInt i ΩS¹ : Type₀ ΩS¹ = base ≡ base winding : ΩS¹ → Int winding p = subst helix p (pos 0) _ : winding (λ i → double ((loop ∙ loop) i)) ≡ pos 4 _ = refl -- We can define the Torus as: data Torus : Type₀ where point : Torus line1 : point ≡ point line2 : point ≡ point square : PathP (λ i → line1 i ≡ line1 i) line2 line2 -- And prove that it is equivalent to two circle: t2c : Torus → S¹ × S¹ t2c point = (base , base) t2c (line1 i) = (loop i , base) t2c (line2 j) = (base , loop j) t2c (square i j) = (loop i , loop j) c2t : S¹ × S¹ → Torus c2t (base , base) = point c2t (loop i , base) = line1 i c2t (base , loop j) = line2 j c2t (loop i , loop j) = square i j c2t-t2c : (t : Torus) → c2t (t2c t) ≡ t c2t-t2c point = refl c2t-t2c (line1 _) = refl c2t-t2c (line2 _) = refl c2t-t2c (square _ _) = refl t2c-c2t : (p : S¹ × S¹) → t2c (c2t p) ≡ p t2c-c2t (base , base) = refl t2c-c2t (base , loop _) = refl t2c-c2t (loop _ , base) = refl t2c-c2t (loop _ , loop _) = refl -- Using univalence we get the following equality: Torus≡S¹×S¹ : Torus ≡ S¹ × S¹ Torus≡S¹×S¹ = isoToPath' (iso t2c c2t t2c-c2t c2t-t2c) windingTorus : point ≡ point → Int × Int windingTorus l = ( winding (λ i → proj₁ (t2c (l i))) , winding (λ i → proj₂ (t2c (l i)))) _ : windingTorus (line1 ∙ sym line2) ≡ (pos 1 , negsuc 0) _ = refl -- We have many more topological examples, including Klein bottle, RP^n, -- higher spheres, suspensions, join, wedges, smash product: open import Cubical.HITs.KleinBottle open import Cubical.HITs.RPn open import Cubical.HITs.S2 open import Cubical.HITs.S3 open import Cubical.HITs.Susp open import Cubical.HITs.Join -- open import Cubical.HITs.Wedge open import Cubical.HITs.SmashProduct -- There's also a proof of the "3x3 lemma" for pushouts in less than -- 200LOC. In HoTT-Agda this took about 3000LOC. For details see: -- https://github.com/HoTT/HoTT-Agda/tree/master/theorems/homotopy/3x3 open import Cubical.HITs.Pushout -- We also defined the Hopf fibration and proved that its total space -- is S³ in about 300LOC: open import Cubical.HITs.Hopf -- There is also some integer cohomology: open import Cubical.ZCohomology.Everything -- To compute cohomology groups of various spaces we need a bunch of -- interesting theorems: Freudenthal suspension theorem, -- Mayer-Vietoris sequence... open import Cubical.Homotopy.Freudenthal -- open import Cubical.ZCohomology.MayerVietorisUnreduced
29.193939
77
0.625078
4bbb6558e758119b6fd500da4dbe716715d49cc6
359
agda
Agda
src/algebra/group/morphism.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/algebra/group/morphism.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/algebra/group/morphism.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 algebra.group.morphism where open import level open import algebra.group.core open import algebra.monoid.morphism module _ {i}{j} {X : Set i}⦃ sX : IsGroup X ⦄ {Y : Set j}⦃ sY : IsGroup Y ⦄ where open IsGroup ⦃ ... ⦄ IsGroupMorphism : (X → Y) → Set (i ⊔ j) IsGroupMorphism f = IsMonoidMorphism f
23.933333
44
0.635097
a06e46c527cfab378bc072cceefa9094bf16a053
7,623
agda
Agda
Cubical/Categories/DistLatticeSheaf.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Categories/DistLatticeSheaf.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Categories/DistLatticeSheaf.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Categories.DistLatticeSheaf where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Structure open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Relation.Binary.Poset open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.Semilattice open import Cubical.Algebra.Lattice open import Cubical.Algebra.DistLattice open import Cubical.Algebra.DistLattice.Basis open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.NaturalTransformation open import Cubical.Categories.Limits.Pullback open import Cubical.Categories.Limits.Terminal open import Cubical.Categories.Limits.Limits open import Cubical.Categories.Limits.RightKan open import Cubical.Categories.Instances.Functors open import Cubical.Categories.Instances.CommRings open import Cubical.Categories.Instances.Poset open import Cubical.Categories.Instances.Semilattice open import Cubical.Categories.Instances.Lattice open import Cubical.Categories.Instances.DistLattice private variable ℓ ℓ' ℓ'' : Level module PreSheafExtension (L : DistLattice ℓ) (C : Category ℓ' ℓ'') (limitC : Limits {ℓ} {ℓ} C) (L' : ℙ (fst L)) where open Functor private DLCat = DistLatticeCategory L DLSubCat = ΣPropCat DLCat L' DLPreSheaf = Functor (DLCat ^op) C DLSubPreSheaf = Functor (DLSubCat ^op) C i : Functor DLSubCat DLCat F-ob i = fst F-hom i f = f F-id i = refl F-seq i _ _ = refl DLRan : DLSubPreSheaf → DLPreSheaf DLRan = Ran limitC (i ^opF) module _ (L : DistLattice ℓ) (C : Category ℓ' ℓ'') (T : Terminal C) where open Category hiding (_⋆_) open Functor open Order (DistLattice→Lattice L) open DistLatticeStr (snd L) open JoinSemilattice (Lattice→JoinSemilattice (DistLattice→Lattice L)) open MeetSemilattice (Lattice→MeetSemilattice (DistLattice→Lattice L)) using (∧≤RCancel ; ∧≤LCancel) open PosetStr (IndPoset .snd) hiding (_≤_) 𝟙 : ob C 𝟙 = terminalOb C T private DLCat : Category ℓ ℓ DLCat = DistLatticeCategory L open Category DLCat -- C-valued presheaves on a distributive lattice DLPreSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'') DLPreSheaf = Functor (DLCat ^op) C hom-∨₁ : (x y : L .fst) → DLCat [ x , x ∨l y ] hom-∨₁ = ∨≤RCancel -- TODO: isn't the fixity of the operators a bit weird? hom-∨₂ : (x y : L .fst) → DLCat [ y , x ∨l y ] hom-∨₂ = ∨≤LCancel hom-∧₁ : (x y : L .fst) → DLCat [ x ∧l y , x ] hom-∧₁ _ _ = (≤m→≤j _ _ (∧≤RCancel _ _)) hom-∧₂ : (x y : L .fst) → DLCat [ x ∧l y , y ] hom-∧₂ _ _ = (≤m→≤j _ _ (∧≤LCancel _ _)) {- x ∧ y ----→ x | | | sq | V V y ----→ x ∨ y -} sq : (x y : L .fst) → hom-∧₂ x y ⋆ hom-∨₂ x y ≡ hom-∧₁ x y ⋆ hom-∨₁ x y sq x y = is-prop-valued (x ∧l y) (x ∨l y) (hom-∧₂ x y ⋆ hom-∨₂ x y) (hom-∧₁ x y ⋆ hom-∨₁ x y) {- F(x ∨ y) ----→ F(x) | | | Fsq | V V F(y) ------→ F(x ∧ y) -} Fsq : (F : DLPreSheaf) (x y : L .fst) → F .F-hom (hom-∨₂ x y) ⋆⟨ C ⟩ F .F-hom (hom-∧₂ x y) ≡ F .F-hom (hom-∨₁ x y) ⋆⟨ C ⟩ F .F-hom (hom-∧₁ x y) Fsq F x y = F-square F (sq x y) isDLSheaf : (F : DLPreSheaf) → Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'') isDLSheaf F = (F-ob F 0l ≡ 𝟙) × ((x y : L .fst) → isPullback C _ _ _ (Fsq F x y)) -- TODO: might be better to define this as a record DLSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'') DLSheaf = Σ[ F ∈ DLPreSheaf ] isDLSheaf F module SheafOnBasis (L : DistLattice ℓ) (C : Category ℓ' ℓ'') (T : Terminal C) (L' : ℙ (fst L)) (hB : IsBasis L L') where open Category open Functor open DistLatticeStr ⦃...⦄ open SemilatticeStr ⦃...⦄ open IsBasis hB private DLCat = DistLatticeCategory L BasisCat = ΣPropCat DLCat L' DLBasisPreSheaf = Functor (BasisCat ^op) C -- to avoid writing 𝟙 L C T 1c : ob C 1c = terminalOb C T instance _ = snd L _ = snd (Basis→MeetSemilattice L L' hB) module condSquare (x y : ob BasisCat) (x∨y∈L' : fst x ∨l fst y ∈ L') where private x∨y : ob BasisCat -- = Σ[ x ∈ L ] (x ∈ L') x∨y = fst x ∨l fst y , x∨y∈L' {- x ∧ y ----→ x | | | sq | V V y ----→ x ∨ y but as a square in BasisCat -} Bsq : seq' BasisCat {x = x · y} {y = y} {z = x∨y} (hom-∧₂ L C T (fst x) (fst y)) (hom-∨₂ L C T (fst x) (fst y)) ≡ seq' BasisCat {x = x · y} {y = x} {z = x∨y} (hom-∧₁ L C T (fst x) (fst y)) (hom-∨₁ L C T (fst x) (fst y)) Bsq = sq L C T (fst x) (fst y) {- F(x ∨ y) ----→ F(x) | | | Fsq | V V F(y) ------→ F(x ∧ y) square in C but now F is only presheaf on BasisCat -} BFsq : (F : DLBasisPreSheaf) → seq' C {x = F .F-ob x∨y} {y = F .F-ob y} {z = F .F-ob (x · y)} (F .F-hom (hom-∨₂ L C T (fst x) (fst y))) (F .F-hom (hom-∧₂ L C T (fst x) (fst y))) ≡ seq' C {x = F .F-ob x∨y} {y = F .F-ob x} {z = F .F-ob (x · y)} (F .F-hom (hom-∨₁ L C T (fst x) (fst y))) (F .F-hom (hom-∧₁ L C T (fst x) (fst y))) BFsq F = F-square F Bsq -- TODO: check that this is equivalent to the functor -- preserving terminal objects and pullbacks isDLBasisSheaf : DLBasisPreSheaf → Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'') isDLBasisSheaf F = ((0∈L' : 0l ∈ L') → F .F-ob (0l , 0∈L') ≡ 1c) × ((x y : ob BasisCat) (x∨y∈L' : fst x ∨l fst y ∈ L') → isPullback C _ _ _ (BFsq x y x∨y∈L' F)) where open condSquare DLBasisSheaf : Type (ℓ-max (ℓ-max ℓ ℓ') ℓ'') DLBasisSheaf = Σ[ F ∈ DLBasisPreSheaf ] isDLBasisSheaf F -- To prove the statement we probably need that C is: -- 1. univalent -- 2. has finite limits (or pullbacks and a terminal object) -- 3. isGroupoid (C .ob) -- The last point is not strictly necessary, but we have to have some -- control over the hLevel as we want to write F(x) in terms of its -- basis cover which is information hidden under a prop truncation... -- Alternatively we just prove the statement for C = CommRingsCategory -- TODO: is unique existence expressed like this what we want? -- statement : (F' : DLBasisSheaf) -- → ∃![ F ∈ DLSheaf L C T ] ((x : fst L) → (x ∈ L') → CatIso C (F-ob (fst F) x) (F-ob (fst F') x)) -- TODO: if C is univalent the CatIso could be ≡? -- statement (F' , h1 , hPb) = ? -- It might be easier to prove all of these if we use the definition -- in terms of particular limits instead -- Scrap zone: -- -- Sublattices: upstream later -- record isSublattice (L' : ℙ (fst L)) : Type ℓ where -- field -- 1l-closed : 1l ∈ L' -- 0l-closed : 0l ∈ L' -- ∧l-closed : {x y : fst L} → x ∈ L' → y ∈ L' → x ∧l y ∈ L' -- ∨l-closed : {x y : fst L} → x ∈ L' → y ∈ L' → x ∨l y ∈ L' -- open isSublattice -- Sublattice : Type (ℓ-suc ℓ) -- Sublattice = Σ[ L' ∈ ℙ (fst L) ] isSublattice L' -- restrictDLSheaf : DLSheaf → Sublattice → DLSheaf -- F-ob (fst (restrictDLSheaf F (L' , HL'))) x = {!F-ob (fst F) x!} -- Hmm, not nice... -- F-hom (fst (restrictDLSheaf F L')) = {!!} -- F-id (fst (restrictDLSheaf F L')) = {!!} -- F-seq (fst (restrictDLSheaf F L')) = {!!} -- snd (restrictDLSheaf F L') = {!!}
30.862348
161
0.569854
9a26d03beabc45ce21303c3b7faaf7a36ca4726b
723
agda
Agda
agda/ScaleDegree.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
28
2017-04-21T09:08:52.000Z
2022-03-04T18:04:07.000Z
agda/ScaleDegree.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
1
2020-11-13T01:26:20.000Z
2020-11-17T00:58:55.000Z
agda/ScaleDegree.agda
halfaya/MusicTools
04896c61b603d46011b7d718fcb47dd756e66021
[ "MIT" ]
3
2019-01-12T17:02:36.000Z
2020-11-10T04:04:40.000Z
{-# OPTIONS --cubical --safe #-} module ScaleDegree where open import Data.Fin using (Fin; toℕ; #_) open import Data.Nat using (ℕ; suc; _+_) open import Data.Nat.DivMod using (_mod_; _div_) open import Data.Product using (_×_; _,_) open import Data.Vec using (lookup) open import Pitch ScaleDegree : ℕ → Set ScaleDegree = Fin ScaleDegreeOctave : ℕ → Set ScaleDegreeOctave n = ScaleDegree n × Octave transposeScaleDegree : {n : ℕ} → ℕ → ScaleDegreeOctave (suc n) → ScaleDegreeOctave (suc n) transposeScaleDegree {n} k (d , o) = let d' = (toℕ d) + k in d' mod (suc n) , o + (d' div (suc n)) scaleDegreeToPC : {n : ℕ} → Scale n → ScaleDegree n → PC scaleDegreeToPC scale d = lookup scale d
26.777778
90
0.665284
13557fef88543a3af042b8fd7d8fe85d4b14159c
1,606
agda
Agda
src/String.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/String.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/String.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Strings ------------------------------------------------------------------------ {-# OPTIONS --without-K #-} module String where open import Prelude ------------------------------------------------------------------------ -- Helper code used below private -- A variant of Maybe that matches the Haskell Maybe type. data HMaybe (A : Type) : Type where Nothing : HMaybe A Just : A → HMaybe A {-# COMPILE GHC HMaybe = data Maybe (Nothing | Just) #-} -- A conversion function. hmaybe-to-maybe : ∀ {A} → HMaybe A → Maybe A hmaybe-to-maybe Nothing = nothing hmaybe-to-maybe (Just x) = just x ------------------------------------------------------------------------ -- Operations on strings -- Implemented using the FFI. These operations do not compute at -- compile-time, and are only supported by the GHC backend. {-# FOREIGN GHC import qualified Data.Text #-} mutual -- Tries to parse the given string as a natural number. Accepts -- whatever the Haskell Read instance for Integer accepts, except -- for negative numbers. parseℕ : String → Maybe ℕ parseℕ = hmaybe-to-maybe ∘ parseℕ′ private postulate parseℕ′ : String → HMaybe ℕ {-# COMPILE GHC parseℕ′ = \s -> case reads (Data.Text.unpack s) of { [(x, "")] | x >= 0 -> Just (x :: Integer) ; _ -> Nothing } #-} -- Turns natural numbers into strings. postulate prettyℕ : ℕ → String {-# COMPILE GHC prettyℕ = \n -> Data.Text.pack (show (n :: Integer)) #-}
23.617647
72
0.511831
190689f86730a6010a488732fe811c670f04974e
3,482
agda
Agda
src/Categories/Category/Core.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Core.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Core.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.Core where open import Level open import Function.Base using (flip) open import Relation.Binary using (Rel; IsEquivalence; Setoid) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) import Relation.Binary.Reasoning.Setoid as SetoidR -- Basic definition of a |Category| with a Hom setoid. -- Also comes with some reasoning combinators (see HomReasoning) record Category (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where eta-equality infix 4 _≈_ _⇒_ infixr 9 _∘_ field Obj : Set o _⇒_ : Rel Obj ℓ _≈_ : ∀ {A B} → Rel (A ⇒ B) e id : ∀ {A} → (A ⇒ A) _∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C) field assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → (h ∘ g) ∘ f ≈ h ∘ (g ∘ f) -- We add a symmetric proof of associativity so that the opposite category of the -- opposite category is definitionally equal to the original category. See how -- `op` is implemented. sym-assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → h ∘ (g ∘ f) ≈ (h ∘ g) ∘ f identityˡ : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f identityʳ : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f -- We add a proof of "neutral" identity proof, in order to ensure the opposite of -- constant functor is definitionally equal to itself. identity² : ∀ {A} → id ∘ id {A} ≈ id {A} equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B}) ∘-resp-≈ : ∀ {A B C} {f h : B ⇒ C} {g i : A ⇒ B} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i module Equiv {A B : Obj} = IsEquivalence (equiv {A} {B}) open Equiv ∘-resp-≈ˡ : ∀ {A B C} {f h : B ⇒ C} {g : A ⇒ B} → f ≈ h → f ∘ g ≈ h ∘ g ∘-resp-≈ˡ pf = ∘-resp-≈ pf refl ∘-resp-≈ʳ : ∀ {A B C} {f h : A ⇒ B} {g : B ⇒ C} → f ≈ h → g ∘ f ≈ g ∘ h ∘-resp-≈ʳ pf = ∘-resp-≈ refl pf hom-setoid : ∀ {A B} → Setoid _ _ hom-setoid {A} {B} = record { Carrier = A ⇒ B ; _≈_ = _≈_ ; isEquivalence = equiv } -- When a category is quantified, it is convenient to refer to the levels from a module, -- so we do not have to explicitly quantify over a category when universe levels do not -- play a big part in a proof (which is the case probably all the time). o-level : Level o-level = o ℓ-level : Level ℓ-level = ℓ e-level : Level e-level = e -- Reasoning combinators. _≈⟨_⟩_ and _≈˘⟨_⟩_ from SetoidR. -- Also some useful combinators for doing reasoning on _∘_ chains module HomReasoning {A B : Obj} where open SetoidR (hom-setoid {A} {B}) public -- open Equiv {A = A} {B = B} public infixr 4 _⟩∘⟨_ refl⟩∘⟨_ infixl 5 _⟩∘⟨refl _⟩∘⟨_ : ∀ {M} {f h : M ⇒ B} {g i : A ⇒ M} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i _⟩∘⟨_ = ∘-resp-≈ refl⟩∘⟨_ : ∀ {M} {f : M ⇒ B} {g i : A ⇒ M} → g ≈ i → f ∘ g ≈ f ∘ i refl⟩∘⟨_ = Equiv.refl ⟩∘⟨_ _⟩∘⟨refl : ∀ {M} {f h : M ⇒ B} {g : A ⇒ M} → f ≈ h → f ∘ g ≈ h ∘ g _⟩∘⟨refl = _⟩∘⟨ Equiv.refl -- convenient inline versions infix 2 ⟺ infixr 3 _○_ ⟺ : {f g : A ⇒ B} → f ≈ g → g ≈ f ⟺ = Equiv.sym _○_ : {f g h : A ⇒ B} → f ≈ g → g ≈ h → f ≈ h _○_ = Equiv.trans op : Category o ℓ e op = record { Obj = Obj ; _⇒_ = flip _⇒_ ; _≈_ = _≈_ ; _∘_ = flip _∘_ ; id = id ; assoc = sym-assoc ; sym-assoc = assoc ; identityˡ = identityʳ ; identityʳ = identityˡ ; identity² = identity² ; equiv = equiv ; ∘-resp-≈ = flip ∘-resp-≈ }
31.944954
91
0.519242
2273adbaccf1c2125defcad5d4cdb0712810e92f
1,123
agda
Agda
stdlib-exts/Data/Tree/Instance.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
stdlib-exts/Data/Tree/Instance.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
stdlib-exts/Data/Tree/Instance.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
module Data.Tree.Instance where open import Class.Functor open import Class.Monad open import Class.Monoid open import Class.Show open import Class.Traversable open import Data.List open import Data.List.Instance open import Data.String using (String) open import Data.String.Instance open import Data.Tree.Base instance {-# TERMINATING #-} Tree-Functor : Functor Tree Tree-Functor = record { _<$>_ = helper } where helper : ∀ {A B} -> (A -> B) -> Tree A -> Tree B helper f (Node x x₁) = Node (f x) (map (helper f) x₁) {-# TERMINATING #-} Tree-Show : ∀ {A} {{_ : Show A}} -> Show (Tree A) Tree-Show = record { show = helper show } where helper : ∀ {A} -> (A -> String) -> Tree A -> String helper f (Node x x₁) = "Node (" + f x + ") " + show (map (helper f) x₁) {-# TERMINATING #-} Tree-Traversable : Traversable Tree Tree-Traversable = record { sequence = helper } where helper : {M : Set → Set} {{_ : Monad M}} {A : Set} → Tree (M A) → M (Tree A) helper (Node x y) = do x' <- x y' <- sequence (map helper y) return (Node x' y')
29.552632
82
0.601959
5e4cd0be191ef54189b6fadb0f302b4a6697d737
2,014
agda
Agda
test/Succeed/Reflection.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Reflection.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Reflection.agda
hborum/agda
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
[ "BSD-3-Clause" ]
1
2021-04-01T18:30:09.000Z
2021-04-01T18:30:09.000Z
{-# OPTIONS --universe-polymorphism #-} module Reflection where open import Common.Prelude hiding (Unit; module Unit) renaming (Nat to ℕ; module Nat to ℕ) open import Common.Reflection open import Common.Equality open import Agda.Builtin.TrustMe data Id {A : Set}(x : A) : (B : Set) → B → Set where course : Id x A x open import Common.Level set₀ : Type set₀ = sort (lit 0) unCheck : Term → Term unCheck (def x (_ ∷ _ ∷ arg _ t ∷ [])) = t unCheck t = unknown infix 1 _is_of_ data Check {a}{A : Set a}(x : A) : Set where _is_of_ : (t t′ : Term) → Id (primTrustMe {x = unCheck t} {t′}) (t′ ≡ t′) refl → Check x `Check : QName `Check = quote Check test₁ : Check ({A : Set} → A → A) test₁ = quoteGoal t in t is pi (hArg set₀) (abs "A" (pi (vArg (var 0 [])) (abs "_" (var 1 [])))) of course test₂ : (X : Set) → Check (λ (x : X) → x) test₂ X = quoteGoal t in t is lam visible (abs "x" (var 0 [])) of course infixr 5 _`∷_ pattern _`∷_ x xs = con (quote _∷_) (hArg unknown ∷ hArg unknown ∷ vArg x ∷ vArg xs ∷ []) pattern `[] = con (quote []) (hArg unknown ∷ hArg unknown ∷ []) pattern `true = con (quote true) [] pattern `false = con (quote false) [] test₃ : Check (true ∷ false ∷ []) test₃ = quoteGoal t in t is (`true `∷ `false `∷ `[]) of course `List : Term → Term `List A = def (quote List) (hArg (def (quote lzero) []) ∷ vArg A ∷ []) `ℕ = def (quote ℕ) [] `Term : Term `Term = def (quote Term) [] `Type : Term `Type = def (quote Type) [] `Sort : Term `Sort = def (quote Sort) [] test₄ : Check (List ℕ) test₄ = quoteGoal t in t is `List `ℕ of course postulate a : ℕ test₁₄ : Check 1 test₁₄ = quoteGoal t in t is lit (nat 1) of course record R : Set₁ where field A : Set macro RA : Term → TC _ RA goal = bindTC (getDefinition (quote R)) λ where (recordDef _ (vArg A ∷ [])) → unify goal (def A []) _ → typeError (strErr "Impossible" ∷ []) test₁₅ : RA ≡ R.A test₁₅ = refl
23.97619
90
0.57994
a0917c5fab9fd354caf7eeb0a40febc8c1f96e9d
622
agda
Agda
test/Fail/Issue1944-instance.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1944-instance.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1944-instance.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, Issue 1944, Bengtfest Marsstrand 2016-04-28 -- A reason why issue 1098 (automatic opening of record modules) -- cannot easily be fixed data Bool : Set where true false : Bool if_then_else_ : ∀{A : Set} → Bool → A → A → A if true then t else e = t if false then t else e = e record Testable (A : Set) : Set where field test : A -> Bool open Testable {{...}} open Testable -- overloading projection `test` mytest : ∀{A} → Testable A → A → Bool mytest dict = test dict -- Should work. t : ∀{A}{{_ : Testable A}} → A → A t = λ x → if test x then x else x -- This may fail when test is overloaded.
24.88
64
0.64791
0649efb65f6d5abf8fa90ee642ae46f738785d83
23
agda
Agda
test/Fail/Issue623.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue623.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue623.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Issue623.B
11.5
22
0.826087
a07d80f7b3ebcf127574aaa317e86ef9a82f6f63
5,833
agda
Agda
Cubical/Core/Primitives.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Core/Primitives.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Core/Primitives.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{- This file document and export the main primitives of Cubical Agda. It also defines some basic derived operations (composition and filling). -} {-# OPTIONS --cubical --safe #-} module Cubical.Core.Primitives where open import Agda.Builtin.Cubical.Path public open import Agda.Builtin.Cubical.Sub public renaming ( inc to inS ; primSubOut to outS ) open import Agda.Primitive.Cubical public renaming ( primIMin to _∧_ -- I → I → I ; primIMax to _∨_ -- I → I → I ; primINeg to ~_ -- I → I ; isOneEmpty to empty ; primComp to comp ; primHComp to hcomp ; primTransp to transp ; itIsOne to 1=1 ) open import Agda.Primitive public using ( Level ) renaming ( lzero to ℓ-zero ; lsuc to ℓ-suc ; _⊔_ to ℓ-max ; Setω to Typeω ) open import Agda.Builtin.Sigma public Type : (ℓ : Level) → Set (ℓ-suc ℓ) Type ℓ = Set ℓ Type₀ : Type (ℓ-suc ℓ-zero) Type₀ = Type ℓ-zero Type₁ : Type (ℓ-suc (ℓ-suc ℓ-zero)) Type₁ = Type (ℓ-suc ℓ-zero) -- This file document the Cubical Agda primitives. The primitives -- themselves are bound by the Agda files imported above. -- * The Interval -- I : Typeω -- Endpoints, Connections, Reversal -- i0 i1 : I -- _∧_ _∨_ : I → I → I -- ~_ : I → I -- * Dependent path type. (Path over Path) -- Introduced with lambda abstraction and eliminated with application, -- just like function types. -- PathP : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1 → Type ℓ infix 4 _[_≡_] _[_≡_] : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1 → Type ℓ _[_≡_] = PathP -- Non dependent path types Path : ∀ {ℓ} (A : Type ℓ) → A → A → Type ℓ Path A a b = PathP (λ _ → A) a b -- PathP (λ i → A) x y gets printed as x ≡ y when A does not mention i. -- _≡_ : ∀ {ℓ} {A : Type ℓ} → A → A → Type ℓ -- _≡_ {A = A} = PathP (λ _ → A) -- * @IsOne r@ represents the constraint "r = i1". -- Often we will use "φ" for elements of I, when we intend to use them -- with IsOne (or Partial[P]). -- IsOne : I → Typeω -- i1 is indeed equal to i1. -- 1=1 : IsOne i1 -- * Types of partial elements, and their dependent version. -- "Partial φ A" is a special version of "IsOne φ → A" with a more -- extensional judgmental equality. -- "PartialP φ A" allows "A" to be defined only on "φ". -- Partial : ∀ {ℓ} → I → Type ℓ → Typeω -- PartialP : ∀ {ℓ} → (φ : I) → Partial φ (Type ℓ) → Typeω -- Partial elements are introduced by pattern matching with (r = i0) -- or (r = i1) constraints, like so: private sys : ∀ i → Partial (i ∨ ~ i) Type₁ sys i (i = i0) = Type₀ sys i (i = i1) = Type₀ → Type₀ -- It also works with pattern matching lambdas: -- http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.PatternMatchingLambdas sys' : ∀ i → Partial (i ∨ ~ i) Type₁ sys' i = λ { (i = i0) → Type₀ ; (i = i1) → Type₀ → Type₀ } -- When the cases overlap they must agree. sys2 : ∀ i j → Partial (i ∨ (i ∧ j)) Type₁ sys2 i j = λ { (i = i1) → Type₀ ; (i = i1) (j = i1) → Type₀ } -- (i0 = i1) is actually absurd. sys3 : Partial i0 Type₁ sys3 = λ { () } -- * There are cubical subtypes as in CCHM. Note that these are not -- fibrant (hence in Typeω): _[_↦_] : ∀ {ℓ} (A : Type ℓ) (φ : I) (u : Partial φ A) → Typeω A [ φ ↦ u ] = Sub A φ u infix 4 _[_↦_] -- Any element u : A can be seen as an element of A [ φ ↦ u ] which -- agrees with u on φ: -- inS : ∀ {ℓ} {A : Type ℓ} {φ} (u : A) → A [ φ ↦ (λ _ → u) ] -- One can also forget that an element agrees with u on φ: -- outS : ∀ {ℓ} {A : Type ℓ} {φ : I} {u : Partial φ A} → A [ φ ↦ u ] → A -- * Composition operation according to [CCHM 18]. -- When calling "comp A φ u a" Agda makes sure that "a" agrees with "u i0" on "φ". -- compCCHM : ∀ {ℓ} (A : (i : I) → Type ℓ) (φ : I) (u : ∀ i → Partial φ (A i)) (a : A i0) → A i1 -- Note: this is not recommended to use, instead use the CHM -- primitives! The reason is that these work with HITs and produce -- fewer empty systems. -- * Generalized transport and homogeneous composition [CHM 18]. -- When calling "transp A φ a" Agda makes sure that "A" is constant on "φ". -- transp : ∀ {ℓ} (A : I → Type ℓ) (φ : I) (a : A i0) → A i1 -- When calling "hcomp A φ u a" Agda makes sure that "a" agrees with "u i0" on "φ". -- hcomp : ∀ {ℓ} {A : Type ℓ} {φ : I} (u : I → Partial φ A) (a : A) → A private variable ℓ : Level ℓ′ : I → Level -- Homogeneous filling hfill : {A : Type ℓ} {φ : I} (u : ∀ i → Partial φ A) (u0 : A [ φ ↦ u i0 ]) ----------------------- (i : I) → A hfill {φ = φ} u u0 i = hcomp (λ j → λ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS u0) -- Heterogeneous composition can defined as in CHM, however we use the -- builtin one as it doesn't require u0 to be a cubical subtype. This -- reduces the number of inS's a lot. -- comp : (A : ∀ i → Type (ℓ′ i)) -- {φ : I} -- (u : ∀ i → Partial φ (A i)) -- (u0 : A i0 [ φ ↦ u i0 ]) -- → --------------------------- -- A i1 -- comp A {φ = φ} u u0 = -- hcomp (λ i → λ { (φ = i1) → transp (λ j → A (i ∨ j)) i (u _ 1=1) }) -- (transp A i0 (outS u0)) -- Heterogeneous filling defined using comp fill : (A : ∀ i → Type (ℓ′ i)) {φ : I} (u : ∀ i → Partial φ (A i)) (u0 : A i0 [ φ ↦ u i0 ]) --------------------------- (i : I) → A i fill A {φ = φ} u u0 i = comp (λ j → A (i ∧ j)) (λ j → λ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS u0) -- Σ-types infix 2 Σ-syntax Σ-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') Σ-syntax = Σ syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
28.315534
96
0.533859
ad54b51a86de9ea4f9253e9dce40608d5d858875
13,680
agda
Agda
old/BaseOver.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/BaseOver.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/BaseOver.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} -- Drop-in replacement for the module [Base]. module BaseOver where -- We hide [apd] and [Σ-eq] because their type is not correct, we want to use -- dependent paths instead open import Base public hiding (apd; Σ-eq) -- Notion of path over a path path-over : ∀ {i j} {A : Set i} (B : A → Set j) {x y : A} (p : x == y) (u : B x) (v : B y) → Set j path-over B refl u v = (u == v) syntax path-over B p u v = u == v [ B ↓ p ] -- New apd apd : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A} → (p : x == y) → f x == f y [ B ↓ p ] apd f refl = refl -- Σ-types are used to simulate telescopes and to be able to only use the -- notion of path over a single path -- Intro for paths in a Σ Σ-eq : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} (p : x == y) {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → (x , u) == (y , v) Σ-eq refl refl = refl uncurryi : ∀ {i j k} {A : Set i} {B : A → Set j} {C : ∀ x → B x → Set k} → (∀ {x} y → C x y) → (∀ s → C (π₁ s) (π₂ s)) uncurryi f (x , y) = f y apdd : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k} (g : {a : A} → Π (B a) (C a)) {x y : A} (p : x == y) {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → g u == g v [ uncurry C ↓ Σ-eq p q ] apdd g p q = apd (uncurryi g) (Σ-eq p q) -- Dependent paths in a constant fibration module _ {i j} {A : Set i} {B : Set j} where ↓-cst-in : {x y : A} (p : x == y) {u v : B} → u == v → u == v [ (λ _ → B) ↓ p ] ↓-cst-in refl q = q ↓-cst-out : {x y : A} {p : x == y} {u v : B} → u == v [ (λ _ → B) ↓ p ] → u == v ↓-cst-out {p = refl} q = q ↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v) → (↓-cst-out (↓-cst-in p q) == q) ↓-cst-β refl q = refl -- -- ap can be defined via apd, not sure whether it’s a good idea or not -- ap : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A} (p : x == y) -- → f x == f y -- ap f p = ↓-cst-out (apd f p) -- Dependent paths in a Π-type module _ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k} where ↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ Σ-eq p q ]) → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) ↓-Π-in {p = refl} f = funext (λ x → f (refl {a = x})) ↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ Σ-eq p q ]) ↓-Π-out {p = refl} q refl = happly q _ ↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ Σ-eq p q ]) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-Π-out (↓-Π-in f) q == f q ↓-Π-β {p = refl} f refl = happly (happly-funext (λ x → f (refl {a = x}))) _ -- Dependent paths in a Π-type where the codomain is not dependent on anything module _ {i j k} {A : Set i} {B : A → Set j} {C : Set k} {x x' : A} {p : x == x'} {u : B x → C} {u' : B x' → C} where ↓-app→cst-in : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') → (u == u' [ (λ x → B x → C) ↓ p ]) ↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (Σ-eq p q) (f q)) ↓-app→cst-out : (u == u' [ (λ x → B x → C) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') ↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q) ↓-app→cst-β : (f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t')) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-app→cst-out (↓-app→cst-in f) q == f q ↓-app→cst-β f q = ↓-app→cst-out (↓-app→cst-in f) q ≡⟨ refl ⟩ ↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (Σ-eq p qq) (f qq))) q) ≡⟨ ↓-Π-β (λ qq → ↓-cst-in (Σ-eq p qq) (f qq)) q |in-ctx ↓-cst-out ⟩ ↓-cst-out (↓-cst-in (Σ-eq p q) (f q)) ≡⟨ ↓-cst-β (Σ-eq p q) (f q) ⟩ f q ∎ -- Dependent paths in a Π-type where the domain is constant module _ {i j k} {A : Set i} {B : Set j} {C : A → B → Set k} {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b} where postulate ↓-cst→app-in : ({t t' : B} (q : t == t') → u t == u' t' [ uncurry C ↓ Σ-eq p (↓-cst-in p q) ]) → (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) -- ↓-cst→app-in f = ↓-Π-in (λ q → {!f (↓-cst-out q)!}) postulate ↓-cst→app-out : (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) → ({t t' : B} (q : t == t') → u t == u' t' [ uncurry C ↓ Σ-eq p (↓-cst-in p q) ]) split-ap2 : ∀ {i j k} {A : Set i} {B : A → Set j} {C : Set k} (f : Σ A B → C) {x y : A} (p : x == y) {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → ap f (Σ-eq p q) == ↓-app→cst-out (apd (curry f) p) q split-ap2 f refl refl = refl ↓-app='cst-in : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B} {x y : A} {p : x == y} {u : f x == b} {v : f y == b} → u == (ap f p ∘' v) → (u == v [ (λ x → f x == b) ↓ p ]) ↓-app='cst-in {p = refl} q = q ∘ refl-left-unit _ ↓-app='cst-out : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B} {x y : A} {p : x == y} {u : f x == b} {v : f y == b} → (u == v [ (λ x → f x == b) ↓ p ]) → u == (ap f p ∘' v) ↓-app='cst-out {p = refl} refl = ! (refl-left-unit _) ↓-cst='app-in : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B} {x y : A} {p : x == y} {u : b == f x} {v : b == f y} → (u ∘' ap f p) == v → (u == v [ (λ x → b == f x) ↓ p ]) ↓-cst='app-in {p = refl} refl = refl ↓-cst='app-out : ∀ {i j} {A : Set i} {B : Set j} {f : A → B} {b : B} {x y : A} {p : x == y} {u : b == f x} {v : b == f y} → (u == v [ (λ x → b == f x) ↓ p ]) → (u ∘' ap f p) == v ↓-cst='app-out {p = refl} refl = refl ↓-='-in : ∀ {i j} {A : Set i} {B : Set j} {f g : A → B} {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} → (u ∘ ap g p) == (ap f p ∘' v) → (u == v [ (λ x → f x == g x) ↓ p ]) ↓-='-in {p = refl} q = ! (refl-right-unit _) ∘ (q ∘ refl-left-unit _) -- Dependent vs nondependent whiskering -- This definitional behaviour make [↓-=-in] slightly more complicated to prove -- but [↓-=-in] is often used in the case where [u] and [v] are [refl] _▹_ : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} {u : B x} {v w : B y} {p : x == y} → (u == v [ B ↓ p ]) → v == w → (u == w [ B ↓ p ]) _▹_ {p = refl} q refl = q refl▹ : ∀ {i j} {A : Set i} {B : A → Set j} {x : A} {v w : B x} (q : v == w) → _▹_ {B = B} {p = refl} refl q == q refl▹ refl = refl _◃_ : ∀ {i j} {A : Set i} {B : A → Set j} {x y : A} {u v : B x} {w : B y} {p : x == y} → (u == v → (v == w [ B ↓ p ]) → (u == w [ B ↓ p ])) _◃_ {p = refl} refl q = q ◃refl : ∀ {i j} {A : Set i} {B : A → Set j} {x : A} {v w : B x} (q : v == w) → _◃_ {B = B} {p = refl} q refl == q ◃refl refl = refl ↓-=-in : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B} {x y : A} {p : x == y} {u : g x == f x} {v : g y == f y} → (u ◃ apd f p) == (apd g p ▹ v) → (u == v [ (λ x → g x == f x) ↓ p ]) ↓-=-in {B = B} {p = refl} {u} {v} q = ! (◃refl {B = B} u) ∘ (q ∘ refl▹ {B = B} v) postulate ↓-=-out : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B} {x y : A} {p : x == y} {u : g x == f x} {v : g y == f y} → (u == v [ (λ x → g x == f x) ↓ p ]) → (u ◃ apd f p) == (apd g p ▹ v) --↓-=-out {B = B} {p = refl} refl = {!!} {- Not used yet apdd-cst : ∀ {i j k} {A : Set i} {B : Set j} {C : A → B → Set k} (g : (a : A) → Π B (C a)) {x y : A} (p : x ≡ y) {u v : B} (q : u ≡ v) {r : u ≡[ (λ _ → B) ↓ p ] v} (α : ↓-cst-in p q ≡ r) → apdd (λ {a} b → g a b) p r ≡ apd (uncurry g) (Σ-eq p r) apdd-cst g refl refl refl = refl -} -- This one seems a bit weird ↓-apd-out : ∀ {i j k} {A : Set i} {B : A → Set j} (C : (a : A) → B a → Set k) (f : Π A B) {x y : A} (p : x == y) {u : C x (f x)} {v : C y (f y)} → u == v [ uncurry C ↓ Σ-eq p (apd f p) ] → u == v [ (λ z → C z (f z)) ↓ p ] ↓-apd-out C f refl refl = refl {- -- Dependent paths over [ap f p] module _ {i j k} {A : Set i} {B : Set j} (C : B → Set k) (f : A → B) where ↓-ap-in : {x y : A} {p : x ≡ y} {u : C (f x)} {v : C (f y)} → u ≡[ C ◯ f ↓ p ] v → u ≡[ C ↓ ap f p ] v ↓-ap-in {p = refl} refl = refl ↓-ap-out : {x y : A} (p : x ≡ y) {u : C (f x)} {v : C (f y)} → u ≡[ C ↓ ap f p ] v → u ≡[ C ◯ f ↓ p ] v ↓-ap-out refl refl = refl -- ↓-ap-β ap-, : ∀ {i j k} {A : Set i} {B : Set j} {C : B → Set k} (f : A → B) (g : (a : A) → C (f a)) {x y : A} (p : x ≡ y) → ap (λ x → _,_ {P = C} (f x) (g x)) p ≡ Σ-eq (ap f p) (↓-ap-in C f (apd g p)) ap-, f g refl = refl -} -- Special case of [ap-,] ap-cst,id : ∀ {i j} {A : Set i} (B : A → Set j) {a : A} {x y : B a} (p : x == y) → ap (λ x → _,_ {P = B} a x) p == Σ-eq refl p ap-cst,id B refl = refl -- apd-nd : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y : A} -- → (p : x ≡ y) → apd f p ≡ ↓-cst-in p (ap f p) -- apd-nd f refl = refl apd-◯ : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k} (f : Π A B) (g : {a : A} → Π (B a) (C a)) {x y : A} (p : x == y) → apd (g ◯ f) p == ↓-apd-out C f p (apdd g p (apd f p)) apd-◯ f g refl = refl {- Not used yet -- apd-apd : ∀ {i j k} {A : Set i} {B : A → Set j} {C : (a : A) → B a → Set k} -- (g : (u : Σ A B) → C (π₁ u) (π₂ u)) (f : Π A B) {x y : A} (p : x ≡ y) -- → apd g (Σ-eq p (apd f p)) ≡ {!↓-ap-in!} -- apd-apd = {!!} apd-π₁-β : ∀ {i j} {A : Set i} {B : A → Set j} {x x' : A} (p : x ≡ x') {y : B x} {y' : B x'} (q : y ≡[ B ↓ p ] y') → ap π₁ (Σ-eq p q) ≡ p apd-π₁-β refl refl = refl apd-π₂-β : ∀ {i j} {A : Set i} {B : A → Set j} {x x' : A} (p : x ≡ x') {y : B x} {y' : B x'} (q : y ≡[ B ↓ p ] y') → apd π₂ (Σ-eq p q) ≡ ↓-ap-out B π₁ (Σ-eq p q) (transport (λ p → y ≡[ B ↓ p ] y') (! (apd-π₁-β p q)) q) apd-π₂-β refl refl = refl -} -- Dependent path in a type of the form [λ x → g (f x) ≡ x] module _ {i j} {A : Set i} {B : Set j} (f : A → B) (g : B → A) where ↓-◯=id-in : {x y : A} {p : x == y} {u : g (f x) == x} {v : g (f y) == y} → ((ap g (ap f p) ∘' v) == (u ∘ p)) → (u == v [ (λ x → g (f x) == x) ↓ p ]) ↓-◯=id-in {p = refl} q = ! (refl-right-unit _) ∘ (! q ∘ refl-left-unit _) -- WIP, derive it from more primitive principles -- ↓-◯≡id-in f g {p = p} {u} {v} q = -- ↓-≡-in (u ◃ apd (λ x → g (f x)) p ≡⟨ apd-◯ f g p |in-ctx (λ t → u ◃ t) ⟩ -- u ◃ ↓-apd-out _ f p (apdd g p (apd f p)) ≡⟨ apdd-cst (λ _ b → g b) p (ap f p) (! (apd-nd f p)) |in-ctx (λ t → u ◃ ↓-apd-out _ f p t) ⟩ -- u ◃ ↓-apd-out _ f p (apd (λ t → g (π₂ t)) (Σ-eq p (apd f p))) ≡⟨ apd-◯ π₂ g (Σ-eq p (apd f p)) |in-ctx (λ t → u ◃ ↓-apd-out _ f p t) ⟩ -- u ◃ ↓-apd-out _ f p (↓-apd-out _ π₂ (Σ-eq p (apd f p)) (apdd g (Σ-eq p (apd f p)) (apd π₂ (Σ-eq p (apd f p))))) ≡⟨ {!!} ⟩ -- apd (λ x → x) p ▹ v ∎) ua-in : ∀ {i} {A B : Set i} → A ≃ B → A == B ua-in = eq-to-path ua-out : ∀ {i} {A B : Set i} → A == B → A ≃ B ua-out = path-to-eq ua-β : ∀ {i} {A B : Set i} (e : A ≃ B) → ua-out (ua-in e) == e ua-β e = eq-to-path-right-inverse e -- These lemmas do not really look computational, but they are only used in the -- [↓-pp] lemmas which do look computational. to-transp-in : ∀ {i j} {A : Set i} (B : A → Set j) {a a' : A} (p : a == a') {u : B a} {v : B a'} → (π₁ (ua-out (ap B p)) u == v) → (u == v [ B ↓ p ]) to-transp-in B refl refl = refl to-transp-out : ∀ {i j} {A : Set i} {B : A → Set j} {a a' : A} {p : a == a'} {u : B a} {v : B a'} → (u == v [ B ↓ p ]) → (π₁ (ua-out (ap B p)) u == v) to-transp-out {p = refl} refl = refl to-transp-β : ∀ {i j} {A : Set i} (B : A → Set j) {a a' : A} (p : a == a') {u : B a} {v : B a'} (q : π₁ (ua-out (ap B p)) u == v) → to-transp-out (to-transp-in B p q) == q to-transp-β B refl refl = refl -- Stuff that do not belong here ap-∘' : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) {x y z : A} (p : x == y) (q : y == z) → ap f (p ∘' q) == (ap f p ∘' ap f q) ap-∘' f refl refl = refl -- Dependent concatenation' _∘'dep_ : ∀ {i j} {A : Set i} {B : A → Set j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} → (u == v [ B ↓ p ] → v == w [ B ↓ p' ] → u == w [ B ↓ (p ∘' p') ]) _∘'dep_ {p' = refl} q refl = q -- Implementation of [_∘'_] on Σ Σ-∘' : ∀ {i j} {A : Set i} {B : A → Set j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ]) → (Σ-eq p q ∘' Σ-eq p' r) == Σ-eq (p ∘' p') (q ∘'dep r) Σ-∘' {p' = refl} q refl = refl -- No idea what that is to-transp-weird : ∀ {i j} {A : Set i} {B : A → Set j} {u v : A} {d : B u} {d' d'' : B v} {p : u == v} (q : d == d' [ B ↓ p ]) (r : π₁ (ua-out (ap B p)) d == d'') → (to-transp-in B p r ∘'dep (! r ∘ to-transp-out q)) == q to-transp-weird {p = refl} refl refl = refl _∘'2_ : ∀ {i j} {A : Set i} {B : A → Set j} {a b c : Π A B} {x y : A} {p : x == y} {q : a x == b x} {q' : a y == b y} {r : b x == c x} {r' : b y == c y} → (q == q' [ (λ z → a z == b z) ↓ p ]) → (r == r' [ (λ z → b z == c z) ↓ p ]) → (q ∘' r == q' ∘' r' [ (λ z → a z == c z) ↓ p ]) _∘'2_ {p = refl} refl refl = refl stuff : ∀ {i j} {A : Set i} {B : Set j} {b : B} {c : A → B} {d : A → B} (q : (a : A) → b == c a) (r : (a : A) → c a == d a) {a a' : A} (p : a == a') → apd (λ a → q a ∘' r a) p == ((apd q p) ∘'2 (apd r p)) stuff q r refl = refl apd= : ∀ {i j} {A : Set i} {B : A → Set j} {f g : Π A B} (q : (x : A) → f x == g x) {x y : A} (p : x == y) -- → (q x == q y [ (λ z → f z == g z) ↓ p ]) → (apd f p ▹ q y) == (q x ◃ apd g p) apd= q p = ! (↓-=-out (apd q p)) --apd= q refl =
35.625
145
0.388231
3815980be349b86c2fb4d628b8584cf57c463c6e
4,889
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/StrictToNonStrict.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Conversion of < to ≤, along with a number of properties ------------------------------------------------------------------------ -- Possible TODO: Prove that a conversion ≤ → < → ≤ returns a -- relation equivalent to the original one (and similarly for -- < → ≤ → <). {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Construct.StrictToNonStrict {a ℓ₁ ℓ₂} {A : Set a} (_≈_ : Rel A ℓ₁) (_<_ : Rel A ℓ₂) where open import Relation.Nullary open import Relation.Binary.Consequences open import Function open import Data.Product open import Data.Sum open import Data.Empty ------------------------------------------------------------------------ -- Conversion -- _<_ can be turned into _≤_ as follows: _≤_ : Rel A _ x ≤ y = (x < y) ⊎ (x ≈ y) ------------------------------------------------------------------------ -- The converted relations have certain properties -- (if the original relations have certain other properties) <⇒≤ : _<_ ⇒ _≤_ <⇒≤ = inj₁ reflexive : _≈_ ⇒ _≤_ reflexive = inj₂ antisym : IsEquivalence _≈_ → Transitive _<_ → Irreflexive _≈_ _<_ → Antisymmetric _≈_ _≤_ antisym eq trans irrefl = as where module Eq = IsEquivalence eq as : Antisymmetric _≈_ _≤_ as (inj₂ x≈y) _ = x≈y as (inj₁ _) (inj₂ y≈x) = Eq.sym y≈x as (inj₁ x<y) (inj₁ y<x) = ⊥-elim (trans∧irr⟶asym {_≈_ = _≈_} Eq.refl trans irrefl x<y y<x) trans : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ → Transitive _≤_ trans eq (respʳ , respˡ) <-trans = tr where module Eq = IsEquivalence eq tr : Transitive _≤_ tr (inj₁ x<y) (inj₁ y<z) = inj₁ $ <-trans x<y y<z tr (inj₁ x<y) (inj₂ y≈z) = inj₁ $ respʳ y≈z x<y tr (inj₂ x≈y) (inj₁ y<z) = inj₁ $ respˡ (Eq.sym x≈y) y<z tr (inj₂ x≈y) (inj₂ y≈z) = inj₂ $ Eq.trans x≈y y≈z <-≤-trans : Transitive _<_ → _<_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_ <-≤-trans trans respʳ x<y (inj₁ y<z) = trans x<y y<z <-≤-trans trans respʳ x<y (inj₂ y≈z) = respʳ y≈z x<y ≤-<-trans : Symmetric _≈_ → Transitive _<_ → _<_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_ ≤-<-trans sym trans respˡ (inj₁ x<y) y<z = trans x<y y<z ≤-<-trans sym trans respˡ (inj₂ x≈y) y<z = respˡ (sym x≈y) y<z ≤-respʳ-≈ : Transitive _≈_ → _<_ Respectsʳ _≈_ → _≤_ Respectsʳ _≈_ ≤-respʳ-≈ trans respʳ y'≈y (inj₁ x<y') = inj₁ (respʳ y'≈y x<y') ≤-respʳ-≈ trans respʳ y'≈y (inj₂ x≈y') = inj₂ (trans x≈y' y'≈y) ≤-respˡ-≈ : Symmetric _≈_ → Transitive _≈_ → _<_ Respectsˡ _≈_ → _≤_ Respectsˡ _≈_ ≤-respˡ-≈ sym trans respˡ x'≈x (inj₁ x'<y) = inj₁ (respˡ x'≈x x'<y) ≤-respˡ-≈ sym trans respˡ x'≈x (inj₂ x'≈y) = inj₂ (trans (sym x'≈x) x'≈y) ≤-resp-≈ : IsEquivalence _≈_ → _<_ Respects₂ _≈_ → _≤_ Respects₂ _≈_ ≤-resp-≈ eq (respʳ , respˡ) = ≤-respʳ-≈ Eq.trans respʳ , ≤-respˡ-≈ Eq.sym Eq.trans respˡ where module Eq = IsEquivalence eq total : Trichotomous _≈_ _<_ → Total _≤_ total <-tri x y with <-tri x y ... | tri< x<y x≉y x≯y = inj₁ (inj₁ x<y) ... | tri≈ x≮y x≈y x≯y = inj₁ (inj₂ x≈y) ... | tri> x≮y x≉y x>y = inj₂ (inj₁ x>y) decidable : Decidable _≈_ → Decidable _<_ → Decidable _≤_ decidable ≈-dec <-dec x y with ≈-dec x y | <-dec x y ... | yes x≈y | _ = yes (inj₂ x≈y) ... | no x≉y | yes x<y = yes (inj₁ x<y) ... | no x≉y | no x≮y = no [ x≮y , x≉y ]′ decidable' : Trichotomous _≈_ _<_ → Decidable _≤_ decidable' compare x y with compare x y ... | tri< x<y _ _ = yes (inj₁ x<y) ... | tri≈ _ x≈y _ = yes (inj₂ x≈y) ... | tri> x≮y x≉y _ = no [ x≮y , x≉y ]′ ------------------------------------------------------------------------ -- Converting structures isPreorder₁ : IsPreorder _≈_ _<_ → IsPreorder _≈_ _≤_ isPreorder₁ PO = record { isEquivalence = S.isEquivalence ; reflexive = reflexive ; trans = trans S.isEquivalence S.∼-resp-≈ S.trans } where module S = IsPreorder PO isPreorder₂ : IsStrictPartialOrder _≈_ _<_ → IsPreorder _≈_ _≤_ isPreorder₂ SPO = record { isEquivalence = S.isEquivalence ; reflexive = reflexive ; trans = trans S.isEquivalence S.<-resp-≈ S.trans } where module S = IsStrictPartialOrder SPO isPartialOrder : IsStrictPartialOrder _≈_ _<_ → IsPartialOrder _≈_ _≤_ isPartialOrder SPO = record { isPreorder = isPreorder₂ SPO ; antisym = antisym S.isEquivalence S.trans S.irrefl } where module S = IsStrictPartialOrder SPO isTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsTotalOrder _≈_ _≤_ isTotalOrder STO = record { isPartialOrder = isPartialOrder S.isStrictPartialOrder ; total = total S.compare } where module S = IsStrictTotalOrder STO isDecTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsDecTotalOrder _≈_ _≤_ isDecTotalOrder STO = record { isTotalOrder = isTotalOrder STO ; _≟_ = S._≟_ ; _≤?_ = decidable' S.compare } where module S = IsStrictTotalOrder STO
33.258503
88
0.586623
8b4b8d3a5c453e3b7c5db2b86033b48171e34e85
1,626
agda
Agda
src/Tactic/Reflection/Meta.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Tactic/Reflection/Meta.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Tactic/Reflection/Meta.agda
L-TChen/agda-prelude
158d299b1b365e186f00d8ef5b8c6844235ee267
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Tactic.Reflection.Meta where open import Prelude open import Builtin.Reflection open import Tactic.Reflection.DeBruijn ensureNoMetas : Term → TC ⊤ noMetaArg : Arg Term → TC ⊤ noMetaArg (arg _ v) = ensureNoMetas v noMetaArgs : List (Arg Term) → TC ⊤ noMetaArgs [] = pure _ noMetaArgs (v ∷ vs) = noMetaArg v *> noMetaArgs vs noMetaTel : List (String × Arg Type) → TC ⊤ noMetaTel [] = pure _ noMetaTel ((x , arg _ a) ∷ tel) = ensureNoMetas a *> noMetaTel tel noMetaClause : Clause → TC ⊤ noMetaClause (clause tel ps t) = noMetaTel tel *> ensureNoMetas t noMetaClause (absurd-clause tel ps) = pure _ noMetaClauses : List Clause → TC ⊤ noMetaClauses [] = pure _ noMetaClauses (c ∷ cs) = noMetaClause c *> noMetaClauses cs noMetaAbs : Abs Term → TC ⊤ noMetaAbs (abs _ v) = ensureNoMetas v noMetaSort : Sort → TC ⊤ noMetaSort (set t) = ensureNoMetas t noMetaSort (lit n) = pure _ noMetaSort (prop t) = ensureNoMetas t noMetaSort (propLit n) = pure _ noMetaSort (inf n) = pure _ noMetaSort unknown = pure _ ensureNoMetas (var x args) = noMetaArgs args ensureNoMetas (con c args) = noMetaArgs args ensureNoMetas (def f args) = noMetaArgs args ensureNoMetas (lam v (abs _ t)) = ensureNoMetas t ensureNoMetas (pat-lam cs args) = noMetaClauses cs *> noMetaArgs args ensureNoMetas (pi a b) = noMetaArg a *> noMetaAbs b ensureNoMetas (agda-sort s) = noMetaSort s ensureNoMetas (lit l) = pure _ ensureNoMetas (meta x x₁) = blockOnMeta x ensureNoMetas unknown = pure _ normaliseNoMetas : Term → TC Term normaliseNoMetas a = do a ← normalise a stripBoundNames a <$ ensureNoMetas a
30.111111
69
0.710947
c7268b46e91fa4db313656f69ddbb7e1352f6d15
19,867
agda
Agda
Definition/Untyped/Properties.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Definition/Untyped/Properties.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Definition/Untyped/Properties.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
-- Laws for weakenings and substitutions. {-# OPTIONS --without-K --safe #-} module Definition.Untyped.Properties where open import Definition.Untyped open import Tools.Nat open import Tools.List open import Tools.PropositionalEquality hiding (subst) -- Weakening properties -- Two weakenings ρ and ρ′ are extensionally equal if they agree on -- all arguments when interpreted as functions mapping variables to -- variables. Formally, they are considered equal iff -- -- (∀ x → wkVar ρ x ≡ wkVar ρ′ x) -- -- Intensional (propositional) equality would be too fine. For -- instance, -- -- lift id : Γ∙A ≤ Γ∙A -- -- is extensionally equal to -- -- id : Γ∙A ≤ Γ∙A -- -- but syntactically different. -- "lift" preserves equality of weakenings. Or: -- If two weakenings are equal under wkVar, then they are equal when lifted. wkVar-lift : ∀ {ρ ρ′} → (∀ x → wkVar ρ x ≡ wkVar ρ′ x) → (∀ x → wkVar (lift ρ) x ≡ wkVar (lift ρ′) x) wkVar-lift eq 0 = refl wkVar-lift eq (1+ x) = cong 1+ (eq x) wkVar-lifts : ∀ {ρ ρ′} → (∀ x → wkVar ρ x ≡ wkVar ρ′ x) → (∀ n x → wkVar (repeat lift ρ n) x ≡ wkVar (repeat lift ρ′ n) x) wkVar-lifts eq 0 x = eq x wkVar-lifts eq (1+ n) x = wkVar-lift (wkVar-lifts eq n) x -- Extensionally equal weakenings, if applied to a term, -- yield the same weakened term. Or: -- If two weakenings are equal under wkVar, then they are equal under wk. mutual wkVar-to-wk : ∀ {ρ ρ′} → (∀ x → wkVar ρ x ≡ wkVar ρ′ x) → ∀ t → wk ρ t ≡ wk ρ′ t wkVar-to-wk eq (var x) = cong var (eq x) wkVar-to-wk eq (gen x c) = cong (gen x) (wkVar-to-wkGen eq c) wkVar-to-wkGen : ∀ {ρ ρ′} → (∀ x → wkVar ρ x ≡ wkVar ρ′ x) → ∀ t → wkGen ρ t ≡ wkGen ρ′ t wkVar-to-wkGen eq [] = refl wkVar-to-wkGen eq (⟦ l , t ⟧ ∷ g) = cong₂ _∷_ (cong (⟦_,_⟧ l) (wkVar-to-wk (wkVar-lifts eq l) t)) (wkVar-to-wkGen eq g) -- lift id is extensionally equal to id. wkVar-lift-id : (x : Nat) → wkVar (lift id) x ≡ wkVar id x wkVar-lift-id 0 = refl wkVar-lift-id (1+ x) = refl wkVar-lifts-id : (n x : Nat) → wkVar (repeat lift id n) x ≡ wkVar id x wkVar-lifts-id 0 x = refl wkVar-lifts-id (1+ n) 0 = refl wkVar-lifts-id (1+ n) (1+ x) = cong 1+ (wkVar-lifts-id n x) -- id is the identity renaming. wkVar-id : (x : Nat) → wkVar id x ≡ x wkVar-id x = refl mutual wk-id : (t : Term) → wk id t ≡ t wk-id (var x) = refl wk-id (gen x c) = cong (gen x) (wkGen-id c) wkGen-id : ∀ x → wkGen id x ≡ x wkGen-id [] = refl wkGen-id (⟦ l , t ⟧ ∷ g) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wkVar-to-wk (wkVar-lifts-id l) t) (wk-id t))) (wkGen-id g) -- lift id is also the identity renaming. wk-lift-id : (t : Term) → wk (lift id) t ≡ t wk-lift-id t = trans (wkVar-to-wk wkVar-lift-id t) (wk-id t) -- The composition of weakenings is correct... -- -- ...as action on variables. wkVar-comp : ∀ ρ ρ′ x → wkVar ρ (wkVar ρ′ x) ≡ wkVar (ρ • ρ′) x wkVar-comp id ρ′ x = refl wkVar-comp (step ρ) ρ′ x = cong 1+ (wkVar-comp ρ ρ′ x) wkVar-comp (lift ρ) id x = refl wkVar-comp (lift ρ) (step ρ′) x = cong 1+ (wkVar-comp ρ ρ′ x) wkVar-comp (lift ρ) (lift ρ′) 0 = refl wkVar-comp (lift ρ) (lift ρ′) (1+ x) = cong 1+ (wkVar-comp ρ ρ′ x) wkVar-comps : ∀ n ρ ρ′ x → wkVar (repeat lift ρ n • repeat lift ρ′ n) x ≡ wkVar (repeat lift (ρ • ρ′) n) x wkVar-comps 0 ρ ρ′ x = refl wkVar-comps (1+ n) ρ ρ′ 0 = refl wkVar-comps (1+ n) ρ ρ′ (1+ x) = cong 1+ (wkVar-comps n ρ ρ′ x) -- ... as action on terms. mutual wk-comp : ∀ ρ ρ′ t → wk ρ (wk ρ′ t) ≡ wk (ρ • ρ′) t wk-comp ρ ρ′ (var x) = cong var (wkVar-comp ρ ρ′ x) wk-comp ρ ρ′ (gen x c) = cong (gen x) (wkGen-comp ρ ρ′ c) wkGen-comp : ∀ ρ ρ′ g → wkGen ρ (wkGen ρ′ g) ≡ wkGen (ρ • ρ′) g wkGen-comp ρ ρ′ [] = refl wkGen-comp ρ ρ′ (⟦ l , t ⟧ ∷ g) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-comp (repeat lift ρ l) (repeat lift ρ′ l) t) (wkVar-to-wk (wkVar-comps l ρ ρ′) t))) (wkGen-comp ρ ρ′ g) -- The following lemmata are variations on the equality -- -- wk1 ∘ ρ = lift ρ ∘ wk1. -- -- Typing: Γ∙A ≤ Γ ≤ Δ <==> Γ∙A ≤ Δ∙A ≤ Δ. lift-step-comp : (ρ : Wk) → step id • ρ ≡ lift ρ • step id lift-step-comp id = refl lift-step-comp (step ρ) = cong step (lift-step-comp ρ) lift-step-comp (lift ρ) = refl wk1-wk : ∀ ρ t → wk1 (wk ρ t) ≡ wk (step ρ) t wk1-wk ρ t = wk-comp (step id) ρ t lift-wk1 : ∀ ρ t → wk (lift ρ) (wk1 t) ≡ wk (step ρ) t lift-wk1 pr A = trans (wk-comp (lift pr) (step id) A) (sym (cong (λ x → wk x A) (lift-step-comp pr))) wk1-wk≡lift-wk1 : ∀ ρ t → wk1 (wk ρ t) ≡ wk (lift ρ) (wk1 t) wk1-wk≡lift-wk1 ρ t = trans (wk1-wk ρ t) (sym (lift-wk1 ρ t)) -- Substitution properties. -- Two substitutions σ and σ′ are equal if they are pointwise equal, -- i.e., agree on all variables. -- -- ∀ x → σ x ≡ σ′ x -- If σ = σ′ then lift σ = lift σ′. substVar-lift : ∀ {σ σ′} → (∀ x → σ x ≡ σ′ x) → ∀ x → liftSubst σ x ≡ liftSubst σ′ x substVar-lift eq 0 = refl substVar-lift eq (1+ x) = cong wk1 (eq x) substVar-lifts : ∀ {σ σ′} → (∀ x → σ x ≡ σ′ x) → ∀ n x → repeat liftSubst σ n x ≡ repeat liftSubst σ′ n x substVar-lifts eq 0 x = eq x substVar-lifts eq (1+ n) 0 = refl substVar-lifts eq (1+ n) (1+ x) = cong wk1 (substVar-lifts eq n x) -- If σ = σ′ then subst σ t = subst σ′ t. mutual substVar-to-subst : ∀ {σ σ′} → ((x : Nat) → σ x ≡ σ′ x) → (t : Term) → subst σ t ≡ subst σ′ t substVar-to-subst eq (var x) = eq x substVar-to-subst eq (gen x c) = cong (gen x) (substVar-to-substGen eq c) substVar-to-substGen : ∀ {σ σ′} → ((x : Nat) → σ x ≡ σ′ x) → ∀ g → substGen σ g ≡ substGen σ′ g substVar-to-substGen eq [] = refl substVar-to-substGen eq (⟦ l , t ⟧ ∷ g) = cong₂ _∷_ (cong (⟦_,_⟧ l) (substVar-to-subst (substVar-lifts eq l) t)) (substVar-to-substGen eq g) -- lift id = id (as substitutions) subst-lift-id : (x : Nat) → (liftSubst idSubst) x ≡ idSubst x subst-lift-id 0 = refl subst-lift-id (1+ x) = refl subst-lifts-id : (n x : Nat) → (repeat liftSubst idSubst n) x ≡ idSubst x subst-lifts-id 0 x = refl subst-lifts-id (1+ n) 0 = refl subst-lifts-id (1+ n) (1+ x) = cong wk1 (subst-lifts-id n x) -- Identity substitution. mutual subst-id : (t : Term) → subst idSubst t ≡ t subst-id (var x) = refl subst-id (gen x c) = cong (gen x) (substGen-id c) substGen-id : ∀ g → substGen idSubst g ≡ g substGen-id [] = refl substGen-id (⟦ l , t ⟧ ∷ g) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substVar-to-subst (subst-lifts-id l) t) (subst-id t))) (substGen-id g) -- Correctness of composition of weakening and substitution. -- Composition of liftings is lifting of the composition. -- lift ρ •ₛ lift σ = lift (ρ •ₛ σ) subst-lift-•ₛ : ∀ {ρ σ} t → subst (lift ρ •ₛ liftSubst σ) t ≡ subst (liftSubst (ρ •ₛ σ)) t subst-lift-•ₛ = substVar-to-subst (λ { 0 → refl ; (1+ x) → sym (wk1-wk≡lift-wk1 _ _)}) helper1 : ∀ {ρ σ} (n x : Nat) → (lift (repeat lift ρ n) •ₛ liftSubst (repeat liftSubst σ n)) x ≡ liftSubst (repeat liftSubst (ρ •ₛ σ) n) x helper1 0 0 = refl helper1 0 (1+ x) = sym (wk1-wk≡lift-wk1 _ _) helper1 (1+ n) 0 = refl helper1 (1+ n) (1+ x) = trans (sym (wk1-wk≡lift-wk1 _ _)) (cong wk1 (helper1 n x)) subst-lifts-•ₛ : ∀ {ρ σ} n t → subst (repeat lift ρ n •ₛ repeat liftSubst σ n) t ≡ subst (repeat liftSubst (ρ •ₛ σ) n) t subst-lifts-•ₛ 0 t = refl subst-lifts-•ₛ (1+ n) t = substVar-to-subst (helper1 n) t -- lift σ ₛ• lift ρ = lift (σ ₛ• ρ) subst-lift-ₛ• : ∀ {ρ σ} t → subst (liftSubst σ ₛ• lift ρ) t ≡ subst (liftSubst (σ ₛ• ρ)) t subst-lift-ₛ• = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) helper2 : ∀ {ρ σ} (n x : Nat) → liftSubst (repeat liftSubst σ n) (wkVar (lift (repeat lift ρ n)) x) ≡ liftSubst (repeat liftSubst (λ x₁ → σ (wkVar ρ x₁)) n) x helper2 0 0 = refl helper2 0 (1+ x) = refl helper2 (1+ n) 0 = refl helper2 (1+ n) (1+ x) = cong wk1 (helper2 n x) subst-lifts-ₛ• : ∀ {ρ σ} n t → subst (repeat liftSubst σ n ₛ• repeat lift ρ n) t ≡ subst (repeat liftSubst (σ ₛ• ρ) n) t subst-lifts-ₛ• 0 t = refl subst-lifts-ₛ• (1+ n) t = substVar-to-subst (helper2 n) t -- wk ρ ∘ subst σ = subst (ρ •ₛ σ) mutual wk-subst : ∀ {ρ σ} t → wk ρ (subst σ t) ≡ subst (ρ •ₛ σ) t wk-subst (var x) = refl wk-subst (gen x c) = cong (gen x) (wkGen-substGen c) wkGen-substGen : ∀ {ρ σ} t → wkGen ρ (substGen σ t) ≡ substGen (ρ •ₛ σ) t wkGen-substGen [] = refl wkGen-substGen (⟦ l , t ⟧ ∷ c) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-subst t) (subst-lifts-•ₛ l t))) (wkGen-substGen c) -- subst σ ∘ wk ρ = subst (σ •ₛ ρ) mutual subst-wk : ∀ {ρ σ} t → subst σ (wk ρ t) ≡ subst (σ ₛ• ρ) t subst-wk (var x) = refl subst-wk (gen x c) = cong (gen x) (substGen-wkGen c) substGen-wkGen : ∀ {ρ σ} t → substGen σ (wkGen ρ t) ≡ substGen (σ ₛ• ρ) t substGen-wkGen [] = refl substGen-wkGen (⟦ l , t ⟧ ∷ c) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (subst-wk t) (subst-lifts-ₛ• l t))) (substGen-wkGen c) -- Composition of liftings is lifting of the composition. wk-subst-lift : ∀ {ρ σ} G → wk (lift ρ) (subst (liftSubst σ) G) ≡ subst (liftSubst (ρ •ₛ σ)) G wk-subst-lift G = trans (wk-subst G) (subst-lift-•ₛ G) -- Renaming with ρ is the same as substituting with ρ turned into a substitution. wk≡subst : ∀ ρ t → wk ρ t ≡ subst (toSubst ρ) t wk≡subst ρ t = trans (cong (wk ρ) (sym (subst-id t))) (wk-subst t) -- Composition of substitutions. -- Composition of liftings is lifting of the composition. substCompLift : ∀ {σ σ′} x → (liftSubst σ ₛ•ₛ liftSubst σ′) x ≡ (liftSubst (σ ₛ•ₛ σ′)) x substCompLift 0 = refl substCompLift {σ} {σ′} (1+ x) = trans (subst-wk (σ′ x)) (sym (wk-subst (σ′ x))) substCompLifts : ∀ {σ σ′} n x → (repeat liftSubst σ n ₛ•ₛ repeat liftSubst σ′ n) x ≡ (repeat liftSubst (σ ₛ•ₛ σ′) n) x substCompLifts 0 x = refl substCompLifts (1+ n) 0 = refl substCompLifts {σ} {σ′} (1+ n) (1+ x) = trans (substCompLift {repeat liftSubst σ n} {repeat liftSubst σ′ n} (1+ x)) (cong wk1 (substCompLifts n x)) -- Soundness of the composition of substitutions. mutual substCompEq : ∀ {σ σ′} (t : Term) → subst σ (subst σ′ t) ≡ subst (σ ₛ•ₛ σ′) t substCompEq (var x) = refl substCompEq (gen x c) = cong (gen x) (substGenCompEq c) substGenCompEq : ∀ {σ σ′} t → substGen σ (substGen σ′ t) ≡ substGen (σ ₛ•ₛ σ′) t substGenCompEq [] = refl substGenCompEq (⟦ l , t ⟧ ∷ c) = cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substCompEq t) (substVar-to-subst (substCompLifts l) t))) (substGenCompEq c) -- Weakening single substitutions. -- Pulling apart a weakening composition in specific context _[a]. wk-comp-subst : ∀ {a} ρ ρ′ G → wk (lift (ρ • ρ′)) G [ a ] ≡ wk (lift ρ) (wk (lift ρ′) G) [ a ] wk-comp-subst {a} ρ ρ′ G = cong (λ x → x [ a ]) (sym (wk-comp (lift ρ) (lift ρ′) G)) -- Pushing a weakening into a single substitution. -- ρ (t[a]) = ((lift ρ) t)[ρ a] wk-β : ∀ {ρ a} t → wk ρ (t [ a ]) ≡ wk (lift ρ) t [ wk ρ a ] wk-β t = trans (wk-subst t) (sym (trans (subst-wk t) (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t))) -- Pushing a weakening into a single shifting substitution. -- If ρ′ = lift ρ then ρ′(t[a]↑) = ρ′(t) [ρ′(a)]↑ wk-β↑ : ∀ {ρ a} t → wk (lift ρ) (t [ a ]↑) ≡ wk (lift ρ) t [ wk (lift ρ) a ]↑ wk-β↑ t = trans (wk-subst t) (sym (trans (subst-wk t) (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t))) -- A specific equation on weakenings used for the reduction of natrec. wk-β-natrec : ∀ ρ G → Π ℕ ▹ (Π wk (lift ρ) G ▹ wk (lift (lift ρ)) (wk1 (G [ suc (var 0) ]↑))) ≡ Π ℕ ▹ (wk (lift ρ) G ▹▹ wk (lift ρ) G [ suc (var 0) ]↑) wk-β-natrec ρ G = cong₂ Π_▹_ refl (cong₂ Π_▹_ refl (trans (wk-comp (lift (lift ρ)) (step id) (subst (consSubst (wk1Subst var) (suc (var 0))) G)) (trans (wk-subst G) (sym (trans (wk-subst (wk (lift ρ) G)) (trans (subst-wk G) (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G))))))) -- Composing a singleton substitution and a lifted substitution. -- sg u ∘ lift σ = cons id u ∘ lift σ = cons σ u substVarSingletonComp : ∀ {u σ} (x : Nat) → (sgSubst u ₛ•ₛ liftSubst σ) x ≡ (consSubst σ u) x substVarSingletonComp 0 = refl substVarSingletonComp {σ = σ} (1+ x) = trans (subst-wk (σ x)) (subst-id (σ x)) -- The same again, as action on a term t. substSingletonComp : ∀ {a σ} t → subst (sgSubst a ₛ•ₛ liftSubst σ) t ≡ subst (consSubst σ a) t substSingletonComp = substVar-to-subst substVarSingletonComp -- A single substitution after a lifted substitution. -- ((lift σ) G)[t] = (cons σ t)(G) singleSubstComp : ∀ t σ G → (subst (liftSubst σ) G) [ t ] ≡ subst (consSubst σ t) G singleSubstComp t σ G = trans (substCompEq G) (substSingletonComp G) -- A single substitution after a lifted substitution (with weakening). -- ((lift (ρ ∘ σ)) G)[t] = (cons (ρ ∘ σ) t)(G) singleSubstWkComp : ∀ {ρ} t σ G → wk (lift ρ) (subst (liftSubst σ) G) [ t ] ≡ subst (consSubst (ρ •ₛ σ) t) G singleSubstWkComp t σ G = trans (cong (subst (consSubst var t)) (trans (wk-subst G) (subst-lift-•ₛ G))) (trans (substCompEq G) (substSingletonComp G)) -- Pushing a substitution into a single substitution. singleSubstLift : ∀ {σ} G t → subst σ (G [ t ]) ≡ subst (liftSubst σ) G [ subst σ t ] singleSubstLift G t = trans (substCompEq G) (trans (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G) (sym (substSingletonComp G))) (sym (substCompEq G))) -- More specific laws. idWkLiftSubstLemma : ∀ σ G → wk (lift (step id)) (subst (liftSubst σ) G) [ var 0 ] ≡ subst (liftSubst σ) G idWkLiftSubstLemma σ G = trans (singleSubstWkComp (var 0) σ G) (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G) substVarComp↑ : ∀ {t} σ x → (consSubst (wk1Subst idSubst) (subst (liftSubst σ) t) ₛ•ₛ liftSubst σ) x ≡ (liftSubst σ ₛ•ₛ consSubst (wk1Subst idSubst) t) x substVarComp↑ σ 0 = refl substVarComp↑ σ (1+ x) = trans (subst-wk (σ x)) (sym (wk≡subst (step id) (σ x))) singleSubstLift↑ : ∀ σ G t → subst (liftSubst σ) (G [ t ]↑) ≡ subst (liftSubst σ) G [ subst (liftSubst σ) t ]↑ singleSubstLift↑ σ G t = trans (substCompEq G) (sym (trans (substCompEq G) (substVar-to-subst (substVarComp↑ σ) G))) substConsComp : ∀ {σ t G} → subst (consSubst (λ x → σ (1+ x)) (subst (tail σ) t)) G ≡ subst σ (subst (consSubst (λ x → var (1+ x)) (wk1 t)) G) substConsComp {t = t} {G = G} = trans (substVar-to-subst (λ { 0 → sym (subst-wk t) ; (1+ x) → refl }) G) (sym (substCompEq G)) wkSingleSubstId : ∀ F → (wk (lift (step id)) F) [ var 0 ] ≡ F wkSingleSubstId F = trans (subst-wk F) (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) F) (subst-id F)) cons-wk-subst : ∀ ρ σ a t → subst (sgSubst a ₛ• lift ρ ₛ•ₛ liftSubst σ) t ≡ subst (consSubst (ρ •ₛ σ) a) t cons-wk-subst ρ σ a = substVar-to-subst (λ { 0 → refl ; (1+ x) → trans (subst-wk (σ x)) (sym (wk≡subst ρ (σ x))) }) natrecSucCaseLemma : ∀ {σ} (x : Nat) → (step id •ₛ consSubst (wk1Subst idSubst) (suc (var 0)) ₛ•ₛ liftSubst σ) x ≡ (liftSubst (liftSubst σ) ₛ• step id ₛ•ₛ consSubst (wk1Subst idSubst) (suc (var 0))) x natrecSucCaseLemma 0 = refl natrecSucCaseLemma {σ} (1+ x) = trans (subst-wk (σ x)) (sym (trans (wk1-wk (step id) _) (wk≡subst (step (step id)) (σ x)))) natrecSucCase : ∀ σ F → Π ℕ ▹ (Π subst (liftSubst σ) F ▹ subst (liftSubst (liftSubst σ)) (wk1 (F [ suc (var 0) ]↑))) ≡ Π ℕ ▹ (subst (liftSubst σ) F ▹▹ subst (liftSubst σ) F [ suc (var 0) ]↑) natrecSucCase σ F = cong₂ Π_▹_ refl (cong₂ Π_▹_ refl (trans (trans (subst-wk (F [ suc (var 0) ]↑)) (substCompEq F)) (sym (trans (wk-subst (subst (liftSubst σ) F)) (trans (substCompEq F) (substVar-to-subst natrecSucCaseLemma F)))))) natrecIrrelevantSubstLemma : ∀ F z s m σ (x : Nat) → (sgSubst (natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m) ₛ•ₛ liftSubst (sgSubst m) ₛ•ₛ liftSubst (liftSubst σ) ₛ• step id ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x ≡ (consSubst σ (suc m)) x natrecIrrelevantSubstLemma F z s m σ 0 = cong suc (trans (subst-wk m) (subst-id m)) natrecIrrelevantSubstLemma F z s m σ (1+ x) = trans (subst-wk (wk (step id) (σ x))) (trans (subst-wk (σ x)) (subst-id (σ x))) natrecIrrelevantSubst : ∀ F z s m σ → subst (consSubst σ (suc m)) F ≡ subst (liftSubst (sgSubst m)) (subst (liftSubst (liftSubst σ)) (wk1 (F [ suc (var 0) ]↑))) [ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m ] natrecIrrelevantSubst F z s m σ = sym (trans (substCompEq (subst (liftSubst (liftSubst σ)) (wk (step id) (subst (consSubst (tail idSubst) (suc (var 0))) F)))) (trans (substCompEq (wk (step id) (subst (consSubst (tail idSubst) (suc (var 0))) F))) (trans (subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F)) (trans (substCompEq F) (substVar-to-subst (natrecIrrelevantSubstLemma F z s m σ) F))))) natrecIrrelevantSubstLemma′ : ∀ F z s n (x : Nat) → (sgSubst (natrec F z s n) ₛ•ₛ liftSubst (sgSubst n) ₛ• step id ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x ≡ (consSubst var (suc n)) x natrecIrrelevantSubstLemma′ F z s n 0 = cong suc (trans (subst-wk n) (subst-id n)) natrecIrrelevantSubstLemma′ F z s n (1+ x) = refl natrecIrrelevantSubst′ : ∀ F z s n → subst (liftSubst (sgSubst n)) (wk1 (F [ suc (var 0) ]↑)) [ natrec F z s n ] ≡ F [ suc n ] natrecIrrelevantSubst′ F z s n = trans (substCompEq (wk (step id) (subst (consSubst (tail idSubst) (suc (var 0))) F))) (trans (subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F)) (trans (substCompEq F) (substVar-to-subst (natrecIrrelevantSubstLemma′ F z s n) F))) cons0wkLift1-id : ∀ σ G → subst (sgSubst (var 0)) (wk (lift (step id)) (subst (liftSubst σ) G)) ≡ subst (liftSubst σ) G cons0wkLift1-id σ G = trans (subst-wk (subst (liftSubst σ) G)) (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl }) (subst (liftSubst σ) G)) (subst-id (subst (liftSubst σ) G))) substConsId : ∀ {σ t} G → subst (consSubst σ (subst σ t)) G ≡ subst σ (subst (sgSubst t) G) substConsId G = sym (trans (substCompEq G) (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)) substConsTailId : ∀ {G t σ} → subst (consSubst (tail σ) (subst σ t)) G ≡ subst σ (subst (consSubst (tail idSubst) t) G) substConsTailId {G} {t} {σ} = trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl }) G) (sym (substCompEq G)) substConcatSingleton′ : ∀ {a σ} t → subst (σ ₛ•ₛ sgSubst a) t ≡ subst (consSubst σ (subst σ a)) t substConcatSingleton′ t = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t wk1-tailId : ∀ t → wk1 t ≡ subst (tail idSubst) t wk1-tailId t = trans (sym (subst-id (wk1 t))) (subst-wk t)
34.793345
90
0.55947
41d5ee072c55102d3ac4ce8f2a3046cb1fef0f8e
13,946
agda
Agda
src/Integer.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Integer.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Integer.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Integers ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Integer {e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq open import Prelude as P hiding (suc) renaming (_+_ to _⊕_; _*_ to _⊛_) open import Bijection eq using (_↔_) open import Equivalence eq as Eq using (_≃_) open import Function-universe eq hiding (_∘_) open import Group eq using (Group; Abelian) open import H-level eq open import H-level.Closure eq import Nat eq as Nat open import Integer.Basics eq public private variable i j : ℤ ------------------------------------------------------------------------ -- Some lemmas -- The sum of i and - i is zero. +-right-inverse : ∀ i → i + - i ≡ + 0 +-right-inverse = λ where (+ zero) → refl _ (+ P.suc n) → lemma n -[1+ n ] → lemma n where lemma : ∀ n → + P.suc n +-[1+ n ] ≡ + 0 lemma n with P.suc n Nat.<= n | T[<=]↔≤ {m = P.suc n} {n = n} … | false | _ = cong (+_) $ Nat.∸≡0 n … | true | eq = ⊥-elim $ Nat.<-irreflexive (_↔_.to eq _) -- The sum of - i and i is zero. +-left-inverse : ∀ i → - i + i ≡ + 0 +-left-inverse i = - i + i ≡⟨ +-comm (- i) ⟩ i + - i ≡⟨ +-right-inverse i ⟩∎ + 0 ∎ -- + 0 is a left identity for addition. +-left-identity : + 0 + i ≡ i +-left-identity {i = + _} = refl _ +-left-identity {i = -[1+ _ ]} = refl _ -- + 0 is a right identity for addition. +-right-identity : i + + 0 ≡ i +-right-identity {i = + _} = cong (+_) Nat.+-right-identity +-right-identity {i = -[1+ _ ]} = refl _ -- Addition is associative. +-assoc : ∀ i {j k} → i + (j + k) ≡ (i + j) + k +-assoc = λ where (+ m) {j = + _} {k = + _} → cong (+_) $ Nat.+-assoc m -[1+ m ] {j = -[1+ n ]} {k = -[1+ o ]} → cong (-[1+_] ∘ P.suc) (m ⊕ P.suc (n ⊕ o) ≡⟨ sym $ Nat.suc+≡+suc m ⟩ P.suc m ⊕ (n ⊕ o) ≡⟨ Nat.+-assoc (P.suc m) ⟩∎ (P.suc m ⊕ n) ⊕ o ∎) -[1+ m ] {j = + n} {k = + o} → sym $ ++-[1+]++ _ n _ (+ m) {j = -[1+ n ]} {k = -[1+ o ]} → sym $ ++-[1+]+-[1+] m _ _ (+ m) {j = + n} {k = -[1+ o ]} → lemma₁ m _ _ (+ m) {j = -[1+ n ]} {k = + o} → lemma₂ m _ _ -[1+ m ] {j = -[1+ n ]} {k = + o} → lemma₃ _ o _ -[1+ m ] {j = + n} {k = -[1+ o ]} → lemma₄ _ n _ where ++-[1+]++ : ∀ m n o → + n +-[1+ m ] + + o ≡ (+ (n ⊕ o) +-[1+ m ]) ++-[1+]++ m zero o = refl _ ++-[1+]++ zero (P.suc n) o = refl _ ++-[1+]++ (P.suc m) (P.suc n) o = ++-[1+]++ m n o ++-[1+]+-[1+] : ∀ m n o → + m +-[1+ n ] + -[1+ o ] ≡ (+ m +-[1+ 1 ⊕ n ⊕ o ]) ++-[1+]+-[1+] zero n o = refl _ ++-[1+]+-[1+] (P.suc m) zero o = refl _ ++-[1+]+-[1+] (P.suc m) (P.suc n) o = ++-[1+]+-[1+] m n o lemma₁ : ∀ m n o → + m + (+ n +-[1+ o ]) ≡ (+ m ⊕ n +-[1+ o ]) lemma₁ m n o = + m + (+ n +-[1+ o ]) ≡⟨ +-comm (+ m) {j = + n +-[1+ o ]} ⟩ (+ n +-[1+ o ]) + + m ≡⟨ ++-[1+]++ _ n _ ⟩ (+ n ⊕ m +-[1+ o ]) ≡⟨ cong +_+-[1+ o ] $ Nat.+-comm n ⟩∎ (+ m ⊕ n +-[1+ o ]) ∎ lemma₂ : ∀ m n o → + m + (+ n +-[1+ o ]) ≡ (+ m +-[1+ o ]) + + n lemma₂ m n o = + m + (+ n +-[1+ o ]) ≡⟨ lemma₁ m n o ⟩ (+ m ⊕ n +-[1+ o ]) ≡⟨ sym $ ++-[1+]++ _ m _ ⟩∎ (+ m +-[1+ o ]) + + n ∎ lemma₃ : ∀ m n o → -[1+ m ] + (+ n +-[1+ o ]) ≡ (+ n +-[1+ 1 ⊕ m ⊕ o ]) lemma₃ m n o = -[1+ m ] + (+ n +-[1+ o ]) ≡⟨ +-comm -[1+ m ] {j = + n +-[1+ o ]} ⟩ (+ n +-[1+ o ]) + -[1+ m ] ≡⟨ ++-[1+]+-[1+] n o m ⟩ (+ n +-[1+ 1 ⊕ o ⊕ m ]) ≡⟨ cong + n +-[1+_] $ cong (1 ⊕_) $ Nat.+-comm o ⟩∎ (+ n +-[1+ 1 ⊕ m ⊕ o ]) ∎ lemma₄ : ∀ m n o → -[1+ m ] + (+ n +-[1+ o ]) ≡ (+ n +-[1+ m ]) + -[1+ o ] lemma₄ m n o = -[1+ m ] + (+ n +-[1+ o ]) ≡⟨ lemma₃ m n o ⟩ (+ n +-[1+ 1 ⊕ m ⊕ o ]) ≡⟨ sym $ ++-[1+]+-[1+] n _ _ ⟩∎ (+ n +-[1+ m ]) + -[1+ o ] ∎ ------------------------------------------------------------------------ -- Successor and predecessor -- The successor function. suc : ℤ → ℤ suc (+ n) = + P.suc n suc -[1+ zero ] = + zero suc -[1+ P.suc n ] = -[1+ n ] -- The successor function adds one to its input. suc≡1+ : ∀ i → suc i ≡ + 1 + i suc≡1+ (+ _) = refl _ suc≡1+ -[1+ zero ] = refl _ suc≡1+ -[1+ P.suc _ ] = refl _ -- The predecessor function. pred : ℤ → ℤ pred (+ zero) = -[1+ zero ] pred (+ P.suc n) = + n pred -[1+ n ] = -[1+ P.suc n ] -- The predecessor function adds minus one to its input. pred≡-1+ : ∀ i → pred i ≡ -[ 1 ] + i pred≡-1+ (+ zero) = refl _ pred≡-1+ (+ P.suc _) = refl _ pred≡-1+ -[1+ _ ] = refl _ -- An equivalence between ℤ and ℤ corresponding to the successor -- function. successor : ℤ ≃ ℤ successor = Eq.↔→≃ suc pred suc-pred pred-suc where suc-pred : ∀ i → suc (pred i) ≡ i suc-pred (+ zero) = refl _ suc-pred (+ P.suc _) = refl _ suc-pred -[1+ _ ] = refl _ pred-suc : ∀ i → pred (suc i) ≡ i pred-suc (+ _) = refl _ pred-suc -[1+ zero ] = refl _ pred-suc -[1+ P.suc _ ] = refl _ ------------------------------------------------------------------------ -- Positive, negative -- The property of being positive. Positive : ℤ → Type Positive (+ zero) = ⊥ Positive (+ P.suc _) = ⊤ Positive -[1+ _ ] = ⊥ -- Positive is propositional. Positive-propositional : Is-proposition (Positive i) Positive-propositional {i = + zero} = ⊥-propositional Positive-propositional {i = + P.suc _} = mono₁ 0 ⊤-contractible Positive-propositional {i = -[1+ _ ]} = ⊥-propositional -- The property of being negative. Negative : ℤ → Type Negative (+ _) = ⊥ Negative -[1+ _ ] = ⊤ -- Negative is propositional. Negative-propositional : Is-proposition (Negative i) Negative-propositional {i = + _} = ⊥-propositional Negative-propositional {i = -[1+ _ ]} = mono₁ 0 ⊤-contractible -- No integer is both positive and negative. ¬+- : Positive i → Negative i → ⊥₀ ¬+- {i = + _} _ neg = neg ¬+- {i = -[1+ _ ]} pos _ = pos -- No integer is both positive and equal to zero. ¬+0 : Positive i → i ≡ + 0 → ⊥₀ ¬+0 {i = + zero} pos _ = pos ¬+0 {i = + P.suc _} _ ≡0 = Nat.0≢+ $ sym $ +-cancellative ≡0 ¬+0 {i = -[1+ _ ]} pos _ = pos -- No integer is both negative and equal to zero. ¬-0 : Negative i → i ≡ + 0 → ⊥₀ ¬-0 {i = + _} neg _ = neg ¬-0 {i = -[1+ _ ]} _ ≡0 = +≢-[1+] $ sym ≡0 -- One can decide if an integer is negative, zero or positive. -⊎0⊎+ : ∀ i → Negative i ⊎ i ≡ + 0 ⊎ Positive i -⊎0⊎+ (+ zero) = inj₂ (inj₁ (refl _)) -⊎0⊎+ (+ P.suc _) = inj₂ (inj₂ _) -⊎0⊎+ -[1+ _ ] = inj₁ _ -- If i and j are positive, then i + j is positive. >0→>0→+>0 : ∀ i j → Positive i → Positive j → Positive (i + j) >0→>0→+>0 (+ P.suc _) (+ P.suc _) _ _ = _ -- If i and j are negative, then i + j is negative. <0→<0→+<0 : ∀ i j → Negative i → Negative j → Negative (i + j) <0→<0→+<0 -[1+ _ ] -[1+ _ ] _ _ = _ ------------------------------------------------------------------------ -- The group of integers -- The group of integers. ℤ-group : Group lzero ℤ-group .Group.Carrier = ℤ ℤ-group .Group.Carrier-is-set = ℤ-set ℤ-group .Group._∘_ = _+_ ℤ-group .Group.id = + 0 ℤ-group .Group._⁻¹ = -_ ℤ-group .Group.left-identity _ = +-left-identity ℤ-group .Group.right-identity _ = +-right-identity ℤ-group .Group.assoc i _ _ = +-assoc i ℤ-group .Group.right-inverse = +-right-inverse ℤ-group .Group.left-inverse = +-left-inverse -- The group of integers is abelian. ℤ-abelian : Abelian ℤ-group ℤ-abelian i _ = +-comm i private module ℤG = Group ℤ-group open ℤG public using () renaming (_^+_ to infixl 7 _*+_; _^_ to infixl 7 _*_) -- + 1 is a left identity for multiplication. *-left-identity : ∀ i → + 1 * i ≡ i *-left-identity = lemma where +lemma : ∀ n → + 1 *+ n ≡ + n +lemma zero = refl _ +lemma (P.suc n) = + 1 + (+ 1) *+ n ≡⟨ cong (λ i → + 1 + i) $ +lemma n ⟩ + 1 + + n ≡⟨⟩ + P.suc n ∎ -lemma : ∀ n → -[ 1 ] *+ n ≡ -[ n ] -lemma zero = refl _ -lemma (P.suc zero) = refl _ -lemma (P.suc (P.suc n)) = -[ 1 ] + -[ 1 ] *+ P.suc n ≡⟨ cong (λ i → -[ 1 ] + i) $ -lemma (P.suc n) ⟩ -[ 1 ] + -[ P.suc n ] ≡⟨⟩ -[ P.suc (P.suc n) ] ∎ lemma : ∀ i → + 1 * i ≡ i lemma (+ n) = +lemma n lemma -[1+ n ] = -lemma (P.suc n) -- _*+ n distributes over addition. *+-distrib-+ : ∀ n → (i + j) *+ n ≡ i *+ n + j *+ n *+-distrib-+ {i = i} n = ℤG.∘^+≡^+∘^+ (+-comm i) n -- If a positive number is multiplied by a positive number, then -- the result is positive. >0→*+suc> : ∀ i m → Positive i → Positive (i *+ P.suc m) >0→*+suc> i zero = Positive i ↝⟨ subst Positive (sym $ ℤG.right-identity i) ⟩ Positive (i + + 0) ↔⟨⟩ Positive (i *+ 1) □ >0→*+suc> i (P.suc m) = Positive i ↝⟨ (λ p → p , >0→*+suc> i m p) ⟩ Positive i × Positive (i *+ P.suc m) ↝⟨ uncurry (>0→>0→+>0 i (i *+ P.suc m)) ⟩ Positive (i + i *+ P.suc m) ↔⟨⟩ Positive (i *+ P.suc (P.suc m)) □ -- If a negative number is multiplied by a positive number, then -- the result is negative. <0→*+suc<0 : ∀ i m → Negative i → Negative (i *+ P.suc m) <0→*+suc<0 i zero = Negative i ↝⟨ subst Negative (sym $ ℤG.right-identity i) ⟩ Negative (i + + 0) ↔⟨⟩ Negative (i *+ 1) □ <0→*+suc<0 i (P.suc m) = Negative i ↝⟨ (λ p → p , <0→*+suc<0 i m p) ⟩ Negative i × Negative (i *+ P.suc m) ↝⟨ uncurry (<0→<0→+<0 i (i *+ P.suc m)) ⟩ Negative (i + i *+ P.suc m) ↔⟨⟩ Negative (i *+ P.suc (P.suc m)) □ ------------------------------------------------------------------------ -- Integer division by two -- Division by two, rounded downwards. ⌊_/2⌋ : ℤ → ℤ ⌊ + n /2⌋ = + Nat.⌊ n /2⌋ ⌊ -[1+ n ] /2⌋ = -[ Nat.⌈ P.suc n /2⌉ ] -- A kind of distributivity property for ⌊_/2⌋ and _+_. ⌊+*+2/2⌋≡ : ∀ i {j} → ⌊ i + j *+ 2 /2⌋ ≡ ⌊ i /2⌋ + j ⌊+*+2/2⌋≡ = λ where (+ m) {j = + n} → cong +_ (Nat.⌊ m ⊕ 2 ⊛ n /2⌋ ≡⟨ cong Nat.⌊_/2⌋ $ Nat.+-comm m ⟩ Nat.⌊ 2 ⊛ n ⊕ m /2⌋ ≡⟨ Nat.⌊2*+/2⌋≡ n ⟩ n ⊕ Nat.⌊ m /2⌋ ≡⟨ Nat.+-comm n ⟩∎ Nat.⌊ m /2⌋ ⊕ n ∎) -[1+ zero ] {j = -[1+ n ]} → cong -[1+_] (Nat.⌈ P.suc (n ⊕ n) /2⌉ ≡⟨ cong (Nat.⌈_/2⌉ ∘ P.suc) $ ⊕-lemma n ⟩ Nat.⌈ 1 ⊕ 2 ⊛ n /2⌉ ≡⟨ cong Nat.⌈_/2⌉ $ Nat.+-comm 1 ⟩ Nat.⌈ 2 ⊛ n ⊕ 1 /2⌉ ≡⟨ Nat.⌈2*+/2⌉≡ n ⟩ n ⊕ Nat.⌈ 1 /2⌉ ≡⟨ Nat.+-comm n ⟩∎ P.suc n ∎) -[1+ P.suc m ] {j = -[1+ n ]} → cong -[1+_] (Nat.⌈ P.suc m ⊕ P.suc (n ⊕ n) /2⌉ ≡⟨ cong (Nat.⌈_/2⌉ ∘ P.suc) $ sym $ Nat.suc+≡+suc m ⟩ P.suc Nat.⌈ m ⊕ (n ⊕ n) /2⌉ ≡⟨ cong (P.suc ∘ Nat.⌈_/2⌉ ∘ (m ⊕_)) $ ⊕-lemma n ⟩ P.suc Nat.⌈ m ⊕ 2 ⊛ n /2⌉ ≡⟨ cong (P.suc ∘ Nat.⌈_/2⌉) $ Nat.+-comm m ⟩ P.suc Nat.⌈ 2 ⊛ n ⊕ m /2⌉ ≡⟨ cong P.suc $ Nat.⌈2*+/2⌉≡ n ⟩ P.suc (n ⊕ Nat.⌈ m /2⌉) ≡⟨ cong P.suc $ Nat.+-comm n ⟩∎ P.suc (Nat.⌈ m /2⌉ ⊕ n) ∎) (+ m) {j = -[1+ n ]} → ⌊ + m +-[1+ P.suc (n ⊕ n) ] /2⌋ ≡⟨ cong (λ n → ⌊ + m +-[1+ P.suc n ] /2⌋) $ ⊕-lemma n ⟩ ⌊ + m +-[1+ P.suc (2 ⊛ n) ] /2⌋ ≡⟨ lemma₁ m n ⟩∎ + Nat.⌊ m /2⌋ +-[1+ n ] ∎ -[1+ 0 ] {j = + 0} → -[ 1 ] ≡⟨⟩ -[ 1 ] ∎ -[1+ 0 ] {j = + P.suc n} → cong +_ (Nat.⌊ n ⊕ P.suc (n ⊕ 0) /2⌋ ≡⟨ cong Nat.⌊_/2⌋ $ sym $ Nat.suc+≡+suc n ⟩ Nat.⌊ 1 ⊕ 2 ⊛ n /2⌋ ≡⟨ Nat.⌊1+2*/2⌋≡ n ⟩∎ n ∎) -[1+ P.suc m ] {j = + n} → ⌊ + 2 ⊛ n +-[1+ P.suc m ] /2⌋ ≡⟨ lemma₂ m n ⟩∎ + n +-[1+ Nat.⌈ m /2⌉ ] ∎ where ⊕-lemma : ∀ n → n ⊕ n ≡ 2 ⊛ n ⊕-lemma n = cong (n ⊕_) $ sym Nat.+-right-identity lemma₁ : ∀ m n → ⌊ + m +-[1+ P.suc (2 ⊛ n) ] /2⌋ ≡ + Nat.⌊ m /2⌋ +-[1+ n ] lemma₁ zero n = cong -[1+_] (Nat.⌈ 2 ⊛ n /2⌉ ≡⟨ Nat.⌈2*/2⌉≡ n ⟩∎ n ∎) lemma₁ (P.suc zero) n = -[ Nat.⌈ 1 ⊕ 2 ⊛ n /2⌉ ] ≡⟨ cong -[_] $ Nat.⌈1+2*/2⌉≡ n ⟩∎ -[1+ n ] ∎ lemma₁ (P.suc (P.suc m)) zero = ⌊ + m /2⌋ ≡⟨⟩ + Nat.⌊ m /2⌋ ∎ lemma₁ (P.suc (P.suc m)) (P.suc n) = ⌊ + m +-[1+ n ⊕ P.suc (n ⊕ 0) ] /2⌋ ≡⟨ cong (⌊_/2⌋ ∘ + m +-[1+_]) $ sym $ Nat.suc+≡+suc n ⟩ ⌊ + m +-[1+ P.suc (2 ⊛ n) ] /2⌋ ≡⟨ lemma₁ m n ⟩∎ + Nat.⌊ m /2⌋ +-[1+ n ] ∎ mutual lemma₂ : ∀ m n → ⌊ + 2 ⊛ n +-[1+ P.suc m ] /2⌋ ≡ + n +-[1+ Nat.⌈ m /2⌉ ] lemma₂ m zero = ⌊ -[1+ P.suc m ] /2⌋ ≡⟨⟩ -[1+ Nat.⌈ m /2⌉ ] ∎ lemma₂ m (P.suc n) = ⌊ + n ⊕ P.suc (n ⊕ 0) +-[1+ m ] /2⌋ ≡⟨ cong (⌊_/2⌋ ∘ +_+-[1+ m ]) $ sym $ Nat.suc+≡+suc n ⟩ ⌊ + P.suc (2 ⊛ n) +-[1+ m ] /2⌋ ≡⟨ lemma₃ m n ⟩∎ + P.suc n +-[1+ Nat.⌈ m /2⌉ ] ∎ lemma₃ : ∀ m n → ⌊ + P.suc (2 ⊛ n) +-[1+ m ] /2⌋ ≡ + P.suc n +-[1+ Nat.⌈ m /2⌉ ] lemma₃ zero n = cong +_ (Nat.⌊ 2 ⊛ n /2⌋ ≡⟨ Nat.⌊2*/2⌋≡ n ⟩∎ n ∎) lemma₃ (P.suc zero) zero = -[ 1 ] ≡⟨⟩ -[ 1 ] ∎ lemma₃ (P.suc zero) (P.suc n) = cong +_ (Nat.⌊ n ⊕ P.suc (n ⊕ zero) /2⌋ ≡⟨ cong Nat.⌊_/2⌋ $ sym $ Nat.suc+≡+suc n ⟩ Nat.⌊ 1 ⊕ 2 ⊛ n /2⌋ ≡⟨ Nat.⌊1+2*/2⌋≡ n ⟩∎ n ∎) lemma₃ (P.suc (P.suc m)) n = ⌊ + 2 ⊛ n +-[1+ P.suc m ] /2⌋ ≡⟨ lemma₂ m n ⟩∎ + n +-[1+ Nat.⌈ m /2⌉ ] ∎ -- If you double and then halve an integer, then you get back what you -- started with. ⌊*+2/2⌋≡ : ∀ i → ⌊ i *+ 2 /2⌋ ≡ i ⌊*+2/2⌋≡ i = ⌊ i *+ 2 /2⌋ ≡⟨ cong ⌊_/2⌋ $ sym $ +-left-identity {i = i *+ 2} ⟩ ⌊ + 0 + i *+ 2 /2⌋ ≡⟨ ⌊+*+2/2⌋≡ (+ 0) {j = i} ⟩ ⌊ + 0 /2⌋ + i ≡⟨⟩ + 0 + i ≡⟨ +-left-identity ⟩∎ i ∎
31.552036
98
0.404704
3d57b776c09a02da45f49eff768a1924a9cd81e1
10,572
agda
Agda
Categories/Congruence.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Congruence.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Congruence.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
module Categories.Congruence where open import Level open import Relation.Binary hiding (_⇒_; Setoid) open import Categories.Support.PropositionalEquality open import Categories.Support.Equivalence open import Categories.Support.EqReasoning open import Categories.Category hiding (module Heterogeneous; _[_∼_]) record Congruence {o ℓ e} (C : Category o ℓ e) q : Set (o ⊔ ℓ ⊔ e ⊔ suc q) where open Category C field _≡₀_ : Rel Obj q equiv₀ : IsEquivalence _≡₀_ module Equiv₀ = IsEquivalence equiv₀ field coerce : ∀ {X₁ X₂ Y₁ Y₂} → X₁ ≡₀ X₂ → Y₁ ≡₀ Y₂ → X₁ ⇒ Y₁ → X₂ ⇒ Y₂ .coerce-resp-≡ : ∀ {X₁ X₂ Y₁ Y₂} (xpf : X₁ ≡₀ X₂) (ypf : Y₁ ≡₀ Y₂) → {f₁ f₂ : X₁ ⇒ Y₁} → f₁ ≡ f₂ → coerce xpf ypf f₁ ≡ coerce xpf ypf f₂ .coerce-refl : ∀ {X Y} (f : X ⇒ Y) → coerce Equiv₀.refl Equiv₀.refl f ≡ f .coerce-invariant : ∀ {X₁ X₂ Y₁ Y₂} (xpf₁ xpf₂ : X₁ ≡₀ X₂) (ypf₁ ypf₂ : Y₁ ≡₀ Y₂) → (f : X₁ ⇒ Y₁) → coerce xpf₁ ypf₁ f ≡ coerce xpf₂ ypf₂ f .coerce-trans : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃} (xpf₁ : X₁ ≡₀ X₂) (xpf₂ : X₂ ≡₀ X₃) (ypf₁ : Y₁ ≡₀ Y₂) (ypf₂ : Y₂ ≡₀ Y₃) → (f : X₁ ⇒ Y₁) → coerce (Equiv₀.trans xpf₁ xpf₂) (Equiv₀.trans ypf₁ ypf₂) f ≡ coerce xpf₂ ypf₂ (coerce xpf₁ ypf₁ f) .coerce-∘ : ∀ {X₁ X₂ Y₁ Y₂ Z₁ Z₂} → (pfX : X₁ ≡₀ X₂) (pfY : Y₁ ≡₀ Y₂) (pfZ : Z₁ ≡₀ Z₂) → (g : Y₁ ⇒ Z₁) (f : X₁ ⇒ Y₁) → coerce pfX pfZ (g ∘ f) ≡ coerce pfY pfZ g ∘ coerce pfX pfY f .coerce-local : ∀ {X Y} (xpf : X ≡₀ X) (ypf : Y ≡₀ Y) {f : X ⇒ Y} → coerce xpf ypf f ≡ f coerce-local xpf ypf {f} = begin coerce xpf ypf f ↓⟨ coerce-invariant xpf Equiv₀.refl ypf Equiv₀.refl f ⟩ coerce Equiv₀.refl Equiv₀.refl f ↓⟨ coerce-refl f ⟩ f ∎ where open HomReasoning .coerce-zigzag : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → {f : X₁ ⇒ Y₁} → coerce rfX rfY (coerce pfX pfY f) ≡ f coerce-zigzag pfX rfX pfY rfY {f} = begin coerce rfX rfY (coerce pfX pfY f) ↑⟨ coerce-trans _ _ _ _ _ ⟩ coerce (trans pfX rfX) (trans pfY rfY) f ↓⟨ coerce-local _ _ ⟩ f ∎ where open HomReasoning open Equiv₀ .coerce-uncong : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (pfY : Y₁ ≡₀ Y₂) (f g : X₁ ⇒ Y₁) → coerce pfX pfY f ≡ coerce pfX pfY g → f ≡ g coerce-uncong xpf ypf f g fg-pf = begin f ↑⟨ coerce-zigzag _ _ _ _ ⟩ coerce (sym xpf) (sym ypf) (coerce xpf ypf f) ↓⟨ coerce-resp-≡ _ _ fg-pf ⟩ coerce (sym xpf) (sym ypf) (coerce xpf ypf g) ↓⟨ coerce-zigzag _ _ _ _ ⟩ g ∎ where open HomReasoning open Equiv₀ .coerce-slide⇒ : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → (f : X₁ ⇒ Y₁) (g : X₂ ⇒ Y₂) → coerce pfX pfY f ≡ g → f ≡ coerce rfX rfY g coerce-slide⇒ pfX rfX pfY rfY f g eq = begin f ↑⟨ coerce-zigzag _ _ _ _ ⟩ coerce rfX rfY (coerce pfX pfY f) ↓⟨ coerce-resp-≡ _ _ eq ⟩ coerce rfX rfY g ∎ where open HomReasoning .coerce-slide⇐ : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → (f : X₁ ⇒ Y₁) (g : X₂ ⇒ Y₂) → f ≡ coerce rfX rfY g → coerce pfX pfY f ≡ g coerce-slide⇐ pfX rfX pfY rfY f g eq = begin coerce pfX pfY f ↓⟨ coerce-resp-≡ _ _ eq ⟩ coerce pfX pfY (coerce rfX rfY g) ↓⟨ coerce-zigzag _ _ _ _ ⟩ g ∎ where open HomReasoning .coerce-id : ∀ {X Y} (pf₁ pf₂ : X ≡₀ Y) → coerce pf₁ pf₂ id ≡ id coerce-id pf₁ pf₂ = begin coerce pf₁ pf₂ id ↑⟨ identityˡ ⟩ id ∘ coerce pf₁ pf₂ id ↑⟨ ∘-resp-≡ˡ (coerce-local _ _) ⟩ coerce (trans (sym pf₂) pf₂) (trans (sym pf₂) pf₂) id ∘ coerce pf₁ pf₂ id ↓⟨ ∘-resp-≡ˡ (coerce-trans _ _ _ _ _) ⟩ coerce pf₂ pf₂ (coerce (sym pf₂) (sym pf₂) id) ∘ coerce pf₁ pf₂ id ↑⟨ coerce-∘ _ _ _ _ _ ⟩ coerce pf₁ pf₂ (coerce (sym pf₂) (sym pf₂) id ∘ id) ↓⟨ coerce-resp-≡ _ _ identityʳ ⟩ coerce pf₁ pf₂ (coerce (sym pf₂) (sym pf₂) id) ↑⟨ coerce-trans _ _ _ _ _ ⟩ coerce (trans (sym pf₂) pf₁) (trans (sym pf₂) pf₂) id ↓⟨ coerce-local _ _ ⟩ id ∎ where open HomReasoning open Equiv₀ module Heterogeneous {o ℓ e} {C : Category o ℓ e} {q} (Q : Congruence C q) where open Category C open Congruence Q open Equiv renaming (refl to refl′; sym to sym′; trans to trans′; reflexive to reflexive′) open Equiv₀ renaming (refl to refl₀; sym to sym₀; trans to trans₀; reflexive to reflexive₀) infix 4 _∼_ data _∼_ {A B} (f : A ⇒ B) {X Y} (g : X ⇒ Y) : Set (o ⊔ ℓ ⊔ e ⊔ q) where ≡⇒∼ : (ax : A ≡₀ X) (by : B ≡₀ Y) → .(coerce ax by f ≡ g) → f ∼ g refl : ∀ {A B} {f : A ⇒ B} → f ∼ f refl = ≡⇒∼ refl₀ refl₀ (coerce-refl _) sym : ∀ {A B} {f : A ⇒ B} {D E} {g : D ⇒ E} → f ∼ g → g ∼ f sym (≡⇒∼ A≡D B≡E f≡g) = ≡⇒∼ (sym₀ A≡D) (sym₀ B≡E) (coerce-slide⇐ _ _ _ _ _ _ (sym′ f≡g)) trans : ∀ {A B} {f : A ⇒ B} {D E} {g : D ⇒ E} {F G} {h : F ⇒ G} → f ∼ g → g ∼ h → f ∼ h trans (≡⇒∼ A≡D B≡E f≡g) (≡⇒∼ D≡F E≡G g≡h) = ≡⇒∼ (trans₀ A≡D D≡F) (trans₀ B≡E E≡G) (trans′ (trans′ (coerce-trans _ _ _ _ _) (coerce-resp-≡ _ _ f≡g)) g≡h) reflexive : ∀ {A B} {f g : A ⇒ B} → f ≣ g → f ∼ g reflexive f≣g = ≡⇒∼ refl₀ refl₀ (trans′ (coerce-refl _) (reflexive′ f≣g)) ∘-resp-∼ : ∀ {A B C A′ B′ C′} {f : B ⇒ C} {h : B′ ⇒ C′} {g : A ⇒ B} {i : A′ ⇒ B′} → f ∼ h → g ∼ i → (f ∘ g) ∼ (h ∘ i) ∘-resp-∼ {f = f} {h} {g} {i} (≡⇒∼ B≡B′₁ C≡C′ f≡h) (≡⇒∼ A≡A′ B≡B′₂ g≡i) = ≡⇒∼ A≡A′ C≡C′ (begin coerce A≡A′ C≡C′ (f ∘ g) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B′₁ C≡C′ f ∘ coerce A≡A′ B≡B′₁ g ↓⟨ ∘-resp-≡ʳ (coerce-invariant _ _ _ _ _) ⟩ coerce B≡B′₁ C≡C′ f ∘ coerce A≡A′ B≡B′₂ g ↓⟨ ∘-resp-≡ f≡h g≡i ⟩ h ∘ i ∎) where open HomReasoning ∘-resp-∼ˡ : ∀ {A B C C′} {f : B ⇒ C} {h : B ⇒ C′} {g : A ⇒ B} → f ∼ h → (f ∘ g) ∼ (h ∘ g) ∘-resp-∼ˡ {f = f} {h} {g} (≡⇒∼ B≡B C≡C′ f≡h) = ≡⇒∼ refl₀ C≡C′ (begin coerce refl₀ C≡C′ (f ∘ g) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B C≡C′ f ∘ coerce refl₀ B≡B g ↓⟨ ∘-resp-≡ʳ (coerce-local _ _) ⟩ coerce B≡B C≡C′ f ∘ g ↓⟨ ∘-resp-≡ˡ f≡h ⟩ h ∘ g ∎) where open HomReasoning ∘-resp-∼ʳ : ∀ {A A′ B C} {f : A ⇒ B} {h : A′ ⇒ B} {g : B ⇒ C} → f ∼ h → (g ∘ f) ∼ (g ∘ h) ∘-resp-∼ʳ {f = f} {h} {g} (≡⇒∼ A≡A′ B≡B f≡h) = ≡⇒∼ A≡A′ refl₀ (begin coerce A≡A′ refl₀ (g ∘ f) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B refl₀ g ∘ coerce A≡A′ B≡B f ↓⟨ ∘-resp-≡ˡ (coerce-local _ _) ⟩ g ∘ coerce A≡A′ B≡B f ↓⟨ ∘-resp-≡ʳ f≡h ⟩ g ∘ h ∎) where open HomReasoning .∼⇒≡ : ∀ {A B} {f g : A ⇒ B} → f ∼ g → f ≡ g ∼⇒≡ (≡⇒∼ A≡A B≡B f≡g) = trans′ (sym′ (coerce-local A≡A B≡B)) (irr f≡g) domain-≣ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → A ≡₀ A′ domain-≣ (≡⇒∼ eq _ _) = eq codomain-≣ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → B ≡₀ B′ codomain-≣ (≡⇒∼ _ eq _) = eq ∼-cong : ∀ {t : Level} {T : Set t} {dom cod : T → Obj} (f : (x : T) → dom x ⇒ cod x) → ∀ {i j} (eq : i ≣ j) → f i ∼ f j ∼-cong f ≣-refl = refl -- henry ford versions .∼⇒≡₂ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → (A≡A′ : A ≡₀ A′) (B≡B′ : B ≡₀ B′) → coerce A≡A′ B≡B′ f ≡ f′ ∼⇒≡₂ (≡⇒∼ pfA pfB pff) A≡A′ B≡B′ = trans′ (coerce-invariant _ _ _ _ _) (irr pff) -- .∼⇒≡ˡ : ∀ {A B B′} {f : A ⇒ B} {f′ : A ⇒ B′} → f ∼ f′ → (B≣B′ : B ≣ B′) → floatˡ B≣B′ f ≡ f′ -- ∼⇒≡ˡ pf ≣-refl = ∼⇒≡ pf -- .∼⇒≡ʳ : ∀ {A A′ B} {f : A ⇒ B} {f′ : A′ ⇒ B} → f ∼ f′ → (A≣A′ : A ≣ A′) → floatʳ A≣A′ f ≡ f′ -- ∼⇒≡ʳ pf ≣-refl = ∼⇒≡ pf -- ≡⇒∼ʳ : ∀ {A A′ B} {f : A ⇒ B} {f′ : A′ ⇒ B} → (A≣A′ : A ≣ A′) → .(floatʳ A≣A′ f ≡ f′) → f ∼ f′ -- ≡⇒∼ʳ ≣-refl pf = ≡⇒∼ pf coerce-resp-∼ : ∀ {A A′ B B′} (A≡A′ : A ≡₀ A′) (B≡B′ : B ≡₀ B′) {f : C [ A , B ]} → f ∼ coerce A≡A′ B≡B′ f coerce-resp-∼ A≡A′ B≡B′ = ≡⇒∼ A≡A′ B≡B′ refl′ -- floatˡ-resp-∼ : ∀ {A B B′} (B≣B′ : B ≣ B′) {f : C [ A , B ]} → f ∼ floatˡ B≣B′ f -- floatˡ-resp-∼ ≣-refl = refl -- floatʳ-resp-∼ : ∀ {A A′ B} (A≣A′ : A ≣ A′) {f : C [ A , B ]} → f ∼ floatʳ A≣A′ f -- floatʳ-resp-∼ ≣-refl = refl infixr 4 ▹_ record -⇒- : Set (o ⊔ ℓ) where constructor ▹_ field {Dom} : Obj {Cod} : Obj morphism : Dom ⇒ Cod ∼-setoid : Setoid _ _ ∼-setoid = record { Carrier = -⇒-; _≈_ = λ x y → -⇒-.morphism x ∼ -⇒-.morphism y; isEquivalence = record { refl = refl; sym = sym; trans = trans } } module HetReasoning where open SetoidReasoning ∼-setoid public _[_∼_] : ∀ {o ℓ e} {C : Category o ℓ e} {q} (Q : Congruence C q) {A B} (f : C [ A , B ]) {X Y} (g : C [ X , Y ]) → Set (q ⊔ o ⊔ ℓ ⊔ e) Q [ f ∼ g ] = Heterogeneous._∼_ Q f g TrivialCongruence : ∀ {o ℓ e} (C : Category o ℓ e) → Congruence C _ TrivialCongruence C = record { _≡₀_ = _≣_ ; equiv₀ = ≣-isEquivalence ; coerce = ≣-subst₂ (_⇒_) ; coerce-resp-≡ = resp-≡ ; coerce-refl = λ f → refl ; coerce-invariant = invariant ; coerce-trans = tranz ; coerce-∘ = compose } where open Category C open Equiv -- XXX must this depend on proof irrelevance? .resp-≡ : ∀ {X₁ X₂ Y₁ Y₂} (xpf : X₁ ≣ X₂) (ypf : Y₁ ≣ Y₂) {f₁ f₂ : X₁ ⇒ Y₁} → f₁ ≡ f₂ → ≣-subst₂ _⇒_ xpf ypf f₁ ≡ ≣-subst₂ _⇒_ xpf ypf f₂ resp-≡ ≣-refl ≣-refl eq = eq .invariant : ∀ {X₁ X₂ Y₁ Y₂} (xpf₁ xpf₂ : X₁ ≣ X₂) (ypf₁ ypf₂ : Y₁ ≣ Y₂) → (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ xpf₁ ypf₁ f ≡ ≣-subst₂ _⇒_ xpf₂ ypf₂ f invariant ≣-refl ≣-refl ≣-refl ≣-refl f = refl .tranz : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃} (xpf₁ : X₁ ≣ X₂) (xpf₂ : X₂ ≣ X₃) (ypf₁ : Y₁ ≣ Y₂) (ypf₂ : Y₂ ≣ Y₃) → (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ (≣-trans xpf₁ xpf₂) (≣-trans ypf₁ ypf₂) f ≡ ≣-subst₂ _⇒_ xpf₂ ypf₂ (≣-subst₂ _⇒_ xpf₁ ypf₁ f) tranz ≣-refl xpf₂ ≣-refl ypf₂ f = refl .compose : ∀ {X₁ X₂ Y₁ Y₂ Z₁ Z₂} (pfX : X₁ ≣ X₂)(pfY : Y₁ ≣ Y₂)(pfZ : Z₁ ≣ Z₂) → (g : Y₁ ⇒ Z₁) (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ pfX pfZ (g ∘ f) ≡ ≣-subst₂ _⇒_ pfY pfZ g ∘ ≣-subst₂ _⇒_ pfX pfY f compose ≣-refl ≣-refl ≣-refl g f = refl
35.59596
134
0.469164
8b279b8e54b105df5c9a88094312875aa78d721d
8,641
agda
Agda
Cubical/Foundations/Equiv.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Foundations/Equiv.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{- Theory about equivalences Definitions are in Core/Glue.agda but re-exported by this module - isEquiv is a proposition ([isPropIsEquiv]) - Any isomorphism is an equivalence ([isoToEquiv]) There are more statements about equivalences in Equiv/Properties.agda: - if f is an equivalence then (cong f) is an equivalence - if f is an equivalence then precomposition with f is an equivalence - if f is an equivalence then postcomposition with f is an equivalence -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Equiv where open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv.Base public open import Cubical.Data.Sigma.Base private variable ℓ ℓ' ℓ'' : Level A B C D : Type ℓ equivIsEquiv : (e : A ≃ B) → isEquiv (equivFun e) equivIsEquiv e = snd e equivCtr : (e : A ≃ B) (y : B) → fiber (equivFun e) y equivCtr e y = e .snd .equiv-proof y .fst equivCtrPath : (e : A ≃ B) (y : B) → (v : fiber (equivFun e) y) → Path _ (equivCtr e y) v equivCtrPath e y = e .snd .equiv-proof y .snd -- Proof using isPropIsContr. This is slow and the direct proof below is better isPropIsEquiv' : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv' f u0 u1 i) y = isPropIsContr (u0 .equiv-proof y) (u1 .equiv-proof y) i -- Direct proof that computes quite ok (can be optimized further if -- necessary, see: -- https://github.com/mortberg/cubicaltt/blob/pi4s3_dimclosures/examples/brunerie2.ctt#L562 isPropIsEquiv : (f : A → B) → isProp (isEquiv f) equiv-proof (isPropIsEquiv f p q i) y = let p2 = p .equiv-proof y .snd q2 = q .equiv-proof y .snd in p2 (q .equiv-proof y .fst) i , λ w j → hcomp (λ k → λ { (i = i0) → p2 w j ; (i = i1) → q2 w (j ∨ ~ k) ; (j = i0) → p2 (q2 w (~ k)) i ; (j = i1) → w }) (p2 w (i ∨ j)) equivEq : {e f : A ≃ B} → (h : e .fst ≡ f .fst) → e ≡ f equivEq {e = e} {f = f} h = λ i → (h i) , isProp→PathP (λ i → isPropIsEquiv (h i)) (e .snd) (f .snd) i equivFun≡→isEquiv : (e : A ≃ B) (f : A → B) (p : (a : A) → equivFun e a ≡ f a) → isEquiv f equivFun≡→isEquiv e f p = subst (λ g → isEquiv g) (funExt (λ a → p a)) (e .snd) module _ {f : A → B} (equivF : isEquiv f) where funIsEq : A → B funIsEq = f invIsEq : B → A invIsEq y = equivF .equiv-proof y .fst .fst secIsEq : section f invIsEq secIsEq y = equivF .equiv-proof y .fst .snd retIsEq : retract f invIsEq retIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .fst commSqIsEq : ∀ a → Square (secIsEq (f a)) refl (cong f (retIsEq a)) refl commSqIsEq a i = equivF .equiv-proof (f a) .snd (a , refl) i .snd module _ (w : A ≃ B) where invEq : B → A invEq = invIsEq (snd w) secEq : section invEq (w .fst) secEq = retIsEq (snd w) retEq : retract invEq (w .fst) retEq = secIsEq (snd w) open Iso equivToIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → A ≃ B → Iso A B fun (equivToIso e) = e .fst inv (equivToIso e) = invEq e rightInv (equivToIso e) = retEq e leftInv (equivToIso e) = secEq e -- TODO: there should be a direct proof of this that doesn't use equivToIso invEquiv : A ≃ B → B ≃ A invEquiv e = isoToEquiv (invIso (equivToIso e)) invEquivIdEquiv : (A : Type ℓ) → invEquiv (idEquiv A) ≡ idEquiv A invEquivIdEquiv _ = equivEq refl -- TODO: there should be a direct proof of this that doesn't use equivToIso compEquiv : A ≃ B → B ≃ C → A ≃ C compEquiv f g = isoToEquiv (compIso (equivToIso f) (equivToIso g)) compEquivIdEquiv : (e : A ≃ B) → compEquiv (idEquiv A) e ≡ e compEquivIdEquiv e = equivEq refl compEquivEquivId : (e : A ≃ B) → compEquiv e (idEquiv B) ≡ e compEquivEquivId e = equivEq refl invEquiv-is-rinv : (e : A ≃ B) → compEquiv e (invEquiv e) ≡ idEquiv A invEquiv-is-rinv e = equivEq (funExt (secEq e)) invEquiv-is-linv : (e : A ≃ B) → compEquiv (invEquiv e) e ≡ idEquiv B invEquiv-is-linv e = equivEq (funExt (retEq e)) compEquiv-assoc : (f : A ≃ B) (g : B ≃ C) (h : C ≃ D) → compEquiv f (compEquiv g h) ≡ compEquiv (compEquiv f g) h compEquiv-assoc f g h = equivEq refl LiftEquiv : A ≃ Lift {i = ℓ} {j = ℓ'} A LiftEquiv .fst a .lower = a LiftEquiv .snd .equiv-proof a+ .fst .fst = a+ .lower LiftEquiv .snd .equiv-proof _ .fst .snd = refl LiftEquiv .snd .equiv-proof _ .snd (_ , p) i .fst = p (~ i) .lower LiftEquiv .snd .equiv-proof _ .snd (_ , p) i .snd j = p (~ i ∨ j) Lift≃Lift : (e : A ≃ B) → Lift {j = ℓ'} A ≃ Lift {j = ℓ''} B Lift≃Lift e .fst a .lower = e .fst (a .lower) Lift≃Lift e .snd .equiv-proof b .fst .fst .lower = invEq e (b .lower) Lift≃Lift e .snd .equiv-proof b .fst .snd i .lower = e .snd .equiv-proof (b .lower) .fst .snd i Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .fst .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .fst Lift≃Lift e .snd .equiv-proof b .snd (a , p) i .snd j .lower = e .snd .equiv-proof (b .lower) .snd (a .lower , cong lower p) i .snd j isContr→Equiv : isContr A → isContr B → A ≃ B isContr→Equiv Actr Bctr = isoToEquiv (isContr→Iso Actr Bctr) propBiimpl→Equiv : (Aprop : isProp A) (Bprop : isProp B) (f : A → B) (g : B → A) → A ≃ B propBiimpl→Equiv Aprop Bprop f g = f , hf where hf : isEquiv f hf .equiv-proof y .fst = (g y , Bprop (f (g y)) y) hf .equiv-proof y .snd h i .fst = Aprop (g y) (h .fst) i hf .equiv-proof y .snd h i .snd = isProp→isSet' Bprop (Bprop (f (g y)) y) (h .snd) (cong f (Aprop (g y) (h .fst))) refl i isEquivPropBiimpl→Equiv : isProp A → isProp B → ((A → B) × (B → A)) ≃ (A ≃ B) isEquivPropBiimpl→Equiv {A = A} {B = B} Aprop Bprop = isoToEquiv isom where isom : Iso (Σ (A → B) (λ _ → B → A)) (A ≃ B) isom .fun (f , g) = propBiimpl→Equiv Aprop Bprop f g isom .inv e = equivFun e , invEq e isom .rightInv e = equivEq refl isom .leftInv _ = refl equivΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ((x : A) → F x ≃ G x) → ((x : A) → F x) ≃ ((x : A) → G x) equivΠCod k .fst f x = k x .fst (f x) equivΠCod k .snd .equiv-proof f .fst .fst x = equivCtr (k x) (f x) .fst equivΠCod k .snd .equiv-proof f .fst .snd i x = equivCtr (k x) (f x) .snd i equivΠCod k .snd .equiv-proof f .snd (g , p) i .fst x = equivCtrPath (k x) (f x) (g x , λ j → p j x) i .fst equivΠCod k .snd .equiv-proof f .snd (g , p) i .snd j x = equivCtrPath (k x) (f x) (g x , λ k → p k x) i .snd j equivImplicitΠCod : ∀ {F : A → Type ℓ} {G : A → Type ℓ'} → ({x : A} → F x ≃ G x) → ({x : A} → F x) ≃ ({x : A} → G x) equivImplicitΠCod k .fst f {x} = k {x} .fst (f {x}) equivImplicitΠCod k .snd .equiv-proof f .fst .fst {x} = equivCtr (k {x}) (f {x}) .fst equivImplicitΠCod k .snd .equiv-proof f .fst .snd i {x} = equivCtr (k {x}) (f {x}) .snd i equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .fst {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ j → p j {x}) i .fst equivImplicitΠCod k .snd .equiv-proof f .snd (g , p) i .snd j {x} = equivCtrPath (k {x}) (f {x}) (g {x} , λ k → p k {x}) i .snd j equiv→Iso : (A ≃ B) → (C ≃ D) → Iso (A → C) (B → D) equiv→Iso h k .Iso.fun f b = equivFun k (f (invEq h b)) equiv→Iso h k .Iso.inv g a = invEq k (g (equivFun h a)) equiv→Iso h k .Iso.rightInv g = funExt λ b → retEq k _ ∙ cong g (retEq h b) equiv→Iso h k .Iso.leftInv f = funExt λ a → secEq k _ ∙ cong f (secEq h a) equiv→ : (A ≃ B) → (C ≃ D) → (A → C) ≃ (B → D) equiv→ h k = isoToEquiv (equiv→Iso h k) equivCompIso : (A ≃ B) → (C ≃ D) → Iso (A ≃ C) (B ≃ D) equivCompIso h k .Iso.fun f = compEquiv (compEquiv (invEquiv h) f) k equivCompIso h k .Iso.inv g = compEquiv (compEquiv h g) (invEquiv k) equivCompIso h k .Iso.rightInv g = equivEq (equiv→Iso h k .Iso.rightInv (equivFun g)) equivCompIso h k .Iso.leftInv f = equivEq (equiv→Iso h k .Iso.leftInv (equivFun f)) equivComp : (A ≃ B) → (C ≃ D) → (A ≃ C) ≃ (B ≃ D) equivComp h k = isoToEquiv (equivCompIso h k) -- Some helpful notation: _≃⟨_⟩_ : (X : Type ℓ) → (X ≃ B) → (B ≃ C) → (X ≃ C) _ ≃⟨ f ⟩ g = compEquiv f g _■ : (X : Type ℓ) → (X ≃ X) _■ = idEquiv infixr 0 _≃⟨_⟩_ infix 1 _■ composesToId→Equiv : (f : A → B) (g : B → A) → f ∘ g ≡ idfun B → isEquiv f → isEquiv g composesToId→Equiv f g id iseqf = isoToIsEquiv (iso g f (λ b → (λ i → equiv-proof iseqf (f b) .snd (g (f b) , cong (λ h → h (f b)) id) (~ i) .fst) ∙∙ cong (λ x → equiv-proof iseqf (f b) .fst .fst) id ∙∙ λ i → equiv-proof iseqf (f b) .snd (b , refl) i .fst) λ a i → id i a)
38.066079
102
0.594144
22cfacdd9945131f2e169d8532962c055c6df568
12,475
agda
Agda
homotopy/3x3/Transpose.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
homotopy/3x3/Transpose.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
homotopy/3x3/Transpose.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import homotopy.3x3.Common open import homotopy.3x3.PushoutPushout module homotopy.3x3.Transpose where open M using (Pushout^2) type-of : ∀ {i} {A : Type i} (u : A) → Type i type-of {A = A} _ = A module _ {i} (d : Span^2 {i}) where open Span^2 d transpose-f : (f : type-of H₁₁ → _) (g : type-of H₃₃ → _) → Span^2 transpose-f f g = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃ (f H₁₁) H₃₁ H₁₃ (g H₃₃) transpose : Span^2 transpose = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃ (! ∘ H₁₁) H₃₁ H₁₃ (! ∘ H₃₃) ch1 : ∀ {i j} {A : Type i} {x y : A} {p : x == y} {f g : A → Type j} {a : f x → g x} {b : f y → g y} → (a == b [ (λ u → f u → g u) ↓ p ]) → (a == b [ (λ u → fst u → snd u) ↓ pair×= (ap f p) (ap g p)]) ch1 {p = idp} α = α ch2 : ∀ {i j} {X : Type i} {x y : X} {p : x == y} {A B₁ B₂ C : X → Type j} {f₁ : (x : X) → A x → B₁ x} {g₁ : (x : X) → B₁ x → C x} {f₂ : (x : X) → A x → B₂ x} {g₂ : (x : X) → B₂ x → C x} {a : _} {b : _} → (a == b [ (λ z → (x : A z) → g₁ z (f₁ z x) == g₂ z (f₂ z x)) ↓ p ]) → (a == b [ (λ u → (x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)) ↓ square=-raw (ap A p) (ap B₁ p) (ap B₂ p) (ap C p) (ch1 (apd f₁ p)) (ch1 (apd f₂ p)) (ch1 (apd g₁ p)) (ch1 (apd g₂ p)) ]) ch2 {p = idp} α = α ap-span^2=-priv : ∀ {i} {d d' : Span^2 {i}} (p : d == d') → ap transpose p == span^2=-raw (ap Span^2.A₀₀ p) (ap Span^2.A₂₀ p) (ap Span^2.A₄₀ p) (ap Span^2.A₀₂ p) (ap Span^2.A₂₂ p) (ap Span^2.A₄₂ p) (ap Span^2.A₀₄ p) (ap Span^2.A₂₄ p) (ap Span^2.A₄₄ p) (ch1 (apd Span^2.f₁₀ p)) (ch1 (apd Span^2.f₃₀ p)) (ch1 (apd Span^2.f₁₂ p)) (ch1 (apd Span^2.f₃₂ p)) (ch1 (apd Span^2.f₁₄ p)) (ch1 (apd Span^2.f₃₄ p)) (ch1 (apd Span^2.f₀₁ p)) (ch1 (apd Span^2.f₀₃ p)) (ch1 (apd Span^2.f₂₁ p)) (ch1 (apd Span^2.f₂₃ p)) (ch1 (apd Span^2.f₄₁ p)) (ch1 (apd Span^2.f₄₃ p)) (ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₁₁ p))) (ch2 (apd Span^2.H₃₁ p)) (ch2 (apd Span^2.H₁₃ p)) (ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₃₃ p))) ap-span^2=-priv {i} {d} {.d} idp = idp ap-span^2=-priv2 : ∀ {i} {A₀₀ A₀₀' : Type i} (eq-A₀₀ : A₀₀ == A₀₀') {A₀₂ A₀₂' : Type i} (eq-A₀₂ : A₀₂ == A₀₂') {A₀₄ A₀₄' : Type i} (eq-A₀₄ : A₀₄ == A₀₄') {A₂₀ A₂₀' : Type i} (eq-A₂₀ : A₂₀ == A₂₀') {A₂₂ A₂₂' : Type i} (eq-A₂₂ : A₂₂ == A₂₂') {A₂₄ A₂₄' : Type i} (eq-A₂₄ : A₂₄ == A₂₄') {A₄₀ A₄₀' : Type i} (eq-A₄₀ : A₄₀ == A₄₀') {A₄₂ A₄₂' : Type i} (eq-A₄₂ : A₄₂ == A₄₂') {A₄₄ A₄₄' : Type i} (eq-A₄₄ : A₄₄ == A₄₄') {f₀₁ : A₀₂ → A₀₀} {f₀₁' : A₀₂' → A₀₀'} (eq-f₀₁ : f₀₁ == f₀₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₀ ]) {f₀₃ : A₀₂ → A₀₄} {f₀₃' : A₀₂' → A₀₄'} (eq-f₀₃ : f₀₃ == f₀₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₄ ]) {f₂₁ : A₂₂ → A₂₀} {f₂₁' : A₂₂' → A₂₀'} (eq-f₂₁ : f₂₁ == f₂₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₀ ]) {f₂₃ : A₂₂ → A₂₄} {f₂₃' : A₂₂' → A₂₄'} (eq-f₂₃ : f₂₃ == f₂₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₄ ]) {f₄₁ : A₄₂ → A₄₀} {f₄₁' : A₄₂' → A₄₀'} (eq-f₄₁ : f₄₁ == f₄₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₀ ]) {f₄₃ : A₄₂ → A₄₄} {f₄₃' : A₄₂' → A₄₄'} (eq-f₄₃ : f₄₃ == f₄₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₄ ]) {f₁₀ : A₂₀ → A₀₀} {f₁₀' : A₂₀' → A₀₀'} (eq-f₁₀ : f₁₀ == f₁₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₀₀ ]) {f₃₀ : A₂₀ → A₄₀} {f₃₀' : A₂₀' → A₄₀'} (eq-f₃₀ : f₃₀ == f₃₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₄₀ ]) {f₁₂ : A₂₂ → A₀₂} {f₁₂' : A₂₂' → A₀₂'} (eq-f₁₂ : f₁₂ == f₁₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₀₂ ]) {f₃₂ : A₂₂ → A₄₂} {f₃₂' : A₂₂' → A₄₂'} (eq-f₃₂ : f₃₂ == f₃₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₄₂ ]) {f₁₄ : A₂₄ → A₀₄} {f₁₄' : A₂₄' → A₀₄'} (eq-f₁₄ : f₁₄ == f₁₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₀₄ ]) {f₃₄ : A₂₄ → A₄₄} {f₃₄' : A₂₄' → A₄₄'} (eq-f₃₄ : f₃₄ == f₃₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₄₄ ]) {H₁₁ : (x : A₂₂) → f₁₀ (f₂₁ x) == f₀₁ (f₁₂ x)} {H₁₁' : (x : A₂₂') → f₁₀' (f₂₁' x) == f₀₁' (f₁₂' x)} (eq-H₁₁ : H₁₁ == H₁₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))) ↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₀₂ eq-A₀₀ eq-f₂₁ eq-f₁₂ eq-f₁₀ eq-f₀₁ ]) {H₁₃ : (x : A₂₂) → f₀₃ (f₁₂ x) == f₁₄ (f₂₃ x)} {H₁₃' : (x : A₂₂') → f₀₃' (f₁₂' x) == f₁₄' (f₂₃' x)} (eq-H₁₃ : H₁₃ == H₁₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))) ↓ square=-raw eq-A₂₂ eq-A₀₂ eq-A₂₄ eq-A₀₄ eq-f₁₂ eq-f₂₃ eq-f₀₃ eq-f₁₄ ]) {H₃₁ : (x : A₂₂) → f₃₀ (f₂₁ x) == f₄₁ (f₃₂ x)} {H₃₁' : (x : A₂₂') → f₃₀' (f₂₁' x) == f₄₁' (f₃₂' x)} (eq-H₃₁ : H₃₁ == H₃₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))) ↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₄₂ eq-A₄₀ eq-f₂₁ eq-f₃₂ eq-f₃₀ eq-f₄₁ ]) {H₃₃ : (x : A₂₂) → f₄₃ (f₃₂ x) == f₃₄ (f₂₃ x)} {H₃₃' : (x : A₂₂') → f₄₃' (f₃₂' x) == f₃₄' (f₂₃' x)} (eq-H₃₃ : H₃₃ == H₃₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))) ↓ square=-raw eq-A₂₂ eq-A₄₂ eq-A₂₄ eq-A₄₄ eq-f₃₂ eq-f₂₃ eq-f₄₃ eq-f₃₄ ]) → ap transpose (span^2=-raw eq-A₀₀ eq-A₀₂ eq-A₀₄ eq-A₂₀ eq-A₂₂ eq-A₂₄ eq-A₄₀ eq-A₄₂ eq-A₄₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-H₁₁ eq-H₁₃ eq-H₃₁ eq-H₃₃) == span^2=-raw eq-A₀₀ eq-A₂₀ eq-A₄₀ eq-A₀₂ eq-A₂₂ eq-A₄₂ eq-A₀₄ eq-A₂₄ eq-A₄₄ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₁₁)) eq-H₃₁ eq-H₁₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₃₃)) ap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp = idp module _ {i} (d : Span^2 {i}) where open Span^2 d transpose-transpose : transpose (transpose d) == d transpose-transpose = span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (λ= (!-! ∘ Span^2.H₁₁ d)) idp idp (λ= (!-! ∘ Span^2.H₃₃ d)) module _ {i} (d : Span^2 {i}) where transpose-equiv : Span^2 {i} ≃ Span^2 transpose-equiv = equiv transpose transpose transpose-transpose transpose-transpose module _ {i} (d : Span^2 {i}) where open Span^2 d d' : (H₁₁' : type-of H₁₁) (H₃₃' : type-of H₃₃) → Span^2 d' H₁₁' H₃₃' = record d {H₁₁ = H₁₁'; H₃₃ = H₃₃'} e : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : M.A₂∙ (d' H₁₁' H₃₃')) → left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c) e {H₁₁'} eq₁ {H₃₃'} eq₃ = E.f module _ where e-glue : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : Span^2.A₂₂ (d' H₁₁' H₃₃')) → glue (left (f₂₁ c)) == glue (right (f₂₃ c)) [ (λ z → left (M.f₁∙ (d' H₁₁' H₃₃') z) == right (M.f₃∙ (d' H₁₁' H₃₃') z)) ↓ glue c ] e-glue idp idp c = apd glue (glue c) module E = PushoutElim {P = λ c → left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c) :> Pushout^2 d} (glue ∘ left) (glue ∘ right) (e-glue eq₁ eq₃) module F {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') = PushoutRec {d = M.v-h-span (d' H₁₁' H₃₃')} {D = Pushout^2 d} left right (e eq₁ eq₃) tr-tr-fun : Pushout^2 (transpose (transpose d)) → Pushout^2 d tr-tr-fun = F.f (! (λ= (!-! ∘ H₁₁))) (! (λ= (!-! ∘ H₃₃))) lemma12 : (c : M.A₂∙ d) → e idp idp c == glue c lemma12 = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-=-in (! (E.glue-β idp idp c))) result' : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (x : Pushout^2 (d' H₁₁' H₃₃')) → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (! eq₁) idp idp (! eq₃) :> (d' H₁₁' H₃₃' == d)) x == F.f eq₁ eq₃ x result' idp idp = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-='-in (F.glue-β idp idp c ∙ lemma12 c ∙ ! (ap-idf (glue c)))) result : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁' == H₁₁) {H₃₃' : type-of H₃₃} (eq₃ : H₃₃' == H₃₃) (x : Pushout^2 (d' H₁₁' H₃₃')) → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp eq₁ idp idp eq₃ :> (d' H₁₁' H₃₃' == d)) x == F.f (! eq₁) (! eq₃) x result eq₁ eq₃ x = ap (λ u → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (fst u) idp idp (snd u) :> (_ == d)) x) (pair×= (! (!-! eq₁)) (! (!-! eq₃))) ∙ result' (! eq₁) (! eq₃) x result2 : (x : Pushout^2 (transpose (transpose d))) → transport Pushout^2 (transpose-transpose d) x == tr-tr-fun x result2 = result (λ= (!-! ∘ Span^2.H₁₁ d)) (λ= (!-! ∘ Span^2.H₃₃ d)) -- module _ {i} where -- postulate -- to : (d : Span^2 {i}) → Pushout^2 d → Pushout^2 (transpose d) -- from : (d : Span^2 {i}) → Pushout^2 (transpose d) → Pushout^2 d -- from d = tr-tr-fun d ∘ to (transpose d) -- postulate -- from-to : (d : Span^2 {i}) (x : Pushout^2 d) → from d (to d x) == x -- lemma3 : {d d' : Span^2 {i}} (p : d == d') (x : Pushout^2 d) → transport (Pushout^2 ∘ transpose) p (to d x) == to d' (transport Pushout^2 p x) -- lemma3 {d} {.d} idp x = idp -- lemma34 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose d))) → transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) x) == to d (tr-tr-fun d x) -- lemma34 d x = lemma3 (transpose-transpose d) x ∙ ap (to d) (result2 d x) -- lm2 : (d : Span^2 {i}) → ap transpose (transpose-transpose d) == transpose-transpose (transpose d) -- lm2 d = ap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp -- (! (! (λ= (!-! ∘ Span^2.H₁₁ d)))) idp idp (! (! (λ= (!-! ∘ Span^2.H₃₃ d)))) ∙ ap (λ u → span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (fst u) idp idp (snd u)) (pair×= (lm3 (Span^2.H₁₁ d)) (lm3 (Span^2.H₃₃ d))) where -- lm3 : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : (a : A) → f a == g a) -- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ p)))) == ! (! (λ= (!-! ∘ ! ∘ p))) -- lm3 p = transport (λ u → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ u)))) == ! (! (λ= (!-! ∘ ! ∘ u)))) (λ= (app=-β p)) (lm3' (λ= p)) where -- lm3' : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : f == g) -- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ app= p)))) == ! (! (λ= (!-! ∘ ! ∘ app= p))) -- lm3' idp = ap (λ u → ap (λ u → ! ∘ u) (! (! u))) (! (λ=-η idp)) ∙ ap (! ∘ !) (λ=-η idp) -- lemma345 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose (transpose d)))) -- → transport (Pushout^2 ∘ transpose) (transpose-transpose d) x == tr-tr-fun (transpose d) x -- lemma345 d x = -- transport (Pushout^2 ∘ transpose) (transpose-transpose d) x -- =⟨ ap (λ u → coe u x) (ap-∘ Pushout^2 transpose (transpose-transpose d)) ⟩ -- transport Pushout^2 (ap transpose (transpose-transpose d)) x -- =⟨ ap (λ u → transport Pushout^2 u x) (lm2 d) ⟩ -- transport Pushout^2 (transpose-transpose (transpose d)) x -- =⟨ result2 (transpose d) x ⟩ -- tr-tr-fun (transpose d) x ∎ -- to-from : (d : Span^2 {i}) (x : Pushout^2 (transpose d)) → to d (from d x) == x -- to-from d x = -- to d (tr-tr-fun d (to (transpose d) x)) -- =⟨ ! (lemma34 d (to (transpose d) x)) ⟩ -- transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) (to (transpose d) x)) -- =⟨ lemma345 d (to (transpose (transpose d)) (to (transpose d) x)) ⟩ -- tr-tr-fun (transpose d) (to (transpose (transpose d)) (to (transpose d) x)) -- =⟨ from-to (transpose d) x ⟩ -- x ∎
63.647959
294
0.503086
2236a2ee26e5d80b50e9694f3d9fa350bd42408c
708
agda
Agda
test/interaction/Issue2803.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2803.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2803.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-11-12, issue #2803 -- Problem: names of hidden variable patterns -- can get lost during case splitting. -- They actually get lost already during lhs type checking, -- but it is noticed only when printed back to the user -- during case splitting. -- {-# OPTIONS -v tc.lhs:40 #-} record HFun (A B : Set) : Set where field apply : {a : A} → B postulate A : Set test : HFun A (A → A) HFun.apply test {β} = {!!} -- C-c C-c -- YIELDS: -- HFun.apply test {a} x = ? -- EXPECTED: -- HFun.apply test {β} x = ? open import Agda.Builtin.Bool test' : {a b : Bool} → Bool → Bool test' {b = z} x = {!x!} -- Splitting on x should yield -- test {b = z} false = {!!} -- test {b = z} true = {!!}
20.228571
59
0.605932
9aad5ba84d664535f8ca53e35bd0c6f0c906d8f8
354
agda
Agda
test/Succeed/WithoutKDisjointSum.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Succeed/WithoutKDisjointSum.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Succeed/WithoutKDisjointSum.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible #-} -- Issue raised by Martin Escardo 2012-12-13 -- on the Agda list "no longer type checks" module WithoutKDisjointSum where open import Common.Equality data ⊥ : Set where data _⊎_ (A B : Set) : Set where inl : A → A ⊎ B inr : B → A ⊎ B distinct : {A B : Set} (a : A) (b : B) → inl a ≡ inr b → ⊥ distinct a b ()
22.125
58
0.624294
205ea18fdfd958207cb931c194f56cebec56648d
80
agda
Agda
examples/tactics/ac/Logic.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/tactics/ac/Logic.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/tactics/ac/Logic.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Logic where data True : Set where tt : True data False : Set where
8.888889
22
0.6875
03858ee63aed33d85bfb08109a4bbc8b4c5c0431
34,137
agda
Agda
src/H-level/Truncation/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/H-level/Truncation/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/H-level/Truncation/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Propositional truncation ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} -- Partly following the HoTT book. -- The module is parametrised by a notion of equality. The higher -- constructor of the HIT defining the propositional truncation uses -- path equality, but the supplied notion of equality is used for many -- other things. import Equality.Path as P module H-level.Truncation.Propositional {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq hiding (elim) open import Dec open import Prelude open import Logical-equivalence using (_⇔_) open import Bijection equality-with-J as Bijection using (_↔_) open import Embedding equality-with-J as Embedding hiding (id; _∘_) open import Equality.Decidable-UIP equality-with-J open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Equivalence.Erased equality-with-J using (_≃ᴱ_) open import Equivalence.Erased.Contractible-preimages equality-with-J as ECP using (_⁻¹ᴱ_) open import Equivalence-relation equality-with-J open import Erased.Cubical eq as E using (Erased; erased; Very-stableᴱ-≡; Erased-singleton) import Erased.Stability equality-with-J as ES open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J import H-level.Truncation.Church equality-with-J as Trunc open import H-level.Truncation.Propositional.Erased eq as TE using (∥_∥ᴱ; Surjectiveᴱ) open import Injection equality-with-J using (_↣_) open import Monad equality-with-J open import Preimage equality-with-J as Preimage using (_⁻¹_) open import Surjection equality-with-J as Surjection using (_↠_; Split-surjective) private variable a b c d p r ℓ : Level A A₁ A₂ B B₁ B₂ C D : Type a P Q : A → Type p R : A → A → Type r A↠B f k s x y : A -- Propositional truncation. data ∥_∥ (A : Type a) : Type a where ∣_∣ : A → ∥ A ∥ truncation-is-propositionᴾ : P.Is-proposition ∥ A ∥ -- The truncation produces propositions. truncation-is-proposition : Is-proposition ∥ A ∥ truncation-is-proposition = _↔_.from (H-level↔H-level 1) truncation-is-propositionᴾ -- A dependent eliminator, expressed using paths. record Elimᴾ′ {A : Type a} (P : ∥ A ∥ → Type p) : Type (a ⊔ p) where no-eta-equality field ∣∣ʳ : (x : A) → P ∣ x ∣ truncation-is-propositionʳ : (p : P x) (q : P y) → P.[ (λ i → P (truncation-is-propositionᴾ x y i)) ] p ≡ q open Elimᴾ′ public elimᴾ′ : Elimᴾ′ P → (x : ∥ A ∥) → P x elimᴾ′ {A = A} {P = P} e = helper where module E′ = Elimᴾ′ e helper : (x : ∥ A ∥) → P x helper ∣ x ∣ = E′.∣∣ʳ x helper (truncation-is-propositionᴾ x y i) = E′.truncation-is-propositionʳ (helper x) (helper y) i -- A possibly more useful dependent eliminator, expressed using paths. record Elimᴾ {A : Type a} (P : ∥ A ∥ → Type p) : Type (a ⊔ p) where no-eta-equality field ∣∣ʳ : (x : A) → P ∣ x ∣ truncation-is-propositionʳ : (x : ∥ A ∥) → P.Is-proposition (P x) open Elimᴾ public elimᴾ : Elimᴾ P → (x : ∥ A ∥) → P x elimᴾ e = elimᴾ′ e′ where module E′ = Elimᴾ e e′ : Elimᴾ′ _ e′ .∣∣ʳ = E′.∣∣ʳ e′ .truncation-is-propositionʳ _ _ = P.heterogeneous-irrelevance E′.truncation-is-propositionʳ -- A non-dependent eliminator, expressed using paths. record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where no-eta-equality field ∣∣ʳ : A → B truncation-is-propositionʳ : P.Is-proposition B open Recᴾ public recᴾ : Recᴾ A B → ∥ A ∥ → B recᴾ r = elimᴾ e where module R = Recᴾ r e : Elimᴾ _ e .∣∣ʳ = R.∣∣ʳ e .truncation-is-propositionʳ _ = R.truncation-is-propositionʳ -- A dependently typed eliminator. record Elim′ {A : Type a} (P : ∥ A ∥ → Type p) : Type (a ⊔ p) where no-eta-equality field ∣∣ʳ : (x : A) → P ∣ x ∣ truncation-is-propositionʳ : (x : ∥ A ∥) → Is-proposition (P x) open Elim′ public elim′ : Elim′ P → (x : ∥ A ∥) → P x elim′ e = elimᴾ e′ where module E′ = Elim′ e e′ : Elimᴾ _ e′ .∣∣ʳ = E′.∣∣ʳ e′ .truncation-is-propositionʳ = _↔_.to (H-level↔H-level 1) ∘ E′.truncation-is-propositionʳ elim : (P : ∥ A ∥ → Type p) → (∀ x → Is-proposition (P x)) → ((x : A) → P ∣ x ∣) → (x : ∥ A ∥) → P x elim _ p f = elim′ λ where .∣∣ʳ → f .truncation-is-propositionʳ → p -- Primitive "recursion". record Rec′ (A : Type a) (B : Type b) : Type (a ⊔ b) where no-eta-equality field ∣∣ʳ : A → B truncation-is-propositionʳ : Is-proposition B open Rec′ public rec′ : Rec′ A B → ∥ A ∥ → B rec′ r = recᴾ r′ where module R = Rec′ r r′ : Recᴾ _ _ r′ .∣∣ʳ = R.∣∣ʳ r′ .truncation-is-propositionʳ = _↔_.to (H-level↔H-level 1) R.truncation-is-propositionʳ rec : Is-proposition B → (A → B) → ∥ A ∥ → B rec p f = rec′ λ where .∣∣ʳ → f .truncation-is-propositionʳ → p -- A map function. ∥∥-map : (A → B) → ∥ A ∥ → ∥ B ∥ ∥∥-map f = rec truncation-is-proposition (∣_∣ ∘ f) -- The propositional truncation defined here is isomorphic to the one -- defined in H-level.Truncation.Church. ∥∥↔∥∥ : ∀ ℓ {a} {A : Type a} → ∥ A ∥ ↔ Trunc.∥ A ∥ 1 (a ⊔ ℓ) ∥∥↔∥∥ ℓ = record { surjection = record { logical-equivalence = record { to = rec (Trunc.truncation-has-correct-h-level 1 ext) Trunc.∣_∣₁ ; from = lower {ℓ = ℓ} ∘ Trunc.rec 1 (↑-closure 1 truncation-is-proposition) (lift ∘ ∣_∣) } ; right-inverse-of = λ _ → Trunc.truncation-has-correct-h-level 1 ext _ _ } ; left-inverse-of = λ _ → truncation-is-proposition _ _ } -- If A is merely inhabited (with erased proofs), then A is merely -- inhabited. ∥∥ᴱ→∥∥ : ∥ A ∥ᴱ → ∥ A ∥ ∥∥ᴱ→∥∥ = TE.rec λ where .TE.∣∣ʳ → ∣_∣ .TE.truncation-is-propositionʳ → truncation-is-proposition -- In an erased context the propositional truncation operator defined -- in H-level.Truncation.Propositional.Erased is equivalent to the one -- defined here. @0 ∥∥ᴱ≃∥∥ : ∥ A ∥ᴱ ≃ ∥ A ∥ ∥∥ᴱ≃∥∥ = Eq.⇔→≃ TE.truncation-is-proposition truncation-is-proposition ∥∥ᴱ→∥∥ (rec TE.truncation-is-proposition TE.∣_∣) mutual -- If A and B are logically equivalent, then functions of any kind can -- be constructed from ∥ A ∥ to ∥ B ∥. ∥∥-cong-⇔ : ∀ {k} → A ⇔ B → ∥ A ∥ ↝[ k ] ∥ B ∥ ∥∥-cong-⇔ A⇔B = ∥∥-cong-⇔′ (∣_∣ ∘ _⇔_.to A⇔B) (∣_∣ ∘ _⇔_.from A⇔B) -- A variant of the previous result. ∥∥-cong-⇔′ : ∀ {k} → (A → ∥ B ∥) → (B → ∥ A ∥) → ∥ A ∥ ↝[ k ] ∥ B ∥ ∥∥-cong-⇔′ A→∥B∥ B→∥A∥ = from-equivalence $ Eq.⇔→≃ truncation-is-proposition truncation-is-proposition (rec truncation-is-proposition A→∥B∥) (rec truncation-is-proposition B→∥A∥) -- The truncation operator preserves all kinds of functions. private ∥∥-cong-↣ : A ↣ B → ∥ A ∥ ↣ ∥ B ∥ ∥∥-cong-↣ f = record { to = ∥∥-map (_↣_.to f) ; injective = λ _ → truncation-is-proposition _ _ } ∥∥-cong : A ↝[ k ] B → ∥ A ∥ ↝[ k ] ∥ B ∥ ∥∥-cong {k = implication} = ∥∥-map ∥∥-cong {k = logical-equivalence} = ∥∥-cong-⇔ ∥∥-cong {k = surjection} = ∥∥-cong-⇔ ∘ _↠_.logical-equivalence ∥∥-cong {k = bijection} = ∥∥-cong-⇔ ∘ from-isomorphism ∥∥-cong {k = equivalence} = ∥∥-cong-⇔ ∘ from-isomorphism ∥∥-cong {k = equivalenceᴱ} = ∥∥-cong-⇔ ∘ _≃ᴱ_.logical-equivalence ∥∥-cong {k = injection} = ∥∥-cong-↣ ∥∥-cong {k = embedding} = _↔_.to (↣↔Embedding ext (mono₁ 1 truncation-is-proposition) (mono₁ 1 truncation-is-proposition)) ∘ ∥∥-cong-↣ ∘ Embedding.injection -- A form of idempotence for binary sums. idempotent : ∥ A ⊎ A ∥ ↔ ∥ A ∥ idempotent = ∥∥-cong-⇔ (record { to = [ id , id ]; from = inj₁ }) -- A generalised flattening lemma. flatten′ : (F : (Type ℓ → Type ℓ) → Type f) → (∀ {G H} → (∀ {A} → G A → H A) → F G → F H) → (F ∥_∥ → ∥ F id ∥) → ∥ F ∥_∥ ∥ ↔ ∥ F id ∥ flatten′ _ map f = record { surjection = record { logical-equivalence = record { to = rec truncation-is-proposition f ; from = ∥∥-map (map ∣_∣) } ; right-inverse-of = λ _ → truncation-is-proposition _ _ } ; left-inverse-of = λ _ → truncation-is-proposition _ _ } -- Nested truncations can be flattened. flatten : ∥ ∥ A ∥ ∥ ↔ ∥ A ∥ flatten {A = A} = flatten′ (λ F → F A) (λ f → f) id private -- Another flattening lemma, given as an example of how flatten′ can -- be used. ∥∃∥∥∥↔∥∃∥ : {B : A → Type b} → ∥ ∃ (∥_∥ ∘ B) ∥ ↔ ∥ ∃ B ∥ ∥∃∥∥∥↔∥∃∥ {B = B} = flatten′ (λ F → ∃ (F ∘ B)) (λ f → Σ-map id f) (uncurry λ x → ∥∥-map (x ,_)) -- A universe-polymorphic variant of bind. infixl 5 _>>=′_ _>>=′_ : ∥ A ∥ → (A → ∥ B ∥) → ∥ B ∥ x >>=′ f = _↔_.to flatten (∥∥-map f x) -- The universe-polymorphic variant of bind is associative. >>=′-associative : (x : ∥ A ∥) {f : A → ∥ B ∥} {g : B → ∥ C ∥} → x >>=′ (λ x → f x >>=′ g) ≡ x >>=′ f >>=′ g >>=′-associative x {f} {g} = elim (λ x → x >>=′ (λ x₁ → f x₁ >>=′ g) ≡ x >>=′ f >>=′ g) (λ _ → ⇒≡ 1 truncation-is-proposition) (λ _ → refl _) x instance -- The propositional truncation operator is a monad. raw-monad : ∀ {ℓ} → Raw-monad (∥_∥ {a = ℓ}) Raw-monad.return raw-monad = ∣_∣ Raw-monad._>>=_ raw-monad = _>>=′_ monad : ∀ {ℓ} → Monad (∥_∥ {a = ℓ}) Monad.raw-monad monad = raw-monad Monad.left-identity monad x f = refl _ Monad.associativity monad x _ _ = >>=′-associative x Monad.right-identity monad = elim _ (λ _ → ⇒≡ 1 truncation-is-proposition) (λ _ → refl _) -- Surjectivity. Surjective : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b) Surjective f = ∀ b → ∥ f ⁻¹ b ∥ -- The property Surjective f is a proposition. Surjective-propositional : {f : A → B} → Is-proposition (Surjective f) Surjective-propositional = Π-closure ext 1 λ _ → truncation-is-proposition -- In an erased context surjectivity with erased proofs is equivalent -- to surjectivity. -- -- It appears to me as if neither direction of this equivalence can be -- established if the erasure annotation is removed. @0 Surjectiveᴱ≃Surjective : Surjectiveᴱ f ≃ Surjective f Surjectiveᴱ≃Surjective {f = f} = (∀ y → ∥ f ⁻¹ᴱ y ∥ᴱ) ↝⟨ (∀-cong ext λ _ → ∥∥ᴱ≃∥∥) ⟩ (∀ y → ∥ f ⁻¹ᴱ y ∥) ↝⟨ (∀-cong ext λ _ → ∥∥-cong (inverse ECP.⁻¹≃⁻¹ᴱ)) ⟩□ (∀ y → ∥ f ⁻¹ y ∥) □ -- The function ∣_∣ is surjective. ∣∣-surjective : Surjective (∣_∣ {A = A}) ∣∣-surjective = elim _ (λ _ → truncation-is-proposition) (λ x → ∣ x , refl _ ∣) -- Split surjective functions are surjective. Split-surjective→Surjective : {f : A → B} → Split-surjective f → Surjective f Split-surjective→Surjective s = λ b → ∣ s b ∣ -- Being both surjective and an embedding is equivalent to being an -- equivalence. -- -- This is Corollary 4.6.4 from the first edition of the HoTT book -- (the proof is perhaps not quite identical). surjective×embedding≃equivalence : {f : A → B} → (Surjective f × Is-embedding f) ≃ Is-equivalence f surjective×embedding≃equivalence {f = f} = (Surjective f × Is-embedding f) ↔⟨ ∀-cong ext (λ _ → ∥∥↔∥∥ lzero) ×-cong F.id ⟩ (Trunc.Surjective _ f × Is-embedding f) ↝⟨ Trunc.surjective×embedding≃equivalence lzero ext ⟩□ Is-equivalence f □ -- If the underlying type is a proposition, then truncations of the -- type are isomorphic to the type itself. ∥∥↔ : Is-proposition A → ∥ A ∥ ↔ A ∥∥↔ A-prop = record { surjection = record { logical-equivalence = record { to = rec A-prop id ; from = ∣_∣ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → truncation-is-proposition _ _ } -- A type is a proposition if it is equivalent to the propositional -- truncation of some type. ≃∥∥→Is-proposition : A ≃ ∥ B ∥ → Is-proposition A ≃∥∥→Is-proposition A≃∥B∥ a₁ a₂ = $⟨ truncation-is-proposition _ _ ⟩ _≃_.to A≃∥B∥ a₁ ≡ _≃_.to A≃∥B∥ a₂ ↝⟨ Eq.≃-≡ A≃∥B∥ ⟩□ a₁ ≡ a₂ □ -- A simple isomorphism involving propositional truncation. ∥∥×↔ : ∥ A ∥ × A ↔ A ∥∥×↔ = drop-⊤-left-× λ a → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible truncation-is-proposition ∣ a ∣ -- A variant of ∥∥×↔, introduced to ensure that the right-inverse-of -- proof is, by definition, simple. ∥∥×≃ : (∥ A ∥ × A) ≃ A ∥∥×≃ = Eq.↔→≃ proj₂ (λ x → ∣ x ∣ , x) refl (λ _ → cong (_, _) (truncation-is-proposition _ _)) _ : _≃_.right-inverse-of ∥∥×≃ x ≡ refl _ _ = refl _ -- A variant of ∥∥×≃. Erased-∥∥×≃ : (Erased ∥ A ∥ × A) ≃ A Erased-∥∥×≃ = Eq.↔→≃ proj₂ (λ x → E.[ ∣ x ∣ ] , x) refl (λ (_ , x) → cong (_, x) (E.[]-cong E.[ truncation-is-proposition _ _ ])) _ : _≃_.right-inverse-of Erased-∥∥×≃ x ≡ refl _ _ = refl _ -- ∥_∥ commutes with _×_. ∥∥×∥∥↔∥×∥ : (∥ A ∥ × ∥ B ∥) ↔ ∥ A × B ∥ ∥∥×∥∥↔∥×∥ = record { surjection = record { logical-equivalence = record { from = λ p → ∥∥-map proj₁ p , ∥∥-map proj₂ p ; to = λ { (x , y) → rec truncation-is-proposition (λ x → rec truncation-is-proposition (λ y → ∣ x , y ∣) y) x } } ; right-inverse-of = λ _ → truncation-is-proposition _ _ } ; left-inverse-of = λ _ → ×-closure 1 truncation-is-proposition truncation-is-proposition _ _ } -- Variants of proj₁-closure. private H-level-×₁-lemma : (A → ∥ B ∥) → ∀ n → H-level (suc n) (A × B) → H-level (suc n) A H-level-×₁-lemma inhabited n h = [inhabited⇒+]⇒+ n λ a → rec (H-level-propositional ext (suc n)) (λ b → proj₁-closure (λ _ → b) (suc n) h) (inhabited a) H-level-×₁ : (A → ∥ B ∥) → ∀ n → H-level n (A × B) → H-level n A H-level-×₁ inhabited zero h = propositional⇒inhabited⇒contractible (H-level-×₁-lemma inhabited 0 (mono₁ 0 h)) (proj₁ (proj₁ h)) H-level-×₁ inhabited (suc n) = H-level-×₁-lemma inhabited n H-level-×₂ : (B → ∥ A ∥) → ∀ n → H-level n (A × B) → H-level n B H-level-×₂ {B = B} {A = A} inhabited n = H-level n (A × B) ↝⟨ H-level.respects-surjection (from-bijection ×-comm) n ⟩ H-level n (B × A) ↝⟨ H-level-×₁ inhabited n ⟩□ H-level n B □ -- If A is merely inhabited, then the truncation of A is isomorphic to -- the unit type. inhabited⇒∥∥↔⊤ : ∥ A ∥ → ∥ A ∥ ↔ ⊤ inhabited⇒∥∥↔⊤ ∥a∥ = _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible truncation-is-proposition ∥a∥ -- If A is not inhabited, then the propositional truncation of A is -- isomorphic to the empty type. not-inhabited⇒∥∥↔⊥ : ¬ A → ∥ A ∥ ↔ ⊥ {ℓ = ℓ} not-inhabited⇒∥∥↔⊥ {A = A} = ¬ A ↝⟨ (λ ¬a ∥a∥ → rec ⊥-propositional ¬a ∥a∥) ⟩ ¬ ∥ A ∥ ↝⟨ inverse ∘ Bijection.⊥↔uninhabited ⟩□ ∥ A ∥ ↔ ⊥ □ -- The negation of the truncation of A is isomorphic to the negation -- of A. ¬∥∥↔¬ : ¬ ∥ A ∥ ↔ ¬ A ¬∥∥↔¬ {A = A} = record { surjection = record { logical-equivalence = record { to = λ f → f ∘ ∣_∣ ; from = rec ⊥-propositional } ; right-inverse-of = λ _ → ¬-propositional ext _ _ } ; left-inverse-of = λ _ → ¬-propositional ext _ _ } -- The function λ R x y → ∥ R x y ∥ preserves Is-equivalence-relation. ∥∥-preserves-Is-equivalence-relation : Is-equivalence-relation R → Is-equivalence-relation (λ x y → ∥ R x y ∥) ∥∥-preserves-Is-equivalence-relation R-equiv = record { reflexive = ∣ reflexive ∣ ; symmetric = symmetric ⟨$⟩_ ; transitive = λ p q → transitive ⟨$⟩ p ⊛ q } where open Is-equivalence-relation R-equiv mutual -- The propositional truncation's universal property. universal-property : Is-proposition B → (∥ A ∥ → B) ≃ (A → B) universal-property B-prop = universal-property-Π (λ _ → B-prop) -- A generalisation of the universal property. universal-property-Π : (∀ x → Is-proposition (P x)) → ((x : ∥ A ∥) → P x) ≃ ((x : A) → P ∣ x ∣) universal-property-Π {A = A} {P = P} P-prop = ((x : ∥ A ∥) → P x) ↝⟨ Eq.⇔→≃ prop truncation-is-proposition (λ f → ∣ f ∘ ∣_∣ ∣) (rec prop (elim _ P-prop)) ⟩ ∥ ((x : A) → P ∣ x ∣) ∥ ↔⟨ ∥∥↔ (Π-closure ext 1 λ _ → P-prop _) ⟩□ ((x : A) → P ∣ x ∣) □ where prop = Π-closure ext 1 λ _ → P-prop _ private -- The universal property computes in the right way. _ : (B-prop : Is-proposition B) (f : ∥ A ∥ → B) → _≃_.to (universal-property B-prop) f ≡ f ∘ ∣_∣ _ = λ _ _ → refl _ _ : (B-prop : Is-proposition B) (f : A → B) (x : A) → _≃_.from (universal-property B-prop) f ∣ x ∣ ≡ f x _ = λ _ _ _ → refl _ -- If there is a function f : A → ∥ B ∥, then f is an equivalence if -- and only if the second projection from A × B is an equivalence. equivalence-to-∥∥≃proj₂-equivalence : (f : A → ∥ B ∥) → Is-equivalence f ≃ Is-equivalence (proj₂ ⦂ (A × B → B)) equivalence-to-∥∥≃proj₂-equivalence {A = A} {B = B} f = Eq.⇔→≃ (Eq.propositional ext _) (Eq.propositional ext _) (λ eq → _≃_.is-equivalence (A × B ↝⟨ (×-cong₁ λ _ → Eq.⟨ _ , eq ⟩) ⟩ ∥ B ∥ × B ↝⟨ ∥∥×≃ ⟩□ B □)) from where from : Is-equivalence proj₂ → Is-equivalence f from eq = _≃_.is-equivalence $ Eq.⇔→≃ A-prop truncation-is-proposition _ (rec A-prop (proj₁ ∘ _≃_.from Eq.⟨ _ , eq ⟩)) where A-prop₁ : B → Is-proposition A A-prop₁ b a₁ a₂ = $⟨ refl _ ⟩ b ≡ b ↔⟨⟩ proj₂ (a₁ , b) ≡ proj₂ (a₂ , b) ↔⟨ Eq.≃-≡ Eq.⟨ _ , eq ⟩ ⟩ (a₁ , b) ≡ (a₂ , b) ↝⟨ cong proj₁ ⟩□ a₁ ≡ a₂ □ A-prop : Is-proposition A A-prop = [inhabited⇒+]⇒+ 0 (A ↝⟨ f ⟩ ∥ B ∥ ↝⟨ rec (H-level-propositional ext 1) A-prop₁ ⟩□ Is-proposition A □) -- There is an equivalence between "A is equivalent to ∥ B ∥" and -- "there is a function from A to ∥ B ∥ and the second projection is -- an equivalence from A × B to B". ≃∥∥≃→∥∥×proj₂-equivalence : (A ≃ ∥ B ∥) ≃ ((A → ∥ B ∥) × Is-equivalence (proj₂ ⦂ (A × B → B))) ≃∥∥≃→∥∥×proj₂-equivalence {A = A} {B = B} = A ≃ ∥ B ∥ ↔⟨ Eq.≃-as-Σ ⟩ (∃ λ (f : A → ∥ B ∥) → Is-equivalence f) ↝⟨ ∃-cong equivalence-to-∥∥≃proj₂-equivalence ⟩□ (A → ∥ B ∥) × Is-equivalence (proj₂ ⦂ (A × B → B)) □ -- The following three results come from "Generalizations of Hedberg's -- Theorem" by Kraus, Escardó, Coquand and Altenkirch. -- Types with constant endofunctions are "h-stable" (meaning that -- "mere inhabitance" implies inhabitance). constant-endofunction⇒h-stable : {f : A → A} → Constant f → ∥ A ∥ → A constant-endofunction⇒h-stable {A = A} {f = f} c = ∥ A ∥ ↝⟨ rec (fixpoint-lemma f c) (λ x → f x , c (f x) x) ⟩ (∃ λ (x : A) → f x ≡ x) ↝⟨ proj₁ ⟩□ A □ -- Having a constant endofunction is logically equivalent to being -- h-stable. constant-endofunction⇔h-stable : (∃ λ (f : A → A) → Constant f) ⇔ (∥ A ∥ → A) constant-endofunction⇔h-stable = record { to = λ { (_ , c) → constant-endofunction⇒h-stable c } ; from = λ f → f ∘ ∣_∣ , λ x y → f ∣ x ∣ ≡⟨ cong f $ truncation-is-proposition _ _ ⟩∎ f ∣ y ∣ ∎ } -- A type is a set if and only if it is "h-separated" (which means -- that all its equality types are h-stable). Is-set⇔h-separated : Is-set A ⇔ ((x y : A) → ∥ x ≡ y ∥ → x ≡ y) Is-set⇔h-separated {A = A} = record { to = λ A-set _ _ → rec A-set id ; from = ((x y : A) → ∥ x ≡ y ∥ → x ≡ y) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → _⇔_.from constant-endofunction⇔h-stable) ⟩ ((x y : A) → ∃ λ (f : x ≡ y → x ≡ y) → Constant f) ↝⟨ constant⇒set ⟩□ Is-set A □ } -- If A is decided, then ∥ A ∥ is decided. Dec→Dec-∥∥ : Dec A → Dec ∥ A ∥ Dec→Dec-∥∥ (yes a) = yes ∣ a ∣ Dec→Dec-∥∥ (no ¬A) = no (_↔_.from ¬∥∥↔¬ ¬A) -- If a binary relation can be decided, then the propositional -- truncation of the relation can also be decided. decidable→decidable-∥∥ : {P : A → B → Type p} → ((x : A) (y : B) → Dec (P x y)) → ((x : A) (y : B) → Dec ∥ P x y ∥) decidable→decidable-∥∥ dec = λ x y → Dec→Dec-∥∥ (dec x y) -- If A is decided, then one can convert between ∥ A ∥ and A. Dec→∥∥⇔ : Dec A → ∥ A ∥ ⇔ A Dec→∥∥⇔ _ ._⇔_.from = ∣_∣ Dec→∥∥⇔ (yes a) ._⇔_.to = λ _ → a Dec→∥∥⇔ (no ¬A) ._⇔_.to = ⊥-elim ∘ rec ⊥-propositional ¬A -- Variants of the following two lemmas were communicated to me by -- Nicolai Kraus. They are closely related to Lemma 2.1 in his paper -- "The General Universal Property of the Propositional Truncation". -- A variant of ∥∥×≃. drop-∥∥ : {B : A → Type b} → (A → ∥ C ∥) → (∥ C ∥ → ∀ x → B x) ≃ (∀ x → B x) drop-∥∥ {C = C} {B = B} inh = Eq.with-other-inverse ((∥ C ∥ → ∀ a → B a) ↔⟨ Π-comm ⟩ (∀ a → ∥ C ∥ → B a) ↝⟨ (∀-cong ext λ a → drop-⊤-left-Π ext (inhabited⇒∥∥↔⊤ (inh a))) ⟩□ (∀ a → B a) □) (λ f _ → f) (λ f → ⟨ext⟩ λ _ → ⟨ext⟩ λ a → _ ≡⟨ subst-const _ ⟩∎ f a ∎) -- Another variant of ∥∥×≃. push-∥∥ : {B : A → Type b} {C : (∀ x → B x) → Type c} → (A → ∥ D ∥) → (∥ D ∥ → ∃ λ (f : ∀ x → B x) → C f) ≃ (∃ λ (f : ∀ x → B x) → ∥ D ∥ → C f) push-∥∥ {D = D} {B = B} {C = C} inh = (∥ D ∥ → ∃ λ (f : ∀ c → B c) → C f) ↔⟨ ΠΣ-comm ⟩ (∃ λ (f : ∥ D ∥ → ∀ c → B c) → ∀ b → C (f b)) ↝⟨ (Σ-cong-contra (inverse $ drop-∥∥ inh) λ _ → F.id) ⟩□ (∃ λ (f : ∀ c → B c) → ∥ D ∥ → C f) □ -- Having a coherently constant function into a groupoid is equivalent -- to having a function from a propositionally truncated type into the -- groupoid. This result is Proposition 2.3 in "The General Universal -- Property of the Propositional Truncation" by Kraus. Coherently-constant : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b) Coherently-constant f = ∃ λ (c : Constant f) → ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃ coherently-constant-function≃∥inhabited∥⇒inhabited : {A : Type a} {B : Type b} → H-level 3 B → (∃ λ (f : A → B) → Coherently-constant f) ≃ (∥ A ∥ → B) coherently-constant-function≃∥inhabited∥⇒inhabited {a = a} {b = b} {A = A} {B} B-groupoid = (∃ λ (f : A → B) → Coherently-constant f) ↝⟨ Trunc.coherently-constant-function≃∥inhabited∥⇒inhabited lzero ext B-groupoid ⟩ (Trunc.∥ A ∥ 1 (a ⊔ b) → B) ↝⟨ →-cong₁ ext (inverse $ ∥∥↔∥∥ (a ⊔ b)) ⟩□ (∥ A ∥ → B) □ private -- One direction of the proposition above computes in the right way. to-coherently-constant-function≃∥inhabited∥⇒inhabited : (h : H-level 3 B) (f : ∃ λ (f : A → B) → Coherently-constant f) (x : A) → _≃_.to (coherently-constant-function≃∥inhabited∥⇒inhabited h) f ∣ x ∣ ≡ proj₁ f x to-coherently-constant-function≃∥inhabited∥⇒inhabited _ _ _ = refl _ -- Having a constant function into a set is equivalent to having a -- function from a propositionally truncated type into the set. The -- statement of this result is that of Proposition 2.2 in "The General -- Universal Property of the Propositional Truncation" by Kraus, but -- it uses a different proof: as observed by Kraus this result follows -- from Proposition 2.3. constant-function≃∥inhabited∥⇒inhabited : {A : Type a} {B : Type b} → Is-set B → (∃ λ (f : A → B) → Constant f) ≃ (∥ A ∥ → B) constant-function≃∥inhabited∥⇒inhabited {a = a} {b = b} {A = A} {B} B-set = (∃ λ (f : A → B) → Constant f) ↝⟨ Trunc.constant-function≃∥inhabited∥⇒inhabited lzero ext B-set ⟩ (Trunc.∥ A ∥ 1 (a ⊔ b) → B) ↝⟨ →-cong₁ ext (inverse $ ∥∥↔∥∥ (a ⊔ b)) ⟩□ (∥ A ∥ → B) □ private -- One direction of the proposition above computes in the right way. to-constant-function≃∥inhabited∥⇒inhabited : (B-set : Is-set B) (f : ∃ λ (f : A → B) → Constant f) (x : A) → _≃_.to (constant-function≃∥inhabited∥⇒inhabited B-set) f ∣ x ∣ ≡ proj₁ f x to-constant-function≃∥inhabited∥⇒inhabited _ _ _ = refl _ -- The axiom of choice, in one of the alternative forms given in the -- HoTT book (§3.8). Axiom-of-choice : (a b : Level) → Type (lsuc (a ⊔ b)) Axiom-of-choice a b = {A : Type a} {B : A → Type b} → Is-set A → (∀ x → ∥ B x ∥) → ∥ (∀ x → B x) ∥ -- The axiom of choice can be turned into a bijection. choice-bijection : {A : Type a} {B : A → Type b} → Axiom-of-choice a b → Is-set A → (∀ x → ∥ B x ∥) ↔ ∥ (∀ x → B x) ∥ choice-bijection choice A-set = record { surjection = record { logical-equivalence = record { to = choice A-set ; from = λ f x → ∥∥-map (_$ x) f } ; right-inverse-of = λ _ → truncation-is-proposition _ _ } ; left-inverse-of = λ _ → (Π-closure ext 1 λ _ → truncation-is-proposition) _ _ } -- The axiom of countable choice, stated in a corresponding way. Axiom-of-countable-choice : (b : Level) → Type (lsuc b) Axiom-of-countable-choice b = {B : ℕ → Type b} → (∀ x → ∥ B x ∥) → ∥ (∀ x → B x) ∥ -- The axiom of countable choice can be turned into a bijection. countable-choice-bijection : {B : ℕ → Type b} → Axiom-of-countable-choice b → (∀ x → ∥ B x ∥) ↔ ∥ (∀ x → B x) ∥ countable-choice-bijection cc = record { surjection = record { logical-equivalence = record { to = cc ; from = λ f x → ∥∥-map (_$ x) f } ; right-inverse-of = λ _ → truncation-is-proposition _ _ } ; left-inverse-of = λ _ → (Π-closure ext 1 λ _ → truncation-is-proposition) _ _ } ------------------------------------------------------------------------ -- Definitions related to truncated binary sums -- Truncated binary sums. infixr 1 _∥⊎∥_ _∥⊎∥_ : Type a → Type b → Type (a ⊔ b) A ∥⊎∥ B = ∥ A ⊎ B ∥ -- Introduction rules. ∣inj₁∣ : A → A ∥⊎∥ B ∣inj₁∣ = ∣_∣ ∘ inj₁ ∣inj₂∣ : B → A ∥⊎∥ B ∣inj₂∣ = ∣_∣ ∘ inj₂ -- _∥⊎∥_ is pointwise propositional. ∥⊎∥-propositional : Is-proposition (A ∥⊎∥ B) ∥⊎∥-propositional = truncation-is-proposition -- _∥⊎∥_ preserves all kinds of functions. infixr 1 _∥⊎∥-cong_ _∥⊎∥-cong_ : A₁ ↝[ k ] A₂ → B₁ ↝[ k ] B₂ → A₁ ∥⊎∥ B₁ ↝[ k ] A₂ ∥⊎∥ B₂ A₁↝A₂ ∥⊎∥-cong B₁↝B₂ = ∥∥-cong (A₁↝A₂ ⊎-cong B₁↝B₂) -- _∥⊎∥_ is commutative. ∥⊎∥-comm : A ∥⊎∥ B ↔ B ∥⊎∥ A ∥⊎∥-comm = ∥∥-cong ⊎-comm -- If one truncates the types to the left or right of _∥⊎∥_, then one -- ends up with an isomorphic type. truncate-left-∥⊎∥ : A ∥⊎∥ B ↔ ∥ A ∥ ∥⊎∥ B truncate-left-∥⊎∥ = inverse $ flatten′ (λ F → F _ ⊎ _) (λ f → ⊎-map f id) [ ∥∥-map inj₁ , ∣inj₂∣ ] truncate-right-∥⊎∥ : A ∥⊎∥ B ↔ A ∥⊎∥ ∥ B ∥ truncate-right-∥⊎∥ {A = A} {B = B} = A ∥⊎∥ B ↝⟨ ∥⊎∥-comm ⟩ B ∥⊎∥ A ↝⟨ truncate-left-∥⊎∥ ⟩ ∥ B ∥ ∥⊎∥ A ↝⟨ ∥⊎∥-comm ⟩□ A ∥⊎∥ ∥ B ∥ □ -- _∥⊎∥_ is associative. ∥⊎∥-assoc : A ∥⊎∥ (B ∥⊎∥ C) ↔ (A ∥⊎∥ B) ∥⊎∥ C ∥⊎∥-assoc {A = A} {B = B} {C = C} = ∥ A ⊎ ∥ B ⊎ C ∥ ∥ ↝⟨ inverse truncate-right-∥⊎∥ ⟩ ∥ A ⊎ B ⊎ C ∥ ↝⟨ ∥∥-cong ⊎-assoc ⟩ ∥ (A ⊎ B) ⊎ C ∥ ↝⟨ truncate-left-∥⊎∥ ⟩□ ∥ ∥ A ⊎ B ∥ ⊎ C ∥ □ -- ⊥ is a left and right identity of _∥⊎∥_ if the other argument is a -- proposition. ∥⊎∥-left-identity : Is-proposition A → ⊥ {ℓ = ℓ} ∥⊎∥ A ↔ A ∥⊎∥-left-identity {A = A} A-prop = ∥ ⊥ ⊎ A ∥ ↝⟨ ∥∥-cong ⊎-left-identity ⟩ ∥ A ∥ ↝⟨ ∥∥↔ A-prop ⟩□ A □ ∥⊎∥-right-identity : Is-proposition A → A ∥⊎∥ ⊥ {ℓ = ℓ} ↔ A ∥⊎∥-right-identity {A = A} A-prop = A ∥⊎∥ ⊥ ↔⟨ ∥⊎∥-comm ⟩ ⊥ ∥⊎∥ A ↔⟨ ∥⊎∥-left-identity A-prop ⟩□ A □ -- _∥⊎∥_ is idempotent for propositions. ∥⊎∥-idempotent : Is-proposition A → A ∥⊎∥ A ↔ A ∥⊎∥-idempotent {A = A} A-prop = ∥ A ⊎ A ∥ ↝⟨ idempotent ⟩ ∥ A ∥ ↝⟨ ∥∥↔ A-prop ⟩□ A □ -- Sometimes a truncated binary sum is isomorphic to one of its -- summands. drop-left-∥⊎∥ : Is-proposition B → (A → B) → A ∥⊎∥ B ↔ B drop-left-∥⊎∥ B-prop A→B = _≃_.bijection $ Eq.⇔→≃ ∥⊎∥-propositional B-prop (rec B-prop [ to-implication A→B , id ]) ∣inj₂∣ drop-right-∥⊎∥ : Is-proposition A → (B → A) → A ∥⊎∥ B ↔ A drop-right-∥⊎∥ {A = A} {B = B} A-prop B→A = A ∥⊎∥ B ↝⟨ ∥⊎∥-comm ⟩ B ∥⊎∥ A ↝⟨ drop-left-∥⊎∥ A-prop B→A ⟩□ A □ drop-⊥-right-∥⊎∥ : Is-proposition A → ¬ B → A ∥⊎∥ B ↔ A drop-⊥-right-∥⊎∥ A-prop ¬B = drop-right-∥⊎∥ A-prop (⊥-elim ∘ ¬B) drop-⊥-left-∥⊎∥ : Is-proposition B → ¬ A → A ∥⊎∥ B ↔ B drop-⊥-left-∥⊎∥ B-prop ¬A = drop-left-∥⊎∥ B-prop (⊥-elim ∘ ¬A) -- A type of functions from a truncated binary sum to a family of -- propositions can be expressed as a binary product of function -- types. Π∥⊎∥↔Π×Π : (∀ x → Is-proposition (P x)) → ((x : A ∥⊎∥ B) → P x) ↔ ((x : A) → P (∣inj₁∣ x)) × ((y : B) → P (∣inj₂∣ y)) Π∥⊎∥↔Π×Π {A = A} {B = B} {P = P} P-prop = ((x : A ∥⊎∥ B) → P x) ↔⟨ universal-property-Π P-prop ⟩ ((x : A ⊎ B) → P ∣ x ∣) ↝⟨ Π⊎↔Π×Π ext ⟩□ ((x : A) → P (∣inj₁∣ x)) × ((y : B) → P (∣inj₂∣ y)) □ -- Two distributivity laws for Σ and _∥⊎∥_. Σ-∥⊎∥-distrib-left : Is-proposition A → Σ A (λ x → P x ∥⊎∥ Q x) ↔ Σ A P ∥⊎∥ Σ A Q Σ-∥⊎∥-distrib-left {P = P} {Q = Q} A-prop = (∃ λ x → ∥ P x ⊎ Q x ∥) ↝⟨ inverse $ ∥∥↔ (Σ-closure 1 A-prop λ _ → ∥⊎∥-propositional) ⟩ ∥ (∃ λ x → ∥ P x ⊎ Q x ∥) ∥ ↝⟨ flatten′ (λ F → (∃ λ x → F (P x ⊎ Q x))) (λ f → Σ-map id f) (uncurry λ x → ∥∥-map (x ,_)) ⟩ ∥ (∃ λ x → P x ⊎ Q x) ∥ ↝⟨ ∥∥-cong ∃-⊎-distrib-left ⟩□ ∥ ∃ P ⊎ ∃ Q ∥ □ Σ-∥⊎∥-distrib-right : (∀ x → Is-proposition (P x)) → Σ (A ∥⊎∥ B) P ↔ Σ A (P ∘ ∣inj₁∣) ∥⊎∥ Σ B (P ∘ ∣inj₂∣) Σ-∥⊎∥-distrib-right {A = A} {B = B} {P = P} P-prop = _≃_.bijection $ Eq.⇔→≃ prop₂ prop₁ (uncurry $ elim _ (λ _ → Π-closure ext 1 λ _ → prop₁) λ where (inj₁ x) y → ∣ inj₁ (x , y) ∣ (inj₂ x) y → ∣ inj₂ (x , y) ∣) (rec prop₂ [ Σ-map ∣inj₁∣ id , Σ-map ∣inj₂∣ id ]) where prop₁ = ∥⊎∥-propositional prop₂ = Σ-closure 1 ∥⊎∥-propositional P-prop -- A variant of one of De Morgan's laws. ¬∥⊎∥¬↔¬× : Dec (¬ A) → Dec (¬ B) → ¬ A ∥⊎∥ ¬ B ↔ ¬ (A × B) ¬∥⊎∥¬↔¬× {A = A} {B = B} dec-¬A dec-¬B = record { surjection = record { logical-equivalence = record { to = rec (¬-propositional ext) ¬⊎¬→׬ ; from = ∣_∣ ∘ _↠_.from (¬⊎¬↠¬× ext dec-¬A dec-¬B) } ; right-inverse-of = λ _ → ¬-propositional ext _ _ } ; left-inverse-of = λ _ → ∥⊎∥-propositional _ _ } -- If ∥ A ∥ is decided, then A ∥⊎∥ B is equivalent to A ∥⊎∥ ¬ A × B. ∥⊎∥≃∥⊎∥¬× : Dec ∥ A ∥ → (A ∥⊎∥ B) ≃ (A ∥⊎∥ ¬ A × B) ∥⊎∥≃∥⊎∥¬× (yes ∥A∥) = Eq.⇔→≃ ∥⊎∥-propositional ∥⊎∥-propositional (const (∥∥-map inj₁ ∥A∥)) (id ∥⊎∥-cong proj₂) ∥⊎∥≃∥⊎∥¬× (no ¬∥A∥) = Eq.⇔→≃ ∥⊎∥-propositional ∥⊎∥-propositional (id ∥⊎∥-cong (¬∥A∥ ∘ ∣_∣) ,_) (id ∥⊎∥-cong proj₂) -- If ∥ B ∥ is decided, then A ∥⊎∥ B is equivalent to ¬ B × A ∥⊎∥ B. ∥⊎∥≃¬×∥⊎∥ : Dec ∥ B ∥ → (A ∥⊎∥ B) ≃ (¬ B × A ∥⊎∥ B) ∥⊎∥≃¬×∥⊎∥ {B = B} {A = A} dec-∥B∥ = A ∥⊎∥ B ↔⟨ ∥⊎∥-comm ⟩ B ∥⊎∥ A ↝⟨ ∥⊎∥≃∥⊎∥¬× dec-∥B∥ ⟩ B ∥⊎∥ ¬ B × A ↔⟨ ∥⊎∥-comm ⟩□ ¬ B × A ∥⊎∥ B □ ------------------------------------------------------------------------ -- Code related to Erased-singleton -- A corollary of erased-singleton-with-erased-center-propositional. ↠→↔Erased-singleton : {@0 y : B} (A↠B : A ↠ B) → Very-stableᴱ-≡ B → ∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ ↔ Erased-singleton y ↠→↔Erased-singleton {A = A} {y = y} A↠B s = ∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ ↝⟨ ∥∥-cong-⇔ (Surjection.Σ-cong-⇔ A↠B λ _ → F.id) ⟩ ∥ Erased-singleton y ∥ ↝⟨ ∥∥↔ (E.erased-singleton-with-erased-center-propositional s) ⟩□ Erased-singleton y □ mutual -- The right-to-left direction of the previous lemma does not depend -- on the assumption of stability. ↠→Erased-singleton→ : {@0 y : B} (A↠B : A ↠ B) → Erased-singleton y → ∥ (∃ λ (x : A) → Erased (_↠_.to A↠B x ≡ y)) ∥ ↠→Erased-singleton→ = _ -- Agda can infer the definition. _ : _↔_.from (↠→↔Erased-singleton A↠B s) x ≡ ↠→Erased-singleton→ A↠B x _ = refl _ -- A corollary of Σ-Erased-Erased-singleton↔ and ↠→↔Erased-singleton. Σ-Erased-∥-Σ-Erased-≡-∥↔ : (A↠B : A ↠ B) → Very-stableᴱ-≡ B → (∃ λ (x : Erased B) → ∥ (∃ λ (y : A) → Erased (_↠_.to A↠B y ≡ erased x)) ∥) ↔ B Σ-Erased-∥-Σ-Erased-≡-∥↔ {A = A} {B = B} A↠B s = (∃ λ (x : Erased B) → ∥ (∃ λ (y : A) → Erased (_↠_.to A↠B y ≡ erased x)) ∥) ↝⟨ (∃-cong λ _ → ↠→↔Erased-singleton A↠B s) ⟩ (∃ λ (x : Erased B) → Erased-singleton (erased x)) ↝⟨ E.Σ-Erased-Erased-singleton↔ ⟩□ B □ mutual -- Again the right-to-left direction of the previous lemma does not -- depend on the assumption of stability. →Σ-Erased-∥-Σ-Erased-≡-∥ : (A↠B : A ↠ B) → B → ∃ λ (x : Erased B) → ∥ (∃ λ (y : A) → Erased (_↠_.to A↠B y ≡ erased x)) ∥ →Σ-Erased-∥-Σ-Erased-≡-∥ = _ -- Agda can infer the definition. _ : _↔_.from (Σ-Erased-∥-Σ-Erased-≡-∥↔ A↠B s) x ≡ →Σ-Erased-∥-Σ-Erased-≡-∥ A↠B x _ = refl _ -- In an erased context the left-to-right direction of -- Σ-Erased-∥-Σ-Erased-≡-∥↔ returns the erased first component. @0 to-Σ-Erased-∥-Σ-Erased-≡-∥↔≡ : ∀ (A↠B : A ↠ B) (s : Very-stableᴱ-≡ B) x → _↔_.to (Σ-Erased-∥-Σ-Erased-≡-∥↔ A↠B s) x ≡ erased (proj₁ x) to-Σ-Erased-∥-Σ-Erased-≡-∥↔≡ A↠B s (E.[ x ] , y) = _↔_.to (Σ-Erased-∥-Σ-Erased-≡-∥↔ A↠B s) (E.[ x ] , y) ≡⟨⟩ proj₁ (_↔_.to (↠→↔Erased-singleton A↠B s) y) ≡⟨ erased (proj₂ (_↔_.to (↠→↔Erased-singleton A↠B s) y)) ⟩∎ x ∎
30.317052
127
0.526115
19813df46404caefbf31fb4bb6bc3684e95492d1
8,481
agda
Agda
TLP01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
TLP01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
TLP01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
module TLP01 where open import Data.Bool open import Data.Nat open import Data.String open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂; trans) _==ℕ_ : ℕ → ℕ → Bool zero ==ℕ zero = true suc n ==ℕ suc m = n ==ℕ m _ ==ℕ _ = false _<ℕ_ : ℕ → ℕ → Bool _ <ℕ zero = false zero <ℕ suc _ = true suc n <ℕ suc m = n <ℕ m -- ----- Star型の定義と同値性 ----- data Star : Set where NIL : Star TRU : Star N : ℕ → Star S : String → Star C : Star → Star → Star eqStar : Star → Star → Bool eqStar NIL NIL = true eqStar NIL _ = false eqStar TRU TRU = true eqStar TRU _ = false eqStar (N x) (N y) = x ==ℕ y eqStar (N _) _ = false eqStar (S x) (S y) = x == y eqStar (S _) _ = false eqStar (C x x₁) (C y y₁) = eqStar x y ∧ eqStar x₁ y₁ eqStar (C _ _) _ = false -- ----- 組込関数の定義 ----- CONS : Star → Star → Star CONS = C CAR : Star → Star CAR (C x _) = x CAR _ = NIL CDR : Star → Star CDR (C _ x₁) = x₁ CDR _ = NIL ATOM : Star → Star ATOM (C _ _) = NIL ATOM _ = TRU IF : Star → Star → Star → Star IF TRU a _ = a IF q a e = if eqStar q NIL then e else a EQUAL : Star → Star → Star EQUAL x y = if eqStar x y then TRU else NIL s-size : Star → ℕ s-size (C a b) = s-size a + s-size b + 1 s-size _ = 0 SIZE : Star → Star SIZE x = N (s-size x) s2n : Star → ℕ s2n (N x) = x s2n _ = 0 LT : Star → Star → Star LT x y = if s2n x <ℕ s2n y then TRU else NIL -- ----- Starから≡に ----- postulate ts : Star → Set ~ : Star → Star equal-eq : {x y : Star} → ts (EQUAL x y) → x ≡ y ifAP : {q x y : Star} → ts (IF q (EQUAL x y) TRU) → (ts q → x ≡ y) ifEP : {q x y : Star} → ts (IF q TRU (EQUAL x y)) → (ts (~ q) → x ≡ y) -- ----- 公理 ----- equal-same : (x : Star) → ts (EQUAL x x) equal-swap : (x y : Star) → ts (EQUAL (EQUAL x y) (EQUAL y x)) equal-if : (x y : Star) → ts (IF (EQUAL x y) (EQUAL x y) TRU) atom/cons : (x y : Star) → ts (EQUAL (ATOM (CONS x y)) NIL) car/cons : (x y : Star) → ts (EQUAL (CAR (CONS x y)) x) cdr/cons : (x y : Star) → ts (EQUAL (CDR (CONS x y)) y) cons/car+cdr : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (CONS (CAR x) (CDR x)) x)) if-true : (x y : Star) → ts (EQUAL (IF TRU x y) x) if-false : (x y : Star) → ts (EQUAL (IF NIL x y) y) if-same : (x y : Star) → ts (EQUAL (IF x y y) y) if-nest-A : (x y z : Star) → ts (IF x (EQUAL (IF x y z) y) TRU) if-nest-E : (x y z : Star) → ts (IF x TRU (EQUAL (IF x y z) z)) size/car : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (LT (SIZE (CAR x)) (SIZE x)) TRU)) size/cdr : (x : Star) → ts (IF (ATOM x) TRU (EQUAL (LT (SIZE (CDR x)) (SIZE x)) TRU)) -- ----- 練習 ----- postulate -- a b : Star foo : ts (EQUAL TRU NIL) hoge6 : (a b : Star) → (IF (EQUAL TRU NIL) TRU TRU) ≡ (IF (EQUAL TRU NIL) NIL TRU) hoge6 a b = ifAP (equal-if TRU NIL) foo hoge2 : (ATOM (CONS TRU TRU)) ≡ NIL hoge2 = equal-eq (atom/cons TRU TRU) -- hoge2' : (ATOM (CONS TRU TRU)) ≡ NIL -- hoge2' rewrite (equal-eq (atom-cons TRU TRU)) = {!!} hoge3 : (C TRU NIL) ≡ (C TRU NIL) hoge3 = equal-eq (equal-same (C TRU NIL)) hoge4 : (EQUAL TRU TRU) ≡ TRU hoge4 = begin (if eqStar TRU TRU then TRU else NIL) ≡⟨ refl ⟩ TRU ∎ where open PropEq.≡-Reasoning hoge5 : (EQUAL NIL NIL) ≡ TRU hoge5 = refl postulate j : (x : Star) → ts (~ (ATOM x)) hoge7 : (x : ℕ) → (IF (ATOM (N x)) TRU (LT (SIZE (CDR (N x))) (SIZE (N x)))) ≡ (IF (ATOM (N x)) TRU TRU) hoge7 x = ifEP (size/cdr (N x)) (j (N x)) -- ----- {- -- ----- 停止性で引っかかる ----- memb?' : Star → Star memb?' xs = (IF (ATOM xs) NIL (IF (EQUAL (CAR xs) (S "?")) TRU (memb?' (CDR xs)))) -} -- ----- memb?の停止性 ----- -- ----- SIZEを使う時はℕを引数にとる postulate premise : (xs : Star) → ts (~ (ATOM xs)) measure-memb? : (x : ℕ) → (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU (LT (SIZE (CDR (N x))) (SIZE (N x))))) ≡ TRU measure-memb? x = begin (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU (LT (SIZE (CDR (N x))) (SIZE (N x))))) ≡⟨ ifEP (size/cdr (N x)) (premise (N x)) ⟩ (IF (ATOM (N x)) TRU (IF (EQUAL (CAR (N x)) (S "?")) TRU TRU)) ≡⟨ equal-eq (if-same (EQUAL (CAR (N x)) (S "?")) TRU) ⟩ (IF (ATOM (N x)) TRU TRU) ≡⟨ equal-eq (if-same (ATOM (N x)) TRU) ⟩ TRU ∎ where open PropEq.≡-Reasoning -- ----- memb?の定義 ----- postulate memb? : Star → Star def-memb? : (xs : Star) → memb? xs ≡ (IF (ATOM xs) NIL (IF (EQUAL (CAR xs) (S "?")) TRU (memb? (CDR xs)))) -- ----- rembの定義 ----- postulate remb : Star → Star def-remb : (xs : Star) → remb xs ≡ (IF (ATOM xs) (S "'()") (IF (EQUAL (CAR xs) (S "?")) (remb (CDR xs)) (CONS (CAR xs) (remb (CDR xs))))) -- ----- 帰納的な証明(未完) ----- -- ----- ATOMを使う時はC x yを引数にとる postulate premise2 : (xs : Star) → ts (ATOM xs) atomt : (ATOM (S "'()")) ≡ TRU atomt = refl memb?/remb : (x y : Star) → (IF (ATOM (C x y)) (EQUAL (memb? (remb (C x y))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡ (IF (ATOM (C x y)) (EQUAL (IF TRU NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) memb?/remb x y = begin (IF (ATOM (C x y)) (EQUAL (memb? (remb (C x y))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong (λ t → ((IF (ATOM (C x y)) (EQUAL (memb? t) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) (def-remb (C x y)) ⟩ (IF (ATOM (C x y)) (EQUAL (memb? (IF (ATOM (C x y)) (S "'()") (IF (EQUAL (CAR (C x y)) (S "?")) (remb (CDR (C x y))) (CONS (CAR (C x y)) (remb (CDR (C x y))))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ ifAP (if-nest-A (ATOM (C x y)) (S "'()") ((IF (EQUAL (CAR (C x y)) (S "?")) (remb (CDR (C x y))) (CONS (CAR (C x y)) (remb (CDR (C x y))))))) (premise2 (C x y)) ⟩ (IF (ATOM (C x y)) (EQUAL (memb? (S "'()")) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong ((λ t → (IF (ATOM (C x y)) (EQUAL t NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) (def-memb? ((S "'()"))) ⟩ (IF (ATOM (C x y)) (EQUAL (IF (ATOM (S "'()")) NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ≡⟨ cong ((λ t → (IF (ATOM (C x y)) (EQUAL (IF t NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)))) atomt ⟩ (IF (ATOM (C x y)) (EQUAL (IF TRU NIL (IF (EQUAL (CAR (S "'()")) (S "?")) TRU (memb? (CDR (S "'()"))))) NIL) (IF (EQUAL (memb? (remb (CDR (C x y)))) NIL) (EQUAL (memb? (remb (C x y))) NIL) TRU)) ∎ where open PropEq.≡-Reasoning
29.14433
91
0.417168
5839ecd5108fdff6aca249d53f09425803168a5f
2,368
agda
Agda
notes/FOT/FOTC/Program/QuickSort/DomainPredicate.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/FOTC/Program/QuickSort/DomainPredicate.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/FOTC/Program/QuickSort/DomainPredicate.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- FOTC version of the domain predicate of quicksort given by the -- Bove-Capretta method ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.QuickSort.DomainPredicate where open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.Nat.Inequalities hiding ( le ; gt ) open import FOTC.Data.Nat.List.Type open import FOTC.Data.Nat.Type open import FOTC.Data.List ------------------------------------------------------------------------------ -- We need to define monadic inequalities. postulate le gt : D le-00 : le · zero · zero ≡ false le-0S : ∀ d → le · zero · succ₁ d ≡ true le-S0 : ∀ d → le · succ₁ d · zero ≡ false le-SS : ∀ d e → le · succ₁ d · succ₁ e ≡ lt d e postulate filter : D → D → D filter-[] : ∀ f → filter f [] ≡ [] filter-∷ : ∀ f d ds → filter f (d ∷ ds) ≡ (if f · d then d ∷ filter f (d ∷ ds) else filter f (d ∷ ds)) postulate filter-List : ∀ f {xs} → List xs → List (filter f xs) postulate qs : D → D qs-[] : qs [] ≡ [] qs-∷ : ∀ x xs → qs (x ∷ xs) ≡ qs (filter (gt · x) xs) ++ x ∷ qs (filter (le · x) xs) -- Domain predicate for quicksort. data Dqs : {xs : D} → List xs → Set where dnil : Dqs lnil dcons : ∀ {x xs} → (Lxs : List xs) → Dqs (filter-List (gt · x) Lxs) → Dqs (filter-List (le · x) Lxs) → Dqs (lcons x Lxs) -- Induction principle associated to the domain predicate of quicksort. Dqs-ind : (P : {xs : D} → List xs → Set) → P lnil → (∀ {x xs} → (Lxs : List xs) → Dqs (filter-List (gt · x) Lxs) → P (filter-List (gt · x) Lxs) → Dqs (filter-List (le · x) Lxs) → P (filter-List (le · x) Lxs) → P (lcons x Lxs)) → (∀ {xs} → {Lxs : List xs} → Dqs Lxs → P Lxs) Dqs-ind P P[] ih dnil = P[] Dqs-ind P P[] ih (dcons Lxs h₁ h₂) = ih Lxs h₁ (Dqs-ind P P[] ih h₁) h₂ (Dqs-ind P P[] ih h₂)
36.430769
78
0.451014
a0acb70a01b03253aaf71f1668a4115822f19d3b
1,058
agda
Agda
Univalence/Obsolete/FiniteFunctions.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/Obsolete/FiniteFunctions.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/Obsolete/FiniteFunctions.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
3
2016-05-29T01:56:33.000Z
2019-09-10T09:47:13.000Z
{-# OPTIONS --without-K #-} module FiniteFunctions where open import Data.Vec using (tabulate; _∷_) open import Data.Fin using (Fin; zero; suc) open import Data.Nat using (ℕ; zero; suc) open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; module ≡-Reasoning) open import Function using (_∘_) ------------------------------------------------------------------------------ -- Important: Extensionality for finite functions finext : {n : ℕ} {A : Set} → {f g : Fin n → A} → ((i : Fin n) → f i ≡ g i) → (tabulate f ≡ tabulate g) finext {0} _ = refl finext {suc n} {_} {f} {g} fi≡gi = begin (tabulate {suc n} f ≡⟨ refl ⟩ f zero ∷ tabulate {n} (f ∘ suc) ≡⟨ cong (λ x → x ∷ tabulate {n} (f ∘ suc)) (fi≡gi zero) ⟩ g zero ∷ tabulate {n} (f ∘ suc) ≡⟨ cong (_∷_ (g zero)) (finext {f = f ∘ suc} {g ∘ suc} (fi≡gi ∘ suc)) ⟩ g zero ∷ tabulate {n} (g ∘ suc) ≡⟨ refl ⟩ tabulate g ∎) where open ≡-Reasoning
35.266667
79
0.490548
a0deb4f31d0034fe9edc3d0fe643432f9dbd2c56
937
agda
Agda
setoid-cats/Category/CategoryCons.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
setoid-cats/Category/CategoryCons.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
setoid-cats/Category/CategoryCons.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
---------------------------------------------------------------------- -- This file contains constructions of new categories from existing -- -- categories. -- ---------------------------------------------------------------------- module Category.CategoryCons where open import Level open import Data.Product open import Setoid.Total open import Category.Category open SetoidFun -- The product of two categories. _●_ : {l₁ l₂ : Level} → (ℂ₁ : Cat {l₁}) → (ℂ₂ : Cat {l₂}) → Cat {l₁ ⊔ l₂} ℂ₁ ● ℂ₂ = record { Obj = (Obj ℂ₁) × (Obj ℂ₂); Hom = λ A B → (Hom ℂ₁ (proj₁ A) (proj₁ B)) ●ₛ ((Hom ℂ₂ (proj₂ A) (proj₂ B))); comp = λ {A} {B} {C} → (comp ℂ₁) ●b (comp ℂ₂); id = λ {A} → (id ℂ₁) , (id ℂ₂); assocPf = λ {A} {B} {C} {D} {f} {g} {h} → (assocPf ℂ₁) , (assocPf ℂ₂); idPf = λ {A} {B} {f} → (idPf ℂ₁) , (idPf ℂ₂) }
39.041667
89
0.426894
10c0de888fa4e8be01ca51a34e5e63cbe09d683f
6,298
agda
Agda
Categories/Cones.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Cones.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Cones.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
{-# OPTIONS --universe-polymorphism #-} module Categories.Cones where open import Level open import Categories.Support.PropositionalEquality open import Categories.Category open import Categories.Functor hiding (_∘_; _≡_; equiv; id; assoc; identityˡ; identityʳ; ∘-resp-≡) open import Categories.Cone record ConeMorphism {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} {F : Functor J C} (c₁ c₂ : Cone F) : Set (ℓ ⊔ e ⊔ o′ ⊔ ℓ′) where module c₁ = Cone c₁ module c₂ = Cone c₂ module C = Category C module J = Category J open C field f : C [ c₁.N , c₂.N ] .commute : ∀ {X} → c₁.ψ X ≡ c₂.ψ X ∘ f Cones : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) → Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′) (ℓ ⊔ e ⊔ o′ ⊔ ℓ′) e Cones {C = C} F = record { Obj = Obj′ ; _⇒_ = Hom′ ; _≡_ = _≡′_ ; _∘_ = _∘′_ ; id = record { f = id; commute = Equiv.sym identityʳ } ; assoc = assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; equiv = record { refl = Equiv.refl ; sym = Equiv.sym ; trans = Equiv.trans } ; ∘-resp-≡ = ∘-resp-≡ } where open Category C open Cone open ConeMorphism open Functor F infixr 9 _∘′_ infix 4 _≡′_ Obj′ = Cone F Hom′ : Obj′ → Obj′ → Set _ Hom′ = ConeMorphism _≡′_ : ∀ {A B} → Hom′ A B → Hom′ A B → Set _ F ≡′ G = f F ≡ f G _∘′_ : ∀ {A B C} → Hom′ B C → Hom′ A B → Hom′ A C _∘′_ {A} {B} {C} F G = record { f = f F ∘ f G ; commute = commute′ } where .commute′ : ∀ {X} → ψ A X ≡ ψ C X ∘ (f F ∘ f G) commute′ {X} = begin ψ A X ↓⟨ ConeMorphism.commute G ⟩ ψ B X ∘ f G ↓⟨ ∘-resp-≡ˡ (ConeMorphism.commute F) ⟩ (ψ C X ∘ f F) ∘ f G ↓⟨ assoc ⟩ ψ C X ∘ (f F ∘ f G) ∎ where open HomReasoning -- Equality of cone morphisms is equality of the underlying arrows in the -- base category, but the same is not (directly) true of the heterogeneous -- equality. These functions make the equivalence manifest. module Heteroconic {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) where open Heterogeneous C module ▵ = Heterogeneous (Cones F) open ▵ public using () renaming (_∼_ to _▵̃_) open ConeMorphism using () renaming (f to ⌞_⌝) demote-∼ : ∀ {K L K′ L′} {f : ConeMorphism K L} {g : ConeMorphism K′ L′} → f ▵̃ g → ⌞ f ⌝ ∼ ⌞ g ⌝ demote-∼ (≡⇒∼ y) = Heterogeneous.≡⇒∼ y -- XXX probably need another argument or something to nail things down -- promote-∼ : ∀ {K L K′ L′} {f : ConeMorphism {C = C} K L} {g : ConeMorphism {C = C} K′ L′} -- → ⌞ f ⌝ ∼ ⌞ g ⌝ → f ▵̃ g -- promote-∼ h = {!h!} -- The category of cones comes with an equivalence of objects, which can be -- used to float morphisms from one to another. Really it should have a -- setoid of objects, but we're not equipped for that. module Float {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) where module H = Heterogeneous C open H hiding (float₂; floatˡ; floatʳ; floatˡ-resp-trans; float₂-breakdown-lr; float₂-breakdown-rl) private lemma₁ : ∀ (A B : Cone F) {f₁ f₂ : C [ Cone.N A , Cone.N B ]} (f₁≣f₂ : f₁ ≣ f₂) .(pf₁ : ∀ {X} → C [ Cone.ψ A X ≡ C [ Cone.ψ B X ∘ f₁ ] ]) .(pf₂ : ∀ {X} → C [ Cone.ψ A X ≡ C [ Cone.ψ B X ∘ f₂ ] ]) → _≣_ {A = ConeMorphism A B} record { f = f₁ ; commute = pf₁ } record { f = f₂ ; commute = pf₂ } lemma₁ A B ≣-refl = λ ._ ._ → ≣-refl morphism-determines-cone-morphism-≣ : ∀ {A B} {m m′ : Cones F [ A , B ]} → ConeMorphism.f m ≣ ConeMorphism.f m′ → m ≣ m′ morphism-determines-cone-morphism-≣ {A} {B} {m} {m′} pf = lemma₁ A B pf (ConeMorphism.commute m) (ConeMorphism.commute m′) float₂ : ∀ {A A′ B B′} → F [ A ≜ A′ ] → F [ B ≜ B′ ] → Cones F [ A , B ] → Cones F [ A′ , B′ ] float₂ A≜A′ B≜B′ κ = record { f = H.float₂ (N-≣ A≜A′) (N-≣ B≜B′) f ; commute = λ {j} → ∼⇒≡ (trans (sym (ψ-≡ A≜A′ j)) (trans (≡⇒∼ commute) (∘-resp-∼ (ψ-≡ B≜B′ j) (float₂-resp-∼ (N-≣ A≜A′) (N-≣ B≜B′))))) } where open ConeMorphism κ open ConeOver._≜_ floatˡ : ∀ {A B B′} → F [ B ≜ B′ ] → Cones F [ A , B ] → Cones F [ A , B′ ] floatˡ {A = A} B≜B′ κ = record { f = H.floatˡ N-≣ f ; commute = λ {j} → C.Equiv.trans commute (∼⇒≡ (∘-resp-∼ (ψ-≡ j) (floatˡ-resp-∼ N-≣))) } where module A = Cone A open ConeMorphism κ open ConeOver._≜_ B≜B′ floatˡ-resp-refl : ∀ {A B} (κ : Cones F [ A , B ]) → floatˡ {A} {B} (ConeOver.≜-refl F) κ ≣ κ floatˡ-resp-refl f = ≣-refl floatˡ-resp-trans : ∀ {A B B′ B″} (B≜B′ : F [ B ≜ B′ ]) (B′≜B″ : F [ B′ ≜ B″ ]) (κ : Cones F [ A , B ]) → floatˡ {A} {B} {B″} (ConeOver.≜-trans F B≜B′ B′≜B″) κ ≣ floatˡ {A} {B′} {B″} B′≜B″ (floatˡ {A} {B} {B′} B≜B′ κ) floatˡ-resp-trans {A} {B} {B′} {B″} B≜B′ B′≜B″ κ = morphism-determines-cone-morphism-≣ {A} {B″} {floatˡ {A} {B} {B″} (ConeOver.≜-trans F B≜B′ B′≜B″) κ} {floatˡ {A} {B′} {B″} B′≜B″ (floatˡ {A} {B} {B′} B≜B′ κ)} (H.floatˡ-resp-trans (N-≣ B≜B′) (N-≣ B′≜B″) f) where module A = Cone A open ConeOver._≜_ open ConeMorphism κ floatʳ : ∀ {A A′ B} → F [ A ≜ A′ ] → Cones F [ A , B ] → Cones F [ A′ , B ] floatʳ {B = B} A≜A′ κ = record { f = ≣-subst (λ X → C [ X , B.N ]) N-≣ f ; commute = λ {j} → ∼⇒≡ (trans (sym (ψ-≡ j)) (trans (≡⇒∼ commute) (∘-resp-∼ʳ (floatʳ-resp-∼ N-≣)))) } where module B = Cone B open ConeMorphism κ open ConeOver._≜_ A≜A′ float₂-breakdown-lr : ∀ {A A′ B B′ : Cone F} (A≜A′ : F [ A ≜ A′ ]) (B≜B′ : F [ B ≜ B′ ]) (κ : Cones F [ A , B ]) → float₂ A≜A′ B≜B′ κ ≣ floatˡ B≜B′ (floatʳ A≜A′ κ) float₂-breakdown-lr {A′ = A′} {B′ = B′} A≜A′ B≜B′ κ = morphism-determines-cone-morphism-≣ {A = A′} {B′} {float₂ A≜A′ B≜B′ κ} {floatˡ B≜B′ (floatʳ A≜A′ κ)} (H.float₂-breakdown-lr (N-≣ A≜A′) (N-≣ B≜B′) (ConeMorphism.f κ)) where open ConeOver._≜_ float₂-breakdown-rl : ∀ {A A′ B B′ : Cone F} (A≜A′ : F [ A ≜ A′ ]) (B≜B′ : F [ B ≜ B′ ]) (κ : Cones F [ A , B ]) → float₂ A≜A′ B≜B′ κ ≣ floatʳ A≜A′ (floatˡ B≜B′ κ) float₂-breakdown-rl {A′ = A′} {B′ = B′} A≜A′ B≜B′ κ = morphism-determines-cone-morphism-≣ {A = A′} {B′} {float₂ A≜A′ B≜B′ κ} {floatʳ A≜A′ (floatˡ B≜B′ κ)} (H.float₂-breakdown-rl (N-≣ A≜A′) (N-≣ B≜B′) (ConeMorphism.f κ)) where open ConeOver._≜_
40.11465
296
0.528898
4a0e322637153a8f4f828d2ae40e289bd109572d
171
agda
Agda
src/container/w.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/container/w.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/container/w.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 container.w where open import container.w.core public open import container.w.algebra public open import container.w.fibration public
24.428571
40
0.783626