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
52069cc76b0ad76554576fb46ea3336a56bbd7cd
3,251
agda
Agda
test/Succeed/LaterPrims.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/LaterPrims.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/LaterPrims.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --cubical --guarded #-} module LaterPrims where open import Agda.Primitive open import Agda.Primitive.Cubical renaming (itIsOne to 1=1) open import Agda.Builtin.Cubical.Path open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS) module Prims where primitive primLockUniv : Set₁ open Prims renaming (primLockUniv to LockU) public private variable l : Level A B : Set l -- We postulate Tick as it is supposed to be an abstract sort. postulate Tick : LockU ▹_ : ∀ {l} → Set l → Set l ▹_ A = (@tick x : Tick) -> A ▸_ : ∀ {l} → ▹ Set l → Set l ▸ A = (@tick x : Tick) → A x next : A → ▹ A next x _ = x _⊛_ : ▹ (A → B) → ▹ A → ▹ B _⊛_ f x a = f a (x a) map▹ : (f : A → B) → ▹ A → ▹ B map▹ f x α = f (x α) transpLater : ∀ (A : I → ▹ Set) → ▸ (A i0) → ▸ (A i1) transpLater A u0 a = primTransp (\ i → A i a) i0 (u0 a) transpLater-prim : (A : I → ▹ Set) → (x : ▸ (A i0)) → ▸ (A i1) transpLater-prim A x = primTransp (\ i → ▸ (A i)) i0 x transpLater-test : ∀ (A : I → ▹ Set) → (x : ▸ (A i0)) → transpLater-prim A x ≡ transpLater A x transpLater-test A x = \ _ → transpLater-prim A x hcompLater-prim : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → ▸ A hcompLater-prim A φ u u0 a = primHComp (\ { i (φ = i1) → u i 1=1 a }) (outS u0 a) hcompLater : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → ▸ A hcompLater A φ u u0 = primHComp (\ { i (φ = i1) → u i 1=1 }) (outS u0) hcompLater-test : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → hcompLater A φ u u0 ≡ hcompLater-prim A φ u u0 hcompLater-test A φ u x = \ _ → hcompLater-prim A φ u x ap : ∀ {A B : Set} (f : A → B) → ∀ {x y} → x ≡ y → f x ≡ f y ap f eq = \ i → f (eq i) _$>_ : ∀ {A B : Set} {f g : A → B} → f ≡ g → ∀ x → f x ≡ g x eq $> x = \ i → eq i x later-ext : ∀ {A : Set} → {f g : ▹ A} → (▸ \ α → f α ≡ g α) → f ≡ g later-ext eq = \ i α → eq α i postulate dfix : ∀ {l} {A : Set l} → (▹ A → A) → ▹ A pfix : ∀ {l} {A : Set l} (f : ▹ A → A) → dfix f ≡ (\ _ → f (dfix f)) pfix' : ∀ {l} {A : Set l} (f : ▹ A → A) → ▸ \ α → dfix f α ≡ f (dfix f) pfix' f α i = pfix f i α fix : ∀ {l} {A : Set l} → (▹ A → A) → A fix f = f (dfix f) data gStream (A : Set) : Set where cons : (x : A) (xs : ▹ gStream A) → gStream A repeat : ∀ {A : Set} → A → gStream A repeat a = fix \ repeat▹ → cons a repeat▹ repeat-eq : ∀ {A : Set} (a : A) → repeat a ≡ cons a (\ α → repeat a) repeat-eq a = ap (cons a) (pfix (cons a)) map : ∀ {A B : Set} → (A → B) → gStream A → gStream B map f = fix \ map▹ → \ { (cons a as) → cons (f a) \ α → map▹ α (as α) } map-eq : ∀ {A B : Set} → (f : A → B) → ∀ a as → map f (cons a as) ≡ cons (f a) (\ α → map f (as α)) map-eq f a b = ap (cons _) (later-ext \ α → pfix' _ α $> b α) _∙_ : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z _∙_ {x = x} p q i = primHComp (\ j → \ { (i = i0) → x; (i = i1) → q j}) (p i) map-repeat : ∀ {A B : Set} → (a : A) → (f : A → B) → map f (repeat a) ≡ repeat (f a) map-repeat a f = fix \ prf▹ → ap (map f) (repeat-eq a) ∙ (map-eq f a _ ∙ ap (cons (f a)) (later-ext prf▹ ∙ later-ext \ α → \ i → pfix' (cons (f a)) α (primINeg i) )) tail : ∀ {A : Set} → gStream A → ▹ gStream A tail (cons x xs) = xs
31.872549
165
0.501999
03c8727a9592e86f52330ec804ab1ef94e807f02
510
agda
Agda
test/Fail/Issue1321.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1321.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1321.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Reported by fredrik.forsberg, Oct 21, 2014 -- The following code gives an internal error -- "An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/InstanceArguments.hs:269" -- on Agda head, since "n ≠ zero" is not expanded. open import Common.Prelude open import Common.Equality ¬ : (A : Set) → Set ¬ A = {{_ : A}} → ⊥ _≠_ : {A : Set} → (A → A → Set) x ≠ y = ¬ (x ≡ y) f : (n : Nat) ⦃ _ : n ≠ zero ⦄ -> Nat f n = n g : Nat g = f (suc zero)
22.173913
78
0.619608
cc390dd4264a6456f9a4993aa7a1ec1a462c7687
17,514
agda
Agda
Cubical/Papers/ZCohomology.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Papers/ZCohomology.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Papers/ZCohomology.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- Please do not move this file. Changes should only be made if necessary. This file contains pointers to the code examples and main results from the paper: Synthetic Integral Cohomology in Cubical Agda Guillaume Brunerie, Axel Ljungström, Anders Mörtberg Computer Science Logic (CSL) 2022 -} -- The "--safe" flag ensures that there are no postulates or -- unfinished goals {-# OPTIONS --safe #-} module Cubical.Papers.ZCohomology where -- Misc. open import Cubical.Data.Int hiding (_+_) open import Cubical.Data.Nat open import Cubical.Foundations.Everything open import Cubical.HITs.S1 open import Cubical.Data.Sum open import Cubical.Data.Sigma -- 2 open import Cubical.Core.Glue as Glue import Cubical.Foundations.Prelude as Prelude import Cubical.Foundations.GroupoidLaws as GroupoidLaws import Cubical.Foundations.Path as Path import Cubical.Foundations.Pointed as Pointed renaming (Pointed to Type∙) open import Cubical.HITs.S1 as S1 open import Cubical.HITs.Susp as Suspension open import Cubical.HITs.Sn as Sn open import Cubical.Homotopy.Loopspace as Loop open import Cubical.Foundations.HLevels as n-types open import Cubical.HITs.Truncation as Trunc open import Cubical.Homotopy.Connected as Connected import Cubical.HITs.Pushout as Push import Cubical.HITs.Wedge as ⋁ import Cubical.Foundations.Univalence as Unival import Cubical.Foundations.SIP as StructIdPrinc import Cubical.Algebra.Group as Gr import Cubical.Algebra.Group.GroupPath as GrPath -- 3 import Cubical.ZCohomology.Base as coHom renaming (coHomK to K ; coHomK-ptd to K∙) import Cubical.HITs.Sn.Properties as S import Cubical.ZCohomology.GroupStructure as GroupStructure import Cubical.ZCohomology.Properties as Properties renaming (Kn→ΩKn+1 to σ ; ΩKn+1→Kn to σ⁻¹) import Cubical.Experiments.ZCohomologyOld.Properties as oldCohom -- 4 import Cubical.ZCohomology.RingStructure.CupProduct as Cup import Cubical.ZCohomology.RingStructure.RingLaws as ⌣Ring import Cubical.ZCohomology.RingStructure.GradedCommutativity as ⌣Comm import Cubical.Foundations.Pointed.Homogeneous as Homogen -- 5 import Cubical.HITs.Torus as 𝕋² renaming (Torus to 𝕋²) import Cubical.HITs.KleinBottle as 𝕂² renaming (KleinBottle to 𝕂²) import Cubical.HITs.RPn as ℝP renaming (RP² to ℝP²) import Cubical.ZCohomology.Groups.Sn as HⁿSⁿ renaming (Hⁿ-Sᵐ≅0 to Hⁿ-Sᵐ≅1) import Cubical.ZCohomology.Groups.Torus as HⁿT² import Cubical.ZCohomology.Groups.Wedge as Hⁿ-wedge import Cubical.ZCohomology.Groups.KleinBottle as Hⁿ𝕂² import Cubical.ZCohomology.Groups.RP2 as HⁿℝP² renaming (H¹-RP²≅0 to H¹-RP²≅1) import Cubical.ZCohomology.Groups.CP2 as HⁿℂP² renaming (CP² to ℂP² ; ℤ→HⁿCP²→ℤ to g) {- Remark: ℂP² is defined as the pushout S² ← TotalHopf → 1 in the formalisation. TotalHopf is just the total space from the Hopf fibration. We have TotalHopf ≃ S³, and the map TotalHopf → S² is given by taking the first projection. This is equivalent to the description given in the paper, since h : S³ → S² is given by S³ ≃ TotalHopf → S² -} -- Additional material import Cubical.Homotopy.EilenbergSteenrod as ES-axioms import Cubical.ZCohomology.EilenbergSteenrodZ as satisfies-ES-axioms renaming (coHomFunctor to H^~ ; coHomFunctor' to Ĥ) import Cubical.ZCohomology.MayerVietorisUnreduced as MayerVietoris ----- 2. HOMOTOPY TYPE THEORY IN CUBICAL AGDA ----- -- 2.1 Important notions in Cubical Agda open Prelude using ( PathP ; _≡_ ; refl ; cong ; cong₂ ; funExt) open GroupoidLaws using (_⁻¹) open Prelude using ( transport ; subst ; hcomp) --- 2.2 Important concepts from HoTT/UF in Cubical Agda -- Pointed Types open Pointed using (Type∙) -- The circle, 𝕊¹ open S1 using (S¹) -- Suspensions open Suspension using (Susp) -- (Pointed) n-spheres, 𝕊ⁿ open Sn using (S₊∙) -- Loop spaces open Loop using (Ω^_) -- Eckmann-Hilton argument Eckmann-Hilton : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → isComm∙ ((Ω^ (suc n)) A) Eckmann-Hilton n α β = transport (λ i → cong (λ x → rUnit x (~ i)) α ∙ cong (λ x → lUnit x (~ i)) β ≡ cong (λ x → lUnit x (~ i)) β ∙ cong (λ x → rUnit x (~ i)) α) (λ i → (λ j → α (j ∧ ~ i) ∙ β (j ∧ i)) ∙ λ j → α (~ i ∨ j) ∙ β (i ∨ j)) -- n-types Note that we start indexing from 0 in the Cubical Library -- (so (-2)-types as referred to as 0-types, (-1) as 1-types, and so -- on) open n-types using (isOfHLevel) -- truncations open Trunc using (hLevelTrunc) -- elimination principle open Trunc using (elim) -- elimination principle for paths truncPathElim : ∀ {ℓ ℓ'} {A : Type ℓ} {x y : A} (n : ℕ) → {B : Path (hLevelTrunc (suc n) A) ∣ x ∣ ∣ y ∣ → Type ℓ'} → ((q : _) → isOfHLevel n (B q)) → ((p : x ≡ y) → B (cong ∣_∣ p)) → (q : _) → B q truncPathElim zero hlev ind q = hlev q .fst truncPathElim (suc n) {B = B} hlev ind q = subst B (Iso.leftInv (Trunc.PathIdTruncIso _) q) (help (ΩTrunc.encode-fun ∣ _ ∣ ∣ _ ∣ q)) where help : (q : _) → B (ΩTrunc.decode-fun ∣ _ ∣ ∣ _ ∣ q) help = Trunc.elim (λ _ → hlev _) ind -- Connectedness open Connected using (isConnected) -- Pushouts open Push using (Pushout) -- Wedge sum open ⋁ using (_⋁_) -- 2.3 Univalence -- Univalence and the ua function respectively open Unival using (univalence ; ua) -- Glue types open Glue using (Glue) -- The structure identity principle and the sip function -- respectively open StructIdPrinc using (SIP ; sip) -- Groups open Gr using (Group) -- Isomorphic groups are path equal open GrPath using (GroupPath) ----- 3. INTEGRAL COHOMOLOGY IN CUBICAL AGDA ----- -- 3.1 Eilenberg-MacLane spaces -- Eilenberg-MacLane spaces Kₙ (unpointed and pointed respectively) open coHom using (K ; K∙) -- Proposition 7 open S using (sphereConnected) -- Lemma 8 open S using (wedgeconFun; wedgeconLeft ; wedgeconRight) -- restated to match the formulation in the paper wedgeConSn' : ∀ {ℓ} (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ} → ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)) → (fₗ : (x : _) → A x (ptSn (suc m))) → (fᵣ : (x : _) → A (ptSn (suc n)) x) → (p : fₗ (ptSn (suc n)) ≡ fᵣ (ptSn (suc m))) → Σ[ F ∈ ((x : S₊ (suc n)) (y : S₊ (suc m)) → A x y) ] (Σ[ (left , right) ∈ ((x : S₊ (suc n)) → fₗ x ≡ F x (ptSn (suc m))) × ((x : S₊ (suc m)) → fᵣ x ≡ F (ptSn (suc n)) x) ] p ≡ left (ptSn (suc n)) ∙ (right (ptSn (suc m))) ⁻¹) wedgeConSn' zero zero hlev fₗ fᵣ p = (wedgeconFun 0 0 hlev fᵣ fₗ p) , ((λ x → sym (wedgeconRight 0 0 hlev fᵣ fₗ p x)) , λ _ → refl) -- right holds by refl , rUnit _ wedgeConSn' zero (suc m) hlev fₗ fᵣ p = (wedgeconFun 0 (suc m) hlev fᵣ fₗ p) , ((λ _ → refl) -- left holds by refl , (λ x → sym (wedgeconLeft 0 (suc m) hlev fᵣ fₗ p x))) , lUnit _ wedgeConSn' (suc n) m hlev fₗ fᵣ p = (wedgeconFun (suc n) m hlev fᵣ fₗ p) , ((λ x → sym (wedgeconRight (suc n) m hlev fᵣ fₗ p x)) , λ _ → refl) -- right holds by refl , rUnit _ -- +ₖ (addition) and 0ₖ open GroupStructure using (_+ₖ_ ; 0ₖ) -- -ₖ (subtraction) open GroupStructure using (-ₖ_) -- The function σ : Kₙ → ΩKₙ₊₁ open Properties using (σ) -- Group laws for +ₖ open GroupStructure using ( rUnitₖ ; lUnitₖ ; rCancelₖ ; lCancelₖ ; commₖ ; assocₖ) -- All group laws are equal to refl at 0ₖ -- rUnitₖ (definitional) 0-rUnit≡refl : rUnitₖ 0 (0ₖ 0) ≡ refl 1-rUnit≡refl : rUnitₖ 1 (0ₖ 1) ≡ refl n≥2-rUnit≡refl : {n : ℕ} → rUnitₖ (2 + n) (0ₖ (2 + n)) ≡ refl 0-rUnit≡refl = refl 1-rUnit≡refl = refl n≥2-rUnit≡refl = refl -- lUnitₖ (definitional) 0-lUnit≡refl : lUnitₖ 0 (0ₖ 0) ≡ refl 1-lUnit≡refl : lUnitₖ 1 (0ₖ 1) ≡ refl n≥2-lUnit≡refl : {n : ℕ} → lUnitₖ (2 + n) (0ₖ (2 + n)) ≡ refl 0-lUnit≡refl = refl 1-lUnit≡refl = refl n≥2-lUnit≡refl = refl -- assocₖ (definitional) 0-assoc≡refl : assocₖ 0 (0ₖ 0) (0ₖ 0) (0ₖ 0) ≡ refl 1-assoc≡refl : assocₖ 1 (0ₖ 1) (0ₖ 1) (0ₖ 1) ≡ refl n≥2-assoc≡refl : {n : ℕ} → assocₖ (2 + n) (0ₖ (2 + n)) (0ₖ (2 + n)) (0ₖ (2 + n)) ≡ refl 0-assoc≡refl = refl 1-assoc≡refl = refl n≥2-assoc≡refl = refl -- commₖ (≡ refl ∙ refl for n ≥ 2) 0-comm≡refl : commₖ 0 (0ₖ 0) (0ₖ 0) ≡ refl 1-comm≡refl : commₖ 1 (0ₖ 1) (0ₖ 1) ≡ refl n≥2-comm≡refl : {n : ℕ} → commₖ (2 + n) (0ₖ (2 + n)) (0ₖ (2 + n)) ≡ refl 0-comm≡refl = refl 1-comm≡refl = refl n≥2-comm≡refl = sym (rUnit refl) -- lCancelₖ (definitional) 0-lCancel≡refl : lCancelₖ 0 (0ₖ 0) ≡ refl 1-lCancel≡refl : lCancelₖ 1 (0ₖ 1) ≡ refl n≥2-lCancel≡refl : {n : ℕ} → lCancelₖ (2 + n) (0ₖ (2 + n)) ≡ refl 0-lCancel≡refl = refl 1-lCancel≡refl = refl n≥2-lCancel≡refl = refl -- rCancelₖ (≡ (refl ∙ refl) ∙ refl for n ≥ 2) 0-rCancel≡refl : rCancelₖ 0 (0ₖ 0) ≡ refl 1-rCancel≡refl : rCancelₖ 1 (0ₖ 1) ≡ refl n≥2-rCancel≡refl : {n : ℕ} → rCancelₖ (2 + n) (0ₖ (2 + n)) ≡ refl 0-rCancel≡refl = refl 1-rCancel≡refl = refl n≥2-rCancel≡refl i = rUnit (rUnit refl (~ i)) (~ i) -- Proof that there is a unique h-structure on Kₙ -- +ₖ defines an h-Structure on Kₙ open GroupStructure using (_+ₖ_ ; 0ₖ ; rUnitₖ ; lUnitₖ ; lUnitₖ≡rUnitₖ) -- and so does Brunerie's addition open oldCohom using (_+ₖ_ ; 0ₖ ; rUnitₖ ; lUnitₖ ; rUnitlUnit0) -- consequently both additions agree open GroupStructure using (+ₖ-unique) open oldCohom using (addLemma) additionsAgree : (n : ℕ) → GroupStructure._+ₖ_ {n = n} ≡ oldCohom._+ₖ_ {n = n} additionsAgree zero i x y = oldCohom.addLemma x y (~ i) additionsAgree (suc n) i x y = +ₖ-unique n (GroupStructure._+ₖ_) (oldCohom._+ₖ_) (GroupStructure.rUnitₖ (suc n)) (GroupStructure.lUnitₖ (suc n)) (oldCohom.rUnitₖ (suc n)) (oldCohom.lUnitₖ (suc n)) (sym (lUnitₖ≡rUnitₖ (suc n))) (rUnitlUnit0 (suc n)) x y i -- Theorem 9 (Kₙ ≃ ΩKₙ₊₁) open Properties using (Kn≃ΩKn+1) -- σ and σ⁻¹ are morphisms -- (for σ⁻¹ this is proved directly without using the fact that σ is a morphism) open Properties using (Kn→ΩKn+1-hom ; ΩKn+1→Kn-hom) -- Lemma 10 (p ∙ q ≡ cong²₊(p,q)) for n = 1 and n ≥ 2 respectively open GroupStructure using (∙≡+₁ ; ∙≡+₂) -- Lemma 11 (cong²₊ is commutative) and Theorem 12 respectively open GroupStructure using (cong+ₖ-comm ; isCommΩK) -- 3.2 Group structure on Hⁿ(A) -- +ₕ (addition), -ₕ and 0ₕ open GroupStructure using (_+ₕ_ ; -ₕ_ ; 0ₕ) -- Cohomology group structure open GroupStructure using ( rUnitₕ ; lUnitₕ ; rCancelₕ ; lCancelₕ ; commₕ ; assocₕ) --- Additional material ------------------------------------------- -- Reduced cohomology, group structure open GroupStructure using (coHomRedGroupDir) -- Equality of unreduced and reduced cohmology open Properties using (coHomGroup≡coHomRedGroup) -------------------------------------------------------------------- ----- 4. The Cup Product and Cohomology Ring ----- -- 4.1 -- Lemma 13 open Properties using (isOfHLevel↑∙) -- ⌣ₖ open Cup using (_⌣ₖ_) -- ⌣ₖ is pointed in both arguments open ⌣Ring using (0ₖ-⌣ₖ ; ⌣ₖ-0ₖ) -- The cup product open Cup using (_⌣_) -- 4.2 -- Lemma 14 Lem14 : ∀ {ℓ} {A : Type∙ ℓ} (n : ℕ) (f g : A →∙ K∙ n) → fst f ≡ fst g → f ≡ g Lem14 n f g p = Homogen.→∙Homogeneous≡ (Properties.isHomogeneousKn n) p -- Proposition 15 open ⌣Ring using (leftDistr-⌣ₖ ; rightDistr-⌣ₖ) -- Lemma 16 open ⌣Ring using (assocer-helpFun≡) -- Proposition 17 open ⌣Ring using (assoc-⌣ₖ) -- Proposition 18 open ⌣Comm using (gradedComm-⌣ₖ) -- Ring structure on ⌣ open ⌣Ring using (leftDistr-⌣ ; rightDistr-⌣ ; assoc-⌣ ; 1⌣ ; rUnit⌣ ; lUnit⌣ ; ⌣0 ; 0⌣) open ⌣Comm using (gradedComm-⌣) ----- 5. CHARACTERIZING INTEGRAL COHOMOLOGY GROUPS ----- -- 5.1 -- Proposition 19 open HⁿSⁿ using (Hⁿ-Sⁿ≅ℤ) -- 5.2 -- The torus open 𝕋² using (𝕋²) -- Propositions 20 and 21 respectively open HⁿT² using (H¹-T²≅ℤ×ℤ ; H²-T²≅ℤ) -- 5.3 -- The Klein bottle open 𝕂² using (𝕂²) -- The real projective plane open ℝP using (ℝP²) -- Proposition 22 and 24 respectively -- ℤ/2ℤ is represented by Bool with the unique group structure -- Lemma 23 is used implicitly in H²-𝕂²≅Bool open Hⁿ𝕂² using (H¹-𝕂²≅ℤ ; H²-𝕂²≅Bool) -- First and second cohomology groups of ℝP² respectively open HⁿℝP² using (H¹-RP²≅1 ; H²-RP²≅Bool) -- 5.4 -- The complex projective plane open HⁿℂP² using (ℂP²) -- Second and fourth cohomology groups ℂP² respectively open HⁿℂP² using (H²CP²≅ℤ ; H⁴CP²≅ℤ) -- 6 Proving by computations in Cubical Agda -- Proof of m = n = 1 case of graded commutativity (post truncation elimination): -- Uncomment and give it a minute. The proof is currently not running very fast. {- open ⌣Comm using (-ₖ^_·_ ) n=m=1 : (a b : S¹) → _⌣ₖ_ {n = 1} {m = 1} ∣ a ∣ ∣ b ∣ ≡ (-ₖ (_⌣ₖ_ {n = 1} {m = 1} ∣ b ∣ ∣ a ∣)) n=m=1 base base = refl n=m=1 base (loop i) k = -ₖ (Properties.Kn→ΩKn+10ₖ _ (~ k) i) n=m=1 (loop i) base k = Properties.Kn→ΩKn+10ₖ _ k i n=m=1 (loop i) (loop j) k = -- This hcomp is just a simple rewriting to get paths in Ω²K₂ hcomp (λ r → λ { (i = i0) → -ₖ Properties.Kn→ΩKn+10ₖ _ (~ k ∨ ~ r) j ; (i = i1) → -ₖ Properties.Kn→ΩKn+10ₖ _ (~ k ∨ ~ r) j ; (j = i0) → Properties.Kn→ΩKn+10ₖ _ (k ∨ ~ r) i ; (j = i1) → Properties.Kn→ΩKn+10ₖ _ (k ∨ ~ r) i ; (k = i0) → doubleCompPath-filler (sym (Properties.Kn→ΩKn+10ₖ _)) (λ j i → _⌣ₖ_ {n = 1} {m = 1} ∣ loop i ∣ ∣ loop j ∣) (Properties.Kn→ΩKn+10ₖ _) (~ r) j i ; (k = i1) → -ₖ doubleCompPath-filler (sym (Properties.Kn→ΩKn+10ₖ _)) (λ j i → _⌣ₖ_ {n = 1} {m = 1} ∣ loop i ∣ ∣ loop j ∣) (Properties.Kn→ΩKn+10ₖ _) (~ r) i j}) ((main ∙ sym (cong-∙∙ (cong (-ₖ_)) (sym (Properties.Kn→ΩKn+10ₖ _)) (λ j i → (_⌣ₖ_ {n = 1} {m = 1} ∣ loop i ∣ ∣ loop j ∣)) (Properties.Kn→ΩKn+10ₖ _))) k i j) where open import Cubical.Foundations.Equiv.HalfAdjoint t : Iso (typ ((Ω^ 2) (K∙ 2))) ℤ t = compIso (congIso (invIso (Properties.Iso-Kn-ΩKn+1 1))) (invIso (Properties.Iso-Kn-ΩKn+1 0)) p₁ = flipSquare ((sym (Properties.Kn→ΩKn+10ₖ _)) ∙∙ (λ j i → _⌣ₖ_ {n = 1} {m = 1} ∣ loop i ∣ ∣ loop j ∣) ∙∙ (Properties.Kn→ΩKn+10ₖ _)) p₂ = (cong (cong (-ₖ_)) ((sym (Properties.Kn→ΩKn+10ₖ _)))) ∙∙ (λ j i → -ₖ (_⌣ₖ_ {n = 1} {m = 1} ∣ loop i ∣ ∣ loop j ∣)) ∙∙ (cong (cong (-ₖ_)) (Properties.Kn→ΩKn+10ₖ _)) computation : Iso.fun t p₁ ≡ Iso.fun t p₂ computation = refl main : p₁ ≡ p₂ main = p₁ ≡⟨ sym (Iso.leftInv t p₁) ⟩ (Iso.inv t (Iso.fun t p₁)) ≡⟨ cong (Iso.inv t) computation ⟩ Iso.inv t (Iso.fun t p₂) ≡⟨ Iso.leftInv t p₂ ⟩ p₂ ∎ -} -- 𝕋² ≠ S² ∨ S¹ ∨ S¹ open HⁿT² using (T²≠S²⋁S¹⋁S¹) -- Second "Brunerie number" open HⁿℂP² using (g) brunerie2 : ℤ brunerie2 = g 1 -- Additional material (from the appendix of the preprint) ----- A. Proofs ----- -- A.2 Proofs for Section 4 -- Lemma 27 open Homogen using (→∙Homogeneous≡) -- Lemma 28 open Homogen using (isHomogeneous→∙) -- Lemma 29 open Properties using (isHomogeneousKn) -- Lemma 30, parts 1-3 respectively open Path using (sym≡flipSquare ; sym-cong-sym≡id ; sym≡cong-sym) -- Lemma 31 open ⌣Comm using (cong-ₖ-gen-inr) -- A.3 Proofs for Section 5 -- Proposition 32 open HⁿSⁿ using (Hⁿ-Sᵐ≅1) ----- B. THE EILENBERG-STEENROD AXIOMS ----- -- B.1 The axioms in HoTT/UF -- The axioms are defined as a record type open ES-axioms.coHomTheory -- Proof of the claim that the alternative reduced cohomology functor -- Ĥ is the same as the usual reduced cohomology functor _ : ∀ {ℓ} → satisfies-ES-axioms.H^~ {ℓ} ≡ satisfies-ES-axioms.Ĥ _ = satisfies-ES-axioms.coHomFunctor≡coHomFunctor' -- B.2 Verifying the axioms -- Propositions 35 and 36. _ : ∀ {ℓ} → ES-axioms.coHomTheory {ℓ} satisfies-ES-axioms.H^~ _ = satisfies-ES-axioms.isCohomTheoryZ -- B.3 Characterizing Z-cohomology groups using the axioms -- Theorem 37 open MayerVietoris.MV using ( Ker-i⊂Im-d ; Im-d⊂Ker-i ; Ker-Δ⊂Im-i ; Im-i⊂Ker-Δ ; Ker-d⊂Im-Δ ; Im-Δ⊂Ker-d) ----- C. BENCHMARKING COMPUTATIONS WITH THE COHOMOLOGY GROUPS ----- import Cubical.Experiments.ZCohomology.Benchmarks
32.614525
90
0.58576
37b3923ebd7333c39c675c1719bf2c4a38e7f338
2,723
agda
Agda
src/Categories/Functor/Instance/Discrete.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
1
2021-04-18T18:21:47.000Z
2021-04-18T18:21:47.000Z
src/Categories/Functor/Instance/Discrete.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
null
null
null
src/Categories/Functor/Instance/Discrete.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Instance.Discrete where -- Discrete Functor -- from Sets to Cats. This works, unlike in the previous version of the library, -- because the equality in Cats is properly NaturalIsomorphism instead of something stricter, -- no need for that pesky Heterogeneous anything. open import Categories.Category open import Categories.Functor open import Categories.Category.Instance.Sets open import Categories.Category.Instance.Cats open import Categories.NaturalTransformation using (ntHelper) open import Categories.NaturalTransformation.NaturalIsomorphism import Categories.Category.Discrete as D import Relation.Binary.PropositionalEquality as ≡ open import Function using () renaming (id to idf; _∘_ to _●_) Discrete : ∀ {o} → Functor (Sets o) (Cats o o o) Discrete {o} = record { F₀ = D.Discrete ; F₁ = DiscreteFunctor ; identity = DiscreteId ; homomorphism = PointwiseHom ; F-resp-≈ = ExtensionalityNI } where DiscreteFunctor : {A B : Set o} → (A → B) → Cats o o o [ D.Discrete A , D.Discrete B ] DiscreteFunctor f = record { F₀ = f ; F₁ = ≡.cong f ; identity = ≡.refl ; homomorphism = λ { {_} {_} {_} {≡.refl} {≡.refl} → ≡.refl} ; F-resp-≈ = λ g≡h → ≡.cong (≡.cong f) g≡h -- marvel at the weirdness involved } DiscreteId : {A : Set o} → NaturalIsomorphism (DiscreteFunctor {A} idf) id DiscreteId = record { F⇒G = record { η = λ X → ≡.refl ; commute = λ { ≡.refl → ≡.refl } ; sym-commute = λ { ≡.refl → ≡.refl} } ; F⇐G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl } ; sym-commute = λ { ≡.refl → ≡.refl} } ; iso = λ X → record { isoˡ = ≡.refl ; isoʳ = ≡.refl } } PointwiseHom : {X Y Z : Set o} {g : X → Y} {h : Y → Z} → NaturalIsomorphism (DiscreteFunctor (h ● g)) (DiscreteFunctor h ∘F DiscreteFunctor g) PointwiseHom = record { F⇒G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl} ; sym-commute = λ { ≡.refl → ≡.refl} } ; F⇐G = record { η = λ _ → ≡.refl ; commute = λ { ≡.refl → ≡.refl} ; sym-commute = λ { ≡.refl → ≡.refl} } ; iso = λ X → record { isoˡ = ≡.refl ; isoʳ = ≡.refl } } ExtensionalityNI : {A B : Set o} {g h : A → B} → ({x : A} → g x ≡.≡ h x) → NaturalIsomorphism (DiscreteFunctor g) (DiscreteFunctor h) ExtensionalityNI g≡h = record { F⇒G = ntHelper record { η = λ X → g≡h {X} ; commute = λ { ≡.refl → ≡.sym (≡.trans-reflʳ g≡h)} } ; F⇐G = ntHelper record { η = λ X → ≡.sym (g≡h {X}) ; commute = λ { ≡.refl → ≡.sym (≡.trans-reflʳ _)} } ; iso = λ X → record { isoˡ = ≡.trans-symʳ g≡h ; isoʳ = ≡.trans-symˡ g≡h } }
47.77193
113
0.593463
1a242244d333b730622c3c2457329fc5d0d31ea7
351
agda
Agda
examples/simple/let/let-output.agda
Yiergot/vehicle
7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df
[ "BSD-3-Clause" ]
null
null
null
examples/simple/let/let-output.agda
Yiergot/vehicle
7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df
[ "BSD-3-Clause" ]
null
null
null
examples/simple/let/let-output.agda
Yiergot/vehicle
7cdd7734fe0d50cc7d5a3b3c6bdddba778cfe6df
[ "BSD-3-Clause" ]
null
null
null
-- WARNING: This file was generated automatically by Vehicle -- and should not be modified manually! -- Metadata -- - Agda version: 2.6.2 -- - AISEC version: 0.1.0.1 -- - Time generated: ??? open import Data.Unit module MyTestModule where e1 : let x = ⊤ in x e1 = checkProperty record { databasePath = DATABASE_PATH ; propertyUUID = ???? }
21.9375
60
0.678063
0dedd0bd966af5fbc7eeb78e998889e6d542d525
2,274
agda
Agda
test/Succeed/Lambda.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/Lambda.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Lambda.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --no-termination-check #-} module Lambda where module Prelude where data Bool : Set where true : Bool false : Bool if_then_else_ : {A : Set} -> Bool -> A -> A -> A if true then x else y = x if false then x else y = y _∧_ : Bool -> Bool -> Bool true ∧ y = y false ∧ y = false _∨_ : Bool -> Bool -> Bool true ∨ y = true false ∨ y = y ¬_ : Bool -> Bool ¬ true = false ¬ false = true data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A _++_ : {A : Set} -> List A -> List A -> List A nil ++ ys = ys (x :: xs) ++ ys = x :: xs ++ ys filter : {A : Set} -> (A -> Bool) -> List A -> List A filter p nil = nil filter p (x :: xs) = if p x then x :: filter p xs else filter p xs postulate String : Set Char : Set {-# BUILTIN BOOL Bool #-} {-# BUILTIN FALSE false #-} {-# BUILTIN TRUE true #-} {-# BUILTIN STRING String #-} {-# BUILTIN CHAR Char #-} {-# BUILTIN LIST List #-} {-# BUILTIN NIL nil #-} {-# BUILTIN CONS _::_ #-} primitive primStringEquality : String -> String -> Bool _==_ = primStringEquality infix 10 if_then_else_ infixr 50 _::_ _++_ infixl 5 _∨_ infixl 7 _∧_ infix 50 ¬_ infix 15 _==_ open Prelude Name : Set Name = String data Exp : Set where var : Name -> Exp ƛ_⟶_ : Name -> Exp -> Exp _$_ : Exp -> Exp -> Exp infixl 50 _$_ infix 20 ƛ_⟶_ infix 80 _[_/_] infix 15 _∈_ _∈_ : Name -> List Name -> Bool x ∈ y :: ys = x == y ∨ x ∈ ys x ∈ nil = false -- Free variables FV : Exp -> List Name FV (var x) = x :: nil FV (s $ t) = FV s ++ FV t FV (ƛ x ⟶ t) = filter (\y -> ¬ (x == y)) (FV t) -- Fresh names fresh : Name -> Exp -> Name fresh x e = fresh' (FV e) where fresh' : List Name -> Name fresh' xs = "z" -- TODO -- Substitution _[_/_] : Exp -> Exp -> Name -> Exp var x [ r / z ] = if x == z then r else var x (s $ t) [ r / z ] = s [ r / z ] $ t [ r / z ] (ƛ x ⟶ t) [ r / z ] = if x == z then ƛ x ⟶ t else if x ∈ FV r then ( let y : Name y = fresh x r in ƛ y ⟶ t [ var y / x ] [ r / z ] ) else ƛ x ⟶ t [ r / z ]
20.862385
68
0.480651
36bb6e1570c33e66e541200c6d617f2a8565de1f
592
agda
Agda
Math/NumberTheory/Summation/Nat/Properties/Lemma.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
3
2020-04-07T17:49:42.000Z
2020-04-21T00:03:43.000Z
Math/NumberTheory/Summation/Nat/Properties/Lemma.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
Math/NumberTheory/Summation/Nat/Properties/Lemma.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Math.NumberTheory.Summation.Nat.Properties.Lemma where -- agda-stdlib open import Data.Nat open import Data.Nat.Properties open import Data.Nat.Solver open import Relation.Binary.PropositionalEquality open import Function.Base lemma₁ : ∀ n → n * (1 + n) * (1 + 2 * n) + 6 * ((1 + n) ^ 2) ≡ (1 + n) * (2 + n) * (1 + 2 * (1 + n)) lemma₁ = solve 1 (λ n → (n :* (con 1 :+ n) :* (con 1 :+ con 2 :* n) :+ con 6 :* (con 1 :+ n) :^ 2) := (con 1 :+ n) :* (con 2 :+ n) :* (con 1 :+ con 2 :* (con 1 :+ n)) ) refl where open +-*-Solver
31.157895
79
0.545608
11c2f0f2753004a2ba0d4fff40915341c0997c04
1,129
agda
Agda
src/Pi/ArrMp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
26
2015-08-31T09:49:52.000Z
2021-11-13T12:37:44.000Z
src/Pi/ArrMp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
null
null
null
src/Pi/ArrMp.agda
mietek/formal-logic
2dd761bfa96ccda089888e8defa6814776fa2922
[ "X11" ]
null
null
null
-- Minimal implicational logic, PHOAS approach, initial encoding module Pi.ArrMp where -- Types infixr 0 _=>_ data Ty : Set where UNIT : Ty _=>_ : Ty -> Ty -> Ty -- Context and truth judgement Cx : Set1 Cx = Ty -> Set isTrue : Ty -> Cx -> Set isTrue a tc = tc a -- Terms module ArrMp where infixl 1 _$_ data Tm (tc : Cx) : Ty -> Set where var : forall {a} -> isTrue a tc -> Tm tc a lam' : forall {a b} -> (isTrue a tc -> Tm tc b) -> Tm tc (a => b) _$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b lam'' : forall {tc a b} -> (Tm tc a -> Tm tc b) -> Tm tc (a => b) lam'' f = lam' \x -> f (var x) syntax lam'' (\a -> b) = lam a => b Thm : Ty -> Set1 Thm a = forall {tc} -> Tm tc a open ArrMp public -- Example theorems aI : forall {a} -> Thm (a => a) aI = lam x => x aK : forall {a b} -> Thm (a => b => a) aK = lam x => lam _ => x aS : forall {a b c} -> Thm ((a => b => c) => (a => b) => a => c) aS = lam f => lam g => lam x => f $ x $ (g $ x) tSKK : forall {a} -> Thm (a => a) tSKK {a = a} = aS {b = a => a} $ aK $ aK
18.209677
70
0.476528
0dbfb5026a7aacfbca3ce5c96b7a06dcaef40e5f
528
agda
Agda
test/Succeed/Issue282.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue282.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue282.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue282 where module Works where record R : Set where constructor c -- foo = R.c -- Andreas, 2019-11-11, #4189, no more qualified record constructors module Doesn't_work where private record R : Set where constructor c -- foo = R.c -- Andreas, 2019-11-11, #4189, no more qualified record constructors -- Bug.agda:17,9-12 -- Not in scope: -- R.c at Bug.agda:17,9-12 -- when scope checking R.c module Doesn't_work_either where private data D : Set where c : D foo = D.c
16.5
84
0.653409
cc8b1c27ba6d05b143693b7a64ee02c25784bd8c
474
agda
Agda
Cubical/Algebra/MonoidSolver/MonoidExpression.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/MonoidSolver/MonoidExpression.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/MonoidSolver/MonoidExpression.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.MonoidSolver.MonoidExpression where open import Cubical.Foundations.Prelude open import Cubical.Data.FinData open import Cubical.Data.Nat open import Cubical.Data.Vec open import Cubical.Algebra.CommMonoid private variable ℓ : Level infixl 7 _⊗_ -- Expression in a type M with n variables data Expr (M : Type ℓ) (n : ℕ) : Type ℓ where ∣ : Fin n → Expr M n ε⊗ : Expr M n _⊗_ : Expr M n → Expr M n → Expr M n
20.608696
58
0.704641
735a1c714035ae420526e84bcccfc9048eed62e4
812
agda
Agda
src/Lambda/Delay-monad/Virtual-machine.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
2
2020-05-21T22:59:18.000Z
2020-07-03T08:56:08.000Z
src/Lambda/Delay-monad/Virtual-machine.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
src/Lambda/Delay-monad/Virtual-machine.agda
nad/partiality-monad
f69749280969f9093e5e13884c6feb0ad2506eae
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A virtual machine ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Lambda.Delay-monad.Virtual-machine where open import Equality.Propositional open import Maybe equality-with-J open import Monad equality-with-J open import Delay-monad open import Delay-monad.Monad open import Lambda.Delay-monad.Interpreter open import Lambda.Syntax open import Lambda.Virtual-machine open Closure Code mutual -- A functional semantics for the VM. exec : ∀ {i} → State → M i Value exec s with step s ... | continue s′ = laterM (∞exec s′) ... | done v = return v ... | crash = fail ∞exec : ∀ {i} → State → M′ i Value force (run (∞exec s)) = run (exec s)
23.2
72
0.557882
11341ab0bffb1cc5431e8933d5ddfc3cb330550e
15,125
agda
Agda
agda-stdlib/src/Algebra/Structures.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Structures.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Structures.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Some algebraic structures (not packed up with sets, operations, -- etc.) ------------------------------------------------------------------------ -- The contents of this module should be accessed via `Algebra`, unless -- you want to parameterise it via the equality relation. {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel; Setoid; IsEquivalence) module Algebra.Structures {a ℓ} {A : Set a} -- The underlying set (_≈_ : Rel A ℓ) -- The underlying equality relation where -- The file is divided into sections depending on the arities of the -- components of the algebraic structure. open import Algebra.Core open import Algebra.Definitions _≈_ import Algebra.Consequences.Setoid as Consequences open import Data.Product using (_,_; proj₁; proj₂) open import Level using (_⊔_) ------------------------------------------------------------------------ -- Structures with 1 binary operation ------------------------------------------------------------------------ record IsMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isEquivalence : IsEquivalence _≈_ ∙-cong : Congruent₂ ∙ open IsEquivalence isEquivalence public setoid : Setoid a ℓ setoid = record { isEquivalence = isEquivalence } ∙-congˡ : LeftCongruent ∙ ∙-congˡ y≈z = ∙-cong refl y≈z ∙-congʳ : RightCongruent ∙ ∙-congʳ y≈z = ∙-cong y≈z refl record IsSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ assoc : Associative ∙ open IsMagma isMagma public record IsBand (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isSemigroup : IsSemigroup ∙ idem : Idempotent ∙ open IsSemigroup isSemigroup public record IsCommutativeSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isSemigroup : IsSemigroup ∙ comm : Commutative ∙ open IsSemigroup isSemigroup public record IsSemilattice (∧ : Op₂ A) : Set (a ⊔ ℓ) where field isBand : IsBand ∧ comm : Commutative ∧ open IsBand isBand public renaming (∙-cong to ∧-cong; ∙-congˡ to ∧-congˡ; ∙-congʳ to ∧-congʳ) record IsSelectiveMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ sel : Selective ∙ open IsMagma isMagma public ------------------------------------------------------------------------ -- Structures with 1 binary operation & 1 element ------------------------------------------------------------------------ record IsMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isSemigroup : IsSemigroup ∙ identity : Identity ε ∙ open IsSemigroup isSemigroup public identityˡ : LeftIdentity ε ∙ identityˡ = proj₁ identity identityʳ : RightIdentity ε ∙ identityʳ = proj₂ identity record IsCommutativeMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isMonoid : IsMonoid ∙ ε comm : Commutative ∙ open IsMonoid isMonoid public isCommutativeSemigroup : IsCommutativeSemigroup ∙ isCommutativeSemigroup = record { isSemigroup = isSemigroup ; comm = comm } record IsIdempotentCommutativeMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isCommutativeMonoid : IsCommutativeMonoid ∙ ε idem : Idempotent ∙ open IsCommutativeMonoid isCommutativeMonoid public -- Idempotent commutative monoids are also known as bounded lattices. -- Note that the BoundedLattice necessarily uses the notation inherited -- from monoids rather than lattices. IsBoundedLattice = IsIdempotentCommutativeMonoid module IsBoundedLattice {∙ : Op₂ A} {ε : A} (isIdemCommMonoid : IsIdempotentCommutativeMonoid ∙ ε) = IsIdempotentCommutativeMonoid isIdemCommMonoid ------------------------------------------------------------------------ -- Structures with 1 binary operation, 1 unary operation & 1 element ------------------------------------------------------------------------ record IsGroup (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where field isMonoid : IsMonoid _∙_ ε inverse : Inverse ε _⁻¹ _∙_ ⁻¹-cong : Congruent₁ _⁻¹ open IsMonoid isMonoid public infixl 6 _-_ _-_ : Op₂ A x - y = x ∙ (y ⁻¹) inverseˡ : LeftInverse ε _⁻¹ _∙_ inverseˡ = proj₁ inverse inverseʳ : RightInverse ε _⁻¹ _∙_ inverseʳ = proj₂ inverse uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹) uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique setoid ∙-cong assoc identity inverseʳ uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹) uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique setoid ∙-cong assoc identity inverseˡ record IsAbelianGroup (∙ : Op₂ A) (ε : A) (⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where field isGroup : IsGroup ∙ ε ⁻¹ comm : Commutative ∙ open IsGroup isGroup public isCommutativeMonoid : IsCommutativeMonoid ∙ ε isCommutativeMonoid = record { isMonoid = isMonoid ; comm = comm } open IsCommutativeMonoid isCommutativeMonoid public using (isCommutativeSemigroup) ------------------------------------------------------------------------ -- Structures with 2 binary operations ------------------------------------------------------------------------ -- Note that `IsLattice` is not defined in terms of `IsSemilattice` -- because the idempotence laws of ∨ and ∧ can be derived from the -- absorption laws, which makes the corresponding "idem" fields -- redundant. The derived idempotence laws are stated and proved in -- `Algebra.Properties.Lattice` along with the fact that every lattice -- consists of two semilattices. record IsLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where field isEquivalence : IsEquivalence _≈_ ∨-comm : Commutative ∨ ∨-assoc : Associative ∨ ∨-cong : Congruent₂ ∨ ∧-comm : Commutative ∧ ∧-assoc : Associative ∧ ∧-cong : Congruent₂ ∧ absorptive : Absorptive ∨ ∧ open IsEquivalence isEquivalence public ∨-absorbs-∧ : ∨ Absorbs ∧ ∨-absorbs-∧ = proj₁ absorptive ∧-absorbs-∨ : ∧ Absorbs ∨ ∧-absorbs-∨ = proj₂ absorptive ∧-congˡ : LeftCongruent ∧ ∧-congˡ y≈z = ∧-cong refl y≈z ∧-congʳ : RightCongruent ∧ ∧-congʳ y≈z = ∧-cong y≈z refl ∨-congˡ : LeftCongruent ∨ ∨-congˡ y≈z = ∨-cong refl y≈z ∨-congʳ : RightCongruent ∨ ∨-congʳ y≈z = ∨-cong y≈z refl record IsDistributiveLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where field isLattice : IsLattice ∨ ∧ ∨-distribʳ-∧ : ∨ DistributesOverʳ ∧ open IsLattice isLattice public ∨-∧-distribʳ = ∨-distribʳ-∧ {-# WARNING_ON_USAGE ∨-∧-distribʳ "Warning: ∨-∧-distribʳ was deprecated in v1.1. Please use ∨-distribʳ-∧ instead." #-} ------------------------------------------------------------------------ -- Structures with 2 binary operations & 1 element ------------------------------------------------------------------------ record IsNearSemiring (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where field +-isMonoid : IsMonoid + 0# *-isSemigroup : IsSemigroup * distribʳ : * DistributesOverʳ + zeroˡ : LeftZero 0# * open IsMonoid +-isMonoid public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; ∙-congˡ to +-congˡ ; ∙-congʳ to +-congʳ ; identity to +-identity ; identityˡ to +-identityˡ ; identityʳ to +-identityʳ ; isMagma to +-isMagma ; isSemigroup to +-isSemigroup ) open IsSemigroup *-isSemigroup public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ; ∙-congˡ to *-congˡ ; ∙-congʳ to *-congʳ ; isMagma to *-isMagma ) record IsSemiringWithoutOne (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where field +-isCommutativeMonoid : IsCommutativeMonoid + 0# *-isSemigroup : IsSemigroup * distrib : * DistributesOver + zero : Zero 0# * open IsCommutativeMonoid +-isCommutativeMonoid public using () renaming ( comm to +-comm ; isMonoid to +-isMonoid ; isCommutativeSemigroup to +-isCommutativeSemigroup ) zeroˡ : LeftZero 0# * zeroˡ = proj₁ zero zeroʳ : RightZero 0# * zeroʳ = proj₂ zero isNearSemiring : IsNearSemiring + * 0# isNearSemiring = record { +-isMonoid = +-isMonoid ; *-isSemigroup = *-isSemigroup ; distribʳ = proj₂ distrib ; zeroˡ = zeroˡ } open IsNearSemiring isNearSemiring public hiding (+-isMonoid; zeroˡ) record IsCommutativeSemiringWithoutOne (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where field isSemiringWithoutOne : IsSemiringWithoutOne + * 0# *-comm : Commutative * open IsSemiringWithoutOne isSemiringWithoutOne public ------------------------------------------------------------------------ -- Structures with 2 binary operations & 2 elements ------------------------------------------------------------------------ record IsSemiringWithoutAnnihilatingZero (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where field -- Note that these structures do have an additive unit, but this -- unit does not necessarily annihilate multiplication. +-isCommutativeMonoid : IsCommutativeMonoid + 0# *-isMonoid : IsMonoid * 1# distrib : * DistributesOver + distribˡ : * DistributesOverˡ + distribˡ = proj₁ distrib distribʳ : * DistributesOverʳ + distribʳ = proj₂ distrib open IsCommutativeMonoid +-isCommutativeMonoid public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; ∙-congˡ to +-congˡ ; ∙-congʳ to +-congʳ ; identity to +-identity ; identityˡ to +-identityˡ ; identityʳ to +-identityʳ ; comm to +-comm ; isMagma to +-isMagma ; isSemigroup to +-isSemigroup ; isMonoid to +-isMonoid ; isCommutativeSemigroup to +-isCommutativeSemigroup ) open IsMonoid *-isMonoid public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ; ∙-congˡ to *-congˡ ; ∙-congʳ to *-congʳ ; identity to *-identity ; identityˡ to *-identityˡ ; identityʳ to *-identityʳ ; isMagma to *-isMagma ; isSemigroup to *-isSemigroup ) record IsSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where field isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero + * 0# 1# zero : Zero 0# * open IsSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero public isSemiringWithoutOne : IsSemiringWithoutOne + * 0# isSemiringWithoutOne = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isSemigroup = *-isSemigroup ; distrib = distrib ; zero = zero } open IsSemiringWithoutOne isSemiringWithoutOne public using ( isNearSemiring ; zeroˡ ; zeroʳ ) record IsCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where field isSemiring : IsSemiring + * 0# 1# *-comm : Commutative * open IsSemiring isSemiring public isCommutativeSemiringWithoutOne : IsCommutativeSemiringWithoutOne + * 0# isCommutativeSemiringWithoutOne = record { isSemiringWithoutOne = isSemiringWithoutOne ; *-comm = *-comm } *-isCommutativeSemigroup : IsCommutativeSemigroup * *-isCommutativeSemigroup = record { isSemigroup = *-isSemigroup ; comm = *-comm } *-isCommutativeMonoid : IsCommutativeMonoid * 1# *-isCommutativeMonoid = record { isMonoid = *-isMonoid ; comm = *-comm } ------------------------------------------------------------------------ -- Structures with 2 binary operations, 1 unary operation & 2 elements ------------------------------------------------------------------------ record IsRing (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where field +-isAbelianGroup : IsAbelianGroup + 0# -_ *-isMonoid : IsMonoid * 1# distrib : * DistributesOver + zero : Zero 0# * open IsAbelianGroup +-isAbelianGroup public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; ∙-congˡ to +-congˡ ; ∙-congʳ to +-congʳ ; identity to +-identity ; identityˡ to +-identityˡ ; identityʳ to +-identityʳ ; inverse to -‿inverse ; inverseˡ to -‿inverseˡ ; inverseʳ to -‿inverseʳ ; ⁻¹-cong to -‿cong ; comm to +-comm ; isMagma to +-isMagma ; isSemigroup to +-isSemigroup ; isMonoid to +-isMonoid ; isCommutativeMonoid to +-isCommutativeMonoid ; isCommutativeSemigroup to +-isCommutativeSemigroup ; isGroup to +-isGroup ) open IsMonoid *-isMonoid public using () renaming ( assoc to *-assoc ; ∙-cong to *-cong ; ∙-congˡ to *-congˡ ; ∙-congʳ to *-congʳ ; identity to *-identity ; identityˡ to *-identityˡ ; identityʳ to *-identityʳ ; isMagma to *-isMagma ; isSemigroup to *-isSemigroup ) zeroˡ : LeftZero 0# * zeroˡ = proj₁ zero zeroʳ : RightZero 0# * zeroʳ = proj₂ zero isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero + * 0# 1# isSemiringWithoutAnnihilatingZero = record { +-isCommutativeMonoid = +-isCommutativeMonoid ; *-isMonoid = *-isMonoid ; distrib = distrib } isSemiring : IsSemiring + * 0# 1# isSemiring = record { isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero ; zero = zero } open IsSemiring isSemiring public using (distribˡ; distribʳ; isNearSemiring; isSemiringWithoutOne) record IsCommutativeRing (+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where field isRing : IsRing + * - 0# 1# *-comm : Commutative * open IsRing isRing public *-isCommutativeMonoid : IsCommutativeMonoid * 1# *-isCommutativeMonoid = record { isMonoid = *-isMonoid ; comm = *-comm } isCommutativeSemiring : IsCommutativeSemiring + * 0# 1# isCommutativeSemiring = record { isSemiring = isSemiring ; *-comm = *-comm } open IsCommutativeSemiring isCommutativeSemiring public using ( isCommutativeSemiringWithoutOne ) record IsBooleanAlgebra (∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where field isDistributiveLattice : IsDistributiveLattice ∨ ∧ ∨-complementʳ : RightInverse ⊤ ¬ ∨ ∧-complementʳ : RightInverse ⊥ ¬ ∧ ¬-cong : Congruent₁ ¬ open IsDistributiveLattice isDistributiveLattice public
28.377111
80
0.561521
ed93db98cc499feb56b26953e0b20c93e6d192ca
2,032
agda
Agda
src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Elimination properties for the inequalities ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Inequalities.EliminationPropertiesI where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities ------------------------------------------------------------------------------ 0<0→⊥ : ¬ (zero < zero) 0<0→⊥ 0<0 = t≢f (trans (sym 0<0) lt-00) S<0→⊥ : ∀ {n} → ¬ (succ₁ n < zero) S<0→⊥ {n} h = t≢f (trans (sym h) (lt-S0 n)) x<0→⊥ : ∀ {n} → N n → ¬ (n < zero) x<0→⊥ nzero 0<0 = 0<0→⊥ 0<0 x<0→⊥ (nsucc _) Sn<0 = S<0→⊥ Sn<0 x<x→⊥ : ∀ {n} → N n → ¬ (n < n) x<x→⊥ nzero 0<0 = 0<0→⊥ 0<0 x<x→⊥ (nsucc {n} Nn) Sn<Sn = ⊥-elim (x<x→⊥ Nn (trans (sym (lt-SS n n)) Sn<Sn)) 0>0→⊥ : ¬ (zero > zero) 0>0→⊥ 0>0 = t≢f (trans (sym 0>0) lt-00) 0>S→⊥ : ∀ {n} → ¬ (zero > succ₁ n) 0>S→⊥ {n} h = t≢f (trans (sym h) (lt-S0 n)) 0>x→⊥ : ∀ {n} → N n → ¬ (zero > n) 0>x→⊥ nzero 0>0 = 0>0→⊥ 0>0 0>x→⊥ (nsucc _) 0>Sn = 0>S→⊥ 0>Sn x>x→⊥ : ∀ {n} → N n → ¬ (n > n) x>x→⊥ Nn = x<x→⊥ Nn S≤0→⊥ : ∀ {n} → N n → ¬ (succ₁ n ≤ zero) S≤0→⊥ nzero S0≤0 = t≢f (trans (sym S0≤0) (trans (lt-SS zero zero) lt-00)) S≤0→⊥ (nsucc {n} _) SSn≤0 = t≢f (trans (sym SSn≤0) (trans (lt-SS (succ₁ n) zero) (lt-S0 n))) 0≥S→⊥ : ∀ {n} → N n → ¬ (zero ≥ succ₁ n) 0≥S→⊥ Nn 0≥Sn = S≤0→⊥ Nn 0≥Sn x<y→y<x→⊥ : ∀ {m n} → N m → N n → m < n → ¬ (n < m) x<y→y<x→⊥ nzero Nn 0<n n<0 = ⊥-elim (0>x→⊥ Nn n<0) x<y→y<x→⊥ (nsucc Nm) nzero Sm<0 0<Sm = ⊥-elim (0>x→⊥ (nsucc Nm) Sm<0) x<y→y<x→⊥ (nsucc {m} Nm) (nsucc {n} Nn) Sm<Sn Sn<Sm = x<y→y<x→⊥ Nm Nn (trans (sym (lt-SS m n)) Sm<Sn) (trans (sym (lt-SS n m)) Sn<Sm) S≯0→⊥ : ∀ {n} → ¬ (succ₁ n ≯ zero) S≯0→⊥ {n} h = ⊥-elim (t≢f (trans (sym (lt-0S n)) h))
33.311475
84
0.418799
7c4e3757ac82559d89f27c474a3e70eff1f1cb30
169
agda
Agda
test/Fail/Issue2774.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Fail/Issue2774.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/Issue2774.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
open import Agda.Builtin.Size data D : Size → Set where postulate f : (i : Size) → D i data P : (i : Size) → D i → Set where c : (i j : Size) → P (i ⊔ˢ j) (f _)
15.363636
37
0.544379
3fa97512ec559f42d4b2f28624a2cbf8c1f157d1
11,132
agda
Agda
ProcessPreservation.agda
danelahman/aeff-agda
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
[ "MIT" ]
4
2020-07-17T00:15:00.000Z
2021-03-22T22:48:48.000Z
ProcessPreservation.agda
danelahman/aeff-agda
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
[ "MIT" ]
null
null
null
ProcessPreservation.agda
danelahman/aeff-agda
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
[ "MIT" ]
null
null
null
open import Data.List renaming (_∷_ to _∷ₗ_ ; [_] to [_]ₗ) open import Data.Maybe open import Data.Product open import Data.Sum open import AEff open import EffectAnnotations open import Preservation open import Renamings open import Substitutions open import Types open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Nullary module ProcessPreservation where -- REDUCTION OF PROCESS TYPES infix 10 _⇝_ data _⇝_ : {o o' : O} → PType o → PType o' → Set where id : {X : VType} {o : O} {i : I} → ---------------------- X ‼ o , i ⇝ X ‼ o , i act : {X : VType} {o o' o'' : O} {i i' i'' : I} → (ops : List Σₛ) → (op : Σₛ) → (o' , i') ≡ ops ↓↓ₑ (o , i) → (o'' , i'') ≡ ((ops ++ [ op ]ₗ) ↓↓ₑ (o , i)) → ---------------------------------------------- (X ‼ o' , i') ⇝ (X ‼ o'' , i'') par : {o o' o'' o''' : O} {PP : PType o} {QQ : PType o'} {PP' : PType o''} {QQ' : PType o'''} → PP ⇝ PP' → QQ ⇝ QQ' → ---------------------- (PP ∥ QQ) ⇝ (PP' ∥ QQ') -- REDUCTION OF PROCESS TYPES IS REFLEXIVE {- LEMMA 4.4 (1) -} ⇝-refl : {o : O} {PP : PType o} → PP ⇝ PP ⇝-refl {o} {X ‼ o , i} = id ⇝-refl {.(_ ∪ₒ _)} {PP ∥ QQ} = par ⇝-refl ⇝-refl -- ACTION OF INTERRUPTS ON GENERAL PROCESS TYPES IS A REDUCTION {- LEMMA 4.4 (2) -} ⇝-↓ₚ : {o : O} {PP : PType o} {op : Σₛ} → -------------- PP ⇝ op ↓ₚ PP ⇝-↓ₚ {.o} {X ‼ o , i} {op} = act [] op refl refl ⇝-↓ₚ {.(_ ∪ₒ _)} {PP ∥ QQ} {op} = par ⇝-↓ₚ ⇝-↓ₚ -- ACTION OF INTERRUPTS PRESERVES PROCESS TYPE REDUCTION {- LEMMA 4.4 (3) -} ⇝-↓ₚ-cong : {o o' : O} {PP : PType o} {QQ : PType o'} {op : Σₛ} → PP ⇝ QQ → -------------------- op ↓ₚ PP ⇝ op ↓ₚ QQ ⇝-↓ₚ-cong id = id ⇝-↓ₚ-cong {_} {_} {_} {_} {op} (act {_} {o} {o'} {o''} {i} {i'} {i''} ops op' p q) = act {o = o} {i = i} (op ∷ₗ ops) op' (cong (λ oi → op ↓ₑ oi) p) (cong (λ oi → op ↓ₑ oi) q) ⇝-↓ₚ-cong (par p q) = par (⇝-↓ₚ-cong p) (⇝-↓ₚ-cong q) -- PROCESS TYPE REDUCTION INCREASES SIGNAL INDEX {- LEMMA 4.4 (4) -} inj-proj₁ : {X Y : Set} {xy xy' : X × Y} → xy ≡ xy' → proj₁ xy ≡ proj₁ xy' inj-proj₁ refl = refl ⇝-⊑ₒ : {o o' : O} {PP : PType o} {QQ : PType o'} → PP ⇝ QQ → ------------------ o ⊑ₒ o' ⇝-⊑ₒ id = ⊑ₒ-refl ⇝-⊑ₒ (act {_} {o} {o'} {o''} {i} ops op p q) with inj-proj₁ p | inj-proj₁ q ... | r | s = subst (λ o → o ⊑ₒ o'') (sym r) (subst (λ o'' → proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ o'') (sym s) (subst (λ v → proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ proj₁ v) (sym (↓↓ₑ-act ops [ op ]ₗ)) (↓↓ₑ-⊑ₒ-act ops op))) ⇝-⊑ₒ (par p q) = ∪ₒ-fun (⇝-⊑ₒ p) (⇝-⊑ₒ q) -- EVALUATION CONTEXTS FOR PROCESSES infix 10 _⊢F⦂_ data _⊢F⦂_ (Γ : Ctx) : {o : O} → PType o → Set where [-] : {o : O} → {PP : PType o} → -------------- Γ ⊢F⦂ PP _∥ₗ_ : {o o' : O} {PP : PType o} {QQ : PType o'} → Γ ⊢F⦂ PP → Γ ⊢P⦂ QQ → ------------------ Γ ⊢F⦂ (PP ∥ QQ) _∥ᵣ_ : {o o' : O} {PP : PType o} {QQ : PType o'} → Γ ⊢P⦂ PP → Γ ⊢F⦂ QQ → ------------------ Γ ⊢F⦂ (PP ∥ QQ) ↑ : {o : O} {PP : PType o} → (op : Σₛ) → op ∈ₒ o → Γ ⊢V⦂ ``(payload op) → Γ ⊢F⦂ PP → ---------------------- Γ ⊢F⦂ PP ↓ : {o : O} {PP : PType o} (op : Σₛ) → Γ ⊢V⦂ ``(payload op) → Γ ⊢F⦂ PP → ---------------------- Γ ⊢F⦂ op ↓ₚ PP -- FINDING THE TYPE OF THE HOLE OF A WELL-TYPED PROCESS EVALUATION CONTEXT hole-ty-f : {Γ : Ctx} {o : O} {PP : PType o} → Γ ⊢F⦂ PP → Σ[ o' ∈ O ] (PType o') hole-ty-f {_} {o} {PP} [-] = o , PP hole-ty-f (_∥ₗ_ {o} {o'} {PP} {QQ} F Q) = proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F) hole-ty-f (_∥ᵣ_ {o} {o'} {PP} {QQ} P F) = proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F) hole-ty-f (↑ op p V F) = proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F) hole-ty-f (↓ op V F) = proj₁ (hole-ty-f F) , proj₂ (hole-ty-f F) -- FILLING A WELL-TYPED PROCESS EVALUATION CONTEXT infix 30 _[_]f _[_]f : {Γ : Ctx} {o : O} {PP : PType o} → (F : Γ ⊢F⦂ PP) → (P : Γ ⊢P⦂ proj₂ (hole-ty-f F)) → Γ ⊢P⦂ PP [-] [ P ]f = P (F ∥ₗ Q) [ P ]f = (F [ P ]f) ∥ Q (Q ∥ᵣ F) [ P ]f = Q ∥ (F [ P ]f) (↑ op p V F) [ P ]f = ↑ op p V (F [ P ]f) (↓ op V F) [ P ]f = ↓ op V (F [ P ]f) -- TYPES OF WELL-TYPED PROCESS EVALUATION CONTEXTS ALSO REDUCE ⇝-f-⇝ : {Γ : Ctx} {o o' : O} {PP : PType o} {QQ : PType o'} → (F : Γ ⊢F⦂ PP) → proj₂ (hole-ty-f F) ⇝ QQ → ------------------------------------------ Σ[ o'' ∈ O ] Σ[ RR ∈ PType o'' ] (PP ⇝ RR) ⇝-f-⇝ {_} {_} {o'} {_} {QQ} [-] p = o' , QQ , p ⇝-f-⇝ (_∥ₗ_ {o} {o'} {PP} {QQ} F Q) p with ⇝-f-⇝ F p ... | o'' , RR , q = (o'' ∪ₒ o') , (RR ∥ QQ) , par q ⇝-refl ⇝-f-⇝ (_∥ᵣ_ {o} {o'} {PP} {QQ} P F) p with ⇝-f-⇝ F p ... | o'' , RR , q = (o ∪ₒ o'') , (PP ∥ RR) , par ⇝-refl q ⇝-f-⇝ (↑ op p V F) q with ⇝-f-⇝ F q ... | o'' , RR , r = o'' , RR , r ⇝-f-⇝ (↓ op V F) p with ⇝-f-⇝ F p ... | o'' , RR , q = proj₁ (op ↓ₚₚ RR) , (op ↓ₚ RR) , ⇝-↓ₚ-cong q ⇝-f-∈ₒ : {Γ : Ctx} {o o' : O} {PP : PType o} {QQ : PType o'} (F : Γ ⊢F⦂ PP) → (p : proj₂ (hole-ty-f F) ⇝ QQ) → -------------------------------- o ⊑ₒ proj₁ (⇝-f-⇝ F p) ⇝-f-∈ₒ [-] p = ⇝-⊑ₒ p ⇝-f-∈ₒ (F ∥ₗ Q) p = ∪ₒ-fun (⇝-f-∈ₒ F p) ⊑ₒ-refl ⇝-f-∈ₒ (P ∥ᵣ F) p = ∪ₒ-fun ⊑ₒ-refl (⇝-f-∈ₒ F p) ⇝-f-∈ₒ (↑ op p V F) q = ⇝-f-∈ₒ F q ⇝-f-∈ₒ (↓ {o} {PP} op V F) p = ⇝-f-∈ₒ-aux (⇝-f-⇝ F p) refl where ⇝-f-∈ₒ-aux : (orp : Σ[ o'' ∈ O ] Σ[ RR ∈ PType o'' ] (PP ⇝ RR)) → orp ≡ ⇝-f-⇝ F p → ---------------------------------------------------- proj₁ (op ↓ₚₚ PP) ⊑ₒ proj₁ (op ↓ₚₚ proj₁ (proj₂ orp)) ⇝-f-∈ₒ-aux (o'' , RR , r) q = ⇝-⊑ₒ (⇝-↓ₚ-cong r) {- LEMMA 4.6 -} ⇝-f : {Γ : Ctx} {o o' : O} {PP : PType o} {QQ : PType o'} → (F : Γ ⊢F⦂ PP) → (p : proj₂ (hole-ty-f F) ⇝ QQ) → --------------------------------- Γ ⊢F⦂ (proj₁ (proj₂ (⇝-f-⇝ F p))) ⇝-f [-] p = [-] ⇝-f (F ∥ₗ Q) p with ⇝-f F p ... | q = q ∥ₗ Q ⇝-f (Q ∥ᵣ F) p with ⇝-f F p ... | q = Q ∥ᵣ q ⇝-f (↑ op p V F) q with ⇝-f F q ... | r = ↑ op (⇝-f-∈ₒ F q op p) V r ⇝-f (↓ op V F) p with ⇝-f F p ... | q = ↓ op V q ⇝-f-tyₒ : {Γ : Ctx} {o o' : O} {PP : PType o} {QQ : PType o'} → (F : Γ ⊢F⦂ PP) → (p : proj₂ (hole-ty-f F) ⇝ QQ) → -------------------------------- o' ≡ proj₁ (hole-ty-f (⇝-f F p)) ⇝-f-tyₒ [-] p = refl ⇝-f-tyₒ (F ∥ₗ Q) p = ⇝-f-tyₒ F p ⇝-f-tyₒ (P ∥ᵣ F) p = ⇝-f-tyₒ F p ⇝-f-tyₒ (↑ op p V F) q = ⇝-f-tyₒ F q ⇝-f-tyₒ (↓ op V F) p = ⇝-f-tyₒ F p ⇝-f-ty : {Γ : Ctx} {o o' : O} {PP : PType o} {QQ : PType o'} → (F : Γ ⊢F⦂ PP) → (p : proj₂ (hole-ty-f F) ⇝ QQ) → -------------------------------------- subst (λ o → PType o) (⇝-f-tyₒ F p) QQ ≡ proj₂ (hole-ty-f (⇝-f F p)) ⇝-f-ty [-] p = refl ⇝-f-ty (F ∥ₗ Q) p = ⇝-f-ty F p ⇝-f-ty (P ∥ᵣ F) p = ⇝-f-ty F p ⇝-f-ty (↑ op p V F) q = ⇝-f-ty F q ⇝-f-ty (↓ op V F) p = ⇝-f-ty F p -- AUXILIARY TWO-LEVEL INDEXED SUBSTITUTION subst-i : {X : Set} {x x' : X} → (Y : X → Set) → {y : Y x} {y' : Y x'} → (Z : (x : X) → Y x → Set) → (p : x ≡ x') → subst Y p y ≡ y' → Z x y → Z x' y' subst-i Y Z refl refl z = z -- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED PROCESSES -- (ADDITIONALLY SERVES AS THE PRESERVATION THEOREM) {- THEOREM 4.7 -} infix 10 _[_]↝_ data _[_]↝_ {Γ : Ctx} : {o o' : O} {PP : PType o} {QQ : PType o'} → Γ ⊢P⦂ PP → PP ⇝ QQ → Γ ⊢P⦂ QQ → Set where -- RUNNING INDIVIDUAL COMPUTATIONS run : {X : VType} {o : O} {i : I} {M N : Γ ⊢M⦂ X ! (o , i)} → M ↝ N → --------------------------- (run M) [ id ]↝ (run N) -- BROADCAST RULES ↑-∥ₗ : {o o' : O} {PP : PType o} {QQ : PType o'} {op : Σₛ} → (p : op ∈ₒ o) → (V : Γ ⊢V⦂ `` (payload op)) → (P : Γ ⊢P⦂ PP) → (Q : Γ ⊢P⦂ QQ) → ------------------------------------------ ((↑ op p V P) ∥ Q) [ par ⇝-refl (⇝-↓ₚ {op = op}) ]↝ ↑ op (∪ₒ-inl op p) V (P ∥ ↓ op V Q) ↑-∥ᵣ : {o o' : O} {PP : PType o} {QQ : PType o'} {op : Σₛ} → (p : op ∈ₒ o') → (V : Γ ⊢V⦂ `` (payload op)) → (P : Γ ⊢P⦂ PP) → (Q : Γ ⊢P⦂ QQ) → ------------------------------------------ (P ∥ (↑ op p V Q)) [ par (⇝-↓ₚ {op = op}) ⇝-refl ]↝ ↑ op (∪ₒ-inr op p) V (↓ op V P ∥ Q) -- INTERRUPT PROPAGATION RULES ↓-run : {X : VType} {o : O} {i : I} {op : Σₛ} → (V : Γ ⊢V⦂ `` (payload op)) → (M : Γ ⊢M⦂ X ! (o , i)) → ----------------------------- ↓ op V (run M) [ id ]↝ run (↓ op V M) ↓-∥ : {o o' : O} {PP : PType o} {QQ : PType o'} {op : Σₛ} (V : Γ ⊢V⦂ `` (payload op)) → (P : Γ ⊢P⦂ PP) → (Q : Γ ⊢P⦂ QQ) → ----------------------------- ↓ op V (P ∥ Q) [ ⇝-refl ]↝ ((↓ op V P) ∥ (↓ op V Q)) ↓-↑ : {o : O} {PP : PType o} {op : Σₛ} {op' : Σₛ} → (p : op' ∈ₒ o) → (V : Γ ⊢V⦂ ``(payload op)) → (W : Γ ⊢V⦂ ``(payload op')) → (P : Γ ⊢P⦂ PP) → ----------------------------------- ↓ op V (↑ op' p W P) [ ⇝-refl ]↝ ↑ op' (↓ₚₚ-⊑ₒ PP op' p) W (↓ op V P) -- SIGNAL HOISTING RULE ↑ : {X : VType} {o : O} {i : I} → {op : Σₛ} → (p : op ∈ₒ o) → (V : Γ ⊢V⦂ `` (payload op)) → (M : Γ ⊢M⦂ X ! (o , i)) → ----------------------------- run (↑ op p V M) [ id ]↝ ↑ op p V (run M) -- EVALUATION CONTEXT RULE context : {o o' : O} {PP : PType o} {QQ : PType o'} (F : Γ ⊢F⦂ PP) → {P : Γ ⊢P⦂ proj₂ (hole-ty-f F)} {Q : Γ ⊢P⦂ QQ} {r : proj₂ (hole-ty-f F) ⇝ QQ} → P [ r ]↝ Q → ----------------------------------------------------------------------------- F [ P ]f [ proj₂ (proj₂ (⇝-f-⇝ F r)) ]↝ (⇝-f F r) [ subst-i PType (λ o QQ → Γ ⊢P⦂ QQ) (⇝-f-tyₒ F r) (⇝-f-ty F r) Q ]f
24.682927
109
0.32995
73cb4dac32d4be06d7184e3dfe31f546170b4b81
861
agda
Agda
Definition/Typed/Consequences/SucCong.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/SucCong.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/SucCong.agda
loic-p/logrel-mltt
2251b8da423be0c6fb916f2675d7bd8537e4cd96
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Consequences.SucCong where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Weakening open import Definition.Typed.Properties open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.Substitution open import Tools.Product -- Congurence of the type of the successor case in natrec. sucCong : ∀ {F G Γ} → Γ ∙ ℕ ⊢ F ≡ G → Γ ⊢ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) ≡ Π ℕ ▹ (G ▹▹ G [ suc (var 0) ]↑) sucCong F≡G with wfEq F≡G sucCong F≡G | ⊢Γ ∙ ⊢ℕ = let ⊢F , _ = syntacticEq F≡G in Π-cong ⊢ℕ (refl ⊢ℕ) (Π-cong ⊢F F≡G (wkEq (step id) (⊢Γ ∙ ⊢ℕ ∙ ⊢F) (subst↑TypeEq F≡G (refl (sucⱼ (var (⊢Γ ∙ ⊢ℕ) here))))))
31.888889
78
0.576074
fdd0a486cdbf6db78ef6eab4a9e0e1f2ab2e1f80
902
agda
Agda
Light/Literals/Definition/Negative.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
1
2019-12-20T21:33:05.000Z
2019-12-20T21:33:05.000Z
Light/Literals/Definition/Negative.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
Light/Literals/Definition/Negative.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Literals.Definition.Negative where open import Light.Library.Data.Natural as ℕ using (ℕ ; zero ; successor) renaming (ℓ to nℓ) open import Light.Level using (++_ ; _⊔_) open import Light.Variable.Sets open import Light.Variable.Levels open import Light.Package using (Package) record FromNegative ⦃ package : Package record { ℕ } ⦄ (𝕒 : Set ℓ) : Set (++ (nℓ ⊔ ℓ)) where field convert : ℕ → 𝕒 open FromNegative ⦃ ... ⦄ using (convert) open import Agda.Builtin.Nat as Nat using (Nat) private change : ∀ ⦃ package : Package record { ℕ } ⦄ → Nat → ℕ change Nat.zero = zero change (Nat.suc n) = successor (change n) from‐literal : ∀ ⦃ package : Package record { ℕ } ⦄ ⦃ natural : FromNegative 𝕒 ⦄ (n : Nat) → 𝕒 from‐literal n = convert (change n) {-# BUILTIN FROMNEG from‐literal #-}
36.08
94
0.677384
8b3ba22adbfe1de265d285a0710f66752e135ab0
5,320
agda
Agda
SOAS/Abstract/Coalgebra.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
SOAS/Abstract/Coalgebra.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
SOAS/Abstract/Coalgebra.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Category of □-coalgebras module SOAS.Abstract.Coalgebra {T : Set} where open import SOAS.Common open import SOAS.Construction.Structure as Structure open import SOAS.Context open import SOAS.ContextMaps.Combinators open import SOAS.ContextMaps.CategoryOfRenamings {T} open import SOAS.Sorting open import SOAS.Families.Core {T} open import SOAS.Variable open import SOAS.Families.BCCC open import Data.Unit using (tt) open import SOAS.Abstract.Hom {T} import SOAS.Abstract.Box {T} as □ private variable α : T Γ Δ Θ : Ctx -- Unsorted □-coalgebras module Unsorted where open □.Unsorted record Coalg (X : Family) : Set where field r : X ⇾ □ X counit : {t : X Γ} → r t id ≡ t comult : {ρ : Γ ↝ Δ}{ϱ : Δ ↝ Θ}{t : X Γ} → r t (ϱ ∘ ρ) ≡ r (r t ρ) ϱ -- Weakening of terms wkr : (Θ : Ctx) → X Γ → X (Θ ∔ Γ) wkr Θ t = r t (inr Θ) wkl : (Γ : Ctx) → X Γ → X (Γ ∔ Θ) wkl Γ t = r t (inl Γ) wk : X Γ → X (α ∙ Γ) wk t = r t old -- Unsorted coalgebra homomorphism record Coalg⇒ {X Y}(Xᵇ : Coalg X)(Yᵇ : Coalg Y) (f : X ⇾ Y) : Set where private module X = Coalg Xᵇ private module Y = Coalg Yᵇ field ⟨r⟩ : {ρ : Γ ↝ Δ}{t : X Γ} → f (X.r t ρ) ≡ Y.r (f t) (ρ) private module CoalgebraStructure = Structure 𝔽amilies Coalg -- Eilenberg–Moore category of a comonad ℂoalgebras : Category 1ℓ 0ℓ 0ℓ ℂoalgebras = CoalgebraStructure.StructCat (record { IsHomomorphism = Coalg⇒ ; id-hom = record { ⟨r⟩ = refl } ; comp-hom = λ{ g f record { ⟨r⟩ = g⟨r⟩ } record { ⟨r⟩ = f⟨r⟩ } → record { ⟨r⟩ = trans (cong g f⟨r⟩) g⟨r⟩ } } }) module ℂoalg = Category ℂoalgebras Coalgebra : Set₁ Coalgebra = ℂoalg.Obj Coalgebra⇒ : Coalgebra → Coalgebra → Set Coalgebra⇒ = ℂoalg._⇒_ module AsCoalgebra (Xᵇ : Coalgebra) where open Object Xᵇ public renaming (𝐶 to X ; ˢ to ᵇ) open Coalg ᵇ public -- Terminal object is a coalgebra ⊤ᵇ : Coalg ⊤ₘ ⊤ᵇ = record { r = λ _ _ → tt ; counit = refl ; comult = refl } -- □ X is the free coalgebra on X □ᵇ : (X : Family) → Coalg (□ X) □ᵇ X = record { r = λ b ρ ϱ → b (ϱ ∘ ρ) ; counit = refl ; comult = refl } -- | Sorted □-coalgebras module Sorted where open □.Sorted record Coalg (𝒳 : Familyₛ) : Set where field r : 𝒳 ⇾̣ □ 𝒳 counit : {t : 𝒳 α Γ} → r t id ≡ t comult : {ρ : Γ ↝ Δ}{ϱ : Δ ↝ Θ}{t : 𝒳 α Γ} → r t (ϱ ∘ ρ) ≡ r (r t ρ) ϱ -- Congruence in both arguments r≈₁ : {ρ : Γ ↝ Δ}{t₁ t₂ : 𝒳 α Γ} → t₁ ≡ t₂ → r t₁ ρ ≡ r t₂ ρ r≈₁ {ρ = ρ} p = cong (λ - → r - ρ) p r≈₂ : {ρ₁ ρ₂ : Γ ↝ Δ}{t : 𝒳 α Γ} → ({τ : T}{x : ℐ τ Γ} → ρ₁ x ≡ ρ₂ x) → r t ρ₁ ≡ r t ρ₂ r≈₂ {t = t} p = cong (r t) (dext′ p) wkr : (Θ : Ctx) → 𝒳 α Γ → 𝒳 α (Θ ∔ Γ) wkr Θ t = r t (inr Θ) wkl : (Γ : Ctx) → 𝒳 α Γ → 𝒳 α (Γ ∔ Θ) wkl Γ t = r t (inl Γ) wk : {τ : T} → 𝒳 α Γ → 𝒳 α (τ ∙ Γ) wk t = r t old -- Coalgebra homomorphism record Coalg⇒ {𝒳 𝒴}(Xᵇ : Coalg 𝒳)(𝒴ᵇ : Coalg 𝒴) (f : 𝒳 ⇾̣ 𝒴) : Set where private module 𝒳 = Coalg Xᵇ private module 𝒴 = Coalg 𝒴ᵇ field ⟨r⟩ : {ρ : Γ ↝ Δ}{t : 𝒳 α Γ} → f (𝒳.r t ρ) ≡ 𝒴.r (f t) (ρ) private module CoalgebraStructure = Structure 𝔽amiliesₛ Coalg -- Eilenberg–Moore category of a comonad ℂoalgebras : Category 1ℓ 0ℓ 0ℓ ℂoalgebras = CoalgebraStructure.StructCat (record { IsHomomorphism = Coalg⇒ ; id-hom = record { ⟨r⟩ = refl } ; comp-hom = λ{ g f record { ⟨r⟩ = g⟨r⟩ } record { ⟨r⟩ = f⟨r⟩ } → record { ⟨r⟩ = trans (cong g f⟨r⟩) g⟨r⟩ } } }) module ℂoalg = Category ℂoalgebras Coalgebra : Set₁ Coalgebra = ℂoalg.Obj Coalgebra⇒ : Coalgebra → Coalgebra → Set Coalgebra⇒ = ℂoalg._⇒_ module AsCoalgebra (𝒳ᵇ : Coalgebra) where open Object 𝒳ᵇ public renaming (𝐶 to 𝒳 ; ˢ to ᵈ) -- 〖 𝒳 , 𝒴 〗 is a coalgebra for any 𝒳 and 𝒴 〖_,_〗ᵇ : (𝒳 𝒴 : Familyₛ) → Coalg (〖 𝒳 , 𝒴 〗) 〖 𝒳 , 𝒴 〗ᵇ = record { r = λ h ρ ϱ → h (ϱ ∘ ρ) ; counit = refl ; comult = refl } -- □ 𝒳 is the free coalgebra on 𝒳 □ᵇ : (𝒳 : Familyₛ) → Coalg (□ 𝒳) □ᵇ 𝒳 = 〖 ℐ , 𝒳 〗ᵇ -- Pointed coalgebra record Coalgₚ (𝒳 : Familyₛ) : Set where field ᵇ : Coalg 𝒳 η : ℐ ⇾̣ 𝒳 open Coalg ᵇ public field r∘η : {α : T}{Γ Δ : Ctx}{v : ℐ α Γ}{ρ : Γ ↝ Δ} → r (η v) ρ ≡ η (ρ v) -- Pointed coalgebra homomorphism record Coalgₚ⇒ {𝒳 𝒴 : Familyₛ}(𝒳ᴮ : Coalgₚ 𝒳)(𝒴ᴮ : Coalgₚ 𝒴) (f : 𝒳 ⇾̣ 𝒴) : Set where private module 𝒳 = Coalgₚ 𝒳ᴮ private module 𝒴 = Coalgₚ 𝒴ᴮ field ᵇ⇒ : Coalg⇒ 𝒳.ᵇ 𝒴.ᵇ f ⟨η⟩ : {α : T}{Γ : Ctx}{v : ℐ α Γ} → f (𝒳.η v) ≡ 𝒴.η v open Coalg⇒ ᵇ⇒ public -- Pointed coalgebra of variables ℐᵇ : Coalg ℐ ℐᵇ = record { r = λ v ρ → ρ v ; counit = refl ; comult = refl } ℐᴮ : Coalgₚ ℐ ℐᴮ = record { ᵇ = ℐᵇ ; η = id ; r∘η = refl } -- □ 𝒳 is free pointed coalgebra on pointed families □ᴮ : (𝒳 : Familyₛ) → ℐ ⇾̣ 𝒳 → Coalgₚ (□ 𝒳) □ᴮ 𝒳 η = record { ᵇ = □ᵇ 𝒳 ; η = λ v ρ → η (ρ v) ; r∘η = refl } -- Identity and point are homomorphisms idᴮ⇒ : {𝒳 : Familyₛ}{𝒳ᴮ : Coalgₚ 𝒳} → Coalgₚ⇒ 𝒳ᴮ 𝒳ᴮ id idᴮ⇒ = record { ᵇ⇒ = record { ⟨r⟩ = refl } ; ⟨η⟩ = refl } ηᴮ⇒ : {𝒳 : Familyₛ}(𝒳ᴮ : Coalgₚ 𝒳) → Coalgₚ⇒ ℐᴮ 𝒳ᴮ (Coalgₚ.η 𝒳ᴮ) ηᴮ⇒ 𝒳ᴮ = record { ᵇ⇒ = record { ⟨r⟩ = sym (Coalgₚ.r∘η 𝒳ᴮ) } ; ⟨η⟩ = refl }
27.42268
81
0.542481
218120a2971a2d4a006d7a209263a4ce30e10c0c
2,402
agda
Agda
src/Relation/Ternary/Separation/Monad/Error.agda
laMudri/linear.agda
461077552d88141ac1bba044aa55b65069c3c6c0
[ "MIT" ]
34
2019-12-20T13:57:50.000Z
2021-02-03T15:22:33.000Z
src/Relation/Ternary/Separation/Monad/Error.agda
laMudri/linear.agda
461077552d88141ac1bba044aa55b65069c3c6c0
[ "MIT" ]
null
null
null
src/Relation/Ternary/Separation/Monad/Error.agda
laMudri/linear.agda
461077552d88141ac1bba044aa55b65069c3c6c0
[ "MIT" ]
2
2020-01-30T14:15:14.000Z
2020-05-23T00:34:36.000Z
open import Relation.Unary open import Relation.Ternary.Separation module Relation.Ternary.Separation.Monad.Error {ℓ} {A : Set ℓ} {{r : RawSep A}} {u} {{_ : IsUnitalSep r u}} where open import Level open import Function open import Data.Unit open import Data.Sum open import Relation.Unary renaming (U to True) open import Relation.Unary.PredicateTransformer using (PT; Pt) open import Relation.Ternary.Separation.Morphisms open import Relation.Ternary.Separation.Monad open import Relation.Binary.PropositionalEquality module _ where record ExceptT (M : Pt A ℓ) (E : Set ℓ) (P : Pred A ℓ) (Φ : A) : Set ℓ where constructor partial field runErr : M ((λ _ → E) ∪ P) Φ open ExceptT public open import Relation.Ternary.Separation.Monad.Identity Except : ∀ E → Pt A ℓ Except E = ExceptT Identity.Id E pattern error e = partial (inj₁ e) pattern ✓ x = partial (inj₂ x) data Err : Set ℓ where err : Err ErrorT : (M : Pt A ℓ) {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }} → Pt A ℓ ErrorT M = ExceptT M Err open import Relation.Ternary.Separation.Monad.Identity Error : Pt A ℓ Error = ErrorT Identity.Id module ExceptTrans (M : Pt A ℓ) {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }} (Exc : Set ℓ) where open Monads instance except-monad : Monad ⊤ ℓ (λ _ _ → ExceptT M Exc) runErr (Monad.return except-monad px) = return (inj₂ px) runErr (app (Monad.bind except-monad f) (partial mpx) σ) = do inj₂ px ×⟨ σ₂ ⟩ f ← mpx &⟨ _ ─✴ _ ∥ ⊎-comm σ ⟩ f where (inj₁ e ×⟨ σ₂ ⟩ f) → return (inj₁ e) case app f px (⊎-comm σ₂) of λ where (partial z) → z mapExc : ∀ {E₁ E₂ P} → (E₁ → E₂) → ∀[ ExceptT M E₁ P ⇒ ExceptT M E₂ P ] mapExc f (partial mc) = partial (mapM mc λ where (inj₁ e) → inj₁ (f e); (inj₂ px) → inj₂ px) module ExceptMonad (Exc : Set ℓ) where open import Relation.Ternary.Separation.Monad.Identity open ExceptTrans Identity.Id {{ Identity.id-monad }} Exc public module ErrorTrans (M : Pt A ℓ) {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }} where open import Relation.Ternary.Separation.Monad.Identity open ExceptTrans M {{ monad }} Err public renaming (except-monad to error-monad) module ErrorMonad where open import Relation.Ternary.Separation.Monad.Identity open ExceptTrans Identity.Id {{ Identity.id-monad }} Err public renaming (except-monad to error-monad)
30.025
94
0.666112
ed6725b26afc8a8483b88de5de7fe52b7a9cec3d
316
agda
Agda
src/Categories/Category/Construction/Fin.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Construction/Fin.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Construction/Fin.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Data.Nat.Base using (ℕ) module Categories.Category.Construction.Fin (n : ℕ) where open import Level open import Data.Fin.Properties open import Categories.Category open import Categories.Category.Construction.Thin 0ℓ (≤-poset n) Fin : Category 0ℓ 0ℓ 0ℓ Fin = Thin
21.066667
64
0.753165
37f0888eb46a37a7455ec4bbb73262d1cf0ae533
1,977
agda
Agda
Cubical/Algebra/CommRing/Instances/MultivariatePoly-Quotient.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/CommRing/Instances/MultivariatePoly-Quotient.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Instances/MultivariatePoly-Quotient.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient where open import Cubical.Foundations.Prelude open import Cubical.Data.Nat open import Cubical.Data.Vec open import Cubical.Data.Vec.OperationsNat open import Cubical.Data.FinData open import Cubical.Relation.Nullary open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.FGIdeal open import Cubical.Algebra.CommRing.QuotientRing open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR) open import Cubical.Algebra.Polynomials.Multivariate.Base open import Cubical.Algebra.CommRing.Instances.MultivariatePoly private variable ℓ : Level ----------------------------------------------------------------------------- -- General Nth polynome / quotient -- Better to declare an alias PolyCommRing-Quotient : (A : CommRing ℓ) → {n m : ℕ} → FinVec (fst (PolyCommRing A n)) m → CommRing ℓ PolyCommRing-Quotient A {n} {m} v = PolyCommRing A n / genIdeal (PolyCommRing A n) v ----------------------------------------------------------------------------- -- Notation in the general case and some real cases 1, 2, 3 module _ (Ar@(A , Astr) : CommRing ℓ) (n : ℕ) where <Xkʲ> : (k j : ℕ) → FinVec (A[x1,···,xn] Ar n) 1 <Xkʲ> k j zero = base (genδℕ-Vec n k j 0) (CommRingStr.1r Astr) A[X1,···,Xn]/<Xkʲ> : (k j : ℕ) → CommRing ℓ A[X1,···,Xn]/<Xkʲ> k j = (A[X1,···,Xn] Ar n) / (genIdeal ((A[X1,···,Xn] Ar n)) (<Xkʲ> k j)) A[x1,···,xn]/<xkʲ> : (k j : ℕ) → Type ℓ A[x1,···,xn]/<xkʲ> k j = fst (A[X1,···,Xn]/<Xkʲ> k j) <X1,···,Xn> : FinVec (A[x1,···,xn] Ar n) n <X1,···,Xn> = λ k → base (δℕ-Vec n (toℕ k)) (CommRingStr.1r Astr) A[X1,···,Xn]/<X1,···,Xn> : CommRing ℓ A[X1,···,Xn]/<X1,···,Xn> = (A[X1,···,Xn] Ar n) / (genIdeal ((A[X1,···,Xn] Ar n)) <X1,···,Xn>) A[x1,···,xn]/<x1,···,xn> : Type ℓ A[x1,···,xn]/<x1,···,xn> = fst A[X1,···,Xn]/<X1,···,Xn>
34.684211
101
0.595852
22b2436fc0bc1880ca0543ca0048696cf538c464
166
agda
Agda
cohesion/david_jaz_261/Basics.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
6
2021-10-06T17:39:22.000Z
2022-02-13T05:51:12.000Z
cohesion/david_jaz_261/Basics.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
cohesion/david_jaz_261/Basics.agda
glangmead/formalization
497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a
[ "CC0-1.0" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} module Basics where open import Base public open import PropT public open import hSet public open import lib.Basics public
16.6
39
0.76506
11cbb5d6b74df8edece18052b3405af547f5ba53
2,178
agda
Agda
Cubical/Homotopy/Loopspace.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Homotopy/Loopspace.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Homotopy/Loopspace.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 --safe #-} module Cubical.Homotopy.Loopspace where open import Cubical.Core.Everything open import Cubical.Data.Nat open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.SetTruncation {- loop space of a pointed type -} Ω : {ℓ : Level} → Pointed ℓ → Pointed ℓ Ω (_ , a) = ((a ≡ a) , refl) {- n-fold loop space of a pointed type -} Ω^_ : ∀ {ℓ} → ℕ → Pointed ℓ → Pointed ℓ (Ω^ 0) p = p (Ω^ (suc n)) p = Ω ((Ω^ n) p) {- loop space map -} Ω→ : ∀ {ℓA ℓB} {A : Pointed ℓA} {B : Pointed ℓB} (f : A →∙ B) → (Ω A →∙ Ω B) Ω→ (f , f∙) = (λ p → (sym f∙ ∙ cong f p) ∙ f∙) , cong (λ q → q ∙ f∙) (sym (rUnit (sym f∙))) ∙ lCancel f∙ generalEH : {ℓ : Level} {A : Type ℓ} {a b c : A} {p q : a ≡ b} {r s : b ≡ c} (α : p ≡ q) (β : r ≡ s) → (cong (λ x → x ∙ r) α) ∙ (cong (λ x → q ∙ x) β) ≡ (cong (λ x → p ∙ x) β) ∙ (cong (λ x → x ∙ s) α) generalEH {p = p} {r = r} α β j i = hcomp (λ k → λ { (i = i0) → p ∙ r ; (i = i1) → α (k ∨ ~ j) ∙ β (k ∨ j) }) (α (~ j ∧ i) ∙ β (j ∧ i)) Eckmann-Hilton : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (α β : typ ((Ω^ (2 + n)) A)) → α ∙ β ≡ β ∙ α Eckmann-Hilton {A = A} n α β i = comp (λ k → rUnit (snd ((Ω^ (1 + n)) A)) (~ k) ≡ rUnit (snd ((Ω^ (1 + n)) A)) (~ k)) -- note : rUnit refl := lUnit refl (λ k → λ { (i = i0) → (cong (λ x → rUnit x (~ k)) α) ∙ cong (λ x → lUnit x (~ k)) β ; (i = i1) → (cong (λ x → lUnit x (~ k)) β) ∙ cong (λ x → rUnit x (~ k)) α}) (generalEH α β i) {- Homotopy group version -} π-comp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) → ∥ typ ((Ω^ (suc n)) A) ∥₂ → ∥ typ ((Ω^ (suc n)) A) ∥₂ → ∥ typ ((Ω^ (suc n)) A) ∥₂ π-comp n = elim2 (λ _ _ → setTruncIsSet) λ p q → ∣ p ∙ q ∣₂ Eckmann-Hilton-π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p q : ∥ typ ((Ω^ (2 + n)) A) ∥₂) → π-comp (1 + n) p q ≡ π-comp (1 + n) q p Eckmann-Hilton-π n = elim2 (λ x y → isOfHLevelPath 2 setTruncIsSet _ _) λ p q → cong ∣_∣₂ (Eckmann-Hilton n p q)
39.6
104
0.479798
ccf2099b3aecd0e4827646874f36d423b3559ee1
1,917
agda
Agda
test/Succeed/RecordUpdateSyntax.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/RecordUpdateSyntax.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/RecordUpdateSyntax.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module RecordUpdateSyntax where open import Common.Prelude open import Common.Equality data Param : Nat → Set where param : ∀ n → Param (suc n) record R : Set where field {i} : Nat p : Param i s : Nat old : R old = record { p = param 0; s = 1 } -- Simple update, it should be able to infer the type and the implicit. new : _ new = record old { p = param 1 } new′ : R new′ = record { i = 2; p = param 1; s = 1 } -- Here's a needlessly complex update. upd-p-s : Nat → Nat → R → R upd-p-s zero s r = record r { p = param zero; s = s } upd-p-s (suc n) s r = record (upd-p-s n 0 r) { p = param n; s = s } eq₁ : new ≡ new′ eq₁ = refl eq₂ : upd-p-s zero 1 (record new { s = 0 }) ≡ old eq₂ = refl -- Check that instance arguments are handled properly postulate T : Nat → Set instance t0 : T 0 t1 : T 1 record Instance : Set where field n : Nat {{t}} : T n r0 : Instance r0 = record { n = 0 } r1 : Instance r1 = record r0 { n = 1 } check : Instance.t r1 ≡ t1 check = refl -- Andreas, 2020-03-27, issue #3684 -- warn only if there are invalid or duplicate fields _ = record old { invalidField = 1 } _ = record old { s = 1; s = 0 } _ = record old { foo = 1; bar = 0; s = 1; s = 0 } -- The record type R does not have the field invalidField but it would -- have the fields i, p, s -- when checking that the expression record old { invalidField = 1 } -- has type R -- Duplicate field s in record -- when checking that the expression record old { s = 1 ; s = 0 } has -- type R -- /Users/abel/agda-erasure/test/Succeed/RecordUpdateSyntax.agda:59,5-50 -- The record type R does not have the fields foo, bar but it would -- have the fields i, p -- when checking that the expression -- record old { foo = 1 ; bar = 0 ; s = 1 ; s = 0 } has type R -- Duplicate field s in record -- when checking that the expression -- record old { foo = 1 ; bar = 0 ; s = 1 ; s = 0 } has type R
23.378049
72
0.622848
ed25c6d6840ad62fd060923a23fd5d264d01e416
22,615
agda
Agda
Cubical/Foundations/HLevels.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Foundations/HLevels.agda
cangiuli/cubical
d103ec455d41cccf9b13a4803e7d3cf462e00067
[ "MIT" ]
null
null
null
{- Basic theory about h-levels/n-types: - Basic properties of isContr, isProp and isSet (definitions are in Prelude) - Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.HLevels where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Structure open import Cubical.Functions.FunExtEquiv open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Path open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence using (ua ; univalence) open import Cubical.Data.Sigma open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-zero; +-comm) HLevel : Type₀ HLevel = ℕ private variable ℓ ℓ' ℓ'' ℓ''' : Level A : Type ℓ B : A → Type ℓ C : (x : A) → B x → Type ℓ D : (x : A) (y : B x) → C x y → Type ℓ E : (x : A) (y : B x) → (z : C x y) → D x y z → Type ℓ w x y z : A n : HLevel isOfHLevel : HLevel → Type ℓ → Type ℓ isOfHLevel 0 A = isContr A isOfHLevel 1 A = isProp A isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y) isOfHLevelFun : (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ') isOfHLevelFun n f = ∀ b → isOfHLevel n (fiber f b) TypeOfHLevel : ∀ ℓ → HLevel → Type (ℓ-suc ℓ) TypeOfHLevel ℓ n = TypeWithStr ℓ (isOfHLevel n) hProp hSet hGroupoid h2Groupoid : ∀ ℓ → Type (ℓ-suc ℓ) hProp ℓ = TypeOfHLevel ℓ 1 hSet ℓ = TypeOfHLevel ℓ 2 hGroupoid ℓ = TypeOfHLevel ℓ 3 h2Groupoid ℓ = TypeOfHLevel ℓ 4 -- lower h-levels imply higher h-levels isOfHLevelSuc : (n : HLevel) → isOfHLevel n A → isOfHLevel (suc n) A isOfHLevelSuc 0 = isContr→isProp isOfHLevelSuc 1 = isProp→isSet isOfHLevelSuc (suc (suc n)) h a b = isOfHLevelSuc (suc n) (h a b) isSet→isGroupoid : isSet A → isGroupoid A isSet→isGroupoid = isOfHLevelSuc 2 isGroupoid→is2Groupoid : isGroupoid A → is2Groupoid A isGroupoid→is2Groupoid = isOfHLevelSuc 3 isOfHLevelPlus : (m : HLevel) → isOfHLevel n A → isOfHLevel (m + n) A isOfHLevelPlus zero hA = hA isOfHLevelPlus (suc m) hA = isOfHLevelSuc _ (isOfHLevelPlus m hA) isOfHLevelPlus' : (m : HLevel) → isOfHLevel m A → isOfHLevel (m + n) A isOfHLevelPlus' {A = A} {n = n} m hA = subst (λ m → isOfHLevel m A) (+-comm n m) (isOfHLevelPlus n hA ) isContr→isOfHLevel : (n : HLevel) → isContr A → isOfHLevel n A isContr→isOfHLevel {A = A} n cA = isOfHLevelPlus' 0 cA isProp→isOfHLevelSuc : (n : HLevel) → isProp A → isOfHLevel (suc n) A isProp→isOfHLevelSuc {A = A} n pA = isOfHLevelPlus' 1 pA -- hlevel of path and dependent path types isProp→isContrPath : isProp A → (x y : A) → isContr (x ≡ y) isProp→isContrPath h x y = h x y , isProp→isSet h x y _ isContr→isContrPath : isContr A → (x y : A) → isContr (x ≡ y) isContr→isContrPath cA = isProp→isContrPath (isContr→isProp cA) isOfHLevelPath' : (n : HLevel) → isOfHLevel (suc n) A → (x y : A) → isOfHLevel n (x ≡ y) isOfHLevelPath' 0 = isProp→isContrPath isOfHLevelPath' (suc n) h x y = h x y isOfHLevelPath'⁻ : (n : HLevel) → ((x y : A) → isOfHLevel n (x ≡ y)) → isOfHLevel (suc n) A isOfHLevelPath'⁻ zero h x y = h x y .fst isOfHLevelPath'⁻ (suc n) h = h isOfHLevelPath : (n : HLevel) → isOfHLevel n A → (x y : A) → isOfHLevel n (x ≡ y) isOfHLevelPath 0 h x y = isContr→isContrPath h x y isOfHLevelPath (suc n) h x y = isOfHLevelSuc n (isOfHLevelPath' n h x y) isOfHLevelPathP' : {A : I → Type ℓ} (n : HLevel) → isOfHLevel (suc n) (A i1) → (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y) isOfHLevelPathP' {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i)) (isOfHLevelPath' n h _ _) isOfHLevelPathP : {A : I → Type ℓ} (n : HLevel) → isOfHLevel n (A i1) → (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y) isOfHLevelPathP {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i)) (isOfHLevelPath n h _ _) -- h-level of isOfHLevel isPropIsOfHLevel : (n : HLevel) → isProp (isOfHLevel n A) isPropIsOfHLevel 0 = isPropIsContr isPropIsOfHLevel 1 = isPropIsProp isPropIsOfHLevel (suc (suc n)) f g i a b = isPropIsOfHLevel (suc n) (f a b) (g a b) i isPropIsSet : isProp (isSet A) isPropIsSet = isPropIsOfHLevel 2 isPropIsGroupoid : isProp (isGroupoid A) isPropIsGroupoid = isPropIsOfHLevel 3 isPropIs2Groupoid : isProp (is2Groupoid A) isPropIs2Groupoid = isPropIsOfHLevel 4 TypeOfHLevel≡ : (n : HLevel) {X Y : TypeOfHLevel ℓ n} → ⟨ X ⟩ ≡ ⟨ Y ⟩ → X ≡ Y TypeOfHLevel≡ n = Σ≡Prop (λ _ → isPropIsOfHLevel n) -- Fillers for cubes from h-level isSet→isSet' : isSet A → isSet' A isSet→isSet' {A = A} Aset a₀₋ a₁₋ a₋₀ a₋₁ = transport⁻ (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋) (Aset _ _ _ _) isSet'→isSet : isSet' A → isSet A isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl isSet→SquareP : {A : I → I → Type ℓ} (isSet : (i j : I) → isSet (A i j)) {a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁) {a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁) (a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁) → SquareP A a₀₋ a₁₋ a₋₀ a₋₁ isSet→SquareP isset a₀₋ a₁₋ a₋₀ a₋₁ = transport (sym (PathP≡Path _ _ _)) (isOfHLevelPathP' 1 (isset _ _) _ _ _ _ ) isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A isGroupoid→isGroupoid' {A = A} Agpd a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ = transport⁻ (PathP≡Path (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋) (isGroupoid→isPropSquare _ _ _ _ _ _) where isGroupoid→isPropSquare : {a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁) {a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁) (a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁) → isProp (Square a₀₋ a₁₋ a₋₀ a₋₁) isGroupoid→isPropSquare a₀₋ a₁₋ a₋₀ a₋₁ = transport⁻ (cong isProp (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋)) (Agpd _ _ _ _) isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A isGroupoid'→isGroupoid Agpd' x y p q r s = Agpd' r s refl refl refl refl -- hlevels are preserved by retracts (and consequently equivalences) isContrRetract : ∀ {B : Type ℓ} → (f : A → B) (g : B → A) → (h : retract f g) → (v : isContr B) → isContr A fst (isContrRetract f g h (b , p)) = g b snd (isContrRetract f g h (b , p)) x = (cong g (p (f x))) ∙ (h x) isPropRetract : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isProp B → isProp A isPropRetract f g h p x y i = hcomp (λ j → λ { (i = i0) → h x j ; (i = i1) → h y j}) (g (p (f x) (f y) i)) isSetRetract : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isSet B → isSet A isSetRetract f g h set x y p q i j = hcomp (λ k → λ { (i = i0) → h (p j) k ; (i = i1) → h (q j) k ; (j = i0) → h x k ; (j = i1) → h y k}) (g (set (f x) (f y) (cong f p) (cong f q) i j)) isGroupoidRetract : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isGroupoid B → isGroupoid A isGroupoidRetract f g h grp x y p q P Q i j k = hcomp ((λ l → λ { (i = i0) → h (P j k) l ; (i = i1) → h (Q j k) l ; (j = i0) → h (p k) l ; (j = i1) → h (q k) l ; (k = i0) → h x l ; (k = i1) → h y l})) (g (grp (f x) (f y) (cong f p) (cong f q) (cong (cong f) P) (cong (cong f) Q) i j k)) is2GroupoidRetract : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → is2Groupoid B → is2Groupoid A is2GroupoidRetract f g h grp x y p q P Q R S i j k l = hcomp (λ r → λ { (i = i0) → h (R j k l) r ; (i = i1) → h (S j k l) r ; (j = i0) → h (P k l) r ; (j = i1) → h (Q k l) r ; (k = i0) → h (p l) r ; (k = i1) → h (q l) r ; (l = i0) → h x r ; (l = i1) → h y r}) (g (grp (f x) (f y) (cong f p) (cong f q) (cong (cong f) P) (cong (cong f) Q) (cong (cong (cong f)) R) (cong (cong (cong f)) S) i j k l)) isOfHLevelRetract : (n : HLevel) {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isOfHLevel n B → isOfHLevel n A isOfHLevelRetract 0 = isContrRetract isOfHLevelRetract 1 = isPropRetract isOfHLevelRetract 2 = isSetRetract isOfHLevelRetract 3 = isGroupoidRetract isOfHLevelRetract 4 = is2GroupoidRetract isOfHLevelRetract (suc (suc (suc (suc (suc n))))) f g h ofLevel x y p q P Q R S = isOfHLevelRetract (suc n) (cong (cong (cong (cong f)))) (λ s i j k l → hcomp (λ r → λ { (i = i0) → h (R j k l) r ; (i = i1) → h (S j k l) r ; (j = i0) → h (P k l) r ; (j = i1) → h (Q k l) r ; (k = i0) → h (p l) r ; (k = i1) → h (q l) r ; (l = i0) → h x r ; (l = i1) → h y r}) (g (s i j k l))) (λ s i j k l m → hcomp (λ n → λ { (i = i1) → s j k l m ; (j = i0) → h (R k l m) (i ∨ n) ; (j = i1) → h (S k l m) (i ∨ n) ; (k = i0) → h (P l m) (i ∨ n) ; (k = i1) → h (Q l m) (i ∨ n) ; (l = i0) → h (p m) (i ∨ n) ; (l = i1) → h (q m) (i ∨ n) ; (m = i0) → h x (i ∨ n) ; (m = i1) → h y (i ∨ n) }) (h (s j k l m) i)) (ofLevel (f x) (f y) (cong f p) (cong f q) (cong (cong f) P) (cong (cong f) Q) (cong (cong (cong f)) R) (cong (cong (cong f)) S)) isOfHLevelRetractFromIso : {A : Type ℓ} {B : Type ℓ'} (n : HLevel) → Iso A B → isOfHLevel n B → isOfHLevel n A isOfHLevelRetractFromIso n e hlev = isOfHLevelRetract n (Iso.fun e) (Iso.inv e) (Iso.leftInv e) hlev isOfHLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : HLevel) → A ≃ B → isOfHLevel n A → isOfHLevel n B isOfHLevelRespectEquiv n eq = isOfHLevelRetract n (invEq eq) (eq .fst) (retEq eq) -- h-level of Σ-types isContrΣ : isContr A → ((x : A) → isContr (B x)) → isContr (Σ A B) isContrΣ {A = A} {B = B} (a , p) q = let h : (x : A) (y : B x) → (q x) .fst ≡ y h x y = (q x) .snd y in (( a , q a .fst) , ( λ x i → p (x .fst) i , h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i)) isContrΣ′ : (ca : isContr A) → isContr (B (fst ca)) → isContr (Σ A B) isContrΣ′ ca cb = isContrΣ ca (λ x → subst _ (snd ca x) cb) section-Σ≡Prop : (pB : (x : A) → isProp (B x)) {u v : Σ A B} → section (Σ≡Prop pB {u} {v}) (cong fst) section-Σ≡Prop {A = A} pB {u} {v} p j i = (p i .fst) , isProp→PathP (λ i → isOfHLevelPath 1 (pB (fst (p i))) (Σ≡Prop pB {u} {v} (cong fst p) i .snd) (p i .snd) ) refl refl i j isEquiv-Σ≡Prop : (pB : (x : A) → isProp (B x)) {u v : Σ A B} → isEquiv (Σ≡Prop pB {u} {v}) isEquiv-Σ≡Prop {A = A} pB {u} {v} = isoToIsEquiv (iso (Σ≡Prop pB) (cong fst) (section-Σ≡Prop pB) (λ _ → refl)) isPropΣ : isProp A → ((x : A) → isProp (B x)) → isProp (Σ A B) isPropΣ pA pB t u = Σ≡Prop pB (pA (t .fst) (u .fst)) isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n (Σ A B) isOfHLevelΣ 0 = isContrΣ isOfHLevelΣ 1 = isPropΣ isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y = isOfHLevelRetractFromIso (suc n) (invIso (IsoΣPathTransportPathΣ _ _)) (isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ x → h2 _ _ _) isSetΣ : isSet A → ((x : A) → isSet (B x)) → isSet (Σ A B) isSetΣ = isOfHLevelΣ 2 isGroupoidΣ : isGroupoid A → ((x : A) → isGroupoid (B x)) → isGroupoid (Σ A B) isGroupoidΣ = isOfHLevelΣ 3 is2GroupoidΣ : is2Groupoid A → ((x : A) → is2Groupoid (B x)) → is2Groupoid (Σ A B) is2GroupoidΣ = isOfHLevelΣ 4 -- h-level of × isProp× : {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → isProp (A × B) isProp× pA pB = isPropΣ pA (λ _ → pB) isProp×2 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} → isProp A → isProp B → isProp C → isProp (A × B × C) isProp×2 pA pB pC = isProp× pA (isProp× pB pC) isProp×3 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} → isProp A → isProp B → isProp C → isProp D → isProp (A × B × C × D) isProp×3 pA pB pC pD = isProp×2 pA pB (isProp× pC pD) isOfHLevel× : ∀ {A : Type ℓ} {B : Type ℓ'} n → isOfHLevel n A → isOfHLevel n B → isOfHLevel n (A × B) isOfHLevel× n hA hB = isOfHLevelΣ n hA (λ _ → hB) isSet× : ∀ {A : Type ℓ} {B : Type ℓ'} → isSet A → isSet B → isSet (A × B) isSet× = isOfHLevel× 2 isGroupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → isGroupoid A → isGroupoid B → isGroupoid (A × B) isGroupoid× = isOfHLevel× 3 is2Groupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → is2Groupoid A → is2Groupoid B → is2Groupoid (A × B) is2Groupoid× = isOfHLevel× 4 -- h-level of Π-types isOfHLevelΠ : ∀ n → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n ((x : A) → B x) isOfHLevelΠ 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i isOfHLevelΠ 1 h f g i x = (h x) (f x) (g x) i isOfHLevelΠ 2 h f g F G i j z = h z (f z) (g z) (funExt⁻ F z) (funExt⁻ G z) i j isOfHLevelΠ 3 h f g p q P Q i j k z = h z (f z) (g z) (funExt⁻ p z) (funExt⁻ q z) (cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q) i j k isOfHLevelΠ 4 h f g p q P Q R S i j k l z = h z (f z) (g z) (funExt⁻ p z) (funExt⁻ q z) (cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q) (cong (cong (λ f → funExt⁻ f z)) R) (cong (cong (λ f → funExt⁻ f z)) S) i j k l isOfHLevelΠ (suc (suc (suc (suc (suc n))))) h f g p q P Q R S = isOfHLevelRetract (suc n) (cong (cong (cong funExt⁻))) (cong (cong (cong funExt))) (λ _ → refl) (isOfHLevelΠ (suc (suc (suc (suc n)))) (λ x → h x (f x) (g x)) (funExt⁻ p) (funExt⁻ q) (cong funExt⁻ P) (cong funExt⁻ Q) (cong (cong funExt⁻) R) (cong (cong funExt⁻) S)) isPropΠ : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x) isPropΠ = isOfHLevelΠ 1 isPropΠ2 : (h : (x : A) (y : B x) → isProp (C x y)) → isProp ((x : A) (y : B x) → C x y) isPropΠ2 h = isPropΠ λ x → isPropΠ λ y → h x y isPropΠ3 : (h : (x : A) (y : B x) (z : C x y) → isProp (D x y z)) → isProp ((x : A) (y : B x) (z : C x y) → D x y z) isPropΠ3 h = isPropΠ λ x → isPropΠ λ y → isPropΠ λ z → h x y z isPropΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isProp (E x y z w)) → isProp ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w) isPropΠ4 h = isPropΠ λ _ → isPropΠ3 λ _ → h _ _ isPropImplicitΠ : (h : (x : A) → isProp (B x)) → isProp ({x : A} → B x) isPropImplicitΠ h f g i {x} = h x (f {x}) (g {x}) i isProp→ : {A : Type ℓ} {B : Type ℓ'} → isProp B → isProp (A → B) isProp→ pB = isPropΠ λ _ → pB isSetΠ : ((x : A) → isSet (B x)) → isSet ((x : A) → B x) isSetΠ = isOfHLevelΠ 2 isSetΠ2 : (h : (x : A) (y : B x) → isSet (C x y)) → isSet ((x : A) (y : B x) → C x y) isSetΠ2 h = isSetΠ λ x → isSetΠ λ y → h x y isGroupoidΠ : ((x : A) → isGroupoid (B x)) → isGroupoid ((x : A) → B x) isGroupoidΠ = isOfHLevelΠ 3 isGroupoidΠ2 : (h : (x : A) (y : B x) → isGroupoid (C x y)) → isGroupoid ((x : A) (y : B x) → C x y) isGroupoidΠ2 h = isGroupoidΠ λ _ → isGroupoidΠ λ _ → h _ _ isGroupoidΠ3 : (h : (x : A) (y : B x) (z : C x y) → isGroupoid (D x y z)) → isGroupoid ((x : A) (y : B x) (z : C x y) → D x y z) isGroupoidΠ3 h = isGroupoidΠ λ _ → isGroupoidΠ2 λ _ → h _ _ isGroupoidΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isGroupoid (E x y z w)) → isGroupoid ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w) isGroupoidΠ4 h = isGroupoidΠ λ _ → isGroupoidΠ3 λ _ → h _ _ is2GroupoidΠ : ((x : A) → is2Groupoid (B x)) → is2Groupoid ((x : A) → B x) is2GroupoidΠ = isOfHLevelΠ 4 isOfHLevelΠ⁻ : ∀ {A : Type ℓ} {B : Type ℓ'} n → isOfHLevel n (A → B) → (A → isOfHLevel n B) isOfHLevelΠ⁻ 0 h x = fst h x , λ y → funExt⁻ (snd h (const y)) x isOfHLevelΠ⁻ 1 h x y z = funExt⁻ (h (const y) (const z)) x isOfHLevelΠ⁻ (suc (suc n)) h x y z = isOfHLevelΠ⁻ (suc n) (subst (isOfHLevel (suc n)) (sym funExtPath) (h (const y) (const z))) x -- h-level of A ≃ B and A ≡ B isOfHLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B) isOfHLevel≃ zero {A = A} {B = B} hA hB = isContr→Equiv hA hB , contr where contr : (y : A ≃ B) → isContr→Equiv hA hB ≡ y contr y = Σ≡Prop isPropIsEquiv (funExt (λ a → snd hB (fst y a))) isOfHLevel≃ (suc n) {A = A} {B = B} hA hB = isOfHLevelΣ (suc n) (isOfHLevelΠ _ λ _ → hB) λ a → isOfHLevelPlus' 1 (isPropIsEquiv a) isOfHLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≡ B) isOfHLevel≡ n hA hB = isOfHLevelRetract n (fst univalence) ua (secEq univalence) (isOfHLevel≃ n hA hB) -- h-level of TypeOfHLevel isPropHContr : isProp (TypeOfHLevel ℓ 0) isPropHContr x y = Σ≡Prop (λ _ → isPropIsContr) (isOfHLevel≡ 0 (x .snd) (y .snd) .fst) isOfHLevelTypeOfHLevel : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n) isOfHLevelTypeOfHLevel zero = isPropHContr isOfHLevelTypeOfHLevel (suc n) (X , a) (Y , b) = isOfHLevelRetract (suc n) (cong fst) (Σ≡Prop λ _ → isPropIsOfHLevel (suc n)) (section-Σ≡Prop λ _ → isPropIsOfHLevel (suc n)) (isOfHLevel≡ (suc n) a b) isSetHProp : isSet (hProp ℓ) isSetHProp = isOfHLevelTypeOfHLevel 1 -- h-level of lifted type isOfHLevelLift : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A) isOfHLevelLift n = isOfHLevelRetract n lower lift λ _ → refl ---------------------------- -- More consequences of isProp and isContr inhProp→isContr : A → isProp A → isContr A inhProp→isContr x h = x , h x extend : isContr A → (∀ φ → (u : Partial φ A) → Sub A φ u) extend (x , p) φ u = inS (hcomp (λ { j (φ = i1) → p (u 1=1) j }) x) isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ} → (extend : ∀ φ → Partial φ A → A) → (∀ u → u ≡ (extend i1 λ { _ → u})) → isContr A isContrPartial→isContr {A = A} extend law = ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y) where ex = extend i0 empty module Aux (y : A) (i : I) where φ = ~ i ∨ i u : Partial φ A u = λ { (i = i0) → ex ; (i = i1) → y } v = extend φ u -- Dependent h-level over a type isOfHLevelDep : HLevel → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') isOfHLevelDep 0 {A = A} B = {a : A} → Σ[ b ∈ B a ] ({a' : A} (b' : B a') (p : a ≡ a') → PathP (λ i → B (p i)) b b') isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1 isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1) isOfHLevel→isOfHLevelDep : (n : HLevel) → {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B isOfHLevel→isOfHLevelDep 0 h {a} = (h a .fst , λ b' p → isProp→PathP (λ i → isContr→isProp (h (p i))) (h a .fst) b') isOfHLevel→isOfHLevelDep 1 h = λ b0 b1 p → isProp→PathP (λ i → h (p i)) b0 b1 isOfHLevel→isOfHLevelDep (suc (suc n)) {A = A} {B} h {a0} {a1} b0 b1 = isOfHLevel→isOfHLevelDep (suc n) (λ p → helper a1 p b1) where helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1) helper a1 p b1 = J (λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)) (λ _ → h _ _ _) p b1 isContrDep→isPropDep : isOfHLevelDep 0 B → isOfHLevelDep 1 B isContrDep→isPropDep {B = B} Bctr {a0 = a0} b0 b1 p i = comp (λ k → B (p (i ∧ k))) (λ k → λ where (i = i0) → Bctr .snd b0 refl k (i = i1) → Bctr .snd b1 p k) (c0 .fst) where c0 = Bctr {a0} isPropDep→isSetDep : isOfHLevelDep 1 B → isOfHLevelDep 2 B isPropDep→isSetDep {B = B} Bprp b0 b1 b2 b3 p i j = comp (λ k → B (p (i ∧ k) (j ∧ k))) (λ k → λ where (j = i0) → Bprp b0 b0 refl k (i = i0) → Bprp b0 (b2 j) (λ k → p i0 (j ∧ k)) k (i = i1) → Bprp b0 (b3 j) (λ k → p k (j ∧ k)) k (j = i1) → Bprp b0 b1 (λ k → p (i ∧ k) (j ∧ k)) k) b0 isOfHLevelDepSuc : (n : HLevel) → isOfHLevelDep n B → isOfHLevelDep (suc n) B isOfHLevelDepSuc 0 = isContrDep→isPropDep isOfHLevelDepSuc 1 = isPropDep→isSetDep isOfHLevelDepSuc (suc (suc n)) Blvl b0 b1 = isOfHLevelDepSuc (suc n) (Blvl b0 b1) isPropDep→isSetDep' : isOfHLevelDep 1 B → {p : w ≡ x} {q : y ≡ z} {r : w ≡ y} {s : x ≡ z} → {tw : B w} {tx : B x} {ty : B y} {tz : B z} → (sq : Square p q r s) → (tp : PathP (λ i → B (p i)) tw tx) → (tq : PathP (λ i → B (q i)) ty tz) → (tr : PathP (λ i → B (r i)) tw ty) → (ts : PathP (λ i → B (s i)) tx tz) → SquareP (λ i j → B (sq i j)) tp tq tr ts isPropDep→isSetDep' {B = B} Bprp {p} {q} {r} {s} {tw} sq tp tq tr ts i j = comp (λ k → B (sq (i ∧ k) (j ∧ k))) (λ k → λ where (i = i0) → Bprp tw (tp j) (λ k → p (k ∧ j)) k (i = i1) → Bprp tw (tq j) (λ k → sq (i ∧ k) (j ∧ k)) k (j = i0) → Bprp tw (tr i) (λ k → r (k ∧ i)) k (j = i1) → Bprp tw (ts i) (λ k → sq (k ∧ i) (j ∧ k)) k) tw isOfHLevelΣ' : ∀ n → isOfHLevel n A → isOfHLevelDep n B → isOfHLevel n (Σ A B) isOfHLevelΣ' 0 Actr Bctr .fst = (Actr .fst , Bctr .fst) isOfHLevelΣ' 0 Actr Bctr .snd (x , y) i = Actr .snd x i , Bctr .snd y (Actr .snd x) i isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .fst = Alvl w x i isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .snd = Blvl y z (Alvl w x) i isOfHLevelΣ' {A = A} {B = B} (suc (suc n)) Alvl Blvl (w , y) (x , z) = isOfHLevelRetract (suc n) (λ p → (λ i → p i .fst) , λ i → p i .snd) ΣPathP (λ x → refl) (isOfHLevelΣ' (suc n) (Alvl w x) (Blvl y z))
39.605954
150
0.523193
375171c91e16645cca6160393f9e7476af0202c8
105
agda
Agda
test/interaction/Issue952.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue952.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue952.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate f : {A B : Set₁} (C : Set) → C → C module _ (A B C : Set) where test : Set test = {!!}
13.125
36
0.485714
73e46aef827433ba0ae3a8552403b7f29d13ac88
941
agda
Agda
src/Implicits/Syntax/Term.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Implicits/Syntax/Term.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Implicits/Syntax/Term.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
open import Prelude module Implicits.Syntax.Term where open import Implicits.Syntax.Type infixl 9 _[_] _·_ data Term (ν n : ℕ) : Set where var : (x : Fin n) → Term ν n Λ : Term (suc ν) n → Term ν n λ' : Type ν → Term ν (suc n) → Term ν n _[_] : Term ν n → Type ν → Term ν n _·_ : Term ν n → Term ν n → Term ν n -- rule abstraction and application ρ : Type ν → Term ν (suc n) → Term ν n _with'_ : Term ν n → Term ν n → Term ν n -- implicit rule application _⟨⟩ : Term ν n → Term ν n ClosedTerm : Set ClosedTerm = Term 0 0 ----------------------------------------------------------------------------- -- syntactic sugar let'_∶_in'_ : ∀ {ν n} → Term ν n → Type ν → Term ν (suc n) → Term ν n let' e₁ ∶ r in' e₂ = (λ' r e₂) · e₁ implicit_∶_in'_ : ∀ {ν n} → Term ν n → Type ν → Term ν (suc n) → Term ν n implicit e₁ ∶ r in' e₂ = (ρ r e₂) with' e₁ ¿_ : ∀ {ν n} → Type ν → Term ν n ¿ r = (ρ r (var zero)) ⟨⟩
26.138889
77
0.521785
737dd6b1f46fa858fe3a51c8507fd0dd61267001
928
agda
Agda
src/data/lib/prim/Agda/Builtin/String.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
src/data/lib/prim/Agda/Builtin/String.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/String.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} module Agda.Builtin.String where open import Agda.Builtin.Bool open import Agda.Builtin.List open import Agda.Builtin.Char postulate String : Set {-# BUILTIN STRING String #-} primitive primStringToList : String → List Char primStringFromList : List Char → String primStringAppend : String → String → String primStringEquality : String → String → Bool primShowChar : Char → String primShowString : String → String {-# COMPILE JS primStringToList = function(x) { return x.split(""); } #-} {-# COMPILE JS primStringFromList = function(x) { return x.join(""); } #-} {-# COMPILE JS primStringAppend = function(x) { return function(y) { return x+y; }; } #-} {-# COMPILE JS primStringEquality = function(x) { return function(y) { return x===y; }; } #-} {-# COMPILE JS primShowChar = function(x) { return x; } #-} {-# COMPILE JS primShowString = function(x) { return x; } #-}
35.692308
93
0.675647
73146ed99b1440448c5350d16df2594cae9f5fec
1,162
agda
Agda
src/LibraBFT/Impl/Types/EpochState.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Types/EpochState.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Types/EpochState.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 LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Logging.Logging import LibraBFT.Impl.Types.LedgerInfoWithSignatures as LIWS open import LibraBFT.ImplShared.Consensus.Types open import Optics.All open import Util.Prelude module LibraBFT.Impl.Types.EpochState where verify : EpochState → LedgerInfoWithSignatures → Either ErrLog Unit verify self ledgerInfo = do lcheck (self ^∙ esEpoch == ledgerInfo ^∙ liwsLedgerInfo ∙ liEpoch) ( "EpochState" ∷ "LedgerInfo has unexpected epoch" ∷ []) --, show (self^.esEpoch), show (ledgerInfo^.liwsLedgerInfo.liEpoch) ] LIWS.verifySignatures ledgerInfo (self ^∙ esVerifier) epochChangeVerificationRequired : EpochState → Epoch → Bool epochChangeVerificationRequired self epoch = ⌊ self ^∙ esEpoch <? epoch ⌋ isLedgerInfoStale : EpochState → LedgerInfo → Bool isLedgerInfoStale self ledgerInfo = ⌊ ledgerInfo ^∙ liEpoch <? self ^∙ esEpoch ⌋
41.5
111
0.7642
3de4e08a6752ca02c257d732848f70ebf197f0fe
195
agda
Agda
test/Succeed/ShadowingLetWithLet.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/ShadowingLetWithLet.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/ShadowingLetWithLet.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate A : Set record R : Set where constructor r field f : A test : R → R test x = let r a = x foo : R → A foo x = let r a = x in a in r (foo (r a))
15
37
0.461538
1b5b584eb1ec3d928b8cf117897a949b0d0ec21b
1,079
agda
Agda
test/bugs/Issue325b.agda
zgrannan/agda
5953ce337eb6b77b29ace7180478f49c541aea1c
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/bugs/Issue325b.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/bugs/Issue325b.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS -v tc.meta:20 #-} -- Andreas, 2011-04-15 -- source: Conor's post "foldl Miller magic" on the Agda list (2008) module Issue325b where data Nat : Set where zero : Nat suc : Nat -> Nat data Vec (X : Set) : Nat -> Set where [] : Vec X zero cons : (n : Nat) -> X -> Vec X n -> Vec X (suc n) foldl : (S : Set)(T : Nat -> Set) -> ((n : Nat) -> T n -> S -> T (suc n)) -> T zero -> (n : Nat) -> Vec S n -> T n foldl S T0 f t ._ [] = t foldl S Tsn f t ._ (cons m s ss) = foldl S _ -- (\ n -> Tsn (suc n)) -- (\ n -> f _) (f _ t s) _ ss _ (f zero t s) _ ss -- (\ n -> f (suc n)) (f zero t s) _ ss {- PROTOCOL: term _43 S Tsn f t m s ss zero := suc zero term _43 S Tsn f t m s ss (suc n) := suc (_43 S Tsn f t m s ss n) term _43 S Tsn f t m s ss m := suc m Pruning could give us: _43 m zero := suc zero _43 m (suc n) := suc (_43 m n) _43 m m := suc m We could then try a) _43 x y := suc x failing b) _43 x y := suc y succeeding but this only complete in the absence of recursion. -}
23.456522
68
0.517146
fd44b8e6a0a27c84df76b5de2c56c83e3eda5a7b
441
agda
Agda
test/succeed/Issue1119.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Issue1119.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/succeed/Issue1119.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
-- 2014-05-02 -- This looped in the epic backend after Andreas' big projection refactoring (Oct 2013) data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} -- Essential f : ℕ → ℕ f zero = zero f (suc m) = m postulate IO : Set → Set {-# COMPILED_TYPE IO IO #-} postulate return : ∀ {A} → A → IO A {-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-} main : IO ℕ main = return zero
15.75
87
0.587302
43514b8213e1e3cae5047c14ea2f5dfb671814d4
1,516
agda
Agda
Cubical/Data/Graph/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/Graph/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Data/Graph/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Graph.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function private variable ℓv ℓv' ℓv'' ℓe ℓe' ℓe'' ℓd ℓd' : Level -- The type of directed multigraphs (with loops) record Graph ℓv ℓe : Type (ℓ-suc (ℓ-max ℓv ℓe)) where field Obj : Type ℓv Hom : Obj → Obj → Type ℓe open Graph public _ᵒᵖ : Graph ℓv ℓe → Graph ℓv ℓe Obj (G ᵒᵖ) = Obj G Hom (G ᵒᵖ) x y = Hom G y x TypeGr : ∀ ℓ → Graph (ℓ-suc ℓ) ℓ Obj (TypeGr ℓ) = Type ℓ Hom (TypeGr ℓ) A B = A → B -- Graph functors/homomorphisms record GraphHom (G : Graph ℓv ℓe ) (G' : Graph ℓv' ℓe') : Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-max ℓv' ℓe'))) where field _$_ : Obj G → Obj G' _<$>_ : ∀ {x y : Obj G} → Hom G x y → Hom G' (_$_ x) (_$_ y) open GraphHom public GraphGr : ∀ ℓv ℓe → Graph _ _ Obj (GraphGr ℓv ℓe) = Graph ℓv ℓe Hom (GraphGr ℓv ℓe) G G' = GraphHom G G' -- Diagrams are (graph) functors with codomain Type Diag : ∀ ℓd (G : Graph ℓv ℓe) → Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd))) Diag ℓd G = GraphHom G (TypeGr ℓd) record DiagMor {G : Graph ℓv ℓe} (F : Diag ℓd G) (F' : Diag ℓd' G) : Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc (ℓ-max ℓd ℓd')))) where field nat : ∀ (x : Obj G) → F $ x → F' $ x comSq : ∀ {x y : Obj G} (f : Hom G x y) → nat y ∘ F <$> f ≡ F' <$> f ∘ nat x open DiagMor public DiagGr : ∀ ℓd (G : Graph ℓv ℓe) → Graph _ _ Obj (DiagGr ℓd G) = Diag ℓd G Hom (DiagGr ℓd G) = DiagMor
27.071429
80
0.587731
1226b73efbbaf4811b0a37fe5186fbf747a6018e
179
agda
Agda
Mockingbird/Forest/Combination.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
1
2022-02-28T23:44:42.000Z
2022-02-28T23:44:42.000Z
Mockingbird/Forest/Combination.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
Mockingbird/Forest/Combination.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
open import Mockingbird.Forest using (Forest) module Mockingbird.Forest.Combination {b ℓ} (forest : Forest {b} {ℓ}) where open import Mockingbird.Forest.Combination.Base public
29.833333
75
0.787709
73388631b38ef84626e47aa947d6ba6d8dde9ff5
233
agda
Agda
test/Fail/TrustMe.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/TrustMe.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Fail/TrustMe.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --universe-polymorphism #-} module TrustMe where open import Common.Equality postulate A : Set x y : A eq : x ≡ y eq = primTrustMe does-not-evaluate-to-refl : sym (sym eq) ≡ eq does-not-evaluate-to-refl = refl
14.5625
45
0.678112
58ac8e80c349fefd82b82efd032ab59710e8233b
1,455
agda
Agda
test/Succeed/SharedSuperclasses.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/SharedSuperclasses.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/SharedSuperclasses.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Agda.Builtin.Bool open import Agda.Builtin.Nat renaming (_==_ to _==N_; _<_ to _<N_) record Eq (A : Set) : Set where field _==_ : A → A → Bool open Eq {{...}} record Ord (A : Set) : Set where constructor mkOrd field _<_ : A → A → Bool overlap {{eqA}} : Eq A open Ord {{...}} hiding (eqA) record Num (A : Set) : Set where constructor mkNum field fromNat : Nat → A overlap {{eqA}} : Eq A open Num {{...}} hiding (eqA) instance EqNat : Eq Nat _==_ {{EqNat}} = _==N_ OrdNat : Ord Nat _<_ {{OrdNat}} = _<N_ Ord.eqA OrdNat = EqNat NumNat : Num Nat fromNat {{NumNat}} n = n Num.eqA NumNat = EqNat infixr 3 _||_ _||_ : Bool → Bool → Bool true || x = true false || x = x -- Here it will pick the eq dictionary from the Ord leq3 : {A : Set} {{OrdA : Ord A}} {{NumA : Num A}} → A → Bool leq3 x = x == fromNat 3 || x < fromNat 3 open import Agda.Builtin.Equality 2<3 : true ≡ leq3 2 2<3 = refl it : ∀ {a} {A : Set a} {{_ : A}} → A it {{x}} = x -- Check that you get the first shared dictionary getShared : {A : Set} {{OrdA : Ord A}} {{NumA : Num A}} → Eq A getShared = it itsOrd : {A : Set} {{OrdA : Ord A}} {{NumA : Num A}} → getShared ≡ Ord.eqA OrdA itsOrd = refl -- Check that it also works if you pattern match on the dictionaries leq3' : {A : Set} {{OrdA : Ord A}} {{NumA : Num A}} → A → Bool leq3' {{mkOrd _<_}} {{mkNum fromNat}} x = x == fromNat 3 || x < fromNat 3
20.785714
79
0.582818
7385816aace6ba6019c9a051f0bafd47fd98bcd1
6,379
agda
Agda
LibraBFT/Impl/Properties/PreferredRound.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/Impl/Properties/PreferredRound.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/Impl/Properties/PreferredRound.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.PKCS open import LibraBFT.Concrete.Records open import LibraBFT.Concrete.System open import LibraBFT.Concrete.System.Parameters open import LibraBFT.Concrete.Obligations.PreferredRound import LibraBFT.Concrete.Properties.Common as Common import LibraBFT.Concrete.Properties.PreferredRound as PR open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Consensus.Types.EpochDep open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.ImplShared.Util.Crypto open import LibraBFT.ImplShared.Util.Util open import LibraBFT.Impl.Consensus.Network as Network open import LibraBFT.Impl.Consensus.Network.Properties as NetworkProps open import LibraBFT.Impl.Consensus.RoundManager import LibraBFT.Impl.Handle as Handle open import LibraBFT.Impl.Handle.Properties open import LibraBFT.Impl.Handle.InitProperties open initHandlerSpec open import LibraBFT.Impl.IO.OBM.InputOutputHandlers open import LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers open import LibraBFT.Impl.Properties.Common open ReachableSystemStateProps open import LibraBFT.Impl.Properties.Util open import LibraBFT.Lemmas open import LibraBFT.Prelude open import Optics.All open Invariants open RoundManagerTransProps open import LibraBFT.Abstract.Types.EpochConfig UID NodeId open ParamsWithInitAndHandlers Handle.InitHandler.InitAndHandlers open import LibraBFT.ImplShared.Util.HashCollisions Handle.InitHandler.InitAndHandlers open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms Handle.InitHandler.InitAndHandlers PeerCanSignForPK PeerCanSignForPK-stable open Structural impl-sps-avp -- This module proves the two "PreferredRound" proof obligations for our handler. module LibraBFT.Impl.Properties.PreferredRound (𝓔 : EpochConfig) where ------------------------------------------------------------------------------ preferredRound₁ : PR.ImplObligation₁ Handle.InitHandler.InitAndHandlers 𝓔 preferredRound₁ {pid} {pid'} {pk = pk} {pre} preach sps@(step-init rm×acts uni) {v = v} {m = m} {v' = v'} {m' = m'} hpk v'⊂m' m'∈acts sig' ¬bootstrap' pcs4' v⊂m m∈pool sig ¬bootstrap eid≡ rnd< v≈vabs v'≈vabs' c3 with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts ...| init-contract with initHandlerSpec.ContractOk.isInitPM init-contract m'∈acts ...| (_ , refl , noSigs) with v'⊂m' ...| vote∈qc vs∈qc _ qc∈pm = ⊥-elim (noSigs vs∈qc qc∈pm) preferredRound₁ {pid} {pid'} {pk = pk} {pre} preach sps@(step-msg {sndr , P vm} vm'∈pool ini) {v = v} {m = m} {v' = v'} {m' = m'} hpk v'⊂m' m'∈acts sig' ¬bootstrap' pcs4' v⊂m m∈pool sig ¬bootstrap eid≡ rnd< v≈vabs v'≈vabs' c3 = obm-dangerous-magic' "Extend and use handleProposalSpec.contract" preferredRound₁ {pid} {pre = pre} preach sps@(step-msg {_ , V vm} _ _) _ v'⊂m' m'∈acts sig' ¬bootstrap' ¬msb _ _ _ _ _ _ _ _ _ with v'⊂m' ...| vote∈qc vs∈qc v≈rbld qc∈m' rewrite cong _vSignature v≈rbld = ⊥-elim ∘′ ¬msb $ qcVoteSigsSentB4-handle pid preach sps m'∈acts qc∈m' sig' vs∈qc v≈rbld ¬bootstrap' ...| vote∈vm = ⊥-elim (sendVote∉actions{outs = hvOut}{st = hvPre} (sym noVotes) m'∈acts) where hvPre = peerStates pre pid hvOut = LBFT-outs (handleVote 0 vm) hvPre open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre) ------------------------------------------------------------------------------ -- This proof is essentially the same as the votesOnce₂: no handler sends two different Votes -- TODO-2: refactor for DRY? preferredRound₂ : PR.ImplObligation₂ Handle.InitHandler.InitAndHandlers 𝓔 preferredRound₂ {pid} _ (step-init rm×acts uni) _ v⊂m m∈acts _ _ _ _ _ _ _ _ _ _ _ _ with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts ...| init-contract with initHandlerSpec.ContractOk.isInitPM init-contract m∈acts ...| (_ , refl , noSigs) with v⊂m ...| vote∈qc vs∈qc _ qc∈pm = ⊥-elim (noSigs vs∈qc qc∈pm) preferredRound₂ {pid}{pk = pk}{pre} rss (step-msg{sndr , m“} m“∈pool ini) {v = v}{v' = v'} hpk v⊂m m∈acts sig ¬bootstrap ¬msb4 pcsfpk v'⊂m' m'∈acts sig' ¬bootstrap' ¬msb4' _ _ round< with v⊂m ...| vote∈qc vs∈qc v≈rbld qc∈m rewrite cong _vSignature v≈rbld = ⊥-elim ∘′ ¬msb4 $ qcVoteSigsSentB4-handle pid rss (step-msg m“∈pool ini) m∈acts qc∈m sig vs∈qc v≈rbld ¬bootstrap ...| vote∈vm with v'⊂m' ...| vote∈qc vs∈qc' v≈rbld' qc∈m' rewrite cong _vSignature v≈rbld' = ⊥-elim ∘′ ¬msb4' $ qcVoteSigsSentB4-handle pid rss (step-msg m“∈pool ini) m'∈acts qc∈m' sig' vs∈qc' v≈rbld' ¬bootstrap' ...| vote∈vm with m“ ...| P pm = ⊥-elim (<⇒≢ round< (cong (_^∙ vRound) v≡v')) where hpPool = msgPool pre hpPre = peerStates pre pid hpOut = LBFT-outs (handleProposal 0 pm) hpPre open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hpPool hpPre) v≡v' : v ≡ v' v≡v' with BlockId-correct? (pm ^∙ pmProposal) ...| no ¬validProposal = ⊥-elim (sendVote∉actions {outs = hpOut} {st = hpPre} (sym (proj₂ $ invalidProposal ¬validProposal)) m∈acts) ...| yes refl with voteAttemptCorrect refl (nohc rss m“∈pool pid ini (invariantsCorrect pid pre ini rss) refl refl ) ...| Voting.mkVoteAttemptCorrectWithEpochReq (Left (_ , Voting.mkVoteUnsentCorrect noVoteMsgOuts _)) _ = ⊥-elim (sendVote∉actions{outs = hpOut}{st = hpPre} (sym noVoteMsgOuts) m∈acts) ...| Voting.mkVoteAttemptCorrectWithEpochReq (Right (Voting.mkVoteSentCorrect vm pid voteMsgOuts _)) _ = begin v ≡⟨ cong (_^∙ vmVote) (sendVote∈actions{outs = hpOut}{st = hpPre} (sym voteMsgOuts) m∈acts) ⟩ vm ^∙ vmVote ≡⟨ (sym $ cong (_^∙ vmVote) (sendVote∈actions{outs = hpOut}{st = hpPre} (sym voteMsgOuts) m'∈acts)) ⟩ v' ∎ where open ≡-Reasoning ... | V vm = ⊥-elim (sendVote∉actions{outs = hvOut}{st = hvPre} (sym noVotes) m∈acts) where hvPre = peerStates pre pid hvOut = LBFT-outs (handle pid (V vm) 0) hvPre open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)
48.694656
182
0.686314
1414835b4c8d349d318ffbf34d2e4e65286e6a62
18,832
agda
Agda
CaTT/Relation.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
CaTT/Relation.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
CaTT/Relation.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting --without-K #-} open import Prelude open import GSeTT.Syntax open import GSeTT.Rules open import GSeTT.Uniqueness-Derivations open import Sets ℕ eqdecℕ open import GSeTT.Dec-Type-Checking open import CaTT.Ps-contexts {- PS-contexts -} module CaTT.Relation where -- The relation ◃ generating cases data _,_◃₀_ Γ x y : Set₁ where ◃∂⁻ : ∀{A z} → Γ ⊢t (Var y) # (⇒ A (Var x) (Var z)) → Γ , x ◃₀ y ◃∂⁺ : ∀{A z} → Γ ⊢t (Var x) # (⇒ A (Var z) (Var y)) → Γ , x ◃₀ y -- Transitive closure : we associate on the right data _,_◃_ Γ x y : Set₁ where gen : Γ , x ◃₀ y → Γ , x ◃ y ◃T : ∀{z} → Γ , x ◃ z → Γ , z ◃₀ y → Γ , x ◃ y rel : ∀ Γ x y → Set₁ rel Γ x y = Γ , x ◃ y W◃₀ : ∀ {Γ x y z A} → (Γ :: (z , A)) ⊢C → Γ , x ◃₀ y → (Γ :: (z , A)) , x ◃₀ y W◃₀ Γ+⊢ (◃∂⁻ Γ⊢x) = ◃∂⁻ (wkt Γ⊢x Γ+⊢) W◃₀ Γ+⊢ (◃∂⁺ Γ⊢x) = ◃∂⁺ (wkt Γ⊢x Γ+⊢) W◃ : ∀ {Γ x y z A} → (Γ :: (z , A)) ⊢C → Γ , x ◃ y → (Γ :: (z , A)) , x ◃ y W◃ Γ+⊢ (gen x◃₀y) = gen (W◃₀ Γ+⊢ x◃₀y) W◃ Γ+⊢ (◃T x◃y y◃₀z) = ◃T (W◃ Γ+⊢ x◃y) (W◃₀ Γ+⊢ y◃₀z) WW◃ : ∀ {Γ x y z f A B} → ((Γ :: (z , A)) :: (f , B)) ⊢C → Γ , x ◃ y → ((Γ :: (z , A)) :: (f , B)) , x ◃ y WW◃ Γ+⊢@(cc Γ⊢ _ idp) x◃y = W◃ Γ+⊢ (W◃ Γ⊢ x◃y) ◃-trans : ∀ {Γ x y z} → Γ , x ◃ y → Γ , y ◃ z → Γ , x ◃ z ◃-trans x◃y (gen y◃₀z) = ◃T x◃y y◃₀z ◃-trans x◃y (◃T y◃z z◃₀w) = ◃T (◃-trans x◃y y◃z) z◃₀w -- TODO : Move at the right place x#A∈Γ→x∈Γ : ∀ {Γ x A} → x # A ∈ Γ → x ∈ Γ x#A∈Γ→x∈Γ {Γ :: (y , _)} (inl x#A∈Γ) = inl (x#A∈Γ→x∈Γ x#A∈Γ) x#A∈Γ→x∈Γ {Γ :: (y , _)} (inr (idp , idp)) = inr idp Γ⊢x:A→x∈Γ : ∀ {Γ x A} → Γ ⊢t (Var x) # A → x ∈ Γ Γ⊢x:A→x∈Γ (var _ x#A∈Γ) = x#A∈Γ→x∈Γ x#A∈Γ data _,_⟿_ : Pre-Ctx → ℕ → ℕ → Set₁ where -- y is an iterated target of x in Γ ∂⁺⟿ : ∀{Γ x a y A} → Γ ⊢t (Var x) # (⇒ A (Var a) (Var y)) → Γ , x ⟿ y x⟿∂⁺ : ∀{Γ x a y z A} → Γ ⊢t (Var x) # (⇒ A (Var a) (Var y)) → Γ , y ⟿ z → Γ , x ⟿ z W⟿ : ∀ {Γ x y z A} → (Γ :: (z , A)) ⊢C → Γ , x ⟿ y → (Γ :: (z , A)) , x ⟿ y W⟿ Γ+⊢ (∂⁺⟿ Γ⊢x) = ∂⁺⟿ (wkt Γ⊢x Γ+⊢) W⟿ Γ+⊢ (x⟿∂⁺ Γ⊢x x⟿y) = x⟿∂⁺ (wkt Γ⊢x Γ+⊢) (W⟿ Γ+⊢ x⟿y) WW⟿ : ∀ {Γ x y z w A B} → ((Γ :: (z , A)) :: (w , B)) ⊢C → Γ , x ⟿ y → ((Γ :: (z , A)) :: (w , B)) , x ⟿ y WW⟿ Γ++⊢@(cc Γ+⊢ _ idp) x⟿y = W⟿ Γ++⊢ (W⟿ Γ+⊢ x⟿y) ⟿→◃ : ∀ {Γ x y} → Γ , x ⟿ y → Γ , x ◃ y ⟿→◃ (∂⁺⟿ Γ⊢x) = gen (◃∂⁺ Γ⊢x) ⟿→◃ (x⟿∂⁺ Γ⊢x x⟿y) = ◃-trans (gen (◃∂⁺ Γ⊢x)) (⟿→◃ x⟿y) Γ++ : ∀ {Γ x A} → Γ ⊢ps x # A → Pre-Ctx Γ++ {Γ} {x} {A} _ = (Γ :: (length Γ , A)) :: (S (length Γ) , ⇒ A (Var x) (Var (length Γ))) //⟿ : ∀ {Γ Δ x y A a} → Γ ⊢t (Var x) # A → Δ ⊢t (Var y) # A → Γ , x ⟿ a → Δ , y ⟿ a //⟿ Γ⊢x Δ⊢y (∂⁺⟿ Γ⊢x') with unique-type Γ⊢x Γ⊢x' idp ... | idp = ∂⁺⟿ Δ⊢y //⟿ Γ⊢x Δ⊢y (x⟿∂⁺ Γ⊢x' x⟿a) with unique-type Γ⊢x Γ⊢x' idp ... | idp = x⟿∂⁺ Δ⊢y (//⟿ (Γ⊢tgt (Γ⊢t:A→Γ⊢A Γ⊢x)) (Γ⊢tgt (Γ⊢t:A→Γ⊢A Δ⊢y)) x⟿a) T⟿ : ∀ {Γ x y z} → Γ , x ⟿ y → Γ , y ⟿ z → Γ , x ⟿ z T⟿ (∂⁺⟿ Γ⊢x) y⟿z = x⟿∂⁺ Γ⊢x y⟿z T⟿ (x⟿∂⁺ Γ⊢x x⟿y) y⟿z = x⟿∂⁺ Γ⊢x (T⟿ x⟿y y⟿z) ⟿dim : ∀ {Γ x y A B} → Γ ⊢t Var x # A → Γ ⊢t Var y # B → Γ , x ⟿ y → dim B < dim A ⟿dim Γ⊢x:A Γ⊢y:B (∂⁺⟿ Γ⊢x) with unique-type Γ⊢x:A Γ⊢x idp | unique-type Γ⊢y:B (Γ⊢tgt(Γ⊢t:A→Γ⊢A Γ⊢x)) idp ... | idp | idp = n≤n _ ⟿dim Γ⊢x:A Γ⊢y:B (x⟿∂⁺ Γ⊢x z⟿y) with unique-type Γ⊢x:A Γ⊢x idp ... | idp = n≤m→n≤Sm (⟿dim (Γ⊢tgt(Γ⊢t:A→Γ⊢A Γ⊢x)) Γ⊢y:B z⟿y) 𝔻0-◃ : ∀ z → ¬ ((nil :: (0 , ∗)) , 0 ◃ z) 𝔻0-◃ z (gen (◃∂⁻ (var _ (inl ())))) 𝔻0-◃ z (gen (◃∂⁻ (var _ (inr ())))) 𝔻0-◃ z (gen (◃∂⁺ (var _ (inl ())))) 𝔻0-◃ z (gen (◃∂⁺ (var _ (inr ())))) 𝔻0-◃ z (◃T 0◃x _) = 𝔻0-◃ _ 0◃x 𝔻0-⟿ : ∀ z → ¬ ((nil :: (0 , ∗)) , 0 ⟿ z) 𝔻0-⟿ z (∂⁺⟿ (var _ (inl ()))) 𝔻0-⟿ z (∂⁺⟿ (var _ (inr ()))) 𝔻0-⟿ z (x⟿∂⁺ (var _ (inl ())) _) 𝔻0-⟿ z (x⟿∂⁺ (var _ (inr ())) _) n≮n : ∀ n → ¬ (n < n) n≮n n n<n = Sn≰n _ n<n ⟿-is-tgt : ∀ {Γ x y z A} → Γ ⊢t Var x # ⇒ A (Var y) (Var z) → Γ , x ⟿ y → y == z ⟿-is-tgt Γ⊢x (∂⁺⟿ Γ⊢'x) with unique-type Γ⊢x Γ⊢'x idp ... | idp = idp ⟿-is-tgt Γ⊢x (x⟿∂⁺ Γ⊢'x y'⟿y) with unique-type Γ⊢x Γ⊢'x idp ... | idp = ⊥-elim (Sn≰n _ (⟿dim (Γ⊢tgt (Γ⊢t:A→Γ⊢A Γ⊢'x)) (Γ⊢src (Γ⊢t:A→Γ⊢A Γ⊢x)) y'⟿y)) no-loop : ∀{Γ x y z T a A} → Γ ⊢ps a # A → Γ ⊢t (Var x) # ⇒ T (Var y) (Var z) → y ≠ z no-loop pss (var _ (inl ())) idp no-loop pss (var _ (inr ())) idp no-loop (psd Γ⊢psf) Γ⊢x idp = no-loop Γ⊢psf Γ⊢x idp no-loop (pse Γ⊢psb idp idp idp idp idp) (var _ (inl (inl x∈Γ))) idp = no-loop Γ⊢psb (var (Γ⊢psx:A→Γ⊢ Γ⊢psb) x∈Γ) idp no-loop (pse Γ⊢psb idp idp idp idp idp) (var _ (inl (inr (idp , idp)))) idp = no-loop Γ⊢psb (Γ⊢psx:A→Γ⊢x:A Γ⊢psb) idp no-loop (pse Γ⊢psb idp idp idp idp idp) (var _ (inr (idp , idp))) idp = x∉ (Γ⊢psx:A→Γ⊢ Γ⊢psb) (n≤n _) (Γ⊢psx:A→Γ⊢x:A Γ⊢psb) dangling-is-not-a-source : ∀ {Γ x A} → Γ ⊢ps x # A → (∀ f z {B} → ¬ (Γ ⊢t Var f # ⇒ B (Var x) (Var z))) post-dangling-is-not-a-source : ∀ {Γ x A} → Γ ⊢ps x # A → (∀ {y B} f z → Γ , x ⟿ y → ¬ (Γ ⊢t (Var f) # ⇒ B (Var y) (Var z))) dangling-is-not-a-source pss _ _ (var _ (inl ())) dangling-is-not-a-source pss _ _ (var _ (inr ())) dangling-is-not-a-source {x = x} (psd Γ⊢ps) t u Γ⊢t = post-dangling-is-not-a-source Γ⊢ps t u (∂⁺⟿ (psvar Γ⊢ps)) Γ⊢t dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (var _ (inl (inl x∈Γ))) = x∉ (psv Γ⊢ps) (n≤Sn _) (Γ⊢src (Γ⊢t:A→Γ⊢A (var (psv Γ⊢ps) x∈Γ))) dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (var _ (inl (inr (idp , idp)))) = x∉ (psv Γ⊢ps) (n≤Sn _) (Γ⊢src (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps))) dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (var _ (inr (idp , idp))) = x∉ (psv Γ⊢ps) (n≤Sn _) (psvar Γ⊢ps) post-dangling-is-not-a-source pss t u x⟿y Γ⊢t = 𝔻0-⟿ _ x⟿y post-dangling-is-not-a-source (psd Γ⊢ps) t u x⟿y Γ⊢t = post-dangling-is-not-a-source Γ⊢ps t u (T⟿ (∂⁺⟿ (psvar Γ⊢ps)) x⟿y) Γ⊢t post-dangling-is-not-a-source Γ+⊢@(pse Γ⊢ps idp idp idp idp idp) t u (∂⁺⟿ Γ⊢Sl) Γ⊢t with unique-type Γ⊢Sl (psvar Γ+⊢) idp post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (∂⁺⟿ Γ⊢Sl) (var _ (inl (inl t∈Γ))) | idp = x∉ (psv Γ⊢ps) (n≤n _) (Γ⊢src (Γ⊢t:A→Γ⊢A (var (psv Γ⊢ps) t∈Γ))) post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (∂⁺⟿ Γ⊢Sl) (var _ (inl (inr (idp , idp)))) | idp = x∉ (psv Γ⊢ps) (n≤n _) (Γ⊢src (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps))) post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (∂⁺⟿ Γ⊢Sl) (var _ (inr (idp , idp))) | idp = x∉ (psv Γ⊢ps) (n≤n _) (psvar Γ⊢ps) post-dangling-is-not-a-source Γ+⊢@(pse Γ⊢ps idp idp idp idp idp) t u (x⟿∂⁺ Γ⊢Sl x⟿y) Γ⊢t with unique-type Γ⊢Sl (psvar Γ+⊢) idp post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (x⟿∂⁺ Γ⊢Sl x⟿y) (var Γ+⊢ (inl (inl t∈Γ))) | idp = post-dangling-is-not-a-source Γ⊢ps _ _ (//⟿ (var Γ+⊢ (inl (inr (idp , idp)))) (psvar Γ⊢ps) x⟿y) (var (psv Γ⊢ps) t∈Γ) post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (x⟿∂⁺ Γ⊢Sl x⟿y) (var Γ+⊢ (inl (inr (idp , idp)))) | idp with ⟿-is-tgt (var Γ+⊢ (inl (inr (idp , idp)))) x⟿y ... | idp = no-loop Γ⊢ps (psvar Γ⊢ps) idp post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (x⟿∂⁺ Γ⊢Sl x⟿y) (var Γ++⊢@(cc Γ+⊢ _ p) (inr (idp , idp))) | idp = n≮n _ (⟿dim (var Γ++⊢ (inl (inr (idp , idp)))) (wkt (wkt (psvar Γ⊢ps) Γ+⊢) Γ++⊢) x⟿y) ⊢psx-◃₀→⟿ : ∀ {Γ x a A} → Γ ⊢ps x # A → Γ , x ◃₀ a → Γ , x ⟿ a ⊢psx-◃₀→⟿ Γ⊢psx (◃∂⁻ Γ⊢a) = ⊥-elim (dangling-is-not-a-source Γ⊢psx _ _ Γ⊢a) ⊢psx-◃₀→⟿ Γ⊢psx (◃∂⁺ Γ⊢x) = ∂⁺⟿ Γ⊢x ⊢psx-◃₀→⟿+ : ∀ {Γ x y a A} → Γ ⊢ps x # A → Γ , x ⟿ y → Γ , y ◃₀ a → Γ , y ⟿ a ⊢psx-◃₀→⟿+ Γ⊢psx x⟿y (◃∂⁻ Γ⊢a) = ⊥-elim (post-dangling-is-not-a-source Γ⊢psx _ _ x⟿y Γ⊢a) ⊢psx-◃₀→⟿+ Γ⊢psx x⟿y (◃∂⁺ Γ⊢y) = ∂⁺⟿ Γ⊢y ⊢psx-◃→⟿ : ∀ {Γ x a A} → Γ ⊢ps x # A → Γ , x ◃ a → Γ , x ⟿ a ⊢psx-◃→⟿+ : ∀ {Γ x a b A} → Γ ⊢ps x # A → Γ , x ⟿ a → Γ , a ◃ b → Γ , a ⟿ b ⊢psx-◃→⟿ Γ⊢psx (gen x◃₀a) = ⊢psx-◃₀→⟿ Γ⊢psx x◃₀a ⊢psx-◃→⟿ Γ⊢psx (◃T x◃z z◃₀a) = T⟿ (⊢psx-◃→⟿ Γ⊢psx x◃z) (⊢psx-◃₀→⟿+ Γ⊢psx (⊢psx-◃→⟿ Γ⊢psx x◃z) z◃₀a) ⊢psx-◃→⟿+ Γ⊢psx x⟿y (gen y◃₀a) = ⊢psx-◃₀→⟿+ Γ⊢psx x⟿y y◃₀a ⊢psx-◃→⟿+ Γ⊢psx x⟿y (◃T y◃z z◃₀a) = T⟿ (⊢psx-◃→⟿+ Γ⊢psx x⟿y y◃z) (⊢psx-◃₀→⟿+ Γ⊢psx (T⟿ x⟿y (⊢psx-◃→⟿+ Γ⊢psx x⟿y y◃z)) z◃₀a) -- easy to finish, and follows the paper proof psx-◃-linear→ : ∀ {Γ x A} → Γ ⊢ps x # A → (∀ a b → a ∈ Γ → b ∈ Γ → (((Γ , a ◃ b) + (Γ , b ◃ a)) + (a == b))) psx-◃-linear→ pss .0 .0 (inr idp) (inr idp) = inr idp psx-◃-linear→ (psd Γ⊢psx) a b a∈Γ b∈Γ = psx-◃-linear→ Γ⊢psx a b a∈Γ b∈Γ psx-◃-linear→ Γ++⊢ps@(pse Γ⊢psx idp idp idp idp idp) a b (inl (inl a∈Γ)) (inl (inl b∈Γ)) with psx-◃-linear→ Γ⊢psx a b a∈Γ b∈Γ ... | inl (inl a◃b) = inl (inl (WW◃ (psv Γ++⊢ps) a◃b)) ... | inl (inr b◃a) = inl (inr (WW◃ (psv Γ++⊢ps) b◃a)) ... | inr idp = inr idp psx-◃-linear→ Γ++⊢ps@(pse {x = x} Γ⊢psx idp idp idp idp idp) a .(length _) (inl (inl a∈Γ)) (inl (inr idp)) with psx-◃-linear→ Γ⊢psx a x a∈Γ (Γ⊢x:A→x∈Γ (psvar Γ⊢psx)) -- a ∈ Γ , b = y ... | inl (inl a◃x) = inl (inl (◃-trans (WW◃ (psv Γ++⊢ps) a◃x) (◃T (gen (◃∂⁻ (psvar Γ++⊢ps))) ((◃∂⁺ (psvar Γ++⊢ps)))))) -- a ◃ x ... | inl (inr x◃a) = inl (inr (⟿→◃ (//⟿ (psvar Γ⊢psx) (var (psv Γ++⊢ps) (inl (inr (idp , idp)))) (⊢psx-◃→⟿ Γ⊢psx x◃a)))) -- x ◃ a ... | inr idp = inl (inl (◃T (gen (◃∂⁻ (psvar Γ++⊢ps))) (◃∂⁺ (psvar Γ++⊢ps)))) -- a = x psx-◃-linear→ Γ++⊢ps@(pse {x = x} Γ⊢psx idp idp idp idp idp) a .(S (length _)) (inl (inl a∈Γ)) (inr idp) with psx-◃-linear→ Γ⊢psx a x a∈Γ (Γ⊢x:A→x∈Γ (psvar Γ⊢psx)) -- a ∈ Γ , b = f (**) ... | inl (inl a◃x) = inl (inl (◃T (WW◃ (psv Γ++⊢ps) a◃x) (◃∂⁻ (psvar Γ++⊢ps)))) -- a ◃ x ... | inl (inr x◃a) = inl (inr (⟿→◃ (x⟿∂⁺ (psvar Γ++⊢ps) (//⟿ (psvar Γ⊢psx) (var (psv Γ++⊢ps) (inl (inr (idp , idp)))) (⊢psx-◃→⟿ Γ⊢psx x◃a))))) -- x ◃ a ... | inr idp = inl (inl (gen (◃∂⁻ (psvar Γ++⊢ps)))) -- a = x psx-◃-linear→ Γ++⊢ps@(pse {x = x} Γ⊢psx idp idp idp idp idp) .(length _) b (inl (inr idp)) (inl (inl b∈Γ)) with psx-◃-linear→ Γ⊢psx b x b∈Γ (Γ⊢x:A→x∈Γ (psvar Γ⊢psx)) -- a = y, b ∈ Γ ... | inl (inl b◃x) = inl (inr (◃-trans (WW◃ (psv Γ++⊢ps) b◃x) (◃T (gen (◃∂⁻ (psvar Γ++⊢ps))) (◃∂⁺ (psvar Γ++⊢ps))))) -- b ◃ x ... | inl (inr x◃b) = inl (inl (⟿→◃ (//⟿ (psvar Γ⊢psx) (var (psv Γ++⊢ps) (inl (inr (idp , idp)))) (⊢psx-◃→⟿ Γ⊢psx x◃b)))) -- x ◃ b ... | inr idp = inl (inr (◃T (gen (◃∂⁻ (psvar Γ++⊢ps))) (◃∂⁺ (psvar Γ++⊢ps)))) -- b = x psx-◃-linear→ (pse Γ⊢psx idp idp idp idp idp) .(length _) .(length _) (inl (inr idp)) (inl (inr idp)) = inr idp psx-◃-linear→ Γ++⊢ps@(pse Γ⊢psx idp idp idp idp idp) .(length _) .(S (length _)) (inl (inr idp)) (inr idp) = inl (inr (gen (◃∂⁺ (psvar Γ++⊢ps)))) -- a = y, b = f psx-◃-linear→ Γ++⊢ps@(pse {x = x} Γ⊢psx idp idp idp idp idp) .(S (length _)) b (inr idp) (inl (inl b∈Γ)) with psx-◃-linear→ Γ⊢psx b x b∈Γ (Γ⊢x:A→x∈Γ (psvar Γ⊢psx)) -- a = f b ∈ Γ ... | inl (inl b◃x) = inl (inr (◃T (WW◃ (psv Γ++⊢ps) b◃x) (◃∂⁻ (psvar Γ++⊢ps)))) -- b ◃ x ... | inl (inr x◃b) = inl (inl (⟿→◃ (x⟿∂⁺ (psvar Γ++⊢ps) (//⟿ (psvar Γ⊢psx) (var (psv Γ++⊢ps) (inl (inr (idp , idp)))) (⊢psx-◃→⟿ Γ⊢psx x◃b))))) -- x ◃ b ... | inr idp = inl (inr (gen (◃∂⁻ (psvar Γ++⊢ps)))) -- b = x psx-◃-linear→ Γ++⊢ps@(pse Γ⊢psx idp idp idp idp idp) .(S (length _)) .(length _) (inr idp) (inl (inr idp)) = inl (inl (gen (◃∂⁺ (psvar Γ++⊢ps)))) -- a = f, b = y psx-◃-linear→ (pse Γ⊢psx idp idp idp idp idp) .(S (length _)) .(S (length _)) (inr idp) (inr idp) = inr idp strengthen : ∀ {Γ x A y B} → (Γ :: (y , B)) ⊢t Var x # A → x ∈ Γ → Γ ⊢t Var x # A strengthen (var (cc Γ⊢ _ idp) (inl x#A∈Γ)) x∈Γ = var Γ⊢ x#A∈Γ strengthen (var (cc Γ⊢ _ idp) (inr (idp , idp))) x∈Γ = ⊥-elim (l∉ Γ⊢ (n≤n _) x∈Γ) strengthen+ : ∀ {Γ x A y B z C} → ((Γ :: (y , B)) :: (z , C)) ⊢t Var x # A → x ∈ Γ → Γ ⊢t Var x # A strengthen+ Γ++⊢x x∈Γ = strengthen (strengthen Γ++⊢x (inl x∈Γ)) x∈Γ ◃₀∈ : ∀ {Γ x a} → Γ , x ◃₀ a → a ∈ Γ ◃₀∈ (◃∂⁻ Γ⊢a) = Γ⊢x:A→x∈Γ Γ⊢a ◃₀∈ (◃∂⁺ Γ⊢x) = Γ⊢x:A→x∈Γ (Γ⊢tgt (Γ⊢t:A→Γ⊢A Γ⊢x)) ◃∈ : ∀ {Γ x a} → Γ , x ◃ a → a ∈ Γ ◃∈ (gen x◃₀a) = ◃₀∈ x◃₀a ◃∈ (◃T _ z◃₀x) = ◃₀∈ z◃₀x ∈◃₀ : ∀ {Γ x a} → Γ , x ◃₀ a → x ∈ Γ ∈◃₀ (◃∂⁻ Γ⊢a) = Γ⊢x:A→x∈Γ (Γ⊢src (Γ⊢t:A→Γ⊢A Γ⊢a)) ∈◃₀ (◃∂⁺ Γ⊢x) = Γ⊢x:A→x∈Γ Γ⊢x ∈◃ : ∀ {Γ x a} → Γ , x ◃ a → x ∈ Γ ∈◃ (gen x◃₀a) = ∈◃₀ x◃₀a ∈◃ (◃T x◃z _) = ∈◃ x◃z WWpsx : ∀ {Γ x A} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps ⊢t (Var x) # A WWpsx Γ⊢ps = wkt (wkt (psvar Γ⊢ps) (cc (psv Γ⊢ps) (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps)) idp)) (psv (pse Γ⊢ps idp idp idp idp idp)) dangling-◃₀ : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , S (length Γ) ◃₀ a → a == length Γ dangling-◃₀ Γ⊢ps (◃∂⁻ Γ⊢a) = ⊥-elim (dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ Γ⊢a) dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inl (inl Sl∈Γ)))) = ⊥-elim (l∉ (psv Γ⊢ps) (n≤Sn _) (x#A∈Γ→x∈Γ Sl∈Γ)) dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inl (inr (Sl=l , idp))))) = ⊥-elim (Sn≠n _ Sl=l) dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inr (_ , idp)))) = idp ◃₀-dangling : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃₀ S (length Γ) → a == x ◃₀-dangling Γ⊢ps (◃∂⁻ Γ+⊢Sl) with unique-type Γ+⊢Sl (psvar (pse Γ⊢ps idp idp idp idp idp)) idp ... | idp = idp ◃₀-dangling Γ⊢ps (◃∂⁺ (var x (inl (inl a∈Γ)))) = ⊥-elim (x∉ (psv Γ⊢ps) (n≤Sn _) (Γ⊢tgt (Γ⊢t:A→Γ⊢A (var (psv Γ⊢ps) a∈Γ)))) ◃₀-dangling Γ⊢ps (◃∂⁺ (var x (inl (inr (idp , idp))))) = ⊥-elim (x∉ (psv Γ⊢ps) (n≤Sn _) (Γ⊢tgt (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps)))) ◃₀-dangling Γ⊢ps (◃∂⁺ (var x (inr (idp , abs)))) = ⊥-elim (Sn≠n _ (=Var (snd (=⇒ abs)))) ◃₀-dangling-tgt : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃₀ length Γ → (a == S (length Γ)) + (Γ++ Γ⊢ps , a ◃₀ x) ◃₀-dangling-tgt Γ⊢ps (◃∂⁻ Γ+⊢l) with unique-type Γ+⊢l (var (psv (pse Γ⊢ps idp idp idp idp idp)) (inl (inr (idp , idp)))) idp ... | idp = inr (◃∂⁻ (WWpsx Γ⊢ps)) ◃₀-dangling-tgt Γ⊢ps (◃∂⁺ (var x (inl (inl a∈Γ)))) = ⊥-elim (x∉ (psv Γ⊢ps) (n≤n _) (Γ⊢tgt (Γ⊢t:A→Γ⊢A (var (psv Γ⊢ps) a∈Γ)))) ◃₀-dangling-tgt Γ⊢ps (◃∂⁺ (var x (inl (inr (idp , idp))))) = ⊥-elim (x∉ (psv Γ⊢ps) (n≤n _) (Γ⊢tgt (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps)))) ◃₀-dangling-tgt Γ⊢ps (◃∂⁺ (var x (inr (p , _)))) = inl p ◃-dangling : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃ S (length Γ) → (a == x) + (Γ++ Γ⊢ps , a ◃ x) ◃-dangling Γ⊢ps (gen x◃₀Sl) with ◃₀-dangling Γ⊢ps x◃₀Sl ... | idp = inl idp ◃-dangling Γ⊢ps (◃T a◃x x◃₀Sl) with ◃₀-dangling Γ⊢ps x◃₀Sl ... | idp = inr a◃x ◃-dangling-tgt : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃ length Γ → (a == S (length Γ) + (a == x)) + (Γ++ Γ⊢ps , a ◃ x) ◃-dangling-tgt Γ⊢ps (gen a◃₀l) with ◃₀-dangling-tgt Γ⊢ps a◃₀l ... | inl idp = inl (inl idp) ... | inr a◃₀x = inr (gen a◃₀x) ◃-dangling-tgt Γ⊢ps (◃T a◃z z◃₀l) with ◃₀-dangling-tgt Γ⊢ps z◃₀l ... | inl idp with ◃-dangling Γ⊢ps a◃z ... | inl idp = inl (inr idp) ... | inr a◃x = inr a◃x ◃-dangling-tgt Γ⊢ps (◃T a◃z z◃₀l) | inr z◃₀x = inr (◃T a◃z z◃₀x) strengthen-◃₀ : ∀ {Γ x A a b} → (Γ⊢ps : Γ ⊢ps x # A) → a ∈ Γ → b ∈ Γ → Γ++ Γ⊢ps , a ◃₀ b → Γ , a ◃₀ b strengthen-◃₀ Γ⊢ps a∈Γ b∈Γ (◃∂⁻ Γ⊢b) = ◃∂⁻ (strengthen+ Γ⊢b b∈Γ) strengthen-◃₀ Γ⊢ps a∈Γ b∈Γ (◃∂⁺ Γ⊢a) = ◃∂⁺ (strengthen+ Γ⊢a a∈Γ) -- useful particular case strengthen-◃₀-dangling : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , length Γ ◃₀ a → Γ , x ◃₀ a strengthen-◃₀-dangling Γ⊢ps (◃∂⁻ Γ⊢a) = ⊥-elim (post-dangling-is-not-a-source (pse Γ⊢ps idp idp idp idp idp) _ _ (∂⁺⟿ (psvar (pse Γ⊢ps idp idp idp idp idp))) Γ⊢a) strengthen-◃₀-dangling Γ⊢ps (◃∂⁺ (var _ (inl (inl l∈Γ)))) = ⊥-elim (l∉ (psv Γ⊢ps) (n≤n _) (x#A∈Γ→x∈Γ l∈Γ)) strengthen-◃₀-dangling Γ⊢ps (◃∂⁺ (var _ (inl (inr (_ , idp))))) = ◃∂⁺ (psvar Γ⊢ps) strengthen-◃₀-dangling Γ⊢ps (◃∂⁺ (var _ (inr (l=Sl , _)))) = ⊥-elim (Sn≠n _ (l=Sl ^)) ∈-dangling : ∀ {Γ x A} → Γ ⊢ps x # A → x ∈ Γ ∈-dangling Γ⊢ps = Γ⊢x:A→x∈Γ (psvar Γ⊢ps) ∈-dangling-◃₀ : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃₀ x → a ∈ Γ ∈-dangling-◃₀ Γ⊢ps (◃∂⁻ Γ+⊢x) with unique-type Γ+⊢x (WWpsx Γ⊢ps) idp ... | idp = Γ⊢x:A→x∈Γ (Γ⊢src (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps))) ∈-dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inl (inl a∈Γ)))) = x#A∈Γ→x∈Γ a∈Γ ∈-dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inl (inr (idp , idp))))) with unique-type (psvar Γ⊢ps) (Γ⊢tgt (Γ⊢t:A→Γ⊢A (psvar Γ⊢ps))) idp ... | () ∈-dangling-◃₀ Γ⊢ps (◃∂⁺ (var _ (inr (idp , idp)))) = ⊥-elim (x∉ (psv Γ⊢ps) (n≤n _) (psvar Γ⊢ps)) strengthen-dangling-◃₀ : ∀ {Γ x A a} → (Γ⊢ps : Γ ⊢ps x # A) → Γ++ Γ⊢ps , a ◃₀ x → Γ , a ◃₀ x strengthen-dangling-◃₀ Γ⊢ps a◃₀x = strengthen-◃₀ Γ⊢ps (∈-dangling-◃₀ Γ⊢ps a◃₀x) (∈-dangling Γ⊢ps) a◃₀x -- Not easy to find a way to express in a terminating way pse-◃-elim : ∀ {Γ x A a b} → (Γ⊢ps : Γ ⊢ps x # A) → a ∈ Γ → b ∈ Γ → Γ++ Γ⊢ps , a ◃ b → Γ , a ◃ b pse-◃-elim Γ⊢ps a∈Γ b∈Γ (gen a◃₀b) = gen (strengthen-◃₀ Γ⊢ps a∈Γ b∈Γ a◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T a◃z z◃₀b) with ◃∈ a◃z pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T a◃z z◃₀b) | inl (inl z∈Γ) = ◃T (pse-◃-elim Γ⊢ps a∈Γ z∈Γ a◃z) (strengthen-◃₀ Γ⊢ps z∈Γ b∈Γ z◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T (gen a◃₀l) l◃₀b) | inl (inr idp) with ◃₀-dangling-tgt Γ⊢ps a◃₀l ... | inl idp = ⊥-elim (l∉ (psv Γ⊢ps) (n≤Sn _) a∈Γ) ... | inr a◃₀x = ◃T (gen (strengthen-◃₀ Γ⊢ps a∈Γ (∈-dangling Γ⊢ps) a◃₀x)) (strengthen-◃₀-dangling Γ⊢ps l◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T (◃T a◃z z◃₀l) l◃₀b) | inl (inr idp) with ◃₀-dangling-tgt Γ⊢ps z◃₀l ... | inr z◃₀x = ◃T (◃T (pse-◃-elim Γ⊢ps a∈Γ (∈-dangling-◃₀ Γ⊢ps z◃₀x) a◃z) (strengthen-dangling-◃₀ Γ⊢ps z◃₀x)) (strengthen-◃₀-dangling Γ⊢ps l◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T (◃T (gen a◃₀Sl) Sl◃₀l) l◃₀b) | inl (inr idp) | inl idp with ◃₀-dangling Γ⊢ps a◃₀Sl ... | idp = gen (strengthen-◃₀-dangling Γ⊢ps l◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T (◃T (◃T a◃z z◃₀Sl) Sl◃₀l) l◃₀b) | inl (inr idp) | inl idp with ◃₀-dangling Γ⊢ps z◃₀Sl ... | idp = ◃T (pse-◃-elim Γ⊢ps a∈Γ (∈-dangling Γ⊢ps) a◃z) (strengthen-◃₀-dangling Γ⊢ps l◃₀b) pse-◃-elim Γ⊢ps a∈Γ b∈Γ (◃T a◃z z◃₀b) | inr idp with dangling-◃₀ Γ⊢ps z◃₀b ... | idp = ⊥-elim (l∉ (psv Γ⊢ps) (n≤n _) b∈Γ) psx-◃-linear← : ∀ {Γ z A} → Γ ⊢ps z # A → (∀ x → x ∈ Γ → ¬ (Γ , x ◃ x)) psx-◃-linear← pss .0 (inr idp) x◃x = 𝔻0-◃ 0 x◃x psx-◃-linear← (psd Γ⊢psz) x x∈Γ x◃x = psx-◃-linear← Γ⊢psz x x∈Γ x◃x psx-◃-linear← (pse Γ⊢psz idp idp idp idp idp) x (inl (inl x∈Γ)) x◃x = psx-◃-linear← Γ⊢psz x x∈Γ (pse-◃-elim Γ⊢psz x∈Γ x∈Γ x◃x) psx-◃-linear← Γ+⊢ps@(pse Γ⊢psz idp idp idp idp idp) x (inl (inr idp)) x◃x = ⊥-elim (Sn≰n _ (⟿dim (var (psv Γ+⊢ps) (inl (inr (idp , idp)))) (var (psv Γ+⊢ps) (inl (inr (idp , idp)))) (⊢psx-◃→⟿+ Γ+⊢ps (∂⁺⟿ (psvar Γ+⊢ps)) x◃x))) psx-◃-linear← Γ+⊢ps@(pse Γ⊢psz idp idp idp idp idp) x (inr idp) x◃x = ⊥-elim (Sn≰n _ (⟿dim (psvar Γ+⊢ps) (psvar Γ+⊢ps) (⊢psx-◃→⟿ Γ+⊢ps x◃x))) ◃-linear : Pre-Ctx → Set₁ ◃-linear Γ = ∀ x y → x ∈ Γ → y ∈ Γ → (x ≠ y) ↔ ((Γ , x ◃ y) + (Γ , y ◃ x)) ps-◃-linear : ∀ Γ → Γ ⊢ps → ◃-linear Γ fst (ps-◃-linear Γ (ps Γ⊢psz) x y x∈Γ y∈Γ) x≠y with psx-◃-linear→ Γ⊢psz x y x∈Γ y∈Γ ... | inl H = H ... | inr x=y = ⊥-elim (x≠y x=y) snd (ps-◃-linear Γ (ps Γ⊢psz) x .x x∈Γ y∈Γ) (inl x◃x) idp = psx-◃-linear← Γ⊢psz x x∈Γ x◃x snd (ps-◃-linear Γ (ps Γ⊢psz) x .x x∈Γ y∈Γ) (inr x◃x) idp = psx-◃-linear← Γ⊢psz x x∈Γ x◃x
61.744262
226
0.474405
35d6c44ec84407af93f13c7e2a7ebe894877c686
3,407
agda
Agda
src/Categories/Category/Monoidal/Closed/IsClosed/Identity.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Monoidal/Closed/IsClosed/Identity.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Monoidal/Closed/IsClosed/Identity.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} -- There are really all 'private' sub-pieces of -- Categories.Category.Monoidal.Closed.IsClosed, but that is taking -- forever to typecheck, so the idea is to split things into pieces and -- hope that that will help. open import Categories.Category using (Category) open import Categories.Category.Monoidal open import Categories.Category.Monoidal.Closed using (Closed) module Categories.Category.Monoidal.Closed.IsClosed.Identity {o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (Cl : Closed M) where open import Function using (_$_) renaming (_∘_ to _∙_) open import Categories.Category.Monoidal.Utilities M open import Categories.Morphism C using (Iso) open import Categories.Morphism.Properties C using (Iso-resp-≈) open import Categories.Morphism.Reasoning C using (pullʳ; pullˡ; pushˡ; cancelʳ) open import Categories.Functor using (Functor) renaming (id to idF) open import Categories.Functor.Bifunctor open import Categories.Functor.Bifunctor.Properties open import Categories.NaturalTransformation hiding (id) open import Categories.NaturalTransformation.Dinatural using (Extranaturalʳ; extranaturalʳ; DinaturalTransformation) open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism) import Categories.Category.Closed as Cls open Closed Cl open Category C -- most of it is used open HomReasoning open adjoint renaming (unit to η; counit to ε; Ladjunct to 𝕃) private λ⇒ = unitorˡ.from λ⇐ = unitorˡ.to ρ⇒ = unitorʳ.from ρ⇐ = unitorʳ.to identity : NaturalIsomorphism idF [ unit ,-] identity = record { F⇒G = F∘id⇒F ∘ᵥ ([ unit ,-] ∘ˡ (unitorʳ-natural.F⇒G)) ∘ᵥ η ; F⇐G = ε ∘ᵥ (unitorʳ-natural.F⇐G ∘ʳ [ unit ,-]) ∘ᵥ F⇒id∘F ; iso = λ X → Iso-resp-≈ (iso X) (⟺ identityˡ) (⟺ (∘-resp-≈ʳ identityʳ)) } where open Functor iso : ∀ X → Iso (𝕃 unitorʳ.from) (ε.η X ∘ unitorʳ.to) iso X = record { isoˡ = begin (ε.η X ∘ ρ⇐) ∘ 𝕃 ρ⇒ ≈⟨ pullʳ unitorʳ-commute-to ⟩ ε.η X ∘ 𝕃 ρ⇒ ⊗₁ id ∘ ρ⇐ ≈⟨ sym-assoc ⟩ Radjunct (𝕃 ρ⇒) ∘ ρ⇐ ≈⟨ RLadjunct≈id ⟩∘⟨refl ⟩ ρ⇒ ∘ ρ⇐ ≈⟨ unitorʳ.isoʳ ⟩ id ∎ ; isoʳ = begin 𝕃 ρ⇒ ∘ ε.η X ∘ ρ⇐ ≈⟨ pullʳ (η.commute _) ⟩ [ id , ρ⇒ ]₁ ∘ 𝕃 ((ε.η X ∘ ρ⇐) ⊗₁ id) ≈˘⟨ pushˡ (homomorphism [ unit ,-]) ⟩ 𝕃 (ρ⇒ ∘ (ε.η X ∘ ρ⇐) ⊗₁ id) ≈⟨ F-resp-≈ [ unit ,-] unitorʳ-commute-from ⟩∘⟨refl ⟩ 𝕃 ((ε.η X ∘ ρ⇐) ∘ ρ⇒) ≈⟨ F-resp-≈ [ unit ,-] (cancelʳ unitorʳ.isoˡ) ⟩∘⟨refl ⟩ 𝕃 (ε.η X) ≈⟨ zag ⟩ id ∎ } module identity = NaturalIsomorphism identity diagonal : Extranaturalʳ unit [-,-] diagonal = extranaturalʳ (λ X → 𝕃 λ⇒) $ λ {X Y f} → begin [ id , f ]₁ ∘ 𝕃 λ⇒ ≈˘⟨ pushˡ (homomorphism [ X ,-]) ⟩ [ id , f ∘ λ⇒ ]₁ ∘ η.η unit ≈˘⟨ F-resp-≈ [ X ,-] unitorˡ-commute-from ⟩∘⟨refl ⟩ [ id , λ⇒ ∘ id ⊗₁ f ]₁ ∘ η.η unit ≈⟨ homomorphism [ X ,-] ⟩∘⟨refl ⟩ ([ id , λ⇒ ]₁ ∘ [ id , id ⊗₁ f ]₁) ∘ η.η unit ≈⟨ pullʳ (mate.commute₁ f) ⟩ [ id , λ⇒ ]₁ ∘ [ f , id ]₁ ∘ η.η unit ≈⟨ pullˡ [ [-,-] ]-commute ⟩ ([ f , id ]₁ ∘ [ id , λ⇒ ]₁) ∘ η.η unit ≈⟨ assoc ⟩ [ f , id ]₁ ∘ 𝕃 λ⇒ ∎ where open Functor module diagonal = DinaturalTransformation diagonal
41.048193
102
0.583505
0de54236b8ba51446fac242ff8278f8c0d0efd68
680
agda
Agda
src/slots/test.agda
semenov-vladyslav/slots-agda
86d777ade14f63032c46bd168b76ac60d6bdf9b9
[ "MIT" ]
null
null
null
src/slots/test.agda
semenov-vladyslav/slots-agda
86d777ade14f63032c46bd168b76ac60d6bdf9b9
[ "MIT" ]
null
null
null
src/slots/test.agda
semenov-vladyslav/slots-agda
86d777ade14f63032c46bd168b76ac60d6bdf9b9
[ "MIT" ]
null
null
null
module slots.test where open import slots.imports open import slots.defs using (config ; game) open import slots.bruteforce using (rtp) c : config c = record { n = 3 ; m = 4 } g : game c g = record { reels = reels ; winTable = winTable } where open config c reel : Reel reel = # 1 ∷ # 1 ∷ # 1 ∷ # 0 ∷ [] reel′ : Reel reel′ = # 1 ∷ # 1 ∷ # 2 ∷ # 0 ∷ [] reel″ : Reel reel″ = # 1 ∷ # 3 ∷ # 1 ∷ # 0 ∷ [] reels : Reels reels = reel ∷ reel′ ∷ reel″ ∷ [] winTable : WinTable winTable = (0 ∷ 0 ∷ 0 ∷ []) ∷ (0 ∷ 1 ∷ 2 ∷ []) ∷ (0 ∷ 0 ∷ 0 ∷ []) ∷ (0 ∷ 0 ∷ 0 ∷ []) ∷ [] % : ℕ × ℕ % = rtp g %-prf : % ≡ (36 , 64) %-prf = refl
16.190476
56
0.460294
115ce55a06e2e614ed2670dce7fc24ddbf032672
4,453
agda
Agda
Integer/Properties.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
Integer/Properties.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
Integer/Properties.agda
onestruggler/EucDomain
7e268e8354065fde734c9c2d9998d2cfd4a21f71
[ "CC0-1.0" ]
null
null
null
-- Some extra properties of integers. {-# OPTIONS --without-K --safe #-} module Integer.Properties where -- imports from stdlib. open import Relation.Nullary using (¬_) open import Relation.Binary.PropositionalEquality as PE using (_≡_ ; refl ; sym ; cong ; trans ; cong₂) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Data.Product as P using (_×_ ; _,_ ; ∃ ; proj₁ ; proj₂) open import Data.Nat as Nat using (ℕ ; suc ; zero ; z≤n) import Data.Nat.Solver as NS open import Data.Integer as Int using (ℤ ; ∣_∣ ; +_ ; +[1+_] ; -[1+_] ; 1ℤ ; +<+ ; -<- ; -≤- ; -<+ ; -≤+ ; +≤+ ; 0ℤ ; NonNegative ; +0) import Data.Integer.Properties as IntP open import Function -- imports from local. open import Instances -- Triangle equality. tri-eq : ∀ (a b : ℤ) .{{_ : NonNegative a}} .{{_ : NonNegative b}} -> ∣ a + b ∣ ≡ ∣ a ∣ + ∣ b ∣ tri-eq (+_ a) (+_ b) = begin ∣ + a + + b ∣ ≡⟨ refl ⟩ ∣ + (a + b) ∣ ≡⟨ refl ⟩ a + b ≡⟨ refl ⟩ ∣ + a ∣ + ∣ + b ∣ ∎ where open PE.≡-Reasoning -- For all a, a * a is always non-negative. a*a=+b : ∀ a -> ∃ λ b → a * a ≡ + b a*a=+b (+_ a) = (a * a) , IntP.pos-distrib-* a a a*a=+b (-[1+_] a) = suc a * suc a , refl 0≤a*a : ∀ {a} → 0ℤ ≤ a * a 0≤a*a {a} rewrite proj₂ $ a*a=+b a = +≤+ Nat.z≤n -- For non-zero natrual number a, a * a is always positive. a*a-pos : ∀ (a : ℕ) .{{_ : Nat.NonZero a}} -> ∃ λ n → a * a ≡ suc n a*a-pos (suc b) = b * b + 2 * b , claim where claim : suc b * suc b ≡ suc (b * b + 2 * b) claim = begin suc b * suc b ≡⟨ refl ⟩ (1 + b) * (1 + b) ≡⟨ solve 1 (λ b → (con 1 :+ b) :* (con 1 :+ b) := con 1 :+ (b :* b :+ con 2 :* b)) refl b ⟩ 1 + (b * b + 2 * b) ≡⟨ refl ⟩ suc (b * b + 2 * b) ∎ where open NS.+-*-Solver open PE.≡-Reasoning a*a-pos' : ∀ (a : ℤ) .{{_ : NonZero a}} -> ∃ λ n → a * a ≡ + (suc n) a*a-pos' +[1+ n ] rewrite proj₂ $ a*a-pos (suc n) = (proj₁ $ a*a-pos (suc n)) , refl a*a-pos' -[1+ n ] rewrite proj₂ $ a*a-pos (suc n) = (proj₁ $ a*a-pos (suc n)) , refl -- For an non-zero integer a, ∣ a * a ∣ is always positive. ∣a*a∣-pos : ∀ (a : ℤ) .{{_ : NonZero a}} -> ∃ λ n → ∣ a * a ∣ ≡ suc n ∣a*a∣-pos (+ (suc b)) = b * b + 2 * b , claim where claim : suc b * suc b ≡ suc (b * b + 2 * b) claim = proj₂ $ a*a-pos (suc b) ∣a*a∣-pos (-[1+_] b) = b * b + 2 * b , claim where claim : suc b * suc b ≡ suc (b * b + 2 * b) claim = proj₂ $ a*a-pos (suc b) +∣a*a∣=a*a : ∀ (a : ℤ) -> + ∣ a * a ∣ ≡ a * a +∣a*a∣=a*a a = IntP.0≤i⇒+∣i∣≡i (0≤a*a {a}) pos : ∀ {a : ℤ} -> ¬ a ≡ 0ℤ -> 0ℤ < a * a pos {+_ zero} n0 with n0 refl ... | () pos {a@(+[1+ n ])} n0 rewrite proj₂ $ a*a-pos' a = +<+ (Nat.s≤s Nat.z≤n) pos {a@(-[1+ n ])} n0 rewrite proj₂ $ a*a-pos' a = +<+ (Nat.s≤s Nat.z≤n) pos' : ∀ {a} -> 0ℤ < a -> Nat.NonZero ∣ a ∣ pos' {(+_ zero)} (+<+ ()) pos' {+[1+ n ]} l = record { nonZero = _ } -- ∣ a * a + b * b ∣ is not zero if one of a and b is. ∣aa+bb∣-nonzero : ∀ a b -> ¬ a ≡ 0ℤ ⊎ ¬ b ≡ 0ℤ -> Nat.NonZero ∣ a * a + b * b ∣ ∣aa+bb∣-nonzero a b (inj₁ x) = pos' (IntP.+-mono-<-≤ (pos x) (0≤a*a {b})) ∣aa+bb∣-nonzero a b (inj₂ y) = pos' (IntP.+-mono-≤-< (0≤a*a {a}) (pos y)) -- ---------------------------------------------------------------------- -- Properties of aa + bb -- A special case of tri-eq. tri-eq' : ∀ a b -> ∣ a * a + b * b ∣ ≡ ∣ a * a ∣ + ∣ b * b ∣ tri-eq' a b = begin let (sa , sae) = (a*a=+b a) in let (sb , sbe) = a*a=+b b in ∣ a * a + b * b ∣ ≡⟨ cong (λ x → ∣ x ∣) (cong₂ _+_ sae sbe) ⟩ ∣ + sa + + sb ∣ ≡⟨ (tri-eq (+ sa) (+ sb)) ⟩ ∣ + sa ∣ + ∣ + sb ∣ ≡⟨ cong₂ _+_ (cong ∣_∣ (sym sae)) (cong ∣_∣ (sym sbe)) ⟩ ∣ a * a ∣ + ∣ b * b ∣ ∎ where open PE.≡-Reasoning -- A property of a pair of integers. a=0×b=0⇒aa+bb=0 : ∀ {a b : ℤ} -> a ≡ 0ℤ × b ≡ 0ℤ -> a * a + b * b ≡ 0ℤ a=0×b=0⇒aa+bb=0 {.0ℤ} {.0ℤ} (refl , refl) = refl aa+bb=0⇒a=0×b=0 : ∀ {a b : ℤ} -> a * a + b * b ≡ 0ℤ -> a ≡ 0ℤ × b ≡ 0ℤ aa+bb=0⇒a=0×b=0 {a} {b} eq = P.map x^2=0⇒x=0 x^2=0⇒x=0 $ z+z (0≤a*a {a}) (0≤a*a {b}) eq where z+z : ∀ {x y} -> 0ℤ ≤ x -> 0ℤ ≤ y -> x + y ≡ 0ℤ -> x ≡ 0ℤ × y ≡ 0ℤ z+z {.+0} {.(+ _)} (+≤+ {n = zero} z≤n) (+≤+ z≤n) x+y=0 = (refl , x+y=0) z+z {.(+[1+ n ])} {.+0} (+≤+ {n = ℕ.suc n} z≤n) (+≤+ {n = zero} m≤n) () z+z {.(+[1+ n ])} {.(+[1+ n₁ ])} (+≤+ {n = ℕ.suc n} z≤n) (+≤+ {n = ℕ.suc n₁} m≤n) () x^2=0⇒x=0 : ∀ {x} -> x * x ≡ 0ℤ -> x ≡ 0ℤ x^2=0⇒x=0 {+_ zero} eq = refl
36.5
118
0.442398
7cae20fc840a4d2c20b3b6e1c55e8f4b426807c7
990
agda
Agda
Cubical/Structures/Parameterized.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Parameterized.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
null
null
null
Cubical/Structures/Parameterized.agda
RobertHarper/cubical
d13941587a58895b65f714f1ccc9c1f5986b109c
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{- A parameterized family of structures S can be combined into a single structure: X ↦ (a : A) → S a X -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Structures.Parameterized where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Functions.FunExtEquiv open import Cubical.Foundations.SIP module _ {ℓ ℓ₁ ℓ₂} (A : Type ℓ) where ParamStructure : (S : A → Type ℓ₁ → Type ℓ₂) → Type ℓ₁ → Type (ℓ-max ℓ ℓ₂) ParamStructure S X = (a : A) → S a X ParamEquivStr : {S : A → Type ℓ₁ → Type ℓ₂} {ℓ₃ : Level} → (∀ a → StrEquiv (S a) ℓ₃) → StrEquiv (ParamStructure S) (ℓ-max ℓ ℓ₃) ParamEquivStr ι (X , l) (Y , m) e = ∀ a → ι a (X , l a) (Y , m a) e ParamUnivalentStr : {S : A → Type ℓ₁ → Type ℓ₂} {ℓ₃ : Level} (ι : ∀ a → StrEquiv (S a) ℓ₃) (θ : ∀ a → UnivalentStr (S a) (ι a)) → UnivalentStr (ParamStructure S) (ParamEquivStr ι) ParamUnivalentStr ι θ e = compEquiv (equivPi λ a → θ a e) funExtEquiv
34.137931
79
0.644444
ed034c09c4e1dea0c6db09bebe869c0ba393c159
8,032
agda
Agda
Cubical/Algebra/RingSolver/RawAlgebra.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Algebra/RingSolver/RawAlgebra.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Algebra/RingSolver/RawAlgebra.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.RingSolver.RawAlgebra where open import Cubical.Foundations.Prelude open import Cubical.Data.Sigma open import Cubical.Data.Nat using (ℕ) open import Cubical.Algebra.RingSolver.AlmostRing hiding (⟨_⟩) open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ) open import Cubical.Algebra.RingSolver.IntAsRawRing public open import Cubical.Algebra.RingSolver.CommRingAsAlmostRing open import Cubical.Algebra.CommRing open import Cubical.Algebra.Ring open import Cubical.Data.Int.Properties using (+-assoc; +-comm; pos0+; sucPred) renaming (-_ to -ℤ_; _+_ to _+ℤ_; _·_ to _·ℤ_) private variable ℓ ℓ′ : Level record RawAlgebra (R : RawRing ℓ) (ℓ′ : Level) : Type (ℓ-suc (ℓ-max ℓ ℓ′)) where constructor rawalgebra field Carrier : Type ℓ′ scalar : ⟨ R ⟩ᵣ → Carrier 0r : Carrier 1r : Carrier _+_ : Carrier → Carrier → Carrier _·_ : Carrier → Carrier → Carrier -_ : Carrier → Carrier infixl 8 _·_ infixl 7 -_ infixl 6 _+_ ⟨_⟩ : {R : RawRing ℓ} → RawAlgebra R ℓ′ → Type ℓ′ ⟨_⟩ = RawAlgebra.Carrier {- Mapping to integer scalars and its (homorphism) properties. -} module _ (R : CommRing ℓ) where open CommRingStr (snd R) open Cubical.Algebra.Ring.RingTheory (CommRing→Ring R) scalarℕ : ℕ → (fst R) scalarℕ ℕ.zero = 0r scalarℕ (ℕ.suc ℕ.zero) = 1r scalarℕ (ℕ.suc (ℕ.suc n)) = 1r + scalarℕ (ℕ.suc n) scalar : ℤ → (fst R) scalar (pos k) = scalarℕ k scalar (negsuc k) = - scalarℕ (ℕ.suc k) -DistScalar : (k : ℤ) → scalar (-ℤ k) ≡ - (scalar k) -DistScalar (pos ℕ.zero) = sym 0Selfinverse -DistScalar (pos (ℕ.suc n)) = refl -DistScalar (negsuc n) = sym (-Idempotent _) lemmaSuc : (k : ℤ) → scalar (sucInt k) ≡ 1r + scalar k lemmaSuc (pos ℕ.zero) = sym (+Rid _) lemmaSuc (pos (ℕ.suc ℕ.zero)) = refl lemmaSuc (pos (ℕ.suc (ℕ.suc n))) = refl lemmaSuc (negsuc ℕ.zero) = sym (+Rinv _) lemmaSuc (negsuc (ℕ.suc n)) = scalar (negsuc n) ≡⟨ sym (+Lid (scalar (negsuc n))) ⟩ 0r + scalar (negsuc n) ≡[ i ]⟨ +Rinv 1r (~ i) + scalar (negsuc n) ⟩ (1r - 1r) + scalar (negsuc n) ≡⟨ sym (+Assoc _ _ _) ⟩ 1r + (- 1r + - scalar (pos (ℕ.suc n))) ≡[ i ]⟨ 1r + -Dist 1r (scalar (pos (ℕ.suc n))) i ⟩ 1r + -(1r + scalar (pos (ℕ.suc n))) ≡⟨ refl ⟩ 1r + -(scalar (pos (ℕ.suc (ℕ.suc n)))) ≡⟨ refl ⟩ 1r + scalar (negsuc (ℕ.suc n)) ∎ lemmaPred : (k : ℤ) → scalar (predInt k) ≡ - 1r + scalar k lemmaPred k = sym( - 1r + scalar k ≡[ i ]⟨ - 1r + scalar (sucPred k (~ i)) ⟩ - 1r + scalar (sucInt (predInt k)) ≡[ i ]⟨ - 1r + lemmaSuc (predInt k) i ⟩ - 1r + (1r + scalar (predInt k)) ≡⟨ +Assoc _ _ _ ⟩ (- 1r + 1r) + scalar (predInt k) ≡[ i ]⟨ +Linv 1r i + scalar (predInt k) ⟩ 0r + scalar (predInt k) ≡⟨ +Lid _ ⟩ scalar (predInt k) ∎) +HomScalar : (k l : ℤ) → scalar (k +ℤ l) ≡ (scalar k) + (scalar l) +HomScalar (pos ℕ.zero) l = scalar (0 +ℤ l) ≡[ i ]⟨ scalar (sym (pos0+ l) i) ⟩ scalar l ≡⟨ sym (+Lid _) ⟩ 0r + scalar l ≡⟨ refl ⟩ scalar 0 + scalar l ∎ +HomScalar (pos (ℕ.suc ℕ.zero)) l = scalar (1 +ℤ l) ≡[ i ]⟨ scalar (+-comm 1 l i) ⟩ scalar (l +ℤ 1) ≡⟨ refl ⟩ scalar (sucInt l) ≡⟨ lemmaSuc l ⟩ 1r + scalar l ≡⟨ refl ⟩ scalar (pos (ℕ.suc ℕ.zero)) + scalar l ∎ +HomScalar (pos (ℕ.suc (ℕ.suc n))) l = scalar (pos (ℕ.suc (ℕ.suc n)) +ℤ l) ≡⟨ refl ⟩ scalar ((pos (ℕ.suc n) +ℤ 1) +ℤ l) ≡[ i ]⟨ scalar ((+-comm (pos (ℕ.suc n)) 1 i) +ℤ l) ⟩ scalar ((1 +ℤ (pos (ℕ.suc n))) +ℤ l) ≡[ i ]⟨ scalar (+-assoc 1 (pos (ℕ.suc n)) l (~ i)) ⟩ scalar (1 +ℤ (pos (ℕ.suc n) +ℤ l)) ≡⟨ +HomScalar (pos (ℕ.suc ℕ.zero)) (pos (ℕ.suc n) +ℤ l) ⟩ scalar 1 + scalar (pos (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩ 1r + (scalar (pos (ℕ.suc n) +ℤ l)) ≡[ i ]⟨ 1r + +HomScalar (pos (ℕ.suc n)) l i ⟩ 1r + (scalar (pos (ℕ.suc n)) + scalar l) ≡⟨ +Assoc _ _ _ ⟩ (1r + scalar (pos (ℕ.suc n))) + scalar l ≡⟨ refl ⟩ scalar (pos (ℕ.suc (ℕ.suc n))) + scalar l ∎ +HomScalar (negsuc ℕ.zero) l = scalar (-1 +ℤ l) ≡[ i ]⟨ scalar (+-comm -1 l i) ⟩ scalar (l +ℤ -1) ≡⟨ refl ⟩ scalar (predInt l) ≡⟨ lemmaPred l ⟩ - 1r + scalar l ≡⟨ refl ⟩ scalar -1 + scalar l ∎ +HomScalar (negsuc (ℕ.suc n)) l = scalar (negsuc (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩ scalar ((negsuc n +ℤ -1) +ℤ l) ≡[ i ]⟨ scalar (+-comm (negsuc n) -1 i +ℤ l) ⟩ scalar ((-1 +ℤ negsuc n) +ℤ l) ≡[ i ]⟨ scalar (+-assoc -1 (negsuc n) l (~ i)) ⟩ scalar (-1 +ℤ (negsuc n +ℤ l)) ≡⟨ +HomScalar -1 (negsuc n +ℤ l) ⟩ - 1r + scalar (negsuc n +ℤ l) ≡[ i ]⟨ - 1r + +HomScalar (negsuc n) l i ⟩ - 1r + (scalar (negsuc n) + scalar l) ≡⟨ +Assoc (- 1r) _ _ ⟩ (- 1r + (scalar (negsuc n))) + scalar l ≡⟨ refl ⟩ (- 1r + - scalar (pos (ℕ.suc n))) + scalar l ≡[ i ]⟨ -Dist 1r (scalar (pos (ℕ.suc n))) i + scalar l ⟩ (- (1r + scalar (pos (ℕ.suc n)))) + scalar l ≡⟨ refl ⟩ scalar (negsuc (ℕ.suc n)) + scalar l ∎ lemma1 : (n : ℕ) → 1r + scalar (pos n) ≡ scalar (pos (ℕ.suc n)) lemma1 ℕ.zero = +Rid _ lemma1 (ℕ.suc k) = refl lemma-1 : (n : ℕ) → - 1r + scalar (negsuc n) ≡ scalar (negsuc (ℕ.suc n)) lemma-1 ℕ.zero = -Dist _ _ lemma-1 (ℕ.suc k) = - 1r + scalar (negsuc (ℕ.suc k)) ≡⟨ refl ⟩ - 1r + - scalar (pos (ℕ.suc (ℕ.suc k))) ≡⟨ -Dist _ _ ⟩ - (1r + scalar (pos (ℕ.suc (ℕ.suc k)))) ≡⟨ refl ⟩ scalar (negsuc (ℕ.suc (ℕ.suc k))) ∎ ·HomScalar : (k l : ℤ) → scalar (k ·ℤ l) ≡ scalar k · scalar l ·HomScalar (pos ℕ.zero) l = 0r ≡⟨ sym (0LeftAnnihilates (scalar l)) ⟩ 0r · scalar l ∎ ·HomScalar (pos (ℕ.suc n)) l = scalar (l +ℤ (pos n ·ℤ l)) ≡⟨ +HomScalar l (pos n ·ℤ l) ⟩ scalar l + scalar (pos n ·ℤ l) ≡[ i ]⟨ scalar l + ·HomScalar (pos n) l i ⟩ scalar l + (scalar (pos n) · scalar l) ≡[ i ]⟨ ·Lid (scalar l) (~ i) + (scalar (pos n) · scalar l) ⟩ 1r · scalar l + (scalar (pos n) · scalar l) ≡⟨ sym (·Ldist+ 1r _ _) ⟩ (1r + scalar (pos n)) · scalar l ≡[ i ]⟨ lemma1 n i · scalar l ⟩ scalar (pos (ℕ.suc n)) · scalar l ∎ ·HomScalar (negsuc ℕ.zero) l = scalar (-ℤ l) ≡⟨ -DistScalar l ⟩ - scalar l ≡[ i ]⟨ - (·Lid (scalar l) (~ i)) ⟩ - (1r · scalar l) ≡⟨ sym (-DistL· _ _) ⟩ - 1r · scalar l ≡⟨ refl ⟩ scalar (negsuc ℕ.zero) · scalar l ∎ ·HomScalar (negsuc (ℕ.suc n)) l = scalar ((-ℤ l) +ℤ (negsuc n ·ℤ l)) ≡⟨ +HomScalar (-ℤ l) (negsuc n ·ℤ l) ⟩ scalar (-ℤ l) + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ -DistScalar l i + scalar (negsuc n ·ℤ l) ⟩ - scalar l + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ - scalar l + ·HomScalar (negsuc n) l i ⟩ - scalar l + scalar (negsuc n) · scalar l ≡[ i ]⟨ (- ·Lid (scalar l) (~ i)) + scalar (negsuc n) · scalar l ⟩ - (1r · scalar l) + scalar (negsuc n) · scalar l ≡[ i ]⟨ -DistL· 1r (scalar l) (~ i) + scalar (negsuc n) · scalar l ⟩ - 1r · scalar l + scalar (negsuc n) · scalar l ≡⟨ sym (·Ldist+ _ _ _) ⟩ (- 1r + scalar (negsuc n)) · scalar l ≡[ i ]⟨ lemma-1 n i · scalar l ⟩ scalar (negsuc (ℕ.suc n)) · scalar l ∎ CommRing→RawℤAlgebra : CommRing ℓ → RawAlgebra ℤAsRawRing ℓ CommRing→RawℤAlgebra (R , commringstr 0r 1r _+_ _·_ -_ isCommRing) = rawalgebra R (scalar ((R , commringstr 0r 1r _+_ _·_ -_ isCommRing))) 0r 1r _+_ _·_ -_
44.375691
109
0.492903
4e439e1d2e4594da5ecbb14fb1e15ca3c456b465
4,913
agda
Agda
models/Containers.agda
dataronio/epigram2
17b7858f51a35b3becb8433028c3f1ba25fbba9a
[ "MIT" ]
48
2016-01-09T17:36:19.000Z
2022-02-11T01:55:28.000Z
models/Containers.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
null
null
null
models/Containers.agda
seanwallawalla-forks/Epigram
a2064e63786cc8004cfc9ac7a0c89c2936f0b797
[ "MIT" ]
12
2016-08-14T21:36:35.000Z
2022-02-11T01:57:40.000Z
{-# OPTIONS --type-in-type --no-termination-check #-} module Containers where record Sigma (A : Set) (B : A -> Set) : Set where field fst : A snd : B fst open Sigma _*_ : (A B : Set) -> Set A * B = Sigma A \_ -> B data Zero : Set where record One : Set where data PROP : Set where Absu : PROP Triv : PROP _/\_ : PROP -> PROP -> PROP All : (S : Set) -> (S -> PROP) -> PROP Prf : PROP -> Set Prf Absu = Zero Prf Triv = One Prf (P /\ Q) = Prf P * Prf Q Prf (All S P) = (x : S) -> Prf (P x) _,_ : forall {A B} -> (a : A) -> B a -> Sigma A B a , b = record { fst = a ; snd = b } split : ∀ {A B} {C : Sigma A B -> Set} -> (f : (a : A) -> (b : B a) -> C (a , b)) -> (ab : Sigma A B) -> C ab split f ab = f (fst ab) (snd ab) data _+_ (A B : Set) : Set where l : A -> A + B r : B -> A + B cases : ∀ {A B} {C : A + B -> Set} -> ((a : A) -> C (l a)) -> ((b : B) -> C (r b)) -> (ab : A + B) -> C ab cases f g (l a) = f a cases f g (r b) = g b rearrange : ∀ {A B X} (C : A → Set) (D : B → Set) (f : Sigma A C → X) → Sigma (A + B) (cases C D) → X + Sigma B D rearrange {A} {B} {X} C D f = split {A + B} (cases (\a c → l (f (a , c))) (\b d → r (b , d))) data CON (I : Set) : Set where ?? : I -> CON I PrfC : PROP -> CON I _*C_ : CON I -> CON I -> CON I PiC : (S : Set) -> (S -> CON I) -> CON I SiC : (S : Set) -> (S -> CON I) -> CON I MuC : (O : Set) -> (O -> CON (I + O)) -> O -> CON I mutual data Mu {I : Set} (O : Set) (D : O -> CON (I + O)) (X : I -> Set) : O -> Set where inm : {o : O} -> [| D o |] (cases X (Mu O D X)) -> Mu O D X o [|_|]_ : {I : Set} -> (CON I) -> (I -> Set) -> Set [| ?? i |] X = X i [| PrfC p |] X = Prf p [| C *C D |] X = [| C |] X * [| D |] X [| PiC S C |] X = (s : S) -> [| C s |] X [| SiC S C |] X = Sigma S \s -> [| C s |] X [| MuC O C o |] X = Mu O C X o outm : {I O : Set} {D : O -> CON (I + O)} {X : I -> Set} {o : O} -> Mu O D X o -> [| D o |] (cases X (Mu O D X)) outm (inm x) = x Everywhere : {I : Set} -> (D : CON I) -> (J : I -> Set) -> (X : Set) -> (Sigma I J -> X) -> [| D |] J -> CON X Everywhere (?? i) J X c t = ?? (c (i , t)) Everywhere (PrfC p) J X c t = PrfC Triv Everywhere (C *C D) J X c t = Everywhere C J X c (fst t) *C Everywhere D J X c (snd t) Everywhere (PiC S C) J X c t = PiC S (\s -> Everywhere (C s) J X c (t s)) Everywhere (SiC S C) J X c t = Everywhere (C (fst t)) J X c (snd t) Everywhere (MuC O C o) J X c t = MuC (Sigma O (Mu O C J)) (\ot' -> Everywhere (C (fst ot')) (cases J (Mu O C J)) (X + (Sigma O (Mu O C J))) (split (cases(\i j -> l (c (i , j))) (\o'' t'' -> r (o'' , t'')))) (outm (snd ot'))) (o , t) everywhere : {I : Set} -> (D : CON I) -> (J : I -> Set) -> (X : Set) -> (c : Sigma I J -> X) -> (Y : X -> Set) -> (f : (ij : Sigma I J) -> Y (c ij)) -> (t : [| D |] J) -> [| Everywhere D J X c t |] Y everywhere (?? i) J X c Y f t = f (i , t) everywhere (PrfC p) J X c Y f t = _ everywhere (C *C D) J X c Y f t = everywhere C J X c Y f (fst t) , everywhere D J X c Y f (snd t) everywhere (PiC S C) J X c Y f t = \s -> everywhere (C s) J X c Y f (t s) everywhere (SiC S C) J X c Y f t = everywhere (C (fst t)) J X c Y f (snd t) everywhere (MuC O C o) J X c Y f (inm t) = inm (everywhere (C o) (cases J (Mu O C J)) (X + Sigma O (Mu O C J)) ( (split (cases (\i j -> l (c (i , j))) (\o t -> r (o , t))))) (cases Y (split \o'' t'' -> [| Everywhere (MuC O C o'') J X c t'' |] Y)) (split (cases (\i j -> f (i , j)) (\o'' t'' -> everywhere (MuC O C o'') J X c Y f t''))) t) induction : {I O : Set} (D : O -> CON (I + O)) (J : I -> Set) (X : Set) (c : Sigma I J -> X) (Y : X -> Set) (f : (ij : Sigma I J) -> Y (c ij)) (P : Sigma O (Mu O D J) -> Set) -> ({o : O} (v : [| D o |] cases J (Mu O D J)) -> [| Everywhere (D o) _ (X + Sigma O (Mu O D J)) (split (cases (\i j -> l (c (i , j))) (\o v -> r (o , v)))) v |] cases Y P -> P (o , inm v)) -> (o : O) (v : Mu O D J o) -> P (o , v) induction {I} {O} D J X c Y f P p o (inm v) = p v (everywhere {I + O} (D o) (λ x -> cases {I} {O} {\_ -> Set} J (Mu O D J) x) ((X + Sigma O (Mu O D J))) (rearrange J (Mu O D J) c) (cases Y P) (split {I + O} (cases (\i j -> f (i , j)) (\o v -> induction D J X c Y f P p o v))) v)
37.792308
95
0.38449
36021a5fee36b8b7a58c08dfb540065f391b5421
2,092
agda
Agda
Vec.agda
pigworker/InteriorDesign
454cdd18f56db0b0d1643a1fcf36951b5ece395c
[ "BSD-3-Clause" ]
6
2018-06-18T15:25:39.000Z
2018-07-31T02:00:13.000Z
Vec.agda
pigworker/InteriorDesign
454cdd18f56db0b0d1643a1fcf36951b5ece395c
[ "BSD-3-Clause" ]
null
null
null
Vec.agda
pigworker/InteriorDesign
454cdd18f56db0b0d1643a1fcf36951b5ece395c
[ "BSD-3-Clause" ]
null
null
null
module Vec where open import Basics open import Ix open import All open import Cutting open import Tensor data Vec (X : Set) : Nat -> Set where [] : Vec X zero _,-_ : forall {n} -> X -> Vec X n -> Vec X (suc n) _+V_ : forall {X n m} -> Vec X n -> Vec X m -> Vec X (n +N m) [] +V ys = ys (x ,- xs) +V ys = x ,- (xs +V ys) record Applicative (F : Set -> Set) : Set1 where field pure : {X : Set} -> X -> F X _<*>_ : {S T : Set} -> F (S -> T) -> F S -> F T infixl 2 _<*>_ VecAppl : (n : Nat) -> Applicative \ X -> Vec X n Applicative.pure (VecAppl zero) x = [] Applicative.pure (VecAppl (suc n)) x = x ,- Applicative.pure (VecAppl n) x Applicative._<*>_ (VecAppl .zero) [] [] = [] Applicative._<*>_ (VecAppl .(suc _)) (f ,- fs) (s ,- ss) = f s ,- Applicative._<*>_ (VecAppl _) fs ss module VTRAVERSE {F}(A : Applicative F) where open Applicative A vtraverse : forall {n S T} -> (S -> F T) -> Vec S n -> F (Vec T n) vtraverse f [] = pure [] vtraverse f (s ,- ss) = pure _,-_ <*> f s <*> vtraverse f ss Matrix : Set -> Nat * Nat -> Set Matrix X (i , j) = Vec (Vec X i) j xpose : forall {X ij} -> Matrix X ij -> Matrix X (swap ij) xpose = vtraverse id where open VTRAVERSE (VecAppl _) module VECALL {I : Set}{P : I -> Set}{n : Nat}where open Applicative (VecAppl n) vecAll : {is : List I} -> All (\ i -> Vec (P i) n) is -> Vec (All P is) n vecAll {[]} pss = pure <> vecAll {i ,- is} (ps , pss) = pure _,_ <*> ps <*> vecAll pss VecLiftAlg : (C : I |> I) -> Algebra (Cutting C) P -> Algebra (Cutting C) (\ i -> Vec (P i) n) VecLiftAlg C alg i (c 8>< pss) = pure (alg i << (c 8><_)) <*> vecAll pss open VECALL NatCutVecAlg : {X : Set} -> Algebra (Cutting NatCut) (Vec X) NatCutVecAlg {X} .(m +N n) (m , n , refl .(m +N n) 8>< xm , xn , <>) = xm +V xn open RECTANGLE NatCut2DMatAlg : {X : Set} -> Algebra (Cutting RectCut) (Matrix X) NatCut2DMatAlg _ (inl c 8>< ms) = VecLiftAlg NatCut NatCutVecAlg _ (c 8>< ms) NatCut2DMatAlg _ (inr c 8>< ms) = NatCutVecAlg _ (c 8>< ms)
29.885714
79
0.550191
d1ba4cc0dc5354a2fdeaffb7cea3aff40d4b5a85
2,007
agda
Agda
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/NaturalCoefficients.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/NaturalCoefficients.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/NaturalCoefficients.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Instantiates the ring solver, using the natural numbers as the -- coefficient "ring" ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Algebra import Algebra.Operations.Semiring as SemiringOps open import Data.Maybe.Base using (Maybe; just; nothing; map) module Algebra.Solver.Ring.NaturalCoefficients {r₁ r₂} (R : CommutativeSemiring r₁ r₂) (dec : let open CommutativeSemiring R open SemiringOps semiring in ∀ m n → Maybe (m × 1# ≈ n × 1#)) where import Algebra.Solver.Ring open import Algebra.Solver.Ring.AlmostCommutativeRing open import Data.Nat.Base as ℕ open import Data.Product using (module Σ) open import Function open CommutativeSemiring R open SemiringOps semiring open import Relation.Binary.Reasoning.Setoid setoid private -- The coefficient "ring". ℕ-ring : RawRing _ ℕ-ring = record { Carrier = ℕ ; _+_ = ℕ._+_ ; _*_ = ℕ._*_ ; -_ = id ; 0# = 0 ; 1# = 1 } -- There is a homomorphism from ℕ to R. -- -- Note that _×′_ is used rather than _×_. If _×_ were used, then -- Function.Related.TypeIsomorphisms.test would fail to type-check. homomorphism : ℕ-ring -Raw-AlmostCommutative⟶ fromCommutativeSemiring R homomorphism = record { ⟦_⟧ = λ n → n ×′ 1# ; +-homo = ×′-homo-+ 1# ; *-homo = ×′1-homo-* ; -‿homo = λ _ → refl ; 0-homo = refl ; 1-homo = refl } -- Equality of certain expressions can be decided. dec′ : ∀ m n → Maybe (m ×′ 1# ≈ n ×′ 1#) dec′ m n = map to (dec m n) where to : m × 1# ≈ n × 1# → m ×′ 1# ≈ n ×′ 1# to m≈n = begin m ×′ 1# ≈⟨ sym $ ×≈×′ m 1# ⟩ m × 1# ≈⟨ m≈n ⟩ n × 1# ≈⟨ ×≈×′ n 1# ⟩ n ×′ 1# ∎ -- The instantiation. open Algebra.Solver.Ring _ _ homomorphism dec′ public
26.407895
72
0.546089
146ba35d7397508a4b6d63d8c3d6946976381177
807
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous/Core.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This file contains some core definitions which are re-exported by -- Data.List.Relation.Binary.Sublist.Heterogeneous. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (REL) module Data.List.Relation.Binary.Sublist.Heterogeneous.Core {a b r} {A : Set a} {B : Set b} (R : REL A B r) where open import Level using (_⊔_) open import Data.List.Base using (List; []; _∷_; [_]) data Sublist : REL (List A) (List B) (a ⊔ b ⊔ r) where [] : Sublist [] [] _∷ʳ_ : ∀ {xs ys} → ∀ y → Sublist xs ys → Sublist xs (y ∷ ys) _∷_ : ∀ {x xs y ys} → R x y → Sublist xs ys → Sublist (x ∷ xs) (y ∷ ys)
35.086957
74
0.505576
3513b4b2a0503a25a4a8b5a1b7de052dd0090f50
1,426
agda
Agda
stdlib-exts/Data/HSTrie.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
stdlib-exts/Data/HSTrie.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
stdlib-exts/Data/HSTrie.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
module Data.HSTrie where open import Class.Map open import Data.List open import Data.String open import Data.String.Instance open import Data.Maybe private variable A B : Set {-# FOREIGN GHC import Data.Trie import Data.Text.Encoding #-} postulate HSTrie : Set -> Set emptyTrie : HSTrie A insertTrie : String -> A -> HSTrie A -> HSTrie A deleteTrie : String -> HSTrie A -> HSTrie A lookupTrie : String -> HSTrie A -> Maybe A fmapTrie : (A -> B) -> HSTrie A -> HSTrie B trieKeysPrim : HSTrie A -> List String submapTrie : String -> HSTrie A -> HSTrie A {-# COMPILE GHC HSTrie = type Trie #-} {-# COMPILE GHC emptyTrie = \ _ -> empty #-} {-# COMPILE GHC insertTrie = \ _ s -> insert (encodeUtf8 s) #-} {-# COMPILE GHC deleteTrie = \ _ s -> delete (encodeUtf8 s) #-} {-# COMPILE GHC lookupTrie = \ _ s -> Data.Trie.lookup (encodeUtf8 s) #-} {-# COMPILE GHC fmapTrie = \ _ _ -> fmap #-} {-# COMPILE GHC trieKeysPrim = \ _ -> fmap decodeUtf8 . keys #-} {-# COMPILE GHC submapTrie = \ _ s -> submap (encodeUtf8 s) #-} instance NDTrie-Map : MapClass String HSTrie NDTrie-Map = record { insert = insertTrie ; remove = deleteTrie ; lookup = lookupTrie ; mapSnd = fmapTrie ; emptyMap = emptyTrie } trieKeys : HSTrie A -> List String trieKeys = trieKeysPrim lookupHSTrie : String -> HSTrie A -> HSTrie A lookupHSTrie = submapTrie
26.90566
73
0.636746
cc0402c81454fa293f5646ffb868b87a82209a3b
1,456
agda
Agda
Cubical/Foundations/Structure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/Structure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Foundations/Structure.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Structure where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude private variable ℓ ℓ' ℓ'' : Level S : Type ℓ → Type ℓ' -- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X, -- the pair (X , s) : TypeWithStr ℓ S means that X is equipped with a S-structure, witnessed by s. TypeWithStr : (ℓ : Level) (S : Type ℓ → Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ') TypeWithStr ℓ S = Σ[ X ∈ Type ℓ ] S X typ : TypeWithStr ℓ S → Type ℓ typ = fst str : (A : TypeWithStr ℓ S) → S (typ A) str = snd -- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism. -- This will be implemented by a function ι : StrEquiv S ℓ' -- that gives us for any two types with S-structure (X , s) and (Y , t) a family: -- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ'' StrEquiv : (S : Type ℓ → Type ℓ'') (ℓ' : Level) → Type (ℓ-max (ℓ-suc (ℓ-max ℓ ℓ')) ℓ'') StrEquiv {ℓ} S ℓ' = (A B : TypeWithStr ℓ S) → typ A ≃ typ B → Type ℓ' -- An S-structure may instead be equipped with an action on equivalences, which will -- induce a notion of S-homomorphism EquivAction : (S : Type ℓ → Type ℓ'') → Type (ℓ-max (ℓ-suc ℓ) ℓ'') EquivAction {ℓ} S = {X Y : Type ℓ} → X ≃ Y → S X ≃ S Y EquivAction→StrEquiv : {S : Type ℓ → Type ℓ''} → EquivAction S → StrEquiv S ℓ'' EquivAction→StrEquiv α (X , s) (Y , t) e = equivFun (α e) s ≡ t
35.512195
98
0.624313
1bc2770b994a2bde48ed602ce8b9e4162a3ad61f
2,559
agda
Agda
src/Semantics/Context.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
4
2018-05-31T20:37:04.000Z
2022-01-04T09:33:48.000Z
src/Semantics/Context.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
null
null
null
src/Semantics/Context.agda
DimaSamoz/temporal-type-systems
7d993ba55e502d5ef8707ca216519012121a08dd
[ "MIT" ]
null
null
null
{- Denotational semantics of the contexts in the category of temporal types. -} module Semantics.Context where open import CategoryTheory.Categories open import CategoryTheory.Instances.Reactive open import CategoryTheory.Functor open import CategoryTheory.Comonad open import CategoryTheory.NatTrans open import TemporalOps.Box open import TemporalOps.Diamond open import Syntax.Context open import Semantics.Types open import Data.Product renaming (_,_ to _,,_) open import Relation.Binary.PropositionalEquality open Comonad W-□ private module F-□ = Functor F-□ -- | Denotation of judgements and contexts -- Denotation of judgements ⟦_⟧ⱼ : Judgement -> τ ⟦ A now ⟧ⱼ = ⟦ A ⟧ₜ ⟦ A always ⟧ⱼ = □ ⟦ A ⟧ₜ infix 50 ⟦_⟧ⱼ -- Denotation of contexts as a finite product of temporal types. ⟦_⟧ₓ : Context -> τ ⟦ ∙ ⟧ₓ = ⊤ ⟦ Γ , A ⟧ₓ = ⟦ Γ ⟧ₓ ⊗ ⟦ A ⟧ⱼ infix 50 ⟦_⟧ₓ -- Denotation of context to denotation of stabilised context -- Standard morphism arising from Γ ˢ ⊆ Γ ⟦_ˢ⟧ : ∀ Γ -> ⟦ Γ ⟧ₓ ⇴ ⟦ Γ ˢ ⟧ₓ ⟦ ∙ ˢ⟧ = ! ⟦ Γ , A now ˢ⟧ = ⟦ Γ ˢ⟧ ∘ π₁ ⟦ Γ , A always ˢ⟧ = ⟦ Γ ˢ⟧ * id -- Denotation of context to stable denotation of stabilised context -- Uses the Cartesian functor property of the □ comonad ⟦_ˢ⟧□ : ∀ Γ -> ⟦ Γ ⟧ₓ ⇴ □ ⟦ Γ ˢ ⟧ₓ ⟦ ∙ ˢ⟧□ = u ⟦ Γ , A now ˢ⟧□ = ⟦ Γ ˢ⟧□ ∘ π₁ ⟦ Γ , A always ˢ⟧□ = m (⟦ Γ ˢ ⟧ₓ) (□ ⟦ A ⟧ₜ) ∘ (⟦ Γ ˢ⟧□ * δ.at ⟦ A ⟧ₜ) -- The normal stabilisation transformation factors through -- the comonadic one via ε ⟦ˢ⟧-factor : ∀ Γ -> ⟦ Γ ˢ⟧ ≈ ε.at ⟦ Γ ˢ ⟧ₓ ∘ ⟦ Γ ˢ⟧□ ⟦ˢ⟧-factor ∙ = refl ⟦ˢ⟧-factor (Γ , A now) {n} {x ,, y} = ⟦ˢ⟧-factor Γ ⟦ˢ⟧-factor (Γ , A always) {n} {x ,, y} rewrite ⟦ˢ⟧-factor Γ {n} {x} = refl -- Applying ⟦ˢ⟧□ twice can be replaced with one ⟦ˢ⟧□ and duplication ⟦ˢ⟧□-twice : ∀ Δ -> F-□.fmap ⟦ Δ ˢ ˢ⟧□ ∘ ⟦ Δ ˢ⟧□ ≈ δ.at ⟦ Δ ˢ ˢ ⟧ₓ ∘ ⟦ Δ ˢ ˢ⟧□ ∘ ⟦ Δ ˢ⟧ ⟦ˢ⟧□-twice ∙ = refl ⟦ˢ⟧□-twice (Δ , A now) = ⟦ˢ⟧□-twice Δ ⟦ˢ⟧□-twice (Δ , A always) {n} {⟦Δ⟧ ,, □⟦A⟧} = ext λ k → ext λ l → cong (_,, □⟦A⟧) (lemma k l) where lemma : ∀ k l -> ⟦ Δ ˢ ˢ⟧□ k (⟦ Δ ˢ⟧□ n ⟦Δ⟧ k) l ≡ ⟦ Δ ˢ ˢ⟧□ n (⟦ Δ ˢ⟧ n ⟦Δ⟧) l lemma k l = □-≡ k l (□-≡ n k (⟦ˢ⟧□-twice Δ {n} {⟦Δ⟧}) k) l -- Applying ⟦ˢ⟧□ and ⟦ˢ⟧ can be commuted ⟦ˢ⟧-comm : ∀ Δ -> ⟦ Δ ˢ ˢ⟧□ ∘ ⟦ Δ ˢ⟧ ≈ F-□.fmap ⟦ Δ ˢ ˢ⟧ ∘ ⟦ Δ ˢ⟧□ ⟦ˢ⟧-comm Δ {n} {⟦Δ⟧} = ext (lemma Δ ⟦Δ⟧) where lemma : ∀ Δ ⟦Δ⟧ l -> (⟦ Δ ˢ ˢ⟧□ ∘ ⟦ Δ ˢ⟧) n ⟦Δ⟧ l ≡ (F-□.fmap ⟦ Δ ˢ ˢ⟧ ∘ ⟦ Δ ˢ⟧□) n ⟦Δ⟧ l lemma ∙ ⟦Δ⟧ l = refl lemma (Δ , A now) (⟦Δ⟧ ,, ⟦A⟧) l = lemma Δ ⟦Δ⟧ l lemma (Δ , A always) (⟦Δ⟧ ,, □⟦A⟧) l = cong (_,, □⟦A⟧) (lemma Δ ⟦Δ⟧ l)
35.054795
93
0.55295
11eae17f19171ca66ad66d1ece279425d175ec78
471
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Propositional/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Subset.Propositional.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Subset.Propositional.Properties where open import Data.List.Relation.Binary.Subset.Propositional.Properties public
33.642857
72
0.539278
7c28072a46db01999fe3d99d9087849601155208
14,896
agda
Agda
src-cbpv/NfCBPV.agda
andreasabel/ipl
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
[ "Unlicense" ]
19
2018-05-16T08:08:51.000Z
2021-04-27T19:10:49.000Z
src-cbpv/NfCBPV.agda
andreasabel/ipl
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
[ "Unlicense" ]
null
null
null
src-cbpv/NfCBPV.agda
andreasabel/ipl
9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a
[ "Unlicense" ]
2
2018-11-13T16:01:46.000Z
2021-02-25T20:39:03.000Z
{-# OPTIONS --rewriting #-} -- Normalization by Evaluation for Call-By-Push-Value module NfCBPV where -- Imports from the Agda standard library. open import Library hiding (_×̇_) open import Data.Nat using (ℕ) open import Data.Fin using (Fin) pattern here! = here refl -- We postulate a set of generic value types. -- There are no operations defined on these types, thus, -- they play the type of (universal) type variables. postulate Base : Set -- Variants (Σ) (and records (Π), resp.) can in principle have any number of -- constructors (fields, resp.), including infinitely one. -- In general, the constructor (field, resp.) names are given by a set I. -- However, I : Set would make syntax already a big type, living in Set₁. -- To keep it in Set₀, we only consider variants (records) with finitely -- many constructors (fields), thus, I : ℕ. -- Branching over I is then realized as functions out of El I, where -- El I = { i | i < I} = Fin I. set = ℕ El = Fin -- Let I range over arities (constructor/field sets) and i over -- constructor/field names. variable I : set i : El I -- The types of CBPV are classified into value types P : Ty⁺ which we -- refer to as positive types, and computation types N : Ty⁻ which we -- refer to as negative types. mutual -- Value types data Ty⁺ : Set where base : (o : Base) → Ty⁺ -- Base type. _×̇_ : (P₁ P₂ : Ty⁺) → Ty⁺ -- Finite product (tensor). Σ̇ : (I : set) (Ps : El I → Ty⁺) → Ty⁺ -- Variant (sum). □̇ : (N : Ty⁻) → Ty⁺ -- Thunk (U). -- Computation types data Ty⁻ : Set where ◇̇ : (P : Ty⁺) → Ty⁻ -- Comp (F). Π̇ : (I : set) (Ns : El I → Ty⁻) → Ty⁻ -- Record (lazy product). _⇒̇_ : (P : Ty⁺) (N : Ty⁻) → Ty⁻ -- Function type. -- In CBPV, a variable stands for a value. -- Thus, environments only contain values, -- and typing contexts only value types. -- We use introduce syntax in an intrinsically well-typed way -- with variables being de Bruijn indices into the typing context. -- Thus, contexts are just lists of types. Cxt = List Ty⁺ variable Γ Δ Φ : Cxt P P₁ P₂ P' P′ Q : Ty⁺ N N₁ N₂ N' N′ : Ty⁻ Ps : El I → Ty⁺ Ns : El I → Ty⁻ -- Generic values module _ (Var : Ty⁺ → Cxt → Set) (Comp : Ty⁻ → Cxt → Set) where -- Right non-invertible data Val' : (P : Ty⁺) (Γ : Cxt) → Set where var : ∀{Γ P} (x : Var P Γ) → Val' P Γ pair : ∀{Γ P₁ P₂} (v₁ : Val' P₁ Γ) (v₂ : Val' P₂ Γ) → Val' (P₁ ×̇ P₂) Γ inj : ∀{Γ I P} i (v : Val' (P i) Γ) → Val' (Σ̇ I P) Γ thunk : ∀{Γ N} (t : Comp N Γ) → Val' (□̇ N) Γ -- Terms mutual Val = Val' _∈_ Comp data Comp : (N : Ty⁻) (Γ : Cxt) → Set where -- introductions ret : ∀{Γ P} (v : Val P Γ) → Comp (◇̇ P) Γ rec : ∀{Γ I N} (t : ∀ i → Comp (N i) Γ) → Comp (Π̇ I N) Γ abs : ∀{Γ P N} (t : Comp N (P ∷ Γ)) → Comp (P ⇒̇ N) Γ -- positive eliminations split : ∀{Γ P₁ P₂ N} (v : Val (P₁ ×̇ P₂) Γ) (t : Comp N (P₂ ∷ P₁ ∷ Γ)) → Comp N Γ case : ∀{Γ I Ps N} (v : Val (Σ̇ I Ps) Γ) (t : ∀ i → Comp N (Ps i ∷ Γ)) → Comp N Γ bind : ∀{Γ P N} (u : Comp (◇̇ P) Γ) (t : Comp N (P ∷ Γ)) → Comp N Γ -- cut letv : ∀{Γ P N} (v : Val P Γ) (t : Comp N (P ∷ Γ)) → Comp N Γ -- negative eliminations force : ∀{Γ N} (v : Val (□̇ N) Γ) → Comp N Γ prj : ∀{Γ I Ns} i (t : Comp (Π̇ I Ns) Γ) → Comp (Ns i) Γ app : ∀{Γ P N} (t : Comp (P ⇒̇ N) Γ) (v : Val P Γ) → Comp N Γ -- Normal forms ------------------------------------------------------------------------ -- Normal values only reference variables of base type NVar : (P : Ty⁺) (Γ : Cxt) → Set NVar (base o) Γ = base o ∈ Γ NVar _ _ = ⊥ -- Negative neutrals module _ (Val : Ty⁺ → Cxt → Set) where -- Right non-invertible data Ne' : (N : Ty⁻) (Γ : Cxt) → Set where force : ∀{Γ N} (x : □̇ N ∈ Γ) → Ne' N Γ prj : ∀{Γ I N} i (t : Ne' (Π̇ I N) Γ) → Ne' (N i) Γ app : ∀{Γ P N} (t : Ne' (P ⇒̇ N) Γ) (v : Val P Γ) → Ne' N Γ mutual NVal = Val' NVar Nf Ne = Ne' NVal -- Cover monad data ◇ (J : Cxt → Set) (Γ : Cxt) : Set where return : (j : J Γ) → ◇ J Γ bind : ∀{P} (u : Ne (◇̇ P) Γ) (t : ◇ J (P ∷ Γ)) → ◇ J Γ case : ∀{I Ps} (x : Σ̇ I Ps ∈ Γ) (t : ∀ i → ◇ J (Ps i ∷ Γ)) → ◇ J Γ split : ∀{P₁ P₂} (x : (P₁ ×̇ P₂) ∈ Γ) (t : ◇ J (P₂ ∷ P₁ ∷ Γ)) → ◇ J Γ data NComp (Q : Ty⁺) (Γ : Cxt) : Set where ret : (v : NVal Q Γ) → NComp Q Γ -- Invoke RFoc ne : (n : Ne (◇̇ Q) Γ) → NComp Q Γ -- Finish with LFoc -- e.g. app (force f) x -- Use lemma LFoc bind : ∀{P} (u : Ne (◇̇ P) Γ) (t : NComp Q (P ∷ Γ)) → NComp Q Γ -- Left invertible split : ∀{P₁ P₂} (x : (P₁ ×̇ P₂) ∈ Γ) (t : NComp Q (P₂ ∷ P₁ ∷ Γ)) → NComp Q Γ case : ∀{I Ps} (x : Σ̇ I Ps ∈ Γ) (t : ∀ i → NComp Q (Ps i ∷ Γ)) → NComp Q Γ -- Right invertible data Nf : (N : Ty⁻) (Γ : Cxt) → Set where ret : ∀{Γ P} (v : ◇ (NVal P) Γ) → Nf (◇̇ P) Γ -- Invoke RFoc ne : ∀{Γ o} (let N = ◇̇ (base o)) (n : ◇ (Ne N) Γ) → Nf N Γ -- comp : ∀{Γ P} (t : NComp P Γ) → Nf (◇̇ P) Γ rec : ∀{Γ I N} (t : ∀ i → Nf (N i) Γ) → Nf (Π̇ I N) Γ abs : ∀{Γ P N} (t : Nf N (P ∷ Γ)) → Nf (P ⇒̇ N) Γ -- Context-indexed sets ------------------------------------------------------------------------ ISet = (Γ : Cxt) → Set variable A B C : ISet F G : (i : El I) → ISet -- Constructions on ISet 1̂ : ISet 1̂ Γ = ⊤ _×̂_ : (A B : ISet) → ISet (A ×̂ B) Γ = A Γ × B Γ Σ̂ : (I : set) (F : El I → ISet) → ISet (Σ̂ I F) Γ = ∃ λ i → F i Γ _⇒̂_ : (A B : ISet) → ISet (A ⇒̂ B) Γ = A Γ → B Γ Π̂ : (I : set) (F : El I → ISet) → ISet (Π̂ I F) Γ = ∀ i → F i Γ ⟨_⟩ : (P : Ty⁺) (A : ISet) → ISet ⟨ P ⟩ A Γ = A (P ∷ Γ) -- Morphisms between ISets _→̇_ : (A B : Cxt → Set) → Set A →̇ B = ∀{Γ} → A Γ → B Γ ⟨_⊙_⟩→̇_ : (P Q R : Cxt → Set) → Set ⟨ P ⊙ Q ⟩→̇ R = ∀{Γ} → P Γ → Q Γ → R Γ ⟨_⊙_⊙_⟩→̇_ : (P Q R S : Cxt → Set) → Set ⟨ P ⊙ Q ⊙ R ⟩→̇ S = ∀{Γ} → P Γ → Q Γ → R Γ → S Γ Map : (F : (Cxt → Set) → Cxt → Set) → Set₁ Map F = ∀{A B : Cxt → Set} (f : A →̇ B) → F A →̇ F B Π-map : (∀ i → F i →̇ G i) → Π̂ I F →̇ Π̂ I G Π-map f r i = f i (r i) -- -- Introductions and eliminations for ×̂ -- p̂air : ⟨ A ⊙ B ⟩→̇ (A ×̂ B) -- p̂air a b = λ -- Monotonicity ------------------------------------------------------------------------ -- Monotonization □ is a monoidal comonad □ : (A : Cxt → Set) → Cxt → Set □ A Γ = ∀{Δ} (τ : Γ ⊆ Δ) → A Δ extract : □ A →̇ A extract a = a ⊆-refl duplicate : □ A →̇ □ (□ A) duplicate a τ τ′ = a (⊆-trans τ τ′) □-map : Map □ □-map f a τ = f (a τ) extend : (□ A →̇ B) → □ A →̇ □ B extend f = □-map f ∘ duplicate □-weak : □ A →̇ ⟨ P ⟩ (□ A) □-weak a τ = a (⊆-trans (_ ∷ʳ ⊆-refl) τ) □-weak' : □ A →̇ □ (⟨ P ⟩ A) □-weak' a τ = a (_ ∷ʳ τ) □-sum : Σ̂ I (□ ∘ F) →̇ □ (Σ̂ I F) □-sum (i , a) τ = i , a τ -- Monoidality: □-unit : 1̂ →̇ □ 1̂ □-unit = _ □-pair : ⟨ □ A ⊙ □ B ⟩→̇ □ (A ×̂ B) □-pair a b τ = (a τ , b τ) -- Strong functoriality Map! : (F : (Cxt → Set) → Cxt → Set) → Set₁ Map! F = ∀{A B : Cxt → Set} → ⟨ □ (A ⇒̂ B) ⊙ F A ⟩→̇ F B -- Monotonicity Mon : (A : Cxt → Set) → Set Mon A = A →̇ □ A monVar : Mon (P ∈_) monVar x τ = ⊆-lookup τ x -- Positive ISets are monotone □-mon : Mon (□ A) □-mon = duplicate 1-mon : Mon 1̂ 1-mon = □-unit ×-mon : Mon A → Mon B → Mon (A ×̂ B) ×-mon mA mB (a , b) = □-pair (mA a) (mB b) Σ-mon : ((i : El I) → Mon (F i)) → Mon (Σ̂ I F) Σ-mon m (i , a) = □-sum (i , m i a) □-intro : Mon A → (A →̇ B) → (A →̇ □ B) □-intro mA f = □-map f ∘ mA -- Cover monad: a strong monad ------------------------------------------------------------------------ join : ◇ (◇ A) →̇ ◇ A join (return c) = c join (bind u c) = bind u (join c) join (case x t) = case x (join ∘ t) join (split x c) = split x (join c) ◇-map : Map ◇ ◇-map f (return j) = return (f j) ◇-map f (bind u a) = bind u (◇-map f a) ◇-map f (case x t) = case x (λ i → ◇-map f (t i)) ◇-map f (split x a) = split x (◇-map f a) ◇-map! : Map! ◇ ◇-map! f (return j) = return (extract f j) ◇-map! f (bind u a) = bind u (◇-map! (□-weak f) a) ◇-map! f (case x t) = case x (λ i → ◇-map! (□-weak f) (t i)) ◇-map! f (split x a) = split x (◇-map! (□-weak (□-weak f)) a) ◇-bind : A →̇ ◇ B → ◇ A →̇ ◇ B ◇-bind f = join ∘ ◇-map f ◇-record : ◇ (Π̂ I F) →̇ Π̂ I (◇ ∘ F) ◇-record c i = ◇-map (_$ i) c ◇-fun : Mon A → ◇ (A ⇒̂ B) →̇ (A ⇒̂ ◇ B) ◇-fun mA c a = ◇-map! (λ τ f → f (mA a τ)) c -- Monoidal functoriality -- ◇-pair : ⟨ ◇ A ⊙ ◇ B ⟩→̇ ◇ (A ×̂ B) -- does not hold! ◇-pair : ⟨ □ (◇ A) ⊙ ◇ (□ B) ⟩→̇ ◇ (A ×̂ B) ◇-pair ca = join ∘ ◇-map! λ τ b → ◇-map! (λ τ′ a → a , b τ′) (ca τ) _⋉_ = ◇-pair □◇-pair' : ⟨ □ (◇ A) ⊙ □ (◇ (□ B)) ⟩→̇ □ (◇ (A ×̂ B)) □◇-pair' ca cb τ = ◇-pair (□-mon ca τ) (cb τ) □◇-pair : Mon B → ⟨ □ (◇ A) ⊙ □ (◇ B) ⟩→̇ □ (◇ (A ×̂ B)) □◇-pair mB ca cb τ = join $ ◇-map! (λ τ₁ b → ◇-map! (λ τ₂ a → a , mB b τ₂) (ca (⊆-trans τ τ₁))) (cb τ) ◇□-pair' : ⟨ ◇ (□ A) ⊙ □ (◇ (□ B)) ⟩→̇ ◇ (□ (A ×̂ B)) ◇□-pair' ca cb = join (◇-map! (λ τ a → ◇-map! (λ τ₁ b τ₂ → a (⊆-trans τ₁ τ₂) , b τ₂) (cb τ)) ca) ◇□-pair : ⟨ □ (◇ (□ A)) ⊙ ◇ (□ B) ⟩→̇ ◇ (□ (A ×̂ B)) ◇□-pair ca cb = join (◇-map! (λ τ b → ◇-map! (λ τ₁ a τ₂ → a τ₂ , b (⊆-trans τ₁ τ₂)) (ca τ)) cb) -- Runnability Run : (A : Cxt → Set) → Set Run A = ◇ A →̇ A -- Negative ISets are runnable ◇-run : Run (◇ A) ◇-run = join Π-run : (∀ i → Run (F i)) → Run (Π̂ I F) Π-run f = Π-map f ∘ ◇-record ⇒-run : Mon A → Run B → Run (A ⇒̂ B) ⇒-run mA rB f = rB ∘ ◇-fun mA f -- Bind for the ◇ monad ◇-elim : Run B → (A →̇ B) → ◇ A →̇ B ◇-elim rB f = rB ∘ ◇-map f ◇-elim! : Run B → ⟨ □ (A ⇒̂ B) ⊙ ◇ A ⟩→̇ B ◇-elim! rB f = rB ∘ ◇-map! f ◇-elim-□ : Run B → ⟨ □ (A ⇒̂ B) ⊙ □ (◇ A) ⟩→̇ □ B ◇-elim-□ rB f c = □-map (uncurry (◇-elim! rB)) (□-pair (□-mon f) c) ◇-elim-□-alt : Run B → ⟨ □ (A ⇒̂ B) ⊙ □ (◇ A) ⟩→̇ □ B ◇-elim-□-alt rB f c τ = ◇-elim! rB (□-mon f τ) (c τ) bind! : Mon C → Run B → (C →̇ ◇ A) → (C →̇ (A ⇒̂ B)) → C →̇ B bind! mC rB f k γ = ◇-elim! rB (λ τ a → k (mC γ τ) a) (f γ) -- Type interpretation ------------------------------------------------------------------------ mutual ⟦_⟧⁺ : Ty⁺ → ISet ⟦ base o ⟧⁺ = base o ∈_ ⟦ P₁ ×̇ P₂ ⟧⁺ = ⟦ P₁ ⟧⁺ ×̂ ⟦ P₂ ⟧⁺ ⟦ Σ̇ I P ⟧⁺ = Σ̂ I λ i → ⟦ P i ⟧⁺ ⟦ □̇ N ⟧⁺ = □ ⟦ N ⟧⁻ ⟦_⟧⁻ : Ty⁻ → ISet ⟦ ◇̇ P ⟧⁻ = ◇ ⟦ P ⟧⁺ ⟦ Π̇ I N ⟧⁻ = Π̂ I λ i → ⟦ N i ⟧⁻ ⟦ P ⇒̇ N ⟧⁻ = ⟦ P ⟧⁺ ⇒̂ ⟦ N ⟧⁻ ⟦_⟧ᶜ : Cxt → ISet ⟦_⟧ᶜ Γ Δ = All (λ P → ⟦ P ⟧⁺ Δ) Γ -- ⟦ [] ⟧ᶜ = 1̂ -- ⟦ P ∷ Γ ⟧ᶜ = ⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺ -- Positive types are monotone. mon⁺ : (P : Ty⁺) → Mon ⟦ P ⟧⁺ mon⁺ (base o) = monVar mon⁺ (P₁ ×̇ P₂) = ×-mon (mon⁺ P₁) (mon⁺ P₂) mon⁺ (Σ̇ I P) = Σ-mon (mon⁺ ∘ P) mon⁺ (□̇ N) = □-mon monᶜ : (Γ : Cxt) → Mon ⟦ Γ ⟧ᶜ monᶜ Γ γ τ = All.map (λ {P} v → mon⁺ P v τ) γ -- Negative types are runnable. run⁻ : (N : Ty⁻) → Run ⟦ N ⟧⁻ run⁻ (◇̇ P) = ◇-run run⁻ (Π̇ I N) = Π-run (run⁻ ∘ N) run⁻ (P ⇒̇ N) = ⇒-run (mon⁺ P) (run⁻ N) -- monᶜ [] = 1-mon -- monᶜ (P ∷ Γ) = ×-mon (monᶜ Γ) (mon⁺ P) -- Interpretation ------------------------------------------------------------------------ mutual ⦅_⦆⁺ : Val P Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⟧⁺ ⦅ var x ⦆⁺ = λ γ → All.lookup γ x ⦅ pair v₁ v₂ ⦆⁺ = < ⦅ v₁ ⦆⁺ , ⦅ v₂ ⦆⁺ > ⦅ inj i v ⦆⁺ = (i ,_) ∘ ⦅ v ⦆⁺ ⦅ thunk t ⦆⁺ = □-intro (monᶜ _) ⦅ t ⦆⁻ λ⦅_⦆⁻ : Comp N (P ∷ Γ) → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⇒̇ N ⟧⁻ λ⦅ t ⦆⁻ γ a = ⦅ t ⦆⁻ (a ∷ γ) ⦅_⦆⁻ : Comp N Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ N ⟧⁻ ⦅ ret v ⦆⁻ = return ∘ ⦅ v ⦆⁺ ⦅ rec t ⦆⁻ = flip λ i → ⦅ t i ⦆⁻ ⦅ abs t ⦆⁻ = λ⦅ t ⦆⁻ ⦅ split v t ⦆⁻ γ = let (a₁ , a₂) = ⦅ v ⦆⁺ γ in ⦅ t ⦆⁻ (a₂ ∷ (a₁ ∷ γ)) ⦅ case v t ⦆⁻ γ = let (i , a) = ⦅ v ⦆⁺ γ in ⦅ t i ⦆⁻ (a ∷ γ) ⦅ bind {Γ = Γ} {N = N} t t₁ ⦆⁻ = bind! (monᶜ Γ) (run⁻ N) ⦅ t ⦆⁻ λ⦅ t₁ ⦆⁻ ⦅ force v ⦆⁻ = extract ∘ ⦅ v ⦆⁺ ⦅ prj i t ⦆⁻ = (_$ i) ∘ ⦅ t ⦆⁻ ⦅ app t v ⦆⁻ = ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺ ⦅ letv v t ⦆⁻ = λ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺ -- Reflection and reification mutual fresh□◇□ : ∀ P {Γ} → ⟨ P ⟩ (□ (◇ (□ ⟦ P ⟧⁺))) Γ fresh□◇□ P = reflect⁺□ P ∘ monVar here! fresh□ : ∀ P {Γ} → ⟨ P ⟩ (□ (◇ ⟦ P ⟧⁺)) Γ fresh□ P = ◇-map extract ∘ reflect⁺□ P ∘ monVar here! fresh□ P = reflect⁺ P ∘ monVar here! fresh : ∀ {P Γ} → ⟨ P ⟩ (◇ ⟦ P ⟧⁺) Γ fresh {P} = ◇-map extract (reflect⁺□ P here!) fresh {P} = reflect⁺ P here! fresh◇ : ∀ {P Γ} → ⟨ P ⟩ (◇ (□ ⟦ P ⟧⁺)) Γ fresh◇ {P} = reflect⁺□ P here! fresh◇ {P} = ◇-map (mon⁺ P) fresh -- saves us use of Mon P in freshᶜ reflect⁺□ : (P : Ty⁺) → (P ∈_) →̇ (◇ (□ ⟦ P ⟧⁺)) reflect⁺□ (base o) x = return (monVar x) reflect⁺□ (P₁ ×̇ P₂) x = split x (◇□-pair (reflect⁺□ P₁ ∘ monVar (there here!)) fresh◇) reflect⁺□ (Σ̇ I Ps) x = case x λ i → ◇-map (□-map (i ,_)) fresh◇ reflect⁺□ (□̇ N) x = return (□-mon (reflect⁻ N ∘ force ∘ monVar x)) reflect⁺ : (P : Ty⁺) → (P ∈_) →̇ (◇ ⟦ P ⟧⁺) reflect⁺ (base o) x = return x reflect⁺ (P₁ ×̇ P₂) x = split x (□-weak (fresh□ P₁) ⋉ fresh◇) reflect⁺ (Σ̇ I Ps) x = case x λ i → ◇-map (i ,_) fresh reflect⁺ (□̇ N) x = return λ τ → reflect⁻ N (force (monVar x τ)) reflect⁻ : (N : Ty⁻) → Ne N →̇ ⟦ N ⟧⁻ reflect⁻ (◇̇ P) u = bind u fresh reflect⁻ (Π̇ I Ns) u = λ i → reflect⁻ (Ns i) (prj i u) reflect⁻ (P ⇒̇ N) u = λ a → reflect⁻ N (app u (reify⁺ P a)) reify⁺ : (P : Ty⁺) → ⟦ P ⟧⁺ →̇ NVal P reify⁺ (base o) = var reify⁺ (P₁ ×̇ P₂) (a₁ , a₂) = pair (reify⁺ P₁ a₁) (reify⁺ P₂ a₂) reify⁺ (Σ̇ I Ps) (i , a ) = inj i (reify⁺ (Ps i) a) reify⁺ (□̇ N) a = thunk (reify⁻ N a) reify⁻ : (N : Ty⁻) → □ ⟦ N ⟧⁻ →̇ Nf N reify⁻ (◇̇ P) f = ret (◇-map (reify⁺ P) (extract f)) reify⁻ (Π̇ I Ns) f = rec λ i → reify⁻ (Ns i) (□-map (_$ i) f) reify⁻ (P ⇒̇ N) f = abs $ reify⁻ N $ ◇-elim-□ (run⁻ N) (□-weak f) $ fresh□ P ext : (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ⟦ P ∷ Γ ⟧ᶜ ext (γ , a) = a ∷ γ ◇-ext : ◇ (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ◇ ⟦ P ∷ Γ ⟧ᶜ ◇-ext = ◇-map ext -- Without the use of ◇-mon! freshᶜ : (Γ : Cxt) → □ (◇ ⟦ Γ ⟧ᶜ) Γ freshᶜ [] = λ τ → return [] freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (fresh□◇□ P) freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair (mon⁺ P) (□-weak (freshᶜ Γ)) (fresh□ P) freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (◇-map (mon⁺ P) ∘ (fresh□ P)) freshᶜ (P ∷ Γ) = ◇-ext ∘ λ τ → (□-weak (□-mon (freshᶜ Γ)) τ) ⋉ ◇-map (mon⁺ P) (fresh□ P τ) norm : Comp N →̇ Nf N norm {N = N} {Γ = Γ} t = reify⁻ N $ □-map (run⁻ N ∘ ◇-map ⦅ t ⦆⁻) $ freshᶜ Γ norm {N = N} {Γ = Γ} t = reify⁻ N $ run⁻ N ∘ ◇-map ⦅ t ⦆⁻ ∘ freshᶜ Γ -- -} -- -} -- -} -- -} -- -} -- -}
28.980545
96
0.422462
11e0c4dcd373f042712c98b51519fcd8816ce386
6,740
agda
Agda
SOAS/Sorting.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
SOAS/Sorting.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
SOAS/Sorting.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Categories with objects parameterised by a sort module SOAS.Sorting {T : Set} where open import SOAS.Common import Categories.Category.CartesianClosed.Canonical as Canonical import Categories.Category.CartesianClosed as CCC open import Categories.Category.Cocartesian open import Categories.Category.BicartesianClosed import Categories.Category.Monoidal as Monoidal import Categories.Category.Monoidal.Closed as MonClosed open import Categories.Object.Product open import Categories.Functor.Bifunctor -- Add sorting to a set Sorted : Set₁ → Set₁ Sorted Obj = T → Obj -- Lift a function on Obj to one on sorted Obj sorted : {O₁ O₂ : Set₁} → (O₁ → O₂) → Sorted O₁ → Sorted O₂ sorted f 𝒳 τ = f (𝒳 τ) -- Lift a binary operation on Obj to one on sorted Obj sorted₂ : {O₁ O₂ O₃ : Set₁} → (O₁ → O₂ → O₃) → Sorted O₁ → Sorted O₂ → Sorted O₃ sorted₂ op 𝒳 𝒴 τ = op (𝒳 τ) (𝒴 τ) sortedᵣ : {O₁ O₂ O₃ : Set₁} → (O₁ → O₂ → O₃) → O₁ → Sorted O₂ → Sorted O₃ sortedᵣ op X 𝒴 τ = op X (𝒴 τ) sortedₗ : {O₁ O₂ O₃ : Set₁} → (O₁ → O₂ → O₃) → Sorted O₁ → O₂ → Sorted O₃ sortedₗ op 𝒳 Y τ = op (𝒳 τ) Y -- Turn a category into a sorted category 𝕊orted : Category 1ℓ 0ℓ 0ℓ → Category 1ℓ 0ℓ 0ℓ 𝕊orted Cat = categoryHelper (record { Obj = Sorted Obj ; _⇒_ = λ A B → ∀{τ : T} → A τ ⇒ B τ ; _≈_ = λ f g → ∀{α : T} → f {α} ≈ g {α} ; id = id Cat ; _∘_ = λ g f → Category._∘_ Cat g f ; assoc = assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; equiv = record { refl = E.refl equiv ; sym = λ p → E.sym equiv p ; trans = λ p q → E.trans equiv p q } ; ∘-resp-≈ = λ p q → ∘-resp-≈ p q }) where open Category Cat open import Relation.Binary.Structures renaming (IsEquivalence to E) -- Lift functors to functors between sorted categories 𝕊orted-Functor : {ℂ 𝔻 : Category 1ℓ 0ℓ 0ℓ} → Functor ℂ 𝔻 → Functor (𝕊orted ℂ) (𝕊orted 𝔻) 𝕊orted-Functor F = record { F₀ = λ X τ → Functor.₀ F (X τ) ; F₁ = λ f → Functor.₁ F f ; identity = Functor.identity F ; homomorphism = Functor.homomorphism F ; F-resp-≈ = λ z → Functor.F-resp-≈ F z } -- Lift bifunctors to bifunctors between sorted categories 𝕊orted-Bifunctor : {ℂ 𝔻 𝔼 : Category 1ℓ 0ℓ 0ℓ} → Bifunctor ℂ 𝔻 𝔼 → Bifunctor (𝕊orted ℂ) (𝕊orted 𝔻) (𝕊orted 𝔼) 𝕊orted-Bifunctor F = record { F₀ = λ{ (X , Y) τ → Functor.₀ F (X τ , Y τ)} ; F₁ = λ{ (f , g) → Functor.₁ F (f , g)} ; identity = Functor.identity F ; homomorphism = Functor.homomorphism F ; F-resp-≈ = λ{ (p , q) → Functor.F-resp-≈ F (p , q)} } private variable C : Category 1ℓ 0ℓ 0ℓ -- A sorted CCC is itself a CCC 𝕊orted-CanCCC : Canonical.CartesianClosed C → Canonical.CartesianClosed (𝕊orted C) 𝕊orted-CanCCC CCC = record { ⊤ = λ τ → 𝓒.terminal.⊤ ; _×_ = λ A B τ → (A τ) 𝓒.× (B τ) ; ! = 𝓒.terminal.! ; π₁ = 𝓒.π₁ ; π₂ = 𝓒.π₂ ; ⟨_,_⟩ = λ f g → 𝓒.⟨ f , g ⟩ ; !-unique = λ f → 𝓒.terminal.!-unique f ; π₁-comp = 𝓒.π₁-comp ; π₂-comp = 𝓒.π₂-comp ; ⟨,⟩-unique = λ p₁ p₂ → 𝓒.⟨,⟩-unique p₁ p₂ ; _^_ = λ B A τ → B τ 𝓒.^ A τ ; eval = 𝓒.eval ; curry = λ f → 𝓒.curry f ; eval-comp = 𝓒.eval-comp ; curry-resp-≈ = λ p → 𝓒.curry-resp-≈ p ; curry-unique = λ p → 𝓒.curry-unique p } where private module 𝓒 = Canonical.CartesianClosed CCC -- A sorted co-Cartesian category is co-Cartesian 𝕊orted-Cocartesian : Cocartesian C → Cocartesian (𝕊orted C) 𝕊orted-Cocartesian Cocart = record { initial = record { ⊥ = λ τ → 𝓒.⊥ ; ⊥-is-initial = record { ! = 𝓒.initial.! ; !-unique = λ f → 𝓒.initial.!-unique f } } ; coproducts = record { coproduct = λ {A}{B} → record { A+B = λ τ → 𝓒.coproduct.A+B {A τ}{B τ} ; i₁ = 𝓒.i₁ ; i₂ = 𝓒.i₂ ; [_,_] = λ f g → 𝓒.[ f , g ] ; inject₁ = 𝓒.inject₁ ; inject₂ = 𝓒.inject₂ ; unique = λ p₁ p₂ → 𝓒.coproduct.unique p₁ p₂ } } } where private module 𝓒 = Cocartesian Cocart -- A sorted bi-Cartesian closed category is itself bi-Cartesian closed 𝕊orted-BCCC : BicartesianClosed C → BicartesianClosed (𝕊orted C) 𝕊orted-BCCC BCCC = record { cartesianClosed = fromCanonical _ (𝕊orted-CanCCC (toCanonical _ cartesianClosed)) ; cocartesian = 𝕊orted-Cocartesian cocartesian } where open BicartesianClosed BCCC open Canonical.Equivalence -- A sorted monoidal category is itself monoidal 𝕊orted-Monoidal : Monoidal.Monoidal C → Monoidal.Monoidal (𝕊orted C) 𝕊orted-Monoidal {C} Mon = record { ⊗ = record { F₀ = λ{ (X , Y) τ → X τ 𝓒.⊗₀ Y τ } ; F₁ = λ{ (f , g) → f 𝓒.⊗₁ g} ; identity = Functor.identity 𝓒.⊗ ; homomorphism = Functor.homomorphism 𝓒.⊗ ; F-resp-≈ = λ{ (p₁ , p₂) {α} → Functor.F-resp-≈ 𝓒.⊗ (p₁ , p₂) } } ; unit = λ τ → 𝓒.unit ; unitorˡ = record { from = λ {τ} → 𝓒.unitorˡ.from ; to = 𝓒.unitorˡ.to ; iso = record { isoˡ = Iso.isoˡ 𝓒.unitorˡ.iso ; isoʳ = Iso.isoʳ 𝓒.unitorˡ.iso } } ; unitorʳ = record { from = λ {τ} → 𝓒.unitorʳ.from ; to = 𝓒.unitorʳ.to ; iso = record { isoˡ = Iso.isoˡ 𝓒.unitorʳ.iso ; isoʳ = Iso.isoʳ 𝓒.unitorʳ.iso } } ; associator = record { from = λ {τ} → 𝓒.associator.from ; to = 𝓒.associator.to ; iso = record { isoˡ = Iso.isoˡ 𝓒.associator.iso ; isoʳ = Iso.isoʳ 𝓒.associator.iso } } ; unitorˡ-commute-from = 𝓒.unitorˡ-commute-from ; unitorˡ-commute-to = 𝓒.unitorˡ-commute-to ; unitorʳ-commute-from = 𝓒.unitorʳ-commute-from ; unitorʳ-commute-to = 𝓒.unitorʳ-commute-to ; assoc-commute-from = 𝓒.assoc-commute-from ; assoc-commute-to = 𝓒.assoc-commute-to ; triangle = 𝓒.triangle ; pentagon = 𝓒.pentagon } where private module 𝓒 = Monoidal.Monoidal Mon open import Categories.Morphism C -- A sorted monoidal closed category is itself monoidal closed 𝕊orted-MonClosed : {Mon : Monoidal.Monoidal C} → MonClosed.Closed Mon → MonClosed.Closed (𝕊orted-Monoidal Mon) 𝕊orted-MonClosed {Mon} Cl = record { [-,-] = record { F₀ = λ (X , Y) τ → 𝓒.[ X τ , Y τ ]₀ ; F₁ = λ (f , g) → 𝓒.[ f , g ]₁ ; identity = λ {A} {α} → Functor.identity 𝓒.[-,-] ; homomorphism = Functor.homomorphism 𝓒.[-,-] ; F-resp-≈ = λ{ (p₁ , p₂) {α} → Functor.F-resp-≈ 𝓒.[-,-] (p₁ , p₂) } } ; adjoint = record { unit = ntHelper record { η = λ X {τ} → NT.η 𝓒.adjoint.unit (X τ) ; commute = λ f → NT.commute 𝓒.adjoint.unit f } ; counit = ntHelper record { η = λ X {τ} → NT.η 𝓒.adjoint.counit (X τ) ; commute = λ f → NT.commute 𝓒.adjoint.counit f } ; zig = 𝓒.adjoint.zig ; zag = 𝓒.adjoint.zag } ; mate = λ f → record { commute₁ = 𝓒.mate.commute₁ f ; commute₂ = 𝓒.mate.commute₂ f } } where private module 𝓒 = MonClosed.Closed Cl
35.661376
112
0.603264
0da323d33d71ec847e5750707987fbe88285df36
279
agda
Agda
test/interaction/Issue2493.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2493.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2493.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-03-10, issue #2493, reported by nad -- {-# OPTIONS -v tc.meta.assign:10 -v tc.size:90 -v tc:30 #-} A : Set A = {!!} P : A → Set P = {!λ _ → ?!} -- give -- Giving this made Agda loop as it solved ?0 := A. -- Solution: don't assign metas during CheckInternal!
23.25
62
0.594982
7c81cf50e5f3d7a332c4c830ef3d82644942d94b
477
agda
Agda
test/Fail/Issue1015.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1015.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1015.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-03-27 fixed issue {-# OPTIONS --copatterns --sized-types #-} open import Common.Size mutual data D (i : Size) : Set where inn : R i → D i record R (i : Size) : Set where inductive field force : (j : Size< i) → D j open R inh : (i : Size) → R i force (inh i) j = inn (inh j) -- inh should be rejected by termination checker data ⊥ : Set where elim : D ∞ → ⊥ elim (inn r) = elim (force r ∞) absurd : ⊥ absurd = elim (inn (inh ∞))
15.9
48
0.582809
2edac1e9275cb60e1535abe1c9d23151f5c74172
916
agda
Agda
src/Categories/Diagram/SubobjectClassifier.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Diagram/SubobjectClassifier.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Diagram/SubobjectClassifier.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category -- the usual notion requires C to have finite limits. -- this definition is a generalization by omitting that requirement as the definition -- itself does not involve any limit. module Categories.Diagram.SubobjectClassifier {o ℓ e} (C : Category o ℓ e) where open Category C open import Level open import Categories.Object.Terminal C open import Categories.Morphism C open import Categories.Diagram.Pullback C record SubobjectClassifier : Set (o ⊔ ℓ ⊔ e) where field Ω : Obj terminal : Terminal module terminal = Terminal terminal open terminal field true : ⊤ ⇒ Ω universal : ∀ {X Y} {f : X ⇒ Y} → Mono f → Y ⇒ Ω pullback : ∀ {X Y} {f : X ⇒ Y} {mono : Mono f} → IsPullback f ! (universal mono) true unique : ∀ {X Y} {f : X ⇒ Y} {g} {mono : Mono f} → IsPullback f ! g true → universal mono ≈ g
29.548387
100
0.668122
0d09ab940d34b8dd1bade424ac8fdae09290cfb9
1,921
agda
Agda
theorems/groups/KernelSndImageInl.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/groups/KernelSndImageInl.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/groups/KernelSndImageInl.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 groups.KernelSndImageInl {i j k} (G : Group i) {H : Group j} {K : Group k} -- the argument [φ-snd], which is intended to be [φ ∘ᴳ ×-snd], -- gives the possibility of making the second part -- (the proof of being a group homomorphism) abstract. (φ : H →ᴳ K) (φ-snd : G ×ᴳ H →ᴳ K) (φ-snd-β : ∀ x → GroupHom.f φ-snd x == GroupHom.f φ (snd x)) (G×H-is-abelian : is-abelian (G ×ᴳ H)) where open import groups.KernelImage φ-snd (×ᴳ-inl {G = G} {H = H}) G×H-is-abelian private module G = Group G module H = Group H Ker-φ-snd-quot-Im-inl : Ker φ ≃ᴳ Ker/Im Ker-φ-snd-quot-Im-inl = to-hom , is-eq to from to-from from-to where to : Ker.El φ → Ker/Im.El to (h , h-in-ker) = q[ (G.ident , h) , lemma ] where abstract lemma = φ-snd-β (G.ident , h) ∙ h-in-ker abstract to-pres-comp : ∀ k₁ k₂ → to (Ker.comp φ k₁ k₂) == Ker/Im.comp (to k₁) (to k₂) to-pres-comp _ _ = ap q[_] $ Ker.El=-out φ-snd $ pair×= (! (G.unit-l G.ident)) idp to-hom : Ker φ →ᴳ Ker/Im to-hom = group-hom to to-pres-comp abstract from' : Ker.El φ-snd → Ker.El φ from' ((g , h) , h-in-ker) = h , ! (φ-snd-β (g , h)) ∙ h-in-ker from-rel : ∀ {gh₁ gh₂} → ker/im-rel gh₁ gh₂ → from' gh₁ == from' gh₂ from-rel {gh₁} {gh₂} = Trunc-rec (λ{(g , inl-g=h₁h₂⁻¹) → Ker.El=-out φ (H.zero-diff-same (snd (fst gh₁)) (snd (fst gh₂)) (! (snd×= inl-g=h₁h₂⁻¹)))}) from : Ker/Im.El → Ker.El φ from = SetQuot-rec from' from-rel abstract to-from : ∀ g → to (from g) == g to-from = SetQuot-elim {P = λ g → to (from g) == g} (λ{((g , h) , h-in-ker) → quot-rel [ G.inv g , ap2 _,_ (! (G.unit-l (G.inv g))) (! (H.inv-r h)) ]}) (λ _ → prop-has-all-paths-↓) from-to : ∀ g → from (to g) == g from-to _ = Ker.El=-out φ idp
33.12069
87
0.531494
735cdeeb73ae6682341f84bc77657f3f317edf60
5,788
agda
Agda
agda-stdlib/src/Relation/Binary/Construct/Intersection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Construct/Intersection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Construct/Intersection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Intersection of two binary relations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Relation.Binary.Construct.Intersection where open import Data.Product open import Data.Sum.Base using (_⊎_; inj₁; inj₂; [_,_]) open import Function using (_∘_) open import Level using (_⊔_) open import Relation.Binary open import Relation.Nullary using (yes; no) open import Relation.Nullary.Product using (_×-dec_) ------------------------------------------------------------------------ -- Definition _∩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} → REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ₁ ⊔ ℓ₂) L ∩ R = λ i j → L i j × R i j ------------------------------------------------------------------------ -- Properties module _ {a ℓ₁ ℓ₂} {A : Set a} (L : Rel A ℓ₁) (R : Rel A ℓ₂) where reflexive : Reflexive L → Reflexive R → Reflexive (L ∩ R) reflexive L-refl R-refl = L-refl , R-refl symmetric : Symmetric L → Symmetric R → Symmetric (L ∩ R) symmetric L-sym R-sym = map L-sym R-sym transitive : Transitive L → Transitive R → Transitive (L ∩ R) transitive L-trans R-trans = zip L-trans R-trans respects : ∀ {p} (P : A → Set p) → P Respects L ⊎ P Respects R → P Respects (L ∩ R) respects P resp (Lxy , Rxy) = [ (λ x → x Lxy) , (λ x → x Rxy) ] resp min : ∀ {⊤} → Minimum L ⊤ → Minimum R ⊤ → Minimum (L ∩ R) ⊤ min L-min R-min = < L-min , R-min > max : ∀ {⊥} → Maximum L ⊥ → Maximum R ⊥ → Maximum (L ∩ R) ⊥ max L-max R-max = < L-max , R-max > module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} (≈ : REL A B ℓ₁) {L : REL A B ℓ₂} {R : REL A B ℓ₃} where implies : (≈ ⇒ L) → (≈ ⇒ R) → ≈ ⇒ (L ∩ R) implies ≈⇒L ≈⇒R = < ≈⇒L , ≈⇒R > module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} (≈ : REL A B ℓ₁) (L : REL A B ℓ₂) (R : REL A B ℓ₃) where irreflexive : Irreflexive ≈ L ⊎ Irreflexive ≈ R → Irreflexive ≈ (L ∩ R) irreflexive irrefl x≈y (Lxy , Rxy) = [ (λ x → x x≈y Lxy) , (λ x → x x≈y Rxy) ] irrefl module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} (≈ : Rel A ℓ₁) (L : Rel A ℓ₂) (R : Rel A ℓ₃) where respectsˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∩ R) Respectsˡ ≈ respectsˡ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y) respectsʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∩ R) Respectsʳ ≈ respectsʳ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y) respects₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∩ R) Respects₂ ≈ respects₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respectsʳ Lʳ Rʳ , respectsˡ Lˡ Rˡ antisymmetric : Antisymmetric ≈ L ⊎ Antisymmetric ≈ R → Antisymmetric ≈ (L ∩ R) antisymmetric (inj₁ L-antisym) (Lxy , _) (Lyx , _) = L-antisym Lxy Lyx antisymmetric (inj₂ R-antisym) (_ , Rxy) (_ , Ryx) = R-antisym Rxy Ryx module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} {L : REL A B ℓ₁} {R : REL A B ℓ₂} where decidable : Decidable L → Decidable R → Decidable (L ∩ R) decidable L? R? x y = L? x y ×-dec R? x y ------------------------------------------------------------------------ -- Structures module _ {a ℓ₁ ℓ₂} {A : Set a} {L : Rel A ℓ₁} {R : Rel A ℓ₂} where isEquivalence : IsEquivalence L → IsEquivalence R → IsEquivalence (L ∩ R) isEquivalence eqₗ eqᵣ = record { refl = reflexive L R Eqₗ.refl Eqᵣ.refl ; sym = symmetric L R Eqₗ.sym Eqᵣ.sym ; trans = transitive L R Eqₗ.trans Eqᵣ.trans } where module Eqₗ = IsEquivalence eqₗ; module Eqᵣ = IsEquivalence eqᵣ isDecEquivalence : IsDecEquivalence L → IsDecEquivalence R → IsDecEquivalence (L ∩ R) isDecEquivalence eqₗ eqᵣ = record { isEquivalence = isEquivalence Eqₗ.isEquivalence Eqᵣ.isEquivalence ; _≟_ = decidable Eqₗ._≟_ Eqᵣ._≟_ } where module Eqₗ = IsDecEquivalence eqₗ; module Eqᵣ = IsDecEquivalence eqᵣ module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} {≈ : Rel A ℓ₁} {L : Rel A ℓ₂} {R : Rel A ℓ₃} where isPreorder : IsPreorder ≈ L → IsPreorder ≈ R → IsPreorder ≈ (L ∩ R) isPreorder Oₗ Oᵣ = record { isEquivalence = Oₗ.isEquivalence ; reflexive = implies ≈ Oₗ.reflexive Oᵣ.reflexive ; trans = transitive L R Oₗ.trans Oᵣ.trans } where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPreorder Oᵣ isPartialOrderˡ : IsPartialOrder ≈ L → IsPreorder ≈ R → IsPartialOrder ≈ (L ∩ R) isPartialOrderˡ Oₗ Oᵣ = record { isPreorder = isPreorder Oₗ.isPreorder Oᵣ ; antisym = antisymmetric ≈ L R (inj₁ Oₗ.antisym) } where module Oₗ = IsPartialOrder Oₗ; module Oᵣ = IsPreorder Oᵣ isPartialOrderʳ : IsPreorder ≈ L → IsPartialOrder ≈ R → IsPartialOrder ≈ (L ∩ R) isPartialOrderʳ Oₗ Oᵣ = record { isPreorder = isPreorder Oₗ Oᵣ.isPreorder ; antisym = antisymmetric ≈ L R (inj₂ Oᵣ.antisym) } where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPartialOrder Oᵣ isStrictPartialOrderˡ : IsStrictPartialOrder ≈ L → Transitive R → R Respects₂ ≈ → IsStrictPartialOrder ≈ (L ∩ R) isStrictPartialOrderˡ Oₗ transᵣ respᵣ = record { isEquivalence = Oₗ.isEquivalence ; irrefl = irreflexive ≈ L R (inj₁ Oₗ.irrefl) ; trans = transitive L R Oₗ.trans transᵣ ; <-resp-≈ = respects₂ ≈ L R Oₗ.<-resp-≈ respᵣ } where module Oₗ = IsStrictPartialOrder Oₗ isStrictPartialOrderʳ : Transitive L → L Respects₂ ≈ → IsStrictPartialOrder ≈ R → IsStrictPartialOrder ≈ (L ∩ R) isStrictPartialOrderʳ transₗ respₗ Oᵣ = record { isEquivalence = Oᵣ.isEquivalence ; irrefl = irreflexive ≈ L R (inj₂ Oᵣ.irrefl) ; trans = transitive L R transₗ Oᵣ.trans ; <-resp-≈ = respects₂ ≈ L R respₗ Oᵣ.<-resp-≈ } where module Oᵣ = IsStrictPartialOrder Oᵣ
39.108108
87
0.569281
735da8f8f40e306ea7fa2fd6c61c1ac46f629e9e
1,253
agda
Agda
theorems/groups/KernelCstImageCst.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/groups/KernelCstImageCst.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/groups/KernelCstImageCst.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 groups.KernelCstImageCst {i j k} (G : Group i) (H : Group j) (K : Group k) (H-ab : is-abelian H) where private module H = Group H open import groups.KernelImage {G = G} {H = H} {K = K} cst-hom cst-hom H-ab Ker-cst-quot-Im-cst : Ker/Im ≃ᴳ H Ker-cst-quot-Im-cst = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where to : Ker/Im.El → H.El to = SetQuot-rec to' to-rel where to' : Ker.El (cst-hom {G = H} {H = K}) → H.El to' ker = fst ker abstract to-rel : ∀ {h₁ h₂} → ker/im-rel' h₁ h₂ → h₁ == h₂ to-rel {h₁} {h₂} = Trunc-rec λ{(_ , 0=h₁h₂⁻¹) → H.zero-diff-same h₁ h₂ (! 0=h₁h₂⁻¹)} from : H.El → Ker/Im.El from h = q[ h , idp ] abstract to-from : ∀ h → to (from h) == h to-from h = idp from-to : ∀ k/i → from (to k/i) == k/i from-to = SetQuot-elim (λ _ → ap q[_] $ Ker.El=-out (cst-hom {G = H} {H = K}) idp) (λ _ → prop-has-all-paths-↓) to-pres-comp : preserves-comp Ker/Im.comp H.comp to to-pres-comp = SetQuot-elim (λ _ → SetQuot-elim (λ _ → idp) (λ _ → prop-has-all-paths-↓)) (λ _ → prop-has-all-paths-↓)
28.477273
82
0.519553
132df42c28a00828034fbd3ec0ba76c2059ac31f
4,855
agda
Agda
Cubical/Homotopy/MayerVietorisCofiber.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Homotopy/MayerVietorisCofiber.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Homotopy/MayerVietorisCofiber.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- Mayer-Vietoris cofiber sequence: Let X be a pointed type, and let a span B ←[f]- X -[g]→ C be given. Then the mapping cone of the canonical map (B ⋁ C) → B ⊔_X C is equivalent to Susp X. The sequence Susp X → (B ⋁ C) → B ⊔_X C therefore induces a long exact sequence in cohomology. Proof is adapted from Evan Cavallo's master's thesis. -} {-# OPTIONS --safe #-} module Cubical.Homotopy.MayerVietorisCofiber where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Pointed open import Cubical.Data.Unit open import Cubical.HITs.MappingCones open import Cubical.HITs.Pushout open import Cubical.HITs.Susp open import Cubical.HITs.Wedge module _ {ℓX ℓB ℓC} {X : Pointed ℓX} {B : Type ℓB} {C : Type ℓC} (f : X .fst → B) (g : X .fst → C) where private Y : Pointed _ Y = (B , f (X .snd)) Z : Pointed _ Z = (C , g (X .snd)) wedgeToPushout : Y ⋁ Z → Pushout f g wedgeToPushout (inl y) = inl y wedgeToPushout (inr z) = inr z wedgeToPushout (push _ i) = push (pt X) i pushoutToSusp : Pushout f g → Susp (X .fst) pushoutToSusp (inl y) = north pushoutToSusp (inr z) = south pushoutToSusp (push x i) = merid x i {- Coherence lemma: To construct a function f : (c : Cone wedgeToPushout) → D c, we can always adjust the definition of (f (spoke (inr z) i)) so that there is a canonical choice for (f (spoke (push tt j) i)) -} module Helper {ℓD} {D : Cone wedgeToPushout → Type ℓD} (inj* : ∀ w → D (inj w)) (hub* : D hub) (inl* : ∀ y → PathP (λ i → D (spoke (inl y) i)) hub* (inj* (inl y))) (inr* : ∀ z → PathP (λ i → D (spoke (inr z) i)) hub* (inj* (inr z))) where cap : (i j : I) → D (spoke (push tt j) i) cap i j = fill (λ i → D (spoke (push tt j) (~ i))) (λ i → λ { (j = i0) → inl* (Y .snd) (~ i) ; (j = i1) → inr* (Z .snd) (~ i) }) (inS (inj* (push (X .snd) j))) (~ i) cap0 : (j : I) → D hub cap0 = cap i0 face-i≡0 : (k j : I) → D hub face-i≡0 k j = hfill (λ j → λ { (k = i0) → cap0 j ; (k = i1) → hub* }) (inS hub*) j inrFiller : ∀ z → (k i : I) → D (spoke (inr z) i) inrFiller z k i = hfill (λ k → λ { (i = i0) → face-i≡0 k i1 ; (i = i1) → inj* (inr z) }) (inS (inr* z i)) k fun : ∀ c → D c fun (inj w) = inj* w fun hub = hub* fun (spoke (inl y) i) = inl* y i fun (spoke (inr z) i) = inrFiller z i1 i fun (spoke (push tt j) i) = hcomp (λ k → λ { (i = i0) → face-i≡0 k j ; (i = i1) → inj* (push (X .snd) j) ; (j = i0) → inl* (Y .snd) i }) (cap i j) equiv : Cone wedgeToPushout ≃ Susp (X .fst) equiv = isoToEquiv (iso fwd bwd fwdBwd bwdFwd) where fwd : Cone wedgeToPushout → Susp (X .fst) fwd (inj w) = pushoutToSusp w fwd hub = north fwd (spoke (inl y) i) = north fwd (spoke (inr z) i) = merid (X .snd) i fwd (spoke (push tt j) i) = merid (X .snd) (i ∧ j) bwd : Susp (X .fst) → Cone wedgeToPushout bwd north = hub bwd south = hub bwd (merid x i) = hcomp (λ k → λ { (i = i0) → spoke (inl (f x)) (~ k) ; (i = i1) → spoke (inr (g x)) (~ k) }) (inj (push x i)) bwdPushout : (w : Pushout f g) → bwd (pushoutToSusp w) ≡ inj w bwdPushout (inl y) = spoke (inl y) bwdPushout (inr z) = spoke (inr z) bwdPushout (push x i) k = hfill (λ k → λ { (i = i0) → spoke (inl (f x)) (~ k) ; (i = i1) → spoke (inr (g x)) (~ k) }) (inS (inj (push x i))) (~ k) bwdMeridPt : refl ≡ cong bwd (merid (X .snd)) bwdMeridPt j i = hcomp (λ k → λ { (i = i0) → spoke (inl (Y .snd)) (~ k) ; (i = i1) → spoke (inr (Z .snd)) (~ k) ; (j = i0) → spoke (push _ i) (~ k) }) (inj (push (X .snd) i)) bwdFwd : (c : Cone wedgeToPushout) → bwd (fwd c) ≡ c bwdFwd = Helper.fun bwdPushout refl (λ y i k → spoke (inl y) (i ∧ k)) (λ z i k → hcomp (λ l → λ { (i = i0) → hub ; (i = i1) → spoke (inr z) k ; (k = i0) → bwdMeridPt l i ; (k = i1) → spoke (inr z) i }) (spoke (inr z) (i ∧ k))) fwdBwd : (s : Susp (X .fst)) → fwd (bwd s) ≡ s fwdBwd north = refl fwdBwd south = merid (X .snd) fwdBwd (merid a i) j = fill (λ _ → Susp (X .fst)) (λ j → λ { (i = i0) → north ; (i = i1) → merid (X .snd) (~ j) }) (inS (merid a i)) (~ j)
26.972222
98
0.481565
64208d29f79510bb7c5149f43d04c8a581bf5937
478
agda
Agda
test/asset/agda-stdlib-1.0/Data/Char.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Char.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Char.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Characters ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Char where ------------------------------------------------------------------------ -- Re-export base definitions and decidability of equality open import Data.Char.Base public open import Data.Char.Properties using (_≟_; _==_) public
29.875
72
0.395397
345afb6ff6d1a11487911561a3655f36d1697b9c
3,119
agda
Agda
src/Max.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
1
2022-02-13T05:43:25.000Z
2022-02-13T05:43:25.000Z
src/Max.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
null
null
null
src/Max.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
1
2019-12-07T16:12:50.000Z
2019-12-07T16:12:50.000Z
module Max where open import Data.Empty using (⊥-elim) open import Data.Fin open import Data.Nat hiding (_≤_) open import Function using (_∘_) open import Relation.Nullary variable n : ℕ -- from https://github.com/zmthy/recursive-types/tree/ftfjp16 -- RecursiveTypes.Inductive.Type -- adapted to use "variable" -- A proposition that the indexed number is the largest it can be, i.e. one less -- than its exclusive upper bound. data Max : Fin n → Set where max : Max {suc n} (fromℕ n) -- A lemma on Max: if a number is max, then one less than that number with a -- simultaneously lowered upper bound is also max. max-pre : {x : Fin (suc n)} → Max (suc x) → Max x max-pre max = max -- A lemma on Max: if a number is max, then one more than that number with a -- simultaneously increased upper bound is also max. max-suc : {x : Fin n} → Max x → Max (suc x) max-suc max = max -- Given a proof that a number is not max, reduce its lower bound by one, -- keeping the value of the number the same. reduce : {x : Fin (suc n)} → ¬ Max x → Fin n reduce {zero} {zero} ¬p = ⊥-elim (¬p max) reduce {zero} {suc ()} ¬p reduce {suc n} {zero} ¬p = zero reduce {suc n} {suc x} ¬p = suc (reduce {x = x} (¬p ∘ max-suc)) -- Max is a decidable proposition: just compare the number value to the value of -- the upper bound. max? : (x : Fin n) → Dec (Max x) max? {zero} () max? {suc zero} zero = yes max max? {suc zero} (suc ()) max? {suc (suc n)} zero = no (λ ()) max? {suc (suc n)} (suc x) with max? x max? {suc (suc n)} (suc .(fromℕ n)) | yes max = yes max max? {suc (suc n)} (suc x) | no ¬p = no (¬p ∘ max-pre) -- The reduce function preserves ≤. reduce₁ : ∀ {m} {x : Fin n} (¬p : ¬ Max (suc x)) → m ≤ x → suc m ≤ inject₁ (reduce ¬p) reduce₁ {m = zero} ¬p₁ z≤n = s≤s z≤n reduce₁ {m = suc m} {zero} ¬p () reduce₁ {m = suc m₁} {suc x₁} ¬p₁ (s≤s q₁) = s≤s (reduce₁ (λ z → ¬p₁ (max-suc z)) q₁) -- Injection is compatible with ordering. inject-≤ : {i j : Fin n} → inject₁ i ≤ inject₁ j → i ≤ j inject-≤ {i = zero} {zero} z≤n = z≤n inject-≤ {i = zero} {suc j} z≤n = z≤n inject-≤ {i = suc i} {zero} () inject-≤ {i = suc i} {suc j} (s≤s ii≤ij) = s≤s (inject-≤ ii≤ij) -- Technical lemma about reduce. lemma-reduce : {i j : Fin (suc n)} → (i≤j : inject₁ i ≤ inject₁ j) → (¬p : ¬ Max j) → i ≤ inject₁ (reduce ¬p) lemma-reduce {i = zero} i≤j ¬p = z≤n lemma-reduce {i = suc i} {suc j} (s≤s i≤j) ¬p = reduce₁ ¬p (inject-≤ i≤j) -- A lemma on ≤: if x ≤ y, then x ≤ suc y. suc-≤ : {x y : Fin n} → x ≤ y → inject₁ x ≤ suc y suc-≤ {x = zero} z≤n = z≤n suc-≤ {x = suc x} {zero} () suc-≤ {x = suc x} {suc y} (s≤s p) = s≤s (suc-≤ p) -- A lemma on ≤: if suc x ≤ y, then x ≤ y. pred-≤ : {x y : Fin n} → suc x ≤ inject₁ y → inject₁ x ≤ inject₁ y pred-≤ {y = zero} () pred-≤ {y = suc x} (s≤s p) = suc-≤ p -- A lemma on ≤: if x ≤ y, then for any z < x, z ≤ y. trans-< : {x y : Fin n} {z : Fin′ x} → x ≤ y → inject z ≤ y trans-< {x = zero} {z = ()} p trans-< {x = suc x} {zero} () trans-< {x = suc x} {suc y} {zero} (s≤s p) = z≤n trans-< {x = suc x} {suc y} {suc z} (s≤s p) = s≤s (trans-< p)
33.902174
80
0.575505
edb7c3a874e290d0a3bdfe6732ef5cbb59def3a8
3,179
agda
Agda
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- An example of how Data.Fin.Substitution can be used: a definition -- of substitution for the untyped λ-calculus, along with some lemmas ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Fin.Substitution.Example where open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Nat open import Data.Fin using (Fin) open import Data.Vec open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (Star; ε; _◅_) -- A representation of the untyped λ-calculus. Uses de Bruijn indices. infixl 9 _·_ data Tm (n : ℕ) : Set where var : (x : Fin n) → Tm n ƛ : (t : Tm (suc n)) → Tm n _·_ : (t₁ t₂ : Tm n) → Tm n -- Code for applying substitutions. module TmApp {ℓ} {T : ℕ → Set ℓ} (l : Lift T Tm) where open Lift l hiding (var) -- Applies a substitution to a term. infix 8 _/_ _/_ : ∀ {m n} → Tm m → Sub T m n → Tm n var x / ρ = lift (lookup ρ x) ƛ t / ρ = ƛ (t / ρ ↑) t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ) open Application (record { _/_ = _/_ }) using (_/✶_) -- Some lemmas about _/_. ƛ-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) → ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k) ƛ-/✶-↑✶ k ε = refl ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (ƛ-/✶-↑✶ k ρs) refl ·-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) → t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k) ·-/✶-↑✶ k ε = refl ·-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (·-/✶-↑✶ k ρs) refl tmSubst : TermSubst Tm tmSubst = record { var = var; app = TmApp._/_ } open TermSubst tmSubst hiding (var) -- Substitution lemmas. tmLemmas : TermLemmas Tm tmLemmas = record { termSubst = tmSubst ; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ } where module Lemma {T₁ T₂} {lift₁ : Lift T₁ Tm} {lift₂ : Lift T₂ Tm} where open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) /✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → (∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → ∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k /✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x /✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩ ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩ ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TmApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩ ƛ t /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.·-/✶-↑✶ _ k ρs₁ ⟩ (t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁) (/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩ (t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TmApp.·-/✶-↑✶ _ k ρs₂) ⟩ t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎ open TermLemmas tmLemmas public hiding (var)
33.114583
86
0.486631
4ecff1c93fb1a2a8fb0ca8e021beb476b94dcf4f
286
agda
Agda
test/Succeed/EmptyInductiveRecord.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/EmptyInductiveRecord.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/EmptyInductiveRecord.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --copatterns #-} module EmptyInductiveRecord where mutual data E : Set where e : F -> E record F : Set where inductive constructor c field f : E open F data ⊥ : Set where elim : E → ⊥ elim (e (c x)) = elim x elim' : E → ⊥ elim' (e y) = elim' (f y)
13
33
0.573427
4bb8434406315484e1eb24c1acc2770945dbd33a
1,508
agda
Agda
src/fot/LTC-PCF/Data/Nat/Inequalities.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/LTC-PCF/Data/Nat/Inequalities.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/LTC-PCF/Data/Nat/Inequalities.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Inequalities on partial natural numbers ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LTC-PCF.Data.Nat.Inequalities where open import LTC-PCF.Base infix 4 _<_ _≮_ _>_ _≯_ _≤_ _≰_ _≥_ _≱_ ------------------------------------------------------------------------------ -- The function terms. lth : D → D lth lt = lam (λ m → lam (λ n → if (iszero₁ n) then false else (if (iszero₁ m) then true else (lt · pred₁ m · pred₁ n)))) lt : D → D → D lt m n = fix lth · m · n le : D → D → D le m n = lt m (succ₁ n) gt : D → D → D gt m n = lt n m ge : D → D → D ge m n = le n m ------------------------------------------------------------------------ -- The relations. _<_ : D → D → Set m < n = lt m n ≡ true _≮_ : D → D → Set m ≮ n = lt m n ≡ false _>_ : D → D → Set m > n = gt m n ≡ true _≯_ : D → D → Set m ≯ n = gt m n ≡ false _≤_ : D → D → Set m ≤ n = le m n ≡ true _≰_ : D → D → Set m ≰ n = le m n ≡ false _≥_ : D → D → Set m ≥ n = ge m n ≡ true _≱_ : D → D → Set m ≱ n = ge m n ≡ false ------------------------------------------------------------------------------ -- The lexicographical order. Lexi : D → D → D → D → Set Lexi m n m' n' = m < m' ∨ m ≡ m' ∧ n < n'
22.507463
78
0.364058
5eb95bb3649b43d14347820312a4da12512abfad
894
agda
Agda
vendor/stdlib/src/Relation/Binary/PropositionalEquality/Core.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Relation/Binary/PropositionalEquality/Core.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Relation/Binary/PropositionalEquality/Core.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- Propositional equality ------------------------------------------------------------------------ -- This file contains some core definitions which are reexported by -- Relation.Binary.PropositionalEquality. module Relation.Binary.PropositionalEquality.Core where open import Relation.Binary.Core open import Relation.Binary.Consequences.Core ------------------------------------------------------------------------ -- Some properties sym : {a : Set} → Symmetric {a} _≡_ sym refl = refl trans : {a : Set} → Transitive {a} _≡_ trans refl refl = refl subst : {a : Set} → Substitutive {a} _≡_ subst P refl p = p resp₂ : ∀ {a} (∼ : Rel a) → ∼ Respects₂ _≡_ resp₂ _∼_ = subst⟶resp₂ _∼_ subst isEquivalence : ∀ {a} → IsEquivalence {a} _≡_ isEquivalence = record { refl = refl ; sym = sym ; trans = trans }
26.294118
72
0.521253
30d15c344e1a5cd0e16ef67f4cd150da843eee7f
173
agda
Agda
test/interaction/Issue2714.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2714.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2714.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-08-23, issue #2714 -- This file should compile from within the interaction mode -- without warning about missing main function. {-# OPTIONS --no-main #-}
24.714286
60
0.716763
736d9f11255104d02542789e5b656cb8ad2a1654
252
agda
Agda
test/interaction/Issue1926.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1926.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1926.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2019-04-10, re #3687, better test case for #1926 -- {-# OPTIONS -v interaction.contents.record:20 #-} module _ (Foo : Set) where open import Agda.Builtin.Sigma test : {A : Set} {B : A → Set} (r : Σ A B) → Set test r = {!r!} -- C-c C-o
22.909091
60
0.599206
43c6a8120de9a59139c5a587abfd3558888470cb
7,480
agda
Agda
Fields/CauchyCompletion/NearlyTotalOrder.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Fields/CauchyCompletion/NearlyTotalOrder.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Fields/CauchyCompletion/NearlyTotalOrder.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K --guardedness #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Setoids.Setoids open import Rings.Definition open import Rings.Orders.Partial.Definition open import Rings.Orders.Total.Definition open import Groups.Definition open import Groups.Lemmas open import Fields.Fields open import Sets.EquivalenceRelations open import Sequences open import Setoids.Orders.Partial.Definition open import Setoids.Orders.Total.Definition open import Functions.Definition open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Order.Lemmas open import Semirings.Definition module Fields.CauchyCompletion.NearlyTotalOrder {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where open Setoid S open SetoidTotalOrder (TotallyOrderedRing.total order) open SetoidPartialOrder pOrder open Equivalence eq open PartiallyOrderedRing pRing open Ring R open Group additiveGroup open Field F open import Fields.Orders.Lemmas {F = F} {pRing} (record { oRing = order }) open import Setoids.Orders.Partial.Sequences pOrder open import Rings.InitialRing R open import Rings.Orders.Partial.Lemmas pRing open import Rings.Orders.Total.Lemmas order open import Rings.Orders.Total.Cauchy order open import Rings.Orders.Total.AbsoluteValue order open import Fields.Lemmas F open import Fields.CauchyCompletion.Definition order F open import Fields.CauchyCompletion.Setoid order F open import Fields.CauchyCompletion.Group order F open import Fields.CauchyCompletion.Addition order F open import Fields.CauchyCompletion.Approximation order F open import Fields.CauchyCompletion.Comparison order F open import Fields.CauchyCompletion.PartiallyOrderedRing order F open import Fields.Orders.Total.Lemmas {F = F} (record { oRing = order }) makeIncreasingLemma : (a : A) (s : Sequence A) → Sequence A Sequence.head (makeIncreasingLemma a s) with totality a (Sequence.head s) ... | inl (inl x) = Sequence.head s ... | inl (inr x) = a ... | inr x = a Sequence.tail (makeIncreasingLemma a s) = makeIncreasingLemma (Sequence.head (makeIncreasingLemma a s)) (Sequence.tail s) makeIncreasingLemmaIsIncreasing : (a : A) (s : Sequence A) → WeaklyIncreasing (makeIncreasingLemma a s) makeIncreasingLemmaIsIncreasing a s zero with totality a (Sequence.head s) makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) with totality (Sequence.head s) (Sequence.head (Sequence.tail s)) makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inl (inl y) = inl y makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inl (inr y) = inr reflexive makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inr y = inr reflexive makeIncreasingLemmaIsIncreasing a s zero | inl (inr x) with totality a (Sequence.head (Sequence.tail s)) ... | inl (inl y) = inl y ... | inl (inr y) = inr reflexive ... | inr y = inr reflexive makeIncreasingLemmaIsIncreasing a s zero | inr x with totality a (Sequence.head (Sequence.tail s)) ... | inl (inl y) = inl y ... | inl (inr y) = inr reflexive ... | inr y = inr reflexive makeIncreasingLemmaIsIncreasing a s (succ m) = makeIncreasingLemmaIsIncreasing (Sequence.head (makeIncreasingLemma a s)) (Sequence.tail s) m makeIncreasing : Sequence A → Sequence A Sequence.head (makeIncreasing x) = Sequence.head x Sequence.tail (makeIncreasing x) = makeIncreasingLemma (Sequence.head x) (Sequence.tail x) makeIncreasingIsIncreasing : (a : Sequence A) → WeaklyIncreasing (makeIncreasing a) makeIncreasingIsIncreasing a zero with totality (Sequence.head a) (Sequence.head (Sequence.tail a)) ... | inl (inl x) = inl x ... | inl (inr x) = inr reflexive ... | inr x = inr reflexive makeIncreasingIsIncreasing a (succ m) = makeIncreasingLemmaIsIncreasing _ _ m approximateIncreasingSeqRaw : CauchyCompletion → Sequence A approximateIncreasingSeqRaw a = funcToSequence f where f : ℕ → A f n with allInvertible (fromN (succ n)) λ n=0 → irreflexive (<WellDefined reflexive n=0 (fromNPreservesOrder (0<1 nontrivial) (succIsPositive n))) ... | 1/n , prN = underlying (approximateBelow a 1/n (reciprocalPositive' (fromN (succ n)) 1/n (fromNPreservesOrder (0<1 nontrivial) (succIsPositive n)) prN)) approximateIncreasingSeq : CauchyCompletion → Sequence A approximateIncreasingSeq a = makeIncreasing (approximateIncreasingSeqRaw a) approximateIncreasingConverges : (a : CauchyCompletion) → cauchy (approximateIncreasingSeq a) approximateIncreasingConverges a e 0<e = {!!} approximateIncreasingIncreases : (a : CauchyCompletion) → WeaklyIncreasing (approximateIncreasingSeq a) approximateIncreasingIncreases a = makeIncreasingIsIncreasing (approximateIncreasingSeqRaw a) approximateIncreasing : CauchyCompletion → CauchyCompletion approximateIncreasing a = record { elts = approximateIncreasingSeq a ; converges = approximateIncreasingConverges a } approximateIncreasingEqual : (a : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid (approximateIncreasing a) a approximateIncreasingEqual a e 0<e = {!!} decideSign : (a : CauchyCompletion) → (Setoid._∼_ cauchyCompletionSetoid a (injection 0R) → False) → (a <Cr 0R) || (0R r<C a) decideSign a a!=0 = {!!} where private lemma : (a b : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid ((b +C (-C a)) +C a) b lemma a b = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {record { converges = CauchyCompletion.converges ((b +C (-C a)) +C a) }} {record { converges = CauchyCompletion.converges (b +C ((-C a) +C a)) }} {record { converges = CauchyCompletion.converges b }} (Group.+Associative' CGroup {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges (-C a) }} { record { converges = CauchyCompletion.converges a }}) (Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {record {converges = CauchyCompletion.converges (b +C ((-C a) +C a))}} {record { converges = CauchyCompletion.converges (b +C (injection 0R))}} {record {converges = CauchyCompletion.converges b}} (Group.+WellDefinedRight CGroup {record {converges = CauchyCompletion.converges b}} {record {converges = CauchyCompletion.converges ((-C a) +C a)}} {record { converges = CauchyCompletion.converges (injection 0R)}} (Group.invLeft CGroup {record { converges = CauchyCompletion.converges a }})) (Group.identRight CGroup {record { converges = CauchyCompletion.converges b }})) nearlyTotal : (a b : CauchyCompletion) → (Setoid._∼_ cauchyCompletionSetoid a b → False) → (a <C b) || (b <C a) nearlyTotal a b a!=b with decideSign (b +C (-C a)) λ bad → a!=b (Equivalence.symmetric (Setoid.eq cauchyCompletionSetoid) {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges a }} (transferToRight CGroup {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges a }} bad)) ... | inl x = inr (<CWellDefined (lemma a b) (Group.identLeft CGroup {record { converges = CauchyCompletion.converges a }}) (PartiallyOrderedRing.orderRespectsAddition CpOrderedRing (<CRelaxR x) a)) ... | inr x = inl (<CWellDefined (Group.identLeft CGroup {record { converges = CauchyCompletion.converges a }}) (lemma a b) (PartiallyOrderedRing.orderRespectsAddition CpOrderedRing (<CRelaxL x) a))
63.389831
1,096
0.762032
737b9ad03973181f2bad3c036b8947d4eeb59edb
3,081
agda
Agda
agda-stdlib-0.9/src/Data/Fin/Substitution/Example.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/Fin/Substitution/Example.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Fin/Substitution/Example.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- An example of how Data.Fin.Substitution can be used: a definition -- of substitution for the untyped λ-calculus, along with some lemmas ------------------------------------------------------------------------ module Data.Fin.Substitution.Example where open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Nat open import Data.Fin using (Fin) open import Data.Vec open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning open import Data.Star using (Star; ε; _◅_) -- A representation of the untyped λ-calculus. Uses de Bruijn indices. infixl 9 _·_ data Tm (n : ℕ) : Set where var : (x : Fin n) → Tm n ƛ : (t : Tm (suc n)) → Tm n _·_ : (t₁ t₂ : Tm n) → Tm n -- Code for applying substitutions. module TmApp {T} (l : Lift T Tm) where open Lift l hiding (var) -- Applies a substitution to a term. infix 8 _/_ _/_ : ∀ {m n} → Tm m → Sub T m n → Tm n var x / ρ = lift (lookup x ρ) ƛ t / ρ = ƛ (t / ρ ↑) t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ) open Application (record { _/_ = _/_ }) using (_/✶_) -- Some lemmas about _/_. ƛ-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) → ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k) ƛ-/✶-↑✶ k ε = refl ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (ƛ-/✶-↑✶ k ρs) refl ·-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) → t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k) ·-/✶-↑✶ k ε = refl ·-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (·-/✶-↑✶ k ρs) refl tmSubst : TermSubst Tm tmSubst = record { var = var; app = TmApp._/_ } open TermSubst tmSubst hiding (var) -- Substitution lemmas. tmLemmas : TermLemmas Tm tmLemmas = record { termSubst = tmSubst ; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ } where module Lemma {T₁ T₂} {lift₁ : Lift T₁ Tm} {lift₂ : Lift T₂ Tm} where open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) /✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → (∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → ∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k /✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x /✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩ ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩ ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TmApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩ ƛ t /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.·-/✶-↑✶ _ k ρs₁ ⟩ (t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁) (/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩ (t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TmApp.·-/✶-↑✶ _ k ρs₂) ⟩ t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎ open TermLemmas tmLemmas public hiding (var)
33.129032
86
0.480688
11f5d783179f1fd080a93d90e86bfec476ead14c
1,575
agda
Agda
plfa/part1/Negation.agda
UnsoundWitch/proofs
275ecc582b3a6a1da1af387251c6b4d74d9a5203
[ "MIT" ]
6
2021-01-03T03:29:40.000Z
2021-01-18T10:58:03.000Z
plfa/part1/Negation.agda
sym-cereal/proofs
275ecc582b3a6a1da1af387251c6b4d74d9a5203
[ "MIT" ]
null
null
null
plfa/part1/Negation.agda
sym-cereal/proofs
275ecc582b3a6a1da1af387251c6b4d74d9a5203
[ "MIT" ]
null
null
null
module plfa.part1.Negation where open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Data.Nat using (ℕ; zero; suc; _<_) open import Data.Empty using (⊥; ⊥-elim) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Product using (_×_; _,_) open import plfa.part1.Isomorphism using (_≃_; extensionality) ¬_ : Set → Set ¬ A = A → ⊥ ¬-elim : ∀ {A : Set} → ¬ A → A --- → ⊥ ¬-elim ¬x x = ¬x x infix 3 ¬_ ¬¬-intro : ∀ {A : Set} → A ----- → ¬ ¬ A ¬¬-intro x = λ{¬x → ¬x x} ¬¬¬-elim : ∀ {A : Set} → ¬ ¬ ¬ A ------- → ¬ A ¬¬¬-elim ¬¬¬x = λ x → ¬¬¬x (¬¬-intro x) contraposition : ∀ {A B : Set} → (A → B) ----------- → (¬ B → ¬ A) contraposition f ¬y x = ¬y (f x) _≢_ : ∀ {A : Set} → A → A → Set x ≢ y = ¬ (x ≡ y) _ : 1 ≢ 2 _ = λ() peano : ∀ {m : ℕ} → zero ≢ suc m peano = λ() id : ⊥ → ⊥ id x = x id′ : ⊥ → ⊥ id′ () assimilation : ∀ {A : Set} (¬x ¬x′ : ¬ A) → ¬x ≡ ¬x′ assimilation ¬x ¬x′ = extensionality (λ x → ⊥-elim (¬x x)) assimilation' : ∀ {A : Set} {¬x ¬x′ : ¬ A} → ¬x ≡ ¬x′ assimilation' {A} {¬x} {¬x′} = assimilation ¬x ¬x′ <-irreflexive : ∀ {n : ℕ} → ¬ (n < n) <-irreflexive (Data.Nat.s≤s x) = <-irreflexive x ⊎-dual-× : ∀ {A B : Set} → ¬ (A ⊎ B) ≃ (¬ A) × (¬ B) ⊎-dual-× = record { to = λ {x → (λ z → x (inj₁ z)) , λ x₁ → x (inj₂ x₁) }; from = λ { (fst , snd) (inj₁ x) → fst x ; (fst , snd) (inj₂ y) → snd y} ; from∘to = λ {¬x → assimilation'} ; to∘from = λ { (fst , snd) → refl} }
22.183099
72
0.445714
4ef8c324ec67a1ad615f590b68a564817162c1c2
11,464
agda
Agda
Syntax/Common/Context.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
2
2016-04-27T14:45:11.000Z
2018-04-06T02:10:49.000Z
Syntax/Common/Context.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
1
2020-07-24T12:53:30.000Z
2020-07-24T12:53:30.000Z
Syntax/Common/Context.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
1
2020-07-24T10:54:38.000Z
2020-07-24T10:54:38.000Z
module Common.Context where import Level open import Data.Nat as Nat open import Data.List as List import Level open import Relation.Binary.PropositionalEquality as PE hiding ([_]) open import Relation.Binary -- using (Setoid; Rel; IsEquivalence) open ≡-Reasoning open import Function as Fun hiding (_∘′_) open import Data.Sum as Sum hiding ([_,_]) -- open import Categories.Category using (Category) -- open import Common.SumProperties ------------------------- ---- Type contexts Ctx : Set → Set Ctx Ty = List Ty _↑_ : ∀{U} → Ctx U → U → Ctx U Γ ↑ a = Γ ++ a ∷ [] -- | De Bruijn variable indexing data Var {Ty : Set} : (Γ : Ctx Ty) (a : Ty) → Set where zero : ∀{Γ a} → Var (a ∷ Γ) a succ : ∀{Γ b} (a : Ty) → (x : Var Γ a) → Var (b ∷ Γ) a data _≅V_ {Ty} : ∀ {Γ Γ' : Ctx Ty} {a a' : Ty} → Var Γ a → Var Γ' a' → Set where zero : ∀ {Γ Γ'} {a a'} → zero {Γ = Γ} {a} ≅V zero {Γ = Γ'} {a'} succ : ∀ {Γ Γ'} {a a'} → ∀ {x : Var Γ a} {x' : Var Γ' a'} {b b' : Ty} → x ≅V x' → succ {b = b} a x ≅V succ {b = b'} a' x' Vrefl : ∀ {Ty} {Γ} {a : Ty} {x : Var Γ a} → x ≅V x Vrefl {x = zero} = zero Vrefl {x = succ _ t} = succ Vrefl Vsym : ∀ {Ty} {Γ Γ'} {a a' : Ty} {x : Var Γ a} {x' : Var Γ' a'} → x ≅V x' → x' ≅V x Vsym zero = zero Vsym {Ty} (succ [x]) = succ (Vsym [x]) Vtrans : ∀ {Ty} {Γ Γ' Γ''} {a a' a'' : Ty} {x : Var Γ a} {x' : Var Γ' a'} {x'' : Var Γ'' a''} → x ≅V x' → x' ≅V x'' → x ≅V x'' Vtrans zero zero = zero Vtrans (succ eq) (succ eq') = succ (Vtrans eq eq') -- Note: makes the equality homogeneous in Γ and a ≅V-setoid : ∀ {Ty} {Γ} {a : Ty} → Setoid _ _ ≅V-setoid {Ty} {Γ} {a} = record { Carrier = Var Γ a ; _≈_ = _≅V_ ; isEquivalence = record { refl = Vrefl ; sym = Vsym ; trans = Vtrans } } arr : ∀ {Ty} → (Γ Δ : Ctx Ty) → Set arr {Ty} Γ Δ = ∀ (a : Ty) → Var Γ a → Var Δ a _►_ = arr -- _▹_ = arr infix 4 _≡C_ record _≡C_ {Ty} {Γ Δ : Ctx Ty} (ρ : arr Γ Δ) (γ : arr Γ Δ) : Set where field ≡C-proof : ∀ {a} {x} → ρ a x ≡ γ a x open _≡C_ _≈_ = _≡C_ Crefl : ∀ {Ty} {Γ Δ : Ctx Ty} → Reflexive (_≡C_ {Γ = Γ} {Δ}) Crefl = record { ≡C-proof = PE.refl } Csym : ∀ {Ty} {Γ Δ : Ctx Ty} → Symmetric (_≡C_ {Γ = Γ} {Δ}) Csym p = record { ≡C-proof = PE.sym (≡C-proof p) } Ctrans : ∀ {Ty} {Γ Δ : Ctx Ty} → Transitive (_≡C_ {Γ = Γ} {Δ}) Ctrans p₁ p₂ = record { ≡C-proof = PE.trans (≡C-proof p₁) (≡C-proof p₂) } ≡C-equiv : ∀ {Ty} {Γ Δ : Ctx Ty} → IsEquivalence (_≡C_ {Γ = Γ} {Δ}) ≡C-equiv = record { refl = Crefl ; sym = Csym ; trans = Ctrans } ≡C-setoid : ∀ {Ty} {Γ Δ : Ctx Ty} → Setoid _ _ ≡C-setoid {_} {Γ} {Δ} = record { Carrier = arr Γ Δ ; _≈_ = _≡C_ ; isEquivalence = ≡C-equiv } _∘′_ : ∀ {Ty} {Γ Δ Ξ : Ctx Ty} (ρ : Δ ► Ξ) (γ : Γ ► Δ) → Γ ► Ξ _∘′_ ρ γ = λ a x → ρ a (γ a x) _●_ = _∘′_ ctx-id : ∀ {Ty} {Γ : Ctx Ty} → arr Γ Γ ctx-id = λ _ x → x comp-resp-≡C : ∀ {Ty} {Γ Δ Ξ : Ctx Ty} {ρ ρ' : arr Δ Ξ} {γ γ' : arr Γ Δ} → ρ ≡C ρ' → γ ≡C γ' → ρ ∘′ γ ≡C ρ' ∘′ γ' comp-resp-≡C {_} {Γ} {Δ} {Ξ} {ρ} {ρ'} {γ} {γ'} ρ≡ρ' γ≡γ' = record { ≡C-proof = p } where p : ∀ {a} {x} → (ρ ∘′ γ) a x ≡ (ρ' ∘′ γ') a x p {a} {x} = begin (ρ ∘′ γ) a x ≡⟨ refl ⟩ ρ a (γ a x) ≡⟨ cong (λ u → ρ a u) (≡C-proof γ≡γ') ⟩ ρ a (γ' a x) ≡⟨ ≡C-proof ρ≡ρ' ⟩ ρ' a (γ' a x) ≡⟨ refl ⟩ (ρ' ∘′ γ') a x ∎ {- -- | Contexts form a category ctx-cat : Set → Category Level.zero Level.zero Level.zero ctx-cat Ty = record { Obj = Ctx Ty ; _⇒_ = arr ; _≡_ = _≡C_ ; _∘_ = _∘′_ ; id = ctx-id ; assoc = record { ≡C-proof = refl } ; identityˡ = record { ≡C-proof = refl } ; identityʳ = record { ≡C-proof = refl } ; equiv = ≡C-equiv ; ∘-resp-≡ = comp-resp-≡C } -} ------------------------- ---- Coproduct structure on contexts {- _⊕_ : Ctx → Ctx → Ctx Γ₁ ⊕ Γ₂ = Γ₁ ++ Γ₂ in₁ : {Γ₁ Γ₂ : Ctx} → Γ₁ ▹ (Γ₁ ⊕ Γ₂) in₁ _ zero = zero in₁ a (succ .a x) = succ a (in₁ a x) in₂ : {{Γ₁ Γ₂ : Ctx}} → Γ₂ ▹ (Γ₁ ⊕ Γ₂) in₂ {{[]}} _ x = x in₂ {{b ∷ Γ₁}} a x = succ a (in₂ a x) split : {Γ₁ Γ₂ : Ctx} {a : Ty} → Var (Γ₁ ⊕ Γ₂) a → Var Γ₁ a ⊎ Var Γ₂ a split {[]} {Γ₂} x = inj₂ x split {a ∷ Γ₁'} {Γ₂} zero = inj₁ zero split {b ∷ Γ₁'} {Γ₂} {a} (succ .a y) = (Sum.map (succ a) (ctx-id a)) (split {Γ₁'} y) [_,_] : {Γ₁ Γ₂ Δ : Ctx} (f : Γ₁ ▹ Δ) (g : Γ₂ ▹ Δ) → ((Γ₁ ⊕ Γ₂) ▹ Δ) [_,_] {Γ} {Γ₂} f g a x = ([ f a , g a ]′) (split x) _-⊕-_ : {Γ Γ₂ Γ' Γ₂' : Ctx} (f : Γ ▹ Γ') (g : Γ₂ ▹ Γ₂') → ((Γ ⊕ Γ₂) ▹ (Γ' ⊕ Γ₂')) _-⊕-_ {Γ} {Γ₂} {Γ'} {Γ₂'} f g = [ in₁ ● f , in₂ {{Γ'}} {{Γ₂'}} ● g ] succ-distr-lemma : {Γ : Ctx} {a b : Ty} (Γ₂ : Ctx) (x : Var Γ a) → (in₁ {b ∷ Γ} ● succ {Γ}) a x ≡ (succ {Γ ⊕ Γ₂} ● in₁ {Γ} {Γ₂}) a x succ-distr-lemma Γ₂ x = refl split-lemma₁ : {a : Ty} (Γ₁ Γ₂ : Ctx) (x : Var Γ₁ a) → split {Γ₁} {Γ₂} (in₁ {Γ₁} a x) ≡ inj₁ x split-lemma₁ (tt ∷ Γ₁) Γ₂ zero = refl split-lemma₁ (tt ∷ Γ₁) Γ₂ (succ a x) = begin split {tt ∷ Γ₁} (in₁ {tt ∷ Γ₁} a (succ a x)) ≡⟨ refl ⟩ (Sum.map (succ a) id) (split (in₁ a x)) ≡⟨ cong (Sum.map (succ a) id) (split-lemma₁ Γ₁ Γ₂ x) ⟩ (Sum.map (succ a) id) (inj₁ x) ≡⟨ refl ⟩ inj₁ (succ a x) ∎ split-lemma₂ : {a : Ty} (Γ₁ Γ₂ : Ctx) (x : Var Γ₂ a) → split {Γ₁} {Γ₂} (in₂ a x) ≡ inj₂ x split-lemma₂ [] Γ₂ x = refl split-lemma₂ {a} (tt ∷ Γ₁) Γ₂ x = begin split {tt ∷ Γ₁} {Γ₂} (in₂ {{tt ∷ Γ₁}} a x) ≡⟨ refl ⟩ Sum.map (succ a) id (split (in₂ {{Γ₁}} a x)) ≡⟨ cong (λ u → Sum.map (succ a) id u) (split-lemma₂ Γ₁ Γ₂ x) ⟩ Sum.map (succ a) id (inj₂ x) ≡⟨ refl ⟩ inj₂ x ∎ split-lemma : (Γ₁ Γ₂ : Ctx) (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ in₁ {Γ₁} {Γ₂} a , in₂ a ]′ (split x) ≡ x split-lemma [] Γ₂ _ x = refl split-lemma (a ∷ Γ₁) Γ₂ .a zero = refl split-lemma (b ∷ Γ₁) Γ₂ a (succ .a x) = begin [ in₁ {b ∷ Γ₁} a , in₂ {{b ∷ Γ₁}} a ]′ (split (succ a x)) ≡⟨ refl ⟩ [ in₁ {b ∷ Γ₁} a , (succ {Γ₁ ⊕ Γ₂} ● in₂ {{Γ₁}} ) a ]′ (Sum.map (succ {Γ₁} a) id (split x)) ≡⟨ copair-sum-map-merge {f₁ = Var.succ {Γ₁} {b} a} (split x) ⟩ [ (in₁ {b ∷ Γ₁} ● succ {Γ₁}) a , (succ {Γ₁ ⊕ Γ₂} ● in₂) a ]′ (split x) ≡⟨ copair-cong {f = (in₁ {b ∷ Γ₁} ● succ {Γ₁}) a} (succ-distr-lemma Γ₂) (split x) ⟩ [ (succ {Γ₁ ⊕ Γ₂} ● in₁ {Γ₁}) a , (succ {Γ₁ ⊕ Γ₂} ● in₂) a ]′ (split x) ≡⟨ copair-distr {f = in₁ {Γ₁} {Γ₂} a} {h = succ {Γ₁ ⊕ Γ₂} a} (split x)⟩ (Var.succ {Γ₁ ⊕ Γ₂} {b} a ∘ [ in₁ {Γ₁} a , in₂ a ]′) (split x) ≡⟨ cong (succ {Γ₁ ⊕ Γ₂} {b} a) (split-lemma Γ₁ Γ₂ a x) ⟩ succ {Γ₁ ⊕ Γ₂} a x ∎ ⊕-is-coprod-arg : ∀{Γ₁ Γ₂ : Ctx} (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ in₁ {Γ₁} {Γ₂} , in₂ ] a x ≡ ctx-id a x ⊕-is-coprod-arg {Γ₁} {Γ₂} = split-lemma Γ₁ Γ₂ ⊕-is-coprod : ∀{Γ₁ Γ₂ : Ctx} → [ in₁ {Γ₁} {Γ₂} , in₂ ] ≡C ctx-id ⊕-is-coprod {Γ₁} = {!!} {- η-≡ {f₁ = [ in₁ {Γ₁} , in₂ ]} {f₂ = ctx-id} (λ (a : Ty) → η-≡ {f₁ = [ in₁ {Γ₁}, in₂ ] a} {f₂ = ctx-id a} (⊕-is-coprod-arg {Γ₁} a) ) -} ●-distr-copair₁ˡ : ∀{Γ₁ Γ₂ Δ : Ctx} (h : (Γ₁ ⊕ Γ₂) ▹ Δ) (a : Ty) (x : Var (Γ₁ ⊕ Γ₂) a) → [ h ● in₁ {Γ₁} {Γ₂} , h ● in₂ {{Γ₁}} {{Γ₂}} ] a x ≡ (h ● [ in₁ {Γ₁} {Γ₂} , in₂ ]) a x ●-distr-copair₁ˡ {Γ₁} {Γ₂} {Δ} h a x = begin [ h ● in₁ {Γ₁} , h ● in₂ ] a x ≡⟨ refl ⟩ ([ (h ● in₁ {Γ₁}) a , (h ● in₂) a ]′) (split x) ≡⟨ copair-distr {f = in₁ {Γ₁} a} {g = in₂ a} {h = h a} (split x) ⟩ (h ● [ in₁ {Γ₁} , in₂ ]) a x ∎ ●-distr-copairˡ : ∀{Γ₁ Γ₂ Δ : Ctx} (h : (Γ₁ ⊕ Γ₂) ▹ Δ) → [ h ● in₁ {Γ₁} {Γ₂} , h ● in₂ {{Γ₁}} {{Γ₂}} ] ≡ h ● [ in₁ {Γ₁} {Γ₂} , in₂ ] ●-distr-copairˡ {Γ₁} h = {!!} -- η-≡ (λ a → η-≡ (●-distr-copair₁ˡ {Γ₁} h a)) ⊕-is-coprod₁ : ∀{Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} {h : (Γ₁ ⊕ Γ₂) ▹ Δ} → h ● in₁ ≡C f → h ● in₂ ≡C g → [ f , g ] ≡C h ⊕-is-coprod₁ {Γ₁} {Γ₂} {Δ} {f} {g} {h} h●in₁≡f h●in₂≡g = record { ≡C-proof = p } where p : ∀ {a} {x} → [ f , g ] a x ≡ h a x p {a} {x} = begin [ f , g ] a x ≡⟨ refl ⟩ ([ f a , g a ]′) (split x) ≡⟨ cong (λ u → [ u , g a ]′ (split x)) {!!} ⟩ ([ (h ● in₁ {Γ₁}) a , g a ]′) (split x) ≡⟨ {!!} ⟩ h a x ∎ {- [ h ● in₁ {Γ₁} , g ] ≡⟨ cong (λ u → [ h ● in₁ {Γ₁} , u ]) (sym h●in₂≡g) ⟩ [ h ● in₁ {Γ₁} , h ● in₂ ] ≡⟨ ●-distr-copairˡ {Γ₁} h ⟩ h ● [ in₁ {Γ₁}, in₂ ] ≡⟨ cong (λ u → h ● u) (⊕-is-coprod {Γ₁}) ⟩ h ● ctx-id ≡⟨ refl ⟩ h -} commute-in₁-arg : ∀ {Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} (a : Ty) (x : Var Γ₁ a) → ([ f , g ] ● in₁) a x ≡ f a x commute-in₁-arg _ zero = refl commute-in₁-arg {b ∷ Γ₁} {Γ₂} {Δ} {f} {g} a (succ .a x) = begin ([ f , g ] ● in₁ {b ∷ Γ₁}) a (succ {Γ₁} a x) ≡⟨ refl ⟩ [ f , g ] a (succ {Γ₁ ⊕ Γ₂} a (in₁ {Γ₁} a x)) ≡⟨ refl ⟩ ([ f a , g a ]′) (split (succ {Γ₁ ⊕ Γ₂} a (in₁ {Γ₁} a x))) ≡⟨ refl ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ refl ⟩ (([ f a , g a ]′ ∘ (Sum.map (succ a) id)) (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ copair-sum-map-merge {f₁ = succ a} (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x)) ⟩ ([ (f ● succ) a , g a ]′ (split {Γ₁} {Γ₂} (in₁ {Γ₁} a x))) ≡⟨ cong ([ (f ● succ) a , g a ]′) (split-lemma₁ Γ₁ Γ₂ x) ⟩ f a (succ a x) ∎ commute-in₁ : (Γ₁ : Ctx) → (Γ₂ : Ctx) → {Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} → ([ f , g ] ● in₁) ≡C f commute-in₁ Γ₁ Γ₂ {Δ} {f} {g} = record { ≡C-proof = λ {a} {x} → commute-in₁-arg {f = f} {g} a x } commute-in₂-arg : ∀ {Γ₁ Γ₂ Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} (a : Ty) (x : Var Γ₂ a) → ([ f , g ] ● in₂) a x ≡ g a x commute-in₂-arg {[]} _ _ = refl commute-in₂-arg {tt ∷ Γ₁} {Γ₂} {Δ} {f} {g} a x = begin ([ f , g ] ● in₂ {{tt ∷ Γ₁}} ) a x ≡⟨ refl ⟩ [ f , g ] a ((succ ● in₂) a x) ≡⟨ refl ⟩ [ f a , g a ]′ (split {tt ∷ Γ₁} (succ a (in₂ a x))) ≡⟨ cong (λ u → [ f a , g a ]′ u) {x = split {tt ∷ Γ₁} (succ a (in₂ a x))} refl ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (split {Γ₁} (in₂ a x))) ≡⟨ cong (λ u → [ f a , g a ]′ (Sum.map (succ a) id u)) (split-lemma₂ Γ₁ Γ₂ x) ⟩ [ f a , g a ]′ ((Sum.map (succ a) id) (inj₂ x)) ≡⟨ copair-sum-map-merge {f₁ = succ {Γ₁} a} {f₂ = id} {g₁ = f a} {g₂ = g a} (inj₂ x) ⟩ [ (f ● succ) a , (g ● ctx-id) a ]′ (inj₂ x) ≡⟨ copair-elimʳ {f = (f ● succ) a} {g = (g ● ctx-id) a} x ⟩ g a x ∎ commute-in₂ : (Γ₁ : Ctx) → (Γ₂ : Ctx) → {Δ : Ctx} {f : Γ₁ ▹ Δ} {g : Γ₂ ▹ Δ} → ([ f , g ] ● in₂) ≡C g commute-in₂ Γ₁ Γ₂ {Δ} {f} {g} = record { ≡C-proof = λ {a} {x} → commute-in₂-arg {f = f} {g} a x } open import Categories.Object.Coproduct ctx-cat ctx-coproduct : ∀{Γ₁ Γ₂ : Ctx} → Coproduct Γ₁ Γ₂ ctx-coproduct {Γ₁} {Γ₂} = record { A+B = Γ₁ ⊕ Γ₂ ; i₁ = in₁ ; i₂ = in₂ ; [_,_] = [_,_] ; commute₁ = commute-in₁ Γ₁ Γ₂ ; commute₂ = commute-in₂ Γ₁ Γ₂ ; universal = ⊕-is-coprod₁ } open import Categories.Object.BinaryCoproducts ctx-cat ctx-bin-coproducts : BinaryCoproducts ctx-bin-coproducts = record { coproduct = ctx-coproduct } open BinaryCoproducts ctx-bin-coproducts -}
31.494505
87
0.436322
8b36c7f8da193d376790466aa9e558b2f97187bb
1,792
agda
Agda
SOAS/Families/Isomorphism.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
SOAS/Families/Isomorphism.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
SOAS/Families/Isomorphism.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Isomorphism of indexed families module SOAS.Families.Isomorphism {T} where open import SOAS.Common open import SOAS.Context {T} open import SOAS.Families.Core {T} open import Categories.Morphism 𝔽amilies public using () renaming ( _≅_ to _≅ₘ_ ; module ≅ to ≅ₘ ; ≅-setoid to ≅ₘ-setoid) -- Isomorphism between two families record FamIso (X Y : Family) : Set where -- Prove isomorphism of the families X and Y in the category 𝔽am from -- a proof of isomorphism of the sets X Γ and Y Γ for all contexts Γ. field iso : (Γ : Ctx) → X Γ ≅ₛ Y Γ -- Two directions of the isomorphism. iso⇒ : X ⇾ Y iso⇒ {Γ} = _≅ₛ_.from (iso Γ) iso⇐ : Y ⇾ X iso⇐ {Γ} = _≅ₛ_.to (iso Γ) -- Construct the isomorphism of families ≅ₘ : X ≅ₘ Y ≅ₘ = record { from = iso⇒ ; to = iso⇐ ; iso = record { isoˡ = λ {Γ}{x} → _≅ₛ_.isoˡ (iso Γ) ; isoʳ = λ {Γ}{x} → _≅ₛ_.isoʳ (iso Γ) } } ≅ₘ→FamIso : {X Y : Family} → X ≅ₘ Y → FamIso X Y ≅ₘ→FamIso p = record { iso = λ Γ → record { from = _≅ₘ_.from p ; to = _≅ₘ_.to p ; iso = record { isoˡ = _≅ₘ_.isoˡ p ; isoʳ = _≅ₘ_.isoʳ p } } } -- | Isomorphism of sorted families open import Categories.Morphism 𝔽amiliesₛ public using () renaming ( _≅_ to _≅̣ₘ_ ; module ≅ to ≅̣ₘ) -- Sorted family isomorphism gives a family isomorphism at each sort ≅̣ₘ→≅ₘ : {τ : T}{𝒳 𝒴 : Familyₛ} → 𝒳 ≅̣ₘ 𝒴 → 𝒳 τ ≅ₘ 𝒴 τ ≅̣ₘ→≅ₘ {τ} p = record { from = _≅̣ₘ_.from p ; to = _≅̣ₘ_.to p ; iso = record { isoˡ = _≅̣ₘ_.isoˡ p ; isoʳ = _≅̣ₘ_.isoʳ p } } -- Family isomorphism at each sort gives sorted family isomorphism ≅ₘ→≅̣ₘ : {𝒳 𝒴 : Familyₛ} → ({τ : T} → 𝒳 τ ≅ₘ 𝒴 τ) → 𝒳 ≅̣ₘ 𝒴 ≅ₘ→≅̣ₘ p = record { from = _≅ₘ_.from p ; to = _≅ₘ_.to p ; iso = record { isoˡ = _≅ₘ_.isoˡ p ; isoʳ = _≅ₘ_.isoʳ p } }
31.438596
83
0.583147
4b28620c665403c3d6c45763ba53e6ed9b53a0f8
843
agda
Agda
src/sets/nat/ordering/leq/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
20
2015-06-12T12:20:17.000Z
2022-02-01T11:25:54.000Z
src/sets/nat/ordering/leq/core.agda
pcapriotti/agda-base
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
[ "BSD-3-Clause" ]
4
2015-02-02T14:32:16.000Z
2016-10-26T11:57:26.000Z
src/sets/nat/ordering/leq/core.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 sets.nat.ordering.leq.core where open import decidable open import equality.core open import function.core open import sets.nat.core open import sets.empty data _≤_ : ℕ → ℕ → Set where z≤n : ∀ {n} → zero ≤ n s≤s : ∀ {m n} (p : m ≤ n) → suc m ≤ suc n ap-pred-≤ : ∀ {n m} → suc n ≤ suc m → n ≤ m ap-pred-≤ (s≤s p) = p refl≤ : {n : ℕ} → n ≤ n refl≤ {0} = z≤n refl≤ {suc n} = s≤s refl≤ ≡⇒≤ : {n m : ℕ} → n ≡ m → n ≤ m ≡⇒≤ refl = refl≤ suc≤ : ∀ {n} → n ≤ suc n suc≤ {0} = z≤n suc≤ {suc n} = s≤s suc≤ suc≰ : ∀ {n} → ¬ (suc n ≤ n) suc≰ {zero} () suc≰ {suc n} p = suc≰ (ap-pred-≤ p) trans≤ : ∀ {n m p} → n ≤ m → m ≤ p → n ≤ p trans≤ z≤n q = z≤n trans≤ (s≤s p) (s≤s q) = s≤s (trans≤ p q) antisym≤ : ∀ {n m} → n ≤ m → m ≤ n → n ≡ m antisym≤ z≤n z≤n = refl antisym≤ (s≤s p) (s≤s q) = ap suc (antisym≤ p q)
21.615385
48
0.502966
21a49d3d1e4b4ec804f7ea5280e0f0eeeaafa8da
2,515
agda
Agda
Cubical/ZCohomology/CohomologyRings/S0.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/ZCohomology/CohomologyRings/S0.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/ZCohomology/CohomologyRings/S0.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.ZCohomology.CohomologyRings.S0 where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Data.Bool open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz) open import Cubical.Data.Sigma open import Cubical.Data.Sum open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.AbGroup.Instances.DirectSum open import Cubical.Algebra.DirectSum.Base open import Cubical.Algebra.Ring open import Cubical.Algebra.Ring.DirectProd open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR) open import Cubical.Algebra.CommRing.FGIdeal open import Cubical.Algebra.CommRing.QuotientRing open import Cubical.Algebra.Polynomials.Multivariate.Base renaming (base to baseP) open import Cubical.Algebra.CommRing.Instances.MultivariatePoly open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ open import Cubical.HITs.Sn open import Cubical.ZCohomology.RingStructure.CohomologyRing open import Cubical.ZCohomology.CohomologyRings.Coproduct open import Cubical.ZCohomology.CohomologyRings.Unit ----------------------------------------------------------------------------- -- Warning -- H*(S0) is not Z[X]/X² -- It is Z[X]/X × Z[X]/X or Z[X] /(X² - X) -- Beware that H*(X ⊔ Y) ≅ H*(X) × H*(Y) -- Which would apply for H*(Unit ⊔ Unit) ----------------------------------------------------------------------------- -- Computation of the cohomology ring open RingEquivs Cohomology-Ring-S⁰P : RingEquiv (H*R (S₊ 0)) (DirectProd-Ring (CommRing→Ring ℤ[X]/X) (CommRing→Ring ℤ[X]/X)) Cohomology-Ring-S⁰P = compRingEquiv (CohomologyRing-Equiv (invIso Iso-⊤⊎⊤-Bool)) (compRingEquiv (CohomologyRing-Coproduct Unit Unit) (Coproduct-Equiv.Coproduct-Equiv-12 CohomologyRing-UnitP CohomologyRing-UnitP)) Cohomology-Ring-S⁰ℤ : RingEquiv (H*R (S₊ 0)) (DirectProd-Ring (CommRing→Ring ℤCR) (CommRing→Ring ℤCR)) Cohomology-Ring-S⁰ℤ = compRingEquiv (CohomologyRing-Equiv (invIso Iso-⊤⊎⊤-Bool)) (compRingEquiv (CohomologyRing-Coproduct Unit Unit) (Coproduct-Equiv.Coproduct-Equiv-12 CohomologyRing-Unitℤ CohomologyRing-Unitℤ))
44.122807
115
0.713718
2144703c977af7119befe73cbcab25f41ece21bc
117,070
agda
Agda
Agda/20-pullbacks.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
null
null
null
Agda/20-pullbacks.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
null
null
null
Agda/20-pullbacks.agda
hemangandhi/HoTT-Intro
09c710bf9c31ba88be144cc950bd7bc19c22a934
[ "CC-BY-4.0" ]
null
null
null
{-# OPTIONS --without-K --exact-split #-} module 20-pullbacks where import 19-fundamental-cover open 19-fundamental-cover public -- Section 13.1 Cartesian squares {- We introduce the basic concepts of this chapter: commuting squares, cospans, cones, and pullback squares. Pullback squares are also called cartesian squares. -} {- Commutativity of squares is expressed with a homotopy. -} coherence-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (top : C → B) (left : C → A) (right : B → X) (bottom : A → X) → UU (l3 ⊔ l4) coherence-square top left right bottom = (bottom ∘ left) ~ (right ∘ top) {- A cospan is a pair of functions with a common codomain. -} cospan : {l1 l2 : Level} (l : Level) (A : UU l1) (B : UU l2) → UU (l1 ⊔ (l2 ⊔ (lsuc l))) cospan l A B = Σ (UU l) (λ X → (A → X) × (B → X)) {- A cone on a cospan with a vertex C is a pair of functions from C into the domains of the maps in the cospan, equipped with a homotopy witnessing that the resulting square commutes. -} cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → UU l4 → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) cone {A = A} {B = B} f g C = Σ (C → A) (λ p → Σ (C → B) (λ q → coherence-square q p g f)) {- A map into the vertex of a cone induces a new cone. -} cone-map : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} {C' : UU l5} → cone f g C → (C' → C) → cone f g C' cone-map f g c h = pair ( (pr1 c) ∘ h) ( pair ( (pr1 (pr2 c)) ∘ h) ( (pr2 (pr2 c)) ·r h)) {- We introduce the universal property of pullbacks. -} universal-property-pullback : {l1 l2 l3 l4 : Level} (l : Level) {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} → cone f g C → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ (l4 ⊔ (lsuc l))))) universal-property-pullback l f g c = (C' : UU l) → is-equiv (cone-map f g {C' = C'} c) is-prop-universal-property-pullback : {l1 l2 l3 l4 : Level} (l : Level) {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → is-prop (universal-property-pullback l f g c) is-prop-universal-property-pullback l f g c = is-prop-Π (λ C' → is-subtype-is-equiv (cone-map f g c)) {- lower-universal-property-pullback : {l1 l2 l3 l4 : Level} (l l' : Level) {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → universal-property-pullback (l ⊔ l') f g c → universal-property-pullback l f g c lower-universal-property-pullback l l' f g c up-c C' = is-equiv-right-factor {!!} {!!} {!!} {!!} {!!} {!!} -} map-universal-property-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → universal-property-pullback l5 f g c → {C' : UU l5} (c' : cone f g C') → C' → C map-universal-property-pullback f g c up-c {C'} c' = inv-is-equiv (up-c C') c' eq-map-universal-property-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → (up-c : universal-property-pullback l5 f g c) → {C' : UU l5} (c' : cone f g C') → Id (cone-map f g c (map-universal-property-pullback f g c up-c c')) c' eq-map-universal-property-pullback f g c up-c {C'} c' = issec-inv-is-equiv (up-c C') c' {- Next we characterize the identity type of the type of cones with a given vertex C. Note that in the definition of htpy-cone we do not use pattern matching on the cones c and c'. This is to ensure that the type htpy-cone f g c c' is a Σ-type for any c and c', not just for c and c' of the form (pair p (pair q H)) and (pair p' (pair q' H')) respectively. -} coherence-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c c' : cone f g C) → (K : (pr1 c) ~ (pr1 c')) (L : (pr1 (pr2 c)) ~ (pr1 (pr2 c'))) → UU (l4 ⊔ l3) coherence-htpy-cone f g c c' K L = ( (pr2 (pr2 c)) ∙h (htpy-left-whisk g L)) ~ ( (htpy-left-whisk f K) ∙h (pr2 (pr2 c'))) htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} → cone f g C → cone f g C → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) htpy-cone f g c c' = Σ ( (pr1 c) ~ (pr1 c')) ( λ K → Σ ((pr1 (pr2 c)) ~ (pr1 (pr2 c'))) ( λ L → coherence-htpy-cone f g c c' K L)) reflexive-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → htpy-cone f g c c reflexive-htpy-cone f g c = pair refl-htpy (pair refl-htpy htpy-right-unit) htpy-cone-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c c' : cone f g C) → Id c c' → htpy-cone f g c c' htpy-cone-eq f g c .c refl = reflexive-htpy-cone f g c abstract is-contr-total-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → is-contr (Σ (cone f g C) (htpy-cone f g c)) is-contr-total-htpy-cone {A = A} {B} f g {C} (pair p (pair q H)) = is-contr-total-Eq-structure ( λ p' qH' K → Σ ( q ~ (pr1 qH')) ( coherence-htpy-cone f g (pair p (pair q H)) (pair p' qH') K)) ( is-contr-total-htpy p) ( pair p refl-htpy) ( is-contr-total-Eq-structure ( λ q' H' → coherence-htpy-cone f g ( pair p (pair q H)) ( pair p (pair q' H')) ( refl-htpy)) ( is-contr-total-htpy q) ( pair q refl-htpy) ( is-contr-equiv' ( Σ ((f ∘ p) ~ (g ∘ q)) (λ H' → H ~ H')) ( equiv-tot ( λ H' → equiv-htpy-concat htpy-right-unit H')) ( is-contr-total-htpy H))) abstract is-fiberwise-equiv-htpy-cone-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → is-fiberwise-equiv (htpy-cone-eq f g c) is-fiberwise-equiv-htpy-cone-eq f g {C = C} c = fundamental-theorem-id c ( htpy-cone-eq f g c c refl) ( is-contr-total-htpy-cone f g c) ( htpy-cone-eq f g c) equiv-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c c' : cone f g C) → Id c c' ≃ htpy-cone f g c c' equiv-htpy-cone f g c c' = pair (htpy-cone-eq f g c c') (is-fiberwise-equiv-htpy-cone-eq f g c c') {- The inverse of htpy-cone-eq is the map eq-htpy-cone. -} eq-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {g : B → X} {C : UU l4} (c c' : cone f g C) → htpy-cone f g c c' → Id c c' eq-htpy-cone {f = f} {g = g} c c' = inv-is-equiv (is-fiberwise-equiv-htpy-cone-eq f g c c') {- This completes our characterization of the identity type of the type of cones with a fixed vertex C. -} {- We now conclude the universal property of pullbacks as the following statement of contractibility. -} abstract is-contr-universal-property-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → universal-property-pullback l5 f g c → (C' : UU l5) (c' : cone f g C') → is-contr (Σ (C' → C) (λ h → htpy-cone f g (cone-map f g c h) c')) is-contr-universal-property-pullback {C = C} f g c up C' c' = is-contr-equiv' ( Σ (C' → C) (λ h → Id (cone-map f g c h) c')) ( equiv-tot (λ h → equiv-htpy-cone f g (cone-map f g c h) c')) ( is-contr-map-is-equiv (up C') c') {- Next we establish a '3-for-2' property for pullbacks. -} triangle-cone-cone : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l5} {f : A → X} {g : B → X} (c : cone f g C) (c' : cone f g C') (h : C' → C) (KLM : htpy-cone f g (cone-map f g c h) c') (D : UU l6) → (cone-map f g {C' = D} c') ~ ((cone-map f g c) ∘ (λ (k : D → C') → h ∘ k)) triangle-cone-cone {C' = C'} {f = f} {g = g} c c' h KLM D k = inv (ap ( λ t → cone-map f g {C' = D} t k) { x = (cone-map f g c h)} { y = c'} ( eq-htpy-cone (cone-map f g c h) c' KLM)) abstract is-equiv-up-pullback-up-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l5} (f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') (h : C' → C) (KLM : htpy-cone f g (cone-map f g c h) c') → ({l : Level} → universal-property-pullback l f g c) → ({l : Level} → universal-property-pullback l f g c') → is-equiv h is-equiv-up-pullback-up-pullback {C = C} {C' = C'} f g c c' h KLM up up' = is-equiv-is-equiv-postcomp h ( λ D → is-equiv-right-factor ( cone-map f g {C' = D} c') ( cone-map f g c) ( λ (k : D → C') → h ∘ k) ( triangle-cone-cone {C = C} {C' = C'} {f = f} {g = g} c c' h KLM D) ( up D) (up' D)) abstract is-equiv-up-pullback-up-pullback' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l4} (f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') → (h : C' → C) (KLM : htpy-cone f g (cone-map f g c h) c') → universal-property-pullback l4 f g c → universal-property-pullback l4 f g c' → is-equiv h is-equiv-up-pullback-up-pullback' {C = C} {C' = C'} f g c c' h KLM up-c up-c' = is-equiv-is-equiv-postcomp' h ( λ D → is-equiv-right-factor ( cone-map f g {C' = D} c') ( cone-map f g c) ( λ (k : D → C') → h ∘ k) ( triangle-cone-cone {C = C} {C' = C'} {f = f} {g = g} c c' h KLM D) (up-c D) (up-c' D)) abstract up-pullback-up-pullback-is-equiv : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l5} (f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') (h : C' → C) (KLM : htpy-cone f g (cone-map f g c h) c') → is-equiv h → ({l : Level} → universal-property-pullback l f g c) → ({l : Level} → universal-property-pullback l f g c') up-pullback-up-pullback-is-equiv f g c c' h KLM is-equiv-h up D = is-equiv-comp ( cone-map f g c') ( cone-map f g c) ( λ k → h ∘ k) ( triangle-cone-cone {f = f} {g = g} c c' h KLM D) ( is-equiv-postcomp-is-equiv h is-equiv-h D) ( up D) abstract up-pullback-is-equiv-up-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l5} (f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') (h : C' → C) (KLM : htpy-cone f g (cone-map f g c h) c') → ({l : Level} → universal-property-pullback l f g c') → is-equiv h → ({l : Level} → universal-property-pullback l f g c) up-pullback-is-equiv-up-pullback f g c c' h KLM up' is-equiv-h D = is-equiv-left-factor ( cone-map f g c') ( cone-map f g c) ( λ k → h ∘ k) ( triangle-cone-cone {f = f} {g = g} c c' h KLM D) ( up' D) ( is-equiv-postcomp-is-equiv h is-equiv-h D) {- This concludes the '3-for-2-property' of pullbacks. -} {- We establish the uniquely uniqueness of pullbacks. -} htpy-cone-map-universal-property-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {C : UU l4} (c : cone f g C) → (up-c : universal-property-pullback l5 f g c) → {C' : UU l5} (c' : cone f g C') → htpy-cone f g ( cone-map f g c (map-universal-property-pullback f g c up-c c')) ( c') htpy-cone-map-universal-property-pullback f g c up-c c' = htpy-cone-eq f g ( cone-map f g c (map-universal-property-pullback f g c up-c c')) ( c') ( eq-map-universal-property-pullback f g c up-c c') {- We describe the type of all pullbacks in a universe UU l. -} UU-pullback : {l1 l2 l3 : Level} (l : Level) {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → UU _ UU-pullback l f g = Σ (UU l) (λ C → Σ (cone f g C) (λ c → universal-property-pullback l f g c)) equiv-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → UU-pullback l4 f g → UU-pullback l5 f g → UU (l1 ⊔ l2 ⊔ l3 ⊔ l4 ⊔ l5) equiv-pullback f g (pair C (pair c is-pb-C)) P' = Σ ( (pr1 P') ≃ C) ( λ e → htpy-cone f g (cone-map f g c (map-equiv e)) (pr1 (pr2 P'))) reflexive-equiv-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (P : UU-pullback l4 f g) → equiv-pullback f g P P reflexive-equiv-pullback f g (pair C (pair c is-pb-C)) = pair (equiv-id C) (reflexive-htpy-cone f g c) equiv-pullback-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (P P' : UU-pullback l4 f g) → Id P P' → equiv-pullback f g P P' equiv-pullback-eq f g P .P refl = reflexive-equiv-pullback f g P is-contr-total-equiv-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (P : UU-pullback l4 f g) → is-contr (Σ (UU-pullback l4 f g) (equiv-pullback f g P)) is-contr-total-equiv-pullback f g (pair C (pair c is-pb-C)) = is-contr-total-Eq-structure ( λ C' t e → htpy-cone f g (cone-map f g c (map-equiv e)) (pr1 t)) ( is-contr-total-equiv' C) ( pair C (equiv-id C)) ( is-contr-total-Eq-substructure ( is-contr-total-htpy-cone f g c) ( is-prop-universal-property-pullback _ f g) ( c) ( reflexive-htpy-cone f g c) ( is-pb-C)) is-equiv-equiv-pullback-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (P Q : UU-pullback l4 f g) → is-equiv (equiv-pullback-eq f g P Q) is-equiv-equiv-pullback-eq f g P = fundamental-theorem-id P ( reflexive-equiv-pullback f g P) ( is-contr-total-equiv-pullback f g P) ( equiv-pullback-eq f g P) equiv-equiv-pullback-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (P P' : UU-pullback l4 f g) → Id P P' ≃ equiv-pullback f g P P' equiv-equiv-pullback-eq f g P P' = pair (equiv-pullback-eq f g P P') (is-equiv-equiv-pullback-eq f g P P') {- We show that pullbacks are uniquely unique, and indeed that the type of all pullbacks in any given universe level is a proposition. -} {- abstract uniquely-unique-pullback : { l1 l2 l3 l4 l5 : Level} { A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l5} ( f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') → ( up-c' : {l : Level} → universal-property-pullback l f g c') → ( up-c : {l : Level} → universal-property-pullback l f g c) → is-contr ( equiv-pullback f g (pair C (pair c up-c)) (pair C' (pair c' up-c'))) uniquely-unique-pullback {C = C} {C' = C'} f g c c' up-c' up-c = is-contr-total-Eq-substructure ( is-contr-universal-property-pullback f g c up-c C' c') ( is-subtype-is-equiv) ( map-universal-property-pullback f g c up-c c') ( htpy-cone-map-universal-property-pullback f g c up-c c') ( is-equiv-up-pullback-up-pullback f g c c' ( map-universal-property-pullback f g c up-c c') ( htpy-cone-map-universal-property-pullback f g c up-c c') up-c up-c') -} abstract uniquely-unique-pullback' : { l1 l2 l3 l4 : Level} { A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {C' : UU l4} ( f : A → X) (g : B → X) (c : cone f g C) (c' : cone f g C') → ( up-c' : universal-property-pullback l4 f g c') → ( up-c : universal-property-pullback l4 f g c) → is-contr ( equiv-pullback f g (pair C (pair c up-c)) (pair C' (pair c' up-c'))) uniquely-unique-pullback' {C = C} {C' = C'} f g c c' up-c' up-c = is-contr-total-Eq-substructure ( is-contr-universal-property-pullback f g c up-c C' c') ( is-subtype-is-equiv) ( map-universal-property-pullback f g c up-c c') ( htpy-cone-map-universal-property-pullback f g c up-c c') ( is-equiv-up-pullback-up-pullback' f g c c' ( map-universal-property-pullback f g c up-c c') ( htpy-cone-map-universal-property-pullback f g c up-c c') up-c up-c') is-prop-UU-pullback : {l1 l2 l3 : Level} (l : Level) {A : UU l1} {B : UU l2} {X : UU l3} ( f : A → X) (g : B → X) → is-prop (UU-pullback l f g) is-prop-UU-pullback l f g (pair C (pair c up-c)) (pair C' (pair c' up-c')) = is-contr-equiv ( equiv-pullback f g ( pair C (pair c up-c)) ( pair C' (pair c' up-c'))) ( equiv-equiv-pullback-eq f g ( pair C (pair c up-c)) ( pair C' (pair c' up-c'))) ( uniquely-unique-pullback' f g c c' up-c' up-c) -- Section 13.2 {- The canonical pullback is a type which can be equipped with a cone that satisfies the universal property of a pullback. -} canonical-pullback : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → UU ((l1 ⊔ l2) ⊔ l3) canonical-pullback {A = A} {B = B} f g = Σ A (λ x → Σ B (λ y → Id (f x) (g y))) {- We construct the maps and homotopies that are part of the cone structure of the canonical pullback. -} π₁ : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {g : B → X} → canonical-pullback f g → A π₁ = pr1 π₂ : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {g : B → X} → canonical-pullback f g → B π₂ t = pr1 (pr2 t) π₃ : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {g : B → X} → (f ∘ (π₁ {f = f} {g = g})) ~ (g ∘ (π₂ {f = f} {g = g})) π₃ t = pr2 (pr2 t) cone-canonical-pullback : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → cone f g (canonical-pullback f g) cone-canonical-pullback f g = pair π₁ (pair π₂ π₃) {- We show that the canonical pullback satisfies the universal property of a pullback. -} abstract universal-property-pullback-canonical-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → universal-property-pullback l4 f g (cone-canonical-pullback f g) universal-property-pullback-canonical-pullback f g C = is-equiv-comp ( cone-map f g (cone-canonical-pullback f g)) ( tot (λ p → choice-∞)) ( mapping-into-Σ) ( refl-htpy) ( is-equiv-mapping-into-Σ) ( is-equiv-tot-is-fiberwise-equiv ( λ p → is-equiv-choice-∞)) {- We characterize the identity type of the canonical pullback. -} Eq-canonical-pullback : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (t t' : canonical-pullback f g) → UU (l1 ⊔ (l2 ⊔ l3)) Eq-canonical-pullback f g (pair a bp) t' = let b = pr1 bp p = pr2 bp a' = pr1 t' b' = pr1 (pr2 t') p' = pr2 (pr2 t') in Σ (Id a a') (λ α → Σ (Id b b') (λ β → Id ((ap f α) ∙ p') (p ∙ (ap g β)))) reflexive-Eq-canonical-pullback : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (t : canonical-pullback f g) → Eq-canonical-pullback f g t t reflexive-Eq-canonical-pullback f g (pair a (pair b p)) = pair refl (pair refl (inv right-unit)) Eq-canonical-pullback-eq : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (t t' : canonical-pullback f g) → Id t t' → Eq-canonical-pullback f g t t' Eq-canonical-pullback-eq f g t .t refl = reflexive-Eq-canonical-pullback f g t abstract is-contr-total-Eq-canonical-pullback : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (t : canonical-pullback f g) → is-contr (Σ (canonical-pullback f g) (Eq-canonical-pullback f g t)) is-contr-total-Eq-canonical-pullback f g (pair a (pair b p)) = is-contr-total-Eq-structure ( λ a' bp' α → Σ (Id b (pr1 bp')) (λ β → Id ((ap f α) ∙ (pr2 bp')) (p ∙ (ap g β)))) ( is-contr-total-path a) ( pair a refl) ( is-contr-total-Eq-structure ( λ b' p' β → Id ((ap f refl) ∙ p') (p ∙ (ap g β))) ( is-contr-total-path b) ( pair b refl) ( is-contr-equiv' ( Σ (Id (f a) (g b)) (λ p' → Id p p')) ( equiv-tot ( λ p' → (equiv-concat' p' (inv right-unit)) ∘e (equiv-inv p p'))) ( is-contr-total-path p))) abstract is-equiv-Eq-canonical-pullback-eq : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (t t' : canonical-pullback f g) → is-equiv (Eq-canonical-pullback-eq f g t t') is-equiv-Eq-canonical-pullback-eq f g t = fundamental-theorem-id t ( reflexive-Eq-canonical-pullback f g t) ( is-contr-total-Eq-canonical-pullback f g t) ( Eq-canonical-pullback-eq f g t) eq-Eq-canonical-pullback : { l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} ( f : A → X) (g : B → X) {t t' : canonical-pullback f g} → ( α : Id (pr1 t) (pr1 t')) (β : Id (pr1 (pr2 t)) (pr1 (pr2 t'))) → ( Id ((ap f α) ∙ (pr2 (pr2 t'))) ((pr2 (pr2 t)) ∙ (ap g β))) → Id t t' eq-Eq-canonical-pullback f g {pair a (pair b p)} {pair a' (pair b' p')} α β γ = inv-is-equiv ( is-equiv-Eq-canonical-pullback-eq f g ( pair a (pair b p)) ( pair a' (pair b' p'))) ( pair α (pair β γ)) {- The gap map of a square is the map fron the vertex of the cone into the canonical pullback. -} gap : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → cone f g C → C → canonical-pullback f g gap f g c z = pair ((pr1 c) z) (pair ((pr1 (pr2 c)) z) ((pr2 (pr2 c)) z)) {- The proposition is-pullback is the assertion that the gap map is an equivalence. Note that this proposition is small, whereas the universal property is a large proposition. Of course, we will show below that the proposition is-pullback is equivalent to the universal property of pullbacks. -} is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → cone f g C → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) is-pullback f g c = is-equiv (gap f g c) {- We first establish that a cone is equal to the value of cone-map at its own gap map. -} htpy-cone-up-pullback-canonical-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → htpy-cone f g (cone-map f g (cone-canonical-pullback f g) (gap f g c)) c htpy-cone-up-pullback-canonical-pullback f g c = pair refl-htpy ( pair refl-htpy htpy-right-unit) {- We show that the universal property of the pullback implies that the gap map is an equivalence. -} abstract is-pullback-up-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → ({l : Level} → universal-property-pullback l f g c) → is-pullback f g c is-pullback-up-pullback f g c up = is-equiv-up-pullback-up-pullback f g ( cone-canonical-pullback f g) ( c) ( gap f g c) ( htpy-cone-up-pullback-canonical-pullback f g c) ( universal-property-pullback-canonical-pullback f g) ( up) {- We show that the universal property follows from the assumption that the the gap map is an equivalence. -} abstract up-pullback-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → ({l : Level} → universal-property-pullback l f g c) up-pullback-is-pullback f g c is-pullback-c = up-pullback-up-pullback-is-equiv f g ( cone-canonical-pullback f g) ( c) ( gap f g c) ( htpy-cone-up-pullback-canonical-pullback f g c) ( is-pullback-c) ( universal-property-pullback-canonical-pullback f g) -- Section 13.3 Fiber products {- We construct the cone for two maps into the unit type. -} cone-prod : {i j : Level} (A : UU i) (B : UU j) → cone (const A unit star) (const B unit star) (A × B) cone-prod A B = pair pr1 (pair pr2 refl-htpy) {- Cartesian products are a special case of pullbacks. -} inv-gap-prod : {i j : Level} (A : UU i) (B : UU j) → canonical-pullback (const A unit star) (const B unit star) → A × B inv-gap-prod A B (pair a (pair b p)) = pair a b issec-inv-gap-prod : {i j : Level} (A : UU i) (B : UU j) → ( ( gap (const A unit star) (const B unit star) (cone-prod A B)) ∘ ( inv-gap-prod A B)) ~ id issec-inv-gap-prod A B (pair a (pair b p)) = eq-Eq-canonical-pullback ( const A unit star) ( const B unit star) refl refl ( is-prop-is-contr' (is-prop-is-contr is-contr-unit star star) p refl) isretr-inv-gap-prod : {i j : Level} (A : UU i) (B : UU j) → ( ( inv-gap-prod A B) ∘ ( gap (const A unit star) (const B unit star) (cone-prod A B))) ~ id isretr-inv-gap-prod A B (pair a b) = eq-pair refl refl abstract is-pullback-prod : {i j : Level} (A : UU i) (B : UU j) → is-pullback (const A unit star) (const B unit star) (cone-prod A B) is-pullback-prod A B = is-equiv-has-inverse ( inv-gap-prod A B) ( issec-inv-gap-prod A B) ( isretr-inv-gap-prod A B) {- We conclude that cartesian products satisfy the universal property of pullbacks. -} abstract universal-property-pullback-prod : {i j : Level} (A : UU i) (B : UU j) → {l : Level} → universal-property-pullback l ( const A unit star) ( const B unit star) ( cone-prod A B) universal-property-pullback-prod A B = up-pullback-is-pullback ( const A unit star) ( const B unit star) ( cone-prod A B) ( is-pullback-prod A B) {- Similar as the above, but now for families of products. -} cone-fiberwise-prod : {l1 l2 l3 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → cone (pr1 {A = X} {B = P}) (pr1 {A = X} {B = Q}) (Σ X (λ x → (P x) × (Q x))) cone-fiberwise-prod P Q = pair ( tot (λ x → pr1)) ( pair ( tot (λ x → pr2)) ( refl-htpy)) {- We will show that the fiberwise product is a pullback by showing that the gap map is an equivalence. We do this by directly construct an inverse to the gap map. -} inv-gap-fiberwise-prod : {l1 l2 l3 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → canonical-pullback (pr1 {B = P}) (pr1 {B = Q}) → Σ X (λ x → (P x) × (Q x)) inv-gap-fiberwise-prod P Q (pair (pair x p) (pair (pair .x q) refl)) = pair x (pair p q) issec-inv-gap-fiberwise-prod : {l1 l2 l3 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → ((gap (pr1 {B = P}) (pr1 {B = Q}) (cone-fiberwise-prod P Q)) ∘ (inv-gap-fiberwise-prod P Q)) ~ id issec-inv-gap-fiberwise-prod P Q (pair (pair x p) (pair (pair .x q) refl)) = eq-pair refl (eq-pair refl refl) isretr-inv-gap-fiberwise-prod : {l1 l2 l3 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → ( ( inv-gap-fiberwise-prod P Q) ∘ ( gap (pr1 {B = P}) (pr1 {B = Q}) (cone-fiberwise-prod P Q))) ~ id isretr-inv-gap-fiberwise-prod P Q (pair x (pair p q)) = refl {- With all the pieces in place we conclude that the fiberwise product is a pullback. -} abstract is-pullback-fiberwise-prod : {l1 l2 l3 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → is-pullback (pr1 {A = X} {B = P}) (pr1 {A = X} {B = Q}) (cone-fiberwise-prod P Q) is-pullback-fiberwise-prod P Q = is-equiv-has-inverse ( inv-gap-fiberwise-prod P Q) ( issec-inv-gap-fiberwise-prod P Q) ( isretr-inv-gap-fiberwise-prod P Q) {- Furthermore we conclude that the fiberwise product satisfies the universal property of pullbacks. -} abstract universal-property-pullback-fiberwise-prod : {l1 l2 l3 l4 : Level} {X : UU l1} (P : X → UU l2) (Q : X → UU l3) → universal-property-pullback l4 (pr1 {B = P}) (pr1 {B = Q}) (cone-fiberwise-prod P Q) universal-property-pullback-fiberwise-prod P Q = up-pullback-is-pullback pr1 pr1 ( cone-fiberwise-prod P Q) ( is-pullback-fiberwise-prod P Q) {- We now generalize the above to arbitrary maps and their fibers. -} cone-total-prod-fibers : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → cone f g (Σ X (λ x → (fib f x) × (fib g x))) cone-total-prod-fibers f g = pair ( λ t → pr1 (pr1 (pr2 t))) ( pair ( λ t → pr1 (pr2 (pr2 t))) ( λ t → (pr2 (pr1 (pr2 t))) ∙ (inv (pr2 (pr2 (pr2 t)))))) cone-span : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l4} {B' : UU l5} {C : A' → B' → UU l6} (i : A' → A) (j : B' → B) (k : (x : A') (y : B') → C x y → Id (f (i x)) (g (j y))) → cone f g (Σ A' (λ x → Σ B' (C x))) cone-span f g i j k = pair ( λ t → i (pr1 t)) ( pair ( λ t → j (pr1 (pr2 t))) ( λ t → k (pr1 t) (pr1 (pr2 t)) (pr2 (pr2 t)))) abstract is-pullback-cone-span-is-equiv : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l4} {B' : UU l5} {C : A' → B' → UU l6} (i : A' → A) (j : B' → B) (k : (x' : A') (y' : B') → C x' y' → Id (f (i x')) (g (j y'))) → is-equiv i → is-equiv j → ((x : A') (y : B') → is-equiv (k x y)) → is-pullback f g (cone-span f g i j k) is-pullback-cone-span-is-equiv {B = B} f g i j k is-equiv-i is-equiv-j is-equiv-k = is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map ( λ x → Σ B (λ y → Id (f x) (g y))) ( i) ( λ x' → toto (λ y → Id (f (i x')) (g y)) j (k x')) ( is-equiv-i) ( λ x' → is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map ( λ y → Id (f (i x')) (g y)) ( j) ( k x') ( is-equiv-j) ( is-equiv-k x')) abstract is-pullback-total-prod-fibers : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → is-pullback f g (cone-total-prod-fibers f g) is-pullback-total-prod-fibers f g = is-equiv-comp ( gap f g (cone-total-prod-fibers f g)) ( gap f g (cone-span f g ( Σ-fib-to-domain f) ( Σ-fib-to-domain g) ( λ s t α → (pr2 (pr2 s)) ∙ (α ∙ (inv (pr2 (pr2 t))))))) ( gap ( pr1 {B = fib f}) ( pr1 {B = fib g}) ( cone-fiberwise-prod (fib f) (fib g))) ( λ t → refl) ( is-pullback-fiberwise-prod (fib f) (fib g)) ( is-pullback-cone-span-is-equiv f g ( Σ-fib-to-domain f) ( Σ-fib-to-domain g) ( λ s t α → (pr2 (pr2 s)) ∙ (α ∙ (inv (pr2 (pr2 t))))) ( is-equiv-Σ-fib-to-domain f) ( is-equiv-Σ-fib-to-domain g) ( λ s t → is-equiv-comp _ ( concat (pr2 (pr2 s)) (g (pr1 (pr2 t)))) ( concat' (pr1 s) (inv (pr2 (pr2 t)))) ( refl-htpy) ( is-equiv-concat' (pr1 s) (inv (pr2 (pr2 t)))) ( is-equiv-concat (pr2 (pr2 s)) (g (pr1 (pr2 t)))))) -- Section 13.4 Fibers as pullbacks square-fiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (b : B) → ( f ∘ (pr1 {B = λ x → Id (f x) b})) ~ ( (const unit B b) ∘ (const (fib f b) unit star)) square-fiber f b = pr2 cone-fiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (b : B) → cone f (const unit B b) (fib f b) cone-fiber f b = pair pr1 (pair (const (fib f b) unit star) (square-fiber f b)) abstract is-pullback-cone-fiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (b : B) → is-pullback f (const unit B b) (cone-fiber f b) is-pullback-cone-fiber f b = is-equiv-tot-is-fiberwise-equiv ( λ a → is-equiv-left-unit-law-Σ-map-gen (λ t → Id (f a) b) is-contr-unit star) abstract universal-property-pullback-cone-fiber : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (b : B) → universal-property-pullback l3 f (const unit B b) (cone-fiber f b) universal-property-pullback-cone-fiber {B = B} f b = up-pullback-is-pullback f (const unit B b) ( cone-fiber f b) ( is-pullback-cone-fiber f b) cone-fiber-fam : {l1 l2 : Level} {A : UU l1} (B : A → UU l2) (a : A) → cone (pr1 {B = B}) (const unit A a) (B a) cone-fiber-fam B a = pair (λ b → pair a b) (pair (const (B a) unit star) (λ b → refl)) abstract is-pullback-cone-fiber-fam : {l1 l2 : Level} {A : UU l1} (B : A → UU l2) → (a : A) → is-pullback (pr1 {B = B}) (const unit A a) (cone-fiber-fam B a) is-pullback-cone-fiber-fam {A = A} B a = is-equiv-comp ( gap (pr1 {B = B}) (const unit A a) (cone-fiber-fam B a)) ( gap (pr1 {B = B}) (const unit A a) (cone-fiber (pr1 {B = B}) a)) ( fib-pr1-fib-fam B a) ( λ y → refl) ( is-equiv-fib-pr1-fib-fam B a) ( is-pullback-cone-fiber pr1 a) -- Section 13.5 Fiberwise equivalences cone-subst : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (Q : B → UU l3) → cone f (pr1 {B = Q}) (Σ A (λ x → Q (f x))) cone-subst f Q = pair pr1 (pair (Σ-map-base-map f Q) (λ t → refl)) inv-gap-cone-subst : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (Q : B → UU l3) → canonical-pullback f (pr1 {B = Q}) → Σ A (λ x → Q (f x)) inv-gap-cone-subst f Q (pair x (pair (pair .(f x) q) refl)) = pair x q issec-inv-gap-cone-subst : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (Q : B → UU l3) → ((gap f (pr1 {B = Q}) (cone-subst f Q)) ∘ (inv-gap-cone-subst f Q)) ~ id issec-inv-gap-cone-subst f Q (pair x (pair (pair .(f x) q) refl)) = refl isretr-inv-gap-cone-subst : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (Q : B → UU l3) → ((inv-gap-cone-subst f Q) ∘ (gap f (pr1 {B = Q}) (cone-subst f Q))) ~ id isretr-inv-gap-cone-subst f Q (pair x q) = refl abstract is-pullback-cone-subst : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (Q : B → UU l3) → is-pullback f (pr1 {B = Q}) (cone-subst f Q) is-pullback-cone-subst f Q = is-equiv-has-inverse ( inv-gap-cone-subst f Q) ( issec-inv-gap-cone-subst f Q) ( isretr-inv-gap-cone-subst f Q) cone-toto : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4) (f : A → B) (g : (x : A) → (P x) → (Q (f x))) → cone f (pr1 {B = Q}) (Σ A P) cone-toto Q f g = pair pr1 (pair (toto Q f g) (λ t → refl)) abstract is-pullback-is-fiberwise-equiv : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4) (f : A → B) (g : (x : A) → (P x) → (Q (f x))) → is-fiberwise-equiv g → is-pullback f (pr1 {B = Q}) (cone-toto Q f g) is-pullback-is-fiberwise-equiv Q f g is-equiv-g = is-equiv-comp ( gap f pr1 (cone-toto Q f g)) ( gap f pr1 (cone-subst f Q)) ( tot g) ( λ t → refl) ( is-equiv-tot-is-fiberwise-equiv is-equiv-g) ( is-pullback-cone-subst f Q) abstract universal-property-pullback-is-fiberwise-equiv : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4) (f : A → B) (g : (x : A) → (P x) → (Q (f x))) → is-fiberwise-equiv g → universal-property-pullback l5 f (pr1 {B = Q}) (cone-toto Q f g) universal-property-pullback-is-fiberwise-equiv Q f g is-equiv-g = up-pullback-is-pullback f pr1 (cone-toto Q f g) ( is-pullback-is-fiberwise-equiv Q f g is-equiv-g) abstract is-fiberwise-equiv-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4) (f : A → B) (g : (x : A) → (P x) → (Q (f x))) → is-pullback f (pr1 {B = Q}) (cone-toto Q f g) → is-fiberwise-equiv g is-fiberwise-equiv-is-pullback Q f g is-pullback-cone-toto = is-fiberwise-equiv-is-equiv-tot g ( is-equiv-right-factor ( gap f pr1 (cone-toto Q f g)) ( gap f pr1 (cone-subst f Q)) ( tot g) ( λ t → refl) ( is-pullback-cone-subst f Q) ( is-pullback-cone-toto)) abstract is-fiberwise-equiv-universal-property-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4) (f : A → B) (g : (x : A) → (P x) → (Q (f x))) → ( {l : Level} → universal-property-pullback l f (pr1 {B = Q}) (cone-toto Q f g)) → is-fiberwise-equiv g is-fiberwise-equiv-universal-property-pullback Q f g up = is-fiberwise-equiv-is-pullback Q f g ( is-pullback-up-pullback f pr1 (cone-toto Q f g) up) fib-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → (x : A) → fib (pr1 c) x → fib g (f x) fib-square f g c x t = let p = pr1 c q = pr1 (pr2 c) H = pr2 (pr2 c) in pair (q (pr1 t) ) ((inv (H (pr1 t))) ∙ (ap f (pr2 t))) fib-square-id : {l1 l2 : Level} {B : UU l1} {X : UU l2} (g : B → X) (x : X) → fib-square id g (pair g (pair id refl-htpy)) x ~ id fib-square-id g .(g b) (pair b refl) = refl square-tot-fib-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → ( (gap f g c) ∘ (Σ-fib-to-domain (pr1 c))) ~ ( (tot (λ a → tot (λ b → inv))) ∘ (tot (fib-square f g c))) square-tot-fib-square f g c (pair .((pr1 c) x) (pair x refl)) = let p = pr1 c q = pr1 (pr2 c) H = pr2 (pr2 c) in eq-pair refl ( eq-pair refl ( inv ((ap inv right-unit) ∙ (inv-inv (H x))))) abstract is-fiberwise-equiv-fib-square-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-fiberwise-equiv (fib-square f g c) is-fiberwise-equiv-fib-square-is-pullback f g c pb = let p = pr1 c q = pr1 (pr2 c) H = pr2 (pr2 c) in is-fiberwise-equiv-is-equiv-tot ( fib-square f g c) ( is-equiv-top-is-equiv-bottom-square ( Σ-fib-to-domain p) ( tot (λ x → tot (λ y → inv))) ( tot (fib-square f g c)) ( gap f g c) ( square-tot-fib-square f g c) ( is-equiv-Σ-fib-to-domain p) ( is-equiv-tot-is-fiberwise-equiv ( λ x → is-equiv-tot-is-fiberwise-equiv ( λ y → is-equiv-inv (g y) (f x)))) ( pb)) abstract is-pullback-is-fiberwise-equiv-fib-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-fiberwise-equiv (fib-square f g c) → is-pullback f g c is-pullback-is-fiberwise-equiv-fib-square f g c is-equiv-fsq = let p = pr1 c q = pr1 (pr2 c) H = pr2 (pr2 c) in is-equiv-bottom-is-equiv-top-square ( Σ-fib-to-domain p) ( tot (λ x → tot (λ y → inv))) ( tot (fib-square f g c)) ( gap f g c) ( square-tot-fib-square f g c) ( is-equiv-Σ-fib-to-domain p) ( is-equiv-tot-is-fiberwise-equiv ( λ x → is-equiv-tot-is-fiberwise-equiv ( λ y → is-equiv-inv (g y) (f x)))) ( is-equiv-tot-is-fiberwise-equiv is-equiv-fsq) abstract is-trunc-is-pullback : {l1 l2 l3 l4 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-trunc-map k g → is-trunc-map k (pr1 c) is-trunc-is-pullback k f g c pb is-trunc-g a = is-trunc-is-equiv k ( fib g (f a)) ( fib-square f g c a) ( is-fiberwise-equiv-fib-square-is-pullback f g c pb a) (is-trunc-g (f a)) abstract is-emb-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-emb g → is-emb (pr1 c) is-emb-is-pullback f g c pb is-emb-g = is-emb-is-prop-map ( pr1 c) ( is-trunc-is-pullback neg-one-𝕋 f g c pb (is-prop-map-is-emb g is-emb-g)) abstract is-equiv-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-equiv g → is-pullback f g c → is-equiv (pr1 c) is-equiv-is-pullback f g c is-equiv-g pb = is-equiv-is-contr-map ( is-trunc-is-pullback neg-two-𝕋 f g c pb ( is-contr-map-is-equiv is-equiv-g)) abstract is-pullback-is-equiv : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-equiv g → is-equiv (pr1 c) → is-pullback f g c is-pullback-is-equiv f g c is-equiv-g is-equiv-p = is-pullback-is-fiberwise-equiv-fib-square f g c ( λ a → is-equiv-is-contr ( fib-square f g c a) ( is-contr-map-is-equiv is-equiv-p a) ( is-contr-map-is-equiv is-equiv-g (f a))) -- Section 13.6 The pullback pasting property coherence-square-comp-horizontal : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (top-left : A → B) (top-right : B → C) (left : A → X) (mid : B → Y) (right : C → Z) (bottom-left : X → Y) (bottom-right : Y → Z) → coherence-square top-left left mid bottom-left → coherence-square top-right mid right bottom-right → coherence-square (top-right ∘ top-left) left right (bottom-right ∘ bottom-left) coherence-square-comp-horizontal top-left top-right left mid right bottom-left bottom-right sq-left sq-right = (bottom-right ·l sq-left) ∙h (sq-right ·r top-left) coherence-square-comp-vertical : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (top : A → X) (left-top : A → B) (right-top : X → Y) (mid : B → Y) (left-bottom : B → C) (right-bottom : Y → Z) (bottom : C → Z) → coherence-square top left-top right-top mid → coherence-square mid left-bottom right-bottom bottom → coherence-square top (left-bottom ∘ left-top) (right-bottom ∘ right-top) bottom coherence-square-comp-vertical top left-top right-top mid left-bottom right-bottom bottom sq-top sq-bottom = (sq-bottom ·r left-top) ∙h (right-bottom ·l sq-top) cone-comp-horizontal : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (i : X → Y) (j : Y → Z) (h : C → Z) → (c : cone j h B) → (cone i (pr1 c) A) → cone (j ∘ i) h A cone-comp-horizontal i j h c d = pair ( pr1 d) ( pair ( (pr1 (pr2 c)) ∘ (pr1 (pr2 d))) ( coherence-square-comp-horizontal (pr1 (pr2 d)) (pr1 (pr2 c)) (pr1 d) (pr1 c) h i j (pr2 (pr2 d)) (pr2 (pr2 c)))) cone-comp-vertical : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (f : C → Z) (g : Y → Z) (h : X → Y) → (c : cone f g B) → cone (pr1 (pr2 c)) h A → cone f (g ∘ h) A cone-comp-vertical f g h c d = pair ( (pr1 c) ∘ (pr1 d)) ( pair ( pr1 (pr2 d)) ( coherence-square-comp-vertical ( pr1 (pr2 d)) (pr1 d) h (pr1 (pr2 c)) (pr1 c) g f ( pr2 (pr2 d)) (pr2 (pr2 c)))) fib-square-comp-horizontal : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (i : X → Y) (j : Y → Z) (h : C → Z) → (c : cone j h B) (d : cone i (pr1 c) A) → (x : X) → ( fib-square (j ∘ i) h (cone-comp-horizontal i j h c d) x) ~ ( (fib-square j h c (i x)) ∘ (fib-square i (pr1 c) d x)) fib-square-comp-horizontal i j h c d .(pr1 d a) (pair a refl) = let f = pr1 d k = pr1 (pr2 d) H = pr2 (pr2 d) g = pr1 c l = pr1 (pr2 c) K = pr2 (pr2 c) in eq-pair refl ( ( ap ( concat' (h (l (k a))) refl) ( distributive-inv-concat (ap j (H a)) (K (k a)))) ∙ ( ( assoc (inv (K (k a))) (inv (ap j (H a))) refl) ∙ ( ap ( concat (inv (K (k a))) (j (i (f a)))) ( ( ap (concat' (j (g (k a))) refl) (inv (ap-inv j (H a)))) ∙ ( inv (ap-concat j (inv (H a)) refl)))))) fib-square-comp-vertical : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (f : C → Z) (g : Y → Z) (h : X → Y) → (c : cone f g B) (d : cone (pr1 (pr2 c)) h A) (x : C) → ( ( fib-square f (g ∘ h) (cone-comp-vertical f g h c d) x) ∘ ( inv-map-fib-comp (pr1 c) (pr1 d) x)) ~ ( ( inv-map-fib-comp g h (f x)) ∘ ( toto ( λ t → fib h (pr1 t)) ( fib-square f g c x) ( λ t → fib-square (pr1 (pr2 c)) h d (pr1 t)))) fib-square-comp-vertical f g h (pair p (pair q H)) (pair p' (pair q' H')) .(p (p' a)) (pair (pair .(p' a) refl) (pair a refl)) = eq-pair refl ( ( right-unit) ∙ ( ( distributive-inv-concat (H (p' a)) (ap g (H' a))) ∙ ( ( ap ( concat (inv (ap g (H' a))) (f (p (p' a)))) ( inv right-unit)) ∙ ( ap ( concat' (g (h (q' a))) ( pr2 ( fib-square f g ( pair p (pair q H)) ( p (p' a)) ( pair (p' a) refl)))) ( ( inv (ap-inv g (H' a))) ∙ ( ap (ap g) (inv right-unit))))))) abstract is-pullback-rectangle-is-pullback-left-square : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (i : X → Y) (j : Y → Z) (h : C → Z) (c : cone j h B) (d : cone i (pr1 c) A) → is-pullback j h c → is-pullback i (pr1 c) d → is-pullback (j ∘ i) h (cone-comp-horizontal i j h c d) is-pullback-rectangle-is-pullback-left-square i j h c d is-pb-c is-pb-d = is-pullback-is-fiberwise-equiv-fib-square (j ∘ i) h ( cone-comp-horizontal i j h c d) ( λ x → is-equiv-comp ( fib-square (j ∘ i) h (cone-comp-horizontal i j h c d) x) ( fib-square j h c (i x)) ( fib-square i (pr1 c) d x) ( fib-square-comp-horizontal i j h c d x) ( is-fiberwise-equiv-fib-square-is-pullback i (pr1 c) d is-pb-d x) ( is-fiberwise-equiv-fib-square-is-pullback j h c is-pb-c (i x))) abstract is-pullback-left-square-is-pullback-rectangle : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (i : X → Y) (j : Y → Z) (h : C → Z) (c : cone j h B) (d : cone i (pr1 c) A) → is-pullback j h c → is-pullback (j ∘ i) h (cone-comp-horizontal i j h c d) → is-pullback i (pr1 c) d is-pullback-left-square-is-pullback-rectangle i j h c d is-pb-c is-pb-rect = is-pullback-is-fiberwise-equiv-fib-square i (pr1 c) d ( λ x → is-equiv-right-factor ( fib-square (j ∘ i) h (cone-comp-horizontal i j h c d) x) ( fib-square j h c (i x)) ( fib-square i (pr1 c) d x) ( fib-square-comp-horizontal i j h c d x) ( is-fiberwise-equiv-fib-square-is-pullback j h c is-pb-c (i x)) ( is-fiberwise-equiv-fib-square-is-pullback (j ∘ i) h ( cone-comp-horizontal i j h c d) is-pb-rect x)) abstract is-pullback-top-is-pullback-rectangle : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (f : C → Z) (g : Y → Z) (h : X → Y) → (c : cone f g B) (d : cone (pr1 (pr2 c)) h A) → is-pullback f g c → is-pullback f (g ∘ h) (cone-comp-vertical f g h c d) → is-pullback (pr1 (pr2 c)) h d is-pullback-top-is-pullback-rectangle f g h c d is-pb-c is-pb-dc = is-pullback-is-fiberwise-equiv-fib-square (pr1 (pr2 c)) h d ( λ x → is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map ( λ t → fib h (pr1 t)) ( fib-square f g c ((pr1 c) x)) ( λ t → fib-square (pr1 (pr2 c)) h d (pr1 t)) ( is-fiberwise-equiv-fib-square-is-pullback f g c is-pb-c ((pr1 c) x)) ( is-equiv-top-is-equiv-bottom-square ( inv-map-fib-comp (pr1 c) (pr1 d) ((pr1 c) x)) ( inv-map-fib-comp g h (f ((pr1 c) x))) ( toto ( λ t → fib h (pr1 t)) ( fib-square f g c ((pr1 c) x)) ( λ t → fib-square (pr1 (pr2 c)) h d (pr1 t))) ( fib-square f (g ∘ h) (cone-comp-vertical f g h c d) ((pr1 c) x)) ( fib-square-comp-vertical f g h c d ((pr1 c) x)) ( is-equiv-inv-map-fib-comp (pr1 c) (pr1 d) ((pr1 c) x)) ( is-equiv-inv-map-fib-comp g h (f ((pr1 c) x))) ( is-fiberwise-equiv-fib-square-is-pullback f (g ∘ h) ( cone-comp-vertical f g h c d) is-pb-dc ((pr1 c) x))) ( pair x refl)) abstract is-pullback-rectangle-is-pullback-top : {l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} (f : C → Z) (g : Y → Z) (h : X → Y) → (c : cone f g B) (d : cone (pr1 (pr2 c)) h A) → is-pullback f g c → is-pullback (pr1 (pr2 c)) h d → is-pullback f (g ∘ h) (cone-comp-vertical f g h c d) is-pullback-rectangle-is-pullback-top f g h c d is-pb-c is-pb-d = is-pullback-is-fiberwise-equiv-fib-square f (g ∘ h) ( cone-comp-vertical f g h c d) ( λ x → is-equiv-bottom-is-equiv-top-square ( inv-map-fib-comp (pr1 c) (pr1 d) x) ( inv-map-fib-comp g h (f x)) ( toto ( λ t → fib h (pr1 t)) ( fib-square f g c x) ( λ t → fib-square (pr1 (pr2 c)) h d (pr1 t))) ( fib-square f (g ∘ h) (cone-comp-vertical f g h c d) x) ( fib-square-comp-vertical f g h c d x) ( is-equiv-inv-map-fib-comp (pr1 c) (pr1 d) x) ( is-equiv-inv-map-fib-comp g h (f x)) ( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map ( λ t → fib h (pr1 t)) ( fib-square f g c x) ( λ t → fib-square (pr1 (pr2 c)) h d (pr1 t)) ( is-fiberwise-equiv-fib-square-is-pullback f g c is-pb-c x) ( λ t → is-fiberwise-equiv-fib-square-is-pullback (pr1 (pr2 c)) h d is-pb-d (pr1 t)))) -- Section 13.7 Descent for coproducts and Σ-types fib-functor-coprod-inl-fib : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (x : A) → fib f x → fib (functor-coprod f g) (inl x) fib-functor-coprod-inl-fib f g x (pair a' p) = pair (inl a') (ap inl p) fib-fib-functor-coprod-inl : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (x : A) → fib (functor-coprod f g) (inl x) → fib f x fib-fib-functor-coprod-inl f g x (pair (inl a') p) = pair a' (map-compute-eq-coprod-inl-inl (f a') x p) fib-fib-functor-coprod-inl f g x (pair (inr b') p) = ind-empty {P = λ t → fib f x} ( map-compute-eq-coprod-inr-inl (g b') x p) issec-fib-fib-functor-coprod-inl : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (x : A) → ( (fib-functor-coprod-inl-fib f g x) ∘ ( fib-fib-functor-coprod-inl f g x)) ~ id issec-fib-fib-functor-coprod-inl f g .(f a') (pair (inl a') refl) = eq-pair refl ( ap (ap inl) ( isretr-inv-is-equiv ( is-equiv-map-raise _ (Id (f a') (f a'))) refl)) issec-fib-fib-functor-coprod-inl f g x (pair (inr b') p) = ind-empty { P = λ t → Id ( fib-functor-coprod-inl-fib f g x ( fib-fib-functor-coprod-inl f g x (pair (inr b') p))) ( pair (inr b') p)} ( map-compute-eq-coprod-inr-inl (g b') x p) isretr-fib-fib-functor-coprod-inl : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (x : A) → ( (fib-fib-functor-coprod-inl f g x) ∘ ( fib-functor-coprod-inl-fib f g x)) ~ id isretr-fib-fib-functor-coprod-inl f g .(f a') (pair a' refl) = eq-pair refl ( isretr-inv-is-equiv (is-equiv-map-raise _ (Id (f a') (f a'))) refl) abstract is-equiv-fib-functor-coprod-inl-fib : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (x : A) → is-equiv (fib-functor-coprod-inl-fib f g x) is-equiv-fib-functor-coprod-inl-fib f g x = is-equiv-has-inverse ( fib-fib-functor-coprod-inl f g x) ( issec-fib-fib-functor-coprod-inl f g x) ( isretr-fib-fib-functor-coprod-inl f g x) fib-functor-coprod-inr-fib : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (y : B) → fib g y → fib (functor-coprod f g) (inr y) fib-functor-coprod-inr-fib f g y (pair b' p) = pair (inr b') (ap inr p) fib-fib-functor-coprod-inr : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (y : B) → fib (functor-coprod f g) (inr y) → fib g y fib-fib-functor-coprod-inr f g y (pair (inl a') p) = ind-empty {P = λ t → fib g y} ( map-compute-eq-coprod-inl-inr (f a') y p) fib-fib-functor-coprod-inr f g y (pair (inr b') p) = pair b' (map-compute-eq-coprod-inr-inr (g b') y p) issec-fib-fib-functor-coprod-inr : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (y : B) → ( (fib-functor-coprod-inr-fib f g y) ∘ ( fib-fib-functor-coprod-inr f g y)) ~ id issec-fib-fib-functor-coprod-inr f g .(g b') (pair (inr b') refl) = eq-pair refl ( ap (ap inr) ( isretr-inv-is-equiv ( is-equiv-map-raise _ (Id (g b') (g b'))) refl)) issec-fib-fib-functor-coprod-inr f g y (pair (inl a') p) = ind-empty { P = λ t → Id ( fib-functor-coprod-inr-fib f g y ( fib-fib-functor-coprod-inr f g y (pair (inl a') p))) ( pair (inl a') p)} ( map-compute-eq-coprod-inl-inr (f a') y p) isretr-fib-fib-functor-coprod-inr : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (y : B) → ( (fib-fib-functor-coprod-inr f g y) ∘ ( fib-functor-coprod-inr-fib f g y)) ~ id isretr-fib-fib-functor-coprod-inr f g .(g b') (pair b' refl) = eq-pair refl ( isretr-inv-is-equiv (is-equiv-map-raise _ (Id (g b') (g b'))) refl) abstract is-equiv-fib-functor-coprod-inr-fib : {l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} (f : A' → A) (g : B' → B) (y : B) → is-equiv (fib-functor-coprod-inr-fib f g y) is-equiv-fib-functor-coprod-inr-fib f g y = is-equiv-has-inverse ( fib-fib-functor-coprod-inr f g y) ( issec-fib-fib-functor-coprod-inr f g y) ( isretr-fib-fib-functor-coprod-inr f g y) cone-descent-coprod : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (i : X' → X) (cone-A' : cone f i A') (cone-B' : cone g i B') → cone (ind-coprod _ f g) i (coprod A' B') cone-descent-coprod f g i (pair h (pair f' H)) (pair k (pair g' K)) = pair ( functor-coprod h k) ( pair ( ind-coprod _ f' g') ( ind-coprod _ H K)) triangle-descent-square-fib-functor-coprod-inl-fib : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A' → A) (g : B' → B) (h : X' → X) (αA : A → X) (αB : B → X) (αA' : A' → X') (αB' : B' → X') (HA : (αA ∘ f) ~ (h ∘ αA')) (HB : (αB ∘ g) ~ (h ∘ αB')) (x : A) → (fib-square αA h (pair f (pair αA' HA)) x) ~ ( (fib-square (ind-coprod _ αA αB) h ( pair ( functor-coprod f g) ( pair (ind-coprod _ αA' αB') (ind-coprod _ HA HB))) (inl x)) ∘ ( fib-functor-coprod-inl-fib f g x)) triangle-descent-square-fib-functor-coprod-inl-fib {X = X} {X' = X'} f g h αA αB αA' αB' HA HB x (pair a' p) = eq-pair refl ( ap (concat (inv (HA a')) (αA x)) ( ap-comp (ind-coprod _ αA αB) inl p)) triangle-descent-square-fib-functor-coprod-inr-fib : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A' → A) (g : B' → B) (h : X' → X) (αA : A → X) (αB : B → X) (αA' : A' → X') (αB' : B' → X') (HA : (αA ∘ f) ~ (h ∘ αA')) (HB : (αB ∘ g) ~ (h ∘ αB')) (y : B) → (fib-square αB h (pair g (pair αB' HB)) y) ~ ( (fib-square (ind-coprod _ αA αB) h ( pair ( functor-coprod f g) ( pair (ind-coprod _ αA' αB') (ind-coprod _ HA HB))) (inr y)) ∘ ( fib-functor-coprod-inr-fib f g y)) triangle-descent-square-fib-functor-coprod-inr-fib {X = X} {X' = X'} f g h αA αB αA' αB' HA HB y ( pair b' p) = eq-pair refl ( ap (concat (inv (HB b')) (αB y)) ( ap-comp (ind-coprod _ αA αB) inr p)) abstract descent-coprod : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (i : X' → X) (cone-A' : cone f i A') (cone-B' : cone g i B') → is-pullback f i cone-A' → is-pullback g i cone-B' → is-pullback (ind-coprod _ f g) i (cone-descent-coprod f g i cone-A' cone-B') descent-coprod f g i (pair h (pair f' H)) (pair k (pair g' K)) is-pb-cone-A' is-pb-cone-B' = is-pullback-is-fiberwise-equiv-fib-square ( ind-coprod _ f g) ( i) ( cone-descent-coprod f g i (pair h (pair f' H)) (pair k (pair g' K))) ( ind-coprod _ ( λ x → is-equiv-left-factor ( fib-square f i (pair h (pair f' H)) x) ( fib-square (ind-coprod _ f g) i ( pair (functor-coprod h k) ( pair (ind-coprod _ f' g') (ind-coprod _ H K))) ( inl x)) ( fib-functor-coprod-inl-fib h k x) ( triangle-descent-square-fib-functor-coprod-inl-fib h k i f g f' g' H K x) ( is-fiberwise-equiv-fib-square-is-pullback f i ( pair h (pair f' H)) is-pb-cone-A' x) ( is-equiv-fib-functor-coprod-inl-fib h k x)) ( λ y → is-equiv-left-factor ( fib-square g i (pair k (pair g' K)) y) ( fib-square ( ind-coprod _ f g) i ( pair ( functor-coprod h k) ( pair (ind-coprod _ f' g') (ind-coprod _ H K))) (inr y)) ( fib-functor-coprod-inr-fib h k y) ( triangle-descent-square-fib-functor-coprod-inr-fib h k i f g f' g' H K y) ( is-fiberwise-equiv-fib-square-is-pullback g i ( pair k (pair g' K)) is-pb-cone-B' y) ( is-equiv-fib-functor-coprod-inr-fib h k y))) abstract descent-coprod-inl : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (i : X' → X) (cone-A' : cone f i A') (cone-B' : cone g i B') → is-pullback ( ind-coprod _ f g) ( i) ( cone-descent-coprod f g i cone-A' cone-B') → is-pullback f i cone-A' descent-coprod-inl f g i (pair h (pair f' H)) (pair k (pair g' K)) is-pb-dsq = is-pullback-is-fiberwise-equiv-fib-square f i (pair h (pair f' H)) ( λ a → is-equiv-comp ( fib-square f i (pair h (pair f' H)) a) ( fib-square (ind-coprod _ f g) i ( cone-descent-coprod f g i ( pair h (pair f' H)) (pair k (pair g' K))) (inl a)) ( fib-functor-coprod-inl-fib h k a) ( triangle-descent-square-fib-functor-coprod-inl-fib h k i f g f' g' H K a) ( is-equiv-fib-functor-coprod-inl-fib h k a) ( is-fiberwise-equiv-fib-square-is-pullback (ind-coprod _ f g) i ( cone-descent-coprod f g i ( pair h (pair f' H)) (pair k (pair g' K))) is-pb-dsq (inl a))) abstract descent-coprod-inr : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (i : X' → X) (cone-A' : cone f i A') (cone-B' : cone g i B') → is-pullback ( ind-coprod _ f g) ( i) ( cone-descent-coprod f g i cone-A' cone-B') → is-pullback g i cone-B' descent-coprod-inr f g i (pair h (pair f' H)) (pair k (pair g' K)) is-pb-dsq = is-pullback-is-fiberwise-equiv-fib-square g i (pair k (pair g' K)) ( λ b → is-equiv-comp ( fib-square g i (pair k (pair g' K)) b) ( fib-square (ind-coprod _ f g) i ( cone-descent-coprod f g i ( pair h (pair f' H)) (pair k (pair g' K))) (inr b)) ( fib-functor-coprod-inr-fib h k b) ( triangle-descent-square-fib-functor-coprod-inr-fib h k i f g f' g' H K b) ( is-equiv-fib-functor-coprod-inr-fib h k b) ( is-fiberwise-equiv-fib-square-is-pullback (ind-coprod _ f g) i ( cone-descent-coprod f g i ( pair h (pair f' H)) (pair k (pair g' K))) is-pb-dsq (inr b))) -- Descent for Σ-types cone-descent-Σ : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {A' : I → UU l3} {X : UU l4} {X' : UU l5} (f : (i : I) → A i → X) (h : X' → X) (c : (i : I) → cone (f i) h (A' i)) → cone (ind-Σ f) h (Σ I A') cone-descent-Σ f h c = pair ( tot (λ i → (pr1 (c i)))) ( pair ( ind-Σ (λ i → (pr1 (pr2 (c i))))) ( ind-Σ (λ i → (pr2 (pr2 (c i)))))) triangle-descent-Σ : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {A' : I → UU l3} {X : UU l4} {X' : UU l5} (f : (i : I) → A i → X) (h : X' → X) (c : (i : I) → cone (f i) h (A' i)) → (i : I) (a : A i) → ( fib-square (f i) h (c i) a) ~ ((fib-square (ind-Σ f) h (cone-descent-Σ f h c) (pair i a)) ∘ (fib-tot-fib-ftr (λ i → (pr1 (c i))) (pair i a))) triangle-descent-Σ f h c i .(pr1 (c i) a') (pair a' refl) = refl abstract descent-Σ : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {A' : I → UU l3} {X : UU l4} {X' : UU l5} (f : (i : I) → A i → X) (h : X' → X) (c : (i : I) → cone (f i) h (A' i)) → ((i : I) → is-pullback (f i) h (c i)) → is-pullback (ind-Σ f) h (cone-descent-Σ f h c) descent-Σ f h c is-pb-c = is-pullback-is-fiberwise-equiv-fib-square ( ind-Σ f) ( h) ( cone-descent-Σ f h c) ( ind-Σ ( λ i a → is-equiv-left-factor ( fib-square (f i) h (c i) a) ( fib-square (ind-Σ f) h (cone-descent-Σ f h c) (pair i a)) ( fib-tot-fib-ftr (λ i → pr1 (c i)) (pair i a)) ( triangle-descent-Σ f h c i a) ( is-fiberwise-equiv-fib-square-is-pullback (f i) h (c i) (is-pb-c i) a) ( is-equiv-fib-tot-fib-ftr (λ i → pr1 (c i)) (pair i a)))) abstract descent-Σ' : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {A' : I → UU l3} {X : UU l4} {X' : UU l5} (f : (i : I) → A i → X) (h : X' → X) (c : (i : I) → cone (f i) h (A' i)) → is-pullback (ind-Σ f) h (cone-descent-Σ f h c) → ((i : I) → is-pullback (f i) h (c i)) descent-Σ' f h c is-pb-dsq i = is-pullback-is-fiberwise-equiv-fib-square (f i) h (c i) ( λ a → is-equiv-comp ( fib-square (f i) h (c i) a) ( fib-square (ind-Σ f) h (cone-descent-Σ f h c) (pair i a)) ( fib-tot-fib-ftr (λ i → pr1 (c i)) (pair i a)) ( triangle-descent-Σ f h c i a) ( is-equiv-fib-tot-fib-ftr (λ i → pr1 (c i)) (pair i a)) ( is-fiberwise-equiv-fib-square-is-pullback (ind-Σ f) h ( cone-descent-Σ f h c) is-pb-dsq (pair i a))) -- Extra material -- Homotopical squares {- We consider the situation where we have two 'parallel squares', i.e. a diagram of the form ---------> C ---------> B | | | | | | | | V V V V A ---------> X. ---------> Suppose that between each parallel pair of maps there is a homotopy, and that there is a homotopy between the homotopies that fill the two squares, as expessed by the type coherence-htpy-square below. Our goal is to show that if one of the squares is a pullback square, then so is the other. We do so without using function extensionality. -} coherence-htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) (c' : cone f' g' C) (Hp : pr1 c ~ pr1 c') (Hq : pr1 (pr2 c) ~ pr1 (pr2 c')) → UU _ coherence-htpy-square {f = f} {f'} Hf {g} {g'} Hg c c' Hp Hq = let p = pr1 c q = pr1 (pr2 c) H = pr2 (pr2 c) p' = pr1 c' q' = pr1 (pr2 c') H' = pr2 (pr2 c') in ( H ∙h ((g ·l Hq) ∙h (Hg ·r q'))) ~ (((f ·l Hp) ∙h (Hf ·r p')) ∙h H') fam-htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) → (c' : cone f' g' C) → (pr1 c ~ pr1 c') → UU _ fam-htpy-square {f = f} {f'} Hf {g} {g'} Hg c c' Hp = Σ ((pr1 (pr2 c)) ~ (pr1 (pr2 c'))) (coherence-htpy-square Hf Hg c c' Hp) htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → cone f g C → cone f' g' C → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) htpy-square {f = f} {f'} Hf {g} {g'} Hg c c' = Σ ((pr1 c) ~ (pr1 c')) (fam-htpy-square Hf Hg c c') map-is-pullback-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {f' : A → X} (Hf : f ~ f') {g : B → X} {g' : B → X} (Hg : g ~ g') → canonical-pullback f' g' → canonical-pullback f g map-is-pullback-htpy {f = f} {f'} Hf {g} {g'} Hg = tot (λ a → tot (λ b → ( concat' (f a) (inv (Hg b))) ∘ (concat (Hf a) (g' b)))) abstract is-equiv-map-is-pullback-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {f : A → X} {f' : A → X} (Hf : f ~ f') {g : B → X} {g' : B → X} (Hg : g ~ g') → is-equiv (map-is-pullback-htpy Hf Hg) is-equiv-map-is-pullback-htpy {f = f} {f'} Hf {g} {g'} Hg = is-equiv-tot-is-fiberwise-equiv (λ a → is-equiv-tot-is-fiberwise-equiv (λ b → is-equiv-comp ( (concat' (f a) (inv (Hg b))) ∘ (concat (Hf a) (g' b))) ( concat' (f a) (inv (Hg b))) ( concat (Hf a) (g' b)) ( refl-htpy) ( is-equiv-concat (Hf a) (g' b)) ( is-equiv-concat' (f a) (inv (Hg b))))) tot-pullback-rel : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (x : A) → UU _ tot-pullback-rel {B = B} f g x = Σ B (λ y → Id (f x) (g y)) triangle-is-pullback-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f : A → X} {f' : A → X} (Hf : f ~ f') {g : B → X} {g' : B → X} (Hg : g ~ g') {c : cone f g C} {c' : cone f' g' C} (Hc : htpy-square Hf Hg c c') → (gap f g c) ~ ((map-is-pullback-htpy Hf Hg) ∘ (gap f' g' c')) triangle-is-pullback-htpy {A = A} {B} {X} {C} {f = f} {f'} Hf {g} {g'} Hg {pair p (pair q H)} {pair p' (pair q' H')} (pair Hp (pair Hq HH)) z = eq-Eq-canonical-pullback f g ( Hp z) ( Hq z) ( ( inv ( assoc (ap f (Hp z)) ((Hf (p' z)) ∙ (H' z)) (inv (Hg (q' z))))) ∙ ( inv ( con-inv ( (H z) ∙ (ap g (Hq z))) ( Hg (q' z)) ( ( ap f (Hp z)) ∙ ((Hf (p' z)) ∙ (H' z))) ( ( assoc (H z) (ap g (Hq z)) (Hg (q' z))) ∙ ( ( HH z) ∙ ( assoc (ap f (Hp z)) (Hf (p' z)) (H' z))))))) abstract is-pullback-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f : A → X} (f' : A → X) (Hf : f ~ f') {g : B → X} (g' : B → X) (Hg : g ~ g') {c : cone f g C} (c' : cone f' g' C) (Hc : htpy-square Hf Hg c c') → is-pullback f' g' c' → is-pullback f g c is-pullback-htpy {f = f} f' Hf {g} g' Hg {c = pair p (pair q H)} (pair p' (pair q' H')) (pair Hp (pair Hq HH)) is-pb-c' = is-equiv-comp ( gap f g (pair p (pair q H))) ( map-is-pullback-htpy Hf Hg) ( gap f' g' (pair p' (pair q' H'))) ( triangle-is-pullback-htpy Hf Hg {pair p (pair q H)} {pair p' (pair q' H')} (pair Hp (pair Hq HH))) ( is-pb-c') ( is-equiv-map-is-pullback-htpy Hf Hg) abstract is-pullback-htpy' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) {f' : A → X} (Hf : f ~ f') (g : B → X) {g' : B → X} (Hg : g ~ g') → (c : cone f g C) {c' : cone f' g' C} (Hc : htpy-square Hf Hg c c') → is-pullback f g c → is-pullback f' g' c' is-pullback-htpy' f {f'} Hf g {g'} Hg (pair p (pair q H)) {pair p' (pair q' H')} (pair Hp (pair Hq HH)) is-pb-c = is-equiv-right-factor ( gap f g (pair p (pair q H))) ( map-is-pullback-htpy Hf Hg) ( gap f' g' (pair p' (pair q' H'))) ( triangle-is-pullback-htpy Hf Hg {pair p (pair q H)} {pair p' (pair q' H')} (pair Hp (pair Hq HH))) ( is-equiv-map-is-pullback-htpy Hf Hg) ( is-pb-c) {- In the following part we will relate the type htpy-square to the Identity type of cones. Here we will rely on function extensionality. -} reflexive-htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → htpy-square (refl-htpy {f = f}) (refl-htpy {f = g}) c c reflexive-htpy-square f g c = pair refl-htpy (pair refl-htpy htpy-right-unit) htpy-square-eq-refl-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c c' : cone f g C) → Id c c' → htpy-square (refl-htpy {f = f}) (refl-htpy {f = g}) c c' htpy-square-eq-refl-htpy f g c .c refl = pair refl-htpy (pair refl-htpy htpy-right-unit) htpy-square-refl-htpy-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → (c c' : cone f g C) → htpy-cone f g c c' → htpy-square (refl-htpy {f = f}) (refl-htpy {f = g}) c c' htpy-square-refl-htpy-htpy-cone f g (pair p (pair q H)) (pair p' (pair q' H')) = tot ( λ K → tot ( λ L M → ( htpy-ap-concat H _ _ htpy-right-unit) ∙h ( M ∙h htpy-ap-concat' _ _ H' (htpy-inv htpy-right-unit)))) abstract is-equiv-htpy-square-refl-htpy-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → (c c' : cone f g C) → is-equiv (htpy-square-refl-htpy-htpy-cone f g c c') is-equiv-htpy-square-refl-htpy-htpy-cone f g (pair p (pair q H)) (pair p' (pair q' H')) = is-equiv-tot-is-fiberwise-equiv ( λ K → is-equiv-tot-is-fiberwise-equiv ( λ L → is-equiv-comp ( λ M → ( htpy-ap-concat H _ _ htpy-right-unit) ∙h ( M ∙h ( htpy-ap-concat' _ _ H' (htpy-inv htpy-right-unit)))) ( htpy-concat ( htpy-ap-concat H _ _ htpy-right-unit) ( ((f ·l K) ∙h refl-htpy) ∙h H')) ( htpy-concat' ( H ∙h (g ·l L)) ( htpy-ap-concat' _ _ H' (htpy-inv htpy-right-unit))) ( refl-htpy) ( is-equiv-htpy-concat' ( H ∙h (g ·l L)) ( λ x → ap (λ z → z ∙ H' x) (inv right-unit))) ( is-equiv-htpy-concat ( λ x → ap (_∙_ (H x)) right-unit) ( ((f ·l K) ∙h refl-htpy) ∙h H')))) abstract is-contr-total-htpy-square-refl-htpy-refl-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → (c : cone f g C) → is-contr (Σ (cone f g C) (htpy-square (refl-htpy' f) (refl-htpy' g) c)) is-contr-total-htpy-square-refl-htpy-refl-htpy {A = A} {B} {X} {C} f g (pair p (pair q H)) = let c = pair p (pair q H) in is-contr-is-equiv' ( Σ (cone f g C) (htpy-cone f g c)) ( tot (htpy-square-refl-htpy-htpy-cone f g c)) ( is-equiv-tot-is-fiberwise-equiv ( is-equiv-htpy-square-refl-htpy-htpy-cone f g c)) ( is-contr-total-htpy-cone f g c) abstract is-contr-total-htpy-square-refl-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) → is-contr (Σ (cone f g' C) (htpy-square (refl-htpy' f) Hg c)) is-contr-total-htpy-square-refl-htpy {C = C} f {g} = ind-htpy g ( λ g'' Hg' → ( c : cone f g C) → is-contr (Σ (cone f g'' C) (htpy-square (refl-htpy' f) Hg' c))) ( is-contr-total-htpy-square-refl-htpy-refl-htpy f g) abstract is-contr-total-htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) → is-contr (Σ (cone f' g' C) (htpy-square Hf Hg c)) is-contr-total-htpy-square {A = A} {B} {X} {C} {f} {f'} Hf {g} {g'} Hg = ind-htpy { A = A} { B = λ t → X} ( f) ( λ f'' Hf' → (g g' : B → X) (Hg : g ~ g') (c : cone f g C) → is-contr (Σ (cone f'' g' C) (htpy-square Hf' Hg c))) ( λ g g' Hg → is-contr-total-htpy-square-refl-htpy f Hg) Hf g g' Hg tr-tr-refl-htpy-cone : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → let tr-c = tr (λ x → cone x g C) (eq-htpy (refl-htpy {f = f})) c tr-tr-c = tr (λ y → cone f y C) (eq-htpy (refl-htpy {f = g})) tr-c in Id tr-tr-c c tr-tr-refl-htpy-cone {C = C} f g c = let tr-c = tr (λ f''' → cone f''' g C) (eq-htpy refl-htpy) c tr-tr-c = tr (λ g'' → cone f g'' C) (eq-htpy refl-htpy) tr-c α : Id tr-tr-c tr-c α = ap (λ t → tr (λ g'' → cone f g'' C) t tr-c) (eq-htpy-refl-htpy g) β : Id tr-c c β = ap (λ t → tr (λ f''' → cone f''' g C) t c) (eq-htpy-refl-htpy f) in α ∙ β htpy-square-eq-refl-htpy-refl-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c c' : cone f g C) → let tr-c = tr (λ x → cone x g C) (eq-htpy (refl-htpy {f = f})) c tr-tr-c = tr (λ y → cone f y C) (eq-htpy (refl-htpy {f = g})) tr-c in Id tr-tr-c c' → htpy-square (refl-htpy' f) (refl-htpy' g) c c' htpy-square-eq-refl-htpy-refl-htpy f g c c' = ind-is-equiv ( λ p → htpy-square (refl-htpy' f) (refl-htpy' g) c c') ( λ (p : Id c c') → (tr-tr-refl-htpy-cone f g c) ∙ p) ( is-equiv-concat (tr-tr-refl-htpy-cone f g c) c') ( htpy-square-eq-refl-htpy f g c c') comp-htpy-square-eq-refl-htpy-refl-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c c' : cone f g C) → ( (htpy-square-eq-refl-htpy-refl-htpy f g c c') ∘ (concat (tr-tr-refl-htpy-cone f g c) c')) ~ ( htpy-square-eq-refl-htpy f g c c') comp-htpy-square-eq-refl-htpy-refl-htpy f g c c' = htpy-comp-is-equiv ( λ p → htpy-square (refl-htpy' f) (refl-htpy' g) c c') ( λ (p : Id c c') → (tr-tr-refl-htpy-cone f g c) ∙ p) ( is-equiv-concat (tr-tr-refl-htpy-cone f g c) c') ( htpy-square-eq-refl-htpy f g c c') abstract htpy-square-eq' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) (c' : cone f g' C) → let tr-c = tr (λ x → cone x g C) (eq-htpy (refl-htpy {f = f})) c tr-tr-c = tr (λ y → cone f y C) (eq-htpy Hg) tr-c in Id tr-tr-c c' → htpy-square (refl-htpy' f) Hg c c' htpy-square-eq' {C = C} f {g} = ind-htpy g ( λ g'' Hg' → ( c : cone f g C) (c' : cone f g'' C) → Id (tr (λ g'' → cone f g'' C) (eq-htpy Hg') ( tr (λ f''' → cone f''' g C) (eq-htpy (refl-htpy' f)) c)) c' → htpy-square refl-htpy Hg' c c') ( htpy-square-eq-refl-htpy-refl-htpy f g) comp-htpy-square-eq' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c c' : cone f g C) → ( ( htpy-square-eq' f refl-htpy c c') ∘ ( concat (tr-tr-refl-htpy-cone f g c) c')) ~ ( htpy-square-eq-refl-htpy f g c c') comp-htpy-square-eq' {A = A} {B} {X} {C} f g c c' = htpy-right-whisk ( htpy-eq (htpy-eq (htpy-eq (comp-htpy g ( λ g'' Hg' → ( c : cone f g C) (c' : cone f g'' C) → Id (tr (λ g'' → cone f g'' C) (eq-htpy Hg') ( tr (λ f''' → cone f''' g C) (eq-htpy (refl-htpy' f)) c)) c' → htpy-square refl-htpy Hg' c c') ( htpy-square-eq-refl-htpy-refl-htpy f g)) c) c')) ( concat (tr-tr-refl-htpy-cone f g c) c') ∙h ( comp-htpy-square-eq-refl-htpy-refl-htpy f g c c') abstract htpy-square-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) (c' : cone f' g' C) → let tr-c = tr (λ x → cone x g C) (eq-htpy Hf) c tr-tr-c = tr (λ y → cone f' y C) (eq-htpy Hg) tr-c in Id tr-tr-c c' → htpy-square Hf Hg c c' htpy-square-eq {A = A} {B} {X} {C} {f} {f'} Hf {g} {g'} Hg c c' p = ind-htpy f ( λ f'' Hf' → ( g g' : B → X) (Hg : g ~ g') (c : cone f g C) (c' : cone f'' g' C) → ( Id (tr (λ g'' → cone f'' g'' C) (eq-htpy Hg) ( tr (λ f''' → cone f''' g C) (eq-htpy Hf') c)) c') → htpy-square Hf' Hg c c') ( λ g g' → htpy-square-eq' f {g = g} {g' = g'}) Hf g g' Hg c c' p comp-htpy-square-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c c' : cone f g C) → ( ( htpy-square-eq refl-htpy refl-htpy c c') ∘ ( concat (tr-tr-refl-htpy-cone f g c) c')) ~ ( htpy-square-eq-refl-htpy f g c c') comp-htpy-square-eq {A = A} {B} {X} {C} f g c c' = htpy-right-whisk ( htpy-eq (htpy-eq (htpy-eq (htpy-eq (htpy-eq (htpy-eq (comp-htpy f ( λ f'' Hf' → ( g g' : B → X) (Hg : g ~ g') (c : cone f g C) (c' : cone f'' g' C) → ( Id ( tr (λ g'' → cone f'' g'' C) (eq-htpy Hg) ( tr (λ f''' → cone f''' g C) (eq-htpy Hf') c)) c') → htpy-square Hf' Hg c c') ( λ g g' → htpy-square-eq' f {g = g} {g' = g'})) g) g) refl-htpy) c) c')) ( concat (tr-tr-refl-htpy-cone f g c) c') ∙h ( comp-htpy-square-eq' f g c c') abstract is-fiberwise-equiv-htpy-square-eq : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) (c' : cone f' g' C) → is-equiv (htpy-square-eq Hf Hg c c') is-fiberwise-equiv-htpy-square-eq {A = A} {B} {X} {C} {f} {f'} Hf {g} {g'} Hg c c' = ind-htpy f ( λ f' Hf → ( g g' : B → X) (Hg : g ~ g') (c : cone f g C) (c' : cone f' g' C) → is-equiv (htpy-square-eq Hf Hg c c')) ( λ g g' Hg c c' → ind-htpy g ( λ g' Hg → ( c : cone f g C) (c' : cone f g' C) → is-equiv (htpy-square-eq refl-htpy Hg c c')) ( λ c c' → is-equiv-left-factor ( htpy-square-eq-refl-htpy f g c c') ( htpy-square-eq refl-htpy refl-htpy c c') ( concat (tr-tr-refl-htpy-cone f g c) c') ( htpy-inv (comp-htpy-square-eq f g c c')) ( fundamental-theorem-id c ( reflexive-htpy-square f g c) ( is-contr-total-htpy-square (refl-htpy' f) (refl-htpy' g) c) ( htpy-square-eq-refl-htpy f g c) c') ( is-equiv-concat (tr-tr-refl-htpy-cone f g c) c')) Hg c c') Hf g g' Hg c c' eq-htpy-square : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {f f' : A → X} (Hf : f ~ f') {g g' : B → X} (Hg : g ~ g') → (c : cone f g C) (c' : cone f' g' C) → let tr-c = tr (λ x → cone x g C) (eq-htpy Hf) c tr-tr-c = tr (λ y → cone f' y C) (eq-htpy Hg) tr-c in htpy-square Hf Hg c c' → Id tr-tr-c c' eq-htpy-square Hf Hg c c' = inv-is-equiv { f = htpy-square-eq Hf Hg c c'} ( is-fiberwise-equiv-htpy-square-eq Hf Hg c c') -- Exercises -- Exercise 10.1 cone-Id : {l : Level} {A : UU l} (x y : A) → cone (const unit A x) (const unit A y) (Id x y) cone-Id x y = pair ( const (Id x y) unit star) ( pair ( const (Id x y) unit star) ( id)) inv-gap-cone-Id : {l : Level} {A : UU l} (x y : A) → canonical-pullback (const unit A x) (const unit A y) → Id x y inv-gap-cone-Id x y (pair star (pair star p)) = p issec-inv-gap-cone-Id : {l : Level} {A : UU l} (x y : A) → ( ( gap (const unit A x) (const unit A y) (cone-Id x y)) ∘ ( inv-gap-cone-Id x y)) ~ id issec-inv-gap-cone-Id x y (pair star (pair star p)) = refl isretr-inv-gap-cone-Id : {l : Level} {A : UU l} (x y : A) → ( ( inv-gap-cone-Id x y) ∘ ( gap (const unit A x) (const unit A y) (cone-Id x y))) ~ id isretr-inv-gap-cone-Id x y p = refl abstract is-pullback-cone-Id : {l : Level} {A : UU l} (x y : A) → is-pullback (const unit A x) (const unit A y) (cone-Id x y) is-pullback-cone-Id x y = is-equiv-has-inverse ( inv-gap-cone-Id x y) ( issec-inv-gap-cone-Id x y) ( isretr-inv-gap-cone-Id x y) {- One way to solve this exercise is to show that Id (pr1 t) (pr2 t) is a pullback for every t : A × A. This allows one to use path induction to show that the inverse of the gap map is a section. -} cone-Id' : {l : Level} {A : UU l} (t : A × A) → cone (const unit (A × A) t) (diagonal A) (Id (pr1 t) (pr2 t)) cone-Id' {A = A} (pair x y) = pair ( const (Id x y) unit star) ( pair ( const (Id x y) A x) ( λ p → eq-pair refl (inv p))) inv-gap-cone-Id' : {l : Level} {A : UU l} (t : A × A) → canonical-pullback (const unit (A × A) t) (diagonal A) → Id (pr1 t) (pr2 t) inv-gap-cone-Id' t (pair star (pair z p)) = (ap pr1 p) ∙ (inv (ap pr2 p)) issec-inv-gap-cone-Id' : {l : Level} {A : UU l} (t : A × A) → ( ( gap (const unit (A × A) t) (diagonal A) (cone-Id' t)) ∘ ( inv-gap-cone-Id' t)) ~ id issec-inv-gap-cone-Id' .(pair z z) (pair star (pair z refl)) = refl isretr-inv-gap-cone-Id' : {l : Level} {A : UU l} (t : A × A) → ( ( inv-gap-cone-Id' t) ∘ ( gap (const unit (A × A) t) (diagonal A) (cone-Id' t))) ~ id isretr-inv-gap-cone-Id' (pair x .x) refl = refl abstract is-pullback-cone-Id' : {l : Level} {A : UU l} (t : A × A) → is-pullback (const unit (A × A) t) (diagonal A) (cone-Id' t) is-pullback-cone-Id' t = is-equiv-has-inverse ( inv-gap-cone-Id' t) ( issec-inv-gap-cone-Id' t) ( isretr-inv-gap-cone-Id' t) -- Exercise 10.2 diagonal-map : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → A → canonical-pullback f f diagonal-map f x = pair x (pair x refl) fib-ap-fib-diagonal-map : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (t : canonical-pullback f f) → (fib (diagonal-map f) t) → (fib (ap f) (pr2 (pr2 t))) fib-ap-fib-diagonal-map f .(pair z (pair z refl)) (pair z refl) = pair refl refl fib-diagonal-map-fib-ap : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (t : canonical-pullback f f) → (fib (ap f) (pr2 (pr2 t))) → (fib (diagonal-map f) t) fib-diagonal-map-fib-ap f (pair x (pair .x .refl)) (pair refl refl) = pair x refl issec-fib-diagonal-map-fib-ap : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (t : canonical-pullback f f) → ((fib-ap-fib-diagonal-map f t) ∘ (fib-diagonal-map-fib-ap f t)) ~ id issec-fib-diagonal-map-fib-ap f (pair x (pair .x .refl)) (pair refl refl) = refl isretr-fib-diagonal-map-fib-ap : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (t : canonical-pullback f f) → ((fib-diagonal-map-fib-ap f t) ∘ (fib-ap-fib-diagonal-map f t)) ~ id isretr-fib-diagonal-map-fib-ap f .(pair x (pair x refl)) (pair x refl) = refl abstract is-equiv-fib-ap-fib-diagonal-map : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (t : canonical-pullback f f) → is-equiv (fib-ap-fib-diagonal-map f t) is-equiv-fib-ap-fib-diagonal-map f t = is-equiv-has-inverse ( fib-diagonal-map-fib-ap f t) ( issec-fib-diagonal-map-fib-ap f t) ( isretr-fib-diagonal-map-fib-ap f t) abstract is-trunc-diagonal-map-is-trunc-map : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} (f : A → B) → is-trunc-map (succ-𝕋 k) f → is-trunc-map k (diagonal-map f) is-trunc-diagonal-map-is-trunc-map k f is-trunc-f (pair x (pair y p)) = is-trunc-is-equiv k (fib (ap f) p) ( fib-ap-fib-diagonal-map f (pair x (pair y p))) ( is-equiv-fib-ap-fib-diagonal-map f (pair x (pair y p))) ( is-trunc-ap-is-trunc-map k f is-trunc-f x y p) abstract is-trunc-map-is-trunc-diagonal-map : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} (f : A → B) → is-trunc-map k (diagonal-map f) → is-trunc-map (succ-𝕋 k) f is-trunc-map-is-trunc-diagonal-map k f is-trunc-δ b (pair x p) (pair x' p') = is-trunc-is-equiv k ( fib (ap f) (p ∙ (inv p'))) ( fib-ap-eq-fib f (pair x p) (pair x' p')) ( is-equiv-fib-ap-eq-fib f (pair x p) (pair x' p')) ( is-trunc-is-equiv' k ( fib (diagonal-map f) (pair x (pair x' (p ∙ (inv p'))))) ( fib-ap-fib-diagonal-map f (pair x (pair x' (p ∙ (inv p'))))) ( is-equiv-fib-ap-fib-diagonal-map f (pair x (pair x' (p ∙ (inv p'))))) ( is-trunc-δ (pair x (pair x' (p ∙ (inv p')))))) abstract is-equiv-diagonal-map-is-emb : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-emb f → is-equiv (diagonal-map f) is-equiv-diagonal-map-is-emb f is-emb-f = is-equiv-is-contr-map ( is-trunc-diagonal-map-is-trunc-map neg-two-𝕋 f ( is-prop-map-is-emb f is-emb-f)) abstract is-emb-is-equiv-diagonal-map : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv (diagonal-map f) → is-emb f is-emb-is-equiv-diagonal-map f is-equiv-δ = is-emb-is-prop-map f ( is-trunc-map-is-trunc-diagonal-map neg-two-𝕋 f ( is-contr-map-is-equiv is-equiv-δ)) -- Exercise 10.3 cone-swap : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → cone f g C → cone g f C cone-swap f g (pair p (pair q H)) = pair q (pair p (htpy-inv H)) map-canonical-pullback-swap : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → canonical-pullback f g → canonical-pullback g f map-canonical-pullback-swap f g (pair a (pair b p)) = pair b (pair a (inv p)) inv-inv-map-canonical-pullback-swap : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → (map-canonical-pullback-swap f g ∘ map-canonical-pullback-swap g f) ~ id inv-inv-map-canonical-pullback-swap f g (pair b (pair a q)) = eq-pair refl (eq-pair refl (inv-inv q)) abstract is-equiv-map-canonical-pullback-swap : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → is-equiv (map-canonical-pullback-swap f g) is-equiv-map-canonical-pullback-swap f g = is-equiv-has-inverse ( map-canonical-pullback-swap g f) ( inv-inv-map-canonical-pullback-swap f g) ( inv-inv-map-canonical-pullback-swap g f) triangle-map-canonical-pullback-swap : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → ( gap g f (cone-swap f g c)) ~ ( ( map-canonical-pullback-swap f g) ∘ ( gap f g c)) triangle-map-canonical-pullback-swap f g (pair p (pair q H)) x = refl abstract is-pullback-cone-swap : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-pullback g f (cone-swap f g c) is-pullback-cone-swap f g c is-pb-c = is-equiv-comp ( gap g f (cone-swap f g c)) ( map-canonical-pullback-swap f g) ( gap f g c) ( triangle-map-canonical-pullback-swap f g c) ( is-pb-c) ( is-equiv-map-canonical-pullback-swap f g) abstract is-pullback-cone-swap' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback g f (cone-swap f g c) → is-pullback f g c is-pullback-cone-swap' f g c is-pb-c' = is-equiv-right-factor ( gap g f (cone-swap f g c)) ( map-canonical-pullback-swap f g) ( gap f g c) ( triangle-map-canonical-pullback-swap f g c) ( is-equiv-map-canonical-pullback-swap f g) ( is-pb-c') {- We conclude the swapped versions of some properties derived above, for future convenience -} abstract is-trunc-is-pullback' : {l1 l2 l3 l4 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-trunc-map k f → is-trunc-map k (pr1 (pr2 c)) is-trunc-is-pullback' k f g (pair p (pair q H)) pb is-trunc-f = is-trunc-is-pullback k g f ( cone-swap f g (pair p (pair q H))) ( is-pullback-cone-swap f g (pair p (pair q H)) pb) is-trunc-f abstract is-emb-is-pullback' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-emb f → is-emb (pr1 (pr2 c)) is-emb-is-pullback' f g c pb is-emb-f = is-emb-is-prop-map ( pr1 (pr2 c)) ( is-trunc-is-pullback' neg-one-𝕋 f g c pb ( is-prop-map-is-emb f is-emb-f)) abstract is-equiv-is-pullback' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-equiv f → is-pullback f g c → is-equiv (pr1 (pr2 c)) is-equiv-is-pullback' f g c is-equiv-f pb = is-equiv-is-contr-map ( is-trunc-is-pullback' neg-two-𝕋 f g c pb ( is-contr-map-is-equiv is-equiv-f)) abstract is-pullback-is-equiv' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-equiv f → is-equiv (pr1 (pr2 c)) → is-pullback f g c is-pullback-is-equiv' f g (pair p (pair q H)) is-equiv-f is-equiv-q = is-pullback-cone-swap' f g (pair p (pair q H)) ( is-pullback-is-equiv g f ( cone-swap f g (pair p (pair q H))) is-equiv-f is-equiv-q) -- Exercise 10.4 cone-empty : {l1 l2 l3 : Level} {B : UU l1} {X : UU l2} {C : UU l3} → (g : B → X) (p : C → empty) (q : C → B) → cone (ind-empty {P = λ t → X}) g C cone-empty g p q = pair p ( pair q ( λ c → ind-empty {P = λ t → Id (ind-empty (p c)) (g (q c))} (p c))) abstract descent-empty : {l1 l2 l3 : Level} {B : UU l1} {X : UU l2} {C : UU l3} → let f = ind-empty {P = λ t → X} in (g : B → X) (c : cone f g C) → is-pullback f g c descent-empty g c = is-pullback-is-fiberwise-equiv-fib-square _ g c ind-empty abstract descent-empty' : {l1 l2 l3 : Level} {B : UU l1} {X : UU l2} {C : UU l3} → (g : B → X) (p : C → empty) (q : C → B) → is-pullback (ind-empty {P = λ t → X}) g (cone-empty g p q) descent-empty' g p q = descent-empty g (cone-empty g p q) -- Exercise 10.5 {- We show that a square is a pullback square if and only if every exponent of it is a pullback square. -} cone-exponent : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} (T : UU l5) (f : A → X) (g : B → X) (c : cone f g C) → cone (λ (h : T → A) → f ∘ h) (λ (h : T → B) → g ∘ h) (T → C) cone-exponent T f g (pair p (pair q H)) = pair ( λ h → p ∘ h) ( pair ( λ h → q ∘ h) ( λ h → eq-htpy (H ·r h))) map-canonical-pullback-exponent : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (T : UU l4) → canonical-pullback (λ (h : T → A) → f ∘ h) (λ (h : T → B) → g ∘ h) → cone f g T map-canonical-pullback-exponent f g T = tot (λ p → tot (λ q → htpy-eq)) abstract is-equiv-map-canonical-pullback-exponent : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (T : UU l4) → is-equiv (map-canonical-pullback-exponent f g T) is-equiv-map-canonical-pullback-exponent f g T = is-equiv-tot-is-fiberwise-equiv ( λ p → is-equiv-tot-is-fiberwise-equiv ( λ q → funext (f ∘ p) (g ∘ q))) triangle-map-canonical-pullback-exponent : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (T : UU l5) (f : A → X) (g : B → X) (c : cone f g C) → ( cone-map f g {C' = T} c) ~ ( ( map-canonical-pullback-exponent f g T) ∘ ( gap ( λ (h : T → A) → f ∘ h) ( λ (h : T → B) → g ∘ h) ( cone-exponent T f g c))) triangle-map-canonical-pullback-exponent {A = A} {B} T f g (pair p (pair q H)) h = eq-pair refl (eq-pair refl (inv (issec-eq-htpy (H ·r h)))) abstract is-pullback-exponent-is-pullback : {l1 l2 l3 l4 l5 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → (T : UU l5) → is-pullback ( λ (h : T → A) → f ∘ h) ( λ (h : T → B) → g ∘ h) ( cone-exponent T f g c) is-pullback-exponent-is-pullback f g c is-pb-c T = is-equiv-right-factor ( cone-map f g c) ( map-canonical-pullback-exponent f g T) ( gap (_∘_ f) (_∘_ g) (cone-exponent T f g c)) ( triangle-map-canonical-pullback-exponent T f g c) ( is-equiv-map-canonical-pullback-exponent f g T) ( up-pullback-is-pullback f g c is-pb-c T) abstract is-pullback-is-pullback-exponent : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → ((l5 : Level) (T : UU l5) → is-pullback ( λ (h : T → A) → f ∘ h) ( λ (h : T → B) → g ∘ h) ( cone-exponent T f g c)) → is-pullback f g c is-pullback-is-pullback-exponent f g c is-pb-exp = is-pullback-up-pullback f g c ( λ T → is-equiv-comp ( cone-map f g c) ( map-canonical-pullback-exponent f g T) ( gap (_∘_ f) (_∘_ g) (cone-exponent T f g c)) ( triangle-map-canonical-pullback-exponent T f g c) ( is-pb-exp _ T) ( is-equiv-map-canonical-pullback-exponent f g T)) -- Exercise 10.6 {- Note: the solution below involves a substantial amount of path algebra. It would be nice to find a simpler solution. -} cone-fold : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) → cone f g C → cone (functor-prod f g) (diagonal X) C cone-fold f g (pair p (pair q H)) = pair ( λ z → pair (p z) (q z)) ( pair ( g ∘ q) ( λ z → eq-pair-triv (pair (H z) refl))) map-cone-fold : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) → (g : B → X) → canonical-pullback f g → canonical-pullback (functor-prod f g) (diagonal X) map-cone-fold f g (pair a (pair b p)) = pair ( pair a b) ( pair ( g b) ( eq-pair-triv (pair p refl))) inv-map-cone-fold : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) → (g : B → X) → canonical-pullback (functor-prod f g) (diagonal X) → canonical-pullback f g inv-map-cone-fold f g (pair (pair a b) (pair x α)) = pair a (pair b ((ap pr1 α) ∙ (inv (ap pr2 α)))) ap-diagonal : {l : Level} {A : UU l} {x y : A} (p : Id x y) → Id (ap (diagonal A) p) (eq-pair-triv (pair p p)) ap-diagonal refl = refl eq-pair-triv-concat : {l1 l2 : Level} {A : UU l1} {B : UU l2} {x x' x'' : A} {y y' y'' : B} (p : Id x x') (p' : Id x' x'') (q : Id y y') (q' : Id y' y'') → Id ( eq-pair-triv {s = pair x y} {t = pair x'' y''} (pair (p ∙ p') (q ∙ q'))) ( ( eq-pair-triv {s = pair x y} {t = pair x' y'} (pair p q)) ∙ ( eq-pair-triv (pair p' q'))) eq-pair-triv-concat refl p' refl q' = refl issec-inv-map-cone-fold : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → ((map-cone-fold f g) ∘ (inv-map-cone-fold f g)) ~ id issec-inv-map-cone-fold {A = A} {B} {X} f g (pair (pair a b) (pair x α)) = eq-Eq-canonical-pullback ( functor-prod f g) ( diagonal X) refl ( ap pr2 α) ( ( ( ( inv (issec-pair-eq-triv' (pair (f a) (g b)) (pair x x) α)) ∙ ( ap ( λ t → (eq-pair-triv ( pair t (ap pr2 α)))) ( ( ( inv right-unit) ∙ ( inv (ap (concat (ap pr1 α) x) (left-inv (ap pr2 α))))) ∙ ( inv (assoc (ap pr1 α) (inv (ap pr2 α)) (ap pr2 α)))))) ∙ ( eq-pair-triv-concat ( (ap pr1 α) ∙ (inv (ap pr2 α))) ( ap pr2 α) ( refl) ( ap pr2 α))) ∙ ( ap ( concat ( eq-pair-triv ( pair ((ap pr1 α) ∙ (inv (ap pr2 α))) refl)) ( pair x x)) ( inv (ap-diagonal (ap pr2 α))))) ap-pr1-eq-pair-triv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {x x' : A} (p : Id x x') {y y' : B} (q : Id y y') → Id (ap pr1 (eq-pair-triv' (pair x y) (pair x' y') (pair p q))) p ap-pr1-eq-pair-triv refl refl = refl ap-pr2-eq-pair-triv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {x x' : A} (p : Id x x') {y y' : B} (q : Id y y') → Id (ap pr2 (eq-pair-triv' (pair x y) (pair x' y') (pair p q))) q ap-pr2-eq-pair-triv refl refl = refl isretr-inv-map-cone-fold : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → ((inv-map-cone-fold f g) ∘ (map-cone-fold f g)) ~ id isretr-inv-map-cone-fold { A = A} { B = B} { X = X} f g (pair a (pair b p)) = eq-Eq-canonical-pullback {A = A} {B = B} {X = X} f g refl refl ( inv ( ( ap ( concat' (f a) refl) ( ( ( ap ( λ t → t ∙ ( inv (ap pr2 (eq-pair-triv' ( pair (f a) (g b)) ( pair (g b) (g b)) ( pair p refl))))) ( ap-pr1-eq-pair-triv p refl)) ∙ ( ap (λ t → p ∙ (inv t)) (ap-pr2-eq-pair-triv p refl))) ∙ ( right-unit))) ∙ ( right-unit))) abstract is-equiv-map-cone-fold : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → is-equiv (map-cone-fold f g) is-equiv-map-cone-fold f g = is-equiv-has-inverse ( inv-map-cone-fold f g) ( issec-inv-map-cone-fold f g) ( isretr-inv-map-cone-fold f g) triangle-map-cone-fold : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → ( gap (functor-prod f g) (diagonal X) (cone-fold f g c)) ~ ( (map-cone-fold f g) ∘ (gap f g c)) triangle-map-cone-fold f g (pair p (pair q H)) z = refl abstract is-pullback-cone-fold-is-pullback : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c → is-pullback (functor-prod f g) (diagonal X) (cone-fold f g c) is-pullback-cone-fold-is-pullback f g c is-pb-c = is-equiv-comp ( gap (functor-prod f g) (diagonal _) (cone-fold f g c)) ( map-cone-fold f g) ( gap f g c) ( triangle-map-cone-fold f g c) ( is-pb-c) ( is-equiv-map-cone-fold f g) abstract is-pullback-is-pullback-cone-fold : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} (f : A → X) (g : B → X) (c : cone f g C) → is-pullback (functor-prod f g) (diagonal X) (cone-fold f g c) → is-pullback f g c is-pullback-is-pullback-cone-fold f g c is-pb-fold = is-equiv-right-factor ( gap (functor-prod f g) (diagonal _) (cone-fold f g c)) ( map-cone-fold f g) ( gap f g c) ( triangle-map-cone-fold f g c) ( is-equiv-map-cone-fold f g) ( is-pb-fold) -- Exercise 10.7 cone-pair : {l1 l2 l3 l4 l1' l2' l3' l4' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} {C' : UU l4'} (f : A → X) (g : B → X) (f' : A' → X') (g' : B' → X') → cone f g C → cone f' g' C' → cone (functor-prod f f') (functor-prod g g') (C × C') cone-pair f g f' g' (pair p (pair q H)) (pair p' (pair q' H')) = pair ( functor-prod p p') ( pair ( functor-prod q q') ( ( htpy-inv (functor-prod-comp p p' f f')) ∙h ( ( functor-prod-htpy H H') ∙h ( functor-prod-comp q q' g g')))) map-cone-pair' : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (f' : A' → X') (g' : B' → X') → (t : A × A') (s : B × B') → (Id (f (pr1 t)) (g (pr1 s))) × (Id (f' (pr2 t)) (g' (pr2 s))) → (Id (pr1 (functor-prod f f' t)) (pr1 (functor-prod g g' s))) × (Id (pr2 (functor-prod f f' t)) (pr2 (functor-prod g g' s))) map-cone-pair' f g f' g' (pair a a') (pair b b') = id abstract is-equiv-map-cone-pair' : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (f' : A' → X') (g' : B' → X') → (t : A × A') (s : B × B') → is-equiv (map-cone-pair' f g f' g' t s) is-equiv-map-cone-pair' f g f' g' (pair a a') (pair b b') = is-equiv-id _ map-cone-pair : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (f' : A' → X') (g' : B' → X') → (canonical-pullback f g) × (canonical-pullback f' g') → canonical-pullback (functor-prod f f') (functor-prod g g') map-cone-pair {A' = A'} {B'} f g f' g' = ( tot ( λ t → ( tot ( λ s → ( eq-pair-triv ∘ (map-cone-pair' f g f' g' t s)))) ∘ ( swap-total-Eq-structure ( λ y → Id (f (pr1 t)) (g y)) ( λ y → B') ( λ y p y' → Id (f' (pr2 t)) (g' y'))))) ∘ ( swap-total-Eq-structure ( λ x → Σ _ (λ y → Id (f x) (g y))) ( λ x → A') ( λ x t x' → Σ _ (λ y' → Id (f' x') (g' y')))) triangle-map-cone-pair : {l1 l2 l3 l4 l1' l2' l3' l4' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} {C' : UU l4'} (f : A → X) (g : B → X) (c : cone f g C) (f' : A' → X') (g' : B' → X') (c' : cone f' g' C') → (gap (functor-prod f f') (functor-prod g g') (cone-pair f g f' g' c c')) ~ ((map-cone-pair f g f' g') ∘ (functor-prod (gap f g c) (gap f' g' c'))) triangle-map-cone-pair f g (pair p (pair q H)) f' g' (pair p' (pair q' H')) (pair z z') = eq-pair refl (eq-pair refl right-unit) abstract is-equiv-map-cone-pair : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f : A → X) (g : B → X) (f' : A' → X') (g' : B' → X') → is-equiv (map-cone-pair f g f' g') is-equiv-map-cone-pair f g f' g' = is-equiv-comp ( map-cone-pair f g f' g') ( tot ( λ t → ( tot ( λ s → ( eq-pair-triv ∘ (map-cone-pair' f g f' g' t s)))) ∘ ( swap-total-Eq-structure _ _ _))) ( swap-total-Eq-structure _ _ _) ( refl-htpy) ( is-equiv-swap-total-Eq-structure _ _ _) ( is-equiv-tot-is-fiberwise-equiv ( λ t → is-equiv-comp ( ( tot ( λ s → ( eq-pair-triv ∘ (map-cone-pair' f g f' g' t s)))) ∘ ( swap-total-Eq-structure ( λ y → Id (f (pr1 t)) (g y)) ( λ y → _) ( λ y p y' → Id (f' (pr2 t)) (g' y')))) ( tot ( λ s → ( eq-pair-triv ∘ (map-cone-pair' f g f' g' t s)))) ( swap-total-Eq-structure ( λ y → Id (f (pr1 t)) (g y)) ( λ y → _) ( λ y p y' → Id (f' (pr2 t)) (g' y'))) ( refl-htpy) ( is-equiv-swap-total-Eq-structure _ _ _) ( is-equiv-tot-is-fiberwise-equiv ( λ s → is-equiv-comp ( eq-pair-triv ∘ (map-cone-pair' f g f' g' t s)) ( eq-pair-triv) ( map-cone-pair' f g f' g' t s) ( refl-htpy) ( is-equiv-map-cone-pair' f g f' g' t s) ( is-equiv-eq-pair-triv' ( functor-prod f f' t) ( functor-prod g g' s)))))) abstract is-pullback-prod-is-pullback-pair : {l1 l2 l3 l4 l1' l2' l3' l4' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} {C' : UU l4'} (f : A → X) (g : B → X) (c : cone f g C) (f' : A' → X') (g' : B' → X') (c' : cone f' g' C') → is-pullback f g c → is-pullback f' g' c' → is-pullback ( functor-prod f f') (functor-prod g g') (cone-pair f g f' g' c c') is-pullback-prod-is-pullback-pair f g c f' g' c' is-pb-c is-pb-c' = is-equiv-comp ( gap (functor-prod f f') (functor-prod g g') (cone-pair f g f' g' c c')) ( map-cone-pair f g f' g') ( functor-prod (gap f g c) (gap f' g' c')) ( triangle-map-cone-pair f g c f' g' c') ( is-equiv-functor-prod _ _ is-pb-c is-pb-c') ( is-equiv-map-cone-pair f g f' g') map-fib-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (t : C × D) → fib (functor-prod f g) t → (fib f (pr1 t)) × (fib g (pr2 t)) map-fib-functor-prod f g .(functor-prod f g (pair a b)) (pair (pair a b) refl) = pair (pair a refl) (pair b refl) inv-map-fib-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (t : C × D) → (fib f (pr1 t)) × (fib g (pr2 t)) → fib (functor-prod f g) t inv-map-fib-functor-prod f g (pair .(f x) .(g y)) (pair (pair x refl) (pair y refl)) = pair (pair x y) refl issec-inv-map-fib-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (t : C × D) → ((map-fib-functor-prod f g t) ∘ (inv-map-fib-functor-prod f g t)) ~ id issec-inv-map-fib-functor-prod f g (pair .(f x) .(g y)) (pair (pair x refl) (pair y refl)) = refl isretr-inv-map-fib-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (t : C × D) → ((inv-map-fib-functor-prod f g t) ∘ (map-fib-functor-prod f g t)) ~ id isretr-inv-map-fib-functor-prod f g .(functor-prod f g (pair a b)) (pair (pair a b) refl) = refl abstract is-equiv-map-fib-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (t : C × D) → is-equiv (map-fib-functor-prod f g t) is-equiv-map-fib-functor-prod f g t = is-equiv-has-inverse ( inv-map-fib-functor-prod f g t) ( issec-inv-map-fib-functor-prod f g t) ( isretr-inv-map-fib-functor-prod f g t) abstract is-equiv-left-factor-is-equiv-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (d : D) → is-equiv (functor-prod f g) → is-equiv f is-equiv-left-factor-is-equiv-functor-prod f g d is-equiv-fg = is-equiv-is-contr-map ( λ x → is-contr-left-factor-prod ( fib f x) ( fib g d) ( is-contr-is-equiv' ( fib (functor-prod f g) (pair x d)) ( map-fib-functor-prod f g (pair x d)) ( is-equiv-map-fib-functor-prod f g (pair x d)) ( is-contr-map-is-equiv is-equiv-fg (pair x d)))) abstract is-equiv-right-factor-is-equiv-functor-prod : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4} (f : A → C) (g : B → D) (c : C) → is-equiv (functor-prod f g) → is-equiv g is-equiv-right-factor-is-equiv-functor-prod f g c is-equiv-fg = is-equiv-is-contr-map ( λ y → is-contr-right-factor-prod ( fib f c) ( fib g y) ( is-contr-is-equiv' ( fib (functor-prod f g) (pair c y)) ( map-fib-functor-prod f g (pair c y)) ( is-equiv-map-fib-functor-prod f g (pair c y)) ( is-contr-map-is-equiv is-equiv-fg (pair c y)))) abstract is-pullback-left-factor-is-pullback-prod : {l1 l2 l3 l4 l1' l2' l3' l4' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} {C' : UU l4'} (f : A → X) (g : B → X) (c : cone f g C) (f' : A' → X') (g' : B' → X') (c' : cone f' g' C') → is-pullback ( functor-prod f f') ( functor-prod g g') ( cone-pair f g f' g' c c') → canonical-pullback f' g' → is-pullback f g c is-pullback-left-factor-is-pullback-prod f g c f' g' c' is-pb-cc' t = is-equiv-left-factor-is-equiv-functor-prod (gap f g c) (gap f' g' c') t ( is-equiv-right-factor ( gap ( functor-prod f f') ( functor-prod g g') ( cone-pair f g f' g' c c')) ( map-cone-pair f g f' g') ( functor-prod (gap f g c) (gap f' g' c')) ( triangle-map-cone-pair f g c f' g' c') ( is-equiv-map-cone-pair f g f' g') ( is-pb-cc')) abstract is-pullback-right-factor-is-pullback-prod : {l1 l2 l3 l4 l1' l2' l3' l4' : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4} {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} {C' : UU l4'} (f : A → X) (g : B → X) (c : cone f g C) (f' : A' → X') (g' : B' → X') (c' : cone f' g' C') → is-pullback ( functor-prod f f') ( functor-prod g g') ( cone-pair f g f' g' c c') → canonical-pullback f g → is-pullback f' g' c' is-pullback-right-factor-is-pullback-prod f g c f' g' c' is-pb-cc' t = is-equiv-right-factor-is-equiv-functor-prod (gap f g c) (gap f' g' c') t ( is-equiv-right-factor ( gap ( functor-prod f f') ( functor-prod g g') ( cone-pair f g f' g' c c')) ( map-cone-pair f g f' g') ( functor-prod (gap f g c) (gap f' g' c')) ( triangle-map-cone-pair f g c f' g' c') ( is-equiv-map-cone-pair f g f' g') ( is-pb-cc')) -- Exercise 10.8 cone-Π : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} {C : I → UU l5} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) (c : (i : I) → cone (f i) (g i) (C i)) → cone (postcomp-Π f) (postcomp-Π g) ((i : I) → C i) cone-Π f g c = pair ( postcomp-Π (λ i → pr1 (c i))) ( pair ( postcomp-Π (λ i → pr1 (pr2 (c i)))) ( htpy-postcomp-Π (λ i → pr2 (pr2 (c i))))) map-canonical-pullback-Π : {l1 l2 l3 l4 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) → canonical-pullback (postcomp-Π f) (postcomp-Π g) → (i : I) → canonical-pullback (f i) (g i) map-canonical-pullback-Π f g (pair α (pair β γ)) i = pair (α i) (pair (β i) (htpy-eq γ i)) inv-map-canonical-pullback-Π : {l1 l2 l3 l4 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) → ((i : I) → canonical-pullback (f i) (g i)) → canonical-pullback (postcomp-Π f) (postcomp-Π g) inv-map-canonical-pullback-Π f g h = pair ( λ i → (pr1 (h i))) ( pair ( λ i → (pr1 (pr2 (h i)))) ( eq-htpy (λ i → (pr2 (pr2 (h i)))))) issec-inv-map-canonical-pullback-Π : {l1 l2 l3 l4 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) → ((map-canonical-pullback-Π f g) ∘ (inv-map-canonical-pullback-Π f g)) ~ id issec-inv-map-canonical-pullback-Π f g h = eq-htpy ( λ i → eq-Eq-canonical-pullback (f i) (g i) refl refl ( inv ( ( right-unit) ∙ ( htpy-eq (issec-eq-htpy (λ i → (pr2 (pr2 (h i))))) i)))) isretr-inv-map-canonical-pullback-Π : {l1 l2 l3 l4 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) → ((inv-map-canonical-pullback-Π f g) ∘ (map-canonical-pullback-Π f g)) ~ id isretr-inv-map-canonical-pullback-Π f g (pair α (pair β γ)) = eq-Eq-canonical-pullback ( postcomp-Π f) ( postcomp-Π g) refl refl ( inv (right-unit ∙ (isretr-eq-htpy γ))) abstract is-equiv-map-canonical-pullback-Π : {l1 l2 l3 l4 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) → is-equiv (map-canonical-pullback-Π f g) is-equiv-map-canonical-pullback-Π f g = is-equiv-has-inverse ( inv-map-canonical-pullback-Π f g) ( issec-inv-map-canonical-pullback-Π f g) ( isretr-inv-map-canonical-pullback-Π f g) triangle-map-canonical-pullback-Π : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} {C : I → UU l5} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) (c : (i : I) → cone (f i) (g i) (C i)) → ( postcomp-Π (λ i → gap (f i) (g i) (c i))) ~ ( ( map-canonical-pullback-Π f g) ∘ ( gap (postcomp-Π f) (postcomp-Π g) (cone-Π f g c))) triangle-map-canonical-pullback-Π f g c h = eq-htpy (λ i → eq-Eq-canonical-pullback (f i) (g i) refl refl ( (htpy-eq (issec-eq-htpy _) i) ∙ (inv right-unit))) abstract is-pullback-cone-Π : {l1 l2 l3 l4 l5 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {X : I → UU l4} {C : I → UU l5} (f : (i : I) → A i → X i) (g : (i : I) → B i → X i) (c : (i : I) → cone (f i) (g i) (C i)) → ((i : I) → is-pullback (f i) (g i) (c i)) → is-pullback (postcomp-Π f) (postcomp-Π g) (cone-Π f g c) is-pullback-cone-Π f g c is-pb-c = is-equiv-right-factor ( postcomp-Π (λ i → gap (f i) (g i) (c i))) ( map-canonical-pullback-Π f g) ( gap (postcomp-Π f) (postcomp-Π g) (cone-Π f g c)) ( triangle-map-canonical-pullback-Π f g c) ( is-equiv-map-canonical-pullback-Π f g) ( is-equiv-postcomp-Π _ is-pb-c) -- Exercise 10.9 hom-cospan : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ (l1' ⊔ (l2' ⊔ l3'))))) hom-cospan {A = A} {B} {X} f g {A'} {B'} {X'} f' g' = Σ (A → A') (λ hA → Σ (B → B') (λ hB → Σ (X → X') (λ hX → ((f' ∘ hA) ~ (hX ∘ f)) × ((g' ∘ hB) ~ (hX ∘ g))))) id-hom-cospan : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) → hom-cospan f g f g id-hom-cospan f g = pair id (pair id (pair id (pair refl-htpy refl-htpy))) functor-canonical-pullback : {l1 l2 l3 l1' l2' l3' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') → hom-cospan f' g' f g → canonical-pullback f' g' → canonical-pullback f g functor-canonical-pullback f g f' g' (pair hA (pair hB (pair hX (pair HA HB)))) (pair a' (pair b' p')) = pair (hA a') (pair (hB b') ((HA a') ∙ ((ap hX p') ∙ (inv (HB b'))))) cospan-hom-cospan-rotate : {l1 l2 l3 l1' l2' l3' l1'' l2'' l3'' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') {A'' : UU l1''} {B'' : UU l2''} {X'' : UU l3''} (f'' : A'' → X'') (g'' : B'' → X'') (h : hom-cospan f' g' f g) (h' : hom-cospan f'' g'' f g) → hom-cospan (pr1 h) (pr1 h') (pr1 (pr2 (pr2 h))) (pr1 (pr2 (pr2 h'))) cospan-hom-cospan-rotate f g f' g' f'' g'' (pair hA (pair hB (pair hX (pair HA HB)))) (pair hA' (pair hB' (pair hX' (pair HA' HB')))) = pair f' (pair f'' (pair f (pair (htpy-inv HA) (htpy-inv HA')))) cospan-hom-cospan-rotate' : {l1 l2 l3 l1' l2' l3' l1'' l2'' l3'' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') {A'' : UU l1''} {B'' : UU l2''} {X'' : UU l3''} (f'' : A'' → X'') (g'' : B'' → X'') (h : hom-cospan f' g' f g) (h' : hom-cospan f'' g'' f g) → hom-cospan (pr1 (pr2 h)) (pr1 (pr2 h')) (pr1 (pr2 (pr2 h))) (pr1 (pr2 (pr2 h'))) cospan-hom-cospan-rotate' f g f' g' f'' g'' (pair hA (pair hB (pair hX (pair HA HB)))) (pair hA' (pair hB' (pair hX' (pair HA' HB')))) = pair g' (pair g'' (pair g (pair (htpy-inv HB) (htpy-inv HB')))) {- map-3-by-3-canonical-pullback' : {l1 l2 l3 l1' l2' l3' l1'' l2'' l3'' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') {A'' : UU l1''} {B'' : UU l2''} {X'' : UU l3''} (f'' : A'' → X'') (g'' : B → X'') (h : hom-cospan f' g' f g) (h' : hom-cospan f'' g'' f g) → Σ ( canonical-pullback f' g') (λ t' → Σ ( canonical-pullback f'' g'') (λ t'' → Eq-canonical-pullback f g ( functor-canonical-pullback f g f' g' h t') ( functor-canonical-pullback f g f'' g'' h' t''))) → Σ ( canonical-pullback (pr1 h) (pr1 h')) (λ s → Σ ( canonical-pullback (pr1 (pr2 h)) (pr1 (pr2 h'))) (λ s' → Eq-canonical-pullback (pr1 (pr2 (pr2 h))) (pr1 (pr2 (pr2 h'))) ( functor-canonical-pullback ( pr1 (pr2 (pr2 h))) ( pr1 (pr2 (pr2 h'))) ( pr1 h) ( pr1 h') ( cospan-hom-cospan-rotate f g f' g' f'' g'' h h') ( s)) ( functor-canonical-pullback ( pr1 (pr2 (pr2 h))) ( pr1 (pr2 (pr2 h'))) ( pr1 (pr2 h)) ( pr1 (pr2 h')) ( cospan-hom-cospan-rotate' f g f' g' f'' g'' h h') ( s')))) map-3-by-3-canonical-pullback' f g f' g' f'' g'' ( pair hA (pair hB (pair hX (pair HA HB)))) ( pair hA' (pair hB' (pair hX' (pair HA' HB')))) ( pair ( pair a' (pair b' p')) ( pair (pair a'' (pair b'' p'')) (pair α (pair β γ)))) = pair (pair a' (pair a'' α)) (pair (pair b' (pair b'' β)) (pair p' (pair p'' {!!}))) map-3-by-3-canonical-pullback : {l1 l2 l3 l1' l2' l3' l1'' l2'' l3'' : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) {A' : UU l1'} {B' : UU l2'} {X' : UU l3'} (f' : A' → X') (g' : B' → X') {A'' : UU l1''} {B'' : UU l2''} {X'' : UU l3''} (f'' : A'' → X'') (g'' : B → X'') (h : hom-cospan f' g' f g) (h' : hom-cospan f'' g'' f g) → canonical-pullback ( functor-canonical-pullback f g f' g' h) ( functor-canonical-pullback f g f'' g'' h') → canonical-pullback ( functor-canonical-pullback ( pr1 (pr2 (pr2 h))) ( pr1 (pr2 (pr2 h'))) ( pr1 h) ( pr1 h') ( cospan-hom-cospan-rotate f g f' g' f'' g'' h h')) ( functor-canonical-pullback ( pr1 (pr2 (pr2 h))) ( pr1 (pr2 (pr2 h'))) ( pr1 (pr2 h)) ( pr1 (pr2 h')) ( cospan-hom-cospan-rotate' f g f' g' f'' g'' h h')) map-3-by-3-canonical-pullback = {!!} -}
38.121133
135
0.513684
ed5504e28a7270f882977aa7ae2969792e9a6629
127
agda
Agda
test/Fail/TuplePat.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
55
2020-10-20T13:36:25.000Z
2022-03-26T21:57:56.000Z
test/Fail/TuplePat.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
63
2020-10-22T05:19:27.000Z
2022-02-25T15:47:30.000Z
test/Fail/TuplePat.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
18
2020-10-21T22:19:09.000Z
2022-03-12T11:42:52.000Z
module Fail.TuplePat where open import Haskell.Prelude fst₃ : a × b × c → a fst₃ (x ∷ xs) = x {-# COMPILE AGDA2HS fst₃ #-}
12.7
28
0.637795
373da7b87d35ddcbe4d299c7898bcbdcdb07f330
11,262
agda
Agda
Cubical/Algebra/Group/MorphismProperties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/Group/MorphismProperties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/Group/MorphismProperties.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- This file contains: - Elementary properties of homomorphisms - H-level results for the properties of morphisms - Special homomorphisms and operations (id, composition, inversion) - Conversion functions between different notions of group morphisms -} {-# OPTIONS --safe #-} module Cubical.Algebra.Group.MorphismProperties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.DirProd open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Morphisms open import Cubical.HITs.PropositionalTruncation hiding (map) private variable ℓ ℓ' ℓ'' ℓ''' : Level F G H : Group ℓ open Iso open GroupStr open IsGroupHom open BijectionIso -- Elementary properties of homomorphisms module _ {A : Type ℓ} {B : Type ℓ'} (G : GroupStr A) (f : A → B) (H : GroupStr B) (pres : (x y : A) → f (G ._·_ x y) ≡ H ._·_ (f x) (f y)) where private module G = GroupStr G module H = GroupStr H -- ϕ(1g) ≡ 1g hom1g : f G.1g ≡ H.1g hom1g = f G.1g ≡⟨ sym (H.rid _) ⟩ f G.1g H.· H.1g ≡⟨ (λ i → f G.1g H.· H.invr (f G.1g) (~ i)) ⟩ f G.1g H.· (f G.1g H.· H.inv (f G.1g)) ≡⟨ H.assoc _ _ _ ⟩ (f G.1g H.· f G.1g) H.· H.inv (f G.1g) ≡⟨ sym (cong (λ x → x H.· _) (sym (cong f (G.lid _)) ∙ pres G.1g G.1g)) ⟩ f G.1g H.· H.inv (f G.1g) ≡⟨ H.invr _ ⟩ H.1g ∎ -- ϕ(- x) = - ϕ(x) homInv : ∀ g → f (G.inv g) ≡ H.inv (f g) homInv g = f (G.inv g) ≡⟨ sym (H.rid _) ⟩ f (G.inv g) H.· H.1g ≡⟨ cong (_ H.·_) (sym (H.invr _)) ⟩ f (G.inv g) H.· (f g H.· H.inv (f g)) ≡⟨ H.assoc _ _ _ ⟩ (f (G.inv g) H.· f g) H.· H.inv (f g) ≡⟨ cong (H._· _) (sym (pres _ g) ∙∙ cong f (G.invl g) ∙∙ hom1g) ⟩ H.1g H.· H.inv (f g) ≡⟨ H.lid _ ⟩ H.inv (f g) ∎ module _ {A : Type ℓ} {B : Type ℓ'} {G : GroupStr A} {f : A → B} {H : GroupStr B} (pres : (x y : A) → f (G ._·_ x y) ≡ H ._·_ (f x) (f y)) where makeIsGroupHom : IsGroupHom G f H makeIsGroupHom .pres· = pres makeIsGroupHom .pres1 = hom1g G f H pres makeIsGroupHom .presinv = homInv G f H pres -- H-level results isPropIsGroupHom : (G : Group ℓ) (H : Group ℓ') {f : ⟨ G ⟩ → ⟨ H ⟩} → isProp (IsGroupHom (G .snd) f (H .snd)) isPropIsGroupHom G H = isOfHLevelRetractFromIso 1 IsGroupHomIsoΣ (isProp× (isPropΠ2 λ _ _ → GroupStr.is-set (snd H) _ _) (isProp× (GroupStr.is-set (snd H) _ _) (isPropΠ λ _ → GroupStr.is-set (snd H) _ _))) isSetGroupHom : isSet (GroupHom G H) isSetGroupHom {G = G} {H = H} = isSetΣ (isSetΠ λ _ → is-set (snd H)) λ _ → isProp→isSet (isPropIsGroupHom G H) isPropIsInIm : (f : GroupHom G H) (x : ⟨ H ⟩) → isProp (isInIm f x) isPropIsInIm f x = squash isSetIm : (f : GroupHom G H) → isSet (Im f) isSetIm {H = H} f = isSetΣ (is-set (snd H)) λ x → isProp→isSet (isPropIsInIm f x) isPropIsInKer : (f : GroupHom G H) (x : ⟨ G ⟩) → isProp (isInKer f x) isPropIsInKer {H = H} f x = is-set (snd H) _ _ isSetKer : (f : GroupHom G H) → isSet (Ker f) isSetKer {G = G} f = isSetΣ (is-set (snd G)) λ x → isProp→isSet (isPropIsInKer f x) isPropIsSurjective : (f : GroupHom G H) → isProp (isSurjective f) isPropIsSurjective f = isPropΠ (λ x → isPropIsInIm f x) isPropIsInjective : (f : GroupHom G H) → isProp (isInjective f) isPropIsInjective {G = G} _ = isPropΠ2 (λ _ _ → is-set (snd G) _ _) isPropIsMono : (f : GroupHom G H) → isProp (isMono f) isPropIsMono {G = G} f = isPropImplicitΠ2 λ _ _ → isPropΠ (λ _ → is-set (snd G) _ _) -- Logically equivalent versions of isInjective isMono→isInjective : (f : GroupHom G H) → isMono f → isInjective f isMono→isInjective f h x p = h (p ∙ sym (f .snd .pres1)) isInjective→isMono : (f : GroupHom G H) → isInjective f → isMono f isInjective→isMono {G = G} {H = H} f h {x = x} {y = y} p = x ≡⟨ sym (G.rid _) ⟩ x G.· G.1g ≡⟨ cong (x G.·_) (sym (G.invl _)) ⟩ x G.· (G.inv y G.· y) ≡⟨ G.assoc _ _ _ ⟩ (x G.· G.inv y) G.· y ≡⟨ cong (G._· y) idHelper ⟩ G.1g G.· y ≡⟨ G.lid _ ⟩ y ∎ where module G = GroupStr (snd G) module H = GroupStr (snd H) idHelper : x G.· G.inv y ≡ G.1g idHelper = h _ (f .snd .pres· _ _ ∙ cong (λ a → f .fst x H.· a) (f .snd .presinv y) ∙ cong (H._· H.inv (f .fst y)) p ∙ H.invr _) -- TODO: maybe it would be better to take this as the definition of isInjective? isInjective→isContrKer : (f : GroupHom G H) → isInjective f → isContr (Ker f) fst (isInjective→isContrKer {G = G} f hf) = 1g (snd G) , f .snd .pres1 snd (isInjective→isContrKer {G = G} f hf) k = Σ≡Prop (isPropIsInKer f) (sym (isInjective→isMono f hf (k .snd ∙ sym (f .snd .pres1)))) isContrKer→isInjective : (f : GroupHom G H) → isContr (Ker f) → isInjective f isContrKer→isInjective {G = G} f ((a , b) , c) x y = cong fst (sym (c (x , y)) ∙ rem) where rem : (a , b) ≡ (1g (snd G) , pres1 (snd f)) rem = c (1g (snd G) , pres1 (snd f)) -- Special homomorphisms and operations (id, composition...) idGroupHom : GroupHom G G idGroupHom .fst x = x idGroupHom .snd = makeIsGroupHom λ _ _ → refl isGroupHomComp : (f : GroupHom F G) → (g : GroupHom G H) → IsGroupHom (F .snd) (fst g ∘ fst f) (H .snd) isGroupHomComp f g = makeIsGroupHom λ _ _ → cong (fst g) (f .snd .pres· _ _) ∙ (g .snd .pres· _ _) compGroupHom : GroupHom F G → GroupHom G H → GroupHom F H fst (compGroupHom f g) = fst g ∘ fst f snd (compGroupHom f g) = isGroupHomComp f g GroupHomDirProd : {A : Group ℓ} {B : Group ℓ'} {C : Group ℓ''} {D : Group ℓ'''} → GroupHom A C → GroupHom B D → GroupHom (DirProd A B) (DirProd C D) fst (GroupHomDirProd mf1 mf2) = map-× (fst mf1) (fst mf2) snd (GroupHomDirProd mf1 mf2) = makeIsGroupHom λ _ _ → ≡-× (mf1 .snd .pres· _ _) (mf2 .snd .pres· _ _) GroupHom≡ : {f g : GroupHom G H} → (fst f ≡ fst g) → f ≡ g fst (GroupHom≡ p i) = p i snd (GroupHom≡ {G = G} {H = H} {f = f} {g = g} p i) = p-hom i where p-hom : PathP (λ i → IsGroupHom (G .snd) (p i) (H .snd)) (f .snd) (g .snd) p-hom = toPathP (isPropIsGroupHom G H _ _) -- GroupEquiv identity, composition and inversion idGroupEquiv : GroupEquiv G G fst (idGroupEquiv {G = G}) = idEquiv ⟨ G ⟩ snd idGroupEquiv = makeIsGroupHom λ _ _ → refl compGroupEquiv : GroupEquiv F G → GroupEquiv G H → GroupEquiv F H fst (compGroupEquiv f g) = compEquiv (fst f) (fst g) snd (compGroupEquiv f g) = isGroupHomComp (_ , f .snd) (_ , g .snd) invGroupEquiv : GroupEquiv G H → GroupEquiv H G fst (invGroupEquiv f) = invEquiv (fst f) snd (invGroupEquiv f) = isGroupHomInv f where isGroupHomInv : (f : GroupEquiv G H) → IsGroupHom (H .snd) (invEq (fst f)) (G .snd) isGroupHomInv {G = G} {H = H} f = makeIsGroupHom λ h h' → isInj-f _ _ (f' (g (h ⋆² h')) ≡⟨ secEq (fst f) _ ⟩ (h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (secEq (fst f) h) (secEq (fst f) h')) ⟩ (f' (g h) ⋆² f' (g h')) ≡⟨ sym (pres· (snd f) _ _) ⟩ f' (g h ⋆¹ g h') ∎) where f' = fst (fst f) _⋆¹_ = _·_ (snd G) _⋆²_ = _·_ (snd H) g = invEq (fst f) isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y isInj-f x y = invEq (_ , isEquiv→isEmbedding (snd (fst f)) x y) GroupEquivDirProd : {A : Group ℓ} {B : Group ℓ'} {C : Group ℓ''} {D : Group ℓ'''} → GroupEquiv A C → GroupEquiv B D → GroupEquiv (DirProd A B) (DirProd C D) fst (GroupEquivDirProd eq1 eq2) = ≃-× (fst eq1) (fst eq2) snd (GroupEquivDirProd eq1 eq2) = GroupHomDirProd (_ , eq1 .snd) (_ , eq2 .snd) .snd GroupEquiv≡ : {f g : GroupEquiv G H} → fst f ≡ fst g → f ≡ g fst (GroupEquiv≡ p i) = p i snd (GroupEquiv≡ {G = G} {H = H} {f} {g} p i) = p-hom i where p-hom : PathP (λ i → IsGroupHom (G .snd) (p i .fst) (H .snd)) (snd f) (snd g) p-hom = toPathP (isPropIsGroupHom G H _ _) -- GroupIso identity, composition and inversion idGroupIso : GroupIso G G fst idGroupIso = idIso snd idGroupIso = makeIsGroupHom λ _ _ → refl compGroupIso : GroupIso G H → GroupIso H F → GroupIso G F fst (compGroupIso iso1 iso2) = compIso (fst iso1) (fst iso2) snd (compGroupIso iso1 iso2) = isGroupHomComp (_ , snd iso1) (_ , snd iso2) invGroupIso : GroupIso G H → GroupIso H G fst (invGroupIso iso1) = invIso (fst iso1) snd (invGroupIso iso1) = isGroupHomInv iso1 where isGroupHomInv : (f : GroupIso G H) → IsGroupHom (H .snd) (inv (fst f)) (G .snd) isGroupHomInv {G = G} {H = H} f = makeIsGroupHom λ h h' → isInj-f _ _ (f' (g (h ⋆² h')) ≡⟨ (rightInv (fst f)) _ ⟩ (h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (rightInv (fst f) h) (rightInv (fst f) h')) ⟩ (f' (g h) ⋆² f' (g h')) ≡⟨ sym (f .snd .pres· _ _) ⟩ f' (g h ⋆¹ g h') ∎) where f' = fun (fst f) _⋆¹_ = GroupStr._·_ (snd G) _⋆²_ = GroupStr._·_ (snd H) g = inv (fst f) isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y isInj-f x y p = sym (leftInv (fst f) _) ∙∙ cong g p ∙∙ leftInv (fst f) _ GroupIsoDirProd : {G : Group ℓ} {H : Group ℓ'} {A : Group ℓ''} {B : Group ℓ'''} → GroupIso G H → GroupIso A B → GroupIso (DirProd G A) (DirProd H B) fun (fst (GroupIsoDirProd iso1 iso2)) prod = fun (fst iso1) (fst prod) , fun (fst iso2) (snd prod) inv (fst (GroupIsoDirProd iso1 iso2)) prod = inv (fst iso1) (fst prod) , inv (fst iso2) (snd prod) rightInv (fst (GroupIsoDirProd iso1 iso2)) a = ΣPathP (rightInv (fst iso1) (fst a) , (rightInv (fst iso2) (snd a))) leftInv (fst (GroupIsoDirProd iso1 iso2)) a = ΣPathP (leftInv (fst iso1) (fst a) , (leftInv (fst iso2) (snd a))) snd (GroupIsoDirProd iso1 iso2) = makeIsGroupHom λ a b → ΣPathP (pres· (snd iso1) (fst a) (fst b) , pres· (snd iso2) (snd a) (snd b)) -- Conversion functions between different notions of group morphisms GroupIso→GroupEquiv : GroupIso G H → GroupEquiv G H fst (GroupIso→GroupEquiv i) = isoToEquiv (fst i) snd (GroupIso→GroupEquiv i) = snd i GroupEquiv→GroupIso : GroupEquiv G H → GroupIso G H fst (GroupEquiv→GroupIso e) = equivToIso (fst e) snd (GroupEquiv→GroupIso e) = snd e -- TODO: prove the converse BijectionIso→GroupIso : BijectionIso G H → GroupIso G H BijectionIso→GroupIso {G = G} {H = H} i = grIso where f = fst (fun i) helper : (b : _) → isProp (Σ[ a ∈ ⟨ G ⟩ ] f a ≡ b) helper _ (a , ha) (b , hb) = Σ≡Prop (λ _ → is-set (snd H) _ _) (isInjective→isMono (fun i) (inj i) (ha ∙ sym hb) ) grIso : GroupIso G H fun (fst grIso) = f inv (fst grIso) b = rec (helper b) (λ a → a) (surj i b) .fst rightInv (fst grIso) b = rec (helper b) (λ a → a) (surj i b) .snd leftInv (fst grIso) b j = rec (helper (f b)) (λ a → a) (isPropPropTrunc (surj i (f b)) ∣ b , refl ∣ j) .fst snd grIso = snd (fun i) BijectionIsoToGroupEquiv : BijectionIso G H → GroupEquiv G H BijectionIsoToGroupEquiv i = GroupIso→GroupEquiv (BijectionIso→GroupIso i)
38.176271
108
0.589416
4efca6a30c542ca6d9e849822196401523d9c25f
4,657
agda
Agda
Syntax/PredicateLifting.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
2
2016-04-27T14:45:11.000Z
2018-04-06T02:10:49.000Z
Syntax/PredicateLifting.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
1
2020-07-24T12:53:30.000Z
2020-07-24T12:53:30.000Z
Syntax/PredicateLifting.agda
StillerHarpo/CoindDepTypes
480ee27c2c0c20fb35f371177a68721cbc6668c3
[ "Unlicense" ]
1
2020-07-24T10:54:38.000Z
2020-07-24T10:54:38.000Z
module PredicateLifting where import Level open import Data.Empty open import Data.Unit as Unit open import Data.Nat open import Data.List as List renaming ([] to Ø; [_] to [_]L) open import NonEmptyList as NList open import Data.Fin hiding (_+_) open import Data.Vec as Vec renaming ([_] to [_]V; _++_ to _++V_) open import Data.Product as Prod open import Function open import Relation.Binary.PropositionalEquality as PE hiding ([_]) open import Relation.Binary open ≡-Reasoning open import Common.Context as Context open import Algebra open Monoid {{ ... }} hiding (refl) open import SyntaxRaw open import Syntax -- | Extend the parameter context of each type variable in the given -- type context by one extra variable. We need this to specify the new -- type variable context, in which the predicate lifting of a type lives. -- See predL below for the correspond typing rule. liftTyCtx : ∀ {Θ} → TyCtxMorP Ø Θ → TyCtx liftTyCtx {Ø} f = Ø liftTyCtx {Γ ∷ Θ} (A , f) = (∗ ∷ Γ) ∷ liftTyCtx f -- | Extend a parameter context by a variable of the given type. extTyVarParams : (Γ₂ : RawCtx) → PreType Ø Ø Γ₂ → RawCtx extTyVarParams Γ₂ A = ∗ ∷ Γ₂ -- | Get the Yᵢ : (Γᵢ, xᵢ : Bᵢ) ⊸ ∗ corresponding to Xᵢ : Γᵢ ⊸ ∗ in -- the lifted context, c.f. the typing rule for predL below. liftTyVar : ∀{Θ Γ₂} → (f : TyCtxMorP Ø Θ) (X : TyVar Θ Γ₂) → TyVar (liftTyCtx f) (extTyVarParams Γ₂ (getTy f X)) liftTyVar f zero = zero liftTyVar (A , f) (succ Γ X) = succ (extTyVarParams Γ (getTy f X)) (liftTyVar f X) -- | Turn an instantiation into a substitution. instToSubst : ∀{Γ₁} (A : U) (Γ₂ : RawCtx) → PreTerm Γ₁ Ø → CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ (Γ₂ ↑ A) ++ Γ₁) instToSubst {Γ₁} A Γ₂ t = let f = weakenPO' (∗ ∷ Γ₂) t ∷ ctxProjP Γ₁ (∗ ∷ Γ₂) in subst (CtxMorP (∗ ∷ Γ₂ ++ Γ₁)) (PE.sym (cong (_∷_ ∗ ) (assoc Γ₂ (A ∷ Ø) Γ₁))) (extendProj (∗ ∷ Γ₂) Ø f) -- | Auxiliary function to define predL below. predL₀ : ∀ {Θ Γ₁ Γ₂} → (A : Raw Θ Γ₁ Γ₂) → DecentType A → (f : TyCtxMorP Ø Θ) → liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty predL₀ ._ (DT-⊤ Θ Γ) f = ⊤-PT (liftTyCtx f) (∗ ∷ Ø ++ Γ) predL₀ ._ (DT-tyVar Γ₁ X) f = tyVarPT _ (liftTyVar f X) §ₜ ctxProjP' Ø _ Γ₁ predL₀ ._ (DT-inst {Γ₂ = Γ₂} B t B-dec t-dec) f = let B' = predL₀ B B-dec f in substPT B' (instToSubst _ Γ₂ (mkPreTerm t-dec)) predL₀ ._ (DT-paramAbstr {Γ₂ = Γ₂} {B = B} Γ₁ A-dec) f = subst (λ u → PreType (liftTyCtx f) u Ø) (cong (_∷_ ∗) (PE.sym (assoc Γ₂ (B ∷ Ø) Γ₁))) (predL₀ _ A-dec f) predL₀ {Θ} {.Γ₁} {Γ₂} ._ (DT-fp Γ₁ ρ D p) f = fpPT (∗ ∷ Γ₂ ++ Γ₁) ρ (mkD' D p 0) §ₜ f' where f' : CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ Γ₂) f' = extendP ∗ (ctxProjP' Ø Γ₂ Γ₁) mkD' : (D : FpData Raw Θ Γ₂) → DecentFpData D → ℕ → FpDataP (liftTyCtx f) (∗ ∷ Γ₂) mkD' [ Γ , g , A ] (g-dec , A-dec) k = let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f) in [ ( (∗ ∷ Γ) , (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ)) ∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø)) , A' ) ] mkD' ((Γ , g , A) ∷ D₁) ((g-dec , A-dec) , q) k = let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f) in ( ∗ ∷ Γ , (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ)) ∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø)) , A' ) ∷ mkD' D₁ q (suc k) -- | Lift an open type A to predicates. More specifically, predL -- implements the following rule, in which we write Ā for predL A. -- X₁ : Δ₁ ⊸ Ty, ..., Xₙ : Δₙ ⊸ Ty | Γ₁ ⊢ A : Γ₂ ⊸ Ty -- B₁ : Δ₁ ⊸ Ty -- ... -- Bₙ : Δ₁ ⊸ Ty -- ================================================================= (predL) -- Y₁ : (Δ₁, x₁ : B₁ ⊙ id) ⊸ Ty, ..., (Yₙ : Δₙ, xₙ : Bₙ ⊙ id) ⊸ Ty -- | Γ₁, Γ₂, z : A[B₁/X₁, ..., Bₙ/Xₙ] ⊙ id -- ⊢ Ā : Ty predL : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → (f : TyCtxMorP Ø Θ) → -- =========================================================== liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty predL (A , A-dec) = predL₀ A A-dec -- | Special instance of the predicate lifting for types with one -- free variable and no parameters. -- X : Δ ⊸ Ty | Γ ⊢ A : Ty B : Δ ⊸ Ty -- =============================================================== (predL₁) -- Y : (Δ, x : B ⊙ id) ⊸ ∗ | Γ, z : A[B/X] ⊢ Ā : Ty predL₁ : ∀ {Δ Γ} → ((Δ ∷ Ø) ∣ Γ / Ø ⊸Ty) → (Ø ∣ Ø / Δ ⊸Ty) → -- =========================================================== ((∗ ∷ Δ) ∷ Ø) ∣ ∗ ∷ Γ / Ø ⊸Ty predL₁ A B = predL A (B , tt)
38.808333
78
0.50204
edbfdef78b2f249e4638c747f8a2a2890d825877
11,942
agda
Agda
src/ctxt.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/ctxt.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/ctxt.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
module ctxt where open import lib open import cedille-types open import ctxt-types public open import subst open import general-util open import syntax-util new-sym-info-trie : trie sym-info new-sym-info-trie = trie-insert empty-trie compileFail-qual ((term-decl compileFailType) , "missing" , "missing") new-qualif : qualif new-qualif = trie-insert empty-trie compileFail (compileFail-qual , ArgsNil) qualif-nonempty : qualif → 𝔹 qualif-nonempty q = trie-nonempty (trie-remove q compileFail) new-ctxt : (filename modname : string) → ctxt new-ctxt fn mn = mk-ctxt (fn , mn , ParamsNil , new-qualif) (empty-trie , empty-trie , empty-trie , empty-trie , 0 , []) new-sym-info-trie empty-trie empty-trie empty-ctxt : ctxt empty-ctxt = new-ctxt "" "" ctxt-get-info : var → ctxt → maybe sym-info ctxt-get-info v (mk-ctxt _ _ i _ _) = trie-lookup i v ctxt-set-qualif : ctxt → qualif → ctxt ctxt-set-qualif (mk-ctxt (f , m , p , q') syms i sym-occurrences d) q = mk-ctxt (f , m , p , q) syms i sym-occurrences d ctxt-get-qualif : ctxt → qualif ctxt-get-qualif (mk-ctxt (_ , _ , _ , q) _ _ _ _) = q ctxt-get-qi : ctxt → var → maybe qualif-info ctxt-get-qi Γ = trie-lookup (ctxt-get-qualif Γ) ctxt-qualif-args-length : ctxt → maybeErased → var → maybe ℕ ctxt-qualif-args-length Γ me v = ctxt-get-qi Γ v ≫=maybe λ qv → just (me-args-length me (snd qv)) qi-var-if : maybe qualif-info → var → var qi-var-if (just (v , _)) _ = v qi-var-if nothing v = v ctxt-restore-info : ctxt → var → maybe qualif-info → maybe sym-info → ctxt ctxt-restore-info (mk-ctxt (fn , mn , ps , q) syms i symb-occs d) v qi si = mk-ctxt (fn , mn , ps , f qi v q) syms (f si (qi-var-if qi v) (trie-remove i (qi-var-if (trie-lookup q v) v))) symb-occs d where f : ∀{A : Set} → maybe A → string → trie A → trie A f (just a) s t = trie-insert t s a f nothing s t = trie-remove t s ctxt-restore-info* : ctxt → 𝕃 (string × maybe qualif-info × maybe sym-info) → ctxt ctxt-restore-info* Γ [] = Γ ctxt-restore-info* Γ ((v , qi , m) :: ms) = ctxt-restore-info* (ctxt-restore-info Γ v qi m) ms def-params : defScope → params → defParams def-params tt ps = nothing def-params ff ps = just ps -- TODO add renamectxt to avoid capture bugs? inst-type : ctxt → params → args → type → type inst-type Γ ps as T with mk-inst ps as ...| σ , ps' = abs-expand-type (substs-params Γ σ ps') (substs Γ σ T) inst-kind : ctxt → params → args → kind → kind inst-kind Γ ps as k with mk-inst ps as ...| σ , ps' = abs-expand-kind (substs-params Γ σ ps') (substs Γ σ k) qualif-x : ∀ {ℓ} {X : Set ℓ} → (ctxt → qualif → X) → ctxt → X qualif-x f Γ = f Γ (ctxt-get-qualif Γ) qualif-term = qualif-x $ substs {TERM} qualif-type = qualif-x $ substs {TYPE} qualif-kind = qualif-x $ substs {KIND} qualif-liftingType = qualif-x $ substs {LIFTINGTYPE} qualif-tk = qualif-x $ substs {TK} qualif-params = qualif-x substs-params qualif-args = qualif-x substs-args erased-margs : ctxt → stringset erased-margs = stringset-insert* empty-stringset ∘ (erased-params ∘ ctxt-get-current-params) ctxt-term-decl : posinfo → var → type → ctxt → ctxt ctxt-term-decl p v t Γ@(mk-ctxt (fn , mn , ps , q) syms i symb-occs d) = mk-ctxt (fn , mn , ps , (qualif-insert-params q v' v ParamsNil)) syms (trie-insert i v' ((term-decl (qualif-type Γ t)) , fn , p)) symb-occs d where v' = p % v ctxt-type-decl : posinfo → var → kind → ctxt → ctxt ctxt-type-decl p v k Γ@(mk-ctxt (fn , mn , ps , q) syms i symb-occs d) = mk-ctxt (fn , mn , ps , (qualif-insert-params q v' v ParamsNil)) syms (trie-insert i v' (type-decl (qualif-kind Γ k) , fn , p)) symb-occs d where v' = p % v ctxt-tk-decl : posinfo → var → tk → ctxt → ctxt ctxt-tk-decl p x (Tkt t) Γ = ctxt-term-decl p x t Γ ctxt-tk-decl p x (Tkk k) Γ = ctxt-type-decl p x k Γ -- TODO not sure how this and renaming interacts with module scope ctxt-var-decl-if : var → ctxt → ctxt ctxt-var-decl-if v Γ with Γ ... | mk-ctxt (fn , mn , ps , q) syms i symb-occs d with trie-lookup i v ... | just (rename-def _ , _) = Γ ... | just (var-decl , _) = Γ ... | _ = mk-ctxt (fn , mn , ps , (trie-insert q v (v , ArgsNil))) syms (trie-insert i v (var-decl , "missing" , "missing")) symb-occs d ctxt-rename-rep : ctxt → var → var ctxt-rename-rep (mk-ctxt m syms i _ _) v with trie-lookup i v ... | just (rename-def v' , _) = v' ... | _ = v -- we assume that only the left variable might have been renamed ctxt-eq-rep : ctxt → var → var → 𝔹 ctxt-eq-rep Γ x y = (ctxt-rename-rep Γ x) =string y {- add a renaming mapping the first variable to the second, unless they are equal. Notice that adding a renaming for v will overwrite any other declarations for v. -} ctxt-rename : var → var → ctxt → ctxt ctxt-rename v v' Γ @ (mk-ctxt (fn , mn , ps , q) syms i symb-occs d) = (mk-ctxt (fn , mn , ps , qualif-insert-params q v' v ps) syms (trie-insert i v (rename-def v' , "missing" , "missing")) symb-occs d) ---------------------------------------------------------------------- -- lookup functions ---------------------------------------------------------------------- -- lookup mod params from filename lookup-mod-params : ctxt → var → maybe params lookup-mod-params (mk-ctxt _ (syms , _ , mn-ps , id) _ _ _) fn = trie-lookup syms fn ≫=maybe λ { (mn , _) → trie-lookup mn-ps mn } -- look for a defined kind for the given var, which is assumed to be a type, -- then instantiate its parameters qual-lookup : ctxt → var → maybe (args × sym-info) qual-lookup Γ@(mk-ctxt (_ , _ , _ , q) _ i _ _) v = trie-lookup q v ≫=maybe λ qv → trie-lookup i (fst qv) ≫=maybe λ si → just (snd qv , si) env-lookup : ctxt → var → maybe sym-info env-lookup Γ@(mk-ctxt (_ , _ , _ , _) _ i _ _) v = trie-lookup i v -- look for a declared kind for the given var, which is assumed to be a type, -- otherwise look for a qualified defined kind ctxt-lookup-type-var : ctxt → var → maybe kind ctxt-lookup-type-var Γ v with qual-lookup Γ v ... | just (as , type-decl k , _) = just k ... | just (as , type-def (just ps) _ T k , _) = just (inst-kind Γ ps as k) ... | just (as , type-def nothing _ T k , _) = just k ... | just (as , datatype-def _ k , _) = just k ... | _ = nothing -- remove ? -- add-param-type : params → type → type -- add-param-type (ParamsCons (Decl pi pix e x tk _) ps) ty = Abs pi e pix x tk (add-param-type ps ty) -- add-param-type ParamsNil ty = ty ctxt-lookup-term-var : ctxt → var → maybe type ctxt-lookup-term-var Γ v with qual-lookup Γ v ... | just (as , term-decl T , _) = just T ... | just (as , term-def (just ps) _ t T , _) = just $ inst-type Γ ps as T ... | just (as , term-def nothing _ t T , _) = just T ... | just (as , const-def T , _) = just T ... | _ = nothing ctxt-lookup-tk-var : ctxt → var → maybe tk ctxt-lookup-tk-var Γ v with qual-lookup Γ v ... | just (as , term-decl T , _) = just $ Tkt T ... | just (as , type-decl k , _) = just $ Tkk k ... | just (as , term-def (just ps) _ t T , _) = just $ Tkt $ inst-type Γ ps as T ... | just (as , type-def (just ps) _ T k , _) = just $ Tkk $ inst-kind Γ ps as k ... | just (as , term-def nothing _ t T , _) = just $ Tkt T ... | just (as , type-def nothing _ T k , _) = just $ Tkk k ... | just (as , datatype-def _ k , _) = just $ Tkk k ... | _ = nothing ctxt-lookup-term-var-def : ctxt → var → maybe term ctxt-lookup-term-var-def Γ v with env-lookup Γ v ... | just (term-def nothing OpacTrans t _ , _) = just t ... | just (term-udef nothing OpacTrans t , _) = just t ... | just (term-def (just ps) OpacTrans t _ , _) = just $ lam-expand-term ps t ... | just (term-udef (just ps) OpacTrans t , _) = just $ lam-expand-term ps t ... | _ = nothing ctxt-lookup-type-var-def : ctxt → var → maybe type ctxt-lookup-type-var-def Γ v with env-lookup Γ v ... | just (type-def nothing OpacTrans T _ , _) = just T ... | just (type-def (just ps) OpacTrans T _ , _) = just $ lam-expand-type ps T ... | _ = nothing ctxt-lookup-kind-var-def : ctxt → var → maybe (params × kind) ctxt-lookup-kind-var-def Γ x with env-lookup Γ x ... | just (kind-def ps k , _) = just (ps , k) ... | _ = nothing ctxt-lookup-kind-var-def-args : ctxt → var → maybe (params × args) ctxt-lookup-kind-var-def-args Γ@(mk-ctxt (_ , _ , _ , q) _ i _ _) v with trie-lookup q v ... | just (v' , as) = ctxt-lookup-kind-var-def Γ v' ≫=maybe λ { (ps , k) → just (ps , as) } ... | _ = nothing ctxt-lookup-occurrences : ctxt → var → 𝕃 (var × posinfo × string) ctxt-lookup-occurrences (mk-ctxt _ _ _ symb-occs _) symbol with trie-lookup symb-occs symbol ... | just l = l ... | nothing = [] ---------------------------------------------------------------------- ctxt-var-location : ctxt → var → location ctxt-var-location (mk-ctxt _ _ i _ _) x with trie-lookup i x ... | just (_ , l) = l ... | nothing = "missing" , "missing" ctxt-clarify-def : ctxt → var → maybe (sym-info × ctxt) ctxt-clarify-def Γ@(mk-ctxt mod@(_ , _ , _ , q) syms i sym-occurrences d) x = trie-lookup i x ≫=maybe λ { (ci , l) → clarified x ci l } where ctxt' : var → ctxt-info → location → ctxt ctxt' v ci l = mk-ctxt mod syms (trie-insert i v (ci , l)) sym-occurrences d clarified : var → ctxt-info → location → maybe (sym-info × ctxt) clarified v ci@(term-def ps _ t T) l = just ((ci , l) , (ctxt' v (term-def ps OpacTrans t T) l)) clarified v ci@(term-udef ps _ t) l = just ((ci , l) , (ctxt' v (term-udef ps OpacTrans t) l)) clarified v ci@(type-def ps _ T k) l = just ((ci , l) , (ctxt' v (type-def ps OpacTrans T k) l)) clarified _ _ _ = nothing ctxt-set-sym-info : ctxt → var → sym-info → ctxt ctxt-set-sym-info (mk-ctxt mod syms i sym-occurrences d) x si = mk-ctxt mod syms (trie-insert i x si) sym-occurrences d ctxt-restore-clarified-def : ctxt → var → sym-info → ctxt ctxt-restore-clarified-def = ctxt-set-sym-info ctxt-set-current-file : ctxt → string → string → ctxt ctxt-set-current-file (mk-ctxt _ syms i symb-occs d) fn mn = mk-ctxt (fn , mn , ParamsNil , new-qualif) syms i symb-occs d ctxt-set-current-mod : ctxt → mod-info → ctxt ctxt-set-current-mod (mk-ctxt _ syms i symb-occs d) m = mk-ctxt m syms i symb-occs d ctxt-add-current-params : ctxt → ctxt ctxt-add-current-params Γ@(mk-ctxt m@(fn , mn , ps , _) (syms , mn-fn , mn-ps , ids) i symb-occs d) = mk-ctxt m (trie-insert syms fn (mn , []) , mn-fn , trie-insert mn-ps mn ps , ids) i symb-occs d ctxt-clear-symbol : ctxt → string → ctxt ctxt-clear-symbol Γ @ (mk-ctxt (fn , mn , pms , q) (syms , mn-fn) i symb-occs d) x = mk-ctxt (fn , mn , pms , (trie-remove q x)) (trie-map (λ ss → fst ss , remove _=string_ x (snd ss)) syms , mn-fn) (trie-remove i (qualif-var Γ x)) symb-occs d ctxt-clear-symbols : ctxt → 𝕃 string → ctxt ctxt-clear-symbols Γ [] = Γ ctxt-clear-symbols Γ (v :: vs) = ctxt-clear-symbols (ctxt-clear-symbol Γ v) vs ctxt-clear-symbols-of-file : ctxt → (filename : string) → ctxt ctxt-clear-symbols-of-file (mk-ctxt f (syms , mn-fn , mn-ps) i symb-occs d) fn = mk-ctxt f (trie-insert syms fn (fst p , []) , trie-insert mn-fn (fst p) fn , mn-ps) (hremove i (fst p) (snd p)) symb-occs d where p = trie-lookup𝕃2 syms fn hremove : ∀ {A : Set} → trie A → var → 𝕃 string → trie A hremove i mn [] = i hremove i mn (x :: xs) = hremove (trie-remove i (mn # x)) mn xs ctxt-add-current-id : ctxt → ctxt ctxt-add-current-id (mk-ctxt mod (syms , mn-fn , mn-ps , fn-ids , id , id-fns) is os d) = mk-ctxt mod (syms , mn-fn , mn-ps , trie-insert fn-ids (fst mod) (suc id) , suc id , (fst mod) :: id-fns) is os d ctxt-initiate-file : ctxt → (filename modname : string) → ctxt ctxt-initiate-file Γ fn mn = ctxt-add-current-id (ctxt-set-current-file (ctxt-clear-symbols-of-file Γ fn) fn mn) unqual : ctxt → var → string unqual (mk-ctxt (_ , _ , _ , q) _ _ _ _) v = if qualif-nonempty q then unqual-local (unqual-all q v) else v
40.344595
160
0.615893
edbef04bf4eebdfdb219e43449e065eb7a989d44
943
agda
Agda
test/Succeed/Conat-Sized.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Conat-Sized.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Conat-Sized.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2018-10-18, re issue #2757 -- -- Extracted this snippet from the standard library -- as it caused problems during work in #2757 -- (runtime erasue using 0-quantity). -- {-# OPTIONS -v tc.lhs.unify:65 -v tc.irr:50 #-} {-# OPTIONS --sized-types #-} open import Agda.Builtin.Size data ⊥ : Set where mutual data Conat (i : Size) : Set where zero : Conat i suc : ∞Conat i → Conat i record ∞Conat (i : Size) : Set where coinductive field force : ∀{j : Size< i} → Conat j open ∞Conat infinity : ∀ {i} → Conat i infinity = suc λ where .force → infinity data Finite : Conat ∞ → Set where zero : Finite zero suc : ∀ {n} → Finite (n .force) → Finite (suc n) ¬Finite∞ : Finite infinity → ⊥ ¬Finite∞ (suc p) = ¬Finite∞ p -- The problem was that the usableMod check in the -- unifier (LHS.Unify) refuted this pattern match -- because a runtime-erased argument ∞ (via meta-variable) -- the the extended lambda.
24.179487
58
0.653234
2e078dec351bd97200040608159b04cec1faa6c9
1,562
agda
Agda
Groups/Subgroups/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Subgroups/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Subgroups/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Groups.Definition module Groups.Subgroups.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) where open import Setoids.Subset S open Group G record Subgroup {c : _} (pred : A → Set c) : Set (a ⊔ b ⊔ c) where field isSubset : subset pred closedUnderPlus : {g h : A} → (pred g) → (pred h) → pred (g + h) containsIdentity : pred 0G closedUnderInverse : ({g : A} → (pred g) → (pred (inverse g))) subgroupOp : {c : _} {pred : A → Set c} → (s : Subgroup pred) → Sg A pred → Sg A pred → Sg A pred subgroupOp {pred = pred} record { closedUnderPlus = one } (a , prA) (b , prB) = (a + b) , one prA prB subgroupIsGroup : {c : _} {pred : A → Set c} → (s : Subgroup pred) → Group (subsetSetoid (Subgroup.isSubset s)) (subgroupOp s) Group.+WellDefined (subgroupIsGroup s) {m , prM} {n , prN} {x , prX} {y , prY} m=x n=y = +WellDefined m=x n=y Group.0G (subgroupIsGroup record { containsIdentity = two }) = 0G , two Group.inverse (subgroupIsGroup record { closedUnderInverse = three }) (a , prA) = (inverse a) , three prA Group.+Associative (subgroupIsGroup s) {a , prA} {b , prB} {c , prC} = +Associative Group.identRight (subgroupIsGroup s) {a , prA} = identRight Group.identLeft (subgroupIsGroup s) {a , prA} = identLeft Group.invLeft (subgroupIsGroup s) {a , prA} = invLeft Group.invRight (subgroupIsGroup s) {a , prA} = invRight
48.8125
126
0.654289
ccbf7cf90c4ac28651ac1bfdb2b751bc9cb4b39e
7,800
agda
Agda
agda-src/RingSolving.agda
dominiquedevriese/reviews
cf6faf7103acd54c67f3464b1968387a98dd8fa2
[ "BSD-3-Clause" ]
7
2022-02-08T00:57:08.000Z
2022-02-22T15:07:19.000Z
agda-src/RingSolving.agda
dominiquedevriese/reviews
cf6faf7103acd54c67f3464b1968387a98dd8fa2
[ "BSD-3-Clause" ]
1
2022-02-17T09:10:00.000Z
2022-02-17T16:51:24.000Z
agda-src/RingSolving.agda
dominiquedevriese/reviews
cf6faf7103acd54c67f3464b1968387a98dd8fa2
[ "BSD-3-Clause" ]
1
2022-02-17T08:46:57.000Z
2022-02-17T08:46:57.000Z
{-# OPTIONS --rewriting #-} module RingSolving where open import Data.Nat hiding (_≟_) open import Data.Nat.Properties hiding (_≟_) import Relation.Binary.PropositionalEquality open Relation.Binary.PropositionalEquality open import Agda.Builtin.Equality.Rewrite open import Function import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) module _ (A : Set) where infixr 5 _+H_ infixr 6 _*H_ infixr 5 _:+_ infixr 6 _:*_ infixr 5 _+A_ infixr 6 _*A_ postulate #0 : A #1 : A _+A_ : A → A → A _*A_ : A → A → A data Poly : Set where con : A → Poly var : Poly _:+_ : Poly → Poly → Poly _:*_ : Poly → Poly → Poly data Horner : Set where PC : A → Horner PX : A → Horner → Horner scalMapHorner : (A → A) → Horner → Horner scalMapHorner f (PC x) = PC (f x) scalMapHorner f (PX x xs) = PX (f x) (scalMapHorner f xs) postulate extensionality : {S : Set}{T : S -> Set} {f g : (x : S) -> T x} -> ((x : S) -> f x ≡ g x) -> f ≡ g postulate +A-id-l : ∀ m → #0 +A m ≡ m *A-id-l : ∀ m → #1 *A m ≡ m +A-id-r : ∀ m → m +A #0 ≡ m *A-id-r : ∀ m → m *A #1 ≡ m +A-assoc : ∀ m n p → (m +A n) +A p ≡ m +A n +A p *A-assoc : ∀ m n p → (m *A n) *A p ≡ m *A n *A p +A-comm : ∀ m n → m +A n ≡ n +A m *A-comm : ∀ m n → m *A n ≡ n *A m *A-+A-distrib : ∀ m n p → m *A (n +A p) ≡ m *A n +A m *A p *A-annhiliate-r : ∀ m → m *A #0 ≡ #0 *A-annhiliate-l : ∀ m → #0 *A m ≡ #0 *A-+A-distrib′ : ∀ m n p → (m +A n) *A p ≡ m *A p +A n *A p *A-+A-distrib′ m n p = begin (m +A n) *A p ≡⟨ *A-comm (m +A n) p ⟩ p *A (m +A n) ≡⟨ *A-+A-distrib p m n ⟩ p *A m +A p *A n ≡⟨ cong₂ (_+A_) (*A-comm p m) (*A-comm p n) ⟩ m *A p +A n *A p ∎ where open ≡-Reasoning {-# REWRITE +A-id-l *A-id-l +A-id-r *A-id-r *A-annhiliate-r *A-annhiliate-l +A-assoc *A-assoc *A-+A-distrib #-} _+H_ : Horner → Horner → Horner _+H_ (PC x) (PC y) = PC (x +A y) _+H_ (PC x) (PX y ys) = PX (x +A y) ys _+H_ (PX x xs) (PC y) = PX (x +A y) xs _+H_ (PX x xs) (PX y ys) = PX (x +A y) (_+H_ xs ys) is-lt : (m : ℕ) → (n : ℕ) → n ⊔ (m Data.Nat.+ suc n) ≡ m Data.Nat.+ suc n is-lt m n = m≤n⇒m⊔n≡n $ begin n ≤⟨ n≤1+n n ⟩ suc n ≤⟨ m≤n+m (suc n) m ⟩ m Data.Nat.+ suc n ∎ where open ≤-Reasoning _*H_ : Horner → Horner → Horner _*H_ (PC x) y = scalMapHorner (x *A_) y _*H_ (PX x xs) y = (scalMapHorner (x *A_) y) +H (PX #0 (xs *H y)) evaluate : Horner → A → A evaluate (PC x) v = x evaluate (PX x xs) v = x +A (v *A evaluate xs v) varH : Horner varH = PX #0 $ PC #1 conH : A → Horner conH = PC construct : Poly → A → A construct (con x) a = x construct var a = a construct (p :+ p2) a = construct p a +A construct p2 a construct (p :* p2) a = construct p a *A construct p2 a normalize : Poly → Horner normalize (con x) = conH x normalize var = varH normalize (x :+ y) = normalize x +H normalize y normalize (x :* y) = normalize x *H normalize y swap : ∀ m n j k → (m +A n) +A (j +A k) ≡ (m +A j) +A (n +A k) swap m n j k = begin (m +A n) +A (j +A k) ≡⟨ +A-assoc m n (j +A k) ⟩ m +A (n +A (j +A k)) ≡⟨ cong (m +A_) $ sym $ +A-assoc n j k ⟩ m +A ((n +A j) +A k) ≡⟨ cong (\ φ → m +A (φ +A k)) $ +A-comm n j ⟩ m +A ((j +A n) +A k) ≡⟨ cong (m +A_) $ +A-assoc j n k ⟩ m +A (j +A (n +A k)) ≡⟨ sym $ +A-assoc m j (n +A k) ⟩ (m +A j) +A (n +A k) ∎ where open Eq.≡-Reasoning swap2-+A : ∀ m n p → m +A (n +A p) ≡ n +A (m +A p) swap2-+A m n p = begin m +A (n +A p) ≡⟨ +A-assoc m n p ⟩ (m +A n) +A p ≡⟨ cong ( _+A p) $ +A-comm m n ⟩ (n +A m) +A p ≡⟨ sym $ +A-assoc n m p ⟩ n +A (m +A p) ∎ where open Eq.≡-Reasoning swap2-*A : ∀ m n p → m *A (n *A p) ≡ n *A (m *A p) swap2-*A m n p = begin m *A (n *A p) ≡⟨ *A-assoc m n p ⟩ (m *A n) *A p ≡⟨ cong ( _*A p) $ *A-comm m n ⟩ (n *A m) *A p ≡⟨ sym $ *A-assoc n m p ⟩ n *A (m *A p) ∎ where open Eq.≡-Reasoning +A-+H-homo : ∀ j k a → evaluate j a +A evaluate k a ≡ evaluate (j +H k) a +A-+H-homo (PC x) (PC x₁) a = refl +A-+H-homo (PC x) (PX x₁ k) a = refl +A-+H-homo (PX x x₁) (PC x₂) a = begin x +A ((a *A evaluate x₁ a) +A x₂) ≡⟨ cong (x +A_) $ +A-comm (a *A evaluate x₁ a) x₂ ⟩ x +A (x₂ +A (a *A evaluate x₁ a)) ∎ where open Eq.≡-Reasoning +A-+H-homo (PX x x₁) (PX x₂ y) a rewrite +A-+H-homo x₁ y a = begin (x +A (a *A evaluate x₁ a)) +A (x₂ +A (a *A evaluate y a)) ≡⟨ swap x (a *A evaluate x₁ a) x₂ (a *A evaluate y a) ⟩ (x +A x₂) +A ((a *A evaluate x₁ a) +A (a *A evaluate y a)) ≡⟨ cong (\φ → (x +A x₂) +A φ) (sym $ *A-+A-distrib a (evaluate x₁ a) (evaluate y a)) ⟩ (x +A x₂) +A (a *A (evaluate x₁ a +A evaluate y a)) ≡⟨ cong (\φ → (x +A x₂) +A (a *A φ)) (+A-+H-homo x₁ y a) ⟩ (x +A x₂) +A (a *A evaluate (x₁ +H y) a) ∎ where open Eq.≡-Reasoning scale-evaluate : ∀ x k a → x *A evaluate k a ≡ evaluate (scalMapHorner (x *A_) k) a scale-evaluate x (PC x₁) a = refl scale-evaluate x (PX x₁ k) a = begin x *A evaluate (PX x₁ k) a ≡⟨⟩ x *A (x₁ +A (a *A evaluate k a)) ≡⟨ *A-+A-distrib x x₁ (a *A evaluate k a) ⟩ (x *A x₁) +A (x *A (a *A evaluate k a)) ≡⟨ cong ((x *A x₁) +A_) $ swap2-*A x a $ evaluate k a ⟩ (x *A x₁) +A (a *A (x *A evaluate k a)) ≡⟨ cong (\ φ → (x *A x₁) +A (a *A φ)) $ scale-evaluate x k a ⟩ (x *A x₁) +A (a *A evaluate (scalMapHorner (x *A_) k) a) ≡⟨⟩ evaluate (PX (x *A x₁) (scalMapHorner (x *A_) k)) a ≡⟨⟩ evaluate (scalMapHorner (x *A_) (PX x₁ k)) a ∎ where open Eq.≡-Reasoning *A-*H-homo : ∀ j k a → evaluate j a *A evaluate k a ≡ evaluate (j *H k) a *A-*H-homo (PC x) k a = scale-evaluate x k a *A-*H-homo (PX x j) k a = begin evaluate (PX x j) a *A evaluate k a ≡⟨⟩ (x +A a *A evaluate j a) *A evaluate k a ≡⟨ *A-+A-distrib′ x (a *A evaluate j a) (evaluate k a) ⟩ x *A (evaluate k a) +A (a *A evaluate j a) *A evaluate k a ≡⟨ cong₂ _+A_ (scale-evaluate x k a) (cong (a *A_) (*A-*H-homo j k a)) ⟩ evaluate (scalMapHorner (_*A_ x) k) a +A evaluate (PX #0 (j *H k)) a ≡⟨ +A-+H-homo (scalMapHorner (_*A_ x) k) (PX #0 (j *H k)) a ⟩ evaluate (scalMapHorner (_*A_ x) k +H PX #0 (j *H k)) a ≡⟨⟩ evaluate (PX x j *H k) a ∎ where open Eq.≡-Reasoning isoToConstruction : (x : Poly) → (a : A) → construct x a ≡ evaluate (normalize x) a isoToConstruction (con x) a = refl isoToConstruction var a = refl isoToConstruction (x :+ y) a rewrite isoToConstruction x a | isoToConstruction y a | +A-+H-homo (normalize x) (normalize y) a = refl isoToConstruction (x :* y) a rewrite isoToConstruction x a | isoToConstruction y a | *A-*H-homo (normalize x) (normalize y) a = refl solve : (x y : Poly) → normalize x ≡ normalize y → (a : A) → construct x a ≡ construct y a solve x y eq a = begin construct x a ≡⟨ isoToConstruction x a ⟩ evaluate (normalize x) a ≡⟨ cong (\φ → evaluate φ a) eq ⟩ evaluate (normalize y) a ≡⟨ sym $ isoToConstruction y a ⟩ construct y a ∎ where open Eq.≡-Reasoning test-a : Poly test-a = (var :+ con #1) :* (var :+ con #1) test-b : Poly test-b = var :* var :+ two :* var :+ con #1 where two = con #1 :+ con #1 blah : (x : A) → (x +A #1) *A (x +A #1) ≡ (x *A x) +A (#1 +A #1) *A x +A #1 blah x = solve test-a test-b refl x
33.913043
152
0.489103
375cf455f4fb74a16820897023d34322bcbe9078
3,319
agda
Agda
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Poly0-A.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Poly0-A.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/Polynomials/Multivariate/EquivCarac/Poly0-A.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A 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.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 Equiv-Poly0-A (A' : CommRing ℓ) where A = fst A' cra = snd A' open CommRingStr cra renaming (is-set to isSetA) open Nth-Poly-structure A' 0 ----------------------------------------------------------------------------- -- Equivalence Poly0→A : Poly A' 0 → A Poly0→A = Poly-Rec-Set.f A' 0 A isSetA 0r (λ v a → a) _+_ +Assoc +Rid +Comm (λ _ → refl) λ _ a b → refl A→Poly0 : A → Poly A' 0 A→Poly0 a = base [] a e-sect : (a : A) → Poly0→A (A→Poly0 a) ≡ a e-sect a = refl e-retr : (P : Poly A' 0) → A→Poly0 (Poly0→A P) ≡ P e-retr = Poly-Ind-Prop.f A' 0 (λ P → A→Poly0 (Poly0→A P) ≡ P) (λ _ → trunc _ _) (base-0P []) (λ { [] a → refl }) λ {U V} ind-U ind-V → (sym (base-poly+ [] (Poly0→A U) (Poly0→A V))) ∙ (cong₂ _poly+_ ind-U ind-V) ----------------------------------------------------------------------------- -- Ring homomorphism map-0P : Poly0→A 0P ≡ 0r map-0P = refl Poly0→A-gmorph : (P Q : Poly A' 0) → Poly0→A ( P poly+ Q) ≡ Poly0→A P + Poly0→A Q Poly0→A-gmorph P Q = refl map-1P : Poly0→A 1P ≡ 1r map-1P = refl Poly0→A-rmorph : (P Q : Poly A' 0) → Poly0→A ( P poly* Q) ≡ Poly0→A P · Poly0→A Q Poly0→A-rmorph = Poly-Ind-Prop.f A' 0 (λ P → (Q : Poly A' 0) → Poly0→A (P poly* Q) ≡ Poly0→A P · Poly0→A Q) (λ P p q i Q j → isSetA (Poly0→A (P poly* Q)) (Poly0→A P · Poly0→A Q) (p Q) (q Q) i j) (λ Q → sym (RingTheory.0LeftAnnihilates (CommRing→Ring A') (Poly0→A Q))) (λ v a → Poly-Ind-Prop.f A' 0 (λ P → Poly0→A (base v a poly* P) ≡ Poly0→A (base v a) · Poly0→A P) (λ _ → isSetA _ _) (sym (RingTheory.0RightAnnihilates (CommRing→Ring A') (Poly0→A (base v a)))) (λ v' a' → refl) λ {U V} ind-U ind-V → (cong₂ _+_ ind-U ind-V) ∙ (sym (·Rdist+ _ _ _))) λ {U V} ind-U ind-V Q → (cong₂ _+_ (ind-U Q) (ind-V Q)) ∙ (sym (·Ldist+ _ _ _)) ----------------------------------------------------------------------------- -- Ring Equivalence module _ (A' : CommRing ℓ) where open Equiv-Poly0-A A' CRE-Poly0-A : CommRingEquiv (PolyCommRing A' 0) A' fst CRE-Poly0-A = isoToEquiv is where is : Iso (Poly A' 0) (A' .fst) Iso.fun is = Poly0→A Iso.inv is = A→Poly0 Iso.rightInv is = e-sect Iso.leftInv is = e-retr snd CRE-Poly0-A = makeIsRingHom map-1P Poly0→A-gmorph Poly0→A-rmorph
32.861386
108
0.515215
11b8178e3cce95467171e0fa9cac42655f18c857
377
agda
Agda
test/Fail/Issue291b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/Issue291b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/Issue291b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- Andreas, 2011-04-14 -- {-# OPTIONS -v tc.cover:20 -v tc.lhs.unify:20 #-} module Issue291b where open import Common.Coinduction open import Common.Equality data RUnit : Set where runit : ∞ RUnit -> RUnit j : (u : RUnit) -> u ≡ runit (♯ u) -> Set j u () -- needs to fail because of a non strongly rigid occurrence -- ♯ does not count as a constructor, and that is good!
23.5625
59
0.671088
fdb79dba3dc67d77eae399248e52919949811cc0
21,158
agda
Agda
complexity-drafts/New-Source.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
2
2016-04-26T20:22:22.000Z
2019-08-08T12:27:18.000Z
complexity-drafts/New-Source.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
1
2020-03-23T08:39:04.000Z
2020-05-12T00:32:45.000Z
complexity-drafts/New-Source.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
null
null
null
{- Name: Bowornmet (Ben) Hudson -- new source language module. trying stuff out -} open import Preliminaries open import Preorder-withmax module New-Source where data Tp : Set where unit : Tp nat : Tp susp : Tp → Tp _->s_ : Tp → Tp → Tp _×s_ : Tp → Tp → Tp list : Tp → Tp bool : Tp Ctx = List Tp -- de Bruijn indices data _∈_ : Tp → Ctx → Set where i0 : ∀ {Γ τ} → τ ∈ τ :: Γ iS : ∀ {Γ τ τ1} → τ ∈ Γ → τ ∈ τ1 :: Γ data _|-_ : Ctx → Tp → Set where unit : ∀ {Γ} → Γ |- unit var : ∀ {Γ τ} → τ ∈ Γ → Γ |- τ z : ∀ {Γ} → Γ |- nat suc : ∀ {Γ} → (e : Γ |- nat) → Γ |- nat rec : ∀ {Γ τ} → Γ |- nat → Γ |- τ → (nat :: (susp τ :: Γ)) |- τ → Γ |- τ lam : ∀ {Γ τ ρ} → (ρ :: Γ) |- τ → Γ |- (ρ ->s τ) app : ∀ {Γ τ1 τ2} → Γ |- (τ2 ->s τ1) → Γ |- τ2 → Γ |- τ1 prod : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → Γ |- (τ1 ×s τ2) delay : ∀ {Γ τ} → Γ |- τ → Γ |- susp τ force : ∀ {Γ τ} → Γ |- susp τ → Γ |- τ split : ∀ {Γ τ τ1 τ2} → Γ |- (τ1 ×s τ2) → (τ1 :: (τ2 :: Γ)) |- τ → Γ |- τ nil : ∀ {Γ τ} → Γ |- list τ _::s_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (susp τ' :: Γ))) |- τ' → Γ |- τ' true : ∀ {Γ} → Γ |- bool false : ∀ {Γ} → Γ |- bool module RenSubst where -- renaming = variable for variable substitution --functional view: --avoids induction, --some associativity/unit properties for free module Ren where -- read: you can rename Γ' as Γ rctx : Ctx → Ctx → Set rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ rename-var ρ a = ρ a idr : ∀ {Γ} → rctx Γ Γ idr x = x -- weakening with renaming p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ' p∙ ρ = λ x → iS (ρ x) p : ∀ {Γ τ} → rctx (τ :: Γ) Γ p = p∙ idr _∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C ρ1 ∙rr ρ2 = ρ1 o ρ2 -- free stuff rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x rename-var-ident _ = Refl rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C) → rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x rename-var-∙ _ _ _ = Refl ∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3) ∙rr-assoc r1 r2 r3 = Refl r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ') r-extend ρ i0 = i0 r-extend ρ (iS x) = iS (ρ x) ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ ren unit ρ = unit ren (var x) ρ = var (ρ x) ren z ρ = z ren (suc e) ρ = suc (ren e ρ) ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ))) ren (lam e) ρ = lam (ren e (r-extend ρ)) ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ) ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ) ren (delay e) ρ = delay (ren e ρ) ren (force e) ρ = force (ren e ρ) ren (split e e₁) ρ = split (ren e ρ) (ren e₁ (r-extend (r-extend ρ))) ren nil ρ = nil ren (x ::s xs) ρ = ren x ρ ::s ren xs ρ ren true ρ = true ren false ρ = false ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ)))) -- weakening a context wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2 wkn e = ren e iS open Ren sctx : Ctx → Ctx → Set sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ --lem2 (addvar) s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ') s-extend Θ i0 = var i0 s-extend Θ (iS x) = wkn (Θ x) ids : ∀ {Γ} → sctx Γ Γ ids x = var x -- weakening with substitution q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ' q∙ Θ = λ x → wkn (Θ x) --lem3 q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ) q e i0 = e q e (iS i) = var i lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ)) lem4 e1 e2 i0 = e1 lem4 e1 e2 (iS i0) = e2 lem4 e1 e2 (iS (iS i)) = var i -- subst-var svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ svar Θ i = q (Θ i) i0 lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ') lem3' Θ e i0 = e lem3' Θ e (iS i) = Θ i lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ')) lem4' Θ a b i0 = a lem4' Θ a b (iS i0) = b lem4' Θ a b (iS (iS i)) = Θ i subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ subst unit Θ = unit subst (var x) Θ = Θ x subst z Θ = z subst (suc e) Θ = suc (subst e Θ) subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ))) subst (lam e) Θ = lam (subst e (s-extend Θ)) subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ) subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ) subst (delay e) Θ = delay (subst e Θ) subst (force e) Θ = force (subst e Θ) subst (split e e₁) Θ = split (subst e Θ) (subst e₁ (s-extend (s-extend Θ))) subst nil Θ = nil subst (x ::s xs) Θ = subst x Θ ::s subst xs Θ subst true Θ = true subst false Θ = false subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ)))) subst1 : ∀ {τ τ1} → [] |- τ1 → (τ1 :: []) |- τ → [] |- τ subst1 e e' = subst e' (q e) _rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C _rs_ ρ Θ x = ren (subst (var x) Θ) ρ _ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C _ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1 _sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C _sr_ Θ ρ x = subst (ren (var x) ρ) Θ --free stuff svar-rs : ∀ {A B C τ} (ρ : rctx A B) (Θ : sctx B C) (x : τ ∈ C) → svar (ρ rs Θ) x == ren (svar Θ x) ρ svar-rs = λ ρ Θ x → Refl svar-ss : ∀ {A B C τ} (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ C) → svar (Θ1 ss Θ2) x == subst (svar Θ2 x) Θ1 svar-ss = λ Θ1 Θ2 x → Refl svar-sr : ∀ {A B C τ} (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ C) → svar Θ (rename-var ρ x) == svar (Θ sr ρ) x svar-sr = λ Θ ρ x → Refl svar-id : ∀ {Γ τ} → (x : τ ∈ Γ) → var x == svar ids x svar-id = λ x → Refl rsr-assoc : ∀ {A B C D} → (ρ1 : rctx A B) (Θ : sctx B C) (ρ2 : rctx C D) → Id {_} {sctx A D} ((ρ1 rs Θ) sr ρ2) (ρ1 rs (Θ sr ρ2)) rsr-assoc = λ ρ1 Θ ρ2 → Refl extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ} (ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x) extend-id-once-lemma i0 = Refl extend-id-once-lemma (iS x) = Refl extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids) extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x)) extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids)) extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once subst-id : ∀ {Γ τ} (e : Γ |- τ) → e == subst e ids subst-id unit = Refl subst-id (var x) = svar-id x subst-id z = Refl subst-id (suc e) = ap suc (subst-id e) subst-id (rec e e₁ e₂) = ap3 rec (subst-id e) (subst-id e₁) (ap (subst e₂) extend-id-twice ∘ subst-id e₂) subst-id (lam e) = ap lam (ap (subst e) extend-id-once ∘ subst-id e) subst-id (app e e₁) = ap2 app (subst-id e) (subst-id e₁) subst-id (prod e e₁) = ap2 prod (subst-id e) (subst-id e₁) subst-id (delay e) = ap delay (subst-id e) subst-id (force e) = ap force (subst-id e) subst-id (split e e₁) = ap2 split (subst-id e) (ap (subst e₁) extend-id-twice ∘ subst-id e₁) subst-id nil = Refl subst-id (e ::s e₁) = ap2 _::s_ (subst-id e) (subst-id e₁) subst-id true = Refl subst-id false = Refl subst-id (listrec e e₁ e₂) = ap3 listrec (subst-id e) (subst-id e₁) (ap (subst e₂) (ap s-extend (ap s-extend extend-id-once) ∘ extend-id-twice) ∘ subst-id e₂) extend-rs-once-lemma : ∀ {A B C τ τ'} → (x : τ ∈ τ' :: B) (ρ : rctx C A) (Θ : sctx A B) → _==_ {_} {τ' :: C |- τ} (_rs_ {τ' :: C} {τ' :: A} {τ' :: B} (r-extend {C} {A} {τ'} ρ) (s-extend {A} {B} {τ'} Θ) {τ} x) (s-extend {C} {B} {τ'} (_rs_ {C} {A} {B} ρ Θ) {τ} x) extend-rs-once-lemma i0 ρ Θ = Refl extend-rs-once-lemma (iS x) ρ Θ = {!!} extend-rs-once : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) → Id {_} {sctx (τ :: C) (τ :: B)} (r-extend ρ rs s-extend Θ) (s-extend (ρ rs Θ)) extend-rs-once ρ Θ = λ=i (λ τ → λ= (λ x → extend-rs-once-lemma x ρ Θ)) extend-rs-twice : ∀ {A B C τ τ'} → (ρ : rctx C A) (Θ : sctx A B) → Id {_} {sctx (τ :: τ' :: C) (τ :: τ' :: B)} ((r-extend (r-extend ρ)) rs (s-extend (s-extend Θ))) ((s-extend (s-extend (ρ rs Θ)))) extend-rs-twice ρ Θ = ap s-extend (extend-rs-once ρ Θ) ∘ extend-rs-once (r-extend ρ) (s-extend Θ) subst-rs : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ) → ren (subst e Θ) ρ == subst e (ρ rs Θ) subst-rs ρ Θ unit = Refl subst-rs ρ Θ (var x) = svar-rs ρ Θ x subst-rs ρ Θ z = Refl subst-rs ρ Θ (suc e) = ap suc (subst-rs ρ Θ e) subst-rs ρ Θ (rec e e₁ e₂) = ap3 rec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁) (ap (subst e₂) (extend-rs-twice ρ Θ) ∘ subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂) subst-rs ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ subst-rs (r-extend ρ) (s-extend Θ) e) subst-rs ρ Θ (app e e₁) = ap2 app (subst-rs ρ Θ e) (subst-rs ρ Θ e₁) subst-rs ρ Θ (prod e e₁) = ap2 prod (subst-rs ρ Θ e) (subst-rs ρ Θ e₁) subst-rs ρ Θ (delay e) = ap delay (subst-rs ρ Θ e) subst-rs ρ Θ (force e) = ap force (subst-rs ρ Θ e) subst-rs ρ Θ (split e e₁) = ap2 split (subst-rs ρ Θ e) (ap (subst e₁) (extend-rs-twice ρ Θ) ∘ subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₁) subst-rs ρ Θ nil = Refl subst-rs ρ Θ (e ::s e₁) = ap2 _::s_ (subst-rs ρ Θ e) (subst-rs ρ Θ e₁) subst-rs ρ Θ true = Refl subst-rs ρ Θ false = Refl subst-rs ρ Θ (listrec e e₁ e₂) = ap3 listrec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁) (ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘ extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘ subst-rs (r-extend (r-extend (r-extend ρ))) (s-extend (s-extend (s-extend Θ))) e₂) extend-ss-once-lemma : ∀ {A B C τ τ'} → (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ τ' :: C) → _==_ {_} {τ' :: A |- τ} (s-extend (_ss_ Θ1 Θ2) x) (_ss_ (s-extend Θ1) (s-extend Θ2) x) extend-ss-once-lemma Θ1 Θ2 i0 = Refl extend-ss-once-lemma Θ1 Θ2 (iS x) = {!!} extend-ss-once : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) → _==_ {_} {sctx (τ :: A) (τ :: C)} (s-extend (Θ1 ss Θ2)) ((s-extend Θ1) ss (s-extend Θ2)) extend-ss-once Θ1 Θ2 = λ=i (λ τ → λ= (λ x → extend-ss-once-lemma Θ1 Θ2 x)) subst-ss : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ) → subst e (Θ1 ss Θ2) == subst (subst e Θ2) Θ1 subst-ss Θ1 Θ2 unit = Refl subst-ss Θ1 Θ2 (var x) = svar-ss Θ1 Θ2 x subst-ss Θ1 Θ2 z = Refl subst-ss Θ1 Θ2 (suc e) = ap suc (subst-ss Θ1 Θ2 e) subst-ss Θ1 Θ2 (rec e e₁ e₂) = ap3 rec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁) (subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₂ ∘ ap (subst e₂) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘ ap s-extend (extend-ss-once Θ1 Θ2))) subst-ss Θ1 Θ2 (lam e) = ap lam (subst-ss (s-extend Θ1) (s-extend Θ2) e ∘ ap (subst e) (extend-ss-once Θ1 Θ2)) subst-ss Θ1 Θ2 (app e e₁) = ap2 app (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁) subst-ss Θ1 Θ2 (prod e e₁) = ap2 prod (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁) subst-ss Θ1 Θ2 (delay e) = ap delay (subst-ss Θ1 Θ2 e) subst-ss Θ1 Θ2 (force e) = ap force (subst-ss Θ1 Θ2 e) subst-ss Θ1 Θ2 (split e e₁) = ap2 split (subst-ss Θ1 Θ2 e) (subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₁ ∘ ap (subst e₁) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘ ap s-extend (extend-ss-once Θ1 Θ2))) subst-ss Θ1 Θ2 nil = Refl subst-ss Θ1 Θ2 (e ::s e₁) = ap2 _::s_ (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁) subst-ss Θ1 Θ2 true = Refl subst-ss Θ1 Θ2 false = Refl subst-ss Θ1 Θ2 (listrec e e₁ e₂) = ap3 listrec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁) (subst-ss (s-extend (s-extend (s-extend Θ1))) (s-extend (s-extend (s-extend Θ2))) e₂ ∘ ap (subst e₂) (extend-ss-once (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) ∘ ap s-extend (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘ ap s-extend (extend-ss-once Θ1 Θ2)))) subst-compose-lemma-lemma : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ τ' :: Γ') → _==_ {_} {Γ |- τ} (_ss_ (q v) (s-extend Θ) x) (lem3' Θ v x) subst-compose-lemma-lemma v Θ i0 = Refl subst-compose-lemma-lemma v Θ (iS x) = {!!} subst-compose-lemma : ∀ {Γ Γ' τ} (v : Γ |- τ) (Θ : sctx Γ Γ') → _==_ {_} {sctx Γ (τ :: Γ')} ((q v) ss (s-extend Θ)) (lem3' Θ v) subst-compose-lemma v Θ = λ=i (λ τ → λ= (λ x → subst-compose-lemma-lemma v Θ x)) subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) ) → subst (subst e (s-extend Θ)) (q v) == subst e (lem3' Θ v) subst-compose Θ v e = ap (subst e) (subst-compose-lemma v Θ) ∘ (! (subst-ss (q v) (s-extend Θ) e)) {-these lemmas can be compressed into one general lemma for subst-compose with 2 s-extends...-} subst-compose2 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (n : Γ |- nat) (e1 : Γ' |- τ) (e2 : (nat :: (susp τ :: Γ')) |- τ) → subst (subst e2 (s-extend (s-extend Θ))) (lem4 n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ)))))) == subst e2 (lem4' Θ n (delay (rec n (subst e1 Θ) (subst e2 (s-extend (s-extend Θ)))))) subst-compose2 Θ n e1 e2 = {!!} subst-compose3 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) → subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) == subst e1 (lem4' Θ v1 v2) subst-compose3 Θ e1 v1 v2 = {!!} subst-compose4 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- susp τ) (e2 : (nat :: (susp τ :: Γ')) |- τ) → subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) == subst e2 (lem4' Θ v' r) subst-compose4 Θ v' r e2 = ap (subst e2) {!!} ∘ ! (subst-ss (lem4 v' r) (s-extend (s-extend Θ)) e2) --i want to use ap with something like --subst-compose-lemma v' Θ --here but i think i'm missing something. open RenSubst --closed values of the source language data val : ∀ {τ} → [] |- τ → Set where z-isval : val z suc-isval : (e : [] |- nat) → (val e) → val (suc e) pair-isval : ∀ {τ1 τ2} (e1 : [] |- τ1) → (e2 : [] |- τ2) → val e1 → val e2 → val (prod e1 e2) lam-isval : ∀ {ρ τ} (e : (ρ :: []) |- τ) → val (lam e) unit-isval : val unit delay-isval : ∀ {τ} (e : [] |- τ) → val (delay e) nil-isval : ∀ {τ} → val (nil {_} {τ}) cons-isval : ∀ {τ} (x : [] |- τ) → (xs : [] |- list τ) → val x → val xs → val (x ::s xs) true-isval : val true false-isval : val false module Costs where data Cost : Set where 0c : Cost 1c : Cost _+c_ : Cost → Cost → Cost data Equals0c : Cost → Set where Eq0-0c : Equals0c 0c Eq0-+c : ∀ {c c'} → Equals0c c → Equals0c c' → Equals0c (c +c c') open Costs mutual -- define evals (e : source exp) (v : value) (c : nat) -- analogous to "e evaluates to v in c steps" -- figure 2 from ICFP paper data evals : {τ : Tp} → [] |- τ → [] |- τ → Cost → Set where pair-evals : ∀ {n1 n2} → {τ1 τ2 : Tp} {e1 v1 : [] |- τ1} {e2 v2 : [] |- τ2} → evals e1 v1 n1 → evals e2 v2 n2 → evals (prod e1 e2) (prod v1 v2) (n1 +c n2) lam-evals : ∀ {ρ τ} {e : (ρ :: []) |- τ} → evals (lam e) (lam e) 0c app-evals : ∀ {n0 n1 n} → {τ1 τ2 : Tp} {e0 : [] |- (τ1 ->s τ2)} {e0' : (τ1 :: []) |- τ2} {e1 v1 : [] |- τ1} {v : [] |- τ2} → evals e0 (lam e0') n0 → evals e1 v1 n1 → evals (subst e0' (q v1)) v n → evals (app e0 e1) v ((n0 +c n1) +c n) z-evals : evals z z 0c s-evals : ∀ {n} → {e v : [] |- nat} → evals e v n → evals (suc e) (suc v) n unit-evals : evals unit unit 0c rec-evals : ∀ {n1 n2} → {τ : Tp} {e v : [] |- nat} {e0 v' : [] |- τ} {e1 : (nat :: (susp τ :: [])) |- τ} → evals e v n1 → evals-rec-branch e0 e1 v v' n2 → evals (rec e e0 e1) v' (n1 +c (1c +c n2)) delay-evals : {τ : Tp} {e : [] |- τ} → evals (delay e) (delay e) 0c force-evals : ∀ {n1 n2} → {τ : Tp} {e' v : [] |- τ} {e : [] |- susp τ} → evals e (delay e') n1 → evals e' v n2 → evals (force e) v (n1 +c n2) split-evals : ∀ {n1 n2} → {τ τ1 τ2 : Tp} {e0 : [] |- (τ1 ×s τ2)} {v1 : [] |- τ1} {v2 : [] |- τ2} {e1 : (τ1 :: (τ2 :: [])) |- τ} {v : [] |- τ} → evals e0 (prod v1 v2) n1 → evals (subst e1 (lem4 v1 v2)) v n2 → evals (split e0 e1) v (n1 +c n2) nil-evals : ∀ {τ : Tp} → evals (nil {_} {τ}) (nil {_} {τ}) 0c cons-evals : ∀ {n1 n2} → {τ : Tp} {x v : [] |- τ} {xs vs : [] |- list τ} → evals x v n1 → evals xs vs n2 → evals (x ::s xs) (v ::s vs) (n1 +c n2) true-evals : evals true true 0c false-evals : evals false false 0c -- means evals (rec v e0 e1) v' n -- but helpful to have a separate type for this data evals-rec-branch {τ : Tp} (e0 : [] |- τ) (e1 : (nat :: (susp τ :: [])) |- τ) : (e : [] |- nat) (v : [] |- τ) → Cost → Set where evals-rec-z : ∀ {v n} → evals e0 v n → evals-rec-branch e0 e1 z v n evals-rec-s : ∀ {v v' n} → evals (subst e1 (lem4 v (delay (rec v e0 e1)))) v' n → evals-rec-branch e0 e1 (suc v) v' n evals-val : {τ : Tp} {e : [] |- τ} {v : [] |- τ} {n : Cost} → evals e v n → val v evals-val (pair-evals D D₁) = pair-isval _ _ (evals-val D) (evals-val D₁) evals-val lam-evals = lam-isval _ evals-val (app-evals D D₁ D₂) = evals-val D₂ evals-val z-evals = z-isval evals-val (s-evals D) = suc-isval _ (evals-val D) evals-val unit-evals = unit-isval evals-val (rec-evals x (evals-rec-z D)) = evals-val D evals-val (rec-evals x (evals-rec-s D)) = evals-val D evals-val delay-evals = delay-isval _ evals-val (force-evals D D₁) = evals-val D₁ evals-val (split-evals D D₁) = evals-val D₁ evals-val nil-evals = nil-isval evals-val (cons-evals D D₁) = cons-isval _ _ (evals-val D) (evals-val D₁) evals-val true-evals = true-isval evals-val false-evals = false-isval -- lemma 2 from ICFP paper val-evals-inversion : {τ : Tp} {v v' : [] |- τ} {n : Cost} → val v → evals v v' n → (v == v') × Equals0c n val-evals-inversion z-isval z-evals = Refl , Eq0-0c val-evals-inversion (suc-isval e ve) (s-evals D) = (ap suc (fst IH)) , snd IH where IH = val-evals-inversion ve D val-evals-inversion (pair-isval e1 e2 ve1 ve2) (pair-evals D D₁) = ap2 prod (fst IH1) (fst IH2) , Eq0-+c (snd IH1) (snd IH2) where IH1 = val-evals-inversion ve1 D IH2 = val-evals-inversion ve2 D₁ val-evals-inversion (lam-isval e) lam-evals = Refl , Eq0-0c val-evals-inversion unit-isval unit-evals = Refl , Eq0-0c val-evals-inversion (delay-isval e) delay-evals = Refl , Eq0-0c val-evals-inversion nil-isval nil-evals = Refl , Eq0-0c val-evals-inversion (cons-isval x xs vx vxs) (cons-evals D D₁) = ap2 _::s_ (fst IH1) (fst IH2) , Eq0-+c (snd IH1) (snd IH2) where IH1 = val-evals-inversion vx D IH2 = val-evals-inversion vxs D₁ val-evals-inversion true-isval true-evals = Refl , Eq0-0c val-evals-inversion false-isval false-evals = Refl , Eq0-0c
43.987526
162
0.471264
cc19019014678b6e82f6984324b5589b2087e15c
248
agda
Agda
test/Fail/Issue3655b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue3655b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue3655b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --allow-unsolved-metas #-} open import Agda.Builtin.Bool postulate A : Set F : Bool → Set F true = A F false = A data D {b : Bool} (x : F b) : Set where variable b : Bool x : F b postulate f : D x → (P : F b → Set) → P x
12.4
39
0.568548
36bee0ff6b64c555de8f84092649a383c604bd2d
163
agda
Agda
Cubical/Algebra/AbGroup.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/AbGroup.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/AbGroup.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.AbGroup where open import Cubical.Algebra.AbGroup.Base public open import Cubical.Algebra.AbGroup.Properties public
27.166667
53
0.803681
73ccd292d9cbd30513454b46958ddb76fc0ca312
548
agda
Agda
test/Succeed/fol-theorems/ProofTerm3.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
10
2015-09-03T20:54:16.000Z
2019-12-03T13:44:25.000Z
test/Succeed/fol-theorems/ProofTerm3.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
121
2015-01-25T13:22:12.000Z
2018-04-22T06:01:44.000Z
test/Succeed/fol-theorems/ProofTerm3.agda
asr/apia
a66c5ddca2ab470539fd68c42c4fbd45f720d682
[ "MIT" ]
4
2016-05-10T23:06:19.000Z
2016-08-03T03:54:55.000Z
------------------------------------------------------------------------------ -- Testing the erasing of proof terms ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module ProofTerm3 where postulate D : Set N : D → Set _≡_ : D → D → Set postulate foo : ∀ {m n} → (Nm : N m) → (Nn : N n) → ∀ {i} → N i → i ≡ i {-# ATP prove foo #-}
28.842105
78
0.35219
06f274ec2d12407a86246b55d530928a3f04b894
629
agda
Agda
notes/k-axiom/WithoutK.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/k-axiom/WithoutK.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/k-axiom/WithoutK.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Testing the --without-K flag ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} -- {-# OPTIONS --without-K #-} module WithoutK where -- The following code fails with the --without-K flag. data _≡_ {A : Set} : A → A → Set where refl : ∀ x → x ≡ x K : {A : Set} (P : {x : A} → x ≡ x → Set) → (∀ x → P (refl x)) → ∀ {x} (x≡x : x ≡ x) → P x≡x K P p (refl x) = p x
29.952381
78
0.3593
cc3736ad0eceda12e041d475d57a0597ff7cf2a7
1,698
agda
Agda
src/Categories/Diagram/End.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
src/Categories/Diagram/End.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
null
null
null
src/Categories/Diagram/End.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Functor.Bifunctor module Categories.Diagram.End {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F : Bifunctor (Category.op C) C D) where private module C = Category C module D = Category D open D open HomReasoning open Equiv variable A B : Obj f g : A ⇒ B open import Level open import Data.Product using (Σ; _,_) open import Categories.Functor open import Categories.Functor.Construction.Constant open import Categories.NaturalTransformation.Dinatural open import Categories.Morphism.Reasoning D open Functor F record Wedge : Set (levelOfTerm F) where field E : Obj dinatural : DinaturalTransformation (const E) F module dinatural = DinaturalTransformation dinatural Wedge-∘ : (W : Wedge) → A ⇒ Wedge.E W → Wedge Wedge-∘ {A = A} W f = record { E = A ; dinatural = extranaturalʳ (λ X → dinatural.α X ∘ f) (sym-assoc ○ ∘-resp-≈ˡ (extranatural-commʳ dinatural) ○ assoc) } where open Wedge W record End : Set (levelOfTerm F) where field wedge : Wedge module wedge = Wedge wedge open wedge public open Wedge field factor : (W : Wedge) → E W ⇒ wedge.E universal : ∀ {W : Wedge} {A} → wedge.dinatural.α A ∘ factor W ≈ dinatural.α W A unique : ∀ {W : Wedge} {g : E W ⇒ wedge.E} → (∀ {A} → wedge.dinatural.α A ∘ g ≈ dinatural.α W A) → factor W ≈ g η-id : factor wedge ≈ D.id η-id = unique identityʳ unique′ :(∀ {A} → wedge.dinatural.α A ∘ f ≈ wedge.dinatural.α A ∘ g) → f ≈ g unique′ {f = f} {g = g} eq = ⟺ (unique {W = Wedge-∘ wedge f} refl) ○ unique (⟺ eq)
27.387097
118
0.634276
59205e29633e7e812a73cfbe1fe4544e55b50e43
706
agda
Agda
Cubical/Categories/Instances/AbGroups.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:28:39.000Z
2022-03-05T00:28:39.000Z
Cubical/Categories/Instances/AbGroups.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Categories/Instances/AbGroups.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
-- The category Ab of abelian groups {-# OPTIONS --safe #-} module Cubical.Categories.Instances.AbGroups where open import Cubical.Algebra.AbGroup.Base open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Categories.Category.Base open import Cubical.Foundations.Prelude module _ {ℓ : Level} where open Category AbGroupCategory : Category (ℓ-suc ℓ) ℓ AbGroupCategory .ob = AbGroup ℓ AbGroupCategory .Hom[_,_] = AbGroupHom AbGroupCategory .id = idGroupHom AbGroupCategory ._⋆_ = compGroupHom AbGroupCategory .⋆IdL f = GroupHom≡ refl AbGroupCategory .⋆IdR f = GroupHom≡ refl AbGroupCategory .⋆Assoc f g h = GroupHom≡ refl AbGroupCategory .isSetHom = isSetGroupHom
29.416667
52
0.769122
ccd04907407df7bae1ebe0ec905711ce5b9b233b
38
agda
Agda
Categories/Monad/Algebra.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Monad/Algebra.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Monad/Algebra.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
module Categories.Monad.Algebra where
19
37
0.868421
7300e638625217f9bbee465ffc9dff0a2751f4e3
10,476
agda
Agda
plfa/induction.agda
aronerben/agda-playground
64a00f1f97f053d246d5b9deab090e75d923fe8f
[ "BSD-3-Clause" ]
null
null
null
plfa/induction.agda
aronerben/agda-playground
64a00f1f97f053d246d5b9deab090e75d923fe8f
[ "BSD-3-Clause" ]
null
null
null
plfa/induction.agda
aronerben/agda-playground
64a00f1f97f053d246d5b9deab090e75d923fe8f
[ "BSD-3-Clause" ]
null
null
null
module induction where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; sym) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎) open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_) -- ------------------------------- -- (zero + n) + p ≡ zero + (n + p) -- -- (m + n) + p ≡ m + (n + p) -- --------------------------------- -- (suc m + n) + p ≡ suc m + (n + p) -- 1) -- In the beginning, we know nothing. -- On the first day, we know zero. -- 0 : ℕ -- On the second day, we know one and about associativity of 0. -- 0 : ℕ -- 1 : ℕ (0 + 0) + 0 ≡ 0 + (0 + 0) -- On the third day, we know two and about associativity of 1. -- 0 : ℕ -- 1 : ℕ (0 + 0) + 0 ≡ 0 + (0 + 0) -- 2 : ℕ (0 + 1) + 0 ≡ 0 + (1 + 0) (0 + 1) + 1 ≡ 0 + (1 + 1) (0 + 0) + 1 ≡ 0 + (0 + 1) (1 + 0) + 0 ≡ 1 + (0 + 0) -- On the fourth day, we know two and about associativity of 2. -- 0 : ℕ -- 1 : ℕ (0 + 0) + 0 ≡ 0 + (0 + 0) -- 2 : ℕ (0 + 1) + 0 ≡ 0 + (1 + 0) (0 + 1) + 1 ≡ 0 + (1 + 1) (0 + 0) + 1 ≡ 0 + (0 + 1) (1 + 0) + 0 ≡ 1 + (0 + 0) (1 + 0) + 1 ≡ 1 + (0 + 1) (1 + 1) + 0 ≡ 1 + (1 + 0) (1 + 1) + 1 ≡ 1 + (1 + 1) -- 3 : ℕ (0 + 2) + 0 ≡ 0 + (2 + 0) (0 + 2) + 2 ≡ 0 + (2 + 2) (0 + 0) + 2 ≡ 0 + (0 + 2) (0 + 2) + 1 ≡ 0 + (2 + 1) (0 + 1) + 2 ≡ 0 + (1 + 2) (2 + 0) + 0 ≡ 2 + (0 + 0) (2 + 1) + 0 ≡ 2 + (1 + 0) (2 + 2) + 0 ≡ 2 + (2 + 0) (2 + 0) + 1 ≡ 2 + (0 + 1) (2 + 0) + 2 ≡ 2 + (0 + 2) (2 + 1) + 1 ≡ 2 + (1 + 1) (2 + 1) + 2 ≡ 2 + (1 + 2) (2 + 2) + 1 ≡ 2 + (2 + 1) (2 + 2) + 2 ≡ 2 + (2 + 2) -- 2) +-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p) +-assoc zero n p = begin (zero + n) + p ≡⟨⟩ n + p ≡⟨⟩ zero + (n + p) ∎ +-assoc (suc m) n p = begin (suc m + n) + p ≡⟨⟩ suc (m + n) + p ≡⟨⟩ suc ((m + n) + p) ≡⟨ cong suc (+-assoc m n p) ⟩ suc (m + (n + p)) ≡⟨⟩ suc m + (n + p) ∎ +-identityʳ : ∀ (m : ℕ) → m + zero ≡ m +-identityʳ zero = begin zero + zero ≡⟨⟩ zero ∎ +-identityʳ (suc m) = begin suc m + zero ≡⟨⟩ suc (m + zero) ≡⟨ cong suc (+-identityʳ m) ⟩ suc m ∎ +-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n) +-suc zero n = begin zero + suc n ≡⟨⟩ suc n ≡⟨⟩ suc (zero + n) ∎ +-suc (suc m) n = begin suc m + suc n ≡⟨⟩ suc (m + suc n) ≡⟨ cong suc (+-suc m n) ⟩ suc (suc (m + n)) ≡⟨⟩ suc (suc m + n) ∎ +-comm : ∀ (m n : ℕ) → m + n ≡ n + m +-comm m zero = begin m + zero ≡⟨ +-identityʳ m ⟩ m ≡⟨⟩ zero + m ∎ +-comm m (suc n) = begin m + suc n ≡⟨ +-suc m n ⟩ suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ suc (n + m) ≡⟨⟩ suc n + m ∎ +-swap : ∀ (m n p : ℕ) → m + (n + p) ≡ n + (m + p) +-swap m n p = begin m + (n + p) ≡⟨ sym (+-assoc m n p) ⟩ (m + n) + p ≡⟨ cong (_+ p) (+-comm m n) ⟩ (n + m) + p ≡⟨ +-assoc n m p ⟩ n + (m + p) ∎ -- +-swap : ∀ (m n p : ℕ) → m + (n + p) ≡ n + (m + p) -- +-swap m n p rewrite sym (+-assoc m n p) -- | cong (_+ p) (+-comm m n) -- | +-assoc n m p -- = refl -- 3) *-distrib-+ : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p *-distrib-+ zero n p = begin (zero + n) * p ≡⟨⟩ n * p ≡⟨⟩ zero * p + n * p ∎ *-distrib-+ (suc m) n p = begin ((suc m) + n) * p ≡⟨⟩ suc (m + n) * p ≡⟨⟩ p + ((m + n) * p) ≡⟨ cong (p +_) (*-distrib-+ m n p) ⟩ p + (m * p + n * p) ≡⟨ sym (+-assoc p (m * p) (n * p))⟩ (p + m * p) + n * p ≡⟨⟩ (suc m) * p + n * p ∎ -- 4) *-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p) *-assoc zero n p = begin (zero * n) * p ≡⟨⟩ zero * p ≡⟨⟩ zero ≡⟨⟩ zero * n ≡⟨⟩ zero * (n * p) ∎ *-assoc (suc m) n p = begin (suc m * n) * p ≡⟨⟩ (n + m * n) * p ≡⟨ *-distrib-+ n (m * n) p ⟩ (n * p) + (m * n) * p ≡⟨ cong ((n * p) +_) (*-assoc m n p) ⟩ (n * p) + m * (n * p) ≡⟨⟩ suc m * (n * p) ∎ -- 5) *-absorbingʳ : ∀ (m : ℕ) → m * zero ≡ zero *-absorbingʳ zero = begin zero * zero ≡⟨⟩ zero ∎ *-absorbingʳ (suc m) = begin suc m * zero ≡⟨⟩ zero + m * zero ≡⟨ cong (zero +_) (*-absorbingʳ m) ⟩ zero + zero ≡⟨⟩ zero ∎ *-suc : ∀ (m n : ℕ) → m * suc n ≡ m + m * n *-suc zero n = begin zero * (suc n) ≡⟨⟩ zero ≡⟨⟩ zero * n ≡⟨⟩ zero + zero * n ∎ *-suc (suc m) n = begin suc m * suc n ≡⟨⟩ (suc n) + (m * suc n) ≡⟨ cong ((suc n) +_) (*-suc m n) ⟩ (suc n) + (m + m * n) ≡⟨⟩ suc (n + (m + m * n)) ≡⟨ cong suc (sym (+-assoc n m (m * n))) ⟩ suc ((n + m) + m * n) ≡⟨ cong (λ {term → suc (term + m * n)}) (+-comm n m) ⟩ suc ((m + n) + m * n) ≡⟨ cong suc (+-assoc m n (m * n)) ⟩ suc (m + (n + m * n)) ≡⟨⟩ suc (m + (suc m * n)) ≡⟨⟩ suc m + suc m * n ∎ *-comm : ∀ (m n : ℕ) → m * n ≡ n * m *-comm m zero = begin m * zero ≡⟨ *-absorbingʳ m ⟩ zero ≡⟨⟩ zero * m ∎ *-comm m (suc n) = begin m * suc n ≡⟨ *-suc m n ⟩ m + m * n ≡⟨ cong (m +_) (*-comm m n) ⟩ m + n * m ≡⟨⟩ suc n * m ∎ -- 6) 0∸n≡0 : ∀ (n : ℕ) → zero ∸ n ≡ zero 0∸n≡0 zero = begin zero ∸ zero ≡⟨⟩ zero ∎ 0∸n≡0 (suc n) = begin zero ∸ suc n ≡⟨⟩ zero ∎ -- No induction needed, just prove it holds for 0 and for suc n. (Holds because of definition of ∸) -- 7) 0∸n≡0∸n+p : ∀ (n p : ℕ) → zero ∸ n ≡ zero ∸ (n + p) 0∸n≡0∸n+p n zero = begin zero ∸ n ≡⟨ cong (zero ∸_) (sym (+-identityʳ n)) ⟩ zero ∸ (n + zero) ∎ 0∸n≡0∸n+p n (suc p) = begin zero ∸ n ≡⟨ 0∸n≡0 n ⟩ zero ≡⟨⟩ zero ∸ suc (n + p) ≡⟨ cong (zero ∸_) (sym (+-suc n p)) ⟩ zero ∸ (n + suc p) ∎ ∸-+-assoc : ∀ (m n p : ℕ) → (m ∸ n) ∸ p ≡ m ∸ (n + p) ∸-+-assoc zero n p = begin (zero ∸ n) ∸ p ≡⟨ cong (_∸ p) (0∸n≡0 n) ⟩ zero ∸ p ≡⟨ 0∸n≡0 p ⟩ zero ≡⟨ sym (0∸n≡0 n) ⟩ zero ∸ n ≡⟨ 0∸n≡0∸n+p n p ⟩ zero ∸ (n + p) ∎ ∸-+-assoc (suc m) zero p = begin (suc m ∸ zero) ∸ p ≡⟨⟩ suc m ∸ (zero + p) ∎ ∸-+-assoc (suc m) (suc n) p = begin (suc m ∸ suc n) ∸ p ≡⟨⟩ (m ∸ n) ∸ p ≡⟨ ∸-+-assoc m n p ⟩ m ∸ (n + p) ≡⟨⟩ suc m ∸ suc (n + p) ≡⟨⟩ suc m ∸ (suc n + p) ∎ -- 8) *-identityˡ : ∀ (n : ℕ) → 1 * n ≡ n *-identityˡ n = begin 1 * n ≡⟨⟩ (suc zero) * n ≡⟨⟩ n + (zero * n) ≡⟨⟩ n + zero ≡⟨ +-identityʳ n ⟩ n ∎ ^-distribˡ-+-* : ∀ (m n p : ℕ) → m ^ (n + p) ≡ (m ^ n) * (m ^ p) ^-distribˡ-+-* m zero p = begin m ^ (zero + p) ≡⟨⟩ m ^ p ≡⟨ sym (*-identityˡ (m ^ p)) ⟩ 1 * m ^ p ≡⟨⟩ (m ^ zero) * (m ^ p) ∎ ^-distribˡ-+-* m (suc n) p = begin m ^ (suc n + p) ≡⟨⟩ m ^ suc (n + p) ≡⟨⟩ m * (m ^ (n + p)) ≡⟨ cong (m *_) (^-distribˡ-+-* m n p) ⟩ m * (m ^ n * m ^ p) ≡⟨ sym (*-assoc m (m ^ n) (m ^ p)) ⟩ (m * m ^ n) * m ^ p ≡⟨⟩ (m ^ suc n) * (m ^ p) ∎ ^-distribʳ-* : ∀ (m n p : ℕ) → (m * n) ^ p ≡ (m ^ p) * (n ^ p) ^-distribʳ-* m n zero = begin (m * n) ^ zero ≡⟨⟩ 1 ≡⟨⟩ 1 * 1 ≡⟨⟩ (m ^ zero) * (n ^ zero) ∎ ^-distribʳ-* m n (suc p) = begin (m * n) ^ (suc p) ≡⟨⟩ (m * n) * (m * n) ^ p ≡⟨ cong ((m * n) *_) (^-distribʳ-* m n p) ⟩ (m * n) * ((m ^ p) * (n ^ p)) ≡⟨ sym (*-assoc (m * n) (m ^ p) (n ^ p)) ⟩ ((m * n) * (m ^ p)) * (n ^ p) ≡⟨ cong (_* (n ^ p)) (*-assoc m n (m ^ p)) ⟩ (m * (n * (m ^ p))) * (n ^ p) ≡⟨ cong (λ {term → (m * term) * (n ^ p)}) (*-comm n (m ^ p)) ⟩ (m * ((m ^ p) * n)) * (n ^ p) ≡⟨ cong (_* (n ^ p)) (sym (*-assoc m (m ^ p) n)) ⟩ (m * (m ^ p) * n) * (n ^ p) ≡⟨ *-assoc (m * (m ^ p)) n (n ^ p) ⟩ m * (m ^ p) * (n * (n ^ p)) ≡⟨⟩ (m ^ suc p) * (n ^ suc p) ∎ ^-*-assoc : ∀ (m n p : ℕ) → (m ^ n) ^ p ≡ m ^ (n * p) ^-*-assoc m n zero = begin (m ^ n) ^ zero ≡⟨⟩ 1 ≡⟨⟩ m ^ zero ≡⟨ cong (m ^_) (sym (*-absorbingʳ n)) ⟩ m ^ (n * zero) ∎ ^-*-assoc m n (suc p) = begin (m ^ n) ^ suc p ≡⟨⟩ (m ^ n) * (m ^ n) ^ p ≡⟨ cong ((m ^ n) *_) (^-*-assoc m n p) ⟩ (m ^ n) * (m ^ (n * p)) ≡⟨ cong (λ {term → (m ^ n) * (m ^ term)}) (*-comm n p) ⟩ (m ^ n) * (m ^ (p * n)) ≡⟨ sym (^-distribˡ-+-* m n (p * n)) ⟩ m ^ (n + p * n) ≡⟨⟩ m ^ (suc p * n) ≡⟨ cong (m ^_) (*-comm (suc p) n) ⟩ m ^ (n * suc p) ∎ -- 9) data Bin : Set where - : Bin _O : Bin → Bin _I : Bin → Bin inc : Bin → Bin inc - = - I inc (rest O) = rest I inc (rest I) = (inc rest) O to : ℕ → Bin to zero = - O to (suc n) = inc (to n) from : Bin → ℕ from - = 0 from (rest O) = 2 * from rest from (rest I) = 2 * from rest + 1 bin-inverse-suc-inc : ∀ (b : Bin) → from (inc b) ≡ suc (from b) bin-inverse-suc-inc - = begin from (inc -) ≡⟨⟩ from (- I) ≡⟨⟩ 2 * from - + 1 ≡⟨⟩ 2 * 0 + 1 ≡⟨⟩ 0 + 1 ≡⟨⟩ 1 ≡⟨⟩ suc 0 ≡⟨⟩ suc (from -) ∎ bin-inverse-suc-inc (b O) = begin from (inc (b O)) ≡⟨⟩ from (b I) ≡⟨⟩ 2 * from b + 1 ≡⟨ +-comm (2 * from b) 1 ⟩ suc (2 * from b) ≡⟨⟩ suc (from (b O)) ∎ bin-inverse-suc-inc (b I) = begin from (inc (b I)) ≡⟨⟩ from ((inc b) O) ≡⟨⟩ 2 * from (inc b) ≡⟨ cong (2 *_) (bin-inverse-suc-inc b) ⟩ 2 * suc (from b) ≡⟨ *-comm 2 (suc (from b)) ⟩ suc (from b) * 2 ≡⟨⟩ (1 + from b) * 2 ≡⟨ *-distrib-+ 1 (from b) 2 ⟩ 1 * 2 + from b * 2 ≡⟨ cong (1 * 2 +_) (*-comm (from b) 2) ⟩ 1 * 2 + 2 * from b ≡⟨⟩ 2 + 2 * from b ≡⟨⟩ suc 1 + 2 * from b ≡⟨⟩ suc (1 + 2 * from b) ≡⟨ cong (suc) (+-comm 1 (2 * from b)) ⟩ suc (2 * from b + 1) ≡⟨⟩ suc (from (b I)) ∎ -- ∀ (b : Bin) → to (from b) ≡ b -- This does not work, as "from" is a surjective function. Both "-" and "- O" from Bin map into 0 from ℕ. Surjective functions have no left inverse. -- 0 would have to map into two values, making the inverse of "from" not a function. -- This works, as "to" is an injective function. 0 from ℕ maps (according to our definition) into "- O" in Bin. Injective functions have a left inverse. -- "from" is a left inverse to "to". Note that there are infinitely many left inverses, since "-" could be mapped to any value in ℕ. from∘to≡idₗ : ∀ (n : ℕ) → from (to n) ≡ n from∘to≡idₗ zero = begin from (to zero) ≡⟨⟩ from (- O) ≡⟨⟩ 2 * from - ≡⟨⟩ 2 * 0 ≡⟨⟩ zero ∎ from∘to≡idₗ (suc n) = begin from (to (suc n)) ≡⟨⟩ from (inc (to n)) ≡⟨ bin-inverse-suc-inc (to n) ⟩ suc (from (to n)) ≡⟨ cong suc (from∘to≡idₗ n) ⟩ suc n ∎
19.617978
414
0.37858
430d5ed6040e12f1a6e10a724a896180389651a4
1,357
agda
Agda
test/Succeed/Issue843.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue843.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue843.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v tc.term.let.pattern:20 #-} -- {-# OPTIONS -v tc.meta.assign:10 #-} -- {-# OPTIONS -v tc.meta.assign.proj:45 #-} -- {-# OPTIONS -v tc.meta.assign.catch:80 #-} -- Andreas, 2013-05-06 deep let-bound patterns were translated wrongly module Issue843 {A B C : Set} (a : A) (b : B) (c : C) where open import Common.Product open import Common.Equality T : Set T = A × B × C val : T val = a , (b , c) -- This was translated wrongly: ap : {R : Set} (f : T → R) → R ap f = let x , (y , z) = a , (b , c) -- val in f (x , (y , z)) works : {R : Set} (f : T → R) → R works f = let x , yz = val in let y , z = yz in f (x , (y , z)) ap′ : {R : Set} (f : T → R) → R ap′ f = f (proj₁ val , (proj₁ (proj₂ val) , proj₂ (proj₂ val))) test : ∀ {R} (f : T → R) → ap f ≡ f (a , (b , c)) test f = refl {- WAS: The type of test f reduces to Goal: f (a , proj₂ a , c) ≡ f (a , b , c) even though it should reduce to f (a , b , c) ≡ f (a , b , c) And indeed, refl doesn't fit there. Typechecking the example where the hole has been replaced with refl produces: D:\Agda\Strange.agda:21,10-14 proj₂ a != b of type B when checking that the expression refl has type ap f ≡ f (a , b , c) With ap′, the goal reduces correctly and refl is accepted. I'm using a development version of Agda, about one day old. 64bit Windows 7, if it matters. -}
23
113
0.582903
3744b73b7ebd8664ff76da3e6d94b91c1af190ac
1,145
agda
Agda
examples/sinatra/Example.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/sinatra/Example.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/sinatra/Example.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Example where open import Prelude import Typed data Data : Set where nat : Data bool : Data Datatype : Data -> List (List Data) Datatype nat = ε ◄ ε ◄ (ε ◄ nat) Datatype bool = ε ◄ ε ◄ ε data Effect : Set where data _⊆_ : Effect -> Effect -> Set where refl⊆ : forall {M} -> M ⊆ M Monad : Effect -> Set -> Set Monad e A = A return : forall {M A} -> A -> Monad M A return x = x map : forall {M A B} -> (A -> B) -> Monad M A -> Monad M B map f m = f m join : forall {M A} -> Monad M (Monad M A) -> Monad M A join m = m morph : forall {M N} -> M ⊆ N -> (A : Set) -> Monad M A -> Monad N A morph _ A x = x open module TT = Typed Data Datatype Effect _⊆_ Monad (\{M A} -> return {M}{A}) (\{M A B} -> map {M}{A}{B}) (\{M A} -> join {M}{A}) morph zero : forall {M Γ} -> InV M Γ (TyCon nat) zero = con (tl hd) ⟨⟩ suc : forall {M Γ} -> InV M Γ (TyCon nat) -> InV M Γ (TyCon nat) suc n = con hd (⟨⟩ ◃ n) true : forall {M Γ} -> InV M Γ (TyCon bool) true = con hd ⟨⟩ false : forall {M Γ} -> InV M Γ (TyCon bool) false = con (tl hd) ⟨⟩
20.818182
69
0.516157
1bb6af93385191d017a8438ebe88a6b17fba7863
270
agda
Agda
test/Succeed/SizedTypesLeqInfty.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/SizedTypesLeqInfty.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/SizedTypesLeqInfty.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --sized-types #-} module SizedTypesLeqInfty where open import Common.Size data Nat : {size : Size} -> Set where zero : {size : Size} -> Nat {↑ size} suc : {size : Size} -> Nat {size} -> Nat {↑ size} weak : {i : Size} -> Nat {i} -> Nat {∞} weak x = x
22.5
52
0.574074
73782bc83a9c8a7a77706c01860755f4ebf2a65f
165
agda
Agda
test/Succeed/Issue1870.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1870.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1870.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where postulate U : Set u : U module M (x : U) where postulate f : U → U module M₁ = M (M.f u u) -- this caused a 'recursive display form' error
13.75
72
0.618182
35eb22c04705fd14f79961e1694bc12cefb01669
2,249
agda
Agda
examples/examplesPaperJFP/loadAllOOAgdaFilesAsInLibrary.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
examples/examplesPaperJFP/loadAllOOAgdaFilesAsInLibrary.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
examples/examplesPaperJFP/loadAllOOAgdaFilesAsInLibrary.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module examplesPaperJFP.loadAllOOAgdaFilesAsInLibrary where -- this file loads those files from the ooAgda paper -- which occur in the library as well -- the code as it occurred in the original paper after adapting to current Agda -- including any code not found directly inthe library -- can be found in loadAllOOAgdaPart1.agda -- and loadAllOOAgdaPart2.agda -- Source of paper: -- Andreas Abel, Stephan Adelsberger, Anton Setzer: -- Interactive Programming in Agda - Objects and Graphical User Interfaces -- Journal of Functional Programming, 27, 2017 -- doi: http://dx.doi.org/10.1145/2976022.2976032 -- authors copy: http://www.cs.swan.ac.uk/~csetzer/articles/ooAgda.pdf -- bibtex: http://www.cs.swan.ac.uk/~csetzer/articles/ooAgda.bib -- 1. Introdution -- 2. Introduction to Agda -- 3. Coalgebras in Agda -- 3.1. Coalgebra by example: Colists -- 3.2. Coalgebras in General -- 4. Interactive Programs in Agda -- 4.1. Interaction interfaces -- 4.2. Interaction trees -- 4.3. Running interactive programs -- 5. Objects in Agda -- code as in paper adapted to new Agda -- open import examplesPaperJFP.Object -- code as in library open import SizedIO.Object -- 6. Sized Coinductive Types -- 7. Interface Extension and Delegation -- code as in paper adapted to new Agda -- open import examplesPaperJFP.CounterCell -- code as in library open import Sized.CounterCell -- 8. State-Dependent Objects and IO -- 8.1 State-Dependent Interfaces -- 8.2 State-Dependent Objects -- 8.2.1. Example of Use of Safe Stack -- 8.3 Reasoning About Stateful Objects -- 8.3.1. Bisimilarity -- 8.3.2. Verifying stack laws} -- 8.3.3. Bisimilarity of different stack implementations -- 8.4. State-Dependent IO -- 9. A Drawing Program in Agda open import SizedIO.IOGraphicsLib -- 10. A Graphical User Interface using an Object -- 10.1. wxHaskell -- 10.2. A Library for Object-Based GUIs in Agda open import StateSizedIO.GUI.VariableList open import StateSizedIO.GUI.WxGraphicsLib -- 10.3 Example: A GUI controlling a Space Ship in Agda open import StateSized.GUI.SpaceShipSimpleVar open import StateSized.GUI.SpaceShipCell open import StateSized.GUI.SpaceShipAdvanced -- 11. Related Work -- 12. Conclusion -- Bibliography
30.391892
79
0.746999
a068cb4b83a02bf4420548e2da555e28e201ca2d
17,868
agda
Agda
src/Delay-monad/Bisimilarity.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
src/Delay-monad/Bisimilarity.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
src/Delay-monad/Bisimilarity.agda
nad/delay-monad
495f9996673d0f1f34ce202902daaa6c39f8925e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A combined definition of strong and weak bisimilarity and -- expansion, along with various properties ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Delay-monad.Bisimilarity where open import Equality.Propositional as E using (_≡_) open import Logical-equivalence using (_⇔_) open import Prelude open import Prelude.Size open import Conat E.equality-with-J as Conat using (zero; suc; force; [_]_≤_) open import Function-universe E.equality-with-J hiding (_∘_; Kind) open import Delay-monad open import Delay-monad.Bisimilarity.Kind ------------------------------------------------------------------------ -- The code below is defined for a fixed type A module _ {a} {A : Type a} where ---------------------------------------------------------------------- -- The relations mutual -- A combined definition of all three relations. The definition -- uses mixed induction and coinduction. infix 4 [_]_⟨_⟩_ [_]_⟨_⟩′_ data [_]_⟨_⟩_ (i : Size) : Delay A ∞ → Kind → Delay A ∞ → Type a where now : ∀ {k x} → [ i ] now x ⟨ k ⟩ now x later : ∀ {k x y} → [ i ] force x ⟨ k ⟩′ force y → [ i ] later x ⟨ k ⟩ later y laterˡ : ∀ {k x y} → [ i ] force x ⟨ other k ⟩ y → [ i ] later x ⟨ other k ⟩ y laterʳ : ∀ {x y} → [ i ] x ⟨ other weak ⟩ force y → [ i ] x ⟨ other weak ⟩ later y record [_]_⟨_⟩′_ (i : Size) (x : Delay A ∞) (k : Kind) (y : Delay A ∞) : Type a where coinductive field force : {j : Size< i} → [ j ] x ⟨ k ⟩ y open [_]_⟨_⟩′_ public -- Strong bisimilarity. infix 4 [_]_∼_ [_]_∼′_ _∼_ _∼′_ [_]_∼_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_∼_ = [_]_⟨ strong ⟩_ [_]_∼′_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_∼′_ = [_]_⟨ strong ⟩′_ _∼_ : Delay A ∞ → Delay A ∞ → Type a _∼_ = [ ∞ ]_∼_ _∼′_ : Delay A ∞ → Delay A ∞ → Type a _∼′_ = [ ∞ ]_∼′_ -- Expansion. infix 4 [_]_≳_ [_]_≳′_ _≳_ _≳′_ [_]_≳_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≳_ = [_]_⟨ other expansion ⟩_ [_]_≳′_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≳′_ = [_]_⟨ other expansion ⟩′_ _≳_ : Delay A ∞ → Delay A ∞ → Type a _≳_ = [ ∞ ]_≳_ _≳′_ : Delay A ∞ → Delay A ∞ → Type a _≳′_ = [ ∞ ]_≳′_ -- The converse of expansion. infix 4 [_]_≲_ [_]_≲′_ _≲_ _≲′_ [_]_≲_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≲_ i = flip [ i ]_⟨ other expansion ⟩_ [_]_≲′_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≲′_ i = flip [ i ]_⟨ other expansion ⟩′_ _≲_ : Delay A ∞ → Delay A ∞ → Type a _≲_ = [ ∞ ]_≲_ _≲′_ : Delay A ∞ → Delay A ∞ → Type a _≲′_ = [ ∞ ]_≲′_ -- Weak bisimilarity. infix 4 [_]_≈_ [_]_≈′_ _≈_ _≈′_ [_]_≈_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≈_ = [_]_⟨ other weak ⟩_ [_]_≈′_ : Size → Delay A ∞ → Delay A ∞ → Type a [_]_≈′_ = [_]_⟨ other weak ⟩′_ _≈_ : Delay A ∞ → Delay A ∞ → Type a _≈_ = [ ∞ ]_≈_ _≈′_ : Delay A ∞ → Delay A ∞ → Type a _≈′_ = [ ∞ ]_≈′_ ---------------------------------------------------------------------- -- Conversions -- Strong bisimilarity is contained in the other relations (and -- itself). ∼→ : ∀ {k i x y} → [ i ] x ∼ y → [ i ] x ⟨ k ⟩ y ∼→ now = now ∼→ (later p) = later λ { .force → ∼→ (force p) } -- Expansion is contained in weak bisimilarity (and expansion). ≳→ : ∀ {k i x y} → [ i ] x ≳ y → [ i ] x ⟨ other k ⟩ y ≳→ now = now ≳→ (later p) = later λ { .force → ≳→ (force p) } ≳→ (laterˡ p) = laterˡ (≳→ p) -- In some cases weak bisimilarity is contained in expansion (and -- itself). ≈→-now : ∀ {k i x y} → [ i ] x ≈ now y → [ i ] x ⟨ other k ⟩ now y ≈→-now now = now ≈→-now (laterˡ p) = laterˡ (≈→-now p) -- In some cases all three relations are contained in strong -- bisimilarity. →∼-neverˡ : ∀ {k i x} → [ i ] never ⟨ k ⟩ x → [ i ] never ∼ x →∼-neverˡ (later p) = later λ { .force → →∼-neverˡ (force p) } →∼-neverˡ (laterˡ p) = →∼-neverˡ p →∼-neverˡ (laterʳ p) = later λ { .force → →∼-neverˡ p } →∼-neverʳ : ∀ {k i x} → [ i ] x ⟨ k ⟩ never → [ i ] x ∼ never →∼-neverʳ (later p) = later λ { .force → →∼-neverʳ (force p) } →∼-neverʳ (laterˡ p) = later λ { .force → →∼-neverʳ p } →∼-neverʳ (laterʳ p) = →∼-neverʳ p ---------------------------------------------------------------------- -- Removing later constructors -- Later constructors can sometimes be removed. drop-laterʳ : ∀ {k i} {j : Size< i} {x y} → [ i ] x ⟨ other k ⟩ y → [ j ] x ⟨ other k ⟩ drop-later y drop-laterʳ now = now drop-laterʳ (later p) = laterˡ (force p) drop-laterʳ (laterʳ p) = p drop-laterʳ (laterˡ p) = laterˡ (drop-laterʳ p) drop-laterˡ : ∀ {i} {j : Size< i} {x y} → [ i ] x ≈ y → [ j ] drop-later x ≈ y drop-laterˡ now = now drop-laterˡ (later p) = laterʳ (force p) drop-laterˡ (laterʳ p) = laterʳ (drop-laterˡ p) drop-laterˡ (laterˡ p) = p drop-laterˡʳ : ∀ {k i} {j : Size< i} {x y} → [ i ] x ⟨ k ⟩ y → [ j ] drop-later x ⟨ k ⟩ drop-later y drop-laterˡʳ now = now drop-laterˡʳ (later p) = force p drop-laterˡʳ (laterʳ p) = drop-laterˡ p drop-laterˡʳ (laterˡ p) = drop-laterʳ p -- Special cases of the functions above. laterʳ⁻¹ : ∀ {k i} {j : Size< i} {x y} → [ i ] x ⟨ other k ⟩ later y → [ j ] x ⟨ other k ⟩ force y laterʳ⁻¹ = drop-laterʳ laterˡ⁻¹ : ∀ {i} {j : Size< i} {x y} → [ i ] later x ≈ y → [ j ] force x ≈ y laterˡ⁻¹ = drop-laterˡ later⁻¹ : ∀ {k i} {j : Size< i} {x y} → [ i ] later x ⟨ k ⟩ later y → [ j ] force x ⟨ k ⟩ force y later⁻¹ = drop-laterˡʳ -- The following size-preserving variant of laterʳ⁻¹ and laterˡ⁻¹ -- can be defined. -- -- Several other variants cannot be defined (unless A is -- uninhabited), see Delay-monad.Bisimilarity.Negative. laterˡʳ⁻¹ : ∀ {k i x y} → [ i ] later x ⟨ other k ⟩ force y → [ i ] force x ⟨ other k ⟩ later y → [ i ] force x ⟨ other k ⟩ force y laterˡʳ⁻¹ {k} {i} p q = laterˡʳ⁻¹′ p q E.refl E.refl where laterˡʳ⁻¹″ : ∀ {x′ y′ x y} → ({j : Size< i} → [ j ] x′ ⟨ other k ⟩ force y) → ({j : Size< i} → [ j ] force x ⟨ other k ⟩ y′) → x′ ≡ later x → y′ ≡ later y → [ i ] later x ⟨ other k ⟩ later y laterˡʳ⁻¹″ p q E.refl E.refl = later λ { .force → laterˡʳ⁻¹ p q } laterˡʳ⁻¹′ : ∀ {x′ y′ x y} → [ i ] later x ⟨ other k ⟩ y′ → [ i ] x′ ⟨ other k ⟩ later y → force x {j = ∞} ≡ x′ → force y ≡ y′ → [ i ] x′ ⟨ other k ⟩ y′ laterˡʳ⁻¹′ (later p) (later q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (force p) (force q) ≡x′ ≡y′ laterˡʳ⁻¹′ (laterʳ p) (later q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (λ { {_} → laterˡ⁻¹ p }) (force q) ≡x′ ≡y′ laterˡʳ⁻¹′ (later p) (laterˡ q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (force p) (λ { {_} → laterʳ⁻¹ q }) ≡x′ ≡y′ laterˡʳ⁻¹′ (laterʳ p) (laterˡ q) ≡x′ ≡y′ = laterˡʳ⁻¹″ (λ { {_} → laterˡ⁻¹ p }) (λ { {_} → laterʳ⁻¹ q }) ≡x′ ≡y′ laterˡʳ⁻¹′ (laterˡ p) _ E.refl E.refl = p laterˡʳ⁻¹′ _ (laterʳ q) E.refl ≡y′ = E.subst ([ i ] _ ⟨ _ ⟩_) ≡y′ q ---------------------------------------------------------------------- -- Reflexivity, symmetry/antisymmetry, transitivity -- All three relations are reflexive. reflexive : ∀ {k i} x → [ i ] x ⟨ k ⟩ x reflexive (now _) = now reflexive (later x) = later λ { .force → reflexive (force x) } -- Strong and weak bisimilarity are symmetric. symmetric : ∀ {k i x y} {¬≳ : if k ≟-Kind other expansion then ⊥ else ⊤} → [ i ] x ⟨ k ⟩ y → [ i ] y ⟨ k ⟩ x symmetric now = now symmetric (laterˡ {k = weak} p) = laterʳ (symmetric p) symmetric (laterʳ p) = laterˡ (symmetric p) symmetric {¬≳ = ¬≳} (later p) = later λ { .force → symmetric {¬≳ = ¬≳} (force p) } symmetric {¬≳ = ()} (laterˡ {k = expansion} _) -- Some special cases of symmetry hold for expansion. symmetric-neverˡ : ∀ {i x} → [ i ] never ≳ x → [ i ] x ≳ never symmetric-neverˡ = ∼→ ∘ symmetric ∘ →∼-neverˡ symmetric-neverʳ : ∀ {i x} → [ i ] x ≳ never → [ i ] never ≳ x symmetric-neverʳ = ∼→ ∘ symmetric ∘ →∼-neverʳ -- The expansion relation is antisymmetric (up to weak -- bisimilarity). antisymmetric-≳ : ∀ {i x y} → [ i ] x ≳ y → [ i ] y ≳ x → [ i ] x ≈ y antisymmetric-≳ p _ = ≳→ p -- Several more or less size-preserving variants of transitivity. -- -- Many size-preserving variants cannot be defined (unless A is -- uninhabited), see Delay-monad.Bisimilarity.Negative. transitive-∼ʳ : ∀ {k i x y z} {¬≈ : if k ≟-Kind other weak then ⊥ else ⊤} → [ i ] x ⟨ k ⟩ y → [ i ] y ∼ z → [ i ] x ⟨ k ⟩ z transitive-∼ʳ now now = now transitive-∼ʳ {¬≈ = ¬≈} (laterˡ p) q = laterˡ (transitive-∼ʳ {¬≈ = ¬≈} p q) transitive-∼ʳ {¬≈ = ()} (laterʳ _) _ transitive-∼ʳ {¬≈ = ¬≈} (later p) (later q) = later λ { .force → transitive-∼ʳ {¬≈ = ¬≈} (force p) (force q) } transitive-∼ˡ : ∀ {k i x y z} → x ∼ y → [ i ] y ⟨ k ⟩ z → [ i ] x ⟨ k ⟩ z transitive-∼ˡ now now = now transitive-∼ˡ (later p) (later q) = later λ { .force → transitive-∼ˡ (force p) (force q) } transitive-∼ˡ (later p) (laterˡ q) = laterˡ (transitive-∼ˡ (force p) q) transitive-∼ˡ p (laterʳ q) = laterʳ (transitive-∼ˡ p q) transitive-∞∼ʳ : ∀ {k i x y z} → [ i ] x ⟨ k ⟩ y → y ∼ z → [ i ] x ⟨ k ⟩ z transitive-∞∼ʳ now now = now transitive-∞∼ʳ (later p) (later q) = later λ { .force → transitive-∞∼ʳ (force p) (force q) } transitive-∞∼ʳ (laterˡ p) q = laterˡ (transitive-∞∼ʳ p q) transitive-∞∼ʳ (laterʳ p) (later q) = laterʳ (transitive-∞∼ʳ p (force q)) transitive-≳ˡ : ∀ {k i x y z} → x ≳ y → [ i ] y ⟨ other k ⟩ z → [ i ] x ⟨ other k ⟩ z transitive-≳ˡ now now = now transitive-≳ˡ (later p) (later q) = later λ { .force → transitive-≳ˡ (force p) (force q) } transitive-≳ˡ (later p) (laterˡ q) = laterˡ (transitive-≳ˡ (force p) q) transitive-≳ˡ (laterˡ p) q = laterˡ (transitive-≳ˡ p q) transitive-≳ˡ p (laterʳ q) = laterʳ (transitive-≳ˡ p q) transitive-≈≲ : ∀ {i x y z} → [ i ] x ≈ y → y ≲ z → [ i ] x ≈ z transitive-≈≲ p q = symmetric (transitive-≳ˡ q (symmetric p)) transitive-≈-now : ∀ {i x′ y z} → let x = now x′ in [ i ] x ≈ y → y ≈ z → [ i ] x ≈ z transitive-≈-now now now = now transitive-≈-now (laterʳ p) q = transitive-≈-now p (laterˡ⁻¹ q) transitive-≈-now p (laterʳ q) = laterʳ (transitive-≈-now p q) mutual transitive-≈-later : ∀ {i x′ y z} → let x = later x′ in x ≈ y → y ≈ z → [ i ] x ≈ z transitive-≈-later p (later q) = later λ { .force → transitive-≈ (later⁻¹ p) (force q) } transitive-≈-later p (laterʳ q) = laterʳ (transitive-≈-later p q) transitive-≈-later p (laterˡ q) = transitive-≈ (laterʳ⁻¹ p) q transitive-≈-later (laterˡ p) q = laterˡ (transitive-≈ p q) transitive-≈ : ∀ {i x y z} → x ≈ y → y ≈ z → [ i ] x ≈ z transitive-≈ {x = now x} p q = transitive-≈-now p q transitive-≈ {x = later x} p q = transitive-≈-later p q -- Equational reasoning combinators. infix -1 _∎ finally finally-≳ finally-≈ infixr -2 step-∼ˡ step-∼∼ step-≳∼ step-≈∼ step-?∼ step-≳ˡ step-≈ _≳⟨⟩_ step-≡ˡ _∼⟨⟩_ _∎ : ∀ {k i} x → [ i ] x ⟨ k ⟩ x _∎ = reflexive finally : ∀ {k i} x y → [ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ y finally _ _ x?y = x?y syntax finally x y x≈y = x ?⟨ x≈y ⟩∎ y ∎ finally-≳ : ∀ {i} x y → [ i ] x ≳ y → [ i ] x ≳ y finally-≳ _ _ x≳y = x≳y syntax finally-≳ x y x≳y = x ≳⟨ x≳y ⟩∎ y ∎ finally-≈ : ∀ {i} x y → [ i ] x ≈ y → [ i ] x ≈ y finally-≈ _ _ x≈y = x≈y syntax finally-≈ x y x≈y = x ≈⟨ x≈y ⟩∎ y ∎ step-∼ˡ : ∀ {k i} x {y z} → [ i ] y ⟨ k ⟩ z → x ∼ y → [ i ] x ⟨ k ⟩ z step-∼ˡ _ y⟨⟩z x∼y = transitive-∼ˡ x∼y y⟨⟩z syntax step-∼ˡ x y⟨⟩z x∼y = x ∼⟨ x∼y ⟩ y⟨⟩z step-∼∼ : ∀ {i} x {y z} → [ i ] y ∼ z → [ i ] x ∼ y → [ i ] x ∼ z step-∼∼ _ y∼z x∼y = transitive-∼ʳ x∼y y∼z syntax step-∼∼ x y∼z x∼y = x ∼⟨ x∼y ⟩∼ y∼z step-≳∼ : ∀ {i} x {y z} → [ i ] y ∼ z → [ i ] x ≳ y → [ i ] x ≳ z step-≳∼ _ y∼z x≳y = transitive-∼ʳ x≳y y∼z syntax step-≳∼ x y∼z x≳y = x ≳⟨ x≳y ⟩∼ y∼z step-≈∼ : ∀ {i} x {y z} → y ∼ z → [ i ] x ≈ y → [ i ] x ≈ z step-≈∼ _ y∼z x≈y = transitive-∞∼ʳ x≈y y∼z syntax step-≈∼ x y∼z x≈y = x ≈⟨ x≈y ⟩∼ y∼z step-?∼ : ∀ {k i} x {y z} → y ∼ z → [ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ z step-?∼ _ y∼z x?y = transitive-∞∼ʳ x?y y∼z syntax step-?∼ x y∼z x?y = x ?⟨ x?y ⟩∼ y∼z step-≳ˡ : ∀ {k i} x {y z} → [ i ] y ⟨ other k ⟩ z → x ≳ y → [ i ] x ⟨ other k ⟩ z step-≳ˡ _ y≳≈z x≳y = transitive-≳ˡ x≳y y≳≈z syntax step-≳ˡ x y≳≈z x≳y = x ≳⟨ x≳y ⟩ y≳≈z step-≈ : ∀ {i} x {y z} → y ≈ z → x ≈ y → [ i ] x ≈ z step-≈ _ y≈z x≈y = transitive-≈ x≈y y≈z syntax step-≈ x y≈z x≈y = x ≈⟨ x≈y ⟩ y≈z _≳⟨⟩_ : ∀ {k i} x {y} → [ i ] drop-later x ⟨ other k ⟩ y → [ i ] x ⟨ other k ⟩ y now _ ≳⟨⟩ p = p later _ ≳⟨⟩ p = laterˡ p step-≡ˡ : ∀ {k i} x {y z} → [ i ] y ⟨ k ⟩ z → x ≡ y → [ i ] x ⟨ k ⟩ z step-≡ˡ _ y⟨⟩z E.refl = y⟨⟩z syntax step-≡ˡ x y⟨⟩z x≡y = x ≡⟨ x≡y ⟩ y⟨⟩z _∼⟨⟩_ : ∀ {k i} x {y} → [ i ] x ⟨ k ⟩ y → [ i ] x ⟨ k ⟩ y _ ∼⟨⟩ x≈y = x≈y ------------------------------------------------------------------------ -- Some results related to the steps function -- If x and y are strongly bisimilar, then they contain the same -- number of later constructors. steps-cong : ∀ {x y i} → [ i ] x ∼ y → Conat.[ i ] steps x ∼ steps y steps-cong now = zero steps-cong (later p) = suc λ { .force → steps-cong (p .force) } -- If y is an expansion of x, then it contains at least as many -- later constructors as x. steps-mono : ∀ {x y i} → [ i ] x ≲ y → [ i ] steps x ≤ steps y steps-mono now = zero steps-mono (later p) = suc λ { .force → steps-mono (p .force) } steps-mono (laterˡ {x = x} {y = y} p) = steps y ≤⟨ steps-mono p ⟩ steps (x .force) ≤⟨ Conat.≤suc ⟩ steps (later x) ∎≤ where open Conat using (step-≤; _∎≤) -- The computation y is an expansion of x iff x and y are weakly -- bisimilar and y contains at least as many later constructors -- as x. ≲⇔≈×steps≤steps : ∀ {i x y} → [ i ] x ≲ y ⇔ [ i ] x ≈ y × [ i ] steps x ≤ steps y ≲⇔≈×steps≤steps = record { to = λ p → symmetric (≳→ p) , steps-mono p ; from = uncurry from } where from : ∀ {x y i} → [ i ] x ≈ y → [ i ] steps x ≤ steps y → [ i ] x ≲ y from {now _} p zero = ≈→-now (symmetric p) from {later _} {now _} _ () from {later _} {later _} p (suc q) = later λ { .force → from (later⁻¹ p) (q .force) } ---------------------------------------------------------------------- -- Some results related to negation -- The computation never is not related to now x. never≉now : ∀ {k i x} → ¬ [ i ] never ⟨ k ⟩ now x never≉now (laterˡ p) = never≉now p -- The computation now x is not related to never. now≉never : ∀ {k i x} → ¬ [ i ] now x ⟨ k ⟩ never now≉never (laterʳ p) = now≉never p -- If A is uninhabited, then the three relations defined above are -- trivial. uninhabited→trivial : ∀ {k i} → ¬ A → ∀ x y → [ i ] x ⟨ k ⟩ y uninhabited→trivial ¬A (now x) _ = ⊥-elim (¬A x) uninhabited→trivial ¬A (later x) (now y) = ⊥-elim (¬A y) uninhabited→trivial ¬A (later x) (later y) = later λ { .force → uninhabited→trivial ¬A (force x) (force y) } -- Expansion and weak bisimilarity are not pointwise propositional. ¬-≳≈-propositional : ∀ {k} → ¬ (∀ {x y} → E.Is-proposition ([ ∞ ] x ⟨ other k ⟩ y)) ¬-≳≈-propositional {k} = (∀ {x y} → E.Is-proposition ([ ∞ ] x ⟨ other k ⟩ y)) ↝⟨ (λ prop → prop {x = never} {y = never}) ⟩ E.Is-proposition ([ ∞ ] never ⟨ other k ⟩ never) ↝⟨ (λ irr → irr _ _) ⟩ proof₁ ≡ proof₂ ↝⟨ (λ ()) ⟩□ ⊥₀ □ where proof₁ : ∀ {i} → [ i ] never ⟨ other k ⟩ never proof₁ = later λ { .force → proof₁ } proof₂ : ∀ {i} → [ i ] never ⟨ other k ⟩ never proof₂ = laterˡ proof₁ ------------------------------------------------------------------------ -- A statement of extensionality for strong bisimilarity -- A statement of extensionality: strongly bisimilar computations are -- equal. Extensionality : (ℓ : Level) → Type (lsuc ℓ) Extensionality a = {A : Type a} {x y : Delay A ∞} → x ∼ y → x ≡ y -- Another form of extensionality. Extensionality′ : (ℓ : Level) → Type (lsuc ℓ) Extensionality′ a = {A : Type a} {x y : Delay′ A ∞} → force x ∼′ force y → x ≡ y -- The latter form of extensionality implies the former. Extensionality′→Extensionality : ∀ {ℓ} → Extensionality′ ℓ → Extensionality ℓ Extensionality′→Extensionality ext {x = x} {y = y} p = E.cong (λ x → force x) (ext {x = λ { .force → x }} {y = λ { .force → y }} λ { .force → p })
32.725275
121
0.468099