Search is not available for this dataset
text
string
meta
dict
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Truncation.Properties where open import Cubical.HITs.Truncation.Base open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.HITs.Sn open import Cubical.Data.Empty open import Cubical.HITs.Susp open import Cubical.HITs.PropositionalTruncation renaming (∥_∥ to ∥_∥₋₁) open import Cubical.HITs.SetTruncation open import Cubical.HITs.GroupoidTruncation open import Cubical.HITs.2GroupoidTruncation private variable ℓ ℓ' : Level A : Type ℓ sphereFill : (n : ℕ) (f : S n → A) → Type _ sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S n) → top ≡ f x) isSphereFilled : ℕ → Type ℓ → Type ℓ isSphereFilled n A = (f : S n → A) → sphereFill n f isSphereFilled∥∥ : {n : ℕ₋₁} → isSphereFilled (1+ n) (∥ A ∥ n) isSphereFilled∥∥ f = (hub f) , (spoke f) isSphereFilled→isOfHLevel : (n : ℕ) → isSphereFilled n A → isOfHLevel (1 + n) A isSphereFilled→isOfHLevel {A = A} 0 h x y = sym (snd (h f) north) ∙ snd (h f) south where f : Susp ⊥ → A f north = x f south = y f (merid () i) isSphereFilled→isOfHLevel {A = A} (suc n) h x y = isSphereFilled→isOfHLevel n (helper h x y) where helper : {n : ℕ} → isSphereFilled (suc n) A → (x y : A) → isSphereFilled n (x ≡ y) helper {n = n} h x y f = l , r where f' : Susp (S n) → A f' north = x f' south = y f' (merid u i) = f u i u : sphereFill (suc n) f' u = h f' z : A z = fst u p : z ≡ x p = snd u north q : z ≡ y q = snd u south l : x ≡ y l = sym p ∙ q r : (s : S n) → l ≡ f s r s i j = hcomp (λ k → λ { (i = i0) → compPath-filler (sym p) q k j ; (i = i1) → snd u (merid s j) k ; (j = i0) → p (k ∨ (~ i)) ; (j = i1) → q k }) (p ((~ i) ∧ (~ j))) isOfHLevel→isSphereFilled : (n : ℕ) → isOfHLevel (1 + n) A → isSphereFilled n A isOfHLevel→isSphereFilled 0 h f = (f north) , (λ _ → h _ _) isOfHLevel→isSphereFilled {A = A} (suc n) h = helper λ x y → isOfHLevel→isSphereFilled n (h x y) where helper : {n : ℕ} → ((x y : A) → isSphereFilled n (x ≡ y)) → isSphereFilled (suc n) A helper {n = n} h f = l , r where l : A l = f north f' : S n → f north ≡ f south f' x i = f (merid x i) h' : sphereFill n f' h' = h (f north) (f south) f' r : (x : S (suc n)) → l ≡ f x r north = refl r south = h' .fst r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north ; (i = i1) → h' .snd x (~ k) j ; (j = i0) → f north ; (j = i1) → f (merid x i) }) (f (merid x (i ∧ j))) isOfHLevel∥∥ : (n : ℕ₋₁) → isOfHLevel (1 + 1+ n) (∥ A ∥ n) isOfHLevel∥∥ n = isSphereFilled→isOfHLevel (1+ n) isSphereFilled∥∥ ind : {n : ℕ₋₁} {B : ∥ A ∥ n → Type ℓ'} (hB : (x : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x)) (g : (a : A) → B (∣ a ∣)) (x : ∥ A ∥ n) → B x ind hB g (∣ a ∣ ) = g a ind {B = B} hB g (hub f) = isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (ind hB g (f x)) ) .fst ind {B = B} hB g (spoke f x i) = toPathP {A = λ i → B (spoke f x (~ i))} (sym (isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (ind hB g (f x))) .snd x)) (~ i) ind2 : {n : ℕ₋₁} {B : ∥ A ∥ n → ∥ A ∥ n → Type ℓ'} (hB : ((x y : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x y))) (g : (a b : A) → B ∣ a ∣ ∣ b ∣) (x y : ∥ A ∥ n) → B x y ind2 {n = n} hB g = ind (λ _ → hLevelPi (1 + 1+ n) (λ _ → hB _ _)) λ a → ind (λ _ → hB _ _) (λ b → g a b) ind3 : {n : ℕ₋₁} {B : (x y z : ∥ A ∥ n) → Type ℓ'} (hB : ((x y z : ∥ A ∥ n) → isOfHLevel (1 + 1+ n) (B x y z))) (g : (a b c : A) → B (∣ a ∣) ∣ b ∣ ∣ c ∣) (x y z : ∥ A ∥ n) → B x y z ind3 {n = n} hB g = ind2 (λ _ _ → hLevelPi (1 + 1+ n) (hB _ _)) λ a b → ind (λ _ → hB _ _ _) (λ c → g a b c) idemTrunc : (n : ℕ₋₁) → isOfHLevel (1 + 1+ n) A → (∥ A ∥ n) ≃ A idemTrunc {A = A} n hA = isoToEquiv (iso f g f-g g-f) where f : ∥ A ∥ n → A f = ind (λ _ → hA) λ a → a g : A → ∥ A ∥ n g = ∣_∣ f-g : ∀ a → f (g a) ≡ a f-g a = refl g-f : ∀ x → g (f x) ≡ x g-f = ind (λ _ → hLevelSuc (1+ n) _ (hLevelPath (1+ n) (isOfHLevel∥∥ n) _ _)) (λ _ → refl) propTrunc≃Trunc-1 : ∥ A ∥₋₁ ≃ ∥ A ∥ neg1 propTrunc≃Trunc-1 = isoToEquiv (iso (elimPropTrunc (λ _ → isOfHLevel∥∥ neg1) ∣_∣) (ind (λ _ → propTruncIsProp) ∣_∣) (ind (λ _ → hLevelSuc 0 _ (hLevelPath 0 (isOfHLevel∥∥ neg1) _ _)) (λ _ → refl)) (elimPropTrunc (λ _ → hLevelSuc 0 _ (hLevelPath 0 propTruncIsProp _ _)) (λ _ → refl))) setTrunc≃Trunc0 : ∥ A ∥₀ ≃ ∥ A ∥ (suc neg1) setTrunc≃Trunc0 = isoToEquiv (iso (elimSetTrunc (λ _ → isOfHLevel∥∥ (suc neg1)) ∣_∣) (ind (λ _ → squash₀) ∣_∣₀) (ind (λ _ → hLevelSuc 1 _ (hLevelPath 1 (isOfHLevel∥∥ (suc neg1)) _ _)) (λ _ → refl)) (elimSetTrunc (λ _ → hLevelSuc 1 _ (hLevelPath 1 squash₀ _ _)) (λ _ → refl))) groupoidTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ (ℕ→ℕ₋₁ 1) groupoidTrunc≃Trunc1 = isoToEquiv (iso (groupoidTruncElim _ _ (λ _ → isOfHLevel∥∥ (ℕ→ℕ₋₁ 1)) ∣_∣) (ind (λ _ → squash₁) ∣_∣₁) (ind (λ _ → hLevelSuc 2 _ (hLevelPath 2 (isOfHLevel∥∥ (ℕ→ℕ₋₁ 1)) _ _)) (λ _ → refl)) (groupoidTruncElim _ _ (λ _ → hLevelSuc 2 _ (hLevelPath 2 squash₁ _ _)) (λ _ → refl))) 2groupoidTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ (ℕ→ℕ₋₁ 2) 2groupoidTrunc≃Trunc2 = isoToEquiv (iso (g2TruncElim _ _ (λ _ → isOfHLevel∥∥ (ℕ→ℕ₋₁ 2)) ∣_∣) (ind (λ _ → squash₂) ∣_∣₂) (ind (λ _ → hLevelSuc 3 _ (hLevelPath 3 (isOfHLevel∥∥ (ℕ→ℕ₋₁ 2)) _ _)) (λ _ → refl)) (g2TruncElim _ _ (λ _ → hLevelSuc 3 _ (hLevelPath 3 squash₂ _ _)) (λ _ → refl)))
{ "alphanum_fraction": 0.49531351, "avg_line_length": 33.4486486486, "ext": "agda", "hexsha": "bfcaf1a30a2f472205a5e6208f69a10388fcdd9f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/HITs/Truncation/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_path": "Cubical/HITs/Truncation/Properties.agda", "max_line_length": 110, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/HITs/Truncation/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2706, "size": 6188 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Boolean.Definition open import Sets.FinSet.Definition open import LogicalFormulae open import Groups.Abelian.Definition open import Groups.Vector open import Groups.Definition open import Groups.Abelian.Definition open import Numbers.Integers.Integers open import Setoids.Setoids open import Sets.EquivalenceRelations open import Modules.Definition open import Groups.Cyclic.Definition open import Groups.Cyclic.DefinitionLemmas open import Rings.Polynomial.Multiplication open import Rings.Polynomial.Ring open import Rings.Definition open import Rings.Lemmas open import Groups.Polynomials.Definition open import Numbers.Naturals.Semiring open import Vectors open import Modules.Span open import Numbers.Integers.Definition open import Numbers.Integers.Addition open import Rings.IntegralDomains.Definition open import Numbers.Naturals.Order open import Numbers.Modulo.Definition open import Numbers.Modulo.Group module Modules.Examples where abGrpModule : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {G' : Group S _+_} (G : AbelianGroup G') → Module ℤRing G (λ x i → elementPower G' i x) Module.dotWellDefined (abGrpModule {S = S} {G' = G'} G) {m} {n} {g} {h} m=n g=h = transitive (elementPowerWellDefinedG G' g h g=h {m}) (elementPowerWellDefinedZ' G' m n m=n {h}) where open Setoid S open Equivalence eq Module.dotDistributesLeft (abGrpModule {G' = G'} G) {n} {x} {y} = elementPowerHomAbelian G' (AbelianGroup.commutative G) x y n Module.dotDistributesRight (abGrpModule {S = S} {G' = G'} G) {r} {s} {x} = symmetric (elementPowerCollapse G' x r s) where open Equivalence (Setoid.eq S) Module.dotAssociative (abGrpModule {G' = G'} G) {r} {s} {x} = elementPowerMultiplies G' r s x Module.dotIdentity (abGrpModule {G' = G'} G) = Group.identRight G' zAndZ : Module ℤRing ℤAbGrp _*Z_ Module.dotWellDefined zAndZ refl refl = refl Module.dotDistributesLeft zAndZ = Ring.*DistributesOver+ ℤRing Module.dotDistributesRight zAndZ {x} {y} {z} = Ring.*DistributesOver+' ℤRing {x} {y} {z} Module.dotAssociative zAndZ {x} {y} {z} = equalityCommutative (Ring.*Associative ℤRing {x} {y} {z}) Module.dotIdentity zAndZ = Ring.identIsIdent ℤRing twoOrAnother : ℤ → Bool → ℤ twoOrAnother _ BoolTrue = nonneg 2 twoOrAnother n BoolFalse = n 23Spans : Spans zAndZ (twoOrAnother (nonneg 3)) 23Spans m = 2 , (((BoolTrue ,- (BoolFalse ,- [])) ,, (Group.inverse ℤGroup m ,- (m ,- []))) , t m) where open Group ℤGroup open Ring ℤRing t : (m : ℤ) → inverse m *Z nonneg 2 +Z (m *Z nonneg 3 +Z nonneg 0) ≡ m t m rewrite identRight {m *Z nonneg 3} | *DistributesOver+ {m} {nonneg 2} {nonneg 1} | +Associative {inverse m *Z nonneg 2} {m *Z nonneg 2} {m *Z nonneg 1} = transitivity (transitivity (+WellDefined {inverse m *Z nonneg 2 +Z m *Z nonneg 2} {m *Z nonneg 1} {nonneg 0} {_} (transitivity (equalityCommutative (*DistributesOver+' {inverse m} {m} {nonneg 2})) (*WellDefined (invLeft {m}) refl)) refl) *Commutative) identIsIdent evenNotOdd : (i : ℤ) → nonneg 0 ≡ i *Z nonneg 2 +Z nonneg 1 → False evenNotOdd (nonneg x) pr rewrite equalityCommutative (+Zinherits (x *N 2) 1) = evenNotOdd' x (nonnegInjective pr) where evenNotOdd' : (i : ℕ) → 0 ≡ i *N 2 +N 1 → False evenNotOdd' zero () evenNotOdd' (succ i) () evenNotOdd (negSucc zero) () evenNotOdd (negSucc (succ zero)) () evenNotOdd (negSucc (succ (succ x))) () 2NotSpan : Spans zAndZ {_} {True} (λ _ → nonneg 2) → False 2NotSpan f with f (nonneg 1) 2NotSpan f | n , (trues , b) = bad (_&&_.fst trues) (_&&_.snd trues) (nonneg 0) b where open Group ℤGroup open Ring ℤRing bad : {n : ℕ} → (t : Vec True n) (u : Vec ℤ n) (i : ℤ) → dot zAndZ (vecMap (λ _ → nonneg 2) t) u ≡ ((i *Z nonneg 2) +Z nonneg 1) → False bad [] [] i x = evenNotOdd i x bad (record {} ,- t) (u ,- us) i x = bad t us (i +Z inverse u) (transitivity (+WellDefined (equalityCommutative (invLeft {u *Z nonneg 2})) refl) (transitivity (equalityCommutative (+Associative {inverse (u *Z nonneg 2)} {u *Z nonneg 2})) (transitivity (+WellDefined (refl {x = inverse (u *Z nonneg 2)}) x) (transitivity (+Associative {inverse (u *Z nonneg 2)} {i *Z nonneg 2}) (+WellDefined {inverse (u *Z nonneg 2) +Z i *Z nonneg 2} {_} {(i +Z inverse u) *Z nonneg 2} (transitivity (transitivity (groupIsAbelian {inverse (u *Z nonneg 2)}) (applyEquality (i *Z nonneg 2 +Z_) (equalityCommutative (ringMinusExtracts' ℤRing)))) (equalityCommutative (*DistributesOver+' {i} {inverse u} {nonneg 2}))) (refl {x = nonneg 1})))))) 3NotSpan : Spans zAndZ {_} {True} (λ _ → nonneg 3) → False 3NotSpan f with f (nonneg 1) ... | n , ((trues ,, coeffs) , b) = bad trues coeffs (nonneg 0) b where open Group ℤGroup open Ring ℤRing bad : {n : ℕ} → (t : Vec True n) (u : Vec ℤ n) (i : ℤ) → dot zAndZ (vecMap (λ _ → nonneg 3) t) u ≡ ((i *Z nonneg 3) +Z nonneg 1) → False bad [] [] (nonneg zero) () bad [] [] (nonneg (succ i)) () bad [] [] (negSucc zero) () bad [] [] (negSucc (succ i)) () bad (record {} ,- ts) (u ,- us) i x = bad ts us (i +Z inverse u) (transitivity (+WellDefined (equalityCommutative (invLeft {u *Z nonneg 3})) (refl {x = dot zAndZ (vecMap (λ _ → nonneg 3) ts) us})) (transitivity (equalityCommutative (+Associative {inverse (u *Z nonneg 3)} {u *Z nonneg 3})) (transitivity (+WellDefined (equalityCommutative (ringMinusExtracts' ℤRing {u} {nonneg 3})) x) (transitivity (+Associative {inverse u *Z nonneg 3} {i *Z nonneg 3} {nonneg 1}) (+WellDefined (transitivity {x = (inverse u *Z nonneg 3 +Z i *Z nonneg 3)} (equalityCommutative (*DistributesOver+' {inverse u} {i})) (*WellDefined (groupIsAbelian {inverse u} {i}) (refl {x = nonneg 3}))) (refl {x = nonneg 1})))))) nothingNotSpan : Spans zAndZ {_} {False} (λ ()) → False nothingNotSpan f with f (nonneg 1) nothingNotSpan f | zero , (([] ,, []) , ()) nothingNotSpan f | succ n , (((() ,- fst) ,, snd) , b) 1Basis : Basis zAndZ {_} {True} (λ _ → nonneg 1) _&&_.fst 1Basis m = 1 , (((record {} ,- []) ,, (m ,- [])) , transitivity (Group.+WellDefined ℤGroup (transitivity (Ring.*Commutative ℤRing {m}) (Ring.identIsIdent ℤRing)) refl) (Group.identRight ℤGroup)) _&&_.snd 1Basis {zero} r x [] x₁ = record {} _&&_.snd 1Basis {succ zero} (record {} ,- []) x (b ,- []) pr = equalityCommutative (transitivity (equalityCommutative (transitivity (Group.+WellDefined ℤGroup (transitivity (Ring.*Commutative ℤRing {b}) (Ring.identIsIdent ℤRing)) refl) (Group.identRight ℤGroup))) pr) ,, record {} _&&_.snd 1Basis {succ (succ n)} (record {} ,- (record {} ,- r)) x b pr with x {0} {1} (succIsPositive _) (succPreservesInequality (succIsPositive _)) refl _&&_.snd 1Basis {succ (succ n)} (record {} ,- (record {} ,- r)) x b pr | () 2Independent : Independent zAndZ {_} {True} (λ _ → nonneg 2) 2Independent {zero} r x [] x₁ = record {} 2Independent {succ zero} (record {} ,- []) x (coeff ,- []) pr rewrite Group.identRight ℤGroup {coeff *Z nonneg 2} = equalityCommutative (IntegralDomain.intDom ℤIntDom (transitivity (Ring.*Commutative ℤRing) pr) λ ()) ,, record {} 2Independent {succ (succ n)} (record {} ,- (record {} ,- rest)) pr b x = exFalso (naughtE t) where t : 0 ≡ 1 t = pr {0} {1} (succIsPositive (succ n)) (succPreservesInequality (succIsPositive n)) refl 2AndExtraNotIndependent : (n : ℤ) → Independent zAndZ (twoOrAnother n) → False 2AndExtraNotIndependent n indep = exFalso (naughtE (nonnegInjective ohNo)) where r : {a b : ℕ} → (a<n : a <N 2) → (b<n : b <N 2) → vecIndex (BoolTrue ,- (BoolFalse ,- [])) a a<n ≡ vecIndex (BoolTrue ,- (BoolFalse ,- [])) b b<n → a ≡ b r {zero} {zero} a<n b<n x = refl r {zero} {succ (succ b)} a<n (le (succ zero) ()) x r {zero} {succ (succ b)} a<n (le (succ (succ y)) ()) x r {succ zero} {succ zero} a<n b<n x = refl r {succ zero} {succ (succ b)} a<n (le (succ zero) ()) x r {succ zero} {succ (succ b)} a<n (le (succ (succ i)) ()) x r {succ (succ a)} {b} (le (succ zero) ()) b<n x r {succ (succ a)} {b} (le (succ (succ i)) ()) b<n x s : dot zAndZ (vecMap (twoOrAnother n) (BoolTrue ,- (BoolFalse ,- []))) (Group.inverse ℤGroup n ,- (nonneg 2 ,- [])) ≡ nonneg 0 s rewrite Group.identRight ℤGroup {nonneg 2 *Z n} | Ring.*Commutative ℤRing {nonneg 2} {n} | equalityCommutative (Ring.*DistributesOver+' ℤRing {additiveInverse n} {n} {nonneg 2}) | Group.invLeft ℤGroup {n} = refl t : _=V_ zAndZ (Ring.additiveGroup ℤRing) (nonneg 0 ,- (nonneg 0 ,- [])) (Group.inverse ℤGroup n ,- (nonneg 2 ,- [])) t = indep (BoolTrue ,- (BoolFalse ,- [])) r (Group.inverse ℤGroup n ,- (nonneg 2 ,- [])) s ohNo : nonneg 0 ≡ nonneg 2 ohNo with t ohNo | () oneLengthAlwaysInj : {a b : ℕ} → (a<n : a <N 1) → (b<n : b <N 1) → a ≡ b oneLengthAlwaysInj {zero} {zero} a<n b<n = refl oneLengthAlwaysInj {zero} {succ b} a<n (le zero ()) oneLengthAlwaysInj {zero} {succ b} a<n (le (succ x) ()) oneLengthAlwaysInj {succ a} {b} (le zero ()) b<n oneLengthAlwaysInj {succ a} {b} (le (succ x) ()) b<n noBasisExample : Independent (abGrpModule (ℤnAbGroup 5 (le 4 refl))) (λ (t : True) → record { x = 1 ; xLess = le 3 refl }) → False noBasisExample ind with ind (record {} ,- []) (λ a<n b<n _ → oneLengthAlwaysInj a<n b<n) (nonneg 5 ,- []) refl noBasisExample ind | ()
{ "alphanum_fraction": 0.6547850508, "avg_line_length": 62.5540540541, "ext": "agda", "hexsha": "a269544d622910f61ebad9f8cadeb67438df7b73", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Modules/Examples.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Modules/Examples.agda", "max_line_length": 727, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Modules/Examples.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 3334, "size": 9258 }
module Data.Map (Key : Set) where import Data.Bool import Data.Maybe open Data.Bool infix 40 _<_ _>_ postulate _<_ : Key -> Key -> Bool _>_ : Key -> Key -> Bool x > y = y < x private data Map' (a : Set) : Set where leaf : Map' a node : Key -> a -> Map' a -> Map' a -> Map' a Map : Set -> Set Map = Map' empty : {a : Set} -> Map a empty = leaf insert : {a : Set} -> Key -> a -> Map a -> Map a insert k v leaf = node k v leaf leaf insert k v (node k' v' l r) = | k < k' => node k' v' (insert k v l) r | k > k' => node k' v' l (insert k v r) | otherwise node k' v l r open Data.Maybe lookup : {a : Set} -> Key -> Map a -> Maybe a lookup k leaf = nothing lookup k (node k' v l r) = | k < k' => lookup k l | k > k' => lookup k r | otherwise just v
{ "alphanum_fraction": 0.5367088608, "avg_line_length": 17.1739130435, "ext": "agda", "hexsha": "019d26ec86dbe74f1da1b29b06e4e6b3af654f11", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Map.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Map.agda", "max_line_length": 49, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Map.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 290, "size": 790 }
{-# OPTIONS --show-irrelevant #-} open import Agda.Builtin.Bool open import Agda.Builtin.Equality postulate A : Set f : .(Bool → A) → Bool → A mutual X : .A → Bool → A X = _ test : (x : Bool → A) → X (x true) ≡ f x test x = refl
{ "alphanum_fraction": 0.5755102041, "avg_line_length": 15.3125, "ext": "agda", "hexsha": "ff4b73f1d8b00110c9d741a45ba9052a41f3eafe", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue4134.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue4134.agda", "max_line_length": 42, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue4134.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 91, "size": 245 }
{-# OPTIONS --without-K --safe #-} module Experiment.Transitive where open import Level open import Relation.Binary open import Relation.Binary.Construct.Closure.Transitive open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) insert-permutation : ∀ x xs → insert x xs ↭ x ∷ xs insert-pres-Sorted : ∀ x {xs} → Sorted xs → Sorted (insert x xs) sort-Sorted : ∀ xs → Sorted (sort xs) sort-permutation : ∀ xs → sort xs ↭ xs private variable a b r : Level A B : Set a R S : Rel A r fold : Transitive R → A [ R ]⁺ B → R A B fold R-trans [ x∼y ] = x∼y fold R-trans (x ∼⁺⟨ x₁ ⟩ x₂) = R-trans (fold R-trans x₁) (fold R-trans x₂) reverse : Symmetric R → A [ R ]⁺ B → B [ R ]⁺ A reverse R-sym [ x∼y ] = [ R-sym x∼y ] reverse R-sym (x ∼⁺⟨ x₁ ⟩ x₂) = _ ∼⁺⟨ reverse R-sym x₂ ⟩ reverse R-sym x₁ fold-reverse : (R-trans : Transitive R) (R-sym : Symmetric R) (xs : A [ R ]⁺ B) → (∀ {a b c} (x : R b c) (y : R a b) → R-trans (R-sym x) (R-sym y) ≡ R-sym (R-trans y x)) → fold R-trans (reverse R-sym xs) ≡ R-sym (fold R-trans xs) fold-reverse R-trans R-sym [ x∼y ] homo = ≡.refl fold-reverse R-trans R-sym (x ∼⁺⟨ xs₁ ⟩ xs₂) homo = begin R-trans (fold R-trans (reverse R-sym xs₂)) (fold R-trans (reverse R-sym xs₁)) ≡⟨ ≡.cong₂ R-trans (fold-reverse R-trans R-sym xs₂ homo) (fold-reverse R-trans R-sym xs₁ homo) ⟩ R-trans (R-sym (fold R-trans xs₂)) (R-sym (fold R-trans xs₁)) ≡⟨ homo (fold R-trans xs₂) (fold R-trans xs₁) ⟩ R-sym (R-trans (fold R-trans xs₁) (fold R-trans xs₂)) ∎ where open ≡.≡-Reasoning -- map : -- Star⇔ReflexiveTransitive : Star R x y ↔ Reflexive (Transitive R x y) -- map-reverse : (RS : R ⊆ S) (R-sym : Symmetric R) (S-sym : Symmetric S) xs → map RS (reverse R-sym xs) ≡ reverse S-sym (map RS xs) -- map-reverse R-sym xs = ? -- ∘ᵢ-tc (reverse f⁺) ∘ᵢ ∘ᵢ-tc f⁺ ≃ ≅.refl
{ "alphanum_fraction": 0.5910761155, "avg_line_length": 38.1, "ext": "agda", "hexsha": "d626c59ba3f506bb518ca19bbea5d14800c2d4d8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rei1024/agda-misc", "max_forks_repo_path": "Experiment/Transitive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rei1024/agda-misc", "max_issues_repo_path": "Experiment/Transitive.agda", "max_line_length": 132, "max_stars_count": 3, "max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rei1024/agda-misc", "max_stars_repo_path": "Experiment/Transitive.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z", "num_tokens": 739, "size": 1905 }
-- {-# OPTIONS -v tc.size.solve:60 #-} module Issue300 where open import Common.Size data Nat : Size → Set where zero : (i : Size) → Nat (↑ i) suc : (i : Size) → Nat i → Nat (↑ i) -- Size meta used in a different context than the one created in A : Set₁ A = (Id : (i : Size) → Nat _ → Set) (k : Size) (m : Nat (↑ k)) (p : Id k m) → (j : Size) (n : Nat j ) → Id j n -- should solve _ with ↑ i -- 1) Id,k,m |- ↑ 1 ≤ X 1 ==> ↑ 4 ≤ X 4 -- 2) Id,k,m,p,j,n |- 1 ≤ X 1 -- Unfixed by fix for #1914 (Andreas, 2016-04-08).
{ "alphanum_fraction": 0.5175600739, "avg_line_length": 23.5217391304, "ext": "agda", "hexsha": "64c9f8db7305c94c0dcc9dca09fad02fcd843c1d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue300.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue300.agda", "max_line_length": 64, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue300.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 210, "size": 541 }
module Everything where import Library import NfCBPV
{ "alphanum_fraction": 0.8518518519, "avg_line_length": 10.8, "ext": "agda", "hexsha": "cb947b5fb43e6d1d82997c81da03b7f62cc48860", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z", "max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "andreasabel/ipl", "max_forks_repo_path": "src-cbpv/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "andreasabel/ipl", "max_issues_repo_path": "src-cbpv/Everything.agda", "max_line_length": 23, "max_stars_count": 19, "max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "andreasabel/ipl", "max_stars_repo_path": "src-cbpv/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z", "num_tokens": 13, "size": 54 }
module Foreword where open import Relation.Binary --open Setoid ⦃ … ⦄ --open IsEquivalence ⦃ … ⦄ open import Level record HasEquivalence (A : Set) ℓ : Set (suc ℓ) where field _≈_ : Rel A ℓ ⦃ isEquivalence ⦄ : IsEquivalence _≈_ setoid : Setoid _ _ Setoid.Carrier setoid = A Setoid._≈_ setoid = _≈_ Setoid.isEquivalence setoid = isEquivalence open HasEquivalence ⦃ … ⦄ module TestEquivalence (A : Set) (B : Set) ⦃ _ : HasEquivalence A zero ⦄ ⦃ _ : HasEquivalence B zero ⦄ where testA : (x : A) → x ≈ x testA = {!!}
{ "alphanum_fraction": 0.6556169429, "avg_line_length": 20.8846153846, "ext": "agda", "hexsha": "cb4d744b482df06a13228608fedc24ae4b2e425e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/Foreword.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/Foreword.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/Foreword.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 213, "size": 543 }
-- Andreas, 2019-07-09, issue #3900 -- Regression introduced by the fix of #3434 -- {-# OPTIONS -v tc.inj:100 #-} data Bool : Set where true false : Bool abstract data Unit : Set where unit : Unit f : Unit f with true ... | true = unit ... | false = unit -- Error WAS: -- Not in Scope: unit -- Should succeed.
{ "alphanum_fraction": 0.6017964072, "avg_line_length": 14.5217391304, "ext": "agda", "hexsha": "1a995fbc70d395ed5ce529c4443746211d660c90", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue3900.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue3900.agda", "max_line_length": 44, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue3900.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 105, "size": 334 }
open import Oscar.Prelude open import Oscar.Class.IsPrecategory open import Oscar.Class.IsCategory open import Oscar.Class.Category open import Oscar.Class.IsFunctor open import Oscar.Class.Functor open import Oscar.Class.Reflexivity open import Oscar.Class.Transitivity open import Oscar.Class.Surjection open import Oscar.Class.Smap open import Oscar.Class.Transextensionality open import Oscar.Class.Transassociativity open import Oscar.Class.Transleftidentity open import Oscar.Class.Transrightidentity open import Oscar.Class.Surjidentity open import Oscar.Class module Oscar.Class.Kitten where productCat : ∀ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} → Category 𝔬₁ 𝔯₁ ℓ₁ → Category 𝔬₂ 𝔯₂ ℓ₂ → Category (𝔬₁ ∙̂ 𝔬₂) (𝔯₁ ∙̂ 𝔯₂) (ℓ₁ ∙̂ ℓ₂) Category.𝔒 (productCat c₁ c₂) = Category.𝔒 c₁ × Category.𝔒 c₂ Category._∼_ (productCat c₁ c₂) (x₁ , x₂) (y₁ , y₂) = Category._∼_ c₁ x₁ y₁ × Category._∼_ c₂ x₂ y₂ Category._∼̇_ (productCat c₁ c₂) {x₁ , x₂} {y₁ , y₂} (f₁ , g₁) (f₂ , g₂) = Category._∼̇_ c₁ f₁ f₂ × Category._∼̇_ c₂ g₁ g₂ Category.category-ε (productCat c₁ c₂) = (Category.category-ε c₁) , (Category.category-ε c₂) Category._↦_ (productCat c₁ c₂) (f₁ , f₂) (g₁ , g₂) = (Category._↦_ c₁ f₁ g₁) , (Category._↦_ c₂ f₂ g₂) Category.`IsCategory (productCat c₁ c₂) .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransextensionality .⋆ (x₁ , y₁) (x₂ , y₂) = transextensionality x₁ x₂ , transextensionality y₁ y₂ Category.`IsCategory (productCat c₁ c₂) .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransassociativity .⋆ f g h = transassociativity (f .π₀) (g .π₀) (h .π₀) , transassociativity (f .π₁) (g .π₁) (h .π₁) Category.`IsCategory (productCat c₁ c₂) .IsCategory.`𝓣ransleftidentity .⋆ = transleftidentity , transleftidentity Category.`IsCategory (productCat c₁ c₂) .IsCategory.`𝓣ransrightidentity = ∁ (transrightidentity , transrightidentity) record AFunctor {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} (source : Category 𝔬₁ 𝔯₁ ℓ₁) (target : Category 𝔬₂ 𝔯₂ ℓ₂) : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where constructor ∁ private module S = Category source private module T = Category target field F₀ : S.𝔒 → T.𝔒 F₁ : Smap.type S._∼_ T._∼_ F₀ F₀ isFunctor : IsFunctor S._∼_ S._∼̇_ S.category-ε S._↦_ T._∼_ T._∼̇_ T.category-ε T._↦_ F₁ record MonoidalCategory 𝔬 𝔯 ℓ : Ø ↑̂ (𝔬 ∙̂ 𝔯 ∙̂ ℓ) where constructor ∁ field thecat : Category 𝔬 𝔯 ℓ thefunc : AFunctor (productCat thecat thecat) thecat O : Ø 𝔬 O = Category.𝔒 thecat field 𝟏 : O _⟶_ : O → O → Ø 𝔯 _⟶_ = Category._∼_ thecat _⊗_ : O → O → O _⊗_ = λ x y → AFunctor.F₀ thefunc (x , y) _⨂_ : ∀ {w x y z} → w ⟶ x → y ⟶ z → (w ⊗ y) ⟶ (x ⊗ z) _⨂_ f g = AFunctor.F₁ thefunc (f , g) _↦_ : ∀ {x y z} (f : x ⟶ y) (g : y ⟶ z) → x ⟶ z _↦_ = Category._↦_ thecat i : ∀ {x} → x ⟶ x i = Category.category-ε thecat _≈̇_ = Category._∼̇_ thecat -- infixr 9 _⊗_ field associator : ∀ (x y z : O) → Σ (((x ⊗ y) ⊗ z) ⟶ (x ⊗ (y ⊗ z))) λ f → Σ ((x ⊗ (y ⊗ z)) ⟶ ((x ⊗ y) ⊗ z)) λ f⁻¹ → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i) left-unitor : ∀ (x : O) → Σ ((𝟏 ⊗ x) ⟶ x) λ f → Σ (x ⟶ (𝟏 ⊗ x)) λ f⁻¹ → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i) right-unitor : ∀ (x : O) → Σ ((x ⊗ 𝟏) ⟶ x) λ f → Σ (x ⟶ (x ⊗ 𝟏)) λ f⁻¹ → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i) assoc : ∀ (x y z : O) → ((x ⊗ y) ⊗ z) ⟶ (x ⊗ (y ⊗ z)) assoc x y z = π₀ (associator x y z) ru : ∀ x → (x ⊗ 𝟏) ⟶ x ru x = π₀ (right-unitor x) lu : ∀ x → (𝟏 ⊗ x) ⟶ x lu x = π₀ (left-unitor x) field triangle-identity : ∀ (x y : O) → (ru x ⨂ i) ≈̇ (assoc x 𝟏 y ↦ (i ⨂ lu y)) pentagon-identity : ∀ (w x y z : O) → (((assoc w x y ⨂ i) ↦ assoc w (x ⊗ y) z) ↦ (i ⨂ assoc x y z)) ≈̇ (assoc (w ⊗ x) y z ↦ assoc w x (y ⊗ z)) module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} (source : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁) (target : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂) where record LaxMonoidalFunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where module C = MonoidalCategory source module D = MonoidalCategory target field 𝓕 : AFunctor C.thecat D.thecat open AFunctor 𝓕 public field e : D.𝟏 D.⟶ F₀ C.𝟏 μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y) -- F A → F B → F (A × B) associativity : ∀ x y z → ((μ x y D.⨂ D.i) D.↦ (μ (x C.⊗ y) z D.↦ F₁ (C.assoc x y z))) D.≈̇ (D.assoc (F₀ x) (F₀ y) (F₀ z) D.↦ ((D.i D.⨂ μ y z) D.↦ μ x (y C.⊗ z))) left-unitality : ∀ x → (D.lu (F₀ x)) D.≈̇ ((e D.⨂ D.i) D.↦ (μ C.𝟏 x D.↦ F₁ (C.lu x))) right-unitality : ∀ x → (D.ru (F₀ x)) D.≈̇ ((D.i D.⨂ e) D.↦ (μ x C.𝟏 D.↦ F₁ (C.ru x))) module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} (source : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁) (target : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂) (let module C = MonoidalCategory source) (let module D = MonoidalCategory target) (𝓕 : AFunctor C.thecat D.thecat) (open AFunctor 𝓕) (e : D.𝟏 D.⟶ F₀ C.𝟏) (μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y)) where record IsLaxMonoidalFunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where field associativity : ∀ x y z → ((μ x y D.⨂ D.i) D.↦ (μ (x C.⊗ y) z D.↦ F₁ (C.assoc x y z))) D.≈̇ (D.assoc (F₀ x) (F₀ y) (F₀ z) D.↦ ((D.i D.⨂ μ y z) D.↦ μ x (y C.⊗ z))) left-unitality : ∀ x → (D.lu (F₀ x)) D.≈̇ ((e D.⨂ D.i) D.↦ (μ C.𝟏 x D.↦ F₁ (C.lu x))) right-unitality : ∀ x → (D.ru (F₀ x)) D.≈̇ ((D.i D.⨂ e) D.↦ (μ x C.𝟏 D.↦ F₁ (C.ru x))) record GenericApplicativeRaw {lc ld} {Oc : Ø lc} {Od : Ø ld} (F : Oc → Od) (1c : Oc) (1d : Od) (_⊗c_ : Oc → Oc → Oc) (_⊗d_ : Od → Od → Od) {ℓc} (_⟶c_ : Oc → Oc → Ø ℓc) {ℓd} (_⟶d_ : Od → Od → Ø ℓd) : Ø ℓd ∙̂ lc ∙̂ ℓc where field m : ∀ {x y} → x ⟶c y → F x ⟶d F y -- fmap e : 1d ⟶d F 1c -- pure μ : ∀ {x y} → (F x ⊗d F y) ⟶d F (x ⊗c y) -- apply -- _<*>_ : ∀ {x y : Oc} → ? → ? → {!!} -- F (x ⟶c y) → F x ⟶d F y -- _<*>_ f x = m ? (μ ) {- _<*>_ : ∀ {A B} → F (A → B) → F A → F B _<*>_ f x = sfmap (λ {(f , x) → f x}) (f <s> x) -} {- record ContainedGenericApplicativeRaw {lc ld} {Oc : Ø lc} {Od : Ø ld} (F : Oc → Od) (1c : Oc) (1d : Od) (_⊗c_ : Oc → Oc → Oc) (_⊗d_ : Od → Od → Od) {ℓd} (_⟶d_ : Od → Od → Ø ℓd) : Ø ℓd ∙̂ lc where field e : 1d ⟶d F 1c μ : ∀ {x y} → (F x ⊗d F y) ⟶d F (x ⊗c y) -} open import Oscar.Data.𝟙 open import Oscar.Data.Proposequality record Action {a b} {A : Set a} {B : Set b} {f g h} (F : A → B → Set f) (G : A → Set g) (H : B → Set h) : Ø a ∙̂ b ∙̂ f ∙̂ g ∙̂ h where field act : ∀ {x y} → F x y → G x → H y record SetApplyM {a b} (F : Set a → Set b) -- (𝟏ᴬ : Set a) (𝟏ᴮ : Set b) (_⊕_ : Set p → Set p → Set p) (_⟶_ : A → A → Set ℓ) : Ø ↑̂ a ∙̂ b where field sfmap : ∀ {A B} → (A → B) → F A → F B sunit : Lift {_} {a} 𝟙 → F (Lift 𝟙) _<s>_ : ∀ {A B} → F A → F B → F (A × B) _<*>_ : ∀ {A B} → F (A → B) → F A → F B _<*>_ f x = sfmap (λ {(f , x) → f x}) (f <s> x) _⨂_ : ∀ {A B C D : Ø a} → (A → B) → (C → D) → A × C → B × D _⨂_ f g ac = let (a , c) = ac in f a , g c assoc : ∀ {A B C : Ø a} → A × (B × C) → (A × B) × C assoc abc = let (a , (b , c)) = abc in (a , b) , c field law-nat : ∀ {A B C D} (f : A → B) (g : C → D) u v → sfmap (f ⨂ g) (u <s> v) ≡ (sfmap f u <s> sfmap g v) leftid : ∀ {B} (v : F B) → sfmap π₁ (sunit _ <s> v) ≡ v righttid : ∀ {A} (u : F A) → sfmap π₀ (u <s> sunit _) ≡ u associativity : ∀ {A B C} u v w → sfmap (assoc {A} {B} {C}) (u <s> (v <s> w)) ≡ ((u <s> v) <s> w) source-cat : MonoidalCategory _ _ _ source-cat .MonoidalCategory.thecat .Category.𝔒 = Ø a source-cat .MonoidalCategory.thecat .Category._∼_ = Function source-cat .MonoidalCategory.thecat .Category._∼̇_ = _≡̇_ source-cat .MonoidalCategory.thecat .Category.category-ε = ¡ source-cat .MonoidalCategory.thecat .Category._↦_ = flip _∘′_ source-cat .MonoidalCategory.thecat .Category.`IsCategory = {!!} source-cat .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B source-cat .MonoidalCategory.thefunc .AFunctor.F₁ = {!!} source-cat .MonoidalCategory.thefunc .AFunctor.isFunctor = {!!} source-cat .MonoidalCategory.𝟏 = Lift 𝟙 source-cat .MonoidalCategory.associator = {!!} source-cat .MonoidalCategory.left-unitor = {!!} source-cat .MonoidalCategory.right-unitor = {!!} source-cat .MonoidalCategory.triangle-identity = {!!} source-cat .MonoidalCategory.pentagon-identity = {!!} target-cat : MonoidalCategory _ _ _ target-cat .MonoidalCategory.thecat .Category.𝔒 = Ø b target-cat .MonoidalCategory.thecat .Category._∼_ = Function target-cat .MonoidalCategory.thecat .Category._∼̇_ = _≡̇_ target-cat .MonoidalCategory.thecat .Category.category-ε = ¡ target-cat .MonoidalCategory.thecat .Category._↦_ = flip _∘′_ target-cat .MonoidalCategory.thecat .Category.`IsCategory = {!!} target-cat .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B target-cat .MonoidalCategory.thefunc .AFunctor.F₁ = {!!} target-cat .MonoidalCategory.thefunc .AFunctor.isFunctor = {!!} target-cat .MonoidalCategory.𝟏 = Lift 𝟙 target-cat .MonoidalCategory.associator = {!!} target-cat .MonoidalCategory.left-unitor = {!!} target-cat .MonoidalCategory.right-unitor = {!!} target-cat .MonoidalCategory.triangle-identity = {!!} target-cat .MonoidalCategory.pentagon-identity = {!!} module C = MonoidalCategory source-cat module D = MonoidalCategory target-cat the-functor : AFunctor C.thecat D.thecat the-functor .AFunctor.F₀ = F the-functor .AFunctor.F₁ = sfmap the-functor .AFunctor.isFunctor = {!!} open AFunctor the-functor the-e : D.𝟏 D.⟶ F₀ C.𝟏 -- F (Lift 𝟙) the-e = {!!} the-μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y) -- F A → F B → F (A × B) the-μ A B (FA , FB) = FA <s> FB toSetApply : ∀ {a b} (F : Set a → Set b) (gar : GenericApplicativeRaw F (Lift 𝟙) (Lift 𝟙) (λ A B → A × B) (λ A B → A × B) Function Function) → SetApplyM F toSetApply F gar .SetApplyM.sfmap = GenericApplicativeRaw.m gar toSetApply F gar .SetApplyM.sunit _ = GenericApplicativeRaw.e gar ! toSetApply F gar .SetApplyM._<s>_ FA FB = GenericApplicativeRaw.μ gar (FA , FB) toSetApply F gar .SetApplyM.law-nat = {!!} toSetApply F gar .SetApplyM.leftid = {!!} toSetApply F gar .SetApplyM.righttid = {!!} toSetApply F gar .SetApplyM.associativity = {!!} module _ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} (C : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁) (D : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂) where record LaxMonoidalFunctorWithStrength : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where field laxMonoidalFunctor : LaxMonoidalFunctor C D open LaxMonoidalFunctor laxMonoidalFunctor {- field β : ∀ v w → (v D.⊗ F₀ w) D.⟶ F₀ (v C.⊗ w) commute-5 : ∀ u v w → (C.assoc u v (F₀ w) C.↦ ((C.i C.⨂ β v w) C.↦ β u (v C.⊗ w))) C.≈̇ (β (u C.⊗ v) w C.↦ F₁ (C.assoc u v w)) commute-3 : ∀ v → C.lu (F₀ v) C.≈̇ (β C.𝟏 v C.↦ F₁ (C.lu v)) -- strength : TensorialStrength C (LaxMonoidalFunctor.𝓕 laxMonoidalEndofunctor) -} module _ {𝔬 𝔯 ℓ} (V : MonoidalCategory 𝔬 𝔯 ℓ) (let C = MonoidalCategory.thecat V) (F : AFunctor C C) where open MonoidalCategory V open AFunctor F record TensorialStrength : Ø 𝔬 ∙̂ 𝔯 ∙̂ ℓ where field β : ∀ v w → (v ⊗ F₀ w) ⟶ F₀ (v ⊗ w) commute-5 : ∀ u v w → (assoc u v (F₀ w) ↦ ((i ⨂ β v w) ↦ β u (v ⊗ w))) ≈̇ (β (u ⊗ v) w ↦ F₁ (assoc u v w)) commute-3 : ∀ v → lu (F₀ v) ≈̇ (β 𝟏 v ↦ F₁ (lu v)) module _ {𝔬 𝔯 ℓ} (C : MonoidalCategory 𝔬 𝔯 ℓ) where record LaxMonoidalEndofunctorWithStrength : Ø 𝔬 ∙̂ 𝔯 ∙̂ ℓ where field laxMonoidalEndofunctor : LaxMonoidalFunctor C C strength : TensorialStrength C (LaxMonoidalFunctor.𝓕 laxMonoidalEndofunctor) {- want parameters : X : Set a Y : Set b X₀ : X F : X → Y _⨁_ : X → X → Set a LaxMonoidalFunctor.e = unit : F X₀ LaxMonoidalFunctor.μ = apply : ∀ {A B : X} → F A → F B → F (A ⨁ B) LaxMonoidalFunctor.𝓕.F₀ = F : X → Y -} record GenericApplyM {a ℓ} {A : Set a} (F : A → A) (𝟏 : A) (_⊕_ : A → A → A) (_⟶_ : A → A → Set ℓ) : Ø a ∙̂ ℓ where field gunit : 𝟏 ⟶ F 𝟏 gproduct : ∀ {x y : A} → (F x ⊕ F y) ⟶ F (x ⊕ y) open import Oscar.Data.𝟙 -- open import Oscar.Class.Kitten open import Oscar.Class.Category open import Oscar.Class.IsPrefunctor open import Oscar.Class.IsCategory open import Oscar.Class.IsPrecategory open import Oscar.Property.Category.Function open import Oscar.Class open import Oscar.Class.Fmap import Oscar.Class.Reflexivity.Function module _ {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) (fmapper : Fmap 𝓕) (fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄) (fapply : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅) where -- instance _ = fmapper fmap' = λ {A B} (f : A → B) → fapply (fpure f) mkProductMonoidalCategory : MonoidalCategory _ _ _ mkProductMonoidalCategory .MonoidalCategory.thecat .Category.𝔒 = Ø 𝔬₁ mkProductMonoidalCategory .MonoidalCategory.thecat .Category._∼_ = MFunction 𝓕 mkProductMonoidalCategory .MonoidalCategory.thecat .Category._∼̇_ = Proposextensequality mkProductMonoidalCategory .MonoidalCategory.thecat .Category.category-ε = ε mkProductMonoidalCategory .MonoidalCategory.thecat .Category._↦_ = (flip _∘′_) mkProductMonoidalCategory .MonoidalCategory.thecat .Category.`IsCategory = ? mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.F₁ (f , g) xy = fapply (fmap' _,_ (f (fmap' π₀ xy))) (g (fmap' π₁ xy)) mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjtranscommutativity = {!!} mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjextensionality = {!!} mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`𝒮urjidentity = {!!} mkProductMonoidalCategory .MonoidalCategory.𝟏 = {!!} mkProductMonoidalCategory .MonoidalCategory.associator = {!!} mkProductMonoidalCategory .MonoidalCategory.left-unitor = {!!} mkProductMonoidalCategory .MonoidalCategory.right-unitor = {!!} mkProductMonoidalCategory .MonoidalCategory.triangle-identity = {!!} mkProductMonoidalCategory .MonoidalCategory.pentagon-identity = {!!} record HApplicativeFunctor {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) : Ø (↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂)) where constructor ∁ field fmapper : Fmap 𝓕 fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄 fapply : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅 field isStrongLaxMonoidalEndofunctor : LaxMonoidalEndofunctorWithStrength (mkProductMonoidalCategory 𝓕 fmapper fpure fapply) module LMF = LaxMonoidalFunctor (LaxMonoidalEndofunctorWithStrength.laxMonoidalEndofunctor isStrongLaxMonoidalEndofunctor) derive-fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄 derive-fpure = {!LMF!} where {- ⦃ isFunctor ⦄ : IsFunctor {𝔒₁ = Ø 𝔬₁} (λ A B → A × 𝓕 B) {!(λ { {A} {B} (x₁ , f₁) (x₂ , f₂) → {!(x₁ ≡ x₂) × !}})!} (λ {A} → {!!} , {!!}) {!!} {𝔒₂ = Ø 𝔬₁} {!!} {!!} {!!} {!!} {!!} -} record MonoidalFunctor {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) : Ø (↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂)) where constructor ∁ field ⦃ isFmap ⦄ : Fmap 𝓕 unit : 𝓕 (Lift 𝟙) mappend : ∀ {𝔄 𝔅} → 𝓕 𝔄 → 𝓕 𝔅 → 𝓕 (𝔄 × 𝔅) {- ⦃ isFunctor ⦄ : IsFunctor Function⟦ 𝔬₁ ⟧ Proposextensequality ε (flip _∘′_) (MFunction 𝓕) Proposextensequality ε (flip _∘′_) {!!} -} pure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄 pure x = fmap (x ∞) unit infixl 4 _<*>_ _<*>_ : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅 f <*> x = fmap (λ {(f , x) → f x}) (mappend f x) app-identity : ∀ {𝔄} (v : 𝓕 𝔄) → (pure ¡[ 𝔄 ] <*> v) ≡ v app-identity v = {!!} open MonoidalFunctor ⦃ … ⦄ public using (unit; mappend) -- record ApplicativeFunctor where module Purity {𝔵₁ 𝔵₂ 𝔯} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (F : 𝔛₁ → 𝔛₂) (x₁ : 𝔛₁) (x₂ : 𝔛₂) (_⟶_ : 𝔛₂ → 𝔛₂ → Ø 𝔯) = ℭLASS (F , x₁ , x₂ , _⟶_) (x₂ ⟶ F x₁) module Applicativity {𝔵₁ 𝔵₂ 𝔯} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (F : 𝔛₁ → 𝔛₂) (_⊗₁_ : 𝔛₁ → 𝔛₁ → 𝔛₁) (_⊗₂_ : 𝔛₂ → 𝔛₂ → 𝔛₂) (_⟶_ : 𝔛₂ → 𝔛₂ → Ø 𝔯) = ℭLASS (F , _⊗₁_ , _⊗₂_ , _⟶_) (∀ x y → (F x ⊗₂ F y) ⟶ F (x ⊗₁ y)) -- FunctionalMonoidalCategory AFunctorFunction²Function : ∀ {𝔬₁} → AFunctor (productCat (CategoryFunction {𝔬₁}) (CategoryFunction {𝔬₁})) (CategoryFunction {𝔬₁}) AFunctorFunction²Function .AFunctor.F₀ = uncurry _×_ AFunctorFunction²Function .AFunctor.F₁ (f₁ , f₂) (x₁ , x₂) = f₁ x₁ , f₂ x₂ AFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjtranscommutativity = {!!} AFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjextensionality = {!!} AFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`𝒮urjidentity = {!!} record LMF {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) ⦃ _ : Fmap 𝓕 ⦄ : Ø ↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂) where constructor ∁ field lmf-pure : Purity.type 𝓕 (Lift 𝟙) (Lift 𝟙) Function lmf-apply : Applicativity.type 𝓕 _×_ _×_ Function lmf-happly : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅 lmf-happly f x = fmap (λ {(f , x) → f x}) (lmf-apply _ _ (f , x)) field ⦃ islmf ⦄ : IsLaxMonoidalFunctor (∁ CategoryFunction (∁ (uncurry _×_) {!!} {!!}) (Lift 𝟙) {!!} {!!} {!!} {!!} {!!}) (∁ CategoryFunction (∁ (uncurry _×_) {!!} {!!}) ((Lift 𝟙)) {!!} {!!} {!!} {!!} {!!}) (record { F₀ = 𝓕 ; F₁ = fmap ; isFunctor = ∁ ⦃ {!!} ⦄ ⦃ ! ⦄ ⦃ ! ⦄ ⦃ {!!} ⦄ }) lmf-pure lmf-apply
{ "alphanum_fraction": 0.5812550282, "avg_line_length": 41.3349168646, "ext": "agda", "hexsha": "a8857bebe8f598ad2742efb02f58f62891121bff", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_line_length": 302, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7918, "size": 17402 }
open import Common.Prelude renaming (Nat to ℕ) open import Common.Reflect module StrangeRecursiveUnquote where `ℕ : Term `ℕ = def (quote ℕ) [] -- the term f n is stuck and so we cannot unquote (as expected) f : ℕ → Term f zero = `ℕ f (suc n) = unquote (f n)
{ "alphanum_fraction": 0.6856060606, "avg_line_length": 20.3076923077, "ext": "agda", "hexsha": "7d8a4e0118486a09af246a574907c519ba7a5728", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/StrangeRecursiveUnquote.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/StrangeRecursiveUnquote.agda", "max_line_length": 63, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/StrangeRecursiveUnquote.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 84, "size": 264 }
open import Agda.Builtin.Nat open import Agda.Builtin.Equality record R : Set where field r1 r2 : Nat test : (x : R) → R.r1 x ≡ 0 → Nat test x refl = 0
{ "alphanum_fraction": 0.6419753086, "avg_line_length": 13.5, "ext": "agda", "hexsha": "97d69cf4ac80283cb3e3a057ad523e195ea7b280", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/PartiallyInstantiatedVariable.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/PartiallyInstantiatedVariable.agda", "max_line_length": 33, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/PartiallyInstantiatedVariable.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 62, "size": 162 }
------------------------------------------------------------------------ -- Syntax of pure type systems (PTS) ------------------------------------------------------------------------ module Pts.Syntax where open import Data.Fin using (Fin) open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Fin.Substitution.ExtraLemmas open import Data.Fin.Substitution.Typed open import Data.Star using (Star; ε; _◅_) open import Data.Nat using (ℕ; suc; _+_) open import Data.Vec using (lookup) open import Relation.Binary.PropositionalEquality as PropEq open PropEq.≡-Reasoning -- All submodules are parametrized by a given set of sorts. module _ (Sort : Set) where ---------------------------------------------------------------------- -- Abstract syntax of terms module Syntax where infixl 9 _·_ -- Untyped terms with up to n free variables. data Term (n : ℕ) : Set where var : (x : Fin n) → Term n -- variable sort : (s : Sort) → Term n -- sort Π : (a : Term n) (b : Term (1 + n)) → Term n -- dependent product ƛ : (a : Term n) (b : Term (1 + n)) → Term n -- abstraction _·_ : (a b : Term n) → Term n -- application open Syntax ---------------------------------------------------------------------- -- Substitutions in terms -- Application of generic substitutions to terms module SubstApp {T} (l : Lift T Term) where open Lift l infixl 8 _/_ -- Apply a substitution to a term. _/_ : ∀ {m n} → Term m → Sub T m n → Term n var x / σ = lift (lookup x σ) sort s / σ = sort s Π a b / σ = Π (a / σ) (b / σ ↑) ƛ a b / σ = ƛ (a / σ) (b / σ ↑) a · b / σ = (a / σ) · (b / σ) -- Some helper lemmas about applying sequences of substitutions. -- To be used in PathSubstLemmas. open Application (record { _/_ = _/_ }) hiding (_/_) -- Sorts are invariant under substitution. sort-/✶-↑✶ : ∀ k {m n s} (σs : Subs T m n) → sort s /✶ σs ↑✶ k ≡ sort s sort-/✶-↑✶ k ε = refl sort-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (sort-/✶-↑✶ k σs) refl -- Substitutions in dependent product types are compositional. Π-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) → (Π a b) /✶ σs ↑✶ k ≡ Π (a /✶ σs ↑✶ k) (b /✶ σs ↑✶ suc k) Π-/✶-↑✶ k ε = refl Π-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Π-/✶-↑✶ k σs) refl -- Substitutions in abstractions are compositional. ƛ-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) → (ƛ a b) /✶ σs ↑✶ k ≡ ƛ (a /✶ σs ↑✶ k) (b /✶ σs ↑✶ suc k) ƛ-/✶-↑✶ k ε = refl ƛ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (ƛ-/✶-↑✶ k σs) refl -- Substitutions in applications are compositional. ·-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) → (a · b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) · (b /✶ σs ↑✶ k) ·-/✶-↑✶ k ε = refl ·-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (·-/✶-↑✶ k σs) refl -- Substitutions in terms and associated lemmas. module Substitution where -- Term substitutions. termSubst : TermSubst Term termSubst = record { var = var; app = SubstApp._/_ } -- Lemmas relating application of sequences of generic substitutions -- lifted to any number of additional variables. -- -- Using these generic lemmas, we can instantiate the record -- Data.Fin.Substitution.Lemmas.TermLemmas below, which gives access -- to a number of useful (derived) lemmas about path substitutions. module Lemmas {T₁ T₂} {lift₁ : Lift T₁ Term} {lift₂ : Lift T₂ Term} where open SubstApp open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_) open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_) open Application (record { _/_ = SubstApp._/_ lift₁ }) using () renaming (_/✶_ to _/✶₁_) open Application (record { _/_ = SubstApp._/_ lift₂ }) using () renaming (_/✶_ to _/✶₂_) -- Sequences of (lifted) T₁ and T₂-substitutions are equivalent -- when applied to terms if they are equivalent when applied to -- variables. /✶-↑✶ : ∀ {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 (sort s) = begin sort s /✶₁ σs₁ ↑✶₁ k ≡⟨ sort-/✶-↑✶ _ k σs₁ ⟩ sort s ≡⟨ sym (sort-/✶-↑✶ _ k σs₂) ⟩ sort s /✶₂ σs₂ ↑✶₂ k ∎ /✶-↑✶ σs₁ σs₂ hyp k (Π a b) = begin (Π a b) /✶₁ σs₁ ↑✶₁ k ≡⟨ Π-/✶-↑✶ _ k σs₁ ⟩ Π (a /✶₁ σs₁ ↑✶₁ k) (b /✶₁ σs₁ ↑✶₁ suc k) ≡⟨ cong₂ Π (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp (suc k) b) ⟩ Π (a /✶₂ σs₂ ↑✶₂ k) (b /✶₂ σs₂ ↑✶₂ suc k) ≡⟨ sym (Π-/✶-↑✶ _ k σs₂) ⟩ (Π a b) /✶₂ σs₂ ↑✶₂ k ∎ /✶-↑✶ σs₁ σs₂ hyp k (ƛ a b) = begin (ƛ a b) /✶₁ σs₁ ↑✶₁ k ≡⟨ ƛ-/✶-↑✶ _ k σs₁ ⟩ ƛ (a /✶₁ σs₁ ↑✶₁ k) (b /✶₁ σs₁ ↑✶₁ suc k) ≡⟨ cong₂ ƛ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp (suc k) b) ⟩ ƛ (a /✶₂ σs₂ ↑✶₂ k) (b /✶₂ σs₂ ↑✶₂ suc k) ≡⟨ sym (ƛ-/✶-↑✶ _ k σs₂) ⟩ (ƛ a b) /✶₂ σs₂ ↑✶₂ k ∎ /✶-↑✶ σs₁ σs₂ hyp k (a · b) = begin (a · b) /✶₁ σs₁ ↑✶₁ k ≡⟨ ·-/✶-↑✶ _ k σs₁ ⟩ (a /✶₁ σs₁ ↑✶₁ k) · (b /✶₁ σs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩ (a /✶₂ σs₂ ↑✶₂ k) · (b /✶₂ σs₂ ↑✶₂ k) ≡⟨ sym (·-/✶-↑✶ _ k σs₂) ⟩ (a · b) /✶₂ σs₂ ↑✶₂ k ∎ -- By instantiating TermLemmas, we get access to a number of useful -- (derived) lemmas about path substitutions. termLemmas : TermLemmas Term termLemmas = record { termSubst = termSubst ; app-var = refl ; /✶-↑✶ = Lemmas./✶-↑✶ } open TermLemmas termLemmas public hiding (var; termSubst) -- By instantiating TermLikeLemmas, we get access to a number of -- useful (derived) lemmas about variable substitutions (renamings). private termLikeLemmas : TermLikeLemmas Term Term termLikeLemmas = record { app = SubstApp._/_ ; termLemmas = termLemmas ; /✶-↑✶₁ = Lemmas./✶-↑✶ ; /✶-↑✶₂ = Lemmas./✶-↑✶ } open TermLikeLemmas termLikeLemmas public using (varLiftAppLemmas; varLiftSubLemmas; _/Var_) infix 10 _[_] -- Shorthand for single-variable term substitutions. _[_] : ∀ {n} → Term (1 + n) → Term n → Term n a [ b ] = a / sub b ---------------------------------------------------------------------- -- Concrete typing contexts over terms. module Ctx where open Substitution using (weaken) open Context Term public hiding (module Ctx) weakenOps : WeakenOps weakenOps = record { weaken = weaken } open WeakenOps weakenOps public hiding (weaken)
{ "alphanum_fraction": 0.4917582418, "avg_line_length": 36.7872340426, "ext": "agda", "hexsha": "fa0b366b9cbdd06edc2ce15633030c24e80569c8", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z", "max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z", "max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/pts-agda", "max_forks_repo_path": "src/Pts/Syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z", "max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "asr/pts-agda", "max_issues_repo_path": "src/Pts/Syntax.agda", "max_line_length": 77, "max_stars_count": 21, "max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/pts-agda", "max_stars_repo_path": "src/Pts/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z", "max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z", "num_tokens": 2694, "size": 6916 }
module Structure.Setoid.Uniqueness where import Lvl open import Functional open import Logic open import Logic.Propositional open import Logic.Predicate open import Structure.Setoid open import Type private variable ℓₗ ℓₗ₁ ℓₗ₂ : Lvl.Level module _ {ℓ₁}{ℓ₂} where -- Definition of uniqueness of a property. -- This means that there is at most one element that satisfies this property. -- This is similiar to "Injective" for functions. Unique : ∀{Obj : Type{ℓ₁}}{ℓₗ} → ⦃ equiv : Equiv{ℓₗ}(Obj) ⦄ → (Pred : Obj → Stmt{ℓ₂}) → Stmt Unique {Obj = Obj} Pred = ∀{x y : Obj} → Pred(x) → Pred(y) → (x ≡ y) -- Definition of existence of an unique element satisfying a property. -- This means that there is one and only one element that satisfies this property. ∃! : ∀{Obj : Type{ℓ₁}}{ℓₗ} → ⦃ equiv : Equiv{ℓₗ}(Obj) ⦄ → (Pred : Obj → Stmt{ℓ₂}) → Stmt ∃! {Obj} Pred = ∃(Pred) ∧ Unique(Pred) [∃!]-intro : ∀{T} → ⦃ _ : Equiv{ℓₗ}(T) ⦄ → ∀{property} → ∃(property) → Unique{T}(property) → ∃!(property) [∃!]-intro = [∧]-intro [∃!]-existence : ∀{Obj} → ⦃ _ : Equiv{ℓₗ}(Obj) ⦄ → ∀{Pred} → ∃!{Obj}(Pred) → ∃(Pred) [∃!]-existence = [∧]-elimₗ [∃!]-uniqueness : ∀{Obj} → ⦃ _ : Equiv{ℓₗ}(Obj) ⦄ → ∀{Pred} → ∃!{Obj}(Pred) → Unique(Pred) [∃!]-uniqueness = [∧]-elimᵣ [∃!]-witness : ∀{Obj} → ⦃ _ : Equiv{ℓₗ}(Obj) ⦄ → ∀{Pred} → ∃!{Obj}(Pred) → Obj [∃!]-witness e = [∃]-witness ([∃!]-existence e) [∃!]-proof : ∀{Obj} → ⦃ _ : Equiv{ℓₗ}(Obj) ⦄ → ∀{Pred} → (e : ∃!{Obj}(Pred)) → Pred([∃!]-witness(e)) [∃!]-proof e = [∃]-proof ([∃!]-existence e) [∃!]-existence-eq : ∀{T} → ⦃ _ : Equiv{ℓₗ}(T) ⦄ → ∀{P} → (e : ∃!(P)) → ∀{x} → P(x) → (x ≡ [∃!]-witness e) [∃!]-existence-eq e {x} px = [∃!]-uniqueness e {x} {[∃!]-witness e} px ([∃!]-proof e) [∃!]-existence-eq-any : ∀{T} → ⦃ _ : Equiv{ℓₗ}(T) ⦄ → ∀{P} → (e : ∃!(P)) → ∀{x} → P(x) → ([∃!]-witness e ≡ x) [∃!]-existence-eq-any e {x} px = [∃!]-uniqueness e {[∃!]-witness e} {x} ([∃!]-proof e) px -- TODO: [∃!]-equivalence {T} property = ∃(a ↦ ∃{property(a)}(pa ↦ pa ∧ Uniqueness{T}(property){a}(pa)))
{ "alphanum_fraction": 0.5504100338, "avg_line_length": 44.1063829787, "ext": "agda", "hexsha": "6adb16b7a2b6614c7d0abdd30760a22736a25f01", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Structure/Setoid/Uniqueness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Structure/Setoid/Uniqueness.agda", "max_line_length": 111, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Structure/Setoid/Uniqueness.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 943, "size": 2073 }
------------------------------------------------------------------------ -- Some χ program combinators ------------------------------------------------------------------------ module Combinators where open import Equality.Propositional open import Prelude hiding (id; if_then_else_; not; const) open import Tactic.By.Propositional open import Equality.Decision-procedures equality-with-J import Nat equality-with-J as Nat -- To simplify the development, let's work with actual natural numbers -- as variables and constants (see -- Atom.one-can-restrict-attention-to-χ-ℕ-atoms). open import Atom open import Chi χ-ℕ-atoms open import Coding χ-ℕ-atoms open import Constants χ-ℕ-atoms open import Deterministic χ-ℕ-atoms open import Free-variables χ-ℕ-atoms open import Reasoning χ-ℕ-atoms open import Substitution χ-ℕ-atoms open import Termination χ-ℕ-atoms open import Values χ-ℕ-atoms open χ-atoms χ-ℕ-atoms import Coding.Instances.Nat ------------------------------------------------------------------------ -- A non-terminating expression loop : Exp loop = rec v-x (var v-x) loop-closed : Closed loop loop-closed = Closed′-closed-under-rec $ Closed′-closed-under-var (inj₁ refl) ¬loop⇓ : ¬ Terminates loop ¬loop⇓ (_ , p) = lemma p where lemma : ∀ {w} → ¬ loop ⇓ w lemma (rec p) with v-x V.≟ v-x ... | no x≢x = x≢x refl ... | yes _ = lemma p ------------------------------------------------------------------------ -- The identity function id : Exp id = lambda v-x (var v-x) id-closed : Closed id id-closed = from-⊎ (closed? id) id-correct : ∀ {e v} → e ⇓ v → apply id e ⇓ v id-correct {e = e} {v = v} e⇓v = apply id e ⟶⟨ apply lambda e⇓v ⟩ var v-x [ v-x ← v ] ≡⟨ var-step-≡ (refl {x = v-x}) ⟩⟶ v ■⟨ ⇓-Value e⇓v ⟩ ------------------------------------------------------------------------ -- Natural numbers -- Equality of natural numbers. private equal-ℕ′ : Exp equal-ℕ′ = rec v-equal (lambda v-m (lambda v-n (case (var v-m) branches))) module Equal-ℕ where zero-branches = branch c-zero [] (const c-true []) ∷ branch c-suc (v-n ∷ []) (const c-false []) ∷ [] suc-branches = branch c-zero [] (const c-false []) ∷ branch c-suc (v-n ∷ []) ( apply (apply (var v-equal) (var v-m)) (var v-n)) ∷ [] branches = branch c-zero [] (case (var v-n) zero-branches) ∷ branch c-suc (v-m ∷ []) (case (var v-n) suc-branches) ∷ [] equal-ℕ : Exp → Exp → Exp equal-ℕ e₁ e₂ = apply (apply equal-ℕ′ e₁) e₂ equal-ℕ-closed : ∀ {xs e₁ e₂} → Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (equal-ℕ e₁ e₂) equal-ℕ-closed {xs} cl-e₁ cl-e₂ = Closed′-closed-under-apply (Closed′-closed-under-apply (from-⊎ (closed′? equal-ℕ′ xs)) cl-e₁) cl-e₂ equal-ℕ-correct : ∀ m n → equal-ℕ ⌜ m ⌝ ⌜ n ⌝ ⇓ ⌜ Prelude.if m Nat.≟ n then true else false ⌝ equal-ℕ-correct m n = equal-ℕ ⌜ m ⌝ ⌜ n ⌝ ⟶⟨⟩ apply (apply equal-ℕ′ ⌜ m ⌝) ⌜ n ⌝ ⟶⟨ apply (apply (rec lambda) (rep⇓rep m) lambda) (rep⇓rep n) ⟩ case ⟨ ⌜ m ⌝ [ v-n ← ⌜ n ⌝ ] ⟩ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ n ⌝ ]B⋆) ≡⟨ ⟨by⟩ (subst-rep m) ⟩⟶ case ⌜ m ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ n ⌝ ]B⋆) ⇓⟨ lemma m n ⟩■ ⌜ Prelude.if m Nat.≟ n then true else false ⌝ where open Equal-ℕ lemma : ∀ m n → case ⌜ m ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ n ⌝ ]B⋆) ⇓ ⌜ Prelude.if m Nat.≟ n then true else false ⌝ lemma zero zero = case ⌜ zero ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ zero ⌝ ]B⋆ [ v-n ← ⌜ zero ⌝ ]B⋆) ⟶⟨ _⇓_.case (rep⇓rep zero) here [] ⟩ case ⌜ zero ⌝ zero-branches ⇓⟨ case (rep⇓rep zero) here [] (rep⇓rep (true ⦂ Bool)) ⟩■ ⌜ true ⦂ Bool ⌝ lemma zero (suc n) = case ⌜ zero ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ zero ⌝ ]B⋆ [ v-n ← ⌜ suc n ⌝ ]B⋆) ⟶⟨ case (rep⇓rep zero) here [] ⟩ case ⌜ suc n ⌝ zero-branches ⇓⟨ case (rep⇓rep (suc n)) (there (λ ()) here) (∷ []) (rep⇓rep (false ⦂ Bool)) ⟩■ ⌜ false ⦂ Bool ⌝ lemma (suc m) zero = case ⌜ suc m ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ suc m ⌝ ]B⋆ [ v-n ← ⌜ zero ⌝ ]B⋆) ⟶⟨ case (rep⇓rep (suc m)) (there (λ ()) here) (∷ []) ⟩ case ⌜ zero ⌝ (suc-branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ zero ⌝ ]B⋆) ⇓⟨ case (rep⇓rep zero) here [] (rep⇓rep (false ⦂ Bool)) ⟩■ ⌜ false ⦂ Bool ⌝ lemma (suc m) (suc n) = case ⌜ suc m ⌝ (branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ suc m ⌝ ]B⋆ [ v-n ← ⌜ suc n ⌝ ]B⋆) ⟶⟨ case (rep⇓rep (suc m)) (there (λ ()) here) (∷ []) ⟩ case ⟨ ⌜ suc n ⌝ [ v-m ← ⌜ m ⌝ ] ⟩ (suc-branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ suc n ⌝ ]B⋆) ≡⟨ ⟨by⟩ (subst-rep (suc n)) ⟩⟶ case ⌜ suc n ⌝ (suc-branches [ v-equal ← equal-ℕ′ ]B⋆ [ v-m ← ⌜ m ⌝ ]B⋆ [ v-n ← ⌜ suc n ⌝ ]B⋆) ⟶⟨ case (rep⇓rep (suc n)) (there (λ ()) here) (∷ []) ⟩ apply (apply equal-ℕ′ ⟨ ⌜ m ⌝ [ v-n ← ⌜ n ⌝ ] ⟩) ⌜ n ⌝ ≡⟨ ⟨by⟩ (subst-rep m) ⟩⟶ apply (apply equal-ℕ′ ⌜ m ⌝) ⌜ n ⌝ ⟶⟨⟩ equal-ℕ ⌜ m ⌝ ⌜ n ⌝ ⇓⟨ equal-ℕ-correct m n ⟩ ⌜ Prelude.if m Nat.≟ n then true else false ⌝ ≡⟨ by lem ⟩⟶ ⌜ Prelude.if suc m Nat.≟ suc n then true else false ⌝ ■⟨ rep-value (Prelude.if suc m Nat.≟ suc n then true else false) ⟩ where lem : Prelude.if m Nat.≟ n then true else false ≡ Prelude.if suc m Nat.≟ suc n then true else false lem with m Nat.≟ n ... | yes _ = refl ... | no _ = refl private equal-ℕ-correct′ : ∀ m n {v} → equal-ℕ ⌜ m ⌝ ⌜ n ⌝ ⇓ v → v ≡ ⌜ Prelude.if m Nat.≟ n then true else false ⌝ equal-ℕ-correct′ m n p = ⇓-deterministic p (equal-ℕ-correct m n) -- Membership of a list of natural numbers. private member′ : Exp member′ = lambda v-x body module Member where cons-branches = branch c-true [] (const c-true []) ∷ branch c-false [] (apply (var v-member) (var v-xs)) ∷ [] branches = branch c-nil [] (const c-false []) ∷ branch c-cons (v-y ∷ v-xs ∷ []) ( case (equal-ℕ (var v-x) (var v-y)) cons-branches) ∷ [] body = rec v-member (lambda v-xs (case (var v-xs) branches)) body-closed : ∀ {xs} → Closed′ (v-x ∷ xs) body body-closed {xs} = from-⊎ (closed′? body (v-x ∷ xs)) member : Exp → Exp → Exp member m ns = apply (apply member′ m) ns member-closed : ∀ {xs m ns} → Closed′ xs m → Closed′ xs ns → Closed′ xs (member m ns) member-closed cl-m cl-ns = Closed′-closed-under-apply (Closed′-closed-under-apply (Closed′-closed-under-lambda Member.body-closed) cl-m) cl-ns member-correct : ∀ m ns → member ⌜ m ⌝ ⌜ ns ⌝ ⇓ ⌜ Prelude.if V.member m ns then true else false ⌝ member-correct m ns = member ⌜ m ⌝ ⌜ ns ⌝ ⟶⟨⟩ apply (apply member′ ⌜ m ⌝) ⌜ ns ⌝ ⟶⟨ apply (apply lambda (rep⇓rep m) (rec lambda)) (rep⇓rep ns) ⟩ case ⌜ ns ⌝ (branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆) ⇓⟨ lemma ns ⟩■ ⌜ Prelude.if V.member m ns then true else false ⌝ where open Member lemma : ∀ ns → case ⌜ ns ⌝ (branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆) ⇓ ⌜ Prelude.if V.member m ns then true else false ⌝ lemma [] = case ⌜ [] ⦂ List ℕ ⌝ (branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆) ⇓⟨ case (rep⇓rep ([] ⦂ List ℕ)) here [] (const []) ⟩■ ⌜ false ⦂ Bool ⌝ lemma (n ∷ ns) = case ⌜ n List.∷ ns ⌝ (branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆) ⟶⟨ case (rep⇓rep (n List.∷ ns)) (there (λ ()) here) (∷ ∷ []) ⟩ case (equal-ℕ ⟨ ⌜ m ⌝ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ] [ v-xs ← ⌜ ns ⌝ ] [ v-y ← ⌜ n ⌝ ] ⟩ ⌜ n ⌝) (cons-branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆ [ v-y ← ⌜ n ⌝ ]B⋆) ≡⟨ ⟨by⟩ (substs-rep m ((v-y , ⌜ n ⌝) ∷ (v-xs , ⌜ ns ⌝) ∷ (v-member , body [ v-x ← ⌜ m ⌝ ]) ∷ [])) ⟩⟶ case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) (⟨ cons-branches [ v-x ← ⌜ m ⌝ ]B⋆ ⟩ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆ [ v-y ← ⌜ n ⌝ ]B⋆) ≡⟨ ⟨by⟩ (subst-∉-B⋆ _ _ ⌜ m ⌝ (from-⊎ (v-x ∈?-B⋆ cons-branches))) ⟩⟶ case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) ⟨ cons-branches [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆ [ v-y ← ⌜ n ⌝ ]B⋆ ⟩ ≡⟨ ⟨by⟩ (subst-∉-B⋆ _ _ _ λ { (._ , ._ , ._ , inj₁ refl , const _ () , _) ; (._ , ._ , ._ , inj₂ (inj₁ refl) , y∈FV[body[x←m]ns] , _) → Closed′-closed-under-apply (Closed′-closed-under-subst body-closed (rep-closed m)) (rep-closed ns) v-y (λ ()) y∈FV[body[x←m]ns] ; (_ , _ , _ , (inj₂ (inj₂ ())) , _) }) ⟩⟶ case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) (cons-branches [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆) ⇓⟨ lemma′ (m Nat.≟ n) (equal-ℕ-correct m n) ⟩■ ⌜ Prelude.if V.member m (n ∷ ns) then true else false ⌝ where lemma′ : (m≟n : Dec (m ≡ n)) → equal-ℕ ⌜ m ⌝ ⌜ n ⌝ ⇓ ⌜ Prelude.if m≟n then true else false ⌝ → case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) (cons-branches [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆) ⇓ ⌜ Prelude.if V.member m (n ∷ ns) then true else false ⌝ lemma′ (yes m≡n) hyp = case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) (cons-branches [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆) ⟶⟨ case hyp here [] ⟩ ⌜ true ⦂ Bool ⌝ ≡⟨ cong ⌜_⌝ lem ⟩⟶ ⌜ Prelude.if V.member m (n ∷ ns) then true else false ⌝ ■⟨ rep-value (Prelude.if V.member m (n ∷ ns) then true else false) ⟩ where lem : true ≡ Prelude.if V.member m (n ∷ ns) then true else false lem with m Nat.≟ n ... | yes _ = refl ... | no m≢n = ⊥-elim (m≢n m≡n) lemma′ (no m≢n) hyp = case (equal-ℕ ⌜ m ⌝ ⌜ n ⌝) (cons-branches [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆ [ v-xs ← ⌜ ns ⌝ ]B⋆) ⟶⟨ case hyp (there (λ ()) here) [] ⟩ apply ⟨ body [ v-x ← ⌜ m ⌝ ] [ v-xs ← ⌜ ns ⌝ ] ⟩ ⌜ ns ⌝ ≡⟨ ⟨by⟩ (subst-closed v-xs ⌜ ns ⌝ (Closed′-closed-under-subst body-closed (rep-closed m))) ⟩⟶ apply (body [ v-x ← ⌜ m ⌝ ]) ⌜ ns ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep ns) ⟩ case ⌜ ns ⌝ (branches [ v-x ← ⌜ m ⌝ ]B⋆ [ v-member ← body [ v-x ← ⌜ m ⌝ ] ]B⋆) ⇓⟨ lemma ns ⟩ ⌜ Prelude.if V.member m ns then true else false ⌝ ≡⟨ cong ⌜_⌝ lem ⟩⟶ ⌜ Prelude.if V.member m (n ∷ ns) then true else false ⌝ ■⟨ rep-value (Prelude.if V.member m (n ∷ ns) then true else false) ⟩ where lem : Prelude.if V.member m ns then true else false ≡ Prelude.if V.member m (n ∷ ns) then true else false lem with m Nat.≟ n ... | yes m≡n = ⊥-elim (m≢n m≡n) ... | no _ with V.member m ns ... | yes _ = refl ... | no _ = refl ------------------------------------------------------------------------ -- Booleans -- If-then-else. infix 5 if_then_else_ if_then_else_ : Exp → Exp → Exp → Exp if c then t else f = case c (branch c-true [] t ∷ branch c-false [] f ∷ []) if-then-else-closed : ∀ {xs c t f} → Closed′ xs c → Closed′ xs t → Closed′ xs f → Closed′ xs (if c then t else f) if-then-else-closed c-cl t-cl f-cl = Closed′-closed-under-case c-cl λ where (inj₁ refl) → t-cl (inj₂ (inj₁ refl)) → f-cl (inj₂ (inj₂ ())) if-then-else-correct : ∀ {A : Type} ⦃ cA : Rep A Consts ⦄ {e₁ e₂ e₃} (b₁ : Bool) (v₂ v₃ : A) → e₁ ⇓ ⌜ b₁ ⌝ → e₂ ⇓ ⌜ v₂ ⌝ → e₃ ⇓ ⌜ v₃ ⌝ → if e₁ then e₂ else e₃ ⇓ ⌜ Prelude.if b₁ then v₂ else v₃ ⌝ if-then-else-correct true _ _ e₁⇓ e₂⇓ e₃⇓ = case e₁⇓ here [] e₂⇓ if-then-else-correct false _ _ e₁⇓ e₂⇓ e₃⇓ = case e₁⇓ (there (λ ()) here) [] e₃⇓ -- Negation of booleans. not : Exp → Exp not e = if e then ⌜ false ⦂ Bool ⌝ else ⌜ true ⦂ Bool ⌝ not-closed : ∀ {xs e} → Closed′ xs e → Closed′ xs (not e) not-closed cl-e = if-then-else-closed cl-e (Closed→Closed′ (from-⊎ (closed? ⌜ false ⦂ Bool ⌝))) (Closed→Closed′ (from-⊎ (closed? ⌜ true ⦂ Bool ⌝))) not-correct : ∀ {e} (b : Bool) → e ⇓ ⌜ b ⌝ → not e ⇓ ⌜ Prelude.not b ⌝ not-correct true e⇓ = case e⇓ here [] (rep⇓rep (false ⦂ Bool)) not-correct false e⇓ = case e⇓ (there (λ ()) here) [] (rep⇓rep (true ⦂ Bool)) -- Conjunction. and : Exp → Exp → Exp and e₁ e₂ = if e₁ then e₂ else ⌜ false ⦂ Bool ⌝ and-closed : ∀ {xs e₁ e₂} → Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (and e₁ e₂) and-closed cl-e₁ cl-e₂ = if-then-else-closed cl-e₁ cl-e₂ (Closed→Closed′ (from-⊎ (closed? ⌜ false ⦂ Bool ⌝))) and-correct : ∀ {e₁ e₂} b₁ b₂ → e₁ ⇓ ⌜ b₁ ⌝ → e₂ ⇓ ⌜ b₂ ⌝ → and e₁ e₂ ⇓ ⌜ b₁ ∧ b₂ ⌝ and-correct b₁ b₂ e₁⇓ e₂⇓ = if-then-else-correct b₁ b₂ false e₁⇓ e₂⇓ (rep⇓rep (false ⦂ Bool)) -- Disjunction. or : Exp → Exp → Exp or e₁ e₂ = if e₁ then ⌜ true ⦂ Bool ⌝ else e₂ or-closed : ∀ {xs e₁ e₂} → Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (or e₁ e₂) or-closed cl-e₁ cl-e₂ = if-then-else-closed cl-e₁ (Closed→Closed′ (from-⊎ (closed? ⌜ true ⦂ Bool ⌝))) cl-e₂ or-correct : ∀ {e₁ e₂} b₁ b₂ → e₁ ⇓ ⌜ b₁ ⌝ → e₂ ⇓ ⌜ b₂ ⌝ → or e₁ e₂ ⇓ ⌜ b₁ ∨ b₂ ⌝ or-correct b₁ b₂ e₁⇓ e₂⇓ = if-then-else-correct b₁ true b₂ e₁⇓ (rep⇓rep (true ⦂ Bool)) e₂⇓ -- Equality of booleans. equal-Bool : Exp → Exp → Exp equal-Bool e₁ e₂ = if e₁ then e₂ else not e₂ equal-Bool-closed : ∀ {xs e₁ e₂} → Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (equal-Bool e₁ e₂) equal-Bool-closed cl-e₁ cl-e₂ = if-then-else-closed cl-e₁ cl-e₂ (not-closed cl-e₂) equal-Bool-correct : ∀ {e₁ e₂} b₁ b₂ → e₁ ⇓ ⌜ b₁ ⌝ → e₂ ⇓ ⌜ b₂ ⌝ → equal-Bool e₁ e₂ ⇓ ⌜ Prelude.if b₁ Bool.≟ b₂ then true else false ⌝ equal-Bool-correct {e₁} {e₂} b₁ b₂ e₁⇓ e₂⇓ = equal-Bool e₁ e₂ ⇓⟨ if-then-else-correct b₁ b₂ (Prelude.not b₂) e₁⇓ e₂⇓ (not-correct b₂ e₂⇓) ⟩ ⌜ Prelude.if b₁ then b₂ else Prelude.not b₂ ⌝ ≡⟨ cong ⌜_⌝ (lemma b₁ b₂) ⟩⟶ ⌜ Prelude.if b₁ Bool.≟ b₂ then true else false ⌝ ■⟨ rep-value (Prelude.if b₁ Bool.≟ b₂ then true else false) ⟩ where lemma : ∀ b₁ b₂ → Prelude.if b₁ then b₂ else Prelude.not b₂ ≡ Prelude.if b₁ Bool.≟ b₂ then true else false lemma true true = refl lemma true false = refl lemma false true = refl lemma false false = refl -- An internal decoding function for booleans. decode-Bool : Exp → Exp decode-Bool e = case e (branch c-const (v-c ∷ v-es ∷ []) (equal-ℕ (var v-c) ⌜ c-true ⌝) ∷ []) decode-Bool-closed : ∀ {xs e} → Closed′ xs e → Closed′ xs (decode-Bool e) decode-Bool-closed cl-e = Closed′-closed-under-case cl-e λ where (inj₁ refl) → equal-ℕ-closed (Closed′-closed-under-var (from-⊎ (V.member v-c (v-c ∷ v-es ∷ _)))) (Closed→Closed′ (rep-closed c-true)) (inj₂ ()) decode-Bool-correct : ∀ {e} (b : Bool) → e ⇓ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ → decode-Bool e ⇓ ⌜ b ⌝ decode-Bool-correct true e⇓ = case e⇓ here (∷ ∷ []) (equal-ℕ-correct c-true c-true) decode-Bool-correct false e⇓ = case e⇓ here (∷ ∷ []) (equal-ℕ-correct c-false c-true)
{ "alphanum_fraction": 0.4553459868, "avg_line_length": 33.5469061876, "ext": "agda", "hexsha": "f4d7528f230795fd0d35051bfde89a449ac17ddf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/chi", "max_forks_repo_path": "src/Combinators.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/chi", "max_issues_repo_path": "src/Combinators.agda", "max_line_length": 137, "max_stars_count": 2, "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/chi", "max_stars_repo_path": "src/Combinators.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "num_tokens": 6841, "size": 16807 }
-- Various operations and proofs on morphisms between products {-# OPTIONS --universe-polymorphism #-} open import Categories.Category module Categories.Object.Product.Morphisms {o ℓ e} (C : Category o ℓ e) where import Categories.Object.Product open Categories.Object.Product C open Category C open Equiv open HomReasoning open import Function using (flip) open import Level infix 10 [_]⟨_,_⟩ [_⇒_]_⁂_ [[_]] : ∀{A B} → Product A B → Obj [[ p ]] = Product.A×B p [_]⟨_,_⟩ : ∀ {A B C} → (p : Product B C) → A ⇒ B → A ⇒ C → A ⇒ [[ p ]] [ p ]⟨ f , g ⟩ = Product.⟨_,_⟩ p f g [_]π₁ : ∀ {A B} → (p : Product A B) → [[ p ]] ⇒ A [_]π₁ = Product.π₁ [_]π₂ : ∀ {A B} → (p : Product A B) → [[ p ]] ⇒ B [_]π₂ = Product.π₂ [_⇒_]_⁂_ : ∀ {A B C D} → (p₁ : Product A C) → (p₂ : Product B D) → (A ⇒ B) → (C ⇒ D) → ([[ p₁ ]] ⇒ [[ p₂ ]]) [ p₁ ⇒ p₂ ] f ⁂ g = [ p₂ ]⟨ f ∘ p₁.π₁ , g ∘ p₁.π₂ ⟩ where module p₁ = Product p₁ module p₂ = Product p₂ .id⁂id : ∀ {A B}(p : Product A B) → [ p ⇒ p ] id ⁂ id ≡ id id⁂id p = begin ⟨ id ∘ π₁ , id ∘ π₂ ⟩ ↓⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩ ⟨ π₁ , π₂ ⟩ ↓⟨ η ⟩ id ∎ where open Product p .repack≡id⁂id : ∀{X Y}(p₁ p₂ : Product X Y) → repack p₁ p₂ ≡ [ p₁ ⇒ p₂ ] id ⁂ id repack≡id⁂id p₁ p₂ = sym (Product.⟨⟩-cong₂ p₂ identityˡ identityˡ) where open Equiv .[_⇒_]π₁∘⁂ : ∀ {A B C D} → {f : A ⇒ B} → {g : C ⇒ D} → (p₁ : Product A C) → (p₂ : Product B D) → Product.π₁ p₂ ∘ [ p₁ ⇒ p₂ ] f ⁂ g ≡ f ∘ Product.π₁ p₁ [_⇒_]π₁∘⁂ {f = f} {g} p₁ p₂ = Product.commute₁ p₂ .[_⇒_]π₂∘⁂ : ∀ {A B C D} → {f : A ⇒ B} → {g : C ⇒ D} → (p₁ : Product A C) → (p₂ : Product B D) → Product.π₂ p₂ ∘ [ p₁ ⇒ p₂ ] f ⁂ g ≡ g ∘ Product.π₂ p₁ [_⇒_]π₂∘⁂ {f = f} {g} p₁ p₂ = Product.commute₂ p₂ .[_⇒_]⁂-cong₂ : ∀ {A B C D}{f g h i} → (p₁ : Product A B) → (p₂ : Product C D) → f ≡ g → h ≡ i → [ p₁ ⇒ p₂ ] f ⁂ h ≡ [ p₁ ⇒ p₂ ] g ⁂ i [_⇒_]⁂-cong₂ {A}{B}{C}{D}{f}{g}{h}{i} p₁ p₂ f≡g h≡i = Product.⟨⟩-cong₂ p₂ (∘-resp-≡ f≡g refl) (∘-resp-≡ h≡i refl) .[_⇒_]⁂∘⟨⟩ : ∀{A B C D X} → {f : A ⇒ C} {f′ : X ⇒ A} → {g : B ⇒ D} {g′ : X ⇒ B} → (p₁ : Product A B) → (p₂ : Product C D) → ([ p₁ ⇒ p₂ ] f ⁂ g) ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≡ [ p₂ ]⟨ f ∘ f′ , g ∘ g′ ⟩ [_⇒_]⁂∘⟨⟩ {A}{B}{C}{D}{X}{f}{f′}{g}{g′} p₁ p₂ = begin [ p₂ ]⟨ f ∘ p₁.π₁ , g ∘ p₁.π₂ ⟩ ∘ [ p₁ ]⟨ f′ , g′ ⟩ ↓⟨ p₂.⟨⟩∘ ⟩ [ p₂ ]⟨ (f ∘ p₁.π₁) ∘ p₁.⟨_,_⟩ f′ g′ , (g ∘ p₁.π₂) ∘ p₁.⟨_,_⟩ f′ g′ ⟩ ↓⟨ p₂.⟨⟩-cong₂ assoc assoc ⟩ [ p₂ ]⟨ f ∘ p₁.π₁ ∘ p₁.⟨_,_⟩ f′ g′ , g ∘ p₁.π₂ ∘ p₁.⟨_,_⟩ f′ g′ ⟩ ↓⟨ p₂.⟨⟩-cong₂ (∘-resp-≡ refl p₁.commute₁) (∘-resp-≡ refl p₁.commute₂) ⟩ [ p₂ ]⟨ f ∘ f′ , g ∘ g′ ⟩ ∎ where module p₁ = Product p₁ module p₂ = Product p₂ .[_⇒_⇒_]⁂∘⁂ : ∀ {A B C D E F}{f g h i} → (p₁ : Product A B) → (p₂ : Product C D) → (p₃ : Product E F) → ([ p₂ ⇒ p₃ ] g ⁂ i) ∘ ([ p₁ ⇒ p₂ ] f ⁂ h) ≡ [ p₁ ⇒ p₃ ] (g ∘ f) ⁂ (i ∘ h) [_⇒_⇒_]⁂∘⁂ {A}{B}{C}{D}{E}{F}{f}{g}{h}{i} p₁ p₂ p₃ = begin [ p₃ ]⟨ g ∘ p₂.π₁ , i ∘ p₂.π₂ ⟩ ∘ [ p₂ ]⟨ f ∘ p₁.π₁ , h ∘ p₁.π₂ ⟩ ↓⟨ [ p₂ ⇒ p₃ ]⁂∘⟨⟩ ⟩ [ p₃ ]⟨ g ∘ f ∘ p₁.π₁ , i ∘ h ∘ p₁.π₂ ⟩ ↑⟨ p₃.⟨⟩-cong₂ assoc assoc ⟩ [ p₃ ]⟨ (g ∘ f) ∘ p₁.π₁ , (i ∘ h) ∘ p₁.π₂ ⟩ ∎ where module p₁ = Product p₁ module p₂ = Product p₂ module p₃ = Product p₃ .[_⇒_⇒_]repack∘⁂ : ∀ {A B C D}{f g} → (p₁ : Product A B) → (p₂ : Product C D) → (p₃ : Product C D) → repack p₂ p₃ ∘ [ p₁ ⇒ p₂ ] f ⁂ g ≡ [ p₁ ⇒ p₃ ] f ⁂ g [_⇒_⇒_]repack∘⁂ {A}{B}{C}{D}{f}{g} p₁ p₂ p₃ = begin repack p₂ p₃ ∘ [ p₁ ⇒ p₂ ] f ⁂ g ↓⟨ repack≡id⁂id p₂ p₃ ⟩∘⟨ refl ⟩ ([ p₂ ⇒ p₃ ] id ⁂ id) ∘ ([ p₁ ⇒ p₂ ] f ⁂ g) ↓⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]⁂∘⁂ ⟩ [ p₁ ⇒ p₃ ] (id ∘ f) ⁂ (id ∘ g) ↓⟨ [ p₁ ⇒ p₃ ]⁂-cong₂ identityˡ identityˡ ⟩ [ p₁ ⇒ p₃ ] f ⁂ g ∎ .[_⇒_⇒_]repack∘repack : ∀{A B} → (p₁ p₂ p₃ : Product A B) → repack p₂ p₃ ∘ repack p₁ p₂ ≡ repack p₁ p₃ [_⇒_⇒_]repack∘repack = repack∘ {- begin repack p₂ p₃ ∘ repack p₁ p₂ ↓⟨ repack≡id⁂id p₂ p₃ ⟩∘⟨ repack≡id⁂id p₁ p₂ ⟩ ([ p₂ ⇒ p₃ ] id ⁂ id) ∘ ([ p₁ ⇒ p₂ ] id ⁂ id) ↓⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]⁂∘⁂ ⟩ [ p₁ ⇒ p₃ ] (id ∘ id) ⁂ (id ∘ id) ↓⟨ [ p₁ ⇒ p₃ ]⁂-cong₂ identityˡ identityˡ ⟩ [ p₁ ⇒ p₃ ] id ⁂ id ↑⟨ repack≡id⁂id p₁ p₃ ⟩ repack p₁ p₃ ∎ -} [_⇒_]first : ∀ {A B C} → (p₁ : Product A C) → (p₂ : Product B C) → A ⇒ B → [[ p₁ ]] ⇒ [[ p₂ ]] [ p₁ ⇒ p₂ ]first f = [ p₁ ⇒ p₂ ] f ⁂ id [_⇒_]second : ∀ {A B C} → (p₁ : Product A B) → (p₂ : Product A C) → B ⇒ C → [[ p₁ ]] ⇒ [[ p₂ ]] [ p₁ ⇒ p₂ ]second g = [ p₁ ⇒ p₂ ] id ⁂ g .first-id : ∀ {A B}(p : Product A B) → [ p ⇒ p ]first id ≡ id first-id = id⁂id .second-id : ∀ {A B}(p : Product A B) → [ p ⇒ p ]second id ≡ id second-id = id⁂id .[_⇒_]first∘⟨⟩ : ∀ {A B C D} → {f : B ⇒ C} {f′ : A ⇒ B} {g′ : A ⇒ D} → (p₁ : Product B D) (p₂ : Product C D) → [ p₁ ⇒ p₂ ]first f ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≡ [ p₂ ]⟨ f ∘ f′ , g′ ⟩ [_⇒_]first∘⟨⟩ {A}{B}{C}{D}{f}{f′}{g′} p₁ p₂ = begin [ p₁ ⇒ p₂ ]first f ∘ [ p₁ ]⟨ f′ , g′ ⟩ ↓⟨ [ p₁ ⇒ p₂ ]⁂∘⟨⟩ ⟩ [ p₂ ]⟨ f ∘ f′ , id ∘ g′ ⟩ ↓⟨ p₂.⟨⟩-cong₂ refl identityˡ ⟩ [ p₂ ]⟨ f ∘ f′ , g′ ⟩ ∎ where module p₂ = Product p₂ .[_⇒_]second∘⟨⟩ : ∀ {A B D E} → {f′ : A ⇒ B} {g : D ⇒ E} {g′ : A ⇒ D} → (p₁ : Product B D) (p₂ : Product B E) → [ p₁ ⇒ p₂ ]second g ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≡ [ p₂ ]⟨ f′ , g ∘ g′ ⟩ [_⇒_]second∘⟨⟩ {A}{B}{D}{E}{f′}{g}{g′} p₁ p₂ = begin [ p₁ ⇒ p₂ ]second g ∘ [ p₁ ]⟨ f′ , g′ ⟩ ↓⟨ [ p₁ ⇒ p₂ ]⁂∘⟨⟩ ⟩ [ p₂ ]⟨ id ∘ f′ , g ∘ g′ ⟩ ↓⟨ p₂.⟨⟩-cong₂ identityˡ refl ⟩ [ p₂ ]⟨ f′ , g ∘ g′ ⟩ ∎ where module p₂ = Product p₂ .[_⇒_⇒_]first∘first : ∀ {A B C D}{f : B ⇒ C} {g : A ⇒ B} → (p₁ : Product A D) → (p₂ : Product B D) → (p₃ : Product C D) → [ p₂ ⇒ p₃ ]first f ∘ [ p₁ ⇒ p₂ ]first g ≡ [ p₁ ⇒ p₃ ]first(f ∘ g) [_⇒_⇒_]first∘first {A}{B}{C}{D}{f}{g} p₁ p₂ p₃ = begin [ p₂ ⇒ p₃ ]first f ∘ [ p₁ ⇒ p₂ ]first g ↓⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]⁂∘⁂ ⟩ [ p₁ ⇒ p₃ ] (f ∘ g) ⁂ (id ∘ id) ↓⟨ [ p₁ ⇒ p₃ ]⁂-cong₂ refl identityˡ ⟩ [ p₁ ⇒ p₃ ]first (f ∘ g) ∎ .[_⇒_⇒_]second∘second : ∀ {A B C D}{f : C ⇒ D} {g : B ⇒ C} → (p₁ : Product A B) → (p₂ : Product A C) → (p₃ : Product A D) → [ p₂ ⇒ p₃ ]second f ∘ [ p₁ ⇒ p₂ ]second g ≡ [ p₁ ⇒ p₃ ]second(f ∘ g) [_⇒_⇒_]second∘second {A}{B}{C}{D}{f}{g} p₁ p₂ p₃ = begin [ p₂ ⇒ p₃ ]second f ∘ [ p₁ ⇒ p₂ ]second g ↓⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]⁂∘⁂ ⟩ [ p₁ ⇒ p₃ ] (id ∘ id) ⁂ (f ∘ g) ↓⟨ [ p₁ ⇒ p₃ ]⁂-cong₂ identityˡ refl ⟩ [ p₁ ⇒ p₃ ]second (f ∘ g) ∎ .[_⇒_,_⇒_]first↔second : ∀ {A B C D}{f : A ⇒ B}{g : C ⇒ D} → (p₁ : Product A D) → (p₂ : Product B D) → (p₃ : Product A C) → (p₄ : Product B C) → [ p₁ ⇒ p₂ ]first f ∘ [ p₃ ⇒ p₁ ]second g ≡ [ p₄ ⇒ p₂ ]second g ∘ [ p₃ ⇒ p₄ ]first f [_⇒_,_⇒_]first↔second {A}{B}{C}{D}{f}{g} p₁ p₂ p₃ p₄ = begin [ p₁ ⇒ p₂ ]first f ∘ [ p₃ ⇒ p₁ ]second g ↓⟨ [ p₃ ⇒ p₁ ⇒ p₂ ]⁂∘⁂ ⟩ [ p₃ ⇒ p₂ ] (f ∘ id) ⁂ (id ∘ g) ↓⟨ [ p₃ ⇒ p₂ ]⁂-cong₂ identityʳ identityˡ ⟩ [ p₃ ⇒ p₂ ] f ⁂ g ↑⟨ [ p₃ ⇒ p₂ ]⁂-cong₂ identityˡ identityʳ ⟩ [ p₃ ⇒ p₂ ] (id ∘ f) ⁂ (g ∘ id) ↑⟨ [ p₃ ⇒ p₄ ⇒ p₂ ]⁂∘⁂ ⟩ [ p₄ ⇒ p₂ ]second g ∘ [ p₃ ⇒ p₄ ]first f ∎
{ "alphanum_fraction": 0.4342808894, "avg_line_length": 28.5381526104, "ext": "agda", "hexsha": "66e9ddd28f29518158d3ec5ac880d3cea88289b8", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Object/Product/Morphisms.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "p-pavel/categories", "max_issues_repo_path": "Categories/Object/Product/Morphisms.agda", "max_line_length": 87, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Object/Product/Morphisms.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 4047, "size": 7106 }
open import Prelude module Implicits.Substitutions.Lemmas where open import Implicits.Syntax.Type open import Implicits.Syntax.Term hiding (var) open import Implicits.Syntax.Context open import Implicits.WellTyped open import Implicits.Substitutions open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Vec.Properties open import Extensions.Substitution import Category.Applicative.Indexed as Applicative open Applicative.Morphism using (op-<$>) module TypeLemmas where open import Implicits.Substitutions.Lemmas.Type public open import Implicits.Substitutions.Lemmas.MetaType public {- module SubstLemmas (_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set) where open TypingRules _⊢ᵣ_ private ⊢subst : ∀ {m n} {Γ₁ Γ₂ : Ktx n m} {t₁ t₂ : Term n m} {a₁ a₂ : Type n} → Γ₁ ≡ Γ₂ → t₁ ≡ t₂ → a₁ ≡ a₂ → Γ₁ ⊢ t₁ ∈ a₁ → Γ₂ ⊢ t₂ ∈ a₂ ⊢subst refl refl refl hyp = hyp ⊢substCtx : ∀ {m n} {Γ₁ Γ₂ : Ktx n m} {t : Term n m} {a : Type n} → Γ₁ ≡ Γ₂ → Γ₁ ⊢ t ∈ a → Γ₂ ⊢ t ∈ a ⊢substCtx refl hyp = hyp ⊢substTp : ∀ {m n} {Γ : Ktx n m} {t : Term n m} {a₁ a₂ : Type n} → a₁ ≡ a₂ → Γ ⊢ t ∈ a₁ → Γ ⊢ t ∈ a₂ ⊢substTp refl hyp = hyp module WtTermLemmas where weaken : ∀ {ν n} {K : Ktx ν n} {t : Term ν n} {a b : Type ν} → K ⊢ t ∈ a → b ∷Γ K ⊢ tmtm-weaken t ∈ a -- weaken {Γ = Γ} {b = b} ⊢t = Var.wk /Var ⊢substCtx (C.wkVar-/Var-∷ Γ b) ⊢t module TermTypeLemmas where open TermTypeSubst private module T = TypeLemmas private module TS = TypeSubst private module V = VarLemmas /-↑⋆ : ∀ {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} → let open TS.Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/tp₁_) open Lifted lift₁ using () renaming (_/_ to _/₁_) open TS.Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/tp₂_) open Lifted lift₂ using () renaming (_/_ to _/₂_) in ∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) → (∀ i x → tvar x /tp₁ ρ₁ ↑⋆₁ i ≡ tvar x /tp₂ ρ₂ ↑⋆₂ i) → ∀ i {m} (t : Term (i N+ n) m) → t /₁ ρ₁ ↑⋆₁ i ≡ t /₂ ρ₂ ↑⋆₂ i /-↑⋆ ρ₁ ρ₂ hyp i (new x) = refl /-↑⋆ ρ₁ ρ₂ hyp i (var x) = refl /-↑⋆ ρ₁ ρ₂ hyp i (Λ t) = cong Λ (/-↑⋆ ρ₁ ρ₂ hyp (1 N+ i) t) /-↑⋆ ρ₁ ρ₂ hyp i (λ' a t) = cong₂ λ' (T./-↑⋆ ρ₁ ρ₂ hyp i a) (/-↑⋆ ρ₁ ρ₂ hyp i t) /-↑⋆ ρ₁ ρ₂ hyp i (t [ b ]) = cong₂ _[_] (/-↑⋆ ρ₁ ρ₂ hyp i t) (T./-↑⋆ ρ₁ ρ₂ hyp i b) /-↑⋆ ρ₁ ρ₂ hyp i (s · t) = cong₂ _·_ (/-↑⋆ ρ₁ ρ₂ hyp i s) (/-↑⋆ ρ₁ ρ₂ hyp i t) /-↑⋆ ρ₁ ρ₂ hyp i (x) = {!!} /-wk : ∀ {m n} (t : Term m n) → t / TypeSubst.wk ≡ weaken t /-wk t = /-↑⋆ TypeSubst.wk VarSubst.wk (λ k x → begin tvar x T./ T.wk T.↑⋆ k ≡⟨ T.var-/-wk-↑⋆ k x ⟩ tvar (finlift k suc x) ≡⟨ cong tvar (sym (V.var-/-wk-↑⋆ k x)) ⟩ tvar (lookup x (V.wk V.↑⋆ k)) ≡⟨ refl ⟩ tvar x TS./Var V.wk V.↑⋆ k ∎) 0 t module KtxLemmas where open KtxSubst hiding (ktx-map) private module Tp = TypeLemmas private module Var = VarSubst ktx-map-cong : ∀ {ν μ n} {f g : Type ν → Type μ} → f ≗ g → _≗_ {A = Ktx ν n} (ktx-map f) (ktx-map g) ktx-map-cong K = ? -- Term variable substitution (renaming) commutes with type -- substitution. {- /Var-/ : ∀ {m ν n l} (ρ : Sub Fin m n) (Γ : Ktx ν n) (σ : Sub Type ν l) → (Γ /Var ρ) / σ ≡ Γ /Var (ρ / σ) /Var-/ ρ Γ σ = begin (ρ /Var Γ) / σ ≡⟨ sym (map-∘ _ _ ρ) ⟩ map (λ x → (lookup x Γ) Tp./ σ) ρ ≡⟨ map-cong (λ x → sym (Tp.lookup-⊙ x)) ρ ⟩ map (λ x → lookup x (Γ / σ)) ρ ∎ -- Term variable substitution (renaming) commutes with weakening of -- typing contexts with an additional type variable. /Var-weaken : ∀ {m n k} (ρ : Sub Fin m k) (Γ : Ctx n k) → weaken (ρ /Var Γ) ≡ ρ /Var (weaken Γ) /Var-weaken ρ Γ = begin (ρ /Var Γ) / Tp.wk ≡⟨ ? ⟩ --/Var-/ ρ Γ Tp.wk ρ /Var (weaken Γ) ∎ -} -- Term variable substitution (renaming) commutes with term variable -- lookup in typing context. {- /Var-lookup : ∀ {m n k} (x : Fin m) (ρ : Sub Fin m k) (Γ : Ctx n k) → lookup x (ρ /Var Γ) ≡ lookup (lookup x ρ) Γ /Var-lookup x ρ Γ = op-<$> (lookup-morphism x) _ _ -- Term variable substitution (renaming) commutes with weakening of -- typing contexts with an additional term variable. /Var-∷ : ∀ {m n k} (a : Type n) (ρ : Sub Fin m k) (Γ : Ctx n k) → a ∷ (ρ /Var Γ) ≡ (ρ Var.↑) /Var (a ∷ Γ) /Var-∷ a [] Γ = refl /Var-∷ a (x ∷ ρ) Γ = cong (_∷_ a) (cong (_∷_ (lookup x Γ)) (begin map (λ x → lookup x Γ) ρ ≡⟨ refl ⟩ map (λ x → lookup (suc x) (a ∷ Γ)) ρ ≡⟨ map-∘ _ _ ρ ⟩ map (λ x → lookup x (a ∷ Γ)) (map suc ρ) ∎)) -- Invariants of term variable substitution (renaming) idVar-/Var : ∀ {m n} (Γ : Ctx n m) → Γ ≡ (Var.id /Var Γ) wkVar-/Var-∷ : ∀ {m n} (Γ : Ctx n m) (a : Type n) → Γ ≡ (Var.wk /Var (a ∷ Γ)) idVar-/Var [] = refl idVar-/Var (a ∷ Γ) = cong (_∷_ a) (wkVar-/Var-∷ Γ a) wkVar-/Var-∷ Γ a = begin Γ ≡⟨ idVar-/Var Γ ⟩ Var.id /Var Γ ≡⟨ map-∘ _ _ VarSubst.id ⟩ Var.wk /Var (a ∷ Γ) ∎ ctx-weaken-sub-vanishes : ∀ {ν n} {Γ : Ktx ν n} {a} → (ktx-weaken Γ) / (Tp.sub a) ≡ Γ ctx-weaken-sub-vanishes {Γ = Γ} {a} = begin (Γ / Tp.wk) / (Tp.sub a) ≡⟨ sym $ map-∘ (λ s → s tp/tp Tp.sub a) (λ s → s tp/tp Tp.wk) Γ ⟩ (map (λ s → s tp/tp Tp.wk tp/tp (Tp.sub a)) Γ) ≡⟨ map-cong (TypeLemmas.wk-sub-vanishes) Γ ⟩ (map (λ s → s) Γ) ≡⟨ map-id Γ ⟩ Γ ∎ -} module WtTypeLemmas where open TypeLemmas hiding (_/_; weaken) private module Tp = TypeLemmas module TmTp = TermTypeLemmas module C = KtxLemmas infixl 8 _/_ -- Type substitutions lifted to well-typed terms _/_ : ∀ {m n k} {Γ : Ktx n m} {t : Term n m} {a : Type n} → Γ ⊢ t ∈ a → (σ : Sub Type n k) → Γ ktx/ σ ⊢ t tm/tp σ ∈ a Tp./ σ new c / σ = new c var x / σ = ⊢substTp (lookup-⊙ x) (var x) _/_ {Γ = Γ} (Λ ⊢t) σ = Λ (⊢substCtx eq (⊢t / σ ↑)) where eq : (ktx-weaken Γ) ktx/ (σ Tp.↑) ≡ ktx-weaken (Γ ktx/ σ) {- eq = begin (ktx-map (λ s → s tp/tp Tp.wk) Γ) ktx/ (σ Tp.↑) ≡⟨ KtxLemmas.ktx-map-cong (λ a → a ktx/ (σ Tp.↑)) (KtxLemmas.ktx-map-cong (λ a → Tp./-wk {t = a}) Γ) ⟩ (ktx-map Tp.weaken Γ) ⊙ (σ Tp.↑) ≡⟨ sym $ map-weaken-⊙ Γ σ ⟩ map Tp.weaken (Γ ⊙ σ) ≡⟨ (map-cong (λ a → sym $ Tp./-wk {t = a}) (Γ ⊙ σ)) ⟩ ktx-weaken (Γ ktx/ σ) ∎ -} λ' a ⊢t / σ = λ' (a Tp./ σ) (⊢t / σ) _[_] {a = a} ⊢t b / σ = ⊢substTp (sym (sub-commutes a)) ((⊢t / σ) [ b Tp./ σ ]) ⊢s · ⊢t / σ = (⊢s / σ) · (⊢t / σ) x / σ = ? -- Weakening of terms with additional type variables lifted to -- well-typed terms. weaken : ∀ {m n} {Γ : Ktx n m} {t : Term n m} {a : Type n} → Γ ⊢ t ∈ a → ktx-weaken Γ ⊢ tm-weaken t ∈ Tp.weaken a weaken {t = t} {a = a} ⊢t = ⊢subst refl (TmTp./-wk t) (/-wk {t = a}) (⊢t / wk) -- Weakening of terms with additional type variables lifted to -- collections of well-typed terms. weakenAll : ∀ {m n k} {Γ : Ktx n m} {ts : Vec (Term n m) k} {as : Vec (Type n) k} → Γ ⊢ⁿ ts ∈ as → ktx-weaken Γ ⊢ⁿ map tm-weaken ts ∈ map Tp.weaken as weakenAll {ts = []} {[]} [] = [] weakenAll {ts = _ ∷ _} {_ ∷ _} (⊢t ∷ ⊢ts) = weaken ⊢t ∷ weakenAll ⊢ts -- Shorthand for single-variable type substitutions in well-typed -- terms. _[/_] : ∀ {m n} {Γ : Ktx (1 N+ n) m} {t a} → Γ ⊢ t ∈ a → (b : Type n) → Γ ktx/ sub b ⊢ t tm/tp sub b ∈ a Tp./ sub b ⊢t [/ b ] = ⊢t / sub b {- tm[/tp]-preserves : ∀ {ν n} {Γ : Ctx ν n} {t τ} → Γ ⊢ Λ t ∈ ∀' τ → ∀ a → Γ ⊢ (t tm[/tp a ]) ∈ τ tp[/tp a ] tm[/tp]-preserves {Γ = Γ} {t} {τ} (Λ p) a = ctx-subst C.ctx-weaken-sub-vanishes (p / (Tp.sub a)) where ctx-subst = Prelude.subst (λ c → c ⊢ t tm[/tp a ] ∈ τ tp[/tp a ]) -} module WtTermLemmas where private module Tp = TypeLemmas module TmTp = TermTypeLemmas module TmTm = TermTermSubst module Var = VarSubst module C = KtxLemmas TmSub = TmTm.TermSub Term infix 4 _⇒_⊢_ -- Well-typed term substitutions are collections of well-typed terms. _⇒_⊢_ : ∀ {ν m k} → Ktx ν m → Ktx ν k → TmSub ν m k → Set Γ ⇒ Δ ⊢ s = Δ ⊢ⁿ s ∈ (proj₁ Γ) infixl 8 _/_ _/Var_ infix 10 _↑ -- Application of term variable substitutions (renaming) lifted to -- well-typed terms. _/Var_ : ∀ {ν m n} {K : Ktx ν n} {t : Term ν m} {a : Type ν} (s : Sub Fin m n) → s ktx/Var K ⊢ t ∈ a → K ⊢ t TmTm./Var s ∈ a _/Var_ {K = K} s (new c) = new c _/Var_ {K = K} s (var x) = ? -- ⊢substTp (sym (ktx/Var-lookup x ρ Γ)) (var (lookup x ρ)) _/Var_ {K = K} s (Λ ⊢t) = ? -- Λ (ρ /Var ⊢substCtx (ktx/Var-weaken ρ Γ) ⊢t) _/Var_ {K = K} s (λ' a ⊢t) = ? -- λ' a (ρ Var.↑ /Var ⊢substCtx (ktx/Var-∷ a ρ Γ) ⊢t) s /Var (⊢t [ b ]) = (s /Var ⊢t) [ b ] s /Var (⊢s · ⊢t) = (s /Var ⊢s) · (s /Var ⊢t) s /Var (x) = ? -- Weakening of terms with additional term variables lifted to -- well-typed terms. weaken : ∀ {ν n} {K : Ktx ν n} {t : Term ν n} {a b : Type ν} → K ⊢ t ∈ a → b ∷Γ K ⊢ TmTm.weaken t ∈ a weaken {K = K} {b = b} ⊢t = ? -- Var.wk /Var ⊢substCtx (C.wkVar-/Var-∷ Γ b) ⊢t -- Weakening of terms with additional term variables lifted to -- collections of well-typed terms. weakenAll : ∀ {ν n k} {K : Ktx ν n} {ts : Vec (Term ν n) k} {as : Vec (Type ν) k} {b : Type ν} → K ⊢ⁿ ts ∈ as → (b ∷Γ K) ⊢ⁿ map TmTm.weaken ts ∈ as weakenAll {ts = []} {[]} [] = [] weakenAll {ts = _ ∷ _} {_ ∷ _} (⊢t ∷ ⊢ts) = weaken ⊢t ∷ weakenAll ⊢ts -- Lifting of well-typed term substitutions. _↑ : ∀ {ν n} {Γ : Ktx ν n} {Δ : Ktx ν n} {ρ b} → Γ ⇒ Δ ⊢ ρ → b ∷Γ Γ ⇒ b ∷Γ Δ ⊢ ρ TmTm.↑ ⊢ρ ↑ = var zero ∷ weakenAll ⊢ρ -- The well-typed identity substitution. id : ∀ {ν n} {K : Ktx ν n} → K ⇒ K ⊢ TmTm.id id {K = K} = ? -- id {zero} {._} {K = [] , _} = [] -- id {suc _} {._} {K = a ∷ Γ , _} = id ↑ -- Well-typed weakening (as a substitution). wk : ∀ {m n} {Γ : Ktx n m} {a} → Γ ⇒ a ∷Γ Γ ⊢ TmTm.wk wk = weakenAll id -- A well-typed substitution which only replaces the first variable. sub : ∀ {ν n} {K : Ktx ν n} {t a} → K ⊢ t ∈ a → a ∷Γ K ⇒ K ⊢ TmTm.sub t sub ⊢t = ⊢t ∷ id -- Application of term substitutions lifted to well-typed terms _/_ : ∀ {ν n} {K : Ktx ν n} {Δ : Ktx ν n} {t a s} → K ⊢ t ∈ a → K ⇒ Δ ⊢ s → Δ ⊢ t TmTm./ s ∈ a new c / ⊢ρ = new c var x / ⊢ρ = lookup-⊢ x ⊢ρ _/_ {K = K} {Δ = Δ} {s = s} (Λ ⊢t) ⊢ρ = Λ (⊢t / weaken-⊢p) where weaken-⊢p : ktx-weaken K ⇒ ktx-weaken Δ ⊢ map tm-weaken s weaken-⊢p = (WtTypeLemmas.weakenAll ⊢ρ) λ' a ⊢t / ⊢ρ = λ' a (⊢t / ⊢ρ ↑) (⊢t [ a ]) / ⊢ρ = (⊢t / ⊢ρ) [ a ] (⊢s · ⊢t) / ⊢ρ = (⊢s / ⊢ρ) · (⊢t / ⊢ρ) -- Shorthand for well-typed single-variable term substitutions. _[/_] : ∀ {m n} {Γ : Ctx n m} {s t a b} → b ∷ Γ ⊢ s ∈ a → Γ ⊢ t ∈ b → Γ ⊢ s TmTm./ TmTm.sub t ∈ a ⊢s [/ ⊢t ] = ⊢s / sub ⊢t tm[/tm]-preserves : ∀ {ν n} {Γ : Ctx ν n} {t u a b} → b ∷ Γ ⊢ t ∈ a → Γ ⊢ u ∈ b → Γ ⊢ (t tm[/tm u ]) ∈ a tm[/tm]-preserves ⊢s ⊢t = ⊢s / sub ⊢t open WtTypeLemmas public using () renaming (weaken to ⊢tp-weaken) open WtTermLemmas public using () renaming (_/_ to _⊢/tp_; _[/_] to _⊢[/_]; weaken to ⊢weaken) -}
{ "alphanum_fraction": 0.4819356977, "avg_line_length": 39.5672131148, "ext": "agda", "hexsha": "222304ad04ae5ba648d6f7bc0a355fc4e17cf0d2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Implicits/Substitutions/Lemmas.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Implicits/Substitutions/Lemmas.agda", "max_line_length": 110, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Implicits/Substitutions/Lemmas.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 5242, "size": 12068 }
module BasicIS4.Metatheory.DyadicGentzen-BasicKripkeBozicDosen where open import BasicIS4.Syntax.DyadicGentzen public open import BasicIS4.Semantics.BasicKripkeBozicDosen public hiding (_⊨_) -- TODO -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A eval (var i) γ δ = lookup i γ eval (lam t) γ δ = λ ξ a → eval t (mono⊩⋆ ξ γ , a) (λ ζ → let _ , (ζ′ , ξ′) = ≤⨾R→R⨾≤ (_ , (ξ , ζ)) in mono⊩⋆ ξ′ (δ ζ′)) eval (app {A} {B} t u) γ δ = _⟪$⟫_ {A} {B} (eval t γ δ) (eval u γ δ) eval (mvar i) γ δ = lookup i (δ reflR) eval (box t) γ δ = λ ζ → eval t ∙ (λ ζ′ → δ (transR ζ ζ′)) eval (unbox t u) γ δ = eval u γ (λ ζ → δ ζ , (eval t γ δ) ζ) eval (pair t u) γ δ = eval t γ δ , eval u γ δ eval (fst t) γ δ = π₁ (eval t γ δ) eval (snd t) γ δ = π₂ (eval t γ δ) eval unit γ δ = ∙ -- TODO: Correctness of evaluation with respect to conversion.
{ "alphanum_fraction": 0.5175438596, "avg_line_length": 41.04, "ext": "agda", "hexsha": "22585bb964f0f34dbe02e1ad7ebb0d7049e247f8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/hilbert-gentzen", "max_forks_repo_path": "BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/hilbert-gentzen", "max_issues_repo_path": "BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda", "max_line_length": 80, "max_stars_count": 29, "max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/hilbert-gentzen", "max_stars_repo_path": "BasicIS4/Metatheory/DyadicGentzen-BasicKripkeBozicDosen.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z", "num_tokens": 404, "size": 1026 }
module Coirc.Network.Primitive where {-# IMPORT Coirc.Network.FFI #-} {-# IMPORT System.IO #-} open import Data.String open import IO.Primitive open import Foreign.Haskell postulate Handle : Set {-# COMPILED_TYPE Handle System.IO.Handle #-} postulate hConnect : String → IO Handle {-# COMPILED hConnect Coirc.Network.FFI.hConnect #-} postulate hPutStr : Handle → String → IO Unit {-# COMPILED hPutStr System.IO.hPutStr #-} postulate hGetLine : Handle → IO String {-# COMPILED hGetLine System.IO.hGetLine #-}
{ "alphanum_fraction": 0.7378640777, "avg_line_length": 25.75, "ext": "agda", "hexsha": "94059b41ce1336a9338993961e3b10ede60f3dba", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:29.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:53:29.000Z", "max_forks_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "larrytheliquid/coirc", "max_forks_repo_path": "src/Coirc/Network/Primitive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/coirc", "max_issues_repo_path": "src/Coirc/Network/Primitive.agda", "max_line_length": 52, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd5b9aeb84851da56ce018ed15a7da1dcc949461", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/coirc", "max_stars_repo_path": "src/Coirc/Network/Primitive.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 129, "size": 515 }
module Algebra.Dioid.Bool.Theorems where open import Algebra.Dioid open import Algebra.Dioid.Bool or-left-congruence : ∀ {b c d : Bool} -> b ≡ c -> (b or d) ≡ (c or d) or-left-congruence {b} {.b} {d} reflexivity = reflexivity or-left-congruence {b} {c} {d} (symmetry eq) = symmetry (or-left-congruence eq) or-left-congruence {b} {c} {d} (transitivity eq eq₁) = transitivity (or-left-congruence eq) (or-left-congruence eq₁) or-right-congruence : ∀ {b c d : Bool} -> c ≡ d -> (b or c) ≡ (b or d) or-right-congruence {b} {c} {.c} reflexivity = reflexivity or-right-congruence {b} {c} {d} (symmetry eq) = symmetry (or-right-congruence eq) or-right-congruence {b} {c} {d} (transitivity eq eq₁) = transitivity (or-right-congruence eq) (or-right-congruence eq₁) and-left-congruence : ∀ {b c d : Bool} -> b ≡ c -> (b and d) ≡ (c and d) and-left-congruence {b} {.b} {d} reflexivity = reflexivity and-left-congruence {b} {c} {d} (symmetry eq) = symmetry (and-left-congruence eq) and-left-congruence {b} {c} {d} (transitivity eq eq₁) = transitivity (and-left-congruence eq) (and-left-congruence eq₁) and-right-congruence : ∀ {b c d : Bool} -> c ≡ d -> (b and c) ≡ (b and d) and-right-congruence {b} {c} {.c} reflexivity = reflexivity and-right-congruence {b} {c} {d} (symmetry eq) = symmetry (and-right-congruence eq) and-right-congruence {b} {c} {d} (transitivity eq eq₁) = transitivity (and-right-congruence eq) (and-right-congruence eq₁) or-idempotence : ∀ {b : Bool} -> (b or b) ≡ b or-idempotence {true} = reflexivity or-idempotence {false} = reflexivity or-commutativity : ∀ {b c : Bool} -> (b or c) ≡ (c or b) or-commutativity {true} {true} = reflexivity or-commutativity {true} {false} = reflexivity or-commutativity {false} {true} = reflexivity or-commutativity {false} {false} = reflexivity or-associativity : ∀ {b c d : Bool} -> (b or (c or d)) ≡ ((b or c) or d) or-associativity {true} {c} {d} = reflexivity or-associativity {false} {true} {d} = reflexivity or-associativity {false} {false} {true} = reflexivity or-associativity {false} {false} {false} = reflexivity or-false-identity : ∀ {b : Bool} -> (b or false) ≡ b or-false-identity {true} = reflexivity or-false-identity {false} = reflexivity and-associativity : ∀ {b c d : Bool} -> (b and (c and d)) ≡ ((b and c) and d) and-associativity {true} {true} {true} = reflexivity and-associativity {true} {true} {false} = reflexivity and-associativity {true} {false} {d} = reflexivity and-associativity {false} {c} {d} = reflexivity and-left-false : ∀ {b : Bool} -> (false and b) ≡ false and-left-false {b} = reflexivity and-right-false : ∀ {b : Bool} -> (b and false) ≡ false and-right-false {true} = reflexivity and-right-false {false} = reflexivity and-left-true : ∀ {b : Bool} -> (true and b) ≡ b and-left-true {true} = reflexivity and-left-true {false} = reflexivity and-right-true : ∀ {b : Bool} -> (b and true) ≡ b and-right-true {true} = reflexivity and-right-true {false} = reflexivity left-distributivity : ∀ {b c d : Bool} -> (b and (c or d)) ≡ ((b and c) or (b and d)) left-distributivity {true} {true} {d} = reflexivity left-distributivity {true} {false} {true} = reflexivity left-distributivity {true} {false} {false} = reflexivity left-distributivity {false} {c} {d} = reflexivity right-distributivity : ∀ {b c d : Bool} -> ((b or c) and d) ≡ ((b and d) or (c and d)) right-distributivity {true} {true} {true} = reflexivity right-distributivity {true} {true} {false} = reflexivity right-distributivity {true} {false} {true} = reflexivity right-distributivity {true} {false} {false} = reflexivity right-distributivity {false} {true} {true} = reflexivity right-distributivity {false} {true} {false} = reflexivity right-distributivity {false} {false} {d} = reflexivity bool-dioid : Dioid Bool _≡_ bool-dioid = record { zero = false ; one = true ; _+_ = _or_ ; _*_ = _and_ ; reflexivity = reflexivity ; symmetry = symmetry ; transitivity = transitivity ; +left-congruence = or-left-congruence ; *left-congruence = and-left-congruence ; *right-congruence = and-right-congruence ; +idempotence = or-idempotence ; +commutativity = or-commutativity ; +associativity = or-associativity ; +zero-identity = or-false-identity ; *associativity = and-associativity ; *left-zero = λ {r} → reflexivity ; *right-zero = and-right-false ; *left-identity = and-left-true ; *right-identity = and-right-true ; left-distributivity = left-distributivity ; right-distributivity = right-distributivity }
{ "alphanum_fraction": 0.675049636, "avg_line_length": 41.2090909091, "ext": "agda", "hexsha": "045a83fe39a9f38b7a84dcee87250c9226e1e82e", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2019-05-09T23:53:28.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-17T20:48:20.000Z", "max_forks_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "snowleopard/alga-proofs", "max_forks_repo_path": "src/Algebra/Dioid/Bool/Theorems.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_issues_repo_issues_event_max_datetime": "2018-06-23T13:54:02.000Z", "max_issues_repo_issues_event_min_datetime": "2018-04-12T16:25:13.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "snowleopard/alga-proofs", "max_issues_repo_path": "src/Algebra/Dioid/Bool/Theorems.agda", "max_line_length": 122, "max_stars_count": 60, "max_stars_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "snowleopard/alga-proofs", "max_stars_repo_path": "src/Algebra/Dioid/Bool/Theorems.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:05:29.000Z", "max_stars_repo_stars_event_min_datetime": "2017-12-27T14:57:04.000Z", "num_tokens": 1561, "size": 4533 }
{-# OPTIONS --without-K --exact-split #-} module 11-function-extensionality where import 10-truncation-levels open 10-truncation-levels public -- Section 9.1 Equivalent forms of Function Extensionality. -- We first define the types Funext, Ind-htpy, and Weak-Funext. htpy-eq : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → (Id f g) → (f ~ g) htpy-eq refl = refl-htpy FUNEXT : {i j : Level} {A : UU i} {B : A → UU j} → (f : (x : A) → B x) → UU (i ⊔ j) FUNEXT f = is-fiberwise-equiv (λ g → htpy-eq {f = f} {g = g}) ev-refl-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) (C : (g : (x : A) → B x) → (f ~ g) → UU l3) → ((g : (x : A) → B x) (H : f ~ g) → C g H) → C f refl-htpy ev-refl-htpy f C φ = φ f refl-htpy IND-HTPY : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) → UU _ IND-HTPY {l1} {l2} {l3} {A} {B} f = (C : (g : (x : A) → B x) → (f ~ g) → UU l3) → sec (ev-refl-htpy f C) WEAK-FUNEXT : {i j : Level} (A : UU i) (B : A → UU j) → UU (i ⊔ j) WEAK-FUNEXT A B = ((x : A) → is-contr (B x)) → is-contr ((x : A) → B x) -- Our goal is now to show that function extensionality holds if and only if the homotopy induction principle is valid, if and only if the weak function extensionality principle holds. This is Theorem 9.1.1 in the notes. abstract is-contr-total-htpy-Funext : {i j : Level} {A : UU i} {B : A → UU j} → (f : (x : A) → B x) → FUNEXT f → is-contr (Σ ((x : A) → B x) (λ g → f ~ g)) is-contr-total-htpy-Funext f funext-f = fundamental-theorem-id' f refl-htpy (λ g → htpy-eq {g = g}) funext-f ev-pair : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : Σ A B → UU l3} → ((t : Σ A B) → C t) → (x : A) (y : B x) → C (pair x y) ev-pair f x y = f (pair x y) sec-ev-pair : {l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : Σ A B → UU l3) → sec (ev-pair {A = A} {B = B} {C = C}) sec-ev-pair A B C = pair (λ f → ind-Σ f) (λ f → refl) triangle-ev-refl-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) (C : Σ ((x : A) → B x) (λ g → f ~ g) → UU l3) → ev-pt (Σ ((x : A) → B x) (λ g → f ~ g)) (pair f refl-htpy) C ~ ((ev-refl-htpy f (λ x y → C (pair x y))) ∘ (ev-pair {C = C})) triangle-ev-refl-htpy f C φ = refl abstract IND-HTPY-FUNEXT : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) → FUNEXT f → IND-HTPY {l3 = l3} f IND-HTPY-FUNEXT {l3 = l3} {A = A} {B = B} f funext-f = Ind-identity-system l3 f ( refl-htpy) ( is-contr-total-htpy-Funext f funext-f) abstract FUNEXT-IND-HTPY : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) → IND-HTPY {l3 = l1 ⊔ l2} f → FUNEXT f FUNEXT-IND-HTPY f ind-htpy-f = fundamental-theorem-id-IND-identity-system f ( refl-htpy) ( ind-htpy-f) ( λ g → htpy-eq) abstract WEAK-FUNEXT-FUNEXT : {l1 l2 : Level} → ((A : UU l1) (B : A → UU l2) (f : (x : A) → B x) → FUNEXT f) → ((A : UU l1) (B : A → UU l2) → WEAK-FUNEXT A B) WEAK-FUNEXT-FUNEXT funext A B is-contr-B = let pi-center = (λ x → center (is-contr-B x)) in pair ( pi-center) ( λ f → inv-is-equiv (funext A B pi-center f) ( λ x → contraction (is-contr-B x) (f x))) abstract FUNEXT-WEAK-FUNEXT : {l1 l2 : Level} → ((A : UU l1) (B : A → UU l2) → WEAK-FUNEXT A B) → ((A : UU l1) (B : A → UU l2) (f : (x : A) → B x) → FUNEXT f) FUNEXT-WEAK-FUNEXT weak-funext A B f = fundamental-theorem-id f ( refl-htpy) ( is-contr-retract-of ( (x : A) → Σ (B x) (λ b → Id (f x) b)) ( pair ( λ t x → pair (pr1 t x) (pr2 t x)) ( pair (λ t → pair (λ x → pr1 (t x)) (λ x → pr2 (t x))) ( λ t → eq-pair refl refl))) ( weak-funext A ( λ x → Σ (B x) (λ b → Id (f x) b)) ( λ x → is-contr-total-path (f x)))) ( λ g → htpy-eq {g = g}) -- From now on we will be assuming that function extensionality holds postulate funext : {i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) → FUNEXT f equiv-funext : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → (Id f g) ≃ (f ~ g) equiv-funext {f = f} {g} = pair htpy-eq (funext f g) abstract eq-htpy : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → (f ~ g) → Id f g eq-htpy = inv-is-equiv (funext _ _) issec-eq-htpy : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → ((htpy-eq {f = f} {g = g}) ∘ (eq-htpy {f = f} {g = g})) ~ id issec-eq-htpy = issec-inv-is-equiv (funext _ _) isretr-eq-htpy : {i j : Level} {A : UU i} {B : A → UU j} {f g : (x : A) → B x} → ((eq-htpy {f = f} {g = g}) ∘ (htpy-eq {f = f} {g = g})) ~ id isretr-eq-htpy = isretr-inv-is-equiv (funext _ _) is-equiv-eq-htpy : {i j : Level} {A : UU i} {B : A → UU j} (f g : (x : A) → B x) → is-equiv (eq-htpy {f = f} {g = g}) is-equiv-eq-htpy f g = is-equiv-inv-is-equiv (funext _ _) eq-htpy-refl-htpy : {i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) → Id (eq-htpy (refl-htpy {f = f})) refl eq-htpy-refl-htpy f = isretr-eq-htpy refl {- The immediate proof of the following theorem would be is-contr-total-htpy-Funext f (funext f) We give a different proof to ensure that the center of contraction is the expected thing: pair f refl-htpy -} abstract is-contr-total-htpy : {i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) → is-contr (Σ ((x : A) → B x) (λ g → f ~ g)) is-contr-total-htpy f = pair ( pair f refl-htpy) ( λ t → ( inv (contraction ( is-contr-total-htpy-Funext f (funext f)) ( pair f refl-htpy))) ∙ ( contraction (is-contr-total-htpy-Funext f (funext f)) t)) abstract Ind-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) → IND-HTPY {l3 = l3} f Ind-htpy f = IND-HTPY-FUNEXT f (funext f) ind-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) (C : (g : (x : A) → B x) → (f ~ g) → UU l3) → C f refl-htpy → {g : (x : A) → B x} (H : f ~ g) → C g H ind-htpy f C t {g} = pr1 (Ind-htpy f C) t g comp-htpy : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) (C : (g : (x : A) → B x) → (f ~ g) → UU l3) → (c : C f refl-htpy) → Id (ind-htpy f C c refl-htpy) c comp-htpy f C = pr2 (Ind-htpy f C) abstract is-contr-Π : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} → ((x : A) → is-contr (B x)) → is-contr ((x : A) → B x) is-contr-Π {A = A} {B = B} = WEAK-FUNEXT-FUNEXT (λ X Y → funext) A B is-trunc-Π : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2} → ((x : A) → is-trunc k (B x)) → is-trunc k ((x : A) → B x) is-trunc-Π neg-two-𝕋 is-trunc-B = is-contr-Π is-trunc-B is-trunc-Π (succ-𝕋 k) is-trunc-B f g = is-trunc-is-equiv k (f ~ g) htpy-eq ( funext f g) ( is-trunc-Π k (λ x → is-trunc-B x (f x) (g x))) is-prop-Π : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} → is-subtype B → is-prop ((x : A) → B x) is-prop-Π = is-trunc-Π neg-one-𝕋 Π-Prop : {l1 l2 : Level} (P : UU-Prop l1) → (type-Prop P → UU-Prop l2) → UU-Prop (l1 ⊔ l2) Π-Prop P Q = pair ( (p : type-Prop P) → type-Prop (Q p)) ( is-prop-Π (λ p → is-prop-type-Prop (Q p))) abstract is-set-Π : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} → ((x : A) → is-set (B x)) → is-set ((x : A) → (B x)) is-set-Π = is-trunc-Π zero-𝕋 Π-Set : {l1 l2 : Level} (A : UU-Set l1) → (type-Set A → UU-Set l2) → UU-Set (l1 ⊔ l2) Π-Set A B = pair ( (x : type-Set A) → type-Set (B x)) ( is-set-Π (λ x → is-set-type-Set (B x))) abstract is-trunc-function-type : {l1 l2 : Level} (k : 𝕋) (A : UU l1) (B : UU l2) → is-trunc k B → is-trunc k (A → B) is-trunc-function-type k A B is-trunc-B = is-trunc-Π k {B = λ (x : A) → B} (λ x → is-trunc-B) is-prop-function-type : {l1 l2 : Level} (A : UU l1) (B : UU l2) → is-prop B → is-prop (A → B) is-prop-function-type = is-trunc-function-type neg-one-𝕋 is-set-function-type : {l1 l2 : Level} (A : UU l1) (B : UU l2) → is-set B → is-set (A → B) is-set-function-type = is-trunc-function-type zero-𝕋 {- The type theoretic principle of choice is the assertion that Π distributes over Σ. In other words, there is an equivalence ((x : A) → Σ (B x) (C x)) ≃ Σ ((x : A) → B x) (λ f → (x : A) → C x (f x)). In the following we construct this equivalence, and we also characterize the relevant identity types. We call the type on the left-hand side Π-total-fam, and we call the type on the right-hand side type-choice-∞. -} Π-total-fam : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) → UU (l1 ⊔ (l2 ⊔ l3)) Π-total-fam {A = A} {B} C = (x : A) → Σ (B x) (C x) type-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) → UU (l1 ⊔ (l2 ⊔ l3)) type-choice-∞ {A = A} {B} C = Σ ((x : A) → B x) (λ f → (x : A) → C x (f x)) {- We compute the identity type of Π-total-fam. Note that its characterization is again of the form Π-total-fam. -} {- We compute the identity type of type-choice-∞. Note that its identity type is again of the form type-choice-∞. -} Eq-type-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : type-choice-∞ C) → UU (l1 ⊔ (l2 ⊔ l3)) Eq-type-choice-∞ {A = A} {B} C t t' = type-choice-∞ ( λ (x : A) (p : Id ((pr1 t) x) ((pr1 t') x)) → Id (tr (C x) p ((pr2 t) x)) ((pr2 t') x)) reflexive-Eq-type-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t : type-choice-∞ C) → Eq-type-choice-∞ C t t reflexive-Eq-type-choice-∞ C (pair f g) = pair refl-htpy refl-htpy Eq-type-choice-∞-eq : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : type-choice-∞ C) → Id t t' → Eq-type-choice-∞ C t t' Eq-type-choice-∞-eq C t .t refl = reflexive-Eq-type-choice-∞ C t abstract is-contr-total-Eq-type-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t : type-choice-∞ C) → is-contr (Σ (type-choice-∞ C) (Eq-type-choice-∞ C t)) is-contr-total-Eq-type-choice-∞ {A = A} {B} C t = is-contr-total-Eq-structure ( λ f g H → (x : A) → Id (tr (C x) (H x) ((pr2 t) x)) (g x)) ( is-contr-total-htpy (pr1 t)) ( pair (pr1 t) refl-htpy) ( is-contr-total-htpy (pr2 t)) is-equiv-Eq-type-choice-∞-eq : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : type-choice-∞ C) → is-equiv (Eq-type-choice-∞-eq C t t') is-equiv-Eq-type-choice-∞-eq C t = fundamental-theorem-id t ( reflexive-Eq-type-choice-∞ C t) ( is-contr-total-Eq-type-choice-∞ C t) ( Eq-type-choice-∞-eq C t) eq-Eq-type-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) {t t' : type-choice-∞ C} → Eq-type-choice-∞ C t t' → Id t t' eq-Eq-type-choice-∞ C {t} {t'} = inv-is-equiv (is-equiv-Eq-type-choice-∞-eq C t t') choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → Π-total-fam C → type-choice-∞ C choice-∞ φ = pair (λ x → pr1 (φ x)) (λ x → pr2 (φ x)) inv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → type-choice-∞ C → Π-total-fam C inv-choice-∞ ψ x = pair ((pr1 ψ) x) ((pr2 ψ) x) issec-inv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → ( ( choice-∞ {A = A} {B = B} {C = C}) ∘ ( inv-choice-∞ {A = A} {B = B} {C = C})) ~ id issec-inv-choice-∞ {A = A} {C = C} (pair ψ ψ') = eq-Eq-type-choice-∞ C (pair refl-htpy refl-htpy) isretr-inv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → ( ( inv-choice-∞ {A = A} {B = B} {C = C}) ∘ ( choice-∞ {A = A} {B = B} {C = C})) ~ id isretr-inv-choice-∞ φ = eq-htpy (λ x → eq-pair refl refl) abstract is-equiv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → is-equiv (choice-∞ {A = A} {B = B} {C = C}) is-equiv-choice-∞ {A = A} {B = B} {C = C} = is-equiv-has-inverse ( inv-choice-∞ {A = A} {B = B} {C = C}) ( issec-inv-choice-∞ {A = A} {B = B} {C = C}) ( isretr-inv-choice-∞ {A = A} {B = B} {C = C}) equiv-choice-∞ : { l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → Π-total-fam C ≃ type-choice-∞ C equiv-choice-∞ = pair choice-∞ is-equiv-choice-∞ abstract is-equiv-inv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : (x : A) → B x → UU l3} → is-equiv (inv-choice-∞ {A = A} {B = B} {C = C}) is-equiv-inv-choice-∞ {A = A} {B = B} {C = C} = is-equiv-has-inverse ( choice-∞ {A = A} {B = B} {C = C}) ( isretr-inv-choice-∞ {A = A} {B = B} {C = C}) ( issec-inv-choice-∞ {A = A} {B = B} {C = C}) equiv-inv-choice-∞ : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) → (type-choice-∞ C) ≃ (Π-total-fam C) equiv-inv-choice-∞ C = pair inv-choice-∞ is-equiv-inv-choice-∞ mapping-into-Σ : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {C : B → UU l3} → (A → Σ B C) → Σ (A → B) (λ f → (x : A) → C (f x)) mapping-into-Σ {B = B} = choice-∞ {B = λ x → B} abstract is-equiv-mapping-into-Σ : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {C : B → UU l3} → is-equiv (mapping-into-Σ {A = A} {C = C}) is-equiv-mapping-into-Σ = is-equiv-choice-∞ {- Next we compute the identity type of products of total spaces. Note again that the identity type of a product of total spaces is again a product of total spaces. -} Eq-Π-total-fam : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : (a : A) → Σ (B a) (C a)) → UU (l1 ⊔ (l2 ⊔ l3)) Eq-Π-total-fam {A = A} C t t' = Π-total-fam (λ x (p : Id (pr1 (t x)) (pr1 (t' x))) → Id (tr (C x) p (pr2 (t x))) (pr2 (t' x))) reflexive-Eq-Π-total-fam : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t : (a : A) → Σ (B a) (C a)) → Eq-Π-total-fam C t t reflexive-Eq-Π-total-fam C t a = pair refl refl Eq-Π-total-fam-eq : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : (a : A) → Σ (B a) (C a)) → Id t t' → Eq-Π-total-fam C t t' Eq-Π-total-fam-eq C t .t refl = reflexive-Eq-Π-total-fam C t is-contr-total-Eq-Π-total-fam : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t : (a : A) → Σ (B a) (C a)) → is-contr (Σ ((a : A) → Σ (B a) (C a)) (Eq-Π-total-fam C t)) is-contr-total-Eq-Π-total-fam {A = A} {B} C t = is-contr-equiv' ( (a : A) → Σ (Σ (B a) (C a)) (λ t' → Σ (Id (pr1 (t a)) (pr1 t')) (λ p → Id (tr (C a) p (pr2 (t a))) (pr2 t')))) ( equiv-choice-∞ {- ( λ x t' → Σ ( Id (pr1 (t x)) (pr1 t')) ( λ p → Id (tr (C x) p (pr2 (t x))) (pr2 t')))-}) ( is-contr-Π ( λ a → is-contr-total-Eq-structure ( λ b c p → Id (tr (C a) p (pr2 (t a))) c) ( is-contr-total-path (pr1 (t a))) ( pair (pr1 (t a)) refl) ( is-contr-total-path (pr2 (t a))))) is-equiv-Eq-Π-total-fam-eq : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : (a : A) → Σ (B a) (C a)) → is-equiv (Eq-Π-total-fam-eq C t t') is-equiv-Eq-Π-total-fam-eq C t = fundamental-theorem-id t ( reflexive-Eq-Π-total-fam C t) ( is-contr-total-Eq-Π-total-fam C t) ( Eq-Π-total-fam-eq C t) eq-Eq-Π-total-fam : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) (t t' : (a : A) → Σ (B a) (C a)) → Eq-Π-total-fam C t t' → Id t t' eq-Eq-Π-total-fam C t t' = inv-is-equiv (is-equiv-Eq-Π-total-fam-eq C t t') -- Section 9.2 Universal properties abstract is-equiv-ev-pair : {l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : Σ A B → UU l3} → is-equiv (ev-pair {C = C}) is-equiv-ev-pair = pair ( sec-ev-pair _ _ _) ( pair ind-Σ ( λ f → eq-htpy ( ind-Σ {C = (λ t → Id (ind-Σ (ev-pair f) t) (f t))} (λ x y → refl)))) ev-refl : {l1 l2 : Level} {A : UU l1} (a : A) {B : (x : A) → Id a x → UU l2} → ((x : A) (p : Id a x) → B x p) → B a refl ev-refl a f = f a refl abstract is-equiv-ev-refl : {l1 l2 : Level} {A : UU l1} (a : A) {B : (x : A) → Id a x → UU l2} → is-equiv (ev-refl a {B = B}) is-equiv-ev-refl a = is-equiv-has-inverse ( ind-Id a _) ( λ b → refl) ( λ f → eq-htpy ( λ x → eq-htpy ( ind-Id a ( λ x' p' → Id (ind-Id a _ (f a refl) x' p') (f x' p')) ( refl) x))) -- Section 9.3 Composing with equivalences. precomp-Π : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) → ((b : B) → C b) → ((a : A) → C (f a)) precomp-Π f C h a = h (f a) tr-precompose-fam : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) {x y : A} (p : Id x y) → tr C (ap f p) ~ tr (λ x → C (f x)) p tr-precompose-fam C f refl = refl-htpy abstract is-equiv-precomp-Π-is-half-adjoint-equivalence : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-half-adjoint-equivalence f → (C : B → UU l3) → is-equiv (precomp-Π f C) is-equiv-precomp-Π-is-half-adjoint-equivalence f ( pair g (pair issec-g (pair isretr-g coh))) C = is-equiv-has-inverse (λ s y → tr C (issec-g y) (s (g y))) ( λ s → eq-htpy (λ x → ( ap (λ t → tr C t (s (g (f x)))) (coh x)) ∙ ( ( tr-precompose-fam C f (isretr-g x) (s (g (f x)))) ∙ ( apd s (isretr-g x))))) ( λ s → eq-htpy λ y → apd s (issec-g y)) abstract is-equiv-precomp-Π-is-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv f → (C : B → UU l3) → is-equiv (precomp-Π f C) is-equiv-precomp-Π-is-equiv f is-equiv-f = is-equiv-precomp-Π-is-half-adjoint-equivalence f ( is-half-adjoint-equivalence-is-path-split f ( is-path-split-is-equiv f is-equiv-f)) precomp-Π-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → (C : B → UU l3) → ((b : B) → C b) ≃ ((a : A) → C (map-equiv e a)) precomp-Π-equiv e C = pair ( precomp-Π (map-equiv e) C) ( is-equiv-precomp-Π-is-equiv (map-equiv e) (is-equiv-map-equiv e) C) abstract ind-is-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) (is-equiv-f : is-equiv f) → ((x : A) → C (f x)) → ((y : B) → C y) ind-is-equiv C f is-equiv-f = inv-is-equiv (is-equiv-precomp-Π-is-equiv f is-equiv-f C) comp-is-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) (is-equiv-f : is-equiv f) (h : (x : A) → C (f x)) → Id (λ x → (ind-is-equiv C f is-equiv-f h) (f x)) h comp-is-equiv C f is-equiv-f h = issec-inv-is-equiv (is-equiv-precomp-Π-is-equiv f is-equiv-f C) h htpy-comp-is-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) (is-equiv-f : is-equiv f) (h : (x : A) → C (f x)) → (λ x → (ind-is-equiv C f is-equiv-f h) (f x)) ~ h htpy-comp-is-equiv C f is-equiv-f h = htpy-eq (comp-is-equiv C f is-equiv-f h) precomp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : UU l3) → (B → C) → (A → C) precomp f C = precomp-Π f (λ b → C) abstract is-equiv-precomp-is-equiv-precomp-Π : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) → ((C : B → UU l3) → is-equiv (precomp-Π f C)) → ((C : UU l3) → is-equiv (precomp f C)) is-equiv-precomp-is-equiv-precomp-Π f is-equiv-precomp-Π-f C = is-equiv-precomp-Π-f (λ y → C) abstract is-equiv-precomp-is-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv f → (C : UU l3) → is-equiv (precomp f C) is-equiv-precomp-is-equiv f is-equiv-f = is-equiv-precomp-is-equiv-precomp-Π f ( is-equiv-precomp-Π-is-equiv f is-equiv-f) equiv-precomp-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) (C : UU l3) → (B → C) ≃ (A → C) equiv-precomp-equiv e C = pair ( precomp (map-equiv e) C) ( is-equiv-precomp-is-equiv (map-equiv e) (is-equiv-map-equiv e) C) abstract is-equiv-is-equiv-precomp-subuniverse : { l1 l2 : Level} ( α : Level → Level) (P : (l : Level) → UU l → UU (α l)) ( A : Σ (UU l1) (P l1)) (B : Σ (UU l2) (P l2)) (f : pr1 A → pr1 B) → ( (l : Level) (C : Σ (UU l) (P l)) → is-equiv (precomp f (pr1 C))) → is-equiv f is-equiv-is-equiv-precomp-subuniverse α P A B f is-equiv-precomp-f = let retr-f = center (is-contr-map-is-equiv (is-equiv-precomp-f _ A) id) in is-equiv-has-inverse ( pr1 retr-f) ( htpy-eq (ap pr1 (is-prop-is-contr' ( is-contr-map-is-equiv (is-equiv-precomp-f _ B) f) ( pair ( f ∘ (pr1 retr-f)) ( ap (λ (g : pr1 A → pr1 A) → f ∘ g) (pr2 retr-f))) ( pair id refl)))) ( htpy-eq (pr2 retr-f)) abstract is-equiv-is-equiv-precomp : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → ((l : Level) (C : UU l) → is-equiv (precomp f C)) → is-equiv f is-equiv-is-equiv-precomp {A = A} {B = B} f is-equiv-precomp-f = is-equiv-is-equiv-precomp-subuniverse ( const Level Level lzero) ( λ l X → unit) ( pair A star) ( pair B star) ( f) ( λ l C → is-equiv-precomp-f l (pr1 C)) -- Exercises -- Exercise 9.1 abstract is-equiv-htpy-inv : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f g : (x : A) → B x) → is-equiv (htpy-inv {f = f} {g = g}) is-equiv-htpy-inv f g = is-equiv-has-inverse ( htpy-inv) ( λ H → eq-htpy (λ x → inv-inv (H x))) ( λ H → eq-htpy (λ x → inv-inv (H x))) equiv-htpy-inv : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f g : (x : A) → B x) → (f ~ g) ≃ (g ~ f) equiv-htpy-inv f g = pair htpy-inv (is-equiv-htpy-inv f g) abstract is-equiv-htpy-concat : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g : (x : A) → B x} (H : f ~ g) → (h : (x : A) → B x) → is-equiv (htpy-concat H h) is-equiv-htpy-concat {A = A} {B = B} {f} = ind-htpy f ( λ g H → (h : (x : A) → B x) → is-equiv (htpy-concat H h)) ( λ h → is-equiv-id (f ~ h)) equiv-htpy-concat : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g : (x : A) → B x} (H : f ~ g) (h : (x : A) → B x) → (g ~ h) ≃ (f ~ h) equiv-htpy-concat H h = pair (htpy-concat H h) (is-equiv-htpy-concat H h) inv-htpy-concat' : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) {g h : (x : A) → B x} → (g ~ h) → (f ~ h) → (f ~ g) inv-htpy-concat' f K = htpy-concat' f (htpy-inv K) issec-inv-htpy-concat' : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) {g h : (x : A) → B x} (K : g ~ h) → ((htpy-concat' f K) ∘ (inv-htpy-concat' f K)) ~ id issec-inv-htpy-concat' f K L = eq-htpy (λ x → issec-inv-concat' (f x) (K x) (L x)) isretr-inv-htpy-concat' : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) {g h : (x : A) → B x} (K : g ~ h) → ((inv-htpy-concat' f K) ∘ (htpy-concat' f K)) ~ id isretr-inv-htpy-concat' f K L = eq-htpy (λ x → isretr-inv-concat' (f x) (K x) (L x)) is-equiv-htpy-concat' : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) {g h : (x : A) → B x} (K : g ~ h) → is-equiv (htpy-concat' f K) is-equiv-htpy-concat' f K = is-equiv-has-inverse ( inv-htpy-concat' f K) ( issec-inv-htpy-concat' f K) ( isretr-inv-htpy-concat' f K) equiv-htpy-concat' : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} (f : (x : A) → B x) {g h : (x : A) → B x} (K : g ~ h) → (f ~ g) ≃ (f ~ h) equiv-htpy-concat' f K = pair (htpy-concat' f K) (is-equiv-htpy-concat' f K) -- Exercise 9.2 abstract is-subtype-is-contr : {l : Level} → is-subtype {lsuc l} {A = UU l} is-contr is-subtype-is-contr A = is-prop-is-contr-if-inh ( λ is-contr-A → is-contr-Σ ( is-contr-A) ( λ x → is-contr-Π (is-prop-is-contr is-contr-A x))) abstract is-prop-is-trunc : {l : Level} (k : 𝕋) (A : UU l) → is-prop (is-trunc k A) is-prop-is-trunc neg-two-𝕋 = is-subtype-is-contr is-prop-is-trunc (succ-𝕋 k) A = is-prop-Π (λ x → is-prop-Π (λ y → is-prop-is-trunc k (Id x y))) abstract is-prop-is-prop : {l : Level} (A : UU l) → is-prop (is-prop A) is-prop-is-prop = is-prop-is-trunc neg-one-𝕋 abstract is-prop-is-set : {l : Level} (A : UU l) → is-prop (is-set A) is-prop-is-set = is-prop-is-trunc zero-𝕋 -- Exercise 9.3 postcomp : {l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} (A : UU l3) → (X → Y) → (A → X) → (A → Y) postcomp A f h = f ∘ h abstract is-equiv-is-equiv-postcomp : {l1 l2 : Level} {X : UU l1} {Y : UU l2} (f : X → Y) → ({l3 : Level} (A : UU l3) → is-equiv (postcomp A f)) → is-equiv f is-equiv-is-equiv-postcomp {X = X} {Y = Y} f post-comp-equiv-f = let sec-f = center (is-contr-map-is-equiv (post-comp-equiv-f Y) id) in is-equiv-has-inverse ( pr1 sec-f) ( htpy-eq (pr2 sec-f)) ( htpy-eq (ap pr1 (is-prop-is-contr' ( is-contr-map-is-equiv (post-comp-equiv-f X) f) ( pair ((pr1 sec-f) ∘ f) (ap (λ t → t ∘ f) (pr2 sec-f))) ( pair id refl)))) {- The following version of the same theorem works when X and Y are in the same universe. The condition of inducing equivalences by postcomposition is simplified to that universe. -} is-equiv-is-equiv-postcomp' : {l : Level} {X : UU l} {Y : UU l} (f : X → Y) → ((A : UU l) → is-equiv (postcomp A f)) → is-equiv f is-equiv-is-equiv-postcomp' {l} {X} {Y} f is-equiv-postcomp-f = let sec-f = center (is-contr-map-is-equiv (is-equiv-postcomp-f Y) id) in is-equiv-has-inverse ( pr1 sec-f) ( htpy-eq (pr2 sec-f)) ( htpy-eq (ap pr1 (is-prop-is-contr' ( is-contr-map-is-equiv (is-equiv-postcomp-f X) f) ( pair ((pr1 sec-f) ∘ f) (ap (λ t → t ∘ f) (pr2 sec-f))) ( pair id refl)))) abstract is-equiv-postcomp-is-equiv : {l1 l2 : Level} {X : UU l1} {Y : UU l2} (f : X → Y) → is-equiv f → ({l3 : Level} (A : UU l3) → is-equiv (postcomp A f)) is-equiv-postcomp-is-equiv {X = X} {Y = Y} f is-equiv-f A = is-equiv-has-inverse ( postcomp A (inv-is-equiv is-equiv-f)) ( λ g → eq-htpy (htpy-right-whisk (issec-inv-is-equiv is-equiv-f) g)) ( λ h → eq-htpy (htpy-right-whisk (isretr-inv-is-equiv is-equiv-f) h)) -- Exercise 9.4 is-contr-sec-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B} → is-equiv f → is-contr (sec f) is-contr-sec-is-equiv {A = A} {B = B} {f = f} is-equiv-f = is-contr-is-equiv' ( Σ (B → A) (λ g → Id (f ∘ g) id)) ( tot (λ g → htpy-eq)) ( is-equiv-tot-is-fiberwise-equiv ( λ g → funext (f ∘ g) id)) ( is-contr-map-is-equiv (is-equiv-postcomp-is-equiv f is-equiv-f B) id) is-contr-retr-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B} → is-equiv f → is-contr (retr f) is-contr-retr-is-equiv {A = A} {B = B} {f = f} is-equiv-f = is-contr-is-equiv' ( Σ (B → A) (λ h → Id (h ∘ f) id)) ( tot (λ h → htpy-eq)) ( is-equiv-tot-is-fiberwise-equiv ( λ h → funext (h ∘ f) id)) ( is-contr-map-is-equiv (is-equiv-precomp-is-equiv f is-equiv-f A) id) is-contr-is-equiv-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B} → is-equiv f → is-contr (is-equiv f) is-contr-is-equiv-is-equiv is-equiv-f = is-contr-prod ( is-contr-sec-is-equiv is-equiv-f) ( is-contr-retr-is-equiv is-equiv-f) abstract is-subtype-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} → is-subtype (is-equiv {A = A} {B = B}) is-subtype-is-equiv f = is-prop-is-contr-if-inh ( λ is-equiv-f → is-contr-prod ( is-contr-sec-is-equiv is-equiv-f) ( is-contr-retr-is-equiv is-equiv-f)) is-equiv-Prop : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → UU-Prop (l1 ⊔ l2) is-equiv-Prop f = pair (is-equiv f) (is-subtype-is-equiv f) abstract is-emb-map-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} → is-emb (map-equiv {A = A} {B = B}) is-emb-map-equiv = is-emb-pr1-is-subtype is-subtype-is-equiv {- For example, we show that homotopies are equivalent to identifications of equivalences. -} htpy-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} → A ≃ B → A ≃ B → UU (l1 ⊔ l2) htpy-equiv e e' = (map-equiv e) ~ (map-equiv e') reflexive-htpy-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → htpy-equiv e e reflexive-htpy-equiv e = refl-htpy htpy-equiv-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} {e e' : A ≃ B} (p : Id e e') → htpy-equiv e e' htpy-equiv-eq {e = e} {.e} refl = reflexive-htpy-equiv e abstract is-contr-total-htpy-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → is-contr (Σ (A ≃ B) (λ e' → htpy-equiv e e')) is-contr-total-htpy-equiv (pair f is-equiv-f) = is-contr-total-Eq-substructure ( is-contr-total-htpy f) ( is-subtype-is-equiv) ( f) ( refl-htpy) ( is-equiv-f) is-equiv-htpy-equiv-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} (e e' : A ≃ B) → is-equiv (htpy-equiv-eq {e = e} {e'}) is-equiv-htpy-equiv-eq e = fundamental-theorem-id e ( reflexive-htpy-equiv e) ( is-contr-total-htpy-equiv e) ( λ e' → htpy-equiv-eq {e = e} {e'}) eq-htpy-equiv : { l1 l2 : Level} {A : UU l1} {B : UU l2} {e e' : A ≃ B} → ( htpy-equiv e e') → Id e e' eq-htpy-equiv {e = e} {e'} = inv-is-equiv (is-equiv-htpy-equiv-eq e e') abstract Ind-htpy-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → (P : (e' : A ≃ B) (H : htpy-equiv e e') → UU l3) → sec ( λ (h : (e' : A ≃ B) (H : htpy-equiv e e') → P e' H) → h e (reflexive-htpy-equiv e)) Ind-htpy-equiv {l3 = l3} e = Ind-identity-system l3 e ( reflexive-htpy-equiv e) ( is-contr-total-htpy-equiv e) ind-htpy-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → (P : (e' : A ≃ B) (H : htpy-equiv e e') → UU l3) → P e (reflexive-htpy-equiv e) → (e' : A ≃ B) (H : htpy-equiv e e') → P e' H ind-htpy-equiv e P = pr1 (Ind-htpy-equiv e P) comp-htpy-equiv : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) → (P : (e' : A ≃ B) (H : htpy-equiv e e') → UU l3) (p : P e (reflexive-htpy-equiv e)) → Id (ind-htpy-equiv e P p e (reflexive-htpy-equiv e)) p comp-htpy-equiv e P = pr2 (Ind-htpy-equiv e P) -- Exercise 9.5 {- We use that is-equiv is a proposition to show that the type of equivalences between k-types is again a k-type. -} is-contr-equiv-is-contr : { l1 l2 : Level} {A : UU l1} {B : UU l2} → is-contr A → is-contr B → is-contr (A ≃ B) is-contr-equiv-is-contr is-contr-A is-contr-B = pair ( equiv-is-contr is-contr-A is-contr-B) ( λ e → eq-htpy-equiv ( λ x → is-prop-is-contr' is-contr-B (center is-contr-B) (map-equiv e x))) is-trunc-is-contr : { l : Level} (k : 𝕋) {A : UU l} → is-contr A → is-trunc k A is-trunc-is-contr neg-two-𝕋 is-contr-A = is-contr-A is-trunc-is-contr (succ-𝕋 k) is-contr-A x y = is-trunc-is-contr k (is-prop-is-contr is-contr-A x y) is-trunc-is-prop : { l : Level} (k : 𝕋) {A : UU l} → is-prop A → is-trunc (succ-𝕋 k) A is-trunc-is-prop k is-prop-A x y = is-trunc-is-contr k (is-prop-A x y) is-trunc-equiv-is-trunc : { l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} → is-trunc k A → is-trunc k B → is-trunc k (A ≃ B) is-trunc-equiv-is-trunc neg-two-𝕋 is-trunc-A is-trunc-B = is-contr-equiv-is-contr is-trunc-A is-trunc-B is-trunc-equiv-is-trunc (succ-𝕋 k) is-trunc-A is-trunc-B = is-trunc-Σ (succ-𝕋 k) ( is-trunc-Π (succ-𝕋 k) (λ x → is-trunc-B)) ( λ x → is-trunc-is-prop k (is-subtype-is-equiv x)) is-prop-equiv-is-prop : { l1 l2 : Level} {A : UU l1} {B : UU l2} → is-prop A → is-prop B → is-prop (A ≃ B) is-prop-equiv-is-prop = is-trunc-equiv-is-trunc neg-one-𝕋 prop-equiv : { l1 l2 : Level} → UU-Prop l1 → UU-Prop l2 → UU-Prop (l1 ⊔ l2) prop-equiv P Q = pair ( type-Prop P ≃ type-Prop Q) ( is-prop-equiv-is-prop (is-prop-type-Prop P) (is-prop-type-Prop Q)) is-set-equiv-is-set : { l1 l2 : Level} {A : UU l1} {B : UU l2} → is-set A → is-set B → is-set (A ≃ B) is-set-equiv-is-set = is-trunc-equiv-is-trunc zero-𝕋 set-equiv : { l1 l2 : Level} → UU-Set l1 → UU-Set l2 → UU-Set (l1 ⊔ l2) set-equiv A B = pair ( type-Set A ≃ type-Set B) ( is-set-equiv-is-set (is-set-type-Set A) (is-set-type-Set B)) {- Now we turn to the exercise. -} _↔_ : {l1 l2 : Level} → UU-Prop l1 → UU-Prop l2 → UU (l1 ⊔ l2) P ↔ Q = (pr1 P → pr1 Q) × (pr1 Q → pr1 P) equiv-iff : {l1 l2 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) → (P ↔ Q) → (pr1 P ≃ pr1 Q) equiv-iff P Q t = pair (pr1 t) (is-equiv-is-prop (pr2 P) (pr2 Q) (pr2 t)) iff-equiv : {l1 l2 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) → (pr1 P ≃ pr1 Q) → (P ↔ Q) iff-equiv P Q equiv-PQ = pair (pr1 equiv-PQ) (inv-is-equiv (pr2 equiv-PQ)) abstract is-prop-iff : {l1 l2 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) → is-prop (P ↔ Q) is-prop-iff P Q = is-prop-prod ( is-prop-function-type (pr1 P) (pr1 Q) (pr2 Q)) ( is-prop-function-type (pr1 Q) (pr1 P) (pr2 P)) abstract is-prop-equiv-Prop : {l1 l2 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) → is-prop ((pr1 P) ≃ (pr1 Q)) is-prop-equiv-Prop P Q = is-prop-equiv-is-prop (pr2 P) (pr2 Q) abstract is-equiv-equiv-iff : {l1 l2 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) → is-equiv (equiv-iff P Q) is-equiv-equiv-iff P Q = is-equiv-is-prop ( is-prop-iff P Q) ( is-prop-equiv-Prop P Q) ( iff-equiv P Q) abstract is-prop-is-contr-endomaps : {l : Level} (P : UU l) → is-contr (P → P) → is-prop P is-prop-is-contr-endomaps P H = is-prop-is-prop' ( λ x → htpy-eq (is-prop-is-contr' H (const P P x) id)) abstract is-contr-endomaps-is-prop : {l : Level} (P : UU l) → is-prop P → is-contr (P → P) is-contr-endomaps-is-prop P is-prop-P = is-contr-is-prop-inh (is-prop-function-type P P is-prop-P) id -- Exercise 9.6 abstract is-prop-is-path-split : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-prop (is-path-split f) is-prop-is-path-split f = is-prop-is-contr-if-inh (λ is-path-split-f → let is-equiv-f = is-equiv-is-path-split f is-path-split-f in is-contr-prod ( is-contr-sec-is-equiv is-equiv-f) ( is-contr-Π ( λ x → is-contr-Π ( λ y → is-contr-sec-is-equiv (is-emb-is-equiv f is-equiv-f x y))))) abstract is-equiv-is-path-split-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv (is-path-split-is-equiv f) is-equiv-is-path-split-is-equiv f = is-equiv-is-prop ( is-subtype-is-equiv f) ( is-prop-is-path-split f) ( is-equiv-is-path-split f) abstract is-prop-is-half-adjoint-equivalence : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-prop (is-half-adjoint-equivalence f) is-prop-is-half-adjoint-equivalence {l1} {l2} {A} {B} f = is-prop-is-contr-if-inh (λ is-hae-f → let is-equiv-f = is-equiv-is-half-adjoint-equivalence f is-hae-f in is-contr-equiv' ( Σ (sec f) ( λ sf → Σ (((pr1 sf) ∘ f) ~ id) ( λ H → (htpy-right-whisk (pr2 sf) f) ~ (htpy-left-whisk f H)))) ( equiv-Σ-assoc (B → A) ( λ g → ((f ∘ g) ~ id)) ( λ sf → Σ (((pr1 sf) ∘ f) ~ id) ( λ H → (htpy-right-whisk (pr2 sf) f) ~ (htpy-left-whisk f H)))) ( is-contr-Σ ( is-contr-sec-is-equiv is-equiv-f) ( λ sf → is-contr-equiv' ( (x : A) → Σ (Id ((pr1 sf) (f x)) x) (λ p → Id ((pr2 sf) (f x)) (ap f p))) ( equiv-choice-∞) ( is-contr-Π (λ x → is-contr-equiv' ( fib (ap f) ((pr2 sf) (f x))) ( equiv-tot ( λ p → equiv-inv (ap f p) ((pr2 sf) (f x)))) ( is-contr-map-is-equiv ( is-emb-is-equiv f is-equiv-f ((pr1 sf) (f x)) x) ( (pr2 sf) (f x)))))))) {- is-contr-is-equiv' ( Σ (sec f) ( λ sf → Σ (((pr1 sf) ∘ f) ~ id) ( λ H → (htpy-right-whisk (pr2 sf) f) ~ (htpy-left-whisk f H)))) ( Σ-assoc (B → A) ( λ g → ((f ∘ g) ~ id)) ( λ sf → Σ (((pr1 sf) ∘ f) ~ id) ( λ H → (htpy-right-whisk (pr2 sf) f) ~ (htpy-left-whisk f H)))) ( is-equiv-Σ-assoc _ _ _) ( is-contr-Σ ( is-contr-sec-is-equiv is-equiv-f) ( λ sf → is-contr-is-equiv' ( (x : A) → Σ (Id ((pr1 sf) (f x)) x) (λ p → Id ((pr2 sf) (f x)) (ap f p))) ( choice-∞) ( is-equiv-choice-∞) ( is-contr-Π (λ x → is-contr-is-equiv' ( fib (ap f) ((pr2 sf) (f x))) ( tot (λ p → inv)) ( is-equiv-tot-is-fiberwise-equiv ( λ p → is-equiv-inv (ap f p) ((pr2 sf) (f x)))) ( is-contr-map-is-equiv ( is-emb-is-equiv f is-equiv-f ((pr1 sf) (f x)) x) ( (pr2 sf) (f x)))))))) -} abstract is-equiv-is-half-adjoint-equivalence-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv (is-half-adjoint-equivalence-is-equiv f) is-equiv-is-half-adjoint-equivalence-is-equiv f = is-equiv-is-prop ( is-subtype-is-equiv f) ( is-prop-is-half-adjoint-equivalence f) ( is-equiv-is-half-adjoint-equivalence f) -- Exercise 9.7 is-invertible-id-htpy-id-id : {l : Level} (A : UU l) → (id {A = A} ~ id {A = A}) → has-inverse (id {A = A}) is-invertible-id-htpy-id-id A H = pair id (pair refl-htpy H) triangle-is-invertible-id-htpy-id-id : {l : Level} (A : UU l) → ( is-invertible-id-htpy-id-id A) ~ ( (Σ-assoc (A → A) (λ g → (id ∘ g) ~ id) (λ s → ((pr1 s) ∘ id) ~ id)) ∘ ( left-unit-law-Σ-map-gen ( λ s → ((pr1 s) ∘ id) ~ id) ( is-contr-sec-is-equiv (is-equiv-id A)) (pair id refl-htpy))) triangle-is-invertible-id-htpy-id-id A H = refl abstract is-equiv-invertible-id-htpy-id-id : {l : Level} (A : UU l) → is-equiv (is-invertible-id-htpy-id-id A) is-equiv-invertible-id-htpy-id-id A = is-equiv-comp ( is-invertible-id-htpy-id-id A) ( Σ-assoc (A → A) (λ g → (id ∘ g) ~ id) (λ s → ((pr1 s) ∘ id) ~ id)) ( left-unit-law-Σ-map-gen ( λ s → ((pr1 s) ∘ id) ~ id) ( is-contr-sec-is-equiv (is-equiv-id A)) ( pair id refl-htpy)) ( triangle-is-invertible-id-htpy-id-id A) ( is-equiv-left-unit-law-Σ-map-gen ( λ s → ((pr1 s) ∘ id) ~ id) ( is-contr-sec-is-equiv (is-equiv-id A)) ( pair id refl-htpy)) ( is-equiv-Σ-assoc _ _ _) -- Exercise 9.8 abstract dependent-universal-property-empty : {l : Level} (P : empty → UU l) → is-contr ((x : empty) → P x) dependent-universal-property-empty P = pair ( ind-empty {P = P}) ( λ f → eq-htpy ind-empty) abstract universal-property-empty : {l : Level} (X : UU l) → is-contr (empty → X) universal-property-empty X = dependent-universal-property-empty (λ t → X) abstract uniqueness-empty : {l : Level} (Y : UU l) → ((l' : Level) (X : UU l') → is-contr (Y → X)) → is-equiv (ind-empty {P = λ t → Y}) uniqueness-empty Y H = is-equiv-is-equiv-precomp ind-empty ( λ l X → is-equiv-is-contr ( λ g → g ∘ ind-empty) ( H _ X) ( universal-property-empty X)) abstract universal-property-empty-is-equiv-ind-empty : {l : Level} (X : UU l) → is-equiv (ind-empty {P = λ t → X}) → ((l' : Level) (Y : UU l') → is-contr (X → Y)) universal-property-empty-is-equiv-ind-empty X is-equiv-ind-empty l' Y = is-contr-is-equiv ( empty → Y) ( λ f → f ∘ ind-empty) ( is-equiv-precomp-is-equiv ind-empty is-equiv-ind-empty Y) ( universal-property-empty Y) -- Exercise 9.9 ev-inl-inr : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (P : coprod A B → UU l3) → ((t : coprod A B) → P t) → ((x : A) → P (inl x)) × ((y : B) → P (inr y)) ev-inl-inr P s = pair (λ x → s (inl x)) (λ y → s (inr y)) abstract dependent-universal-property-coprod : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (P : coprod A B → UU l3) → is-equiv (ev-inl-inr P) dependent-universal-property-coprod P = is-equiv-has-inverse ( λ p → ind-coprod P (pr1 p) (pr2 p)) ( ind-Σ (λ f g → eq-pair-triv (pair refl refl))) ( λ s → eq-htpy (ind-coprod _ (λ x → refl) λ y → refl)) abstract universal-property-coprod : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (X : UU l3) → is-equiv (ev-inl-inr (λ (t : coprod A B) → X)) universal-property-coprod X = dependent-universal-property-coprod (λ t → X) abstract uniqueness-coprod : { l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {Y : UU l3} ( i : A → Y) (j : B → Y) → ( (l : Level) (X : UU l) → is-equiv (λ (s : Y → X) → pair' (s ∘ i) (s ∘ j))) → is-equiv (ind-coprod (λ t → Y) i j) uniqueness-coprod {Y = Y} i j H = is-equiv-is-equiv-precomp ( ind-coprod _ i j) ( λ l X → is-equiv-right-factor ( λ (s : Y → X) → pair (s ∘ i) (s ∘ j)) ( ev-inl-inr (λ t → X)) ( precomp (ind-coprod (λ t → Y) i j) X) ( λ s → refl) ( universal-property-coprod X) ( H _ X)) abstract universal-property-coprod-is-equiv-ind-coprod : { l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (X : UU l3) ( i : A → X) (j : B → X) → is-equiv (ind-coprod (λ t → X) i j) → ( (l4 : Level) (Y : UU l4) → is-equiv (λ (s : X → Y) → pair' (s ∘ i) (s ∘ j))) universal-property-coprod-is-equiv-ind-coprod X i j is-equiv-ind-coprod l Y = is-equiv-comp ( λ s → pair (s ∘ i) (s ∘ j)) ( ev-inl-inr (λ t → Y)) ( precomp (ind-coprod (λ t → X) i j) Y) ( λ s → refl) ( is-equiv-precomp-is-equiv ( ind-coprod (λ t → X) i j) ( is-equiv-ind-coprod) ( Y)) ( universal-property-coprod Y) -- Exercise 9.10 ev-star : {l : Level} (P : unit → UU l) → ((x : unit) → P x) → P star ev-star P f = f star abstract dependent-universal-property-unit : {l : Level} (P : unit → UU l) → is-equiv (ev-star P) dependent-universal-property-unit P = is-equiv-has-inverse ( ind-unit) ( λ p → refl) ( λ f → eq-htpy (ind-unit refl)) equiv-ev-star : {l : Level} (P : unit → UU l) → ((x : unit) → P x) ≃ P star equiv-ev-star P = pair (ev-star P) (dependent-universal-property-unit P) ev-star' : {l : Level} (Y : UU l) → (unit → Y) → Y ev-star' Y = ev-star (λ t → Y) abstract universal-property-unit : {l : Level} (Y : UU l) → is-equiv (ev-star' Y) universal-property-unit Y = dependent-universal-property-unit (λ t → Y) equiv-ev-star' : {l : Level} (Y : UU l) → (unit → Y) ≃ Y equiv-ev-star' Y = pair (ev-star' Y) (universal-property-unit Y) abstract is-equiv-ind-unit-universal-property-unit : {l1 : Level} (X : UU l1) (x : X) → ((l2 : Level) (Y : UU l2) → is-equiv (λ (f : X → Y) → f x)) → is-equiv (ind-unit {P = λ t → X} x) is-equiv-ind-unit-universal-property-unit X x H = is-equiv-is-equiv-precomp ( ind-unit x) ( λ l Y → is-equiv-right-factor ( λ f → f x) ( ev-star (λ t → Y)) ( precomp (ind-unit x) Y) ( λ f → refl) ( universal-property-unit Y) ( H _ Y)) abstract universal-property-unit-is-equiv-ind-unit : {l1 : Level} (X : UU l1) (x : X) → is-equiv (ind-unit {P = λ t → X} x) → ((l2 : Level) (Y : UU l2) → is-equiv (λ (f : X → Y) → f x)) universal-property-unit-is-equiv-ind-unit X x is-equiv-ind-unit l2 Y = is-equiv-comp ( λ f → f x) ( ev-star (λ t → Y)) ( precomp (ind-unit x) Y) ( λ f → refl) ( is-equiv-precomp-is-equiv (ind-unit x) is-equiv-ind-unit Y) ( universal-property-unit Y) -- Exercise 9.11 Eq-sec : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → sec f → sec f → UU (l1 ⊔ l2) Eq-sec f sec-f sec-f' = Σ ( (pr1 sec-f) ~ (pr1 sec-f')) ( λ H → (pr2 sec-f) ~ ((f ·l H) ∙h (pr2 sec-f'))) reflexive-Eq-sec : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (sec-f : sec f) → Eq-sec f sec-f sec-f reflexive-Eq-sec f (pair g G) = pair refl-htpy refl-htpy Eq-sec-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (sec-f sec-f' : sec f) → Id sec-f sec-f' → Eq-sec f sec-f sec-f' Eq-sec-eq f sec-f .sec-f refl = reflexive-Eq-sec f sec-f abstract is-contr-total-Eq-sec : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (sec-f : sec f) → is-contr (Σ (sec f) (Eq-sec f sec-f)) is-contr-total-Eq-sec f (pair g G) = is-contr-total-Eq-structure ( λ g' G' H → G ~ ((f ·l H) ∙h G')) ( is-contr-total-htpy g) ( pair g refl-htpy) ( is-contr-total-htpy G) abstract is-equiv-Eq-sec-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (sec-f sec-f' : sec f) → is-equiv (Eq-sec-eq f sec-f sec-f') is-equiv-Eq-sec-eq f sec-f = fundamental-theorem-id sec-f ( reflexive-Eq-sec f sec-f) ( is-contr-total-Eq-sec f sec-f) ( Eq-sec-eq f sec-f) eq-Eq-sec : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → {sec-f sec-f' : sec f} → Eq-sec f sec-f sec-f' → Id sec-f sec-f' eq-Eq-sec f {sec-f} {sec-f'} = inv-is-equiv (is-equiv-Eq-sec-eq f sec-f sec-f') isretr-section-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) (sec-h : sec h) → ((section-comp f g h H sec-h) ∘ (section-comp' f g h H sec-h)) ~ id isretr-section-comp f g h H (pair k K) (pair l L) = eq-Eq-sec g ( pair ( K ·r l) ( ( htpy-inv ( htpy-assoc ( htpy-inv (H ·r (k ∘ l))) ( H ·r (k ∘ l)) ( (g ·l (K ·r l)) ∙h L))) ∙h ( htpy-ap-concat' ( (htpy-inv (H ·r (k ∘ l))) ∙h (H ·r (k ∘ l))) ( refl-htpy) ( (g ·l (K ·r l)) ∙h L) ( htpy-left-inv (H ·r (k ∘ l)))))) sec-left-factor-retract-of-sec-composition : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → sec h → (sec g) retract-of (sec f) sec-left-factor-retract-of-sec-composition {X = X} f g h H sec-h = pair ( section-comp' f g h H sec-h) ( pair ( section-comp f g h H sec-h) ( isretr-section-comp f g h H sec-h)) Eq-retr : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → retr f → retr f → UU (l1 ⊔ l2) Eq-retr f retr-f retr-f' = Σ ( (pr1 retr-f) ~ (pr1 retr-f')) ( λ H → (pr2 retr-f) ~ ((H ·r f) ∙h (pr2 retr-f'))) reflexive-Eq-retr : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (retr-f : retr f) → Eq-retr f retr-f retr-f reflexive-Eq-retr f (pair h H) = pair refl-htpy refl-htpy Eq-retr-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (retr-f retr-f' : retr f) → Id retr-f retr-f' → Eq-retr f retr-f retr-f' Eq-retr-eq f retr-f .retr-f refl = reflexive-Eq-retr f retr-f abstract is-contr-total-Eq-retr : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (retr-f : retr f) → is-contr (Σ (retr f) (Eq-retr f retr-f)) is-contr-total-Eq-retr f (pair h H) = is-contr-total-Eq-structure ( λ h' H' K → H ~ ((K ·r f) ∙h H')) ( is-contr-total-htpy h) ( pair h refl-htpy) ( is-contr-total-htpy H) abstract is-equiv-Eq-retr-eq : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → (retr-f retr-f' : retr f) → is-equiv (Eq-retr-eq f retr-f retr-f') is-equiv-Eq-retr-eq f retr-f = fundamental-theorem-id retr-f ( reflexive-Eq-retr f retr-f) ( is-contr-total-Eq-retr f retr-f) ( Eq-retr-eq f retr-f) eq-Eq-retr : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → {retr-f retr-f' : retr f} → Eq-retr f retr-f retr-f' → Id retr-f retr-f' eq-Eq-retr f {retr-f} {retr-f'} = inv-is-equiv (is-equiv-Eq-retr-eq f retr-f retr-f') isretr-retraction-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) (retr-g : retr g) → ((retraction-comp f g h H retr-g) ∘ (retraction-comp' f g h H retr-g)) ~ id isretr-retraction-comp f g h H (pair l L) (pair k K) = eq-Eq-retr h ( pair ( k ·l L) ( ( htpy-inv ( htpy-assoc ( htpy-inv ((k ∘ l) ·l H)) ( (k ∘ l) ·l H) ( (k ·l (L ·r h)) ∙h K))) ∙h ( htpy-ap-concat' ( (htpy-inv ((k ∘ l) ·l H)) ∙h ((k ∘ l) ·l H)) ( refl-htpy) ( (k ·l (L ·r h)) ∙h K) ( htpy-left-inv ((k ∘ l) ·l H))))) sec-right-factor-retract-of-sec-left-factor : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → retr g → (retr h) retract-of (retr f) sec-right-factor-retract-of-sec-left-factor f g h H retr-g = pair ( retraction-comp' f g h H retr-g) ( pair ( retraction-comp f g h H retr-g) ( isretr-retraction-comp f g h H retr-g)) -- Exercise 9.12 postcomp-Π : {l1 l2 l3 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} (e : (i : I) → A i → B i) → ((i : I) → A i) → ((i : I) → B i) postcomp-Π e f i = e i (f i) htpy-postcomp-Π : {l1 l2 l3 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} {f f' : (i : I) → A i → B i} (H : (i : I) → (f i) ~ (f' i)) → (postcomp-Π f) ~ (postcomp-Π f') htpy-postcomp-Π H h = eq-htpy (λ i → H i (h i)) abstract is-equiv-postcomp-Π : {l1 l2 l3 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} (e : (i : I) → A i → B i) (is-equiv-e : is-fiberwise-equiv e) → is-equiv (postcomp-Π e) is-equiv-postcomp-Π e is-equiv-e = is-equiv-has-inverse ( λ g i → inv-is-equiv (is-equiv-e i) (g i)) ( λ g → eq-htpy (λ i → issec-inv-is-equiv (is-equiv-e i) (g i))) ( λ f → eq-htpy (λ i → isretr-inv-is-equiv (is-equiv-e i) (f i))) equiv-postcomp-Π : {l1 l2 l3 : Level} {I : UU l1} {A : I → UU l2} {B : I → UU l3} (e : (i : I) → (A i) ≃ (B i)) → ((i : I) → A i) ≃ ((i : I) → B i) equiv-postcomp-Π e = pair ( postcomp-Π (λ i → map-equiv (e i))) ( is-equiv-postcomp-Π _ (λ i → is-equiv-map-equiv (e i))) -- Exercise 9.13 hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → UU (l1 ⊔ (l2 ⊔ l3)) hom-slice {A = A} {B} f g = Σ (A → B) (λ h → f ~ (g ∘ h)) map-hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → hom-slice f g → A → B map-hom-slice f g h = pr1 h triangle-hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) (h : hom-slice f g) → f ~ (g ∘ (map-hom-slice f g h)) triangle-hom-slice f g h = pr2 h fiberwise-hom-hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → hom-slice f g → (x : X) → (fib f x) → (fib g x) fiberwise-hom-hom-slice f g (pair h H) = fib-triangle f g h H hom-slice-fiberwise-hom : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → ((x : X) → (fib f x) → (fib g x)) → hom-slice f g hom-slice-fiberwise-hom f g α = pair ( λ a → pr1 (α (f a) (pair a refl))) ( λ a → inv (pr2 (α (f a) (pair a refl)))) issec-hom-slice-fiberwise-hom-eq-htpy : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) (α : (x : X) → (fib f x) → (fib g x)) (x : X) → (fiberwise-hom-hom-slice f g (hom-slice-fiberwise-hom f g α) x) ~ (α x) issec-hom-slice-fiberwise-hom-eq-htpy f g α .(f a) (pair a refl) = eq-pair refl (inv-inv (pr2 (α (f a) (pair a refl)))) issec-hom-slice-fiberwise-hom : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → ((fiberwise-hom-hom-slice f g) ∘ (hom-slice-fiberwise-hom f g)) ~ id issec-hom-slice-fiberwise-hom f g α = eq-htpy (λ x → eq-htpy (issec-hom-slice-fiberwise-hom-eq-htpy f g α x)) isretr-hom-slice-fiberwise-hom : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → ((hom-slice-fiberwise-hom f g) ∘ (fiberwise-hom-hom-slice f g)) ~ id isretr-hom-slice-fiberwise-hom f g (pair h H) = eq-pair refl (eq-htpy (λ a → (inv-inv (H a)))) abstract is-equiv-fiberwise-hom-hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → is-equiv (fiberwise-hom-hom-slice f g) is-equiv-fiberwise-hom-hom-slice f g = is-equiv-has-inverse ( hom-slice-fiberwise-hom f g) ( issec-hom-slice-fiberwise-hom f g) ( isretr-hom-slice-fiberwise-hom f g) abstract is-equiv-hom-slice-fiberwise-hom : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → is-equiv (hom-slice-fiberwise-hom f g) is-equiv-hom-slice-fiberwise-hom f g = is-equiv-has-inverse ( fiberwise-hom-hom-slice f g) ( isretr-hom-slice-fiberwise-hom f g) ( issec-hom-slice-fiberwise-hom f g) equiv-slice : {l1 l2 l3 : Level} (X : UU l1) {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → UU (l1 ⊔ (l2 ⊔ l3)) equiv-slice X {A} {B} f g = Σ (A ≃ B) (λ e → f ~ (g ∘ (map-equiv e))) hom-slice-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → equiv-slice X f g → hom-slice f g hom-slice-equiv-slice f g (pair (pair h is-equiv-h) H) = pair h H {- We first prove two closely related generic lemmas that establishes equivalences of subtypes -} abstract is-equiv-subtype-is-equiv : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} {Q : B → UU l4} (is-subtype-P : is-subtype P) (is-subtype-Q : is-subtype Q) (f : A → B) (g : (x : A) → P x → Q (f x)) → is-equiv f → ((x : A) → (Q (f x)) → P x) → is-equiv (toto Q f g) is-equiv-subtype-is-equiv {Q = Q} is-subtype-P is-subtype-Q f g is-equiv-f h = is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map Q f g is-equiv-f ( λ x → is-equiv-is-prop (is-subtype-P x) (is-subtype-Q (f x)) (h x)) abstract is-equiv-subtype-is-equiv' : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} {Q : B → UU l4} (is-subtype-P : is-subtype P) (is-subtype-Q : is-subtype Q) (f : A → B) (g : (x : A) → P x → Q (f x)) → (is-equiv-f : is-equiv f) → ((y : B) → (Q y) → P (inv-is-equiv is-equiv-f y)) → is-equiv (toto Q f g) is-equiv-subtype-is-equiv' {P = P} {Q} is-subtype-P is-subtype-Q f g is-equiv-f h = is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map Q f g is-equiv-f ( λ x → is-equiv-is-prop (is-subtype-P x) (is-subtype-Q (f x)) ( (tr P (isretr-inv-is-equiv is-equiv-f x)) ∘ (h (f x)))) abstract is-fiberwise-equiv-fiberwise-equiv-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) (t : hom-slice f g) → is-equiv (pr1 t) → is-fiberwise-equiv (fiberwise-hom-hom-slice f g t) is-fiberwise-equiv-fiberwise-equiv-equiv-slice f g (pair h H) = is-fiberwise-equiv-is-equiv-triangle f g h H left-factor-fiberwise-equiv-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → Σ (hom-slice f g) (λ hH → is-equiv (pr1 hH)) → Σ ((x : X) → (fib f x) → (fib g x)) is-fiberwise-equiv left-factor-fiberwise-equiv-equiv-slice f g = toto ( is-fiberwise-equiv) ( fiberwise-hom-hom-slice f g) ( is-fiberwise-equiv-fiberwise-equiv-equiv-slice f g) swap-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → equiv-slice X f g → Σ (hom-slice f g) (λ hH → is-equiv (pr1 hH)) swap-equiv-slice {A = A} {B} f g = double-structure-swap (A → B) is-equiv (λ h → f ~ (g ∘ h)) abstract is-equiv-swap-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → is-equiv (swap-equiv-slice f g) is-equiv-swap-equiv-slice f g = is-equiv-double-structure-swap _ is-equiv (λ h → (f ~ (g ∘ h))) abstract fiberwise-equiv-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → equiv-slice X f g → Σ ((x : X) → (fib f x) → (fib g x)) is-fiberwise-equiv fiberwise-equiv-equiv-slice {X = X} {A} {B} f g = ( left-factor-fiberwise-equiv-equiv-slice f g) ∘ ( swap-equiv-slice f g) abstract is-equiv-hom-slice-is-fiberwise-equiv-fiberwise-hom-hom-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → (t : hom-slice f g) → ((x : X) → is-equiv (fiberwise-hom-hom-slice f g t x)) → is-equiv (pr1 t) is-equiv-hom-slice-is-fiberwise-equiv-fiberwise-hom-hom-slice f g (pair h H) = is-equiv-triangle-is-fiberwise-equiv f g h H abstract is-equiv-fiberwise-equiv-equiv-slice : {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} {B : UU l3} (f : A → X) (g : B → X) → is-equiv (fiberwise-equiv-equiv-slice f g) is-equiv-fiberwise-equiv-equiv-slice {X = X} {A} {B} f g = is-equiv-comp ( fiberwise-equiv-equiv-slice f g) ( left-factor-fiberwise-equiv-equiv-slice f g) ( swap-equiv-slice f g) ( refl-htpy) ( is-equiv-swap-equiv-slice f g) ( is-equiv-subtype-is-equiv ( λ t → is-subtype-is-equiv (pr1 t)) ( λ α → is-prop-Π (λ x → is-subtype-is-equiv (α x))) ( fiberwise-hom-hom-slice f g) ( is-fiberwise-equiv-fiberwise-equiv-equiv-slice f g) ( is-equiv-fiberwise-hom-hom-slice f g) ( is-equiv-hom-slice-is-fiberwise-equiv-fiberwise-hom-hom-slice f g)) -- Exercise 9.14 hom-over-morphism : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → UU (l1 ⊔ (l2 ⊔ l4)) hom-over-morphism i f g = hom-slice (i ∘ f) g fiberwise-hom-hom-over-morphism : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → hom-over-morphism i f g → (x : X) → (fib f x) → (fib g (i x)) fiberwise-hom-hom-over-morphism i f g (pair h H) .(f a) (pair a refl) = pair (h a) (inv (H a)) hom-over-morphism-fiberwise-hom : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → ((x : X) → (fib f x) → (fib g (i x))) → hom-over-morphism i f g hom-over-morphism-fiberwise-hom i f g α = pair ( λ a → pr1 (α (f a) (pair a refl))) ( λ a → inv (pr2 (α (f a) (pair a refl)))) issec-hom-over-morphism-fiberwise-hom-eq-htpy : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → (α : (x : X) → (fib f x) → (fib g (i x))) (x : X) → ( fiberwise-hom-hom-over-morphism i f g ( hom-over-morphism-fiberwise-hom i f g α) x) ~ (α x) issec-hom-over-morphism-fiberwise-hom-eq-htpy i f g α .(f a) (pair a refl) = eq-pair refl (inv-inv (pr2 (α (f a) (pair a refl)))) issec-hom-over-morphism-fiberwise-hom : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → ( ( fiberwise-hom-hom-over-morphism i f g) ∘ ( hom-over-morphism-fiberwise-hom i f g)) ~ id issec-hom-over-morphism-fiberwise-hom i f g α = eq-htpy ( λ x → ( eq-htpy ( issec-hom-over-morphism-fiberwise-hom-eq-htpy i f g α x))) isretr-hom-over-morphism-fiberwise-hom : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → ( ( hom-over-morphism-fiberwise-hom i f g) ∘ ( fiberwise-hom-hom-over-morphism i f g)) ~ id isretr-hom-over-morphism-fiberwise-hom i f g (pair h H) = eq-pair refl (eq-htpy (λ a → (inv-inv (H a)))) abstract is-equiv-fiberwise-hom-hom-over-morphism : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → is-equiv (fiberwise-hom-hom-over-morphism i f g) is-equiv-fiberwise-hom-hom-over-morphism i f g = is-equiv-has-inverse ( hom-over-morphism-fiberwise-hom i f g) ( issec-hom-over-morphism-fiberwise-hom i f g) ( isretr-hom-over-morphism-fiberwise-hom i f g) abstract is-equiv-hom-over-morphism-fiberwise-hom : {l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {Y : UU l4} (i : X → Y) (f : A → X) (g : B → Y) → is-equiv (hom-over-morphism-fiberwise-hom i f g) is-equiv-hom-over-morphism-fiberwise-hom i f g = is-equiv-has-inverse ( fiberwise-hom-hom-over-morphism i f g) ( isretr-hom-over-morphism-fiberwise-hom i f g) ( issec-hom-over-morphism-fiberwise-hom i f g) -- Exercise 9.15 set-isomorphism : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → UU (l1 ⊔ l2) set-isomorphism A B = Σ ((pr1 A) → (pr1 B)) has-inverse has-inverse-is-half-adjoint-equivalence : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-half-adjoint-equivalence f → has-inverse f has-inverse-is-half-adjoint-equivalence f = tot (λ g → tot (λ G → pr1)) set-isomorphism-equiv-fiberwise : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → (f : (pr1 A) → (pr1 B)) → is-equiv f → has-inverse f set-isomorphism-equiv-fiberwise A B f = ( has-inverse-is-half-adjoint-equivalence f) ∘ ( is-half-adjoint-equivalence-is-equiv f) abstract is-equiv-has-inverse-is-half-adjoint-equivalence-is-set : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) (f : (pr1 A) → (pr1 B)) → is-equiv (has-inverse-is-half-adjoint-equivalence f) is-equiv-has-inverse-is-half-adjoint-equivalence-is-set (pair A is-set-A) (pair B is-set-B) f = is-equiv-tot-is-fiberwise-equiv ( λ g → is-equiv-tot-is-fiberwise-equiv ( λ G → is-equiv-pr1-is-contr ( coherence-is-half-adjoint-equivalence f g G) ( λ H → is-contr-Π ( λ x → is-set-B _ _ (G (f x)) (ap f (H x)))))) abstract is-fiberwise-equiv-set-isomorphism-equiv-fiberwise : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → is-fiberwise-equiv (set-isomorphism-equiv-fiberwise A B) is-fiberwise-equiv-set-isomorphism-equiv-fiberwise A B f = is-equiv-comp ( set-isomorphism-equiv-fiberwise A B f) ( has-inverse-is-half-adjoint-equivalence f) ( is-half-adjoint-equivalence-is-equiv f) ( refl-htpy) ( is-equiv-is-half-adjoint-equivalence-is-equiv f) ( is-equiv-has-inverse-is-half-adjoint-equivalence-is-set A B f) set-isomorphism-equiv : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → ((pr1 A) ≃ (pr1 B)) → set-isomorphism A B set-isomorphism-equiv A B = tot (set-isomorphism-equiv-fiberwise A B) abstract is-equiv-set-isomorphism-equiv : {l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → is-equiv (set-isomorphism-equiv A B) is-equiv-set-isomorphism-equiv A B = is-equiv-tot-is-fiberwise-equiv ( is-fiberwise-equiv-set-isomorphism-equiv-fiberwise A B) {- Some lemmas about equivalences on Π-types -} abstract is-equiv-htpy-inv-con : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g h : (x : A) → B x} ( H : f ~ g) (K : g ~ h) (L : f ~ h) → is-equiv (htpy-inv-con H K L) is-equiv-htpy-inv-con H K L = is-equiv-postcomp-Π _ (λ x → is-equiv-inv-con (H x) (K x) (L x)) equiv-htpy-inv-con : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g h : (x : A) → B x} ( H : f ~ g) (K : g ~ h) (L : f ~ h) → ( (H ∙h K) ~ L) ≃ (K ~ ((htpy-inv H) ∙h L)) equiv-htpy-inv-con H K L = pair ( htpy-inv-con H K L) ( is-equiv-htpy-inv-con H K L) abstract is-equiv-htpy-con-inv : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g h : (x : A) → B x} ( H : f ~ g) (K : g ~ h) (L : f ~ h) → is-equiv (htpy-con-inv H K L) is-equiv-htpy-con-inv H K L = is-equiv-postcomp-Π _ (λ x → is-equiv-con-inv (H x) (K x) (L x)) equiv-htpy-con-inv : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} {f g h : (x : A) → B x} ( H : f ~ g) (K : g ~ h) (L : f ~ h) → ( (H ∙h K) ~ L) ≃ (H ~ (L ∙h (htpy-inv K))) equiv-htpy-con-inv H K L = pair ( htpy-con-inv H K L) ( is-equiv-htpy-con-inv H K L) map-equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e : A' ≃ A) (f : (a' : A') → B' a' ≃ B (map-equiv e a')) → ( (a' : A') → B' a') → ( (a : A) → B a) map-equiv-Π {B' = B'} B e f = ( postcomp-Π (λ a → ( tr B (issec-inv-is-equiv (is-equiv-map-equiv e) a)) ∘ ( map-equiv (f (inv-is-equiv (is-equiv-map-equiv e) a))))) ∘ ( precomp-Π (inv-is-equiv (is-equiv-map-equiv e)) B') id-map-equiv-Π : { l1 l2 : Level} {A : UU l1} (B : A → UU l2) → ( map-equiv-Π B (equiv-id A) (λ a → equiv-id (B a))) ~ id id-map-equiv-Π B = refl-htpy abstract is-equiv-map-equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e : A' ≃ A) (f : (a' : A') → B' a' ≃ B (map-equiv e a')) → is-equiv (map-equiv-Π B e f) is-equiv-map-equiv-Π {B' = B'} B e f = is-equiv-comp' ( postcomp-Π (λ a → ( tr B (issec-inv-is-equiv (is-equiv-map-equiv e) a)) ∘ ( map-equiv (f (inv-is-equiv (is-equiv-map-equiv e) a))))) ( precomp-Π (inv-is-equiv (is-equiv-map-equiv e)) B') ( is-equiv-precomp-Π-is-equiv ( inv-is-equiv (is-equiv-map-equiv e)) ( is-equiv-inv-is-equiv (is-equiv-map-equiv e)) ( B')) ( is-equiv-postcomp-Π _ ( λ a → is-equiv-comp' ( tr B (issec-inv-is-equiv (is-equiv-map-equiv e) a)) ( map-equiv (f (inv-is-equiv (is-equiv-map-equiv e) a))) ( is-equiv-map-equiv (f (inv-is-equiv (is-equiv-map-equiv e) a))) ( is-equiv-tr B (issec-inv-is-equiv (is-equiv-map-equiv e) a)))) equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e : A' ≃ A) (f : (a' : A') → B' a' ≃ B (map-equiv e a')) → ( (a' : A') → B' a') ≃ ( (a : A) → B a) equiv-Π B e f = pair (map-equiv-Π B e f) (is-equiv-map-equiv-Π B e f) HTPY-map-equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} (B' : A' → UU l2) {A : UU l3} (B : A → UU l4) ( e e' : A' ≃ A) (H : htpy-equiv e e') → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) HTPY-map-equiv-Π {A' = A'} B' {A} B e e' H = ( f : (a' : A') → B' a' ≃ B (map-equiv e a')) → ( f' : (a' : A') → B' a' ≃ B (map-equiv e' a')) → ( K : (a' : A') → ((tr B (H a')) ∘ (map-equiv (f a'))) ~ (map-equiv (f' a'))) → ( map-equiv-Π B e f) ~ (map-equiv-Π B e' f') htpy-map-equiv-Π-refl-htpy : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e : A' ≃ A) → HTPY-map-equiv-Π B' B e e (reflexive-htpy-equiv e) htpy-map-equiv-Π-refl-htpy {B' = B'} B e f f' K = ( htpy-postcomp-Π ( λ a → ( tr B (issec-inv-is-equiv (is-equiv-map-equiv e) a)) ·l ( K (inv-is-equiv (is-equiv-map-equiv e) a)))) ·r ( precomp-Π (inv-is-equiv (is-equiv-map-equiv e)) B') abstract htpy-map-equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e e' : A' ≃ A) (H : htpy-equiv e e') → HTPY-map-equiv-Π B' B e e' H htpy-map-equiv-Π {B' = B'} B e e' H f f' K = ind-htpy-equiv e ( HTPY-map-equiv-Π B' B e) ( htpy-map-equiv-Π-refl-htpy B e) e' H f f' K comp-htpy-map-equiv-Π : { l1 l2 l3 l4 : Level} { A' : UU l1} {B' : A' → UU l2} {A : UU l3} (B : A → UU l4) ( e : A' ≃ A) → Id ( htpy-map-equiv-Π {B' = B'} B e e (reflexive-htpy-equiv e)) ( ( htpy-map-equiv-Π-refl-htpy B e)) comp-htpy-map-equiv-Π {B' = B'} B e = comp-htpy-equiv e ( HTPY-map-equiv-Π B' B e) ( htpy-map-equiv-Π-refl-htpy B e) map-automorphism-Π : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} ( e : A ≃ A) (f : (a : A) → B a ≃ B (map-equiv e a)) → ( (a : A) → B a) → ((a : A) → B a) map-automorphism-Π {B = B} e f = ( postcomp-Π (λ a → (inv-is-equiv (is-equiv-map-equiv (f a))))) ∘ ( precomp-Π (map-equiv e) B) abstract is-equiv-map-automorphism-Π : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} ( e : A ≃ A) (f : (a : A) → B a ≃ B (map-equiv e a)) → is-equiv (map-automorphism-Π e f) is-equiv-map-automorphism-Π {B = B} e f = is-equiv-comp' _ _ ( is-equiv-precomp-Π-is-equiv _ (is-equiv-map-equiv e) B) ( is-equiv-postcomp-Π _ ( λ a → is-equiv-inv-is-equiv (is-equiv-map-equiv (f a)))) automorphism-Π : { l1 l2 : Level} {A : UU l1} {B : A → UU l2} ( e : A ≃ A) (f : (a : A) → B a ≃ B (map-equiv e a)) → ( (a : A) → B a) ≃ ((a : A) → B a) automorphism-Π e f = pair (map-automorphism-Π e f) (is-equiv-map-automorphism-Π e f) -- is-contr-total-Eq-Π is-contr-total-Eq-Π : { l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} (C : (x : A) → B x → UU l3) → ( is-contr-total-C : (x : A) → is-contr (Σ (B x) (C x))) → ( f : (x : A) → B x) → is-contr (Σ ((x : A) → B x) (λ g → (x : A) → C x (g x))) is-contr-total-Eq-Π {A = A} {B} C is-contr-total-C f = is-contr-equiv' ( (x : A) → Σ (B x) (C x)) ( equiv-choice-∞) ( is-contr-Π is-contr-total-C)
{ "alphanum_fraction": 0.519982006, "avg_line_length": 35.2852022529, "ext": "agda", "hexsha": "4c674ab91606e7d477cb87659262326ed5656725", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_path": "Agda/11-function-extensionality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_path": "Agda/11-function-extensionality.agda", "max_line_length": 220, "max_stars_count": null, "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_path": "Agda/11-function-extensionality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 29506, "size": 68912 }
{-# 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} → Pullback (universal mono) true unique : ∀ {X Y} {f : X ⇒ Y} {g} {mono : Mono f} → Pullback g true → universal mono ≈ g
{ "alphanum_fraction": 0.6703539823, "avg_line_length": 29.1612903226, "ext": "agda", "hexsha": "0d5cabf334b2c54000a35fb0d1ef0a7d00110d07", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Diagram/SubobjectClassifier.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Diagram/SubobjectClassifier.agda", "max_line_length": 94, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Diagram/SubobjectClassifier.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 254, "size": 904 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to negation ------------------------------------------------------------------------ module Relation.Nullary.Negation where open import Relation.Nullary open import Relation.Unary open import Data.Bool open import Data.Empty open import Function open import Data.Product as Prod open import Data.Fin using (Fin) open import Data.Fin.Dec open import Data.Sum as Sum open import Category.Monad open import Level contradiction : ∀ {p w} {P : Set p} {Whatever : Set w} → P → ¬ P → Whatever contradiction p ¬p = ⊥-elim (¬p p) contraposition : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → ¬ Q → ¬ P contraposition f ¬q p = contradiction (f p) ¬q -- Note also the following use of flip: private note : ∀ {p q} {P : Set p} {Q : Set q} → (P → ¬ Q) → Q → ¬ P note = flip -- If we can decide P, then we can decide its negation. ¬? : ∀ {p} {P : Set p} → Dec P → Dec (¬ P) ¬? (yes p) = no (λ ¬p → ¬p p) ¬? (no ¬p) = yes ¬p ------------------------------------------------------------------------ -- Quantifier juggling ∃⟶¬∀¬ : ∀ {a p} {A : Set a} {P : A → Set p} → ∃ P → ¬ (∀ x → ¬ P x) ∃⟶¬∀¬ = flip uncurry ∀⟶¬∃¬ : ∀ {a p} {A : Set a} {P : A → Set p} → (∀ x → P x) → ¬ ∃ λ x → ¬ P x ∀⟶¬∃¬ ∀xPx (x , ¬Px) = ¬Px (∀xPx x) ¬∃⟶∀¬ : ∀ {a p} {A : Set a} {P : A → Set p} → ¬ ∃ (λ x → P x) → ∀ x → ¬ P x ¬∃⟶∀¬ = curry ∀¬⟶¬∃ : ∀ {a p} {A : Set a} {P : A → Set p} → (∀ x → ¬ P x) → ¬ ∃ (λ x → P x) ∀¬⟶¬∃ = uncurry ∃¬⟶¬∀ : ∀ {a p} {A : Set a} {P : A → Set p} → ∃ (λ x → ¬ P x) → ¬ (∀ x → P x) ∃¬⟶¬∀ = flip ∀⟶¬∃¬ -- When P is a decidable predicate over a finite set the following -- lemma can be proved. ¬∀⟶∃¬ : ∀ n {p} (P : Fin n → Set p) → Decidable P → ¬ (∀ i → P i) → ∃ λ i → ¬ P i ¬∀⟶∃¬ n P dec ¬P = Prod.map id proj₁ $ ¬∀⟶∃¬-smallest n P dec ¬P ------------------------------------------------------------------------ -- Double-negation ¬¬-map : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → ¬ ¬ P → ¬ ¬ Q ¬¬-map f = contraposition (contraposition f) -- Stability under double-negation. Stable : ∀ {ℓ} → Set ℓ → Set ℓ Stable P = ¬ ¬ P → P -- Everything is stable in the double-negation monad. stable : ∀ {p} {P : Set p} → ¬ ¬ Stable P stable ¬[¬¬p→p] = ¬[¬¬p→p] (λ ¬¬p → ⊥-elim (¬¬p (¬[¬¬p→p] ∘ const))) -- Negated predicates are stable. negated-stable : ∀ {p} {P : Set p} → Stable (¬ P) negated-stable ¬¬¬P P = ¬¬¬P (λ ¬P → ¬P P) -- Decidable predicates are stable. decidable-stable : ∀ {p} {P : Set p} → Dec P → Stable P decidable-stable (yes p) ¬¬p = p decidable-stable (no ¬p) ¬¬p = ⊥-elim (¬¬p ¬p) ¬-drop-Dec : ∀ {p} {P : Set p} → Dec (¬ ¬ P) → Dec (¬ P) ¬-drop-Dec (yes ¬¬p) = no ¬¬p ¬-drop-Dec (no ¬¬¬p) = yes (negated-stable ¬¬¬p) -- Double-negation is a monad (if we assume that all elements of ¬ ¬ P -- are equal). ¬¬-Monad : ∀ {p} → RawMonad (λ (P : Set p) → ¬ ¬ P) ¬¬-Monad = record { return = contradiction ; _>>=_ = λ x f → negated-stable (¬¬-map f x) } ¬¬-push : ∀ {p q} {P : Set p} {Q : P → Set q} → ¬ ¬ ((x : P) → Q x) → (x : P) → ¬ ¬ Q x ¬¬-push ¬¬P⟶Q P ¬Q = ¬¬P⟶Q (λ P⟶Q → ¬Q (P⟶Q P)) -- A double-negation-translated variant of excluded middle (or: every -- nullary relation is decidable in the double-negation monad). excluded-middle : ∀ {p} {P : Set p} → ¬ ¬ Dec P excluded-middle ¬h = ¬h (no (λ p → ¬h (yes p))) -- If Whatever is instantiated with ¬ ¬ something, then this function -- is call with current continuation in the double-negation monad, or, -- if you will, a double-negation translation of Peirce's law. -- -- In order to prove ¬ ¬ P one can assume ¬ P and prove ⊥. However, -- sometimes it is nice to avoid leaving the double-negation monad; in -- that case this function can be used (with Whatever instantiated to -- ⊥). call/cc : ∀ {w p} {Whatever : Set w} {P : Set p} → ((P → Whatever) → ¬ ¬ P) → ¬ ¬ P call/cc hyp ¬p = hyp (λ p → ⊥-elim (¬p p)) ¬p -- The "independence of premise" rule, in the double-negation monad. -- It is assumed that the index set (Q) is inhabited. independence-of-premise : ∀ {p q r} {P : Set p} {Q : Set q} {R : Q → Set r} → Q → (P → Σ Q R) → ¬ ¬ (Σ[ x ∈ Q ] (P → R x)) independence-of-premise {P = P} q f = ¬¬-map helper excluded-middle where helper : Dec P → _ helper (yes p) = Prod.map id const (f p) helper (no ¬p) = (q , ⊥-elim ∘′ ¬p) -- The independence of premise rule for binary sums. independence-of-premise-⊎ : ∀ {p q r} {P : Set p} {Q : Set q} {R : Set r} → (P → Q ⊎ R) → ¬ ¬ ((P → Q) ⊎ (P → R)) independence-of-premise-⊎ {P = P} f = ¬¬-map helper excluded-middle where helper : Dec P → _ helper (yes p) = Sum.map const const (f p) helper (no ¬p) = inj₁ (⊥-elim ∘′ ¬p) private -- Note that independence-of-premise-⊎ is a consequence of -- independence-of-premise (for simplicity it is assumed that Q and -- R have the same type here): corollary : ∀ {p ℓ} {P : Set p} {Q R : Set ℓ} → (P → Q ⊎ R) → ¬ ¬ ((P → Q) ⊎ (P → R)) corollary {P = P} {Q} {R} f = ¬¬-map helper (independence-of-premise true ([ _,_ true , _,_ false ] ∘′ f)) where helper : ∃ (λ b → P → if b then Q else R) → (P → Q) ⊎ (P → R) helper (true , f) = inj₁ f helper (false , f) = inj₂ f -- The classical statements of excluded middle and double-negation -- elimination. Excluded-Middle : (ℓ : Level) → Set (suc ℓ) Excluded-Middle p = {P : Set p} → Dec P Double-Negation-Elimination : (ℓ : Level) → Set (suc ℓ) Double-Negation-Elimination p = {P : Set p} → Stable P private -- The two statements above are equivalent. The proofs are so -- simple, given the definitions above, that they are not exported. em⇒dne : ∀ {ℓ} → Excluded-Middle ℓ → Double-Negation-Elimination ℓ em⇒dne em = decidable-stable em dne⇒em : ∀ {ℓ} → Double-Negation-Elimination ℓ → Excluded-Middle ℓ dne⇒em dne = dne excluded-middle
{ "alphanum_fraction": 0.5249626804, "avg_line_length": 31.0773195876, "ext": "agda", "hexsha": "ba2ce61e6e5c027971ea61e05b1a6fa33298ccf2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Nullary/Negation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Nullary/Negation.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Nullary/Negation.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 2246, "size": 6029 }
{-# OPTIONS --without-K #-} module hott where open import hott.level public open import hott.equivalence public open import hott.univalence public -- open import hott.truncation public
{ "alphanum_fraction": 0.7807486631, "avg_line_length": 20.7777777778, "ext": "agda", "hexsha": "f6effcd58cb512ea9afb6c98d918db190b318a96", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z", "max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "HoTT/M-types", "max_forks_repo_path": "hott.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "HoTT/M-types", "max_issues_repo_path": "hott.agda", "max_line_length": 37, "max_stars_count": 27, "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_path": "hott.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "num_tokens": 39, "size": 187 }
postulate A : Set data B (a : A) : Set where conB : B a → B a data C (a : A) : B a → Set where conC : (b : B a) → C a (conB b) goo : (a1 a2 a3 : A) (c : C a1 _) → Set goo a1 a2 a3 (conC b) = {!!}
{ "alphanum_fraction": 0.4829268293, "avg_line_length": 17.0833333333, "ext": "agda", "hexsha": "eb185f26a5d4682896c1bf4f3c1568962a62ae92", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue2679c.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue2679c.agda", "max_line_length": 39, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue2679c.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 98, "size": 205 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Sublist-related properties ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Sublist.Propositional.Disjoint {a} {A : Set a} where open import Data.List.Base using (List) open import Data.List.Relation.Binary.Sublist.Propositional open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong) ------------------------------------------------------------------------ -- A Union where the triangles commute is a -- Cospan in the slice category (_ ⊆ zs). record IsCospan {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (u : UpperBound τ₁ τ₂) : Set a where field tri₁ : ⊆-trans (UpperBound.inj₁ u) (UpperBound.sub u) ≡ τ₁ tri₂ : ⊆-trans (UpperBound.inj₂ u) (UpperBound.sub u) ≡ τ₂ record Cospan {xs ys zs : List A} (τ₁ : xs ⊆ zs) (τ₂ : ys ⊆ zs) : Set a where field upperBound : UpperBound τ₁ τ₂ isCospan : IsCospan upperBound open UpperBound upperBound public open IsCospan isCospan public open IsCospan open Cospan module _ {x : A} {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (d : Disjoint τ₁ τ₂) (c : IsCospan (⊆-disjoint-union d)) where ∷ₙ-cospan : IsCospan (⊆-disjoint-union (x ∷ₙ d)) ∷ₙ-cospan = record { tri₁ = cong (x ∷ʳ_) (c .tri₁) ; tri₂ = cong (x ∷ʳ_) (c .tri₂) } ∷ₗ-cospan : IsCospan (⊆-disjoint-union (refl {x = x} ∷ₗ d)) ∷ₗ-cospan = record { tri₁ = cong (refl ∷_) (c .tri₁) ; tri₂ = cong (x ∷ʳ_) (c .tri₂) } ∷ᵣ-cospan : IsCospan (⊆-disjoint-union (refl {x = x} ∷ᵣ d)) ∷ᵣ-cospan = record { tri₁ = cong (x ∷ʳ_) (c .tri₁) ; tri₂ = cong (refl ∷_) (c .tri₂) } ⊆-disjoint-union-is-cospan : ∀ {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} → (d : Disjoint τ₁ τ₂) → IsCospan (⊆-disjoint-union d) ⊆-disjoint-union-is-cospan [] = record { tri₁ = refl ; tri₂ = refl } ⊆-disjoint-union-is-cospan (x ∷ₙ d) = ∷ₙ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-is-cospan (refl ∷ₗ d) = ∷ₗ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-is-cospan (refl ∷ᵣ d) = ∷ᵣ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-cospan : ∀ {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} → Disjoint τ₁ τ₂ → Cospan τ₁ τ₂ ⊆-disjoint-union-cospan d = record { upperBound = ⊆-disjoint-union d ; isCospan = ⊆-disjoint-union-is-cospan d }
{ "alphanum_fraction": 0.5691747573, "avg_line_length": 34.8169014085, "ext": "agda", "hexsha": "576644a77a022d5664ddfa2517dffbebff8be471", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda", "max_line_length": 102, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 961, "size": 2472 }
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.MaybeEmbed {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Substitution open import Tools.Product -- Any level can be embedded into the highest level (validity variant). maybeEmbᵛ : ∀ {l A r Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A ^ r / [Γ] → Γ ⊩ᵛ⟨ ∞ ⟩ A ^ r / [Γ] maybeEmbᵛ {ι ⁰} [Γ] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ [σ]) [σA]′ = maybeEmb (proj₁ ([A] ⊢Δ [σ])) in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′])) maybeEmbᵛ {ι ¹} [Γ] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ [σ]) [σA]′ = maybeEmb (proj₁ ([A] ⊢Δ [σ])) in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′])) maybeEmbᵛ {∞} [Γ] [A] ⊢Δ [σ] = [A] ⊢Δ [σ] maybeEmbTermᵛ : ∀ {l A t r Γ} → ([Γ] : ⊩ᵛ Γ) → ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ r / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ t ∷ A ^ r / [Γ] / [A] → Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ r / [Γ] / maybeEmbᵛ {A = A} [Γ] [A] maybeEmbTermᵛ {ι ⁰} [Γ] [A] [t] = [t] maybeEmbTermᵛ {ι ¹} [Γ] [A] [t] = [t] maybeEmbTermᵛ {∞} [Γ] [A] [t] = [t] -- The lowest level can be embedded in any level (validity variant). maybeEmbₛ′ : ∀ {l A r Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ ι ⁰ ⟩ A ^ r / [Γ] → Γ ⊩ᵛ⟨ l ⟩ A ^ r / [Γ] maybeEmbₛ′ {ι ⁰} [Γ] [A] = [A] maybeEmbₛ′ {ι ¹} [Γ] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ [σ]) [σA]′ = maybeEmb′ (<is≤ 0<1) (proj₁ ([A] ⊢Δ [σ])) in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′])) maybeEmbₛ′ {∞} [Γ] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ [σ]) [σA]′ = maybeEmb (proj₁ ([A] ⊢Δ [σ])) in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq [σA] [σA]′ (proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′])) maybeEmbEqTermᵛ : ∀ {l A t u r Γ} → ([Γ] : ⊩ᵛ Γ) → ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ r / [Γ] ) → Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A ^ r / [Γ] / [A] → Γ ⊩ᵛ⟨ ∞ ⟩ t ≡ u ∷ A ^ r / [Γ] / maybeEmbᵛ {A = A} [Γ] [A] maybeEmbEqTermᵛ {ι ⁰} [Γ] [A] [t≡u] = [t≡u] maybeEmbEqTermᵛ {ι ¹} [Γ] [A] [t≡u] = [t≡u] maybeEmbEqTermᵛ {∞} [Γ] [A] [t≡u] = [t≡u]
{ "alphanum_fraction": 0.4693277311, "avg_line_length": 34, "ext": "agda", "hexsha": "88f466b57c61c33d26fd7efdc9617b41107c4b5e", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda", "max_line_length": 84, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/MaybeEmbed.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 1270, "size": 2380 }
module WeakArrows where open import Library open import Categories record Arrow {l m}(J : Cat {l}{m}) : Set (lsuc (l ⊔ m)) where constructor arrow open Cat J field R : Obj → Obj → Set m pure : ∀{X Y} -> Hom X Y -> R X Y _<<<_ : ∀{X Y Z} → R Y Z -> R X Y -> R X Z alaw1 : ∀{X Y Z}(g : Hom Y Z)(f : Hom X Y) -> pure (comp g f) ≅ pure g <<< pure f alaw2 : ∀{X Y}(s : R X Y) -> s <<< pure iden ≅ s alaw3 : ∀{X Y}(r : R X Y) -> pure iden <<< r ≅ r alaw4 : ∀{W X Y Z}(t : R Y Z)(s : R X Y)(r : R W X) -> t <<< (s <<< r) ≅ (t <<< s) <<< r open import Functors open import Naturals open import Categories.Sets open import YonedaLemma open import RMonads module Arrow2RMonad {l m}(C : Cat {l}{m})(A : Arrow C) where open Cat C open Arrow A T : Cat.Obj C -> Fun (C Op) (Sets {m}) T X = functor (λ Y -> R Y X) (λ f s -> s <<< pure f) (ext alaw2) (ext (λ s -> trans (cong (s <<<_) (alaw1 _ _)) (alaw4 _ _ _))) η : {X : Obj} -> NatT HomF[-, X ] (T X) η = natural pure (ext λ _ -> sym (alaw1 _ _)) bind : {X Y : Obj} -> NatT HomF[-, X ] (T Y) -> NatT (T X) (T Y) bind α = natural (λ s -> cmp iden <<< s) (ext λ _ -> sym (alaw4 _ _ _)) where open NatT α -- cmp iden is one direction of the yoneda lemma law1 : {X : Obj} → bind (η {X}) ≅ idNat {F = T X} law1 = NatTEq (iext (\ _ -> ext alaw3)) law2 : {X Y : Obj}{f : NatT HomF[-, X ] (T Y)} → compNat (bind f) η ≅ f law2 {f = f} = NatTEq (iext \ _ -> ext \ s -> trans (fcong iden (nat {f = s})) (cong cmp idl)) where open NatT f law3 : {X Y Z : Obj} {f : NatT HomF[-, X ] (T Y)} → {g : NatT HomF[-, Y ] (T Z)} → bind (compNat (bind g) f) ≅ compNat (bind g) (bind f) law3 = NatTEq (iext \ W -> ext (\ s -> sym (alaw4 _ _ s))) ArrowRMonad : RMonad (y C) ArrowRMonad = rmonad T η bind law1 law2 (λ {_ _ _ f g} -> law3 {f = f}{g = g}) module RMonad2Arrow {l m}(C : Cat {l}{m})(M : RMonad (y C)) where open Cat C open RMonad M open Fun open NatT R : Obj → Obj → Set m R X Y = OMap (T Y) X pure : {X Y : Obj} → Hom X Y → R X Y pure f = cmp η f _<<<_ : ∀{X Y Z} → R Y Z → R X Y → R X Z s <<< t = cmp (bind (ylem C (T _) _ s)) t alaw1 : ∀{X Y Z}(g : Hom Y Z)(f : Hom X Y) → pure (comp g f) ≅ (pure g <<< pure f) alaw1 g f = trans (sym (fcong g (nat η))) (sym (fcong f (ifcong _ (cong cmp law2)))) alaw2 : ∀{X Y} -> (s : R X Y) → (s <<< pure iden) ≅ s alaw2 s = trans (fcong iden (ifcong _ (cong cmp law2))) (fcong s (fid (T _))) alaw3 : ∀{X Y}(r : R X Y) → (pure iden <<< r) ≅ r alaw3 r = trans (cong (\ α -> cmp (bind α) r) (NatTEq (iext \ Z -> ext \ f -> trans (fcong iden (nat η)) (cong (cmp η) idl)))) (fcong r (ifcong _ (cong cmp law1))) alaw4 : ∀{W X Y Z}(t : R Y Z)(s : R X Y)(r : R W X) → (t <<< (s <<< r)) ≅ ((t <<< s) <<< r) alaw4 t s r = trans (sym (fcong r (ifcong _ (cong cmp law3)))) (cong (\ α -> cmp (bind α) r) (NatTEq (iext \ _ -> ext \ _ -> sym (fcong s (nat (bind (ylem C (T _) _ t))))))) RMonadArrow : Arrow C RMonadArrow = arrow R pure _<<<_ alaw1 alaw2 alaw3 alaw4
{ "alphanum_fraction": 0.4726457399, "avg_line_length": 27.875, "ext": "agda", "hexsha": "23bf6900e23f426a0841a665861d5f2ebfc69779", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_path": "WeakArrows.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_path": "WeakArrows.agda", "max_line_length": 76, "max_stars_count": 21, "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_path": "WeakArrows.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "num_tokens": 1387, "size": 3345 }
{-# OPTIONS --without-K #-} module PiLevel1 where open import Data.Unit using (⊤; tt) open import Relation.Binary.Core using (IsEquivalence) open import Relation.Binary.PropositionalEquality using (_≡_; refl; subst; sym; [_]) open import PiU using (U; ZERO; ONE; PLUS; TIMES) open import PiLevel0 -- hiding triv≡ certainly; we are replacing it with _⇔_ using (_⟷_; !; unite₊l; uniti₊l; unite₊r; uniti₊r; swap₊; assocl₊; assocr₊; unite⋆l; uniti⋆l; unite⋆r; uniti⋆r; swap⋆; assocl⋆; assocr⋆; absorbr; absorbl; factorzr; factorzl; dist; factor; distl; factorl; id⟷; _◎_; _⊕_; _⊗_) ------------------------------------------------------------------------------ -- Level 1: instead of using triv≡ to reason about equivalence of -- combinators, we use the following 2-combinators infix 30 _⇔_ data _⇔_ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) → Set where assoc◎l : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} → (c₁ ◎ (c₂ ◎ c₃)) ⇔ ((c₁ ◎ c₂) ◎ c₃) assoc◎r : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} → ((c₁ ◎ c₂) ◎ c₃) ⇔ (c₁ ◎ (c₂ ◎ c₃)) assocl⊕l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → ((c₁ ⊕ (c₂ ⊕ c₃)) ◎ assocl₊) ⇔ (assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃)) assocl⊕r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃)) ⇔ ((c₁ ⊕ (c₂ ⊕ c₃)) ◎ assocl₊) assocl⊗l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → ((c₁ ⊗ (c₂ ⊗ c₃)) ◎ assocl⋆) ⇔ (assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃)) assocl⊗r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃)) ⇔ ((c₁ ⊗ (c₂ ⊗ c₃)) ◎ assocl⋆) assocr⊕r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊) ⇔ (assocr₊ ◎ (c₁ ⊕ (c₂ ⊕ c₃))) assocr⊗l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (assocr⋆ ◎ (c₁ ⊗ (c₂ ⊗ c₃))) ⇔ (((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆) assocr⊗r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆) ⇔ (assocr⋆ ◎ (c₁ ⊗ (c₂ ⊗ c₃))) assocr⊕l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → (assocr₊ ◎ (c₁ ⊕ (c₂ ⊕ c₃))) ⇔ (((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊) dist⇔l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → ((a ⊕ b) ⊗ c) ◎ dist ⇔ dist ◎ ((a ⊗ c) ⊕ (b ⊗ c)) dist⇔r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → dist ◎ ((a ⊗ c) ⊕ (b ⊗ c)) ⇔ ((a ⊕ b) ⊗ c) ◎ dist distl⇔l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → (a ⊗ (b ⊕ c)) ◎ distl ⇔ distl ◎ ((a ⊗ b) ⊕ (a ⊗ c)) distl⇔r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → distl ◎ ((a ⊗ b) ⊕ (a ⊗ c)) ⇔ (a ⊗ (b ⊕ c)) ◎ distl factor⇔l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → ((a ⊗ c) ⊕ (b ⊗ c)) ◎ factor ⇔ factor ◎ ((a ⊕ b) ⊗ c) factor⇔r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → factor ◎ ((a ⊕ b) ⊗ c) ⇔ ((a ⊗ c) ⊕ (b ⊗ c)) ◎ factor factorl⇔l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → ((a ⊗ b) ⊕ (a ⊗ c)) ◎ factorl ⇔ factorl ◎ (a ⊗ (b ⊕ c)) factorl⇔r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {a : t₁ ⟷ t₂} {b : t₃ ⟷ t₄} {c : t₅ ⟷ t₆} → factorl ◎ (a ⊗ (b ⊕ c)) ⇔ ((a ⊗ b) ⊕ (a ⊗ c)) ◎ factorl idl◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (id⟷ ◎ c) ⇔ c idl◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ id⟷ ◎ c idr◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ id⟷) ⇔ c idr◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ (c ◎ id⟷) linv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ ! c) ⇔ id⟷ linv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (c ◎ ! c) rinv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (! c ◎ c) ⇔ id⟷ rinv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (! c ◎ c) unite₊l⇔l : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (unite₊l ◎ c₂) ⇔ ((c₁ ⊕ c₂) ◎ unite₊l) unite₊l⇔r : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → ((c₁ ⊕ c₂) ◎ unite₊l) ⇔ (unite₊l ◎ c₂) uniti₊l⇔l : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (uniti₊l ◎ (c₁ ⊕ c₂)) ⇔ (c₂ ◎ uniti₊l) uniti₊l⇔r : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (c₂ ◎ uniti₊l) ⇔ (uniti₊l ◎ (c₁ ⊕ c₂)) unite₊r⇔l : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (unite₊r ◎ c₂) ⇔ ((c₂ ⊕ c₁) ◎ unite₊r) unite₊r⇔r : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → ((c₂ ⊕ c₁) ◎ unite₊r) ⇔ (unite₊r ◎ c₂) uniti₊r⇔l : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (uniti₊r ◎ (c₂ ⊕ c₁)) ⇔ (c₂ ◎ uniti₊r) uniti₊r⇔r : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → (c₂ ◎ uniti₊r) ⇔ (uniti₊r ◎ (c₂ ⊕ c₁)) swapl₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → (swap₊ ◎ (c₁ ⊕ c₂)) ⇔ ((c₂ ⊕ c₁) ◎ swap₊) swapr₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → ((c₂ ⊕ c₁) ◎ swap₊) ⇔ (swap₊ ◎ (c₁ ⊕ c₂)) unitel⋆⇔l : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (unite⋆l ◎ c₂) ⇔ ((c₁ ⊗ c₂) ◎ unite⋆l) uniter⋆⇔l : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → ((c₁ ⊗ c₂) ◎ unite⋆l) ⇔ (unite⋆l ◎ c₂) unitil⋆⇔l : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (uniti⋆l ◎ (c₁ ⊗ c₂)) ⇔ (c₂ ◎ uniti⋆l) unitir⋆⇔l : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (c₂ ◎ uniti⋆l) ⇔ (uniti⋆l ◎ (c₁ ⊗ c₂)) unitel⋆⇔r : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (unite⋆r ◎ c₂) ⇔ ((c₂ ⊗ c₁) ◎ unite⋆r) uniter⋆⇔r : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → ((c₂ ⊗ c₁) ◎ unite⋆r) ⇔ (unite⋆r ◎ c₂) unitil⋆⇔r : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (uniti⋆r ◎ (c₂ ⊗ c₁)) ⇔ (c₂ ◎ uniti⋆r) unitir⋆⇔r : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → (c₂ ◎ uniti⋆r) ⇔ (uniti⋆r ◎ (c₂ ⊗ c₁)) swapl⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → (swap⋆ ◎ (c₁ ⊗ c₂)) ⇔ ((c₂ ⊗ c₁) ◎ swap⋆) swapr⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → ((c₂ ⊗ c₁) ◎ swap⋆) ⇔ (swap⋆ ◎ (c₁ ⊗ c₂)) id⇔ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ c trans⇔ : {t₁ t₂ : U} {c₁ c₂ c₃ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃) _⊡_ : {t₁ t₂ t₃ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₁ ⟷ t₂} {c₄ : t₂ ⟷ t₃} → (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ◎ c₂) ⇔ (c₃ ◎ c₄) resp⊕⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} → (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊕ c₂) ⇔ (c₃ ⊕ c₄) resp⊗⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} → (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊗ c₂) ⇔ (c₃ ⊗ c₄) -- below are the combinators added for the RigCategory structure id⟷⊕id⟷⇔ : {t₁ t₂ : U} → (id⟷ {t₁} ⊕ id⟷ {t₂}) ⇔ id⟷ split⊕-id⟷ : {t₁ t₂ : U} → (id⟷ {PLUS t₁ t₂}) ⇔ (id⟷ ⊕ id⟷) hom⊕◎⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₅ ⟷ t₁} {c₂ : t₆ ⟷ t₂} {c₃ : t₁ ⟷ t₃} {c₄ : t₂ ⟷ t₄} → ((c₁ ◎ c₃) ⊕ (c₂ ◎ c₄)) ⇔ ((c₁ ⊕ c₂) ◎ (c₃ ⊕ c₄)) hom◎⊕⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₅ ⟷ t₁} {c₂ : t₆ ⟷ t₂} {c₃ : t₁ ⟷ t₃} {c₄ : t₂ ⟷ t₄} → ((c₁ ⊕ c₂) ◎ (c₃ ⊕ c₄)) ⇔ ((c₁ ◎ c₃) ⊕ (c₂ ◎ c₄)) id⟷⊗id⟷⇔ : {t₁ t₂ : U} → (id⟷ {t₁} ⊗ id⟷ {t₂}) ⇔ id⟷ split⊗-id⟷ : {t₁ t₂ : U} → (id⟷ {TIMES t₁ t₂}) ⇔ (id⟷ ⊗ id⟷) hom⊗◎⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₅ ⟷ t₁} {c₂ : t₆ ⟷ t₂} {c₃ : t₁ ⟷ t₃} {c₄ : t₂ ⟷ t₄} → ((c₁ ◎ c₃) ⊗ (c₂ ◎ c₄)) ⇔ ((c₁ ⊗ c₂) ◎ (c₃ ⊗ c₄)) hom◎⊗⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₅ ⟷ t₁} {c₂ : t₆ ⟷ t₂} {c₃ : t₁ ⟷ t₃} {c₄ : t₂ ⟷ t₄} → ((c₁ ⊗ c₂) ◎ (c₃ ⊗ c₄)) ⇔ ((c₁ ◎ c₃) ⊗ (c₂ ◎ c₄)) -- associativity triangle triangle⊕l : {t₁ t₂ : U} → (unite₊r {t₁} ⊕ id⟷ {t₂}) ⇔ assocr₊ ◎ (id⟷ ⊕ unite₊l) triangle⊕r : {t₁ t₂ : U} → assocr₊ ◎ (id⟷ {t₁} ⊕ unite₊l {t₂}) ⇔ (unite₊r ⊕ id⟷) triangle⊗l : {t₁ t₂ : U} → ((unite⋆r {t₁}) ⊗ id⟷ {t₂}) ⇔ assocr⋆ ◎ (id⟷ ⊗ unite⋆l) triangle⊗r : {t₁ t₂ : U} → (assocr⋆ ◎ (id⟷ {t₁} ⊗ unite⋆l {t₂})) ⇔ (unite⋆r ⊗ id⟷) pentagon⊕l : {t₁ t₂ t₃ t₄ : U} → assocr₊ ◎ (assocr₊ {t₁} {t₂} {PLUS t₃ t₄}) ⇔ ((assocr₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ assocr₊) pentagon⊕r : {t₁ t₂ t₃ t₄ : U} → ((assocr₊ {t₁} {t₂} {t₃} ⊕ id⟷ {t₄}) ◎ assocr₊) ◎ (id⟷ ⊕ assocr₊) ⇔ assocr₊ ◎ assocr₊ pentagon⊗l : {t₁ t₂ t₃ t₄ : U} → assocr⋆ ◎ (assocr⋆ {t₁} {t₂} {TIMES t₃ t₄}) ⇔ ((assocr⋆ ⊗ id⟷) ◎ assocr⋆) ◎ (id⟷ ⊗ assocr⋆) pentagon⊗r : {t₁ t₂ t₃ t₄ : U} → ((assocr⋆ {t₁} {t₂} {t₃} ⊗ id⟷ {t₄}) ◎ assocr⋆) ◎ (id⟷ ⊗ assocr⋆) ⇔ assocr⋆ ◎ assocr⋆ -- from the braiding -- unit coherence unite₊l-coh-l : {t₁ : U} → unite₊l {t₁} ⇔ swap₊ ◎ unite₊r unite₊l-coh-r : {t₁ : U} → swap₊ ◎ unite₊r ⇔ unite₊l {t₁} unite⋆l-coh-l : {t₁ : U} → unite⋆l {t₁} ⇔ swap⋆ ◎ unite⋆r unite⋆l-coh-r : {t₁ : U} → swap⋆ ◎ unite⋆r ⇔ unite⋆l {t₁} hexagonr⊕l : {t₁ t₂ t₃ : U} → (assocr₊ ◎ swap₊) ◎ assocr₊ {t₁} {t₂} {t₃} ⇔ ((swap₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ swap₊) hexagonr⊕r : {t₁ t₂ t₃ : U} → ((swap₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ swap₊) ⇔ (assocr₊ ◎ swap₊) ◎ assocr₊ {t₁} {t₂} {t₃} hexagonl⊕l : {t₁ t₂ t₃ : U} → (assocl₊ ◎ swap₊) ◎ assocl₊ {t₁} {t₂} {t₃} ⇔ ((id⟷ ⊕ swap₊) ◎ assocl₊) ◎ (swap₊ ⊕ id⟷) hexagonl⊕r : {t₁ t₂ t₃ : U} → ((id⟷ ⊕ swap₊) ◎ assocl₊) ◎ (swap₊ ⊕ id⟷) ⇔ (assocl₊ ◎ swap₊) ◎ assocl₊ {t₁} {t₂} {t₃} hexagonr⊗l : {t₁ t₂ t₃ : U} → (assocr⋆ ◎ swap⋆) ◎ assocr⋆ {t₁} {t₂} {t₃} ⇔ ((swap⋆ ⊗ id⟷) ◎ assocr⋆) ◎ (id⟷ ⊗ swap⋆) hexagonr⊗r : {t₁ t₂ t₃ : U} → ((swap⋆ ⊗ id⟷) ◎ assocr⋆) ◎ (id⟷ ⊗ swap⋆) ⇔ (assocr⋆ ◎ swap⋆) ◎ assocr⋆ {t₁} {t₂} {t₃} hexagonl⊗l : {t₁ t₂ t₃ : U} → (assocl⋆ ◎ swap⋆) ◎ assocl⋆ {t₁} {t₂} {t₃} ⇔ ((id⟷ ⊗ swap⋆) ◎ assocl⋆) ◎ (swap⋆ ⊗ id⟷) hexagonl⊗r : {t₁ t₂ t₃ : U} → ((id⟷ ⊗ swap⋆) ◎ assocl⋆) ◎ (swap⋆ ⊗ id⟷) ⇔ (assocl⋆ ◎ swap⋆) ◎ assocl⋆ {t₁} {t₂} {t₃} absorbl⇔l : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → (c₁ ⊗ id⟷ {ZERO}) ◎ absorbl ⇔ absorbl ◎ id⟷ {ZERO} absorbl⇔r : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → absorbl ◎ id⟷ {ZERO} ⇔ (c₁ ⊗ id⟷ {ZERO}) ◎ absorbl absorbr⇔l : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → (id⟷ {ZERO} ⊗ c₁) ◎ absorbr ⇔ absorbr ◎ id⟷ {ZERO} absorbr⇔r : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → absorbr ◎ id⟷ {ZERO} ⇔ (id⟷ {ZERO} ⊗ c₁) ◎ absorbr factorzl⇔l : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → id⟷ ◎ factorzl ⇔ factorzl ◎ (id⟷ ⊗ c₁) factorzl⇔r : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → factorzl ◎ (id⟷ {ZERO} ⊗ c₁) ⇔ id⟷ {ZERO} ◎ factorzl factorzr⇔l : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → id⟷ ◎ factorzr ⇔ factorzr ◎ (c₁ ⊗ id⟷) factorzr⇔r : {t₁ t₂ : U} {c₁ : t₁ ⟷ t₂} → factorzr ◎ (c₁ ⊗ id⟷) ⇔ id⟷ ◎ factorzr -- from the coherence conditions of RigCategory swap₊distl⇔l : {t₁ t₂ t₃ : U} → (id⟷ {t₁} ⊗ swap₊ {t₂} {t₃}) ◎ distl ⇔ distl ◎ swap₊ swap₊distl⇔r : {t₁ t₂ t₃ : U} → distl ◎ swap₊ ⇔ (id⟷ {t₁} ⊗ swap₊ {t₂} {t₃}) ◎ distl dist-swap⋆⇔l : {t₁ t₂ t₃ : U} → dist {t₁} {t₂} {t₃} ◎ (swap⋆ ⊕ swap⋆) ⇔ swap⋆ ◎ distl dist-swap⋆⇔r : {t₁ t₂ t₃ : U} → swap⋆ ◎ distl {t₁} {t₂} {t₃} ⇔ dist ◎ (swap⋆ ⊕ swap⋆) assocl₊-dist-dist⇔l : {t₁ t₂ t₃ t₄ : U} → ((assocl₊ {t₁} {t₂} {t₃} ⊗ id⟷ {t₄}) ◎ dist) ◎ (dist ⊕ id⟷) ⇔ (dist ◎ (id⟷ ⊕ dist)) ◎ assocl₊ assocl₊-dist-dist⇔r : {t₁ t₂ t₃ t₄ : U} → (dist {t₁} ◎ (id⟷ ⊕ dist {t₂} {t₃} {t₄})) ◎ assocl₊ ⇔ ((assocl₊ ⊗ id⟷) ◎ dist) ◎ (dist ⊕ id⟷) assocl⋆-distl⇔l : {t₁ t₂ t₃ t₄ : U} → assocl⋆ {t₁} {t₂} ◎ distl {TIMES t₁ t₂} {t₃} {t₄} ⇔ ((id⟷ ⊗ distl) ◎ distl) ◎ (assocl⋆ ⊕ assocl⋆) assocl⋆-distl⇔r : {t₁ t₂ t₃ t₄ : U} → ((id⟷ ⊗ distl) ◎ distl) ◎ (assocl⋆ ⊕ assocl⋆) ⇔ assocl⋆ {t₁} {t₂} ◎ distl {TIMES t₁ t₂} {t₃} {t₄} absorbr0-absorbl0⇔ : absorbr {ZERO} ⇔ absorbl {ZERO} absorbl0-absorbr0⇔ : absorbl {ZERO} ⇔ absorbr {ZERO} absorbr⇔distl-absorb-unite : {t₁ t₂ : U} → absorbr ⇔ (distl {t₂ = t₁} {t₂} ◎ (absorbr ⊕ absorbr)) ◎ unite₊l distl-absorb-unite⇔absorbr : {t₁ t₂ : U} → (distl {t₂ = t₁} {t₂} ◎ (absorbr ⊕ absorbr)) ◎ unite₊l ⇔ absorbr unite⋆r0-absorbr1⇔ : unite⋆r ⇔ absorbr absorbr1-unite⋆r-⇔ : absorbr ⇔ unite⋆r absorbl≡swap⋆◎absorbr : {t₁ : U} → absorbl {t₁} ⇔ swap⋆ ◎ absorbr swap⋆◎absorbr≡absorbl : {t₁ : U} → swap⋆ ◎ absorbr ⇔ absorbl {t₁} absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr : {t₁ t₂ : U} → absorbr ⇔ (assocl⋆ {ZERO} {t₁} {t₂} ◎ (absorbr ⊗ id⟷)) ◎ absorbr [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr : {t₁ t₂ : U} → (assocl⋆ {ZERO} {t₁} {t₂} ◎ (absorbr ⊗ id⟷)) ◎ absorbr ⇔ absorbr [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr : {t₁ t₂ : U} → (id⟷ ⊗ absorbr {t₂}) ◎ absorbl {t₁} ⇔ (assocl⋆ ◎ (absorbl ⊗ id⟷)) ◎ absorbr assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl : {t₁ t₂ : U} → (assocl⋆ ◎ (absorbl ⊗ id⟷)) ◎ absorbr ⇔ (id⟷ ⊗ absorbr {t₂}) ◎ absorbl {t₁} elim⊥-A[0⊕B]⇔l : {t₁ t₂ : U} → (id⟷ {t₁} ⊗ unite₊l {t₂}) ⇔ (distl ◎ (absorbl ⊕ id⟷)) ◎ unite₊l elim⊥-A[0⊕B]⇔r : {t₁ t₂ : U} → (distl ◎ (absorbl ⊕ id⟷)) ◎ unite₊l ⇔ (id⟷ {t₁} ⊗ unite₊l {t₂}) elim⊥-1[A⊕B]⇔l : {t₁ t₂ : U} → unite⋆l ⇔ distl ◎ (unite⋆l {t₁} ⊕ unite⋆l {t₂}) elim⊥-1[A⊕B]⇔r : {t₁ t₂ : U} → distl ◎ (unite⋆l {t₁} ⊕ unite⋆l {t₂}) ⇔ unite⋆l fully-distribute⇔l : {t₁ t₂ t₃ t₄ : U} → (distl ◎ (dist {t₁} {t₂} {t₃} ⊕ dist {t₁} {t₂} {t₄})) ◎ assocl₊ ⇔ ((((dist ◎ (distl ⊕ distl)) ◎ assocl₊) ◎ (assocr₊ ⊕ id⟷)) ◎ ((id⟷ ⊕ swap₊) ⊕ id⟷)) ◎ (assocl₊ ⊕ id⟷) fully-distribute⇔r : {t₁ t₂ t₃ t₄ : U} → ((((dist ◎ (distl ⊕ distl)) ◎ assocl₊) ◎ (assocr₊ ⊕ id⟷)) ◎ ((id⟷ ⊕ swap₊) ⊕ id⟷)) ◎ (assocl₊ ⊕ id⟷) ⇔ (distl ◎ (dist {t₁} {t₂} {t₃} ⊕ dist {t₁} {t₂} {t₄})) ◎ assocl₊ -- At the next level we have a trivial equivalence that equates all -- 2-morphisms of the same type. triv≡ : {t₁ t₂ : U} {f g : t₁ ⟷ t₂} → (α β : f ⇔ g) → Set triv≡ _ _ = ⊤ triv≡Equiv : {t₁ t₂ : U} {f₁ f₂ : t₁ ⟷ t₂} → IsEquivalence (triv≡ {t₁} {t₂} {f₁} {f₂}) triv≡Equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt } ------------------------------------------------------------------------------ -- Inverses for 2paths 2! : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₁) 2! assoc◎l = assoc◎r 2! assoc◎r = assoc◎l 2! assocl⊕l = assocl⊕r 2! assocl⊕r = assocl⊕l 2! assocl⊗l = assocl⊗r 2! assocl⊗r = assocl⊗l 2! assocr⊕r = assocr⊕l 2! assocr⊕l = assocr⊕r 2! assocr⊗r = assocr⊗l 2! assocr⊗l = assocr⊗r 2! dist⇔l = dist⇔r 2! dist⇔r = dist⇔l 2! distl⇔l = distl⇔r 2! distl⇔r = distl⇔l 2! factor⇔l = factor⇔r 2! factor⇔r = factor⇔l 2! factorl⇔l = factorl⇔r 2! factorl⇔r = factorl⇔l 2! idl◎l = idl◎r 2! idl◎r = idl◎l 2! idr◎l = idr◎r 2! idr◎r = idr◎l 2! linv◎l = linv◎r 2! linv◎r = linv◎l 2! rinv◎l = rinv◎r 2! rinv◎r = rinv◎l 2! unite₊l⇔l = unite₊l⇔r 2! unite₊l⇔r = unite₊l⇔l 2! uniti₊l⇔l = uniti₊l⇔r 2! uniti₊l⇔r = uniti₊l⇔l 2! unite₊r⇔l = unite₊r⇔r 2! unite₊r⇔r = unite₊r⇔l 2! uniti₊r⇔l = uniti₊r⇔r 2! uniti₊r⇔r = uniti₊r⇔l 2! swapl₊⇔ = swapr₊⇔ 2! swapr₊⇔ = swapl₊⇔ 2! unitel⋆⇔l = uniter⋆⇔l 2! uniter⋆⇔l = unitel⋆⇔l 2! unitil⋆⇔l = unitir⋆⇔l 2! unitir⋆⇔l = unitil⋆⇔l 2! unitel⋆⇔r = uniter⋆⇔r 2! uniter⋆⇔r = unitel⋆⇔r 2! unitil⋆⇔r = unitir⋆⇔r 2! unitir⋆⇔r = unitil⋆⇔r 2! swapl⋆⇔ = swapr⋆⇔ 2! swapr⋆⇔ = swapl⋆⇔ 2! id⇔ = id⇔ 2! (α ⊡ β) = (2! α) ⊡ (2! β) 2! (trans⇔ α β) = trans⇔ (2! β) (2! α) 2! (resp⊕⇔ α β) = resp⊕⇔ (2! α) (2! β) 2! (resp⊗⇔ α β) = resp⊗⇔ (2! α) (2! β) 2! id⟷⊕id⟷⇔ = split⊕-id⟷ 2! split⊕-id⟷ = id⟷⊕id⟷⇔ 2! hom⊕◎⇔ = hom◎⊕⇔ 2! hom◎⊕⇔ = hom⊕◎⇔ 2! id⟷⊗id⟷⇔ = split⊗-id⟷ 2! split⊗-id⟷ = id⟷⊗id⟷⇔ 2! hom⊗◎⇔ = hom◎⊗⇔ 2! hom◎⊗⇔ = hom⊗◎⇔ 2! triangle⊕l = triangle⊕r 2! triangle⊕r = triangle⊕l 2! triangle⊗l = triangle⊗r 2! triangle⊗r = triangle⊗l 2! pentagon⊕l = pentagon⊕r 2! pentagon⊕r = pentagon⊕l 2! pentagon⊗l = pentagon⊗r 2! pentagon⊗r = pentagon⊗l 2! unite₊l-coh-l = unite₊l-coh-r 2! unite₊l-coh-r = unite₊l-coh-l 2! unite⋆l-coh-l = unite⋆l-coh-r 2! unite⋆l-coh-r = unite⋆l-coh-l 2! hexagonr⊕l = hexagonr⊕r 2! hexagonr⊕r = hexagonr⊕l 2! hexagonl⊕l = hexagonl⊕r 2! hexagonl⊕r = hexagonl⊕l 2! hexagonr⊗l = hexagonr⊗r 2! hexagonr⊗r = hexagonr⊗l 2! hexagonl⊗l = hexagonl⊗r 2! hexagonl⊗r = hexagonl⊗l 2! absorbl⇔l = absorbl⇔r 2! absorbl⇔r = absorbl⇔l 2! absorbr⇔l = absorbr⇔r 2! absorbr⇔r = absorbr⇔l 2! factorzl⇔l = factorzl⇔r 2! factorzl⇔r = factorzl⇔l 2! factorzr⇔l = factorzr⇔r 2! factorzr⇔r = factorzr⇔l 2! swap₊distl⇔l = swap₊distl⇔r 2! swap₊distl⇔r = swap₊distl⇔l 2! dist-swap⋆⇔l = dist-swap⋆⇔r 2! dist-swap⋆⇔r = dist-swap⋆⇔l 2! assocl₊-dist-dist⇔l = assocl₊-dist-dist⇔r 2! assocl₊-dist-dist⇔r = assocl₊-dist-dist⇔l 2! assocl⋆-distl⇔l = assocl⋆-distl⇔r 2! assocl⋆-distl⇔r = assocl⋆-distl⇔l 2! absorbr0-absorbl0⇔ = absorbl0-absorbr0⇔ 2! absorbl0-absorbr0⇔ = absorbr0-absorbl0⇔ 2! absorbr⇔distl-absorb-unite = distl-absorb-unite⇔absorbr 2! distl-absorb-unite⇔absorbr = absorbr⇔distl-absorb-unite 2! unite⋆r0-absorbr1⇔ = absorbr1-unite⋆r-⇔ 2! absorbr1-unite⋆r-⇔ = unite⋆r0-absorbr1⇔ 2! absorbl≡swap⋆◎absorbr = swap⋆◎absorbr≡absorbl 2! swap⋆◎absorbr≡absorbl = absorbl≡swap⋆◎absorbr 2! absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr = [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr 2! [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr = absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr 2! [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr = assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl 2! assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl = [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr 2! elim⊥-A[0⊕B]⇔l = elim⊥-A[0⊕B]⇔r 2! elim⊥-A[0⊕B]⇔r = elim⊥-A[0⊕B]⇔l 2! elim⊥-1[A⊕B]⇔l = elim⊥-1[A⊕B]⇔r 2! elim⊥-1[A⊕B]⇔r = elim⊥-1[A⊕B]⇔l 2! fully-distribute⇔l = fully-distribute⇔r 2! fully-distribute⇔r = fully-distribute⇔l 2!! : {t₁ t₂ : U} {f g : t₁ ⟷ t₂} {α : f ⇔ g} → triv≡ (2! (2! α)) α 2!! = tt -- This makes _⇔_ an equivalence relation... ⇔Equiv : {t₁ t₂ : U} → IsEquivalence (_⇔_ {t₁} {t₂}) ⇔Equiv = record { refl = id⇔ ; sym = 2! ; trans = trans⇔ } ------------------------------------------------------------------------------ -- Unit coherence has two versions, but one is derivable -- from the other. As it turns out, one of our examples -- needs the 'flipped' version. unite₊r-coh-r : {t₁ : U} → swap₊ ◎ unite₊l ⇔ unite₊r {t₁} unite₊r-coh-r = trans⇔ (id⇔ ⊡ unite₊l-coh-l) ( trans⇔ assoc◎l (( trans⇔ (linv◎l ⊡ id⇔) idl◎l ) ) ) ------------------------------------------------------------------------------ -- It is often useful to have that reversing c twice is ⇔ c rather than ≡ -- Unfortunately, it needs a 'proof', which is quite dull, though -- it does have 3 non-trivial cases. !!⇔id : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (! (! c)) ⇔ c !!⇔id {c = unite₊l} = id⇔ !!⇔id {c = uniti₊l} = id⇔ !!⇔id {c = unite₊r} = id⇔ !!⇔id {c = uniti₊r} = id⇔ !!⇔id {c = swap₊} = id⇔ !!⇔id {c = assocl₊} = id⇔ !!⇔id {c = assocr₊} = id⇔ !!⇔id {c = unite⋆l} = id⇔ !!⇔id {c = uniti⋆l} = id⇔ !!⇔id {c = unite⋆r} = id⇔ !!⇔id {c = uniti⋆r} = id⇔ !!⇔id {c = swap⋆} = id⇔ !!⇔id {c = assocl⋆} = id⇔ !!⇔id {c = assocr⋆} = id⇔ !!⇔id {c = absorbr} = id⇔ !!⇔id {c = absorbl} = id⇔ !!⇔id {c = factorzr} = id⇔ !!⇔id {c = factorzl} = id⇔ !!⇔id {c = dist} = id⇔ !!⇔id {c = factor} = id⇔ !!⇔id {c = distl} = id⇔ !!⇔id {c = factorl} = id⇔ !!⇔id {c = id⟷} = id⇔ !!⇔id {c = c ◎ c₁} = !!⇔id ⊡ !!⇔id !!⇔id {c = c ⊕ c₁} = resp⊕⇔ !!⇔id !!⇔id !!⇔id {c = c ⊗ c₁} = resp⊗⇔ !!⇔id !!⇔id ------------- mutual eval₁ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) → (t₁ ⟷ t₂) eval₁ (assoc◎l {c₁ = c₁} {c₂} {c₃}) = (c₁ ◎ c₂) ◎ c₃ eval₁ (assoc◎r {c₁ = c₁} {c₂} {c₃}) = c₁ ◎ (c₂ ◎ c₃) eval₁ (assocl⊕l {c₁ = c₁} {c₂} {c₃}) = assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) eval₁ (assocl⊕r {c₁ = c₁} {c₂} {c₃}) = (c₁ ⊕ (c₂ ⊕ c₃)) ◎ assocl₊ eval₁ (assocl⊗l {c₁ = c₁} {c₂} {c₃}) = assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) eval₁ (assocl⊗r {c₁ = c₁} {c₂} {c₃}) = (c₁ ⊗ (c₂ ⊗ c₃)) ◎ assocl⋆ eval₁ (assocr⊕r {c₁ = c₁} {c₂} {c₃}) = assocr₊ ◎ (c₁ ⊕ (c₂ ⊕ c₃)) eval₁ (assocr⊗l {c₁ = c₁} {c₂} {c₃}) = ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆ eval₁ (assocr⊗r {c₁ = c₁} {c₂} {c₃}) = assocr⋆ ◎(c₁ ⊗ (c₂ ⊗ c₃)) eval₁ (assocr⊕l {c₁ = c₁} {c₂} {c₃}) = ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊ eval₁ (dist⇔l {a = c₁} {c₂} {c₃}) = dist ◎ ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) eval₁ (dist⇔r {a = c₁} {c₂} {c₃}) = ((c₁ ⊕ c₂) ⊗ c₃) ◎ dist eval₁ (distl⇔l {a = c₁} {c₂} {c₃}) = distl ◎ ((c₁ ⊗ c₂) ⊕ (c₁ ⊗ c₃)) eval₁ (distl⇔r {a = c₁} {c₂} {c₃}) = (c₁ ⊗ (c₂ ⊕ c₃)) ◎ distl eval₁ (factor⇔l {a = c₁} {c₂} {c₃}) = factor ◎ ((c₁ ⊕ c₂) ⊗ c₃) eval₁ (factor⇔r {a = c₁} {c₂} {c₃}) = ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) ◎ factor eval₁ (factorl⇔l {a = c₁} {c₂} {c₃}) = factorl ◎ (c₁ ⊗ (c₂ ⊕ c₃)) eval₁ (factorl⇔r {a = c₁} {c₂} {c₃}) = ((c₁ ⊗ c₂) ⊕ (c₁ ⊗ c₃)) ◎ factorl eval₁ (idl◎l {c = c}) = c eval₁ (idl◎r {c = c}) = id⟷ ◎ c eval₁ (idr◎l {c = c}) = c eval₁ (idr◎r {c = c}) = c ◎ id⟷ eval₁ (linv◎l {c = c}) = id⟷ eval₁ (linv◎r {c = c}) = c ◎ ! c eval₁ (rinv◎l {c = c}) = id⟷ eval₁ (rinv◎r {c = c}) = ! c ◎ c eval₁ (unite₊l⇔l {c₁ = c₁} {c₂}) = (c₁ ⊕ c₂) ◎ unite₊l eval₁ (unite₊l⇔r {c₁ = c₁} {c₂}) = unite₊l ◎ c₂ eval₁ (uniti₊l⇔l {c₁ = c₁} {c₂}) = c₂ ◎ uniti₊l eval₁ (uniti₊l⇔r {c₁ = c₁} {c₂}) = uniti₊l ◎ (c₁ ⊕ c₂) eval₁ (unite₊r⇔l {c₁ = c₁} {c₂}) = (c₂ ⊕ c₁) ◎ unite₊r eval₁ (unite₊r⇔r {c₁ = c₁} {c₂}) = unite₊r ◎ c₂ eval₁ (uniti₊r⇔l {c₁ = c₁} {c₂}) = c₂ ◎ uniti₊r eval₁ (uniti₊r⇔r {c₁ = c₁} {c₂}) = uniti₊r ◎ (c₂ ⊕ c₁) eval₁ (swapl₊⇔ {c₁ = c₁} {c₂}) = (c₂ ⊕ c₁) ◎ swap₊ eval₁ (swapr₊⇔ {c₁ = c₁} {c₂}) = swap₊ ◎ (c₁ ⊕ c₂) eval₁ (unitel⋆⇔l {c₁ = c₁} {c₂}) = (c₁ ⊗ c₂) ◎ unite⋆l eval₁ (uniter⋆⇔l {c₁ = c₁} {c₂}) = unite⋆l ◎ c₂ eval₁ (unitil⋆⇔l {c₁ = c₁} {c₂}) = c₂ ◎ uniti⋆l eval₁ (unitir⋆⇔l {c₁ = c₁} {c₂}) = uniti⋆l ◎ (c₁ ⊗ c₂) eval₁ (unitel⋆⇔r {c₁ = c₁} {c₂}) = (c₂ ⊗ c₁) ◎ unite⋆r eval₁ (uniter⋆⇔r {c₁ = c₁} {c₂}) = unite⋆r ◎ c₂ eval₁ (unitil⋆⇔r {c₁ = c₁} {c₂}) = c₂ ◎ uniti⋆r eval₁ (unitir⋆⇔r {c₁ = c₁} {c₂}) = uniti⋆r ◎ (c₂ ⊗ c₁) eval₁ (swapl⋆⇔ {c₁ = c₁} {c₂}) = (c₂ ⊗ c₁) ◎ swap⋆ eval₁ (swapr⋆⇔ {c₁ = c₁} {c₂}) = swap⋆ ◎ (c₁ ⊗ c₂) eval₁ (id⇔ {c = c}) = c eval₁ (trans⇔ {t₁} {t₂} {c₁} {c₂} {c₃} ce ce₁) with eval₁ ce | exact ce ... | cc | refl = eval₁ {c₁ = cc} {c₃} ce₁ eval₁ (_⊡_ {c₁ = c₁} {c₂} {c₃} {c₄} ce₀ ce₁) = let r₀ = eval₁ ce₀ in let r₁ = eval₁ ce₁ in r₀ ◎ r₁ eval₁ (resp⊕⇔ ce₀ ce₁) = let r₀ = eval₁ ce₀ in let r₁ = eval₁ ce₁ in r₀ ⊕ r₁ eval₁ (resp⊗⇔ ce₀ ce₁) = let r₀ = eval₁ ce₀ in let r₁ = eval₁ ce₁ in r₀ ⊗ r₁ eval₁ id⟷⊕id⟷⇔ = id⟷ eval₁ split⊕-id⟷ = id⟷ ⊕ id⟷ eval₁ (hom⊕◎⇔ {c₁ = c₁} {c₂} {c₃} {c₄}) = (c₁ ⊕ c₂) ◎ (c₃ ⊕ c₄) eval₁ (hom◎⊕⇔ {c₁ = c₁} {c₂} {c₃} {c₄}) = (c₁ ◎ c₃) ⊕ (c₂ ◎ c₄) eval₁ id⟷⊗id⟷⇔ = id⟷ eval₁ split⊗-id⟷ = id⟷ ⊗ id⟷ eval₁ (hom⊗◎⇔ {c₁ = c₁} {c₂} {c₃} {c₄}) = (c₁ ⊗ c₂) ◎ (c₃ ⊗ c₄) eval₁ (hom◎⊗⇔ {c₁ = c₁} {c₂} {c₃} {c₄}) = (c₁ ◎ c₃) ⊗ (c₂ ◎ c₄) eval₁ triangle⊕l = assocr₊ ◎ (id⟷ ⊕ unite₊l) eval₁ triangle⊕r = unite₊r ⊕ id⟷ eval₁ triangle⊗l = assocr⋆ ◎ (id⟷ ⊗ unite⋆l) eval₁ triangle⊗r = unite⋆r ⊗ id⟷ eval₁ pentagon⊕l = ((assocr₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ assocr₊) eval₁ pentagon⊕r = assocr₊ ◎ assocr₊ eval₁ pentagon⊗l = ((assocr⋆ ⊗ id⟷) ◎ assocr⋆) ◎ (id⟷ ⊗ assocr⋆) eval₁ pentagon⊗r = assocr⋆ ◎ assocr⋆ eval₁ unite₊l-coh-l = swap₊ ◎ unite₊r eval₁ unite₊l-coh-r = unite₊l eval₁ unite⋆l-coh-l = swap⋆ ◎ unite⋆r eval₁ unite⋆l-coh-r = unite⋆l eval₁ hexagonr⊕l = ((swap₊ ⊕ id⟷) ◎ assocr₊) ◎ (id⟷ ⊕ swap₊) eval₁ hexagonr⊕r = (assocr₊ ◎ swap₊) ◎ assocr₊ eval₁ hexagonl⊕l = ((id⟷ ⊕ swap₊) ◎ assocl₊) ◎ (swap₊ ⊕ id⟷) eval₁ hexagonl⊕r = (assocl₊ ◎ swap₊) ◎ assocl₊ eval₁ hexagonr⊗l = ((swap⋆ ⊗ id⟷) ◎ assocr⋆) ◎ (id⟷ ⊗ swap⋆) eval₁ hexagonr⊗r = (assocr⋆ ◎ swap⋆) ◎ assocr⋆ eval₁ hexagonl⊗l = ((id⟷ ⊗ swap⋆) ◎ assocl⋆) ◎ (swap⋆ ⊗ id⟷) eval₁ hexagonl⊗r = (assocl⋆ ◎ swap⋆) ◎ assocl⋆ eval₁ absorbl⇔l = absorbl ◎ id⟷ eval₁ (absorbl⇔r {c₁ = c₁}) = (c₁ ⊗ id⟷) ◎ absorbl eval₁ absorbr⇔l = absorbr ◎ id⟷ eval₁ (absorbr⇔r {c₁ = c₁}) = (id⟷ ⊗ c₁) ◎ absorbr eval₁ (factorzl⇔l {c₁ = c₁}) = factorzl ◎ (id⟷ ⊗ c₁) eval₁ (factorzl⇔r {c₁ = c₁}) = id⟷ ◎ factorzl eval₁ (factorzr⇔l {c₁ = c₁}) = factorzr ◎ (c₁ ⊗ id⟷) eval₁ (factorzr⇔r {c₁ = c₁}) = id⟷ ◎ factorzr eval₁ swap₊distl⇔l = distl ◎ swap₊ eval₁ swap₊distl⇔r = (id⟷ ⊗ swap₊) ◎ distl eval₁ dist-swap⋆⇔l = swap⋆ ◎ distl eval₁ dist-swap⋆⇔r = dist ◎ (swap⋆ ⊕ swap⋆) eval₁ assocl₊-dist-dist⇔l = (dist ◎ (id⟷ ⊕ dist)) ◎ assocl₊ eval₁ assocl₊-dist-dist⇔r = ((assocl₊ ⊗ id⟷) ◎ dist) ◎ (dist ⊕ id⟷) eval₁ assocl⋆-distl⇔l = ((id⟷ ⊗ distl) ◎ distl) ◎ (assocl⋆ ⊕ assocl⋆) eval₁ assocl⋆-distl⇔r = assocl⋆ ◎ distl eval₁ absorbr0-absorbl0⇔ = absorbl eval₁ absorbl0-absorbr0⇔ = absorbr eval₁ absorbr⇔distl-absorb-unite = (distl ◎ (absorbr ⊕ absorbr)) ◎ unite₊l eval₁ distl-absorb-unite⇔absorbr = absorbr eval₁ unite⋆r0-absorbr1⇔ = absorbr eval₁ absorbr1-unite⋆r-⇔ = unite⋆r eval₁ absorbl≡swap⋆◎absorbr = swap⋆ ◎ absorbr eval₁ swap⋆◎absorbr≡absorbl = absorbl eval₁ absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr = (assocl⋆ ◎ (absorbr ⊗ id⟷)) ◎ absorbr eval₁ [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr = absorbr eval₁ [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr = (assocl⋆ ◎ (absorbl ⊗ id⟷)) ◎ absorbr eval₁ assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl = (id⟷ ⊗ absorbr) ◎ absorbl eval₁ elim⊥-A[0⊕B]⇔l = (distl ◎ (absorbl ⊕ id⟷)) ◎ unite₊l eval₁ elim⊥-A[0⊕B]⇔r = id⟷ ⊗ unite₊l eval₁ elim⊥-1[A⊕B]⇔l = distl ◎ (unite⋆l ⊕ unite⋆l) eval₁ elim⊥-1[A⊕B]⇔r = unite⋆l eval₁ fully-distribute⇔l = ((((dist ◎ (distl ⊕ distl)) ◎ assocl₊) ◎ (assocr₊ ⊕ id⟷)) ◎ ((id⟷ ⊕ swap₊) ⊕ id⟷)) ◎ (assocl₊ ⊕ id⟷) eval₁ fully-distribute⇔r = (distl ◎ (dist ⊕ dist)) ◎ assocl₊ exact : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) → eval₁ ce ≡ c₂ exact assoc◎l = refl exact assoc◎r = refl exact assocl⊕l = refl exact assocl⊕r = refl exact assocl⊗l = refl exact assocl⊗r = refl exact assocr⊕r = refl exact assocr⊗l = refl exact assocr⊗r = refl exact assocr⊕l = refl exact dist⇔l = refl exact dist⇔r = refl exact distl⇔l = refl exact distl⇔r = refl exact factor⇔l = refl exact factor⇔r = refl exact factorl⇔l = refl exact factorl⇔r = refl exact idl◎l = refl exact idl◎r = refl exact idr◎l = refl exact idr◎r = refl exact linv◎l = refl exact linv◎r = refl exact rinv◎l = refl exact rinv◎r = refl exact unite₊l⇔l = refl exact unite₊l⇔r = refl exact uniti₊l⇔l = refl exact uniti₊l⇔r = refl exact unite₊r⇔l = refl exact unite₊r⇔r = refl exact uniti₊r⇔l = refl exact uniti₊r⇔r = refl exact swapl₊⇔ = refl exact swapr₊⇔ = refl exact unitel⋆⇔l = refl exact uniter⋆⇔l = refl exact unitil⋆⇔l = refl exact unitir⋆⇔l = refl exact unitel⋆⇔r = refl exact uniter⋆⇔r = refl exact unitil⋆⇔r = refl exact unitir⋆⇔r = refl exact swapl⋆⇔ = refl exact swapr⋆⇔ = refl exact id⇔ = refl exact (trans⇔ ce ce₁) rewrite exact ce | exact ce₁ = refl exact (ce ⊡ ce₁) rewrite exact ce | exact ce₁ = refl exact (resp⊕⇔ ce ce₁) rewrite exact ce | exact ce₁ = refl exact (resp⊗⇔ ce ce₁) rewrite exact ce | exact ce₁ = refl exact id⟷⊕id⟷⇔ = refl exact split⊕-id⟷ = refl exact hom⊕◎⇔ = refl exact hom◎⊕⇔ = refl exact id⟷⊗id⟷⇔ = refl exact split⊗-id⟷ = refl exact hom⊗◎⇔ = refl exact hom◎⊗⇔ = refl exact triangle⊕l = refl exact triangle⊕r = refl exact triangle⊗l = refl exact triangle⊗r = refl exact pentagon⊕l = refl exact pentagon⊕r = refl exact pentagon⊗l = refl exact pentagon⊗r = refl exact unite₊l-coh-l = refl exact unite₊l-coh-r = refl exact unite⋆l-coh-l = refl exact unite⋆l-coh-r = refl exact hexagonr⊕l = refl exact hexagonr⊕r = refl exact hexagonl⊕l = refl exact hexagonl⊕r = refl exact hexagonr⊗l = refl exact hexagonr⊗r = refl exact hexagonl⊗l = refl exact hexagonl⊗r = refl exact absorbl⇔l = refl exact absorbl⇔r = refl exact absorbr⇔l = refl exact absorbr⇔r = refl exact factorzl⇔l = refl exact factorzl⇔r = refl exact factorzr⇔l = refl exact factorzr⇔r = refl exact swap₊distl⇔l = refl exact swap₊distl⇔r = refl exact dist-swap⋆⇔l = refl exact dist-swap⋆⇔r = refl exact assocl₊-dist-dist⇔l = refl exact assocl₊-dist-dist⇔r = refl exact assocl⋆-distl⇔l = refl exact assocl⋆-distl⇔r = refl exact absorbr0-absorbl0⇔ = refl exact absorbl0-absorbr0⇔ = refl exact absorbr⇔distl-absorb-unite = refl exact distl-absorb-unite⇔absorbr = refl exact unite⋆r0-absorbr1⇔ = refl exact absorbr1-unite⋆r-⇔ = refl exact absorbl≡swap⋆◎absorbr = refl exact swap⋆◎absorbr≡absorbl = refl exact absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr = refl exact [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr = refl exact [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr = refl exact assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl = refl exact elim⊥-A[0⊕B]⇔l = refl exact elim⊥-A[0⊕B]⇔r = refl exact elim⊥-1[A⊕B]⇔l = refl exact elim⊥-1[A⊕B]⇔r = refl exact fully-distribute⇔l = refl exact fully-distribute⇔r = refl
{ "alphanum_fraction": 0.5066322136, "avg_line_length": 40.4247910864, "ext": "agda", "hexsha": "66aa71c697da078def68f7814139cdf73ea8f5fb", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/PiLevel1.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/PiLevel1.agda", "max_line_length": 99, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/PiLevel1.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 18174, "size": 29025 }
{-# OPTIONS --without-K #-} {- *** Definition 5.3 and Lemma 5.5 are taken from the library *** *** Corollary 6.8 is too trivial a consequence of -} {- ConnectednessAlt and the last submodule of Connection are the only modules importing real truncation types from the library. Except for that, Univalence is the only additional assumption to Agda-style MLTT we work with. -} module Universe.index where {- General utility funcions and type constructors for the pseudo-universe of types of fixed truncation level. -} import Universe.Utility.General import Universe.Utility.TruncUniverse {- Pointed types. Corresponds to section 4 plus some lemmata of section 5, which are used in multiple modules and thus belong here. -} -- *** Definitions 4.1, 4.3, 4.5, 4.6 and Lemmata 4.5, 4.7, 5.1, 5.4 *** import Universe.Utility.Pointed {- Homotopically complicated types. Corresponds to section 5 sans the initial lemma. Concludes with the main theorem that the n-types in the n-th universe from a strict n-type. Hierarchy and Trunc.* are mutually independent. -} {- *** Lemmata 5.2, 5.7, 5.8(*), Theorems 5.9, 5.11, and Corollary 5.6 *** (*) a slightly weaker version -} import Universe.Hierarchy {- Connectedness constructions Corresponds to section 6 and 7. The first three modules develop a framework of truncations internal to MLTT+Univalence without truncations. Connection contains the main result of section 6. ConnectednessAlt is independent from the first four modules and presents a provably equivalent definition of n-connectedness using only propositional truncation (as remarked in the article and mentioned in an exercise in the HoTT book). -} --- *** Definition 6.2, Lemma 6.6 import Universe.Trunc.Universal --- *** Definition 6.4, Lemma 6.7 *** import Universe.Trunc.Basics --- *** Lemmata 6.9, 6.10 import Universe.Trunc.TypeConstructors --- *** Definitions 6.11, 6.13, Lemmata 6.12, 6.14, 6.15 import Universe.Trunc.Connection import Universe.Trunc.ConnectednessAlt
{ "alphanum_fraction": 0.7354807223, "avg_line_length": 37.9444444444, "ext": "agda", "hexsha": "7369a9b296ad05d90e5a68a014abf5a7a53deb9c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sattlerc/HoTT-Agda", "max_forks_repo_path": "Universe/index.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sattlerc/HoTT-Agda", "max_issues_repo_path": "Universe/index.agda", "max_line_length": 74, "max_stars_count": null, "max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "sattlerc/HoTT-Agda", "max_stars_repo_path": "Universe/index.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 552, "size": 2049 }
module +-example where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) open import Naturals using (suc; _+_) +-example : 3 + 4 ≡ 7 +-example = begin 3 + 4 ≡⟨⟩ suc (2 + 4) ≡⟨⟩ suc (suc (1 + 4)) ≡⟨⟩ suc (suc (suc (0 + 4))) ≡⟨⟩ suc (suc (suc 4)) ≡⟨⟩ 7 ∎
{ "alphanum_fraction": 0.5333333333, "avg_line_length": 15.652173913, "ext": "agda", "hexsha": "b0fdc0360a4b1b33a257476e75b678f581bde003", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "akiomik/plfa-solutions", "max_forks_repo_path": "part1/naturals/+-example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "akiomik/plfa-solutions", "max_issues_repo_path": "part1/naturals/+-example.agda", "max_line_length": 50, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "akiomik/plfa-solutions", "max_stars_repo_path": "part1/naturals/+-example.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z", "num_tokens": 170, "size": 360 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Vectors where all elements satisfy a given property ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Relation.Unary.All where open import Data.Nat.Base using (zero; suc) open import Data.Fin.Base using (Fin; zero; suc) open import Data.Product as Prod using (_×_; _,_; uncurry; <_,_>) open import Data.Vec.Base as Vec using (Vec; []; _∷_) open import Function using (_∘_) open import Level using (Level; _⊔_) open import Relation.Nullary hiding (Irrelevant) import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Product using (_×-dec_) open import Relation.Unary open import Relation.Binary.PropositionalEquality as P using (subst) private variable a b c p q r : Level A : Set a B : Set b C : Set c ------------------------------------------------------------------------ -- All P xs means that all elements in xs satisfy P. infixr 5 _∷_ data All {a} {A : Set a} (P : Pred A p) : ∀ {n} → Vec A n → Set (p ⊔ a) where [] : All P [] _∷_ : ∀ {n x} {xs : Vec A n} (px : P x) (pxs : All P xs) → All P (x ∷ xs) ------------------------------------------------------------------------ -- Operations on All module _ {P : Pred A p} where head : ∀ {n x} {xs : Vec A n} → All P (x ∷ xs) → P x head (px ∷ pxs) = px tail : ∀ {n x} {xs : Vec A n} → All P (x ∷ xs) → All P xs tail (px ∷ pxs) = pxs uncons : ∀ {n x} {xs : Vec A n} → All P (x ∷ xs) → P x × All P xs uncons = < head , tail > lookup : ∀ {n} {xs : Vec A n} (i : Fin n) → All P xs → P (Vec.lookup xs i) lookup zero (px ∷ pxs) = px lookup (suc i) (px ∷ pxs) = lookup i pxs tabulate : ∀ {n xs} → (∀ i → P (Vec.lookup xs i)) → All P {n} xs tabulate {xs = []} pxs = [] tabulate {xs = _ ∷ _} pxs = pxs zero ∷ tabulate (pxs ∘ suc) module _ {P : Pred A p} {Q : Pred A q} where map : ∀ {n} → P ⊆ Q → All P {n} ⊆ All Q {n} map g [] = [] map g (px ∷ pxs) = g px ∷ map g pxs zip : ∀ {n} → All P ∩ All Q ⊆ All (P ∩ Q) {n} zip ([] , []) = [] zip (px ∷ pxs , qx ∷ qxs) = (px , qx) ∷ zip (pxs , qxs) unzip : ∀ {n} → All (P ∩ Q) {n} ⊆ All P ∩ All Q unzip [] = [] , [] unzip (pqx ∷ pqxs) = Prod.zip _∷_ _∷_ pqx (unzip pqxs) module _ {P : Pred A p} {Q : Pred B q} {R : Pred C r} where zipWith : ∀ {_⊕_ : A → B → C} → (∀ {x y} → P x → Q y → R (x ⊕ y)) → ∀ {n xs ys} → All P {n} xs → All Q {n} ys → All R {n} (Vec.zipWith _⊕_ xs ys) zipWith _⊕_ {xs = []} {[]} [] [] = [] zipWith _⊕_ {xs = x ∷ xs} {y ∷ ys} (px ∷ pxs) (qy ∷ qys) = px ⊕ qy ∷ zipWith _⊕_ pxs qys ------------------------------------------------------------------------ -- Properties of predicates preserved by All module _ {P : Pred A p} where all : ∀ {n} → Decidable P → Decidable (All P {n}) all P? [] = yes [] all P? (x ∷ xs) = Dec.map′ (uncurry _∷_) uncons (P? x ×-dec all P? xs) universal : Universal P → ∀ {n} → Universal (All P {n}) universal u [] = [] universal u (x ∷ xs) = u x ∷ universal u xs irrelevant : Irrelevant P → ∀ {n} → Irrelevant (All P {n}) irrelevant irr [] [] = P.refl irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) = P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂) satisfiable : Satisfiable P → ∀ {n} → Satisfiable (All P {n}) satisfiable (x , p) {zero} = [] , [] satisfiable (x , p) {suc n} = Prod.map (x ∷_) (p ∷_) (satisfiable (x , p))
{ "alphanum_fraction": 0.4779005525, "avg_line_length": 33.8317757009, "ext": "agda", "hexsha": "14d4a3c05bb2487ab936638582e06ccfcbe3d1e0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/Vec/Relation/Unary/All.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/Vec/Relation/Unary/All.agda", "max_line_length": 77, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/Vec/Relation/Unary/All.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1270, "size": 3620 }
-- Andreas, 2015-07-22 Fixed bug in test for empty type of sizes {-# OPTIONS --copatterns #-} open import Common.Size record U (i : Size) : Set where coinductive field out : (j : Size< i) → U j open U fixU : {A : Size → Set} (let C = λ i → A i → U i) → ∀ i (f : ∀ i → (∀ (j : Size< i) → C j) → C i) → C i out (fixU i f a) j = out (f i {!λ (j : Size< i) → fixU j f!} a) j -- Giving should succeed (even if termination checking might not succeed yet)
{ "alphanum_fraction": 0.579175705, "avg_line_length": 27.1176470588, "ext": "agda", "hexsha": "e7c2a284d8b1e2dc76222d303b97d95763f3ed18", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue1523.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue1523.agda", "max_line_length": 77, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue1523.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 169, "size": 461 }
{- 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 -} module Dijkstra.Syntax where open import Dijkstra.EitherD open import Dijkstra.EitherLike open import Dijkstra.RWS open import Haskell.Prelude open import Optics.All {- Within a "Dijkstra-fied" monad `M`, `if` and `ifD` are semantically interchangeable. The difference is in how proof obligations are generated - with the *D variants generating new weakestPre obligations for each case. In some cases, this is helpful for structuring proofs, while in other cases it is unnecessary and introduces more structure to the proof without adding any benefit. A rule of thumb is that, if the "scrutinee" (whatever we are doing case analysis on, i.e., the first argument) is the value provided via >>= (bind) by a previous code block, then we already have a weakestPre proof obligation, so introducing additional ones via the *D variants only creates more work and provides no additional benefit. -} record MonadIfD {ℓ₁ ℓ₂ ℓ₃ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁ ℓ⊔ ℓ+1 ℓ₃) where infix 1 ifD‖_ field ⦃ monad ⦄ : Monad M ifD‖_ : ∀ {A : Set ℓ₁} → Guards{ℓ₂}{ℓ₃} (M A) → M A open MonadIfD ⦃ ... ⦄ public module _ {ℓ₁ ℓ₂ ℓ₃} {M : Set ℓ₁ → Set ℓ₂} where private variable A : Set ℓ₁ B : Set ℓ₃ infix 0 ifD_then_else_ ifD_then_else_ : ⦃ _ : MonadIfD{ℓ₃ = ℓ₃} M ⦄ ⦃ _ : ToBool B ⦄ → B → (c₁ c₂ : M A) → M A ifD b then c₁ else c₂ = ifD‖ b ≔ c₁ ‖ otherwise≔ c₂ whenD : ∀ {ℓ₂ ℓ₃} {M : Set → Set ℓ₂} {B : Set ℓ₃} ⦃ _ : MonadIfD{ℓ0}{ℓ₂}{ℓ₃} M ⦄ ⦃ _ : ToBool B ⦄ → B → M Unit → M Unit whenD b f = ifD b then f else pure unit module _ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} where private variable A B : Set ℓ₁ ifMD : ⦃ mi : MonadIfD{ℓ₃ = ℓ₁} M ⦄ ⦃ _ : ToBool B ⦄ → M B → (c₁ c₂ : M A) → M A ifMD{B = B} ⦃ mi ⦄ m c₁ c₂ = do x ← m ifD x then c₁ else c₂ record MonadMaybeD {ℓ₁ ℓ₂ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where field ⦃ monad ⦄ : Monad M maybeD : ∀ {A B : Set ℓ₁} → M B → (A → M B) → Maybe A → M B open MonadMaybeD ⦃ ... ⦄ public infix 0 caseMD_of_ caseMD_of_ : ∀ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : MonadMaybeD M ⦄ {A B : Set ℓ₁} → Maybe A → (Maybe A → M B) → M B caseMD m of f = maybeD (f nothing) (f ∘ just) m record MonadEitherD {ℓ₁ ℓ₂ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where field ⦃ monad ⦄ : Monad M eitherD : ∀ {E A B : Set ℓ₁} → (E → M B) → (A → M B) → Either E A → M B open MonadEitherD ⦃ ... ⦄ public hiding (eitherD) eitherD : ∀ {ℓ₁ ℓ₂ ℓ₃} {M : Set ℓ₁ → Set ℓ₂} ⦃ med : MonadEitherD M ⦄ → ∀ {EL : Set ℓ₁ → Set ℓ₁ → Set ℓ₃} ⦃ _ : EitherLike EL ⦄ → ∀ {E A B : Set ℓ₁} → (E → M B) → (A → M B) → EL E A → M B eitherD ⦃ med = med ⦄ f₁ f₂ e = MonadEitherD.eitherD med f₁ f₂ (toEither e) infix 0 case⊎D_of_ case⊎D_of_ : ∀ {ℓ₁ ℓ₂ ℓ₃} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : MonadEitherD M ⦄ → ∀ {EL : Set ℓ₁ → Set ℓ₁ → Set ℓ₃} ⦃ _ : EitherLike EL ⦄ → ∀ {E A B : Set ℓ₁} → EL E A → (EL E A → M B) → M B case⊎D e of f = eitherD (f ∘ fromEither ∘ Left) (f ∘ fromEither ∘ Right) e
{ "alphanum_fraction": 0.6233128834, "avg_line_length": 34.6808510638, "ext": "agda", "hexsha": "af6a59470f745755de4ee4dd4a9ab2a8bc342d66", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/Dijkstra/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/Dijkstra/Syntax.agda", "max_line_length": 119, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/Dijkstra/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1396, "size": 3260 }
open import Agda.Builtin.Nat foo : Nat → Nat foo x = bar x where bar : Nat → Nat bar y = {!x!} -- WAS: Splitting on x produces the following garbage: -- foo : Nat → Nat -- foo x = bar x -- where -- bar : Nat → Nat -- bar y = {!!} -- bar y = {!!} -- SHOULD: raise an error
{ "alphanum_fraction": 0.5317725753, "avg_line_length": 16.6111111111, "ext": "agda", "hexsha": "b7d232f5f35886ac17e00b9aa35c08aed33a0198", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue3095-visible.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue3095-visible.agda", "max_line_length": 54, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue3095-visible.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 98, "size": 299 }
module Numeral.Natural.Relation.Divisibility.Proofs where import Lvl open import Data open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Logic.Propositional open import Logic.Propositional.Theorems open import Logic.Predicate open import Logic.Predicate.Theorems open import Numeral.Finite open import Numeral.Natural open import Numeral.Natural.Function open import Numeral.Natural.Oper open import Numeral.Natural.Oper.Modulo open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Oper.Proofs.Multiplication open import Numeral.Natural.Oper.Proofs.Order open import Numeral.Natural.Relation open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Classical open import Numeral.Natural.Relation.Order.Proofs open import Numeral.Natural.Relation.Order.Existence using ([≤]-equivalence) open import Numeral.Natural.Relation.Order.Existence.Proofs using () open import Numeral.Natural.Relation.Divisibility open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Operator open import Structure.Operator.Proofs.Util open import Structure.Operator.Properties open import Structure.Relator open import Structure.Relator.Properties open import Syntax.Transitivity open import Type open import Type.Properties.MereProposition {- div-elim-test : ∀{ℓ ℓ₁}{A : Type{ℓ₁}}{f : A → ℕ}{g : ℕ → ℕ}{P : ∀{y x} → (f(y) ∣ x) → Type{ℓ}} → (∀{y} → P(Div𝟎{f y})) → (∀{y x}{p : f y ∣ g x} → P(p) → P(Div𝐒 p)) → (∀{y x}{p : f(y) ∣ g x} → P(p)) div-elim-test {f = f}{g = g} z s {y}{x}{p = p} with g(x) ... | 𝟎 = {!p!} ... | 𝐒 a = {!p!} -- div-elim-test z s {p = Div𝟎} = z -- div-elim-test{f = f}{P = P} z s {p = Div𝐒 p} = s(div-elim-test{f = f}{P = P} z s {p = p}) -} {- Even-mereProposition : ∀{n} → MereProposition(Even(n)) Even-mereProposition = intro proof where proof : ∀{n}{p q : Even n} → (p ≡ q) proof {𝟎} {Even0} {Even0} = [≡]-intro proof {𝐒(𝐒(n))} {Even𝐒 p} {Even𝐒 q} = [≡]-with(Even𝐒) (proof {n} {p} {q}) Odd-mereProposition : ∀{n} → MereProposition(Odd(n)) Odd-mereProposition = intro proof where proof : ∀{n}{p q : Odd n} → (p ≡ q) proof {𝐒(𝟎)} {Odd0} {Odd0} = [≡]-intro proof {𝐒(𝐒(n))} {Odd𝐒 p} {Odd𝐒 q} = [≡]-with(Odd𝐒) (proof {n} {p} {q}) -} {- div-elim-test : ∀{f : ℕ → ℕ}{ℓ}{P : ∀{y x} → (f y ∣ x) → Type{ℓ}} → (∀{y} → P(Div𝟎{f y})) → (∀{y x}{p : f y ∣ x} → P(p) → P(Div𝐒 p)) → (∀{y x}{p : f y ∣ x} → P(p)) div-elim-test z s {p = Div𝟎} = z div-elim-test{f = f}{P = P} z s {p = Div𝐒 p} = s(div-elim-test{f = f}{P = P} z s {p = p}) divides-mereProposition : ∀{d n} → MereProposition(𝐒(d) ∣ n) divides-mereProposition = intro proof where proof : ∀{d n}{p q : (𝐒(d) ∣ n)} → (p ≡ q) proof {d} {.𝟎} {Div𝟎} {Div𝟎} = [≡]-intro proof {d} {.(𝐒 d + _)} {Div𝐒 p} {q} = {!div-elim-test{P = Div𝐒 p ≡_} ? ? {?}!} --proof{d}{n}{p}{q} = div-elim {P = \q → ∀{p} → (p ≡ q)} (\{y}{p} → {!div-elim {P = _≡ Div𝟎} ? ? {p = p}!}) {!!} {p = q} -- div-elim{P = {!!}} (div-elim {!!} {!!} {p = p}) (div-elim {!!} {!!} {p = p}) {p = q} {- test : ∀{y x} → (y ∣ x) → ∃{Obj = ℕ ⨯ ℕ}(Tuple.uncurry(_∣_)) test {y}{.𝟎} Div𝟎 = [∃]-intro (y , 𝟎) ⦃ Div𝟎 ⦄ test (Div𝐒 p) = [∃]-intro _ ⦃ p ⦄ -} -} DivN : ∀{y : ℕ} → (n : ℕ) → (y ∣ (y ⋅ n)) DivN {y}(𝟎) = Div𝟎 DivN {y}(𝐒(n)) = Div𝐒(DivN{y}(n)) divides-quotient : ∀{x y} → (y ∣ x) → ℕ divides-quotient = divides-elim 𝟎 𝐒 divides-quotient-correctness : ∀{x y}{yx : (y ∣ x)} → (y ⋅ (divides-quotient yx) ≡ x) divides-quotient-correctness {yx = Div𝟎} = [≡]-intro divides-quotient-correctness {_}{y} {yx = Div𝐒 yx} = congruence₂ᵣ(_+_)(y) (divides-quotient-correctness {yx = yx}) divides-[⋅]-existence : ∀{x y} → ∃(n ↦ y ⋅ n ≡ x) ↔ (y ∣ x) divides-[⋅]-existence = [↔]-intro l r where l : ∀{x y} → (y ∣ x) → (∃(n ↦ y ⋅ n ≡ x)) l yx = [∃]-intro (divides-quotient yx) ⦃ divides-quotient-correctness {yx = yx} ⦄ r : ∀{x y} → (∃(n ↦ y ⋅ n ≡ x)) → (y ∣ x) r {x}{y} ([∃]-intro n ⦃ y⋅n≡x ⦄) = [≡]-substitutionᵣ y⋅n≡x {y ∣_} (DivN{y}(n)) divides-[⋅]-existence₊ : ∀{x y} → (y ∣ 𝐒(x)) → ∃(n ↦ y ⋅ 𝐒(n) ≡ 𝐒(x)) divides-[⋅]-existence₊ {x}{y} p with [↔]-to-[←] (divides-[⋅]-existence{𝐒(x)}{y}) p ... | [∃]-intro (𝐒(n)) = [∃]-intro n instance divides-transitivity : Transitivity(_∣_) Transitivity.proof (divides-transitivity) {a}{b}{c} (a-div-b) (b-div-c) with ([↔]-to-[←] divides-[⋅]-existence a-div-b , [↔]-to-[←] divides-[⋅]-existence b-div-c) ... | (([∃]-intro (n₁) ⦃ a⋅n₁≡b ⦄),([∃]-intro (n₂) ⦃ b⋅n₂≡c ⦄)) = ([↔]-to-[→] divides-[⋅]-existence ([∃]-intro (n₁ ⋅ n₂) ⦃ (symmetry(_≡_) (associativity(_⋅_) {a}{n₁}{n₂})) 🝖 ([≡]-with(expr ↦ expr ⋅ n₂) (a⋅n₁≡b)) 🝖 (b⋅n₂≡c) ⦄ ) ) divides-with-[+] : ∀{a b c} → (a ∣ b) → (a ∣ c) → (a ∣ (b + c)) divides-with-[+] {a}{b}{c} (a-div-b) (a-div-c) with ([↔]-to-[←] divides-[⋅]-existence a-div-b , [↔]-to-[←] divides-[⋅]-existence a-div-c) ... | (([∃]-intro (n₁) ⦃ a⋅n₁≡b ⦄),([∃]-intro (n₂) ⦃ a⋅n₂≡c ⦄)) = ([↔]-to-[→] divides-[⋅]-existence ([∃]-intro (n₁ + n₂) ⦃ (distributivityₗ(_⋅_)(_+_) {a}{n₁}{n₂}) 🝖 ([≡]-with-op(_+_) (a⋅n₁≡b) (a⋅n₂≡c) ) ⦄ ) ) divides-with-[−₀] : ∀{a b c} → (a ∣ b) → (a ∣ c) → (a ∣ (b −₀ c)) divides-with-[−₀] {a}{b}{c} (a-div-b) (a-div-c) with ([↔]-to-[←] divides-[⋅]-existence a-div-b , [↔]-to-[←] divides-[⋅]-existence a-div-c) ... | (([∃]-intro (n₁) ⦃ a⋅n₁≡b ⦄),([∃]-intro (n₂) ⦃ a⋅n₂≡c ⦄)) = ([↔]-to-[→] divides-[⋅]-existence ([∃]-intro (n₁ −₀ n₂) ⦃ (distributivityₗ(_⋅_)(_−₀_) {a}{n₁}{n₂}) 🝖 ([≡]-with-op(_−₀_) (a⋅n₁≡b) (a⋅n₂≡c) ) ⦄ ) ) divides-without-[+] : ∀{a b c} → (a ∣ (b + c)) → ((a ∣ b) ↔ (a ∣ c)) divides-without-[+] {a}{b}{c} abc = [↔]-intro (l abc) (r abc) where l : ∀{a b c} → (a ∣ (b + c)) → (a ∣ b) ← (a ∣ c) l{a}{b}{c} abc ac = [≡]-substitutionᵣ ([−₀]ₗ[+]ᵣ-nullify{b}{c}) {expr ↦ (a ∣ expr)} (divides-with-[−₀] {a}{b + c}{c} abc ac) r : ∀{a b c} → (a ∣ (b + c)) → (a ∣ b) → (a ∣ c) r{a}{b}{c} abc ab = l {a}{c}{b} ([≡]-substitutionᵣ (commutativity(_+_) {b}{c}) {expr ↦ a ∣ expr} abc) ab divides-with-[𝄩] : ∀{a b c} → (a ∣ b) → (a ∣ c) → (a ∣ (b 𝄩 c)) divides-with-[𝄩] {a} ab ac with [∃]-intro n₁ ⦃ p ⦄ ← [↔]-to-[←] divides-[⋅]-existence ab with [∃]-intro n₂ ⦃ q ⦄ ← [↔]-to-[←] divides-[⋅]-existence ac = [↔]-to-[→] divides-[⋅]-existence ([∃]-intro (n₁ 𝄩 n₂) ⦃ distributivityₗ(_⋅_)(_𝄩_) {a}{n₁}{n₂} 🝖 congruence₂(_𝄩_) p q ⦄) -- instance -- divides-with-fn : ∀{a b} → (a ∣ b) → ∀{f : ℕ → ℕ} → {_ : ∀{x y : ℕ} → ∃{ℕ → ℕ}(\g → f(x ⋅ y) ≡ f(x) ⋅ g(y))} → ((f(a)) ∣ (f(b))) -- divides-with-fn {a}{b} (a-div-b) {f} ⦃ f-prop ⦄ instance [1]-divides : ∀{n} → (1 ∣ n) [1]-divides {𝟎} = Div𝟎 [1]-divides {𝐒(n)} = [≡]-substitutionₗ (commutativity(_+_) {n}{1}) {expr ↦ (1 ∣ expr)} (Div𝐒([1]-divides{n})) -- TODO: Rename these reflexivity proofs instance divides-reflexivity : ∀{n} → (n ∣ n) divides-reflexivity = Div𝐒(Div𝟎) instance divides-reflexivity-instance : Reflexivity(_∣_) divides-reflexivity-instance = intro divides-reflexivity instance [0]-divides-[0] : (0 ∣ 0) [0]-divides-[0] = Div𝟎 [0]-only-divides-[0] : ∀{n} → (0 ∣ n) → (n ≡ 0) [0]-only-divides-[0] {𝟎} _ = [≡]-intro [0]-only-divides-[0] {𝐒(n)} proof with () ← [∃]-proof([↔]-to-[←] divides-[⋅]-existence proof) [0]-divides-not : ∀{n} → ¬(0 ∣ 𝐒(n)) [0]-divides-not (0divSn) = [𝐒]-not-0([0]-only-divides-[0] 0divSn) divides-not-[1] : ∀{n} → ¬((n + 2) ∣ 1) divides-not-[1] () [1]-only-divides-[1] : ∀{n} → (n ∣ 1) → (n ≡ 1) [1]-only-divides-[1] {𝟎} ndiv1 = [⊥]-elim ([0]-divides-not ndiv1) [1]-only-divides-[1] {𝐒(𝟎)} ndiv1 = [≡]-intro [1]-only-divides-[1] {𝐒(𝐒(n))} () divides-with-[⋅] : ∀{a b c} → ((a ∣ b) ∨ (a ∣ c)) → (a ∣ (b ⋅ c)) divides-with-[⋅] {a}{b}{c} = [∨]-elim (l{a}{b}{c}) (r{a}{b}{c}) where l : ∀{a b c} → (a ∣ b) → (a ∣ (b ⋅ c)) l Div𝟎 = Div𝟎 l {a}{a}{c} (Div𝐒 Div𝟎) = DivN{a} c l {a} {.(a + x)} {c} (Div𝐒 {.a} {x} ab@(Div𝐒 _)) = [≡]-substitutionₗ (distributivityᵣ(_⋅_)(_+_) {a}{x}{c}) {a ∣_} (divides-with-[+] (l {a}{a}{c} (Div𝐒 Div𝟎)) (l {a}{x}{c} ab)) r : ∀{a b c} → (a ∣ c) → (a ∣ (b ⋅ c)) r {a}{b}{c} ac = [≡]-substitutionᵣ (commutativity(_⋅_) {c}{b}) {a ∣_} (l {a}{c}{b} ac) divides-upper-limit : ∀{a b} → (a ∣ 𝐒(b)) → (a ≤ 𝐒(b)) divides-upper-limit {𝟎} {_} (proof) = [⊥]-elim ([0]-divides-not (proof)) divides-upper-limit {𝐒(a)}{b} (proof) = ([↔]-to-[→] [≤]-equivalence) (existence2) where existence1 : ∃(n ↦ 𝐒(a) + (𝐒(a) ⋅ n) ≡ 𝐒(b)) existence1 = divides-[⋅]-existence₊(proof) existence2 : ∃(n ↦ 𝐒(a) + n ≡ 𝐒(b)) existence2 = [∃]-intro(𝐒(a) ⋅ [∃]-witness(existence1)) ⦃ [∃]-proof(existence1) ⦄ divides-not-lower-limit : ∀{a b} → (a > 𝐒(b)) → (a ∤ 𝐒(b)) divides-not-lower-limit {a}{b} = (contrapositiveᵣ (divides-upper-limit {a}{b})) ∘ [>]-to-[≰] Div𝐏 : ∀{x y : ℕ} → (y ∣ (y + x)) → (y ∣ x) Div𝐏 {x}{y} proof = [↔]-to-[→] (divides-without-[+] {y}{y}{x} proof) (divides-reflexivity) Div𝐏-monus : ∀{x y : ℕ} → (y ∣ x) → (y ∣ (x −₀ y)) Div𝐏-monus Div𝟎 = Div𝟎 Div𝐏-monus {.(y + x)}{y} (Div𝐒 {_}{x} yx) = [≡]-substitutionₗ ([−₀]ₗ[+]ₗ-nullify {y}{x}) {y ∣_} yx divides-with-[⋅]ₗ-both : ∀{x y z} → (x ∣ y) → (z ⋅ x ∣ z ⋅ y) divides-with-[⋅]ₗ-both {x} {.0} {z} Div𝟎 = Div𝟎 divides-with-[⋅]ₗ-both {x} {.(x + _)} {z} (Div𝐒 {_}{y} xy) rewrite distributivityₗ(_⋅_)(_+_) {z}{x}{y} = Div𝐒 (divides-with-[⋅]ₗ-both {x}{y}{z} xy) divides-with-[⋅]ᵣ-both : ∀{x y z} → (x ∣ y) → (x ⋅ z ∣ y ⋅ z) divides-with-[⋅]ᵣ-both {x} {.0} {z} Div𝟎 = Div𝟎 divides-with-[⋅]ᵣ-both {x} {.(x + _)} {z} (Div𝐒 {_}{y} xy) rewrite distributivityᵣ(_⋅_)(_+_) {x}{y}{z} = Div𝐒 (divides-with-[⋅]ᵣ-both {x}{y}{z} xy) divides-with-[⋅]-both : ∀{x₁ y₁ x₂ y₂} → (x₁ ∣ y₁) → (x₂ ∣ y₂) → (x₁ ⋅ x₂ ∣ y₁ ⋅ y₂) divides-with-[⋅]-both {x₁}{y₁}{x₂}{y₂} xy1 xy2 with [∃]-intro n₁ ⦃ [≡]-intro ⦄ ← [↔]-to-[←] divides-[⋅]-existence xy1 with [∃]-intro n₂ ⦃ [≡]-intro ⦄ ← [↔]-to-[←] divides-[⋅]-existence xy2 = [↔]-to-[→] divides-[⋅]-existence ([∃]-intro (n₁ ⋅ n₂) ⦃ One.associate-commute4 {_▫_ = _⋅_} {a = x₁}{x₂}{n₁}{n₂} (commutativity(_⋅_) {x₂}{n₁}) ⦄) divides-with-[^] : ∀{a b n} → (a ∣ b) → ((a ^ n) ∣ (b ^ n)) divides-with-[^] {n = 𝟎} _ = Div𝐒 Div𝟎 divides-with-[^] {n = 𝐒 n} ab = divides-with-[⋅]-both ab (divides-with-[^] {n = n} ab) divides-withᵣ-[^] : ∀{a b n} → ⦃ pos : Positive(n) ⦄ → (a ∣ b) → (a ∣ (b ^ n)) divides-withᵣ-[^] {a}{b}{𝐒 n} ab = divides-with-[⋅] {a}{b}{b ^ n} ([∨]-introₗ ab) divides-without-[⋅]ᵣ-both : ∀{x y z} → (x ⋅ 𝐒(z) ∣ y ⋅ 𝐒(z)) → (x ∣ y) divides-without-[⋅]ᵣ-both {x}{y}{z} p with [∃]-intro n ⦃ peq ⦄ ← [↔]-to-[←] divides-[⋅]-existence p = [↔]-to-[→] divides-[⋅]-existence ([∃]-intro n ⦃ [⋅]-cancellationᵣ{𝐒(z)} (symmetry(_≡_) (One.commuteᵣ-assocₗ{_▫_ = _⋅_}{x}{𝐒(z)}{n}) 🝖 peq) ⦄) divides-without-[⋅]ₗ-both : ∀{x y z} → (𝐒(z) ⋅ x ∣ 𝐒(z) ⋅ y) → (x ∣ y) divides-without-[⋅]ₗ-both {x}{y}{z} p = divides-without-[⋅]ᵣ-both {x}{y}{z} (substitute₂(_∣_) (commutativity(_⋅_) {𝐒(z)}{x}) (commutativity(_⋅_) {𝐒(z)}{y}) p) divides-without-[⋅]ᵣ-both' : ∀{x y z} → (z > 0) → (x ⋅ z ∣ y ⋅ z) → (x ∣ y) divides-without-[⋅]ᵣ-both' {x}{y}{𝐒(z)} _ = divides-without-[⋅]ᵣ-both {x}{y}{z} divides-without-[⋅]ₗ-both' : ∀{x y z} → (z > 0) → (z ⋅ x ∣ z ⋅ y) → (x ∣ y) divides-without-[⋅]ₗ-both' {x}{y}{𝐒(z)} _ = divides-without-[⋅]ₗ-both {x}{y}{z} divides-factorial : ∀{n x} → (𝐒(x) ≤ n) → (𝐒(x) ∣ (n !)) divides-factorial {.(𝐒 y)}{.x} (succ {x}{y} xy) with [≥]-or-[<] {x}{y} ... | [∨]-introₗ yx with [≡]-intro ← antisymmetry(_≤_)(_≡_) xy yx = divides-with-[⋅] {𝐒(x)}{𝐒(x)}{x !} ([∨]-introₗ(reflexivity(_∣_))) ... | [∨]-introᵣ sxy = divides-with-[⋅] {𝐒(x)}{𝐒(y)}{y !} ([∨]-introᵣ(divides-factorial{y}{x} sxy)) instance divides-antisymmetry : Antisymmetry(_∣_)(_≡_) Antisymmetry.proof divides-antisymmetry {𝟎} {𝟎} ab ba = [≡]-intro Antisymmetry.proof divides-antisymmetry {𝟎} {𝐒 b} ab ba with () ← [0]-divides-not ab Antisymmetry.proof divides-antisymmetry {𝐒 a} {𝟎} ab ba with () ← [0]-divides-not ba Antisymmetry.proof divides-antisymmetry {𝐒 a} {𝐒 b} ab ba = antisymmetry(_≤_)(_≡_) (divides-upper-limit ab) (divides-upper-limit ba) divides-quotient-positive : ∀{d n}{dn : (d ∣ 𝐒(n))} → (divides-quotient dn ≥ 1) divides-quotient-positive {𝟎} {n} {dn = dn} with () ← [0]-divides-not dn divides-quotient-positive {𝐒 d} {.(d + _)} {dn = Div𝐒 dn} = succ _≤_.min divides-quotient-composite : ∀{d n} → (d ≥ 2) → (d < n) → ∀{dn : (d ∣ n)} → (divides-quotient dn ≥ 2) divides-quotient-composite l g {Div𝐒 {x = 𝟎} dn} with () ← irreflexivity(_<_) g divides-quotient-composite l g {Div𝐒 {x = 𝐒 x} dn} = succ (divides-quotient-positive {dn = dn})
{ "alphanum_fraction": 0.5244169667, "avg_line_length": 44.0620689655, "ext": "agda", "hexsha": "6774d064db4e7ce1a387103014ff31f466594467", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Numeral/Natural/Relation/Divisibility/Proofs.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Numeral/Natural/Relation/Divisibility/Proofs.agda", "max_line_length": 197, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Numeral/Natural/Relation/Divisibility/Proofs.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 6425, "size": 12778 }
open import Nat open import Prelude open import List open import contexts open import judgemental-erase open import lemmas-matching open import moveerase open import sensibility open import statics-core open import synth-unicity module statics-checks where -- these three judmgements lift the action semantics judgements to relate -- an expression and a list of pair-wise composable actions to the -- expression that's produced by tracing through the action semantics for -- each element in that list. -- -- we do this just by appealing to the original judgement with -- constraints on the terms to enforce composability. -- -- in all three cases, we assert that the empty list of actions -- constitutes a reflexivity step, so when you run out of actions to -- preform you have to be where you wanted to be. -- -- note that the only difference between the types for each judgement and -- the original action semantics is that the action is now a list of -- actions. data runtype : (t : ztyp) (Lα : List action) (t' : ztyp) → Set where DoRefl : {t : ztyp} → runtype t [] t DoType : {t : ztyp} {α : action} {t' t'' : ztyp} {L : List action} → t + α +> t' → runtype t' L t'' → runtype t (α :: L) t'' data runsynth : (Γ : tctx) (e : zexp) (t1 : htyp) (Lα : List action) (e' : zexp) (t2 : htyp) → Set where DoRefl : {Γ : tctx} {e : zexp} {t : htyp} → runsynth Γ e t [] e t DoSynth : {Γ : tctx} {e : zexp} {t : htyp} {α : action} {e' e'' : zexp} {t' t'' : htyp} {L : List action} → Γ ⊢ e => t ~ α ~> e' => t' → runsynth Γ e' t' L e'' t'' → runsynth Γ e t (α :: L) e'' t'' data runana : (Γ : tctx) (e : zexp) (Lα : List action) (e' : zexp) (t : htyp) → Set where DoRefl : {Γ : tctx} {e : zexp} {t : htyp} → runana Γ e [] e t DoAna : {Γ : tctx} {e : zexp} {α : action} {e' e'' : zexp} {t : htyp} {L : List action} → Γ ⊢ e ~ α ~> e' ⇐ t → runana Γ e' L e'' t → runana Γ e (α :: L) e'' t -- all three run judgements lift to the list monoid as expected. these -- theorems are simple because the structure of lists is simple, but they -- amount a reasoning principle about the composition of action sequences -- by letting you split lists in (nearly) arbitrary places and argue -- about the consequences of the splits before composing them together. runtype++ : ∀{t t' t'' L1 L2 } → runtype t L1 t' → runtype t' L2 t'' → runtype t (L1 ++ L2) t'' runtype++ DoRefl d2 = d2 runtype++ (DoType x d1) d2 = DoType x (runtype++ d1 d2) runsynth++ : ∀{Γ e t L1 e' t' L2 e'' t''} → runsynth Γ e t L1 e' t' → runsynth Γ e' t' L2 e'' t'' → runsynth Γ e t (L1 ++ L2) e'' t'' runsynth++ DoRefl d2 = d2 runsynth++ (DoSynth x d1) d2 = DoSynth x (runsynth++ d1 d2) runana++ : ∀{Γ e t L1 e' L2 e''} → runana Γ e L1 e' t → runana Γ e' L2 e'' t → runana Γ e (L1 ++ L2) e'' t runana++ DoRefl d2 = d2 runana++ (DoAna x d1) d2 = DoAna x (runana++ d1 d2) -- the following collection of lemmas asserts that the various runs -- interoperate nicely. in many cases, these amount to observing -- something like congruence: if a subterm is related to something by one -- of the judgements, it can be replaced by the thing to which it is -- related in a larger context without disrupting that larger -- context. -- -- taken together, this is a little messier than a proper congruence, -- because the action semantics demand well-typedness at each step, and -- therefore there are enough premises to each lemma to supply to the -- action semantics rules. -- -- therefore, these amount to a checksum on the zipper actions under the -- lifing of the action semantics to the list monoid. -- -- they only check the zipper actions they happen to be include, however, -- which is driven by the particular lists we use in the proofs of -- contructability and reachability, which may or may not be all of -- them. additionally, the lemmas given here are what is needed for these -- proofs, not anything that's more general. -- type zippers ziplem-tmarr1 : ∀{t1 t1' t2 L} → runtype t1' L t1 → runtype (t1' ==>₁ t2) L (t1 ==>₁ t2) ziplem-tmarr1 DoRefl = DoRefl ziplem-tmarr1 (DoType x L') = DoType (TMArrZip1 x) (ziplem-tmarr1 L') ziplem-tmarr2 : ∀{t1 t2 t2' L} → runtype t2' L t2 → runtype (t1 ==>₂ t2') L (t1 ==>₂ t2) ziplem-tmarr2 DoRefl = DoRefl ziplem-tmarr2 (DoType x L') = DoType (TMArrZip2 x) (ziplem-tmarr2 L') ziplem-tmplus1 : ∀{t1 t1' t2 L} → runtype t1' L t1 → runtype (t1' ⊕₁ t2) L (t1 ⊕₁ t2) ziplem-tmplus1 DoRefl = DoRefl ziplem-tmplus1 (DoType x L') = DoType (TMPlusZip1 x) (ziplem-tmplus1 L') ziplem-tmplus2 : ∀{t1 t2 t2' L} → runtype t2' L t2 → runtype (t1 ⊕₂ t2') L (t1 ⊕₂ t2) ziplem-tmplus2 DoRefl = DoRefl ziplem-tmplus2 (DoType x L') = DoType (TMPlusZip2 x) (ziplem-tmplus2 L') ziplem-tmprod1 : ∀{t1 t1' t2 L} → runtype t1' L t1 → runtype (t1' ⊠₁ t2) L (t1 ⊠₁ t2) ziplem-tmprod1 DoRefl = DoRefl ziplem-tmprod1 (DoType x L') = DoType (TMProdZip1 x) (ziplem-tmprod1 L') ziplem-tmprod2 : ∀{t1 t2 t2' L} → runtype t2' L t2 → runtype (t1 ⊠₂ t2') L (t1 ⊠₂ t2) ziplem-tmprod2 DoRefl = DoRefl ziplem-tmprod2 (DoType x L') = DoType (TMProdZip2 x) (ziplem-tmprod2 L') -- expression zippers ziplem-asc1 : ∀{Γ t L e e'} → runana Γ e L e' t → runsynth Γ (e ·:₁ t) t L (e' ·:₁ t) t ziplem-asc1 DoRefl = DoRefl ziplem-asc1 (DoAna a r) = DoSynth (SAZipAsc1 a) (ziplem-asc1 r) ziplem-asc2 : ∀{Γ t L t' t◆ t'◆ u} → erase-t t t◆ → erase-t t' t'◆ → runtype t L t' → runsynth Γ (⦇-⦈[ u ] ·:₂ t) t◆ L (⦇-⦈[ u ] ·:₂ t') t'◆ ziplem-asc2 {Γ} er er' rt with erase-t◆ er | erase-t◆ er' ... | refl | refl = ziplem-asc2' {Γ = Γ} rt where ziplem-asc2' : ∀{t L t' Γ u} → runtype t L t' → runsynth Γ (⦇-⦈[ u ] ·:₂ t) (t ◆t) L (⦇-⦈[ u ] ·:₂ t') (t' ◆t) ziplem-asc2' DoRefl = DoRefl ziplem-asc2' (DoType x rt) = DoSynth (SAZipAsc2 x (◆erase-t _ _ refl) (◆erase-t _ _ refl) (ASubsume SEHole TCHole1)) (ziplem-asc2' rt) ziplem-lam : ∀{Γ x e t t1 t2 L e'} → x # Γ → t ▸arr (t1 ==> t2) → runana (Γ ,, (x , t1)) e L e' t2 → runana Γ (·λ x e) L (·λ x e') t ziplem-lam a m DoRefl = DoRefl ziplem-lam a m (DoAna x₁ d) = DoAna (AAZipLam a m x₁) (ziplem-lam a m d) ziplem-halflam1 : ∀{Γ u t1 t1' t1◆ t1'◆ x l} → x # Γ → erase-t t1 t1◆ → erase-t t1' t1'◆ → runtype t1 l t1' → runsynth Γ (·λ x ·[ t1 ]₁ ⦇-⦈[ u ]) (t1◆ ==> ⦇-⦈) l (·λ x ·[ t1' ]₁ ⦇-⦈[ u ]) (t1'◆ ==> ⦇-⦈) ziplem-halflam1 apt et et' DoRefl with eraset-det et et' ... | refl = DoRefl ziplem-halflam1 apt et et' (DoType x rt) = DoSynth (SAZipLam1 apt et (rel◆t _) x SEHole SEHole) (ziplem-halflam1 apt (rel◆t _) et' rt) ziplem-halflam2 : ∀{Γ e e' e◆ t1 t2 t2' x L} → x # Γ → erase-e e e◆ → (Γ ,, (x , t1)) ⊢ e◆ => t2 → runsynth (Γ ,, (x , t1)) e t2 L e' t2' → runsynth Γ (·λ x ·[ t1 ]₂ e) (t1 ==> t2) L (·λ x ·[ t1 ]₂ e') (t1 ==> t2') ziplem-halflam2 apt ee wt DoRefl = DoRefl ziplem-halflam2 apt ee wt (DoSynth x rs) = DoSynth (SAZipLam2 apt ee wt x) (ziplem-halflam2 apt (rel◆ _) (actsense-synth ee (rel◆ _) x wt) rs) ziplem-plus1 : ∀{Γ e L e' f} → runana Γ e L e' num → runsynth Γ (e ·+₁ f) num L (e' ·+₁ f) num ziplem-plus1 DoRefl = DoRefl ziplem-plus1 (DoAna x d) = DoSynth (SAZipPlus1 x) (ziplem-plus1 d) ziplem-plus2 : ∀{Γ e L e' f} → runana Γ e L e' num → runsynth Γ (f ·+₂ e) num L (f ·+₂ e') num ziplem-plus2 DoRefl = DoRefl ziplem-plus2 (DoAna x d) = DoSynth (SAZipPlus2 x) (ziplem-plus2 d) ziplem-ap2 : ∀{Γ e L e' t t' f tf} → Γ ⊢ f => t' → t' ▸arr (t ==> tf) → runana Γ e L e' t → runsynth Γ (f ∘₂ e) tf L (f ∘₂ e') tf ziplem-ap2 wt m DoRefl = DoRefl ziplem-ap2 wt m (DoAna x d) = DoSynth (SAZipApAna m wt x) (ziplem-ap2 wt m d) ziplem-nehole-a : ∀{Γ e e' L t t' u} → (Γ ⊢ e ◆e => t) → runsynth Γ e t L e' t' → runsynth Γ ⦇⌜ e ⌟⦈[ u ] ⦇-⦈ L ⦇⌜ e' ⌟⦈[ u ] ⦇-⦈ ziplem-nehole-a wt DoRefl = DoRefl ziplem-nehole-a wt (DoSynth {e = e} x d) = DoSynth (SAZipNEHole (rel◆ e) wt x) (ziplem-nehole-a (actsense-synth (rel◆ e) (rel◆ _) x wt) d) ziplem-nehole-b : ∀{Γ e e' L t t' t'' u} → (Γ ⊢ e ◆e => t) → (t'' ~ t') → runsynth Γ e t L e' t' → runana Γ ⦇⌜ e ⌟⦈[ u ] L ⦇⌜ e' ⌟⦈[ u ] t'' ziplem-nehole-b wt c DoRefl = DoRefl ziplem-nehole-b wt c (DoSynth x rs) = DoAna (AASubsume (erase-in-hole (rel◆ _)) (SNEHole wt) (SAZipNEHole (rel◆ _) wt x) TCHole1) (ziplem-nehole-b (actsense-synth (rel◆ _) (rel◆ _) x wt) c rs) -- because the point of the reachability theorems is to show that we -- didn't forget to define any of the action semantic cases, it's -- important that theorems include the fact that the witness only uses -- move -- otherwise, you could cheat by just prepending [ del ] to the -- list produced by constructability. constructability does also use -- some, but not all, of the possible movements, so this would no longer -- demonstrate the property we really want. to that end, we define a -- predicate on lists that they contain only (move _) and that the -- various things above that produce the lists we use have this property. -- predicate data movements : List action → Set where AM:: : {L : List action} {δ : direction} → movements L → movements ((move δ) :: L) AM[] : movements [] -- movements breaks over the list monoid, as expected movements++ : {l1 l2 : List action} → movements l1 → movements l2 → movements (l1 ++ l2) movements++ (AM:: m1) m2 = AM:: (movements++ m1 m2) movements++ AM[] m2 = m2 -- these are zipper lemmas that are specific to list of movement -- actions. they are not true for general actions, but because -- reachability is restricted to movements, we get some milage out of -- them anyway. endpoints : ∀{Γ e t L e' t'} → Γ ⊢ (e ◆e) => t → runsynth Γ e t L e' t' → movements L → t == t' endpoints _ DoRefl AM[] = refl endpoints wt (DoSynth x rs) (AM:: mv) with endpoints (actsense-synth (rel◆ _) (rel◆ _) x wt) rs mv ... | refl = π2 (moveerase-synth (rel◆ _) wt x) ziplem-moves-asc2 : ∀{ Γ l t t' e t◆} → movements l → erase-t t t◆ → Γ ⊢ e <= t◆ → runtype t l t' → runsynth Γ (e ·:₂ t) t◆ l (e ·:₂ t') t◆ ziplem-moves-asc2 _ _ _ DoRefl = DoRefl ziplem-moves-asc2 (AM:: m) er wt (DoType x rt) with moveeraset' er x ... | er' = DoSynth (SAZipAsc2 x er' er wt) (ziplem-moves-asc2 m er' wt rt) synthana-moves : ∀{t t' l e e' Γ} → Γ ⊢ e ◆e => t' → movements l → t ~ t' → runsynth Γ e t' l e' t' → runana Γ e l e' t synthana-moves _ _ _ DoRefl = DoRefl synthana-moves wt (AM:: m) c (DoSynth x rs) with π2 (moveerase-synth (rel◆ _) wt x) ... | refl = DoAna (AASubsume (rel◆ _) wt x c) (synthana-moves (actsense-synth (rel◆ _) (rel◆ _) x wt) m c rs) ziplem-moves-halflam1 : ∀{Γ e t1 t1' t1◆ t1'◆ t2 t2' x l} → x # Γ → erase-t t1 t1◆ → erase-t t1' t1'◆ → movements l → runtype t1 l t1' → (Γ ,, (x , t1◆)) ⊢ e => t2 → (Γ ,, (x , t1'◆)) ⊢ e => t2' → runsynth Γ (·λ x ·[ t1 ]₁ e) (t1◆ ==> t2) l (·λ x ·[ t1' ]₁ e) (t1'◆ ==> t2') ziplem-moves-halflam1 apt et et' AM[] DoRefl wt1 wt2 with eraset-det et et' ... | refl with synthunicity wt1 wt2 ... | refl = DoRefl ziplem-moves-halflam1 apt et et' (AM:: mv) (DoType x rt) wt1 wt2 with erase-t◆ et | erase-t◆ et' ... | refl | refl with moveeraset x ... | qq rewrite qq with ziplem-moves-halflam1 apt (rel◆t _) (rel◆t _) mv rt wt1 wt2 ... | ww = DoSynth (SAZipLam1 apt et (rel◆t _) x wt1 wt1) ww ziplem-moves-ap1 : ∀{Γ l e1 e1' e2 t t' tx} → Γ ⊢ e1 ◆e => t → t ▸arr (tx ==> t') → Γ ⊢ e2 <= tx → movements l → runsynth Γ e1 t l e1' t → runsynth Γ (e1 ∘₁ e2) t' l (e1' ∘₁ e2) t' ziplem-moves-ap1 _ _ _ _ DoRefl = DoRefl ziplem-moves-ap1 wt1 mch wt2 (AM:: m) (DoSynth x rs) with π2 (moveerase-synth (rel◆ _) wt1 x) ... | refl = DoSynth (SAZipApArr mch (rel◆ _) wt1 x wt2) (ziplem-moves-ap1 (actsense-synth (rel◆ _) (rel◆ _) x wt1) mch wt2 m rs) -- zip lemmas for sums ziplem-inl : ∀{t t1 t2 Γ e L e'} → t ▸sum (t1 ⊕ t2) → runana Γ e L e' t1 → runana Γ (inl e) L (inl e') t ziplem-inl m DoRefl = DoRefl ziplem-inl m (DoAna x r) = DoAna (AAZipInl m x) (ziplem-inl m r) ziplem-inr : ∀{t t1 t2 Γ e L e'} → t ▸sum (t1 ⊕ t2) → runana Γ e L e' t2 → runana Γ (inr e) L (inr e') t ziplem-inr m DoRefl = DoRefl ziplem-inr m (DoAna x r) = DoAna (AAZipInr m x) (ziplem-inr m r) ziplem-case1a : ∀{x Γ y e e◆ t0 t+ e' e1 e2 L t1 t2 t} → x # Γ → y # Γ → erase-e e e◆ → Γ ⊢ e◆ => t0 → runsynth Γ e t0 L e' t+ → t+ ▸sum (t1 ⊕ t2) → (Γ ,, (x , t1)) ⊢ e1 <= t → (Γ ,, (y , t2)) ⊢ e2 <= t → movements L → runana Γ (case₁ e x e1 y e2) L (case₁ e' x e1 y e2) t ziplem-case1a x# y# er wt0 DoRefl m wt1 wt2 mv = DoRefl ziplem-case1a x# y# er wt0 (DoSynth α rs) m wt1 wt2 (AM:: mv) with endpoints (actsense-synth er (rel◆ _) α wt0) rs mv ... | refl with (π2 (moveerase-synth er wt0 α)) ... | refl = DoAna (AAZipCase1 x# y# er wt0 α m wt1 wt2) (ziplem-case1a x# y# (eq-er-trans (π1 (moveerase-synth er wt0 α)) er) wt0 rs m wt1 wt2 mv) ziplem-case1b : ∀{Γ e e' t L t' x y t0 e◆ u u1 u2} → x # Γ → y # Γ → erase-e e e◆ → Γ ⊢ e◆ => t → runsynth Γ e t L e' t' → runana Γ (case₁ ⦇⌜ e ⌟⦈[ u ] x ⦇-⦈[ u1 ] y ⦇-⦈[ u2 ]) L (case₁ ⦇⌜ e' ⌟⦈[ u ] x ⦇-⦈[ u1 ] y ⦇-⦈[ u2 ]) t0 ziplem-case1b _ _ _ _ DoRefl = DoRefl ziplem-case1b x# y# er wt (DoSynth x₁ rs) = DoAna (AAZipCase1 x# y# (erase-in-hole er) (SNEHole wt) (SAZipNEHole er wt x₁) MSHole (ASubsume SEHole TCHole1) (ASubsume SEHole TCHole1)) (ziplem-case1b x# y# (rel◆ _) (actsense-synth er (rel◆ _) x₁ wt) rs) ziplem-case2 : ∀{t t+ t1 t2 Γ x y e e1 e1' e2 l} → x # Γ → y # Γ → Γ ⊢ e => t+ → (Γ ,, (y , t2)) ⊢ e2 <= t → t+ ▸sum (t1 ⊕ t2) → runana (Γ ,, (x , t1)) e1 l e1' t → runana Γ (case₂ e x e1 y e2) l (case₂ e x e1' y e2) t ziplem-case2 x# y# wt1 wt2 m DoRefl = DoRefl ziplem-case2 x# y# wt1 wt2 m (DoAna x₁ ra) = DoAna (AAZipCase2 x# y# wt1 m x₁) (ziplem-case2 x# y# wt1 wt2 m ra) ziplem-case3 : ∀{t t+ t1 t2 Γ x y e e1 e2 e2' l} → x # Γ → y # Γ → Γ ⊢ e => t+ → (Γ ,, (x , t1)) ⊢ e1 <= t → t+ ▸sum (t1 ⊕ t2) → runana (Γ ,, (y , t2)) e2 l e2' t → runana Γ (case₃ e x e1 y e2) l (case₃ e x e1 y e2') t ziplem-case3 x# y# wt1 wt2 m DoRefl = DoRefl ziplem-case3 x# y# wt1 wt2 m (DoAna x₁ ra) = DoAna (AAZipCase3 x# y# wt1 m x₁) (ziplem-case3 x# y# wt1 wt2 m ra) -- zip lemma for products ziplem-pair1 : ∀ {t1 t1' t2 Γ e1 e1◆ l e1' e2} → erase-e e1 e1◆ → Γ ⊢ e1◆ => t1 → runsynth Γ e1 t1 l e1' t1' → Γ ⊢ e2 => t2 → runsynth Γ ⟨ e1 , e2 ⟩₁ (t1 ⊠ t2) l ⟨ e1' , e2 ⟩₁ (t1' ⊠ t2) ziplem-pair1 er wt1 DoRefl wt2 = DoRefl ziplem-pair1 er wt1 (DoSynth x rs) wt2 = DoSynth (SAZipPair1 er wt1 x wt2) (ziplem-pair1 (rel◆ _) (actsense-synth er (rel◆ _) x wt1) rs wt2) ziplem-pair2 : ∀ {t1 t2 t2' Γ e1 e2 e2◆ l e2'} → Γ ⊢ e1 => t1 → erase-e e2 e2◆ → Γ ⊢ e2◆ => t2 → runsynth Γ e2 t2 l e2' t2' → runsynth Γ ⟨ e1 , e2 ⟩₂ (t1 ⊠ t2) l ⟨ e1 , e2' ⟩₂ (t1 ⊠ t2') ziplem-pair2 wt1 er wt2 DoRefl = DoRefl ziplem-pair2 wt1 er wt2 (DoSynth x rs) = DoSynth (SAZipPair2 wt1 er wt2 x) (ziplem-pair2 wt1 (rel◆ _) (actsense-synth er (rel◆ _) x wt2) rs) ziplem-moves-fst : ∀ {t× t×' t1 t1' t2 t2' Γ e e◆ l e'} → t× ▸prod (t1 ⊠ t2) → t×' ▸prod (t1' ⊠ t2') → erase-e e e◆ → Γ ⊢ e◆ => t× → movements l → runsynth Γ e t× l e' t×' → runsynth Γ (fst e) t1 l (fst e') t1' ziplem-moves-fst pr pr' er wt m DoRefl with ▸prod-unicity pr pr' ... | refl = DoRefl ziplem-moves-fst pr pr' er wt (AM:: m) (DoSynth x rs) with endpoints (actsense-synth er (rel◆ _) x wt) rs m ... | refl with moveerase-synth er wt x ... | q , refl with ▸prod-unicity pr pr' ... | refl = DoSynth (SAZipFst pr pr' er wt x) (ziplem-moves-fst pr pr' (eq-er-trans q er) wt m rs) ziplem-moves-snd : ∀ {t× t×' t1 t1' t2 t2' Γ e e◆ l e'} → t× ▸prod (t1 ⊠ t2) → t×' ▸prod (t1' ⊠ t2') → erase-e e e◆ → Γ ⊢ e◆ => t× → movements l → runsynth Γ e t× l e' t×' → runsynth Γ (snd e) t2 l (snd e') t2' ziplem-moves-snd pr pr' er wt m DoRefl with ▸prod-unicity pr pr' ... | refl = DoRefl ziplem-moves-snd pr pr' er wt (AM:: m) (DoSynth x rs) with endpoints (actsense-synth er (rel◆ _) x wt) rs m ... | refl with moveerase-synth er wt x ... | q , refl with ▸prod-unicity pr pr' ... | refl = DoSynth (SAZipSnd pr pr' er wt x) (ziplem-moves-snd pr pr' (eq-er-trans q er) wt m rs)
{ "alphanum_fraction": 0.5005376619, "avg_line_length": 41.9077253219, "ext": "agda", "hexsha": "6c4d9de4e3c7d42fa9894ff1531d5b06c9d9268c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_path": "statics-checks.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-agda", "max_issues_repo_path": "statics-checks.agda", "max_line_length": 95, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_path": "statics-checks.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7340, "size": 19529 }
module SubstantiveDischargeIsReflexive where open import HasSubstantiveDischarge record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁ where field ≽-reflexive : (x : A) → x ≽ x {- record SubstantiveDischargeIsReflexive (A : Set) : Set₁ where field overlap ⦃ hasSubstantiveDischarge ⦄ : HasSubstantiveDischarge A A ≽-reflexive : (x : A) → x ≽ x -} open SubstantiveDischargeIsReflexive ⦃ … ⦄ public {- record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁ where field ≽-reflexive : {x : A} → x ≽ x open SubstantiveDischargeIsReflexive ⦃ … ⦄ -} {-# DISPLAY SubstantiveDischargeIsReflexive.≽-reflexive _ = ≽-reflexive #-}
{ "alphanum_fraction": 0.7168508287, "avg_line_length": 25.8571428571, "ext": "agda", "hexsha": "33b167697d1e172e8ff446e550d98878aaf2f3a5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/SubstantiveDischargeIsReflexive.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/SubstantiveDischargeIsReflexive.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/SubstantiveDischargeIsReflexive.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 279, "size": 724 }
-- Andreas, 2017-10-09, issue #2576 -- Duplicate definition should be reported as such, -- not as "Missing type signature." data ⊥ : Set where data ⊥ where -- Error was: Missing type signature for ⊥ -- Error was: Duplicate definition of module ⊥ (fixed 2019-07-07) -- Expected error: Multiple definitions of ⊥
{ "alphanum_fraction": 0.7156549521, "avg_line_length": 26.0833333333, "ext": "agda", "hexsha": "61d69dbc7acc497cd1324a0175c9db21f76cd9e2", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue2576.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue2576.agda", "max_line_length": 65, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue2576.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 86, "size": 313 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties related to Fin, and operations making use of these -- properties (or other properties not available in Data.Fin) ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Fin.Properties where open import Algebra.FunctionProperties using (Involutive) open import Category.Applicative using (RawApplicative) open import Category.Functor using (RawFunctor) open import Data.Empty using (⊥-elim) open import Data.Fin.Base open import Data.Nat as ℕ using (ℕ; zero; suc; s≤s; z≤n; _∸_) renaming ( _≤_ to _ℕ≤_ ; _<_ to _ℕ<_ ; _+_ to _ℕ+_ ) import Data.Nat.Properties as ℕₚ open import Data.Unit using (tt) open import Data.Product using (∃; ∃₂; ∄; _×_; _,_; map; proj₁) open import Function using (_∘_; id) open import Function.Injection using (_↣_) open import Relation.Binary as B hiding (Decidable) open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl; sym; trans; cong; subst; module ≡-Reasoning) open import Relation.Nullary using (¬_) import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Negation using (contradiction) open import Relation.Nullary using (Dec; yes; no; ¬_) open import Relation.Unary as U using (U; Pred; Decidable; _⊆_) open import Relation.Unary.Properties using (U?) ------------------------------------------------------------------------ -- Fin ¬Fin0 : ¬ Fin 0 ¬Fin0 () ------------------------------------------------------------------------ -- Properties of _≡_ suc-injective : ∀ {o} {m n : Fin o} → Fin.suc m ≡ suc n → m ≡ n suc-injective refl = refl infix 4 _≟_ _≟_ : ∀ {n} → B.Decidable {A = Fin n} _≡_ zero ≟ zero = yes refl zero ≟ suc y = no λ() suc x ≟ zero = no λ() suc x ≟ suc y with x ≟ y ... | yes x≡y = yes (cong suc x≡y) ... | no x≢y = no (x≢y ∘ suc-injective) preorder : ℕ → Preorder _ _ _ preorder n = P.preorder (Fin n) setoid : ℕ → Setoid _ _ setoid n = P.setoid (Fin n) isDecEquivalence : ∀ {n} → IsDecEquivalence (_≡_ {A = Fin n}) isDecEquivalence = record { isEquivalence = P.isEquivalence ; _≟_ = _≟_ } decSetoid : ℕ → DecSetoid _ _ decSetoid n = record { Carrier = Fin n ; _≈_ = _≡_ ; isDecEquivalence = isDecEquivalence } ------------------------------------------------------------------------ -- toℕ toℕ-injective : ∀ {n} {i j : Fin n} → toℕ i ≡ toℕ j → i ≡ j toℕ-injective {zero} {} {} _ toℕ-injective {suc n} {zero} {zero} eq = refl toℕ-injective {suc n} {zero} {suc j} () toℕ-injective {suc n} {suc i} {zero} () toℕ-injective {suc n} {suc i} {suc j} eq = cong suc (toℕ-injective (cong ℕ.pred eq)) toℕ-strengthen : ∀ {n} (i : Fin n) → toℕ (strengthen i) ≡ toℕ i toℕ-strengthen zero = refl toℕ-strengthen (suc i) = cong suc (toℕ-strengthen i) toℕ-raise : ∀ {m} n (i : Fin m) → toℕ (raise n i) ≡ n ℕ+ toℕ i toℕ-raise zero i = refl toℕ-raise (suc n) i = cong suc (toℕ-raise n i) toℕ<n : ∀ {n} (i : Fin n) → toℕ i ℕ< n toℕ<n zero = s≤s z≤n toℕ<n (suc i) = s≤s (toℕ<n i) toℕ≤pred[n] : ∀ {n} (i : Fin n) → toℕ i ℕ≤ ℕ.pred n toℕ≤pred[n] zero = z≤n toℕ≤pred[n] (suc {n = zero} ()) toℕ≤pred[n] (suc {n = suc n} i) = s≤s (toℕ≤pred[n] i) -- A simpler implementation of toℕ≤pred[n], -- however, with a different reduction behavior. -- If no one needs the reduction behavior of toℕ≤pred[n], -- it can be removed in favor of toℕ≤pred[n]′. toℕ≤pred[n]′ : ∀ {n} (i : Fin n) → toℕ i ℕ≤ ℕ.pred n toℕ≤pred[n]′ i = ℕₚ.<⇒≤pred (toℕ<n i) ------------------------------------------------------------------------ -- fromℕ toℕ-fromℕ : ∀ n → toℕ (fromℕ n) ≡ n toℕ-fromℕ zero = refl toℕ-fromℕ (suc n) = cong suc (toℕ-fromℕ n) fromℕ-toℕ : ∀ {n} (i : Fin n) → fromℕ (toℕ i) ≡ strengthen i fromℕ-toℕ zero = refl fromℕ-toℕ (suc i) = cong suc (fromℕ-toℕ i) ------------------------------------------------------------------------ -- fromℕ≤ fromℕ≤-toℕ : ∀ {m} (i : Fin m) (i<m : toℕ i ℕ< m) → fromℕ≤ i<m ≡ i fromℕ≤-toℕ zero (s≤s z≤n) = refl fromℕ≤-toℕ (suc i) (s≤s (s≤s m≤n)) = cong suc (fromℕ≤-toℕ i (s≤s m≤n)) toℕ-fromℕ≤ : ∀ {m n} (m<n : m ℕ< n) → toℕ (fromℕ≤ m<n) ≡ m toℕ-fromℕ≤ (s≤s z≤n) = refl toℕ-fromℕ≤ (s≤s (s≤s m<n)) = cong suc (toℕ-fromℕ≤ (s≤s m<n)) -- fromℕ is a special case of fromℕ≤. fromℕ-def : ∀ n → fromℕ n ≡ fromℕ≤ ℕₚ.≤-refl fromℕ-def zero = refl fromℕ-def (suc n) = cong suc (fromℕ-def n) ------------------------------------------------------------------------ -- fromℕ≤″ fromℕ≤≡fromℕ≤″ : ∀ {m n} (m<n : m ℕ< n) (m<″n : m ℕ.<″ n) → fromℕ≤ m<n ≡ fromℕ≤″ m m<″n fromℕ≤≡fromℕ≤″ (s≤s z≤n) (ℕ.less-than-or-equal refl) = refl fromℕ≤≡fromℕ≤″ (s≤s (s≤s m<n)) (ℕ.less-than-or-equal refl) = cong suc (fromℕ≤≡fromℕ≤″ (s≤s m<n) (ℕ.less-than-or-equal refl)) toℕ-fromℕ≤″ : ∀ {m n} (m<n : m ℕ.<″ n) → toℕ (fromℕ≤″ m m<n) ≡ m toℕ-fromℕ≤″ {m} {n} m<n = begin toℕ (fromℕ≤″ m m<n) ≡⟨ cong toℕ (sym (fromℕ≤≡fromℕ≤″ _ m<n)) ⟩ toℕ (fromℕ≤ _) ≡⟨ toℕ-fromℕ≤ (ℕₚ.≤″⇒≤ m<n) ⟩ m ∎ where open ≡-Reasoning ------------------------------------------------------------------------ -- cast toℕ-cast : ∀ {m n} .(eq : m ≡ n) (k : Fin m) → toℕ (cast eq k) ≡ toℕ k toℕ-cast {n = zero} () zero toℕ-cast {n = suc n} eq zero = refl toℕ-cast {n = zero} () (suc k) toℕ-cast {n = suc n} eq (suc k) = cong suc (toℕ-cast (cong ℕ.pred eq) k) ------------------------------------------------------------------------ -- Properties of _≤_ -- Relational properties ≤-reflexive : ∀ {n} → _≡_ ⇒ (_≤_ {n}) ≤-reflexive refl = ℕₚ.≤-refl ≤-refl : ∀ {n} → Reflexive (_≤_ {n}) ≤-refl = ≤-reflexive refl ≤-trans : ∀ {n} → Transitive (_≤_ {n}) ≤-trans = ℕₚ.≤-trans ≤-antisym : ∀ {n} → Antisymmetric _≡_ (_≤_ {n}) ≤-antisym x≤y y≤x = toℕ-injective (ℕₚ.≤-antisym x≤y y≤x) ≤-total : ∀ {n} → Total (_≤_ {n}) ≤-total x y = ℕₚ.≤-total (toℕ x) (toℕ y) infix 4 _≤?_ _<?_ _≤?_ : ∀ {n} → B.Decidable (_≤_ {n}) a ≤? b = toℕ a ℕ.≤? toℕ b _<?_ : ∀ {n} → B.Decidable (_<_ {n}) m <? n = suc (toℕ m) ℕ.≤? toℕ n ≤-isPreorder : ∀ {n} → IsPreorder _≡_ (_≤_ {n}) ≤-isPreorder = record { isEquivalence = P.isEquivalence ; reflexive = ≤-reflexive ; trans = ≤-trans } ≤-preorder : ℕ → Preorder _ _ _ ≤-preorder n = record { isPreorder = ≤-isPreorder {n} } ≤-isPartialOrder : ∀ {n} → IsPartialOrder _≡_ (_≤_ {n}) ≤-isPartialOrder = record { isPreorder = ≤-isPreorder ; antisym = ≤-antisym } ≤-poset : ℕ → Poset _ _ _ ≤-poset n = record { isPartialOrder = ≤-isPartialOrder {n} } ≤-isTotalOrder : ∀ {n} → IsTotalOrder _≡_ (_≤_ {n}) ≤-isTotalOrder = record { isPartialOrder = ≤-isPartialOrder ; total = ≤-total } ≤-totalOrder : ℕ → TotalOrder _ _ _ ≤-totalOrder n = record { isTotalOrder = ≤-isTotalOrder {n} } ≤-isDecTotalOrder : ∀ {n} → IsDecTotalOrder _≡_ (_≤_ {n}) ≤-isDecTotalOrder = record { isTotalOrder = ≤-isTotalOrder ; _≟_ = _≟_ ; _≤?_ = _≤?_ } ≤-decTotalOrder : ℕ → DecTotalOrder _ _ _ ≤-decTotalOrder n = record { isDecTotalOrder = ≤-isDecTotalOrder {n} } -- Other properties ≤-irrelevant : ∀ {n} → Irrelevant (_≤_ {n}) ≤-irrelevant = ℕₚ.≤-irrelevant ------------------------------------------------------------------------ -- Properties of _<_ -- Relational properties <-irrefl : ∀ {n} → Irreflexive _≡_ (_<_ {n}) <-irrefl refl = ℕₚ.<-irrefl refl <-asym : ∀ {n} → Asymmetric (_<_ {n}) <-asym = ℕₚ.<-asym <-trans : ∀ {n} → Transitive (_<_ {n}) <-trans = ℕₚ.<-trans <-cmp : ∀ {n} → Trichotomous _≡_ (_<_ {n}) <-cmp zero zero = tri≈ (λ()) refl (λ()) <-cmp zero (suc j) = tri< (s≤s z≤n) (λ()) (λ()) <-cmp (suc i) zero = tri> (λ()) (λ()) (s≤s z≤n) <-cmp (suc i) (suc j) with <-cmp i j ... | tri< i<j i≢j j≮i = tri< (s≤s i<j) (i≢j ∘ suc-injective) (j≮i ∘ ℕₚ.≤-pred) ... | tri> i≮j i≢j j<i = tri> (i≮j ∘ ℕₚ.≤-pred) (i≢j ∘ suc-injective) (s≤s j<i) ... | tri≈ i≮j i≡j j≮i = tri≈ (i≮j ∘ ℕₚ.≤-pred) (cong suc i≡j) (j≮i ∘ ℕₚ.≤-pred) <-respˡ-≡ : ∀ {n} → (_<_ {n}) Respectsˡ _≡_ <-respˡ-≡ refl x≤y = x≤y <-respʳ-≡ : ∀ {n} → (_<_ {n}) Respectsʳ _≡_ <-respʳ-≡ refl x≤y = x≤y <-resp₂-≡ : ∀ {n} → (_<_ {n}) Respects₂ _≡_ <-resp₂-≡ = <-respʳ-≡ , <-respˡ-≡ <-isStrictPartialOrder : ∀ {n} → IsStrictPartialOrder _≡_ (_<_ {n}) <-isStrictPartialOrder = record { isEquivalence = P.isEquivalence ; irrefl = <-irrefl ; trans = <-trans ; <-resp-≈ = <-resp₂-≡ } <-strictPartialOrder : ℕ → StrictPartialOrder _ _ _ <-strictPartialOrder n = record { isStrictPartialOrder = <-isStrictPartialOrder {n} } <-isStrictTotalOrder : ∀ {n} → IsStrictTotalOrder _≡_ (_<_ {n}) <-isStrictTotalOrder = record { isEquivalence = P.isEquivalence ; trans = <-trans ; compare = <-cmp } <-strictTotalOrder : ℕ → StrictTotalOrder _ _ _ <-strictTotalOrder n = record { isStrictTotalOrder = <-isStrictTotalOrder {n} } -- Other properties <-irrelevant : ∀ {n} → Irrelevant (_<_ {n}) <-irrelevant = ℕₚ.<-irrelevant <⇒≢ : ∀ {n} {i j : Fin n} → i < j → i ≢ j <⇒≢ i<i refl = ℕₚ.n≮n _ i<i ≤∧≢⇒< : ∀ {n} {i j : Fin n} → i ≤ j → i ≢ j → i < j ≤∧≢⇒< {i = zero} {zero} _ 0≢0 = contradiction refl 0≢0 ≤∧≢⇒< {i = zero} {suc j} _ _ = s≤s z≤n ≤∧≢⇒< {i = suc i} {zero} () ≤∧≢⇒< {i = suc i} {suc j} (s≤s i≤j) 1+i≢1+j = s≤s (≤∧≢⇒< i≤j (1+i≢1+j ∘ (cong suc))) ------------------------------------------------------------------------ -- inject toℕ-inject : ∀ {n} {i : Fin n} (j : Fin′ i) → toℕ (inject j) ≡ toℕ j toℕ-inject {i = zero} () toℕ-inject {i = suc i} zero = refl toℕ-inject {i = suc i} (suc j) = cong suc (toℕ-inject j) ------------------------------------------------------------------------ -- inject+ toℕ-inject+ : ∀ {m} n (i : Fin m) → toℕ i ≡ toℕ (inject+ n i) toℕ-inject+ n zero = refl toℕ-inject+ n (suc i) = cong suc (toℕ-inject+ n i) ------------------------------------------------------------------------ -- inject₁ inject₁-injective : ∀ {n} {i j : Fin n} → inject₁ i ≡ inject₁ j → i ≡ j inject₁-injective {i = zero} {zero} i≡j = refl inject₁-injective {i = zero} {suc j} () inject₁-injective {i = suc i} {zero} () inject₁-injective {i = suc i} {suc j} i≡j = cong suc (inject₁-injective (suc-injective i≡j)) toℕ-inject₁ : ∀ {n} (i : Fin n) → toℕ (inject₁ i) ≡ toℕ i toℕ-inject₁ zero = refl toℕ-inject₁ (suc i) = cong suc (toℕ-inject₁ i) toℕ-inject₁-≢ : ∀ {n}(i : Fin n) → n ≢ toℕ (inject₁ i) toℕ-inject₁-≢ zero = λ () toℕ-inject₁-≢ (suc i) = λ p → toℕ-inject₁-≢ i (ℕₚ.suc-injective p) ------------------------------------------------------------------------ -- inject₁ and lower₁ inject₁-lower₁ : ∀ {n} (i : Fin (suc n)) (n≢i : n ≢ toℕ i) → inject₁ (lower₁ i n≢i) ≡ i inject₁-lower₁ {zero} zero 0≢0 = contradiction refl 0≢0 inject₁-lower₁ {zero} (suc ()) _ inject₁-lower₁ {suc n} zero _ = refl inject₁-lower₁ {suc n} (suc i) n+1≢i+1 = cong suc (inject₁-lower₁ i (n+1≢i+1 ∘ cong suc)) lower₁-inject₁′ : ∀ {n} (i : Fin n) (n≢i : n ≢ toℕ (inject₁ i)) → lower₁ (inject₁ i) n≢i ≡ i lower₁-inject₁′ zero _ = refl lower₁-inject₁′ (suc i) n+1≢i+1 = cong suc (lower₁-inject₁′ i (n+1≢i+1 ∘ cong suc)) lower₁-inject₁ : ∀ {n} (i : Fin n) → lower₁ (inject₁ i) (toℕ-inject₁-≢ i) ≡ i lower₁-inject₁ i = lower₁-inject₁′ i (toℕ-inject₁-≢ i) lower₁-irrelevant : ∀ {n} (i : Fin (suc n)) n≢i₁ n≢i₂ → lower₁ {n} i n≢i₁ ≡ lower₁ {n} i n≢i₂ lower₁-irrelevant {zero} zero 0≢0 _ = contradiction refl 0≢0 lower₁-irrelevant {zero} (suc ()) _ _ lower₁-irrelevant {suc n} zero _ _ = refl lower₁-irrelevant {suc n} (suc i) _ _ = cong suc (lower₁-irrelevant i _ _) ------------------------------------------------------------------------ -- inject≤ toℕ-inject≤ : ∀ {m n} (i : Fin m) (le : m ℕ≤ n) → toℕ (inject≤ i le) ≡ toℕ i toℕ-inject≤ zero (s≤s le) = refl toℕ-inject≤ (suc i) (s≤s le) = cong suc (toℕ-inject≤ i le) inject≤-refl : ∀ {n} (i : Fin n) (n≤n : n ℕ≤ n) → inject≤ i n≤n ≡ i inject≤-refl zero (s≤s _ ) = refl inject≤-refl (suc i) (s≤s n≤n) = cong suc (inject≤-refl i n≤n) ------------------------------------------------------------------------ -- _≺_ ≺⇒<′ : _≺_ ⇒ ℕ._<′_ ≺⇒<′ (n ≻toℕ i) = ℕₚ.≤⇒≤′ (toℕ<n i) <′⇒≺ : ℕ._<′_ ⇒ _≺_ <′⇒≺ {n} ℕ.≤′-refl = subst (_≺ suc n) (toℕ-fromℕ n) (suc n ≻toℕ fromℕ n) <′⇒≺ (ℕ.≤′-step m≤′n) with <′⇒≺ m≤′n ... | n ≻toℕ i = subst (_≺ suc n) (toℕ-inject₁ i) (suc n ≻toℕ _) ------------------------------------------------------------------------ -- pred <⇒≤pred : ∀ {n} {i j : Fin n} → j < i → j ≤ pred i <⇒≤pred {i = zero} {_} () <⇒≤pred {i = suc i} {zero} j<i = z≤n <⇒≤pred {i = suc i} {suc j} (s≤s j<i) = subst (_ ℕ≤_) (sym (toℕ-inject₁ i)) j<i ------------------------------------------------------------------------ -- ℕ- toℕ‿ℕ- : ∀ n i → toℕ (n ℕ- i) ≡ n ∸ toℕ i toℕ‿ℕ- n zero = toℕ-fromℕ n toℕ‿ℕ- zero (suc ()) toℕ‿ℕ- (suc n) (suc i) = toℕ‿ℕ- n i ------------------------------------------------------------------------ -- ℕ-ℕ nℕ-ℕi≤n : ∀ n i → n ℕ-ℕ i ℕ≤ n nℕ-ℕi≤n n zero = ℕₚ.≤-refl nℕ-ℕi≤n zero (suc ()) nℕ-ℕi≤n (suc n) (suc i) = begin n ℕ-ℕ i ≤⟨ nℕ-ℕi≤n n i ⟩ n ≤⟨ ℕₚ.n≤1+n n ⟩ suc n ∎ where open ℕₚ.≤-Reasoning ------------------------------------------------------------------------ -- punchIn punchIn-injective : ∀ {m} i (j k : Fin m) → punchIn i j ≡ punchIn i k → j ≡ k punchIn-injective zero _ _ refl = refl punchIn-injective (suc i) zero zero _ = refl punchIn-injective (suc i) zero (suc k) () punchIn-injective (suc i) (suc j) zero () punchIn-injective (suc i) (suc j) (suc k) ↑j+1≡↑k+1 = cong suc (punchIn-injective i j k (suc-injective ↑j+1≡↑k+1)) punchInᵢ≢i : ∀ {m} i (j : Fin m) → punchIn i j ≢ i punchInᵢ≢i zero _ () punchInᵢ≢i (suc i) zero () punchInᵢ≢i (suc i) (suc j) = punchInᵢ≢i i j ∘ suc-injective ------------------------------------------------------------------------ -- punchOut -- A version of 'cong' for 'punchOut' in which the inequality argument can be -- changed out arbitrarily (reflecting the proof-irrelevance of that argument). punchOut-cong : ∀ {n} (i : Fin (suc n)) {j k} {i≢j : i ≢ j} {i≢k : i ≢ k} → j ≡ k → punchOut i≢j ≡ punchOut i≢k punchOut-cong zero {zero} {i≢j = 0≢0} = contradiction refl 0≢0 punchOut-cong zero {suc j} {zero} {i≢k = 0≢0} = contradiction refl 0≢0 punchOut-cong zero {suc j} {suc k} = suc-injective punchOut-cong {zero} (suc ()) punchOut-cong {suc n} (suc i) {zero} {zero} _ = refl punchOut-cong {suc n} (suc i) {zero} {suc k} () punchOut-cong {suc n} (suc i) {suc j} {zero} () punchOut-cong {suc n} (suc i) {suc j} {suc k} = cong suc ∘ punchOut-cong i ∘ suc-injective -- An alternative to 'punchOut-cong' in the which the new inequality argument is -- specific. Useful for enabling the omission of that argument during equational -- reasoning. punchOut-cong′ : ∀ {n} (i : Fin (suc n)) {j k} {p : i ≢ j} (q : j ≡ k) → punchOut p ≡ punchOut (p ∘ sym ∘ trans q ∘ sym) punchOut-cong′ i q = punchOut-cong i q punchOut-injective : ∀ {m} {i j k : Fin (suc m)} (i≢j : i ≢ j) (i≢k : i ≢ k) → punchOut i≢j ≡ punchOut i≢k → j ≡ k punchOut-injective {_} {zero} {zero} {_} 0≢0 _ _ = contradiction refl 0≢0 punchOut-injective {_} {zero} {_} {zero} _ 0≢0 _ = contradiction refl 0≢0 punchOut-injective {_} {zero} {suc j} {suc k} _ _ pⱼ≡pₖ = cong suc pⱼ≡pₖ punchOut-injective {zero} {suc ()} punchOut-injective {suc n} {suc i} {zero} {zero} _ _ _ = refl punchOut-injective {suc n} {suc i} {zero} {suc k} _ _ () punchOut-injective {suc n} {suc i} {suc j} {zero} _ _ () punchOut-injective {suc n} {suc i} {suc j} {suc k} i≢j i≢k pⱼ≡pₖ = cong suc (punchOut-injective (i≢j ∘ cong suc) (i≢k ∘ cong suc) (suc-injective pⱼ≡pₖ)) punchIn-punchOut : ∀ {m} {i j : Fin (suc m)} (i≢j : i ≢ j) → punchIn i (punchOut i≢j) ≡ j punchIn-punchOut {_} {zero} {zero} 0≢0 = contradiction refl 0≢0 punchIn-punchOut {_} {zero} {suc j} _ = refl punchIn-punchOut {zero} {suc ()} punchIn-punchOut {suc m} {suc i} {zero} i≢j = refl punchIn-punchOut {suc m} {suc i} {suc j} i≢j = cong suc (punchIn-punchOut (i≢j ∘ cong suc)) punchOut-punchIn : ∀ {n} i {j : Fin n} → punchOut {i = i} {j = punchIn i j} (punchInᵢ≢i i j ∘ sym) ≡ j punchOut-punchIn zero {j} = refl punchOut-punchIn (suc i) {zero} = refl punchOut-punchIn (suc i) {suc j} = cong suc (begin punchOut (punchInᵢ≢i i j ∘ suc-injective ∘ sym ∘ cong suc) ≡⟨ punchOut-cong i refl ⟩ punchOut (punchInᵢ≢i i j ∘ sym) ≡⟨ punchOut-punchIn i ⟩ j ∎) where open ≡-Reasoning ------------------------------------------------------------------------ -- _+′_ infixl 6 _+′_ _+′_ : ∀ {m n} (i : Fin m) (j : Fin n) → Fin (ℕ.pred m ℕ+ n) i +′ j = inject≤ (i + j) (ℕₚ.+-mono-≤ (toℕ≤pred[n] i) ℕₚ.≤-refl) ------------------------------------------------------------------------ -- Quantification ∀-cons : ∀ {n p} {P : Pred (Fin (suc n)) p} → P zero → (∀ i → P (suc i)) → (∀ i → P i) ∀-cons z s zero = z ∀-cons z s (suc i) = s i decFinSubset : ∀ {n p q} {P : Pred (Fin n) p} {Q : Pred (Fin n) q} → Decidable Q → (∀ {f} → Q f → Dec (P f)) → Dec (Q ⊆ P) decFinSubset {zero} {_} {_} _ _ = yes λ{} decFinSubset {suc n} {P = P} {Q} Q? P? with decFinSubset (Q? ∘ suc) P? ... | no ¬q⟶p = no (λ q⟶p → ¬q⟶p (q⟶p)) ... | yes q⟶p with Q? zero ... | no ¬q₀ = yes (∀-cons {P = Q U.⇒ P} (⊥-elim ∘ ¬q₀) (λ _ → q⟶p) _) ... | yes q₀ with P? q₀ ... | no ¬p₀ = no (λ q⟶p → ¬p₀ (q⟶p q₀)) ... | yes p₀ = yes (∀-cons {P = Q U.⇒ P} (λ _ → p₀) (λ _ → q⟶p) _) any? : ∀ {n p} {P : Fin n → Set p} → Decidable P → Dec (∃ P) any? {zero} {_} P? = no λ { (() , _) } any? {suc n} {P} P? with P? zero | any? (P? ∘ suc) ... | yes P₀ | _ = yes (_ , P₀) ... | no _ | yes (_ , P₁₊ᵢ) = yes (_ , P₁₊ᵢ) ... | no ¬P₀ | no ¬P₁₊ᵢ = no λ { (zero , P₀) → ¬P₀ P₀ ; (suc f , P₁₊ᵢ) → ¬P₁₊ᵢ (_ , P₁₊ᵢ) } all? : ∀ {n p} {P : Pred (Fin n) p} → Decidable P → Dec (∀ f → P f) all? P? with decFinSubset U? (λ {f} _ → P? f) ... | yes ∀p = yes (λ f → ∀p tt) ... | no ¬∀p = no (λ ∀p → ¬∀p (λ _ → ∀p _)) -- If a decidable predicate P over a finite set is sometimes false, -- then we can find the smallest value for which this is the case. ¬∀⟶∃¬-smallest : ∀ n {p} (P : Pred (Fin n) p) → Decidable P → ¬ (∀ i → P i) → ∃ λ i → ¬ P i × ((j : Fin′ i) → P (inject j)) ¬∀⟶∃¬-smallest zero P P? ¬∀P = contradiction (λ()) ¬∀P ¬∀⟶∃¬-smallest (suc n) P P? ¬∀P with P? zero ... | no ¬P₀ = (zero , ¬P₀ , λ ()) ... | yes P₀ = map suc (map id (∀-cons P₀)) (¬∀⟶∃¬-smallest n (P ∘ suc) (P? ∘ suc) (¬∀P ∘ (∀-cons P₀))) -- When P is a decidable predicate over a finite set the following -- lemma can be proved. ¬∀⟶∃¬ : ∀ n {p} (P : Pred (Fin n) p) → Decidable P → ¬ (∀ i → P i) → (∃ λ i → ¬ P i) ¬∀⟶∃¬ n P P? ¬P = map id proj₁ (¬∀⟶∃¬-smallest n P P? ¬P) -- The pigeonhole principle. pigeonhole : ∀ {m n} → m ℕ.< n → (f : Fin n → Fin m) → ∃₂ λ i j → i ≢ j × f i ≡ f j pigeonhole (s≤s z≤n) f = contradiction (f zero) λ() pigeonhole (s≤s (s≤s m≤n)) f with any? (λ k → f zero ≟ f (suc k)) ... | yes (j , f₀≡fⱼ) = zero , suc j , (λ()) , f₀≡fⱼ ... | no f₀≢fₖ with pigeonhole (s≤s m≤n) (λ j → punchOut (f₀≢fₖ ∘ (j ,_ ))) ... | (i , j , i≢j , fᵢ≡fⱼ) = suc i , suc j , i≢j ∘ suc-injective , punchOut-injective (f₀≢fₖ ∘ (i ,_)) _ fᵢ≡fⱼ ------------------------------------------------------------------------ -- Categorical module _ {f} {F : Set f → Set f} (RA : RawApplicative F) where open RawApplicative RA sequence : ∀ {n} {P : Pred (Fin n) f} → (∀ i → F (P i)) → F (∀ i → P i) sequence {zero} ∀iPi = pure λ() sequence {suc n} ∀iPi = ∀-cons <$> ∀iPi zero ⊛ sequence (∀iPi ∘ suc) module _ {f} {F : Set f → Set f} (RF : RawFunctor F) where open RawFunctor RF sequence⁻¹ : ∀ {A : Set f} {P : Pred A f} → F (∀ i → P i) → (∀ i → F (P i)) sequence⁻¹ F∀iPi i = (λ f → f i) <$> F∀iPi ------------------------------------------------------------------------ -- If there is an injection from a type to a finite set, then the type -- has decidable equality. module _ {a} {A : Set a} where eq? : ∀ {n} → A ↣ Fin n → B.Decidable {A = A} _≡_ eq? inj = Dec.via-injection inj _≟_ ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 cmp = <-cmp {-# WARNING_ON_USAGE cmp "Warning: cmp was deprecated in v0.15. Please use <-cmp instead." #-} strictTotalOrder = <-strictTotalOrder {-# WARNING_ON_USAGE strictTotalOrder "Warning: strictTotalOrder was deprecated in v0.15. Please use <-strictTotalOrder instead." #-} -- Version 0.16 to-from = toℕ-fromℕ {-# WARNING_ON_USAGE to-from "Warning: to-from was deprecated in v0.16. Please use toℕ-fromℕ instead." #-} from-to = fromℕ-toℕ {-# WARNING_ON_USAGE from-to "Warning: from-to was deprecated in v0.16. Please use fromℕ-toℕ instead." #-} bounded = toℕ<n {-# WARNING_ON_USAGE bounded "Warning: bounded was deprecated in v0.16. Please use toℕ<n instead." #-} prop-toℕ-≤ = toℕ≤pred[n] {-# WARNING_ON_USAGE prop-toℕ-≤ "Warning: prop-toℕ-≤ was deprecated in v0.16. Please use toℕ≤pred[n] instead." #-} prop-toℕ-≤′ = toℕ≤pred[n]′ {-# WARNING_ON_USAGE prop-toℕ-≤′ "Warning: prop-toℕ-≤′ was deprecated in v0.16. Please use toℕ≤pred[n]′ instead." #-} inject-lemma = toℕ-inject {-# WARNING_ON_USAGE inject-lemma "Warning: inject-lemma was deprecated in v0.16. Please use toℕ-inject instead." #-} inject+-lemma = toℕ-inject+ {-# WARNING_ON_USAGE inject+-lemma "Warning: inject+-lemma was deprecated in v0.16. Please use toℕ-inject+ instead." #-} inject₁-lemma = toℕ-inject₁ {-# WARNING_ON_USAGE inject₁-lemma "Warning: inject₁-lemma was deprecated in v0.16. Please use toℕ-inject₁ instead." #-} inject≤-lemma = toℕ-inject≤ {-# WARNING_ON_USAGE inject≤-lemma "Warning: inject≤-lemma was deprecated in v0.16. Please use toℕ-inject≤ instead." #-} -- Version 0.17 ≤+≢⇒< = ≤∧≢⇒< {-# WARNING_ON_USAGE ≤+≢⇒< "Warning: ≤+≢⇒< was deprecated in v0.17. Please use ≤∧≢⇒< instead." #-} -- Version 1.0 ≤-irrelevance = ≤-irrelevant {-# WARNING_ON_USAGE ≤-irrelevance "Warning: ≤-irrelevance was deprecated in v1.0. Please use ≤-irrelevant instead." #-} <-irrelevance = <-irrelevant {-# WARNING_ON_USAGE <-irrelevance "Warning: <-irrelevance was deprecated in v1.0. Please use <-irrelevant instead." #-}
{ "alphanum_fraction": 0.5131968641, "avg_line_length": 33.3236574746, "ext": "agda", "hexsha": "963c69c98ca8975f834f60644f421dc35f7a79c6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Properties.agda", "max_line_length": 120, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 9589, "size": 22960 }
{-# OPTIONS --cubical #-} open import Agda.Primitive.Cubical open import Agda.Builtin.Cubical.Path open import Agda.Builtin.Sigma data S1 : Set where base : S1 loop : base ≡ base data Torus : Set where point : Torus line1 : point ≡ point line2 : point ≡ point square : PathP (λ i → line1 i ≡ line1 i) line2 line2 t2c : Torus → Σ S1 \ _ → S1 t2c point = ( base , base ) t2c (line1 i) = ( loop i , base ) t2c (line2 i) = ( base , loop i ) t2c (square i1 i2) = ( loop i1 , loop i2 )
{ "alphanum_fraction": 0.6404040404, "avg_line_length": 23.5714285714, "ext": "agda", "hexsha": "467af94fa5e2af5a0c2b24434db06b07452b70e7", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue5237.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue5237.agda", "max_line_length": 54, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue5237.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 189, "size": 495 }
------------------------------------------------------------------------------ -- Issue in the translation ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Issue10 where postulate D : Set P' : D → Set postulate foo : ∀ d → P' d → P' d {-# ATP prove foo #-}
{ "alphanum_fraction": 0.3473684211, "avg_line_length": 26.3888888889, "ext": "agda", "hexsha": "2b87a90dff2b5d77f13b2db7e8cea9d5fec3eea9", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/Issue10.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/Issue10.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/Issue10.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 84, "size": 475 }
open import Agda.Primitive open import Agda.Builtin.Nat Type : (i : Level) -> Set (lsuc i) Type i = Set i postulate P : (i : Level) (A : Type i) → A → Type i postulate lemma : (a : Nat) -> P _ _ a
{ "alphanum_fraction": 0.6078431373, "avg_line_length": 17, "ext": "agda", "hexsha": "e286fd514bf3a651df50cf896305a4b4863d81a0", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Succeed/Issue4615-missing-reduce.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue4615-missing-reduce.agda", "max_line_length": 43, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue4615-missing-reduce.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 76, "size": 204 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.ListedFiniteSet.Properties where open import Cubical.Foundations.Prelude open import Cubical.HITs.ListedFiniteSet.Base private variable A : Type₀ _++_ : ∀ (xs ys : LFSet A) → LFSet A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) --------------------------------------------- dup x xs i ++ ys = proof i where proof : -- Need: (x ∷ x ∷ xs) ++ ys ≡ (x ∷ xs) ++ ys -- which reduces to: x ∷ x ∷ (xs ++ ys) ≡ x ∷ (xs ++ ys) proof = dup x (xs ++ ys) comm x y xs i ++ ys = comm x y (xs ++ ys) i trunc xs zs p q i j ++ ys = trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j assoc-++ : ∀ (xs : LFSet A) ys zs → xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs assoc-++ [] ys zs = refl assoc-++ (x ∷ xs) ys zs = cong (x ∷_) (assoc-++ xs ys zs) ------------------------------------ assoc-++ (dup x xs i) ys zs j = dup x (assoc-++ xs ys zs j) i assoc-++ (comm x y xs i) ys zs j = comm x y (assoc-++ xs ys zs j) i assoc-++ (trunc xs xs' p q i k) ys zs j = trunc (assoc-++ xs ys zs j) (assoc-++ xs' ys zs j) (cong (\ xs -> assoc-++ xs ys zs j) p) (cong (\ xs -> assoc-++ xs ys zs j) q) i k
{ "alphanum_fraction": 0.46184107, "avg_line_length": 31.775, "ext": "agda", "hexsha": "5739152ac8392426a996d4699e39e8754133cc5b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "69d358f6be7842f77105634712821eda22d9c044", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "aljungstrom/cubical", "max_forks_repo_path": "Cubical/HITs/ListedFiniteSet/Properties.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/cubical", "max_issues_repo_path": "Cubical/HITs/ListedFiniteSet/Properties.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/cubical", "max_stars_repo_path": "Cubical/HITs/ListedFiniteSet/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 457, "size": 1271 }
module Data.QuadTree.Implementation.DataLenses where open import Haskell.Prelude renaming (zero to Z; suc to S) open import Data.Lens.Lens open import Data.Logic open import Data.QuadTree.Implementation.PropDepthRelation open import Data.QuadTree.Implementation.Definition open import Data.QuadTree.Implementation.ValidTypes open import Data.QuadTree.Implementation.QuadrantLenses {-# FOREIGN AGDA2HS {-# LANGUAGE Safe #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE Rank2Types #-} import Data.Nat import Data.Lens.Lens import Data.Logic import Data.QuadTree.Implementation.Definition import Data.QuadTree.Implementation.ValidTypes import Data.QuadTree.Implementation.QuadrantLenses #-} ---- Functions for whether a coordinate is inside isInsideQuadTree : {t : Set} -> (Nat × Nat) -> QuadTree t -> Bool isInsideQuadTree (x , y) (Wrapper (w , h) _) = x < w && y < h isInsidePow : (Nat × Nat) -> Nat -> Bool isInsidePow (x , y) deps = x < pow 2 deps && y < pow 2 deps insideQTtoInsidePow : {t : Set} {{eqT : Eq t}} -> (loc : Nat × Nat) -> {dep : Nat} -> (vqt : VQuadTree t {dep}) -> IsTrue (isInsideQuadTree loc (qtFromSafe vqt)) -> IsTrue (isInsidePow loc dep) insideQTtoInsidePow (x , y) {dep} (CVQuadTree (Wrapper (w , h) qd) {p} {q}) it = let p1 : IsTrue (pow 2 dep >= (max w h)) p1 = log2upPow dep (max w h) (eqToGte dep (log2up (max w h)) q) p2 : IsTrue ((max w h) <= pow 2 dep) p2 = gteInvert (pow 2 dep) (max w h) p1 p3 : IsTrue (w <= pow 2 dep && h <= pow 2 dep) p3 = useEq (sym $ propMaxLte w h (pow 2 dep)) p2 in andCombine ( ltLteTransitive x w (pow 2 dep) (andFst {x < w} it) (andFst p3) ) ( ltLteTransitive y h (pow 2 dep) (andSnd {x < w} it) (andSnd p3) ) ---- Data access -- Lens into the leaf quadrant corresponding to a location in a quadrant go : {t : Set} {{eqT : Eq t}} -> (loc : Nat × Nat) -> (dep : Nat) -> {.(IsTrue (isInsidePow loc dep))} -> Lens (VQuadrant t {dep}) t go _ Z = lensLeaf go {t} (x , y) (S deps) = let mid = pow 2 deps gorec = go {t} (mod x mid {pow_not_zero_cv deps} , mod y mid {pow_not_zero_cv deps}) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})} in if (y < mid) then if x < mid then (lensA ∘ gorec) else (lensB ∘ gorec) else if x < mid then (lensC ∘ gorec) else (lensD ∘ gorec) {-# COMPILE AGDA2HS go #-} -- Lenses into the root quadrant of a quadtree lensWrappedTree : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> Lens (VQuadTree t {dep}) (VQuadrant t {dep}) lensWrappedTree fun (CVQuadTree (Wrapper (w , h) qd) {p} {q}) = fmap (λ where (CVQuadrant qd {p}) → CVQuadTree (Wrapper (w , h) qd) {p} {q}) (fun (CVQuadrant qd {p})) {-# COMPILE AGDA2HS lensWrappedTree #-} -- Lens into the leaf quadrant corresponding to a location in a quadtree atLocation : {t : Set} {{eqT : Eq t}} -> (loc : Nat × Nat) -> (dep : Nat) -> {.(IsTrue (isInsidePow loc dep))} -> Lens (VQuadTree t {dep}) t atLocation index dep {p} = lensWrappedTree ∘ (go index dep {p}) {-# COMPILE AGDA2HS atLocation #-}
{ "alphanum_fraction": 0.6418246065, "avg_line_length": 35.375, "ext": "agda", "hexsha": "efcaa8a509adb23a0e7253f98d401c364c1e9e7e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_path": "src/Data/QuadTree/Implementation/DataLenses.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_path": "src/Data/QuadTree/Implementation/DataLenses.agda", "max_line_length": 111, "max_stars_count": 1, "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_path": "src/Data/QuadTree/Implementation/DataLenses.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "num_tokens": 1055, "size": 3113 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Unit.Base where open import Cubical.Foundations.Prelude -- Obtain Unit open import Agda.Builtin.Unit public renaming ( ⊤ to Unit ) -- Universe polymorphic version Unit* : {ℓ : Level} → Type ℓ Unit* = Lift Unit pattern tt* = lift tt -- Universe polymorphic version without definitional equality -- Allows us to "lock" proofs. See "Locking, unlocking" in -- https://coq.inria.fr/refman/proof-engine/ssreflect-proof-language.html data lockUnit {ℓ} : Type ℓ where unlock : lockUnit
{ "alphanum_fraction": 0.7324955117, "avg_line_length": 27.85, "ext": "agda", "hexsha": "a5b64c7431baa78310c1157c9299df15eedb698b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Data/Unit/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Data/Unit/Base.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Data/Unit/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 152, "size": 557 }
{-# OPTIONS --without-K #-} module PiLevel0 where open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; module ≡-Reasoning) -- using (_≡_; refl; sym; trans; cong₂; proof-irrelevance; module ≡-Reasoning) --open import Data.Nat.Properties.Simple -- using (+-right-identity; +-suc; +-assoc; +-comm; -- *-assoc; *-comm; *-right-zero; distribʳ-*-+) --open import Data.Bool using (Bool; false; true; _∧_; _∨_) open import Data.Nat using (ℕ) -- ; _+_; _*_) --open import Data.Vec -- using (Vec; []; _∷_) -- renaming (_++_ to _++V_; map to mapV; concat to concatV) --open import Data.Empty using (⊥; ⊥-elim) --open import Data.Unit using (⊤; tt) --open import Data.Sum using (_⊎_; inj₁; inj₂) --open import Data.Product using (_×_; _,_; proj₁; proj₂) --open import Proofs using ( -- FinNatLemmas -- distribˡ-*-+; *-right-identity -- ) open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ) ------------------------------------------------------------------------------ -- Level 0 of Pi -- {-- ⟦_⟧ : U → Set ⟦ ZERO ⟧ = ⊥ ⟦ ONE ⟧ = ⊤ ⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧ ⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧ -- Abbreviations for examples BOOL : U BOOL = PLUS ONE ONE BOOL² : U BOOL² = TIMES BOOL BOOL -- false⟷ true⟷ : ⟦ BOOL ⟧ -- false⟷ = inj₁ tt -- true⟷ = inj₂ tt -- For any finite type (t : U) there is no non-trivial path structure -- between the elements of t. All such finite types are discrete -- groupoids -- -- For U, there are non-trivial paths between its points. In the -- conventional HoTT presentation, a path between t₁ and t₂ is -- postulated by univalence for each equivalence between t₁ and t₂. In -- the context of finite types, an equivalence corresponds to a -- permutation as each permutation has a unique inverse -- permutation. Thus instead of the detour using univalence, we can -- give an inductive definition of all possible permutations between -- finite types which naturally induces paths between the points of U, -- i.e., the finite types. More precisely, two types t₁ and t₂ have a -- path between them if there is a permutation (c : t₁ ⟷ t₂). The fact -- that c is a permutation guarantees, by construction, that (c ◎ ! c -- ∼ id⟷) and (! c ◎ c ∼ id⟷). A complete set of generators for all -- possible permutations between finite types is given by the -- following definition. Note that these permutations do not reach -- inside the types and hence do not generate paths between the points -- within the types. The paths are just between the types themselves. --} size : U → ℕ size = toℕ infix 30 _⟷_ infixr 50 _◎_ -- Combinators, permutations, or paths depending on the perspective data _⟷_ : U → U → Set where unite₊l : {t : U} → PLUS ZERO t ⟷ t uniti₊l : {t : U} → t ⟷ PLUS ZERO t unite₊r : {t : U} → PLUS t ZERO ⟷ t uniti₊r : {t : U} → t ⟷ PLUS t ZERO swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁ assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃ assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃) unite⋆l : {t : U} → TIMES ONE t ⟷ t uniti⋆l : {t : U} → t ⟷ TIMES ONE t unite⋆r : {t : U} → TIMES t ONE ⟷ t uniti⋆r : {t : U} → t ⟷ TIMES t ONE swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁ assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃ assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃) absorbr : {t : U} → TIMES ZERO t ⟷ ZERO absorbl : {t : U} → TIMES t ZERO ⟷ ZERO factorzr : {t : U} → ZERO ⟷ TIMES t ZERO factorzl : {t : U} → ZERO ⟷ TIMES ZERO t dist : {t₁ t₂ t₃ : U} → TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) factor : {t₁ t₂ t₃ : U} → PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃ distl : {t₁ t₂ t₃ : U } → TIMES t₁ (PLUS t₂ t₃) ⟷ PLUS (TIMES t₁ t₂) (TIMES t₁ t₃) factorl : {t₁ t₂ t₃ : U } → PLUS (TIMES t₁ t₂) (TIMES t₁ t₃) ⟷ TIMES t₁ (PLUS t₂ t₃) id⟷ : {t : U} → t ⟷ t _◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃) _⊕_ : {t₁ t₂ t₃ t₄ : U} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄) _⊗_ : {t₁ t₂ t₃ t₄ : U} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄) {-- -- Syntactic equality of combinators comb= : {t₁ t₂ t₃ t₄ : U} → (t₁ ⟷ t₂) → (t₃ ⟷ t₄) → Bool comb= unite₊l unite₊l = true comb= uniti₊l uniti₊l = true comb= swap₊ swap₊ = true comb= assocl₊ assocl₊ = true comb= assocr₊ assocr₊ = true comb= unite⋆l unite⋆l = true comb= unite⋆r unite⋆r = true comb= uniti⋆l uniti⋆l = true comb= uniti⋆r uniti⋆r = true comb= swap⋆ swap⋆ = true comb= assocl⋆ assocl⋆ = true comb= assocr⋆ assocr⋆ = true comb= absorbl absorbl = true comb= absorbr absorbr = true comb= factorzl factorzl = true comb= factorzr factorzr = true comb= dist dist = true comb= factor factor = true comb= id⟷ id⟷ = true comb= (c₁ ◎ c₂) (c₃ ◎ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄ comb= (c₁ ⊕ c₂) (c₃ ⊕ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄ comb= (c₁ ⊗ c₂) (c₃ ⊗ c₄) = comb= c₁ c₃ ∧ comb= c₂ c₄ comb= _ _ = false -- Extensional evaluator for testing: serves as a specification -- A canonical representation of each type as a vector of values. This -- fixes a canonical order for the elements of the types: each value -- has a canonical index. utoVec : (t : U) → Vec ⟦ t ⟧ (size t) utoVec ZERO = [] utoVec ONE = tt ∷ [] utoVec (PLUS t₁ t₂) = mapV inj₁ (utoVec t₁) ++V mapV inj₂ (utoVec t₂) utoVec (TIMES t₁ t₂) = concatV (mapV (λ v₁ → mapV (λ v₂ → (v₁ , v₂)) (utoVec t₂)) (utoVec t₁)) -- Combinators are always between types of the same size -- Paths preserve sizes size≡ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (size t₁ ≡ size t₂) -- the composition case must be the first one -- otherwise Agda will not unfold (c ◎ id⟷) -- See "inconclusive matching" at -- http://wiki.portal.chalmers.se/agda/ -- pmwiki.php?n=ReferenceManual.PatternMatching size≡ (c₁ ◎ c₂) = trans (size≡ c₁) (size≡ c₂) size≡ {PLUS ZERO t} {.t} unite₊l = refl size≡ {t} {PLUS ZERO .t} uniti₊l = refl size≡ {PLUS t ZERO} unite₊r = +-right-identity (size t) size≡ {t} uniti₊r = sym (+-right-identity (size t)) size≡ {PLUS t₁ t₂} {PLUS .t₂ .t₁} swap₊ = +-comm (size t₁) (size t₂) size≡ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} assocl₊ = sym (+-assoc (size t₁) (size t₂) (size t₃)) size≡ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} assocr₊ = +-assoc (size t₁) (size t₂) (size t₃) size≡ {TIMES ONE t} {.t} unite⋆l = +-right-identity (size t) size≡ {t} {TIMES ONE .t} uniti⋆l = sym (+-right-identity (size t)) size≡ {TIMES t ONE} {.t} unite⋆r = *-right-identity (size t) size≡ {t} {TIMES .t ONE} uniti⋆r = sym (*-right-identity (size t)) size≡ {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = *-comm (size t₁) (size t₂) size≡ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} assocl⋆ = sym (*-assoc (size t₁) (size t₂) (size t₃)) size≡ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} assocr⋆ = *-assoc (size t₁) (size t₂) (size t₃) size≡ {TIMES .ZERO t} {ZERO} absorbr = refl size≡ {TIMES t .ZERO} {ZERO} absorbl = *-right-zero (size t) size≡ {ZERO} {TIMES ZERO t} factorzl = refl size≡ {ZERO} {TIMES t ZERO} factorzr = sym (*-right-zero (size t)) size≡ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} dist = distribʳ-*-+ (size t₃) (size t₁) (size t₂) size≡ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} factor = sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)) size≡ {TIMES t₁ (PLUS t₂ t₃)} distl = distribˡ-*-+ (size t₁) (size t₂) (size t₃) size≡ {PLUS (TIMES t₁ t₂) (TIMES .t₁ t₃)} factorl = sym (distribˡ-*-+ (size t₁) (size t₂) (size t₃)) size≡ {t} {.t} id⟷ = refl size≡ {PLUS t₁ t₂} {PLUS t₃ t₄} (c₁ ⊕ c₂) = cong₂ _+_ (size≡ c₁) (size≡ c₂) size≡ {TIMES t₁ t₂} {TIMES t₃ t₄} (c₁ ⊗ c₂) = cong₂ _*_ (size≡ c₁) (size≡ c₂) -- All proofs about sizes are "the same" size∼ : {t₁ t₂ : U} → (c₁ c₂ : t₁ ⟷ t₂) → (size≡ c₁ ≡ size≡ c₂) size∼ c₁ c₂ = proof-irrelevance (size≡ c₁) (size≡ c₂) ------------------------------------------------------------------------------ -- Examples of Pi programs -- Nicer syntax that shows intermediate values instead of the above -- point-free notation of permutations infixr 2 _⟷⟨_⟩_ infix 2 _□ _⟷⟨_⟩_ : (t₁ : U) {t₂ : U} {t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃) _ ⟷⟨ α ⟩ β = α ◎ β _□ : (t : U) → {t : U} → (t ⟷ t) _□ t = id⟷ -- calculate and print specification of a combinator spec : {t₁ t₂ : U} → (t₁ ⟷ t₂) → Vec (⟦ t₁ ⟧ × ⟦ t₂ ⟧) (size t₁) spec {t₁} {t₂} c = mapV (λ v₁ → (v₁ , eval c v₁)) (utoVec t₁) -- For easier manipulation of Bool foldBool unfoldBool : BOOL ⟷ BOOL foldBool = id⟷ unfoldBool = id⟷ -- Many ways of negating a BOOL. Again, it is absolutely critical that there -- is NO path between false⟷ and true⟷. These permutations instead are based -- on paths between x and neg (neg x) which are the trivial paths on each of -- the two points in BOOL. NOT : BOOL ⟷ BOOL NOT = unfoldBool ◎ swap₊ ◎ foldBool -- spec: (false , true) ∷ (true , false) ∷ [] NEG1 NEG2 NEG3 NEG4 NEG5 : BOOL ⟷ BOOL NEG1 = unfoldBool ◎ swap₊ ◎ foldBool -- spec: (false , true) ∷ (true , false) ∷ [] NEG2 = id⟷ ◎ NOT -- spec: (false , true) ∷ (true , false) ∷ [] NEG3 = NOT ◎ NOT ◎ NOT -- spec: (false , true) ∷ (true , false) ∷ [] NEG4 = NOT ◎ id⟷ -- spec: (false , true) ∷ (true , false) ∷ [] NEG5 = uniti⋆l ◎ swap⋆ ◎ (NOT ⊗ id⟷) ◎ swap⋆ ◎ unite⋆l -- spec: (false , true) ∷ (true , false) ∷ [] NEG6 = uniti⋆r ◎ (NOT ⊗ id⟷) ◎ unite⋆r -- same as above, but shorter -- CNOT CNOT : BOOL² ⟷ BOOL² CNOT = TIMES BOOL BOOL ⟷⟨ unfoldBool ⊗ id⟷ ⟩ TIMES (PLUS x y) BOOL ⟷⟨ dist ⟩ PLUS (TIMES x BOOL) (TIMES y BOOL) ⟷⟨ id⟷ ⊕ (id⟷ ⊗ NOT) ⟩ PLUS (TIMES x BOOL) (TIMES y BOOL) ⟷⟨ factor ⟩ TIMES (PLUS x y) BOOL ⟷⟨ foldBool ⊗ id⟷ ⟩ TIMES BOOL BOOL □ where x = ONE; y = ONE -- spec: -- ((false , false) , false , false) ∷ -- ((false , true) , false , true) ∷ -- ((true , false) , true , true) ∷ -- ((true , true) , true , false) ∷ [] -- TOFFOLI TOFFOLI : TIMES BOOL BOOL² ⟷ TIMES BOOL BOOL² TOFFOLI = TIMES BOOL BOOL² ⟷⟨ unfoldBool ⊗ id⟷ ⟩ TIMES (PLUS x y) BOOL² ⟷⟨ dist ⟩ PLUS (TIMES x BOOL²) (TIMES y BOOL²) ⟷⟨ id⟷ ⊕ (id⟷ ⊗ CNOT) ⟩ PLUS (TIMES x BOOL²) (TIMES y BOOL²) ⟷⟨ factor ⟩ TIMES (PLUS x y) BOOL² ⟷⟨ foldBool ⊗ id⟷ ⟩ TIMES BOOL BOOL² □ where x = ONE; y = ONE -- spec: -- ((false , false , false) , false , false , false) ∷ -- ((false , false , true) , false , false , true) ∷ -- ((false , true , false) , false , true , false) ∷ -- ((false , true , true) , false , true , true) ∷ -- ((true , false , false) , true , false , false) ∷ -- ((true , false , true) , true , false , true) ∷ -- ((true , true , false) , true , true , true) ∷ -- ((true , true , true) , true , true , false) ∷ [] -- Swaps for the type 1+(1+1) -- We have three values in the type 1+(1+1) -- Let's call them a, b, and c -- There 6 permutations. Using the swaps below we can express every permutation: -- a b c id⟷ -- a c b SWAP23 -- b a c SWAP12 -- b c a ROTL -- c a b ROTR -- c b a SWAP13 SWAP12 SWAP23 SWAP13 ROTL ROTR : PLUS ONE (PLUS ONE ONE) ⟷ PLUS ONE (PLUS ONE ONE) SWAP12 = assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊ -- spec: -- (inj₁ tt , inj₂ (inj₁ tt)) ∷ -- (inj₂ (inj₁ tt) , inj₁ tt) ∷ -- (inj₂ (inj₂ tt) , inj₂ (inj₂ tt)) ∷ [] SWAP23 = id⟷ ⊕ swap₊ -- spec: -- (inj₁ tt , inj₁ tt) ∷ -- (inj₂ (inj₁ tt) , inj₂ (inj₂ tt)) ∷ -- (inj₂ (inj₂ tt) , inj₂ (inj₁ tt)) ∷ [] SWAP13 = SWAP23 ◎ SWAP12 ◎ SWAP23 -- spec: -- (inj₁ tt , inj₂ (inj₂ tt)) ∷ -- (inj₂ (inj₁ tt) , inj₂ (inj₁ tt)) ∷ -- (inj₂ (inj₂ tt) , inj₁ tt) ∷ [] ROTR = SWAP12 ◎ SWAP23 -- spec: -- (inj₁ tt , inj₂ (inj₂ tt)) ∷ -- (inj₂ (inj₁ tt) , inj₁ tt) ∷ -- (inj₂ (inj₂ tt) , inj₂ (inj₁ tt)) ∷ [] ROTL = SWAP13 ◎ SWAP23 -- spec: -- (inj₁ tt , inj₂ (inj₁ tt)) ∷ -- (inj₂ (inj₁ tt) , inj₂ (inj₂ tt)) ∷ -- (inj₂ (inj₂ tt) , inj₁ tt) ∷ [] -- The Peres gate is a universal gate: it takes three inputs a, b, and c, and -- produces a, a xor b, (a and b) xor c PERES : TIMES (TIMES BOOL BOOL) BOOL ⟷ TIMES (TIMES BOOL BOOL) BOOL PERES = (id⟷ ⊗ NOT) ◎ assocr⋆ ◎ (id⟷ ⊗ swap⋆) ◎ TOFFOLI ◎ (id⟷ ⊗ (NOT ⊗ id⟷)) ◎ TOFFOLI ◎ (id⟷ ⊗ swap⋆) ◎ (id⟷ ⊗ (NOT ⊗ id⟷)) ◎ TOFFOLI ◎ (id⟷ ⊗ (NOT ⊗ id⟷)) ◎ assocl⋆ -- spec: -- (((false , false) , false) , (false , false) , false) ∷ -- (((false , false) , true) , (false , false) , true) ∷ -- (((false , true) , false) , (false , true) , false) ∷ -- (((false , true) , true) , (false , true) , true) ∷ -- (((true , false) , false) , (true , true) , false) ∷ -- (((true , false) , true) , (true , true) , true) ∷ -- (((true , true) , false) , (true , false) , true) ∷ -- (((true , true) , true) , (true , false) , false) ∷ [] -- A reversible full adder: See http://arxiv.org/pdf/1008.3533.pdf -- Input: (z, ((n1, n2), cin))) -- Output (g1, (g2, (sum, cout))) -- where sum = n1 xor n2 xor cin -- and cout = ((n1 xor n2) and cin) xor (n1 and n2) xor z FULLADDER : TIMES BOOL (TIMES (TIMES BOOL BOOL) BOOL) ⟷ TIMES BOOL (TIMES BOOL (TIMES BOOL BOOL)) FULLADDER = -- (z,((n1,n2),cin)) swap⋆ ◎ -- (((n1,n2),cin),z) (swap⋆ ⊗ id⟷) ◎ -- ((cin,(n1,n2)),z) assocr⋆ ◎ -- (cin,((n1,n2),z)) swap⋆ ◎ -- (((n1,n2),z),cin) (PERES ⊗ id⟷) ◎ -- (((n1,n1 xor n2),(n1 and n2) xor z),cin) assocr⋆ ◎ -- ((n1,n1 xor n2),((n1 and n2) xor z,cin)) (id⟷ ⊗ swap⋆) ◎ -- ((n1,n1 xor n2),(cin,(n1 and n2) xor z)) assocr⋆ ◎ -- (n1,(n1 xor n2,(cin,(n1 and n2) xor z))) (id⟷ ⊗ assocl⋆) ◎ -- (n1,((n1 xor n2,cin),(n1 and n2) xor z)) (id⟷ ⊗ PERES) ◎ -- (n1,((n1 xor n2,n1 xor n2 xor cin), -- ((n1 xor n2) and cin) xor (n1 and n2) xor z)) (id⟷ ⊗ assocr⋆) -- (n1,(n1 xor n2, -- (n1 xor n2 xor cin,((n1 xor n2) and cin) xor (n1 and n2) xor z))) -- spec: -- ((false , (false , false) , false) , false , false , false , false) ∷ -- ((false , (false , false) , true) , false , false , true , false) ∷ -- ((false , (false , true) , false) , false , true , true , false) ∷ -- ((false , (false , true) , true) , false , true , false , true) ∷ -- ((false , (true , false) , false) , true , true , true , false) ∷ -- ((false , (true , false) , true) , true , true , false , true) ∷ -- ((false , (true , true) , false) , true , false , false , true) ∷ -- ((false , (true , true) , true) , true , false , true , true) ∷ -- ((true , (false , false) , false) , false , false , false , true) ∷ -- ((true , (false , false) , true) , false , false , true , true) ∷ -- ((true , (false , true) , false) , false , true , true , true) ∷ -- ((true , (false , true) , true) , false , true , false , false) ∷ -- ((true , (true , false) , false) , true , true , true , true) ∷ -- ((true , (true , false) , true) , true , true , false , false) ∷ -- ((true , (true , true) , false) , true , false , false , false) ∷ -- ((true , (true , true) , true) , true , false , true , false) ∷ [] --} ------------------------------------------------------------------------------ -- Every permutation has an inverse. There are actually many syntactically -- different inverses but they are all equivalent. -- Alternative view: this corresponds to Lemma 2.1.1 In our notation, -- for every path t₁ ⟷ t₂, we have a path t₂ ⟷ t₁ such that (! id⟷) -- reduces to id⟷. ! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁) ! unite₊l = uniti₊l ! uniti₊l = unite₊l ! unite₊r = uniti₊r ! uniti₊r = unite₊r ! swap₊ = swap₊ ! assocl₊ = assocr₊ ! assocr₊ = assocl₊ ! unite⋆l = uniti⋆l ! uniti⋆l = unite⋆l ! unite⋆r = uniti⋆r ! uniti⋆r = unite⋆r ! swap⋆ = swap⋆ ! assocl⋆ = assocr⋆ ! assocr⋆ = assocl⋆ ! absorbl = factorzr ! absorbr = factorzl ! factorzl = absorbr ! factorzr = absorbl ! dist = factor ! factor = dist ! distl = factorl ! factorl = distl ! id⟷ = id⟷ ! (c₁ ◎ c₂) = ! c₂ ◎ ! c₁ ! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂) ! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂) !! : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → ! (! c) ≡ c !! {c = unite₊l} = refl !! {c = uniti₊l} = refl !! {c = unite₊r} = refl !! {c = uniti₊r} = refl !! {c = swap₊} = refl !! {c = assocl₊} = refl !! {c = assocr₊} = refl !! {c = unite⋆l} = refl !! {c = uniti⋆l} = refl !! {c = unite⋆r} = refl !! {c = uniti⋆r} = refl !! {c = swap⋆} = refl !! {c = assocl⋆} = refl !! {c = assocr⋆} = refl !! {c = absorbr} = refl !! {c = absorbl} = refl !! {c = factorzl} = refl !! {c = factorzr} = refl !! {c = dist} = refl !! {c = factor} = refl !! {c = distl} = refl !! {c = factorl} = refl !! {c = id⟷} = refl !! {c = c₁ ◎ c₂} = begin (! (! (c₁ ◎ c₂)) ≡⟨ refl ⟩ ! (! c₂ ◎ ! c₁) ≡⟨ refl ⟩ ! (! c₁) ◎ ! (! c₂) ≡⟨ cong₂ _◎_ (!! {c = c₁}) (!! {c = c₂}) ⟩ c₁ ◎ c₂ ∎) where open ≡-Reasoning !! {c = c₁ ⊕ c₂} = begin (! (! (c₁ ⊕ c₂)) ≡⟨ refl ⟩ ! (! c₁) ⊕ ! (! c₂) ≡⟨ cong₂ _⊕_ (!! {c = c₁}) (!! {c = c₂}) ⟩ c₁ ⊕ c₂ ∎) where open ≡-Reasoning !! {c = c₁ ⊗ c₂} = begin (! (! (c₁ ⊗ c₂)) ≡⟨ refl ⟩ ! (! c₁) ⊗ ! (! c₂) ≡⟨ cong₂ _⊗_ (!! {c = c₁}) (!! {c = c₂}) ⟩ c₁ ⊗ c₂ ∎) where open ≡-Reasoning {-- -- size≡ and ! size≡! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (size t₂ ≡ size t₁) size≡! c = sym (size≡ c) ------------------------------------------------------------------------------ ttt : {t₁ t₂ t₃ t₄ : U} → (TIMES (PLUS t₁ t₂) (PLUS t₃ t₄)) ⟷ (PLUS (PLUS (PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)) (TIMES t₁ t₄))) (TIMES t₂ t₄) ttt {t₁} {t₂} {t₃} {t₄} = (distl ◎ (dist {t₁} {t₂} {t₃} ⊕ dist {t₁} {t₂} {t₄})) ◎ assocl₊ ------------------------------------------------------------------------------ -- generalized CNOT gcnot : {A B C : U} → (TIMES (PLUS A B) (PLUS C C)) ⟷ (TIMES (PLUS A B) (PLUS C C)) gcnot = dist ◎ (id⟷ ⊕ (id⟷ ⊗ swap₊)) ◎ factor -- Generalized Toffolli gate. See what 'arithmetic' it performs. GToffoli : {A B C D E : U} → TIMES (PLUS A B) (TIMES (PLUS C D) (PLUS E E)) ⟷ TIMES (PLUS A B) (TIMES (PLUS C D) (PLUS E E)) GToffoli = dist ◎ (id⟷ ⊕ (id⟷ ⊗ gcnot)) ◎ factor ------------------------------------------------------------------------------ --}
{ "alphanum_fraction": 0.5345004593, "avg_line_length": 35.1844106464, "ext": "agda", "hexsha": "397e18f416d53b4cd22aff028f81f8e1735ffddc", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/Obsolete/PiLevel0.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/Obsolete/PiLevel0.agda", "max_line_length": 124, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/Obsolete/PiLevel0.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 7873, "size": 18507 }
module Prelude.Alternative where open import Agda.Primitive open import Prelude.Bool open import Prelude.Maybe open import Prelude.List open import Prelude.Sum open import Prelude.Decidable open import Prelude.Functor open import Prelude.Applicative open import Prelude.Function open import Prelude.Monoid module _ {a b} (F : Set a → Set b) where record FunctorZero : Set (lsuc a ⊔ b) where field empty : ∀ {A} → F A overlap {{super}} : Functor F record Alternative : Set (lsuc a ⊔ b) where infixl 3 _<|>_ field _<|>_ : ∀ {A} → F A → F A → F A overlap {{super}} : FunctorZero open FunctorZero {{...}} public open Alternative {{...}} public {-# DISPLAY FunctorZero.empty _ = empty #-} {-# DISPLAY Alternative._<|>_ _ x y = x <|> y #-} instance FunctorZeroMaybe : ∀ {a} → FunctorZero (Maybe {a}) empty {{FunctorZeroMaybe}} = nothing -- Left-biased choice AlternativeMaybe : ∀ {a} → Alternative (Maybe {a}) _<|>_ {{AlternativeMaybe}} nothing y = y _<|>_ {{AlternativeMaybe}} x y = x FunctorZeroList : ∀ {a} → FunctorZero (List {a}) empty {{FunctorZeroList}} = [] AlternativeList : ∀ {a} → Alternative (List {a}) _<|>_ {{AlternativeList}} = _++_ FunctorZeroEither : ∀ {a b} {E : Set b} {{_ : Monoid E}} → FunctorZero (Either {b = a} E) empty {{FunctorZeroEither}} = left mempty AlternativeEither : ∀ {a b} {E : Set b} {{_ : Monoid E}} → Alternative (Either {b = a} E) _<|>_ {{AlternativeEither}} x y = either (const y) right x module _ {a b} {F : Set a → Set b} {A : Set a} {{_ : FunctorZero F}} where guard! : Bool → F A → F A guard! true x = x guard! false _ = empty guard : ∀ {p} {P : Set p} (d : Dec P) → ({{_ : P}} → F A) → F A guard (yes p) x = x {{p}} guard (no _) _ = empty module _ {a b} {F : Set a → Set b} {A : Set a} {{_ : Alternative F}} where choice : List (F A) → F A choice = foldr _<|>_ empty maybeA : {{_ : Applicative F}} → F A → F (Maybe A) maybeA x = just <$> x <|> pure nothing
{ "alphanum_fraction": 0.6047548291, "avg_line_length": 28.8428571429, "ext": "agda", "hexsha": "e6905647526638bf2a41fa82895c4c89da2a0d03", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lclem/agda-prelude", "max_forks_repo_path": "src/Prelude/Alternative.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lclem/agda-prelude", "max_issues_repo_path": "src/Prelude/Alternative.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lclem/agda-prelude", "max_stars_repo_path": "src/Prelude/Alternative.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 659, "size": 2019 }
{-# OPTIONS --allow-unsolved-metas #-} open import Agda.Builtin.Nat record R : Set where field r₁ : Nat r₂ : Nat open R h : (n : Nat) → R r₁ (h zero) = {!!} r₂ (h zero) = {!!} h (suc n) = {!!}
{ "alphanum_fraction": 0.5291262136, "avg_line_length": 13.7333333333, "ext": "agda", "hexsha": "692c9a1ecfbcd4e342a5a4aba99839cfe62f35ae", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue2833.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue2833.agda", "max_line_length": 38, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue2833.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 80, "size": 206 }
------------------------------------------------------------------------------ -- Agda-Prop Library. -- Classical Propositional Logic. ------------------------------------------------------------------------------ open import Data.Nat using ( ℕ ) module Data.PropFormula.Theorems.Classical ( n : ℕ ) where ------------------------------------------------------------------------------ open import Data.PropFormula.Syntax n ------------------------------------------------------------------------------ postulate PEM : ∀ {Γ} {φ} → Γ ⊢ φ ∨ ¬ φ -- Theorem. RAA : ∀ {Γ} {φ} → Γ , ¬ φ ⊢ ⊥ → Γ ⊢ φ -- Proof. RAA {φ = φ} Γ¬φ⊢⊥ = ⊃-elim (⊃-intro (∨-elim (assume φ) (⊥-elim φ Γ¬φ⊢⊥))) PEM -------------------------------------------------------------------------- ∎
{ "alphanum_fraction": 0.2675709001, "avg_line_length": 23.1714285714, "ext": "agda", "hexsha": "51a89b8f7bdf5fe1b87a8d702060d5cc43a39772", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z", "max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z", "max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jonaprieto/agda-prop", "max_forks_repo_path": "src/Data/PropFormula/Theorems/Classical.agda", "max_issues_count": 18, "max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z", "max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jonaprieto/agda-prop", "max_issues_repo_path": "src/Data/PropFormula/Theorems/Classical.agda", "max_line_length": 78, "max_stars_count": 13, "max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jonaprieto/agda-prop", "max_stars_repo_path": "src/Data/PropFormula/Theorems/Classical.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z", "num_tokens": 185, "size": 811 }
open import Coinduction using ( ♭ ) open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ) open import System.IO.Transducers.Lazy using () renaming ( done to doneL ; _⟫_ to _⟫L_ ) open import System.IO.Transducers.Strict using () renaming ( done to doneS ; _⟫_ to _⟫S_ ) open import System.IO.Transducers.Session using ( Session ; I ; Σ ) open import System.IO.Transducers.Trace using ( Trace ) module System.IO.Transducers where open System.IO.Transducers.Lazy public using ( _⇒_ ; inp ; out ; ⟦_⟧ ; _≃_ ) open System.IO.Transducers.Strict public using ( _⇛_ ) data Style : Set where lazy strict : Style _⇒_is_ : Session → Session → Style → Set₁ S ⇒ T is lazy = S ⇒ T S ⇒ T is strict = S ⇛ T done : ∀ {s S} → (S ⇒ S is s) done {lazy} = doneL done {strict} = doneS _⟫_ : ∀ {s S T U} → (S ⇒ T is s) → (T ⇒ U is s) → (S ⇒ U is s) _⟫_ {lazy} = _⟫L_ _⟫_ {strict} = _⟫S_
{ "alphanum_fraction": 0.6508287293, "avg_line_length": 28.28125, "ext": "agda", "hexsha": "dd0a90cae6bf2e0c85d74f40d07a764bd0c8afb3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ilya-fiveisky/agda-system-io", "max_forks_repo_path": "src/System/IO/Transducers.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ilya-fiveisky/agda-system-io", "max_issues_repo_path": "src/System/IO/Transducers.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ilya-fiveisky/agda-system-io", "max_stars_repo_path": "src/System/IO/Transducers.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 314, "size": 905 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Rationals.SigmaQ.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.HITs.Ints.QuoInt import Cubical.HITs.SetQuotients as SetQuotient open import Cubical.Data.Nat as ℕ hiding (_·_) open import Cubical.Data.NatPlusOne open import Cubical.Data.Sigma open import Cubical.Data.Nat.GCD open import Cubical.Data.Nat.Coprime open import Cubical.HITs.Rationals.QuoQ as Quo using (ℕ₊₁→ℤ) import Cubical.HITs.Rationals.SigmaQ.Base as Sigma reduce : Quo.ℚ → Sigma.ℚ reduce = SetQuotient.rec Sigma.isSetℚ Sigma.[_] (λ { (a , b) (c , d) p → sym (Sigma.[]-cancelʳ (a , b) d) ∙ (λ i → Sigma.[ p i , ·₊₁-comm b d i ]) ∙ Sigma.[]-cancelʳ (c , d) b }) private toCoprime-eq₁ : ∀ s ((a , b) : ℕ × ℕ₊₁) → signed s (toCoprime (a , b) .fst) · ℕ₊₁→ℤ b ≡ signed s a · ℕ₊₁→ℤ (toCoprime (a , b) .snd) toCoprime-eq₁ s (a , b) = signed s c₁ · ℕ₊₁→ℤ b ≡⟨ ·-signed-pos c₁ (ℕ₊₁→ℕ b) ⟩ signed s (c₁ ℕ.· ℕ₊₁→ℕ b) ≡[ i ]⟨ signed s (c₁ ℕ.· p₂ (~ i)) ⟩ signed s (c₁ ℕ.· (ℕ₊₁→ℕ c₂ ℕ.· d)) ≡[ i ]⟨ signed s (c₁ ℕ.· ℕ.·-comm (ℕ₊₁→ℕ c₂) d i) ⟩ signed s (c₁ ℕ.· (d ℕ.· ℕ₊₁→ℕ c₂)) ≡[ i ]⟨ signed s (ℕ.·-assoc c₁ d (ℕ₊₁→ℕ c₂) i) ⟩ signed s ((c₁ ℕ.· d) ℕ.· ℕ₊₁→ℕ c₂) ≡[ i ]⟨ signed s (p₁ i ℕ.· ℕ₊₁→ℕ c₂) ⟩ signed s (a ℕ.· ℕ₊₁→ℕ c₂) ≡⟨ sym (·-signed-pos a (ℕ₊₁→ℕ c₂)) ⟩ signed s a · ℕ₊₁→ℤ c₂ ∎ where open ToCoprime (a , b) []-reduce : ∀ x → Quo.[ reduce x .fst ] ≡ x []-reduce = SetQuotient.elimProp (λ _ → Quo.isSetℚ _ _) (λ { (signed s a , b) → Quo.eq/ _ _ (toCoprime-eq₁ s (a , b)) ; (posneg i , b) j → isSet→isSet' Quo.isSetℚ (Quo.eq/ (fst (reduce Quo.[ pos 0 , b ])) (pos 0 , b) (toCoprime-eq₁ spos (0 , b))) (Quo.eq/ (fst (reduce Quo.[ neg 0 , b ])) (neg 0 , b) (toCoprime-eq₁ sneg (0 , b))) (λ i → Quo.[ reduce (Quo.[ posneg i , b ]) .fst ]) (λ i → Quo.[ posneg i , b ]) i j }) private toCoprime-eq₂ : ∀ s ((a , b) : ℕ × ℕ₊₁) (cp : areCoprime (a , ℕ₊₁→ℕ b)) → Sigma.signedPair s (toCoprime (a , b)) ≡ Sigma.signedPair s (a , b) toCoprime-eq₂ s (a , b) cp i = Sigma.signedPair s (toCoprime-idem (a , b) cp i) reduce-[] : ∀ x → reduce Quo.[ x .fst ] ≡ x -- equivalent to: Sigma.[ s .fst ] ≡ x reduce-[] ((signed s a , b) , cp) = Σ≡Prop (λ _ → isPropIsGCD) (toCoprime-eq₂ s (a , b) cp) reduce-[] ((posneg i , b) , cp) j = isSet→isSet' Sigma.isSetℚ (Σ≡Prop (λ _ → isPropIsGCD) (toCoprime-eq₂ spos (0 , b) cp)) (Σ≡Prop (λ _ → isPropIsGCD) (toCoprime-eq₂ sneg (0 , b) cp)) (λ i → Sigma.[ posneg i , b ]) (λ i → (posneg i , b) , cp) i j Quoℚ-iso-Sigmaℚ : Iso Quo.ℚ Sigma.ℚ Iso.fun Quoℚ-iso-Sigmaℚ = reduce Iso.inv Quoℚ-iso-Sigmaℚ = Quo.[_] ∘ fst Iso.rightInv Quoℚ-iso-Sigmaℚ = reduce-[] Iso.leftInv Quoℚ-iso-Sigmaℚ = []-reduce Quoℚ≃Sigmaℚ : Quo.ℚ ≃ Sigma.ℚ Quoℚ≃Sigmaℚ = isoToEquiv Quoℚ-iso-Sigmaℚ Quoℚ≡Sigmaℚ : Quo.ℚ ≡ Sigma.ℚ Quoℚ≡Sigmaℚ = isoToPath Quoℚ-iso-Sigmaℚ
{ "alphanum_fraction": 0.5780525502, "avg_line_length": 40.9493670886, "ext": "agda", "hexsha": "88d34943055ca79fb03b046c45369f46026e97a5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/Rationals/SigmaQ/Properties.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/Rationals/SigmaQ/Properties.agda", "max_line_length": 95, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/Rationals/SigmaQ/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1452, "size": 3235 }
{-# OPTIONS --rewriting #-} module Luau.RuntimeError.ToString where open import Agda.Builtin.Float using (primShowFloat) open import FFI.Data.String using (String; _++_) open import Luau.RuntimeError using (RuntimeErrorᴮ; RuntimeErrorᴱ; local; return; FunctionMismatch; BinOpMismatch₁; BinOpMismatch₂; UnboundVariable; SEGV; app₁; app₂; block; bin₁; bin₂) open import Luau.RuntimeType.ToString using (runtimeTypeToString) open import Luau.Addr.ToString using (addrToString) open import Luau.Syntax.ToString using (valueToString; exprToString) open import Luau.Var.ToString using (varToString) open import Luau.Syntax using (var; val; addr; binexp; block_is_end; local_←_; return; _∙_; name; _$_; ··) errToStringᴱ : ∀ {a H} M → RuntimeErrorᴱ {a} H M → String errToStringᴮ : ∀ {a H} B → RuntimeErrorᴮ {a} H B → String errToStringᴱ (var x) (UnboundVariable) = "variable " ++ varToString x ++ " is unbound" errToStringᴱ (val (addr a)) (SEGV p) = "address " ++ addrToString a ++ " is unallocated" errToStringᴱ (M $ N) (FunctionMismatch v w p) = "value " ++ (valueToString v) ++ " is not a function" errToStringᴱ (M $ N) (app₁ E) = errToStringᴱ M E errToStringᴱ (M $ N) (app₂ E) = errToStringᴱ N E errToStringᴱ (binexp M ·· N) (BinOpMismatch₁ v w p) = "value " ++ (valueToString v) ++ " is not a string" errToStringᴱ (binexp M ·· N) (BinOpMismatch₂ v w p) = "value " ++ (valueToString w) ++ " is not a string" errToStringᴱ (binexp M op N) (BinOpMismatch₁ v w p) = "value " ++ (valueToString v) ++ " is not a number" errToStringᴱ (binexp M op N) (BinOpMismatch₂ v w p) = "value " ++ (valueToString w) ++ " is not a number" errToStringᴱ (binexp M op N) (bin₁ E) = errToStringᴱ M E errToStringᴱ (binexp M op N) (bin₂ E) = errToStringᴱ N E errToStringᴱ (block b is B end) (block E) = errToStringᴮ B E ++ "\n in call of function " ++ varToString (name b) errToStringᴮ (local x ← M ∙ B) (local E) = errToStringᴱ M E ++ "\n in definition of " ++ varToString (name x) errToStringᴮ (return M ∙ B) (return E) = errToStringᴱ M E ++ "\n in return statement"
{ "alphanum_fraction": 0.7052220595, "avg_line_length": 64.03125, "ext": "agda", "hexsha": "cd5f18f25a14cae719753dd6827bfd193f8ebed6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "XanderYZZ/luau", "max_forks_repo_path": "prototyping/Luau/RuntimeError/ToString.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "XanderYZZ/luau", "max_issues_repo_path": "prototyping/Luau/RuntimeError/ToString.agda", "max_line_length": 185, "max_stars_count": 1, "max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TheGreatSageEqualToHeaven/luau", "max_stars_repo_path": "prototyping/Luau/RuntimeError/ToString.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z", "num_tokens": 694, "size": 2049 }
module DeadCodePatSyn.Lib where private data Hidden : Set where hidden : Hidden pattern not-hidden = hidden
{ "alphanum_fraction": 0.7435897436, "avg_line_length": 13, "ext": "agda", "hexsha": "6d30589e2dc86497329c37826866a730aaffef26", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/DeadCodePatSyn/Lib.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/DeadCodePatSyn/Lib.agda", "max_line_length": 31, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/DeadCodePatSyn/Lib.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 29, "size": 117 }
open import Data.Product using (∃; ∃-syntax; _×_; _,_) open import DeBruijn open import Parallel open import Beta open import Takahashi par-triangle : ∀ {n} {M N : Term n} → M ⇉ N ------- → N ⇉ M * par-triangle {M = # x} ⇉-c = ⇉-c par-triangle {M = ƛ M} (⇉-ƛ M⇉N) = ⇉-ƛ (par-triangle M⇉N) par-triangle {M = (ƛ M) · N} (⇉-β M⇉M′ N⇉N′) = sub-par (par-triangle M⇉M′) (par-triangle N⇉N′) par-triangle {M = # _ · N} (⇉-ξ M⇉M′ N⇉N′) = ⇉-ξ (par-triangle M⇉M′) (par-triangle N⇉N′) par-triangle {M = _ · _ · N} (⇉-ξ M⇉M′ N⇉N′) = ⇉-ξ (par-triangle M⇉M′) (par-triangle N⇉N′) par-triangle {M = (ƛ _) · N} (⇉-ξ (⇉-ƛ M⇉M′) N⇉N′) = ⇉-β (par-triangle M⇉M′) (par-triangle N⇉N′) par-diamond : ∀ {n} {M A B : Term n} → M ⇉ A → M ⇉ B ---------------------- → ∃[ N ] (A ⇉ N × B ⇉ N) par-diamond {M = M} M⇉A M⇉B = M * , par-triangle M⇉A , par-triangle M⇉B strip : ∀ {n} {M A B : Term n} → M ⇉ A → M ⇉* B ------------------------ → ∃[ N ] (A ⇉* N × B ⇉ N) strip {A = A} M⇉A (M ∎) = A , (A ∎) , M⇉A strip {A = A} M⇉A (M ⇉⟨ M⇉M′ ⟩ M′⇉*B) with par-diamond M⇉A M⇉M′ ... | N , A⇉N , M′⇉N with strip M′⇉N M′⇉*B ... | N′ , N⇉*N′ , B⇉N′ = N′ , (A ⇉⟨ A⇉N ⟩ N⇉*N′) , B⇉N′ par-confluence : ∀ {n} {M A B : Term n} → M ⇉* A → M ⇉* B ------------------------ → ∃[ N ] (A ⇉* N × B ⇉* N) par-confluence {B = B} (M ∎) M⇉*B = B , M⇉*B , (B ∎) par-confluence {B = B} (M ⇉⟨ M⇉A ⟩ A⇉*A′) M⇉*B with strip M⇉A M⇉*B ... | N , A⇉*N , B⇉N with par-confluence A⇉*A′ A⇉*N ... | N′ , A′⇉*N′ , N⇉*N′ = N′ , A′⇉*N′ , (B ⇉⟨ B⇉N ⟩ N⇉*N′) confluence : ∀ {n} {M A B : Term n} → M —↠ A → M —↠ B ------------------------ → ∃[ N ] (A —↠ N × B —↠ N) confluence M—↠A M—↠B with par-confluence (betas-pars M—↠A) (betas-pars M—↠B) ... | N , A⇉*N , B⇉*N = N , pars-betas A⇉*N , pars-betas B⇉*N
{ "alphanum_fraction": 0.4097406035, "avg_line_length": 30.4677419355, "ext": "agda", "hexsha": "4c7aba39f47a307e7c23263a219650226a149e04", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "iwilare/church-rosser", "max_forks_repo_path": "ConfluenceParallelTakahashi.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "iwilare/church-rosser", "max_issues_repo_path": "ConfluenceParallelTakahashi.agda", "max_line_length": 96, "max_stars_count": 5, "max_stars_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "iwilare/church-rosser", "max_stars_repo_path": "ConfluenceParallelTakahashi.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-22T01:43:09.000Z", "max_stars_repo_stars_event_min_datetime": "2020-06-02T07:27:54.000Z", "num_tokens": 1057, "size": 1889 }
module Issue1258 where data _==_ {A : Set}(x : A) : A -> Set where refl : x == x data Bool : Set where true false : Bool postulate f : (A : Set) -> A -> Bool Foo : Bool -> Set Foo true = Bool Foo false = Bool Alpha : Bool Beta : Foo Alpha test : f (Foo Alpha) Beta == f Bool false Alpha = _ Beta = Alpha test = refl -- Normalizing Alpha yields a metavariable, but normalizing Beta yields -- false.
{ "alphanum_fraction": 0.6414634146, "avg_line_length": 15.7692307692, "ext": "agda", "hexsha": "f7cad896fd3d983b7a76c5cc87985f5b44de308b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1258.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1258.agda", "max_line_length": 71, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1258.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 125, "size": 410 }
module non-regular where open import Data.Nat open import Data.Empty open import Data.List open import Data.Maybe hiding ( map ) open import Relation.Binary.PropositionalEquality hiding ( [_] ) open import logic open import automaton open import automaton-ex open import finiteSetUtil open import finiteSet open import Relation.Nullary open import regular-language open import nat open FiniteSet inputnn : List In2 → Maybe (List In2) inputnn [] = just [] inputnn (i1 ∷ t) = just (i1 ∷ t) inputnn (i0 ∷ t) with inputnn t ... | nothing = nothing ... | just [] = nothing ... | just (i0 ∷ t1) = nothing -- can't happen ... | just (i1 ∷ t1) = just t1 -- remove i1 from later part inputnn1 : List In2 → Bool inputnn1 s with inputnn s ... | nothing = false ... | just [] = true ... | just _ = false t1 = inputnn1 ( i0 ∷ i1 ∷ [] ) t2 = inputnn1 ( i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] ) t3 = inputnn1 ( i0 ∷ i0 ∷ i0 ∷ i1 ∷ i1 ∷ [] ) inputnn0 : ( n : ℕ ) → { Σ : Set } → ( x y : Σ ) → List Σ → List Σ inputnn0 zero {_} _ _ s = s inputnn0 (suc n) x y s = x ∷ ( inputnn0 n x y ( y ∷ s ) ) t4 : inputnn1 ( inputnn0 5 i0 i1 [] ) ≡ true t4 = refl t5 : ( n : ℕ ) → Set t5 n = inputnn1 ( inputnn0 n i0 i1 [] ) ≡ true -- -- if there is an automaton with n states , which accespt inputnn1, it has a trasition function. -- The function is determinted by inputs, -- open RegularLanguage open Automaton open _∧_ data Trace { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) : (is : List Σ) → Q → Set where tend : {q : Q} → aend fa q ≡ true → Trace fa [] q tnext : (q : Q) → {i : Σ} { is : List Σ} → Trace fa is (δ fa q i) → Trace fa (i ∷ is) q tr-len : { Q : Set } { Σ : Set } → (fa : Automaton Q Σ ) → (is : List Σ) → (q : Q) → Trace fa is q → suc (length is) ≡ length (trace fa q is ) tr-len {Q} {Σ} fa .[] q (tend x) = refl tr-len {Q} {Σ} fa (i ∷ is) q (tnext .q t) = cong suc (tr-len {Q} {Σ} fa is (δ fa q i) t) tr-accept→ : { Q : Set } { Σ : Set } → (fa : Automaton Q Σ ) → (is : List Σ) → (q : Q) → Trace fa is q → accept fa q is ≡ true tr-accept→ {Q} {Σ} fa [] q (tend x) = x tr-accept→ {Q} {Σ} fa (i ∷ is) q (tnext _ tr) = tr-accept→ {Q} {Σ} fa is (δ fa q i) tr tr-accept← : { Q : Set } { Σ : Set } → (fa : Automaton Q Σ ) → (is : List Σ) → (q : Q) → accept fa q is ≡ true → Trace fa is q tr-accept← {Q} {Σ} fa [] q ac = tend ac tr-accept← {Q} {Σ} fa (x ∷ []) q ac = tnext _ (tend ac ) tr-accept← {Q} {Σ} fa (x ∷ x1 ∷ is) q ac = tnext _ (tr-accept← fa (x1 ∷ is) (δ fa q x) ac) tr→qs : { Q : Set } { Σ : Set } → (fa : Automaton Q Σ ) → (is : List Σ) → (q : Q) → Trace fa is q → List Q tr→qs fa [] q (tend x) = [] tr→qs fa (i ∷ is) q (tnext q tr) = q ∷ tr→qs fa is (δ fa q i) tr tr→qs=is : { Q : Set } { Σ : Set } → (fa : Automaton Q Σ ) → (is : List Σ) → (q : Q) → (tr : Trace fa is q ) → length is ≡ length (tr→qs fa is q tr) tr→qs=is fa .[] q (tend x) = refl tr→qs=is fa (i ∷ is) q (tnext .q tr) = cong suc (tr→qs=is fa is (δ fa q i) tr) open Data.Maybe open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) open import Relation.Binary.Definitions open import Data.Unit using (⊤ ; tt) open import Data.Nat.Properties data QDSEQ { Q : Set } { Σ : Set } { fa : Automaton Q Σ} ( finq : FiniteSet Q) (qd : Q) (z1 : List Σ) : {q : Q} {y2 : List Σ} → Trace fa (y2 ++ z1) q → Set where qd-nil : (q : Q) → (tr : Trace fa z1 q) → equal? finq qd q ≡ true → QDSEQ finq qd z1 tr qd-next : {i : Σ} (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) (δ fa q i)) → equal? finq qd q ≡ false → QDSEQ finq qd z1 tr → QDSEQ finq qd z1 (tnext q tr) record TA1 { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) ( q qd : Q ) (is : List Σ) : Set where field y z : List Σ yz=is : y ++ z ≡ is trace-z : Trace fa z qd trace-yz : Trace fa (y ++ z) q q=qd : QDSEQ finq qd z trace-yz -- -- using accept ≡ true may simplify the pumping-lemma -- QDSEQ is too complex, should we generate (lengty y ≡ 0 → equal ) ∧ ... -- -- like this ... -- record TA2 { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) ( q qd : Q ) (is : List Σ) : Set where -- field -- y z : List Σ -- yz=is : y ++ z ≡ is -- trace-z : accpet fa z qd ≡ true -- trace-yz : accept fa (y ++ z) q ≡ true -- q=qd : last (tr→qs fa q trace-yz) ≡ just qd -- ¬q=qd : non-last (tr→qs fa q trace-yz) ≡ just qd record TA { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) ( q : Q ) (is : List Σ) : Set where field x y z : List Σ xyz=is : x ++ y ++ z ≡ is trace-xyz : Trace fa (x ++ y ++ z) q trace-xyyz : Trace fa (x ++ y ++ y ++ z) q non-nil-y : ¬ (y ≡ []) pumping-lemma : { Q : Set } { Σ : Set } (fa : Automaton Q Σ ) (finq : FiniteSet Q) (q qd : Q) (is : List Σ) → (tr : Trace fa is q ) → dup-in-list finq qd (tr→qs fa is q tr) ≡ true → TA fa q is pumping-lemma {Q} {Σ} fa finq q qd is tr dup = tra-phase1 q is tr dup where open TA tra-phase2 : (q : Q) → (is : List Σ) → (tr : Trace fa is q ) → phase2 finq qd (tr→qs fa is q tr) ≡ true → TA1 fa finq q qd is tra-phase2 q (i ∷ is) (tnext q tr) p with equal? finq qd q | inspect ( equal? finq qd) q ... | true | record { eq = eq } = record { y = [] ; z = i ∷ is ; yz=is = refl ; q=qd = qd-nil q (tnext q tr) eq ; trace-z = subst (λ k → Trace fa (i ∷ is) k ) (sym (equal→refl finq eq)) (tnext q tr) ; trace-yz = tnext q tr } ... | false | record { eq = ne } = record { y = i ∷ TA1.y ta ; z = TA1.z ta ; yz=is = cong (i ∷_ ) (TA1.yz=is ta ) ; q=qd = tra-08 ; trace-z = TA1.trace-z ta ; trace-yz = tnext q ( TA1.trace-yz ta ) } where ta : TA1 fa finq (δ fa q i) qd is ta = tra-phase2 (δ fa q i) is tr p tra-07 : Trace fa (TA1.y ta ++ TA1.z ta) (δ fa q i) tra-07 = subst (λ k → Trace fa k (δ fa q i)) (sym (TA1.yz=is ta)) tr tra-08 : QDSEQ finq qd (TA1.z ta) (tnext q (TA1.trace-yz ta)) tra-08 = qd-next (TA1.y ta) q (TA1.trace-yz (tra-phase2 (δ fa q i) is tr p)) ne (TA1.q=qd ta) tra-phase1 : (q : Q) → (is : List Σ) → (tr : Trace fa is q ) → phase1 finq qd (tr→qs fa is q tr) ≡ true → TA fa q is tra-phase1 q (i ∷ is) (tnext q tr) p with equal? finq qd q | inspect (equal? finq qd) q ... | true | record { eq = eq } = record { x = [] ; y = i ∷ TA1.y ta ; z = TA1.z ta ; xyz=is = cong (i ∷_ ) (TA1.yz=is ta) ; non-nil-y = λ () ; trace-xyz = tnext q (TA1.trace-yz ta) ; trace-xyyz = tnext q tra-05 } where ta : TA1 fa finq (δ fa q i ) qd is ta = tra-phase2 (δ fa q i ) is tr p y1 = TA1.y ta z1 = TA1.z ta tryz0 : Trace fa (y1 ++ z1) (δ fa qd i) tryz0 = subst₂ (λ j k → Trace fa k (δ fa j i) ) (sym (equal→refl finq eq)) (sym (TA1.yz=is ta)) tr tryz : Trace fa (i ∷ y1 ++ z1) qd tryz = tnext qd tryz0 -- create Trace (y ++ y ++ z) tra-04 : (y2 : List Σ) → (q : Q) → (tr : Trace fa (y2 ++ z1) q) → QDSEQ finq qd z1 {q} {y2} tr → Trace fa (y2 ++ (i ∷ y1) ++ z1) q tra-04 [] q tr (qd-nil q _ x₁) with equal? finq qd q | inspect (equal? finq qd) q ... | true | record { eq = eq } = subst (λ k → Trace fa (i ∷ y1 ++ z1) k) (equal→refl finq eq) tryz ... | false | record { eq = ne } = ⊥-elim ( ¬-bool refl x₁ ) tra-04 (y0 ∷ y2) q (tnext q tr) (qd-next _ _ _ x₁ qdseq) with equal? finq qd q | inspect (equal? finq qd) q ... | true | record { eq = eq } = ⊥-elim ( ¬-bool x₁ refl ) ... | false | record { eq = ne } = tnext q (tra-04 y2 (δ fa q y0) tr qdseq ) tra-05 : Trace fa (TA1.y ta ++ (i ∷ TA1.y ta) ++ TA1.z ta) (δ fa q i) tra-05 with equal→refl finq eq ... | refl = tra-04 y1 (δ fa qd i) (TA1.trace-yz ta) (TA1.q=qd ta) ... | false | _ = record { x = i ∷ x ta ; y = y ta ; z = z ta ; xyz=is = cong (i ∷_ ) (xyz=is ta) ; non-nil-y = non-nil-y ta ; trace-xyz = tnext q (trace-xyz ta ) ; trace-xyyz = tnext q (trace-xyyz ta )} where ta : TA fa (δ fa q i ) is ta = tra-phase1 (δ fa q i ) is tr p open RegularLanguage open import Data.Nat.Properties open import nat lemmaNN : (r : RegularLanguage In2 ) → ¬ ( (s : List In2) → isRegular inputnn1 s r ) lemmaNN r Rg = tann {TA.x TAnn} (TA.non-nil-y TAnn ) {!!} (tr-accept→ (automaton r) _ (astart r) (TA.trace-xyz TAnn) ) (tr-accept→ (automaton r) _ (astart r) (TA.trace-xyyz TAnn) ) where n : ℕ n = suc (finite (afin r)) nn = inputnn0 n i0 i1 [] nn01 : (i : ℕ) → inputnn1 ( inputnn0 i i0 i1 [] ) ≡ true nn01 zero = refl nn01 (suc i) = {!!} where nn02 : (i : ℕ) → ( x : List In2) → inputnn ( inputnn0 i i0 i1 x ) ≡ inputnn x nn02 zero _ = refl nn02 (suc i) x with inputnn (inputnn0 (suc i) i0 i1 x) ... | nothing = {!!} ... | just [] = {!!} ... | just (i0 ∷ t1) = {!!} ... | just (i1 ∷ t1) = {!!} nn03 : accept (automaton r) (astart r) nn ≡ true nn03 = subst (λ k → k ≡ true ) (Rg nn ) (nn01 n) nn09 : (n m : ℕ) → n ≤ n + m nn09 zero m = z≤n nn09 (suc n) m = s≤s (nn09 n m) nn04 : Trace (automaton r) nn (astart r) nn04 = tr-accept← (automaton r) nn (astart r) nn03 nntrace = tr→qs (automaton r) nn (astart r) nn04 nn07 : (n : ℕ) → length (inputnn0 n i0 i1 []) ≡ n + n nn07 n = subst (λ k → length (inputnn0 n i0 i1 []) ≡ k) (+-comm (n + n) _ ) (nn08 n [] )where nn08 : (n : ℕ) → (s : List In2) → length (inputnn0 n i0 i1 s) ≡ n + n + length s nn08 zero s = refl nn08 (suc n) s = begin length (inputnn0 (suc n) i0 i1 s) ≡⟨ refl ⟩ suc (length (inputnn0 n i0 i1 (i1 ∷ s))) ≡⟨ cong suc (nn08 n (i1 ∷ s)) ⟩ suc (n + n + suc (length s)) ≡⟨ +-assoc (suc n) n _ ⟩ suc n + (n + suc (length s)) ≡⟨ cong (λ k → suc n + k) (sym (+-assoc n _ _)) ⟩ suc n + ((n + 1) + length s) ≡⟨ cong (λ k → suc n + (k + length s)) (+-comm n _) ⟩ suc n + (suc n + length s) ≡⟨ sym (+-assoc (suc n) _ _) ⟩ suc n + suc n + length s ∎ where open ≡-Reasoning nn05 : length nntrace > finite (afin r) nn05 = begin suc (finite (afin r)) ≤⟨ nn09 _ _ ⟩ n + n ≡⟨ sym (nn07 n) ⟩ length (inputnn0 n i0 i1 []) ≡⟨ tr→qs=is (automaton r) (inputnn0 n i0 i1 []) (astart r) nn04 ⟩ length nntrace ∎ where open ≤-Reasoning nn06 : Dup-in-list ( afin r) (tr→qs (automaton r) nn (astart r) nn04) nn06 = dup-in-list>n (afin r) nntrace nn05 TAnn : TA (automaton r) (astart r) nn TAnn = pumping-lemma (automaton r) (afin r) (astart r) (Dup-in-list.dup nn06) nn nn04 (Dup-in-list.is-dup nn06) count : In2 → List In2 → ℕ count _ [] = 0 count i0 (i0 ∷ s) = suc (count i0 s) count i1 (i1 ∷ s) = suc (count i1 s) count x (_ ∷ s) = count x s nn11 : {x : In2} → (s t : List In2) → count x (s ++ t) ≡ count x s + count x t nn11 {x} [] t = refl nn11 {i0} (i0 ∷ s) t = cong suc ( nn11 s t ) nn11 {i0} (i1 ∷ s) t = nn11 s t nn11 {i1} (i0 ∷ s) t = nn11 s t nn11 {i1} (i1 ∷ s) t = cong suc ( nn11 s t ) nn10 : (s : List In2) → accept (automaton r) (astart r) s ≡ true → count i0 s ≡ count i1 s nn10 s p = nn101 s (subst (λ k → k ≡ true) (sym (Rg s)) p ) where nn101 : (s : List In2) → inputnn1 s ≡ true → count i0 s ≡ count i1 s nn101 [] p = refl nn101 (x ∷ s) p = {!!} i1-i0? : List In2 → Bool i1-i0? [] = false i1-i0? (i1 ∷ []) = false i1-i0? (i0 ∷ []) = false i1-i0? (i1 ∷ i0 ∷ s) = true i1-i0? (_ ∷ s0 ∷ s1) = i1-i0? (s0 ∷ s1) nn20 : {s s0 s1 : List In2} → accept (automaton r) (astart r) s ≡ true → ¬ ( s ≡ s0 ++ i1 ∷ i0 ∷ s1 ) nn20 {s} {s0} {s1} p np = {!!} mono-color : List In2 → Bool mono-color [] = true mono-color (i0 ∷ s) = mono-color0 s where mono-color0 : List In2 → Bool mono-color0 [] = true mono-color0 (i1 ∷ s) = false mono-color0 (i0 ∷ s) = mono-color0 s mono-color (i1 ∷ s) = mono-color1 s where mono-color1 : List In2 → Bool mono-color1 [] = true mono-color1 (i0 ∷ s) = false mono-color1 (i1 ∷ s) = mono-color1 s record Is10 (s : List In2) : Set where field s0 s1 : List In2 is-10 : s ≡ s0 ++ i1 ∷ i0 ∷ s1 not-mono : { s : List In2 } → ¬ (mono-color s ≡ true) → Is10 (s ++ s) not-mono = {!!} mono-count : { s : List In2 } → mono-color s ≡ true → (length s ≡ count i0 s) ∨ ( length s ≡ count i1 s) mono-count = {!!} tann : {x y z : List In2} → ¬ y ≡ [] → x ++ y ++ z ≡ nn → accept (automaton r) (astart r) (x ++ y ++ z) ≡ true → ¬ (accept (automaton r) (astart r) (x ++ y ++ y ++ z) ≡ true ) tann {x} {y} {z} ny eq axyz axyyz with mono-color y ... | true = {!!} ... | false = {!!}
{ "alphanum_fraction": 0.5105210804, "avg_line_length": 44.6040955631, "ext": "agda", "hexsha": "653a8f09728b0e77d68d70bc243d63f2996432cb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/automaton-in-agda", "max_forks_repo_path": "src/non-regular.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shinji-kono/automaton-in-agda", "max_issues_repo_path": "src/non-regular.agda", "max_line_length": 127, "max_stars_count": null, "max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/automaton-in-agda", "max_stars_repo_path": "src/non-regular.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5339, "size": 13069 }
{-# OPTIONS --no-qualified-instances #-} module CF.Transform.UnCo where open import Data.Product open import Data.List open import Data.List.Relation.Unary.All open import Data.List.Membership.Propositional open import Relation.Unary hiding (_∈_) open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax open import Relation.Ternary.Monad hiding (unit) open import Relation.Ternary.Monad.Weakening open import Relation.Ternary.Data.Bigstar hiding ([_]) open import CF.Types open import CF.Syntax.Hoisted as Hoisted open import CF.Contexts.Lexical open import CF.Transform.Hoist open import CF.Syntax.DeBruijn as Tgt open Hoisted open import Relation.Ternary.Data.Allstar Ty {-# TERMINATING #-} mutual uncoₑ : ∀[ Hoisted.Exp a ⇑ ⇒ Tgt.Exp a ] uncoₑ (unit ⇈ wk) = unit uncoₑ (num x ⇈ wk) = num x uncoₑ (bool x ⇈ wk) = bool x uncoₑ (Exp.var' vars ⇈ wk) = Tgt.var' (member wk) uncoₑ (bop f e₁✴e₂ ⇈ wk) with e₁ , e₂ ← unstar (e₁✴e₂ ⇈ wk) = bop f (uncoₑ e₁) (uncoₑ e₂) uncoₑ (ifthenelse c✴e₁✴e₂ ⇈ wk) = let c , e₁✴e₂ = unstar (c✴e₁✴e₂ ⇈ wk) e₁ , e₂ = unstar e₁✴e₂ in ifthenelse (uncoₑ c) (uncoₑ e₁) (uncoₑ e₂) uncos : ∀[ (Allstar Hoisted.Exp as) ⇑ ⇒ Exps as ] uncos (nil ⇈ wk) = [] uncos (cons e✴es ⇈ wk) with e , es ← unstar (e✴es ⇈ wk) = uncoₑ e ∷ uncos es {-# TERMINATING #-} mutual uncoₛ : ∀[ Hoisted.Stmt r ⇑ ⇒ Tgt.Stmt r ] uncoₛ (run x ⇈ wk) = run (uncoₑ (x ⇈ wk)) uncoₛ (asgn v✴e ⇈ wk) with unstar (v✴e ⇈ wk) ... | vars ⇈ wk' , e⇑ = asgn (member wk') (uncoₑ e⇑) uncoₛ (ifthenelse c✴s₁✴s₂ ⇈ wk) = let c , s₁✴s₂ = unstar (c✴s₁✴s₂ ⇈ wk) s₁ , s₂ = unstar s₁✴s₂ in ifthenelse (uncoₑ c) (uncoₛ s₁) (uncoₛ s₂) uncoₛ (while c✴s ⇈ wk) with c , s ← unstar (c✴s ⇈ wk) = while (uncoₑ c) (uncoₛ s) uncoₛ (block x ⇈ wk) = block (unco' (x ⇈ wk)) unco' : ∀[ Hoisted.Block r ⇑ ⇒ Tgt.Block r ] unco' (nil ⇈ wk) = nil unco' (cons s✴b ⇈ wk) with s , b ← unstar (s✴b ⇈ wk) = uncoₛ s ⍮⍮ unco' b unco : ∀[ Hoisted.Block r ⇒ Tgt.Block r ] unco bl = unco' (return bl)
{ "alphanum_fraction": 0.647601476, "avg_line_length": 34.4126984127, "ext": "agda", "hexsha": "4368c2d93a82ffb71f189744f0a36e8af85a370d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z", "max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ajrouvoet/jvm.agda", "max_forks_repo_path": "src/CF/Transform/UnCo.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ajrouvoet/jvm.agda", "max_issues_repo_path": "src/CF/Transform/UnCo.agda", "max_line_length": 91, "max_stars_count": 6, "max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ajrouvoet/jvm.agda", "max_stars_repo_path": "src/CF/Transform/UnCo.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z", "num_tokens": 904, "size": 2168 }
-- Andreas, 2014-09-02 -- Up to today, there was no implementation of shadowing local variables -- (e.g., λ-bound variables) by local imports. -- {-# OPTIONS -v scope.locals:10 #-} module _ where module M where A = Set1 test : (A : Set) → let open M in A test A = Set -- The A exported by M is in competition with the local A. -- Ambiguous name should be reported.
{ "alphanum_fraction": 0.6782841823, "avg_line_length": 20.7222222222, "ext": "agda", "hexsha": "fbd7e480fc6820cc5cb8583e06706e481d86c9d4", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1266a.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue1266a.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1266a.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 105, "size": 373 }
import Imports.Issue5357-B import Imports.Issue5357-C
{ "alphanum_fraction": 0.8518518519, "avg_line_length": 18, "ext": "agda", "hexsha": "ecfc5210f1cb5d0fe25106c60b7e8757d67acb50", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "cagix/agda", "max_forks_repo_path": "test/interaction/Issue5357.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "cagix/agda", "max_issues_repo_path": "test/interaction/Issue5357.agda", "max_line_length": 26, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "cagix/agda", "max_stars_repo_path": "test/interaction/Issue5357.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 16, "size": 54 }
{-# OPTIONS --universe-polymorphism #-} module WrongMetaLeft where open import Imports.Level postulate ∃₂ : ∀ {a c : Level} {A : Set a} {B : Set} (C : A → B → Set c) → Set (a ⊔ c) proj₂ : ∀ {a c}{A : Set a}{B : Set}{C : A → B → Set c} → ∃₂ {a}{c}{A}{B} C → B postulate Position : Set Result : Set _≡_ : Result → Result → Set postulate Mono : {p : Level} (P : Position → Position → Set p) → Set p postulate Fun : ∀ {a : Level} {A : Set a} → (A → A → Set) → (A → Result) → Set a -- The problem is that the "wrong" meta is left unsolved. It's really the -- level of _<P_ that's not getting solved but it's instantiated to the -- sort of the type of resultsEqual, so the yellow ends up in a weird place. postulate Monad : (_<P_ : Position → Position → Set _) → (Key : Mono _<P_ -> Result -> Set) (_≈_ : ∃₂ Key → ∃₂ Key → Set) (resultsEqual : Fun {_} {∃₂ {_}{_}{Mono _<P_}{Result} Key} _≈_ (\(rfk : ∃₂ Key) -> proj₂ {_}{_}{_}{Result}{_} rfk)) → Set
{ "alphanum_fraction": 0.5347744361, "avg_line_length": 30.4, "ext": "agda", "hexsha": "164b76aaa696394392f766002c9868dbde54d848", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/WrongMetaLeft.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/WrongMetaLeft.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/WrongMetaLeft.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 371, "size": 1064 }
{-# OPTIONS --universe-polymorphism #-} module LLev where --**************** -- Universe polymorphism --**************** data Level : Set where ze : Level su : Level -> Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO ze #-} {-# BUILTIN LEVELSUC su #-} max : Level -> Level -> Level max ze m = m max (su n) ze = su n max (su n) (su m) = su (max n m) {-# BUILTIN LEVELMAX max #-} record Up {l : Level} (A : Set l) : Set (su l) where constructor up field down : A open Up record Sg {l : Level}(S : Set l)(T : S -> Set l) : Set l where constructor _,_ field fst : S snd : T fst open Sg _*_ : {l : Level} -> Set l -> Set l -> Set l S * T = Sg S \ _ -> T infixr 4 _*_ _,_ data Zero : Set where record One {l : Level} : Set l where constructor <> data Desc {l : Level}(I : Set l) : Set (su l) where var : (i : I) -> Desc I con : (A : Set l) -> Desc I sg pi : (S : Set l)(T : S -> Desc I) -> Desc I _**_ : (S T : Desc I) -> Desc I infixr 4 _**_ [!_!] : {l : Level}{I : Set l} -> Desc I -> (I -> Set l) -> Set l [! var i !] X = X i [! con A !] X = A [! sg S T !] X = Sg S \ s -> [! T s !] X [! pi S T !] X = (s : S) -> [! T s !] X [! S ** T !] X = [! S !] X * [! T !] X {- data Mu {l : Level}(I : Set l)(F : I -> Desc I)(i : I) : Set l where <_> : [! F i !] (Mu I F) -> Mu I F i -} All : {l : Level}{I : Set l} (D : Desc I)(X : I -> Set l) -> [! D !] X -> Desc (Sg I X) All (var i) X x = var (i , x) All (con A) X d = con One All (sg S T) X (s , t) = All (T s) X t All (pi S T) X f = pi S \ s -> All (T s) X (f s) All (S ** T) X (s , t) = All S X s ** All T X t all : {l : Level}{I : Set l} (D : Desc I)(X : I -> Set l)(P : Sg I X -> Set l) -> ((ix : Sg I X) -> P ix) -> (d : [! D !] X) -> [! All D X d !] P all (var i) X P p x = p (i , x) all (con A) X P p d = _ all (sg S T) X P p (s , t) = all (T s) X P p t all (pi S T) X P p f = \ s -> all (T s) X P p (f s) all (S ** T) X P p (s , t) = all S X P p s , all T X P p t {- induction : {l : Level}{I : Set l}{F : I -> Desc I} (P : Sg I (Mu I F) -> Set l) -> ((i : I)(d : [! F i !] (Mu I F)) -> [! All (F i) (Mu I F) d !] P -> P (i , < d >)) -> (ix : Sg I (Mu I F)) -> P ix induction {F = F} P p (i , < d >) = p i d (all (F i) (Mu _ F) P (induction P p) d) -} {- mutual induction : {l : Level}{I : Set l}{F : I -> Desc I} (P : Sg I (Mu I F) -> Set l) -> ((i : I)(d : [! F i !] (Mu I F)) -> [! All (F i) (Mu I F) d !] P -> P (i , < d >)) -> {i : I}(x : Mu I F i) -> P (i , x) induction {F = F} P p {i} < d > = p i d (allInduction F P p (F i) d) allInduction : {l : Level}{I : Set l}(F : I -> Desc I) (P : Sg I (Mu I F) -> Set l) -> ((i : I)(d : [! F i !] (Mu I F)) -> [! All (F i) (Mu I F) d !] P -> P (i , < d >)) -> (D : Desc I) -> (d : [! D !] (Mu I F)) -> [! All D (Mu I F) d !] P allInduction F P p (var i) d = induction P p d allInduction F P p (con A) d = _ allInduction F P p (sg S T) (s , t) = allInduction F P p (T s) t allInduction F P p (pi S T) f = \ s -> allInduction F P p (T s) (f s) allInduction F P p (S ** T) (s , t) = allInduction F P p S s , allInduction F P p T t -} data List {l : Level}(X : Set l) : Set l where [] : List X _::_ : X -> List X -> List X infixr 3 _::_ map : {k l : Level}{X : Set k}{Y : Set l} -> (X -> Y) -> List X -> List Y map f [] = [] map f (x :: xs) = f x :: map f xs data UId {l : Level} : Set l where ze : UId su : UId {l} -> UId data # {l : Level} : List {l} UId -> Set l where ze : forall {x xs} -> # (x :: xs) su : forall {x xs} -> # xs -> # (x :: xs) Constrs : {l : Level} -> Set l -> Set (su l) Constrs I = List (Up UId * Desc I) Constr : {l : Level}{I : Set l} -> Constrs I -> Set l Constr uDs = # (map (\ uD -> down (fst uD)) uDs) ConD : {l : Level}{I : Set l}(uDs : Constrs I) -> Constr uDs -> Desc I ConD [] () ConD (uD :: _) ze = snd uD ConD (_ :: uDs) (su c) = ConD uDs c data Data {l : Level}{I : Set l}(F : I -> Constrs I)(i : I) : Set l where _/_ : (u : Constr (F i))(d : [! ConD (F i) u !] (Data F)) -> Data F i {- DataD : {l : Level}{I : Set l} -> Constrs I -> Desc I DataD uDs = sg (Constr uDs) (ConD uDs) Data : {l : Level}{I : Set l}(F : I -> Constrs I)(i : I) -> Set l Data F = Mu _ \ i -> DataD (F i) -} MethodD : {l : Level}{I : Set l}(X : I -> Set l) (uDs : Constrs I) (P : Sg I X -> Set l) (i : I) -> ((u : Constr uDs)(d : [! ConD uDs u !] X) -> X i) -> Set l MethodD X [] P i c = One MethodD X ((u , D) :: uDs) P i c = ((d : [! D !] X) -> [! All D X d !] P -> P (i , c ze d)) * MethodD X uDs P i (\ u d -> c (su u) d) mutual induction : {l : Level}{I : Set l}{F : I -> Constrs I}{i : I}(x : Data F i) (P : Sg I (Data F) -> Set l) (ps : (i : I) -> MethodD (Data F) (F i) P i _/_) -> P (i , x) induction {F = F}{i = i}(u / d) P ps = indMethod P ps (F i) _/_ (ps i) u d indMethod : {l : Level}{I : Set l}{F : I -> Constrs I}{i : I} (P : Sg I (Data F) -> Set l) (ps : (i : I) -> MethodD (Data F) (F i) P i _/_) (uDs : Constrs I) (c : (u : Constr uDs) -> [! ConD uDs u !] (Data F) -> Data F i) (ms : MethodD (Data F) uDs P i c) (u : Constr uDs) (d : [! ConD uDs u !] (Data F)) -> P (i , c u d) indMethod P ps [] c ms () d indMethod P ps ((u , D) :: _) c (p , ms) ze d = p d (indHyps P ps D d) indMethod P ps ((_ , _) :: uDs) c (m , ms) (su u) d = indMethod P ps uDs _ ms u d indHyps : {l : Level}{I : Set l}{F : I -> Constrs I} (P : Sg I (Data F) -> Set l) (ps : (i : I) -> MethodD (Data F) (F i) P i _/_) (D : Desc I) (d : [! D !] (Data F)) -> [! All D (Data F) d !] P indHyps P ps (var i) x = induction x P ps indHyps P ps (con A) a = _ indHyps P ps (sg S T) (s , t) = indHyps P ps (T s) t indHyps P ps (pi S T) f = \ s -> indHyps P ps (T s) (f s) indHyps P ps (S ** T) (s , t) = indHyps P ps S s , indHyps P ps T t zi : {l : Level} -> UId {l} zi = ze si : {l : Level} -> UId {l} si = su ze data UQ {l : Level}(x : UId {l}) : UId {l} -> Set l where yes : UQ x x no : {y : UId {l}} -> UQ x y uq : {l : Level}(x y : UId {l}) -> UQ x y uq ze ze = yes uq ze (su y) = no uq (su x) ze = no uq (su x) (su y) with uq x y uq (su x) (su .x) | yes = yes uq (su x) (su y) | no = no UIn : {l : Level}(x : UId {l}) -> List (UId {l}) -> Set UIn x [] = Zero UIn x (y :: ys) with uq x y UIn x (.x :: _) | yes = One UIn x (_ :: ys) | no = UIn x ys uin : {l : Level}(x : UId {l})(ys : List (UId {l})) -> UIn x ys -> # ys uin x [] () uin x (y :: ys) p with uq x y uin x (.x :: _) _ | yes = ze uin x (_ :: ys) p | no = su (uin x ys p) _!_ : {l : Level}{I : Set l}{F : I -> Constrs I}{i : I} -> let us = map (\ uD -> down (fst uD)) (F i) in (u : UId {l}){p : UIn u us} -> [! ConD (F i) (uin u us p) !] (Data F) -> Data F i _!_ {l}{I}{F}{i} u {p} d = uin u (map (\ uD -> down (fst uD)) (F i)) p / d infixr 3 _!_ NAT : {l : Level} -> One {l} -> Constrs {l} One NAT _ = up zi , con One :: up si , var _ ** con One :: [] ZE : {l : Level} -> Data {l} NAT <> ZE = zi ! <> SU : {l : Level} -> Data {l} NAT <> -> Data {l} NAT <> SU n = si ! n , <> vari : {l : Level} -> UId {l} vari = ze coni : {l : Level} -> UId {l} coni = su ze sgi : {l : Level} -> UId {l} sgi = su (su ze) pii : {l : Level} -> UId {l} pii = su (su (su ze)) asti : {l : Level} -> UId {l} asti = su (su (su (su ze))) DESC : {l : Level}(I : Set l) -> One {su l} -> Constrs {su l} One DESC I _ = up vari , con (Up I) ** con One :: up coni , con (Set _) ** con One :: up sgi , (sg (Set _) \ S -> (pi (Up S) \ _ -> var _) ** con One) :: up pii , (sg (Set _) \ S -> (pi (Up S) \ _ -> var _) ** con One) :: up asti , var _ ** var _ ** con One :: []
{ "alphanum_fraction": 0.4347398204, "avg_line_length": 31.3861003861, "ext": "agda", "hexsha": "2a737abe9b8a45dc6913fa78fdf87ec9a513cdf0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:51:42.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:51:42.000Z", "max_forks_repo_head_hexsha": "17b7858f51a35b3becb8433028c3f1ba25fbba9a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dataronio/epigram2", "max_forks_repo_path": "models/LLev.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "17b7858f51a35b3becb8433028c3f1ba25fbba9a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dataronio/epigram2", "max_issues_repo_path": "models/LLev.agda", "max_line_length": 87, "max_stars_count": 4, "max_stars_repo_head_hexsha": "17b7858f51a35b3becb8433028c3f1ba25fbba9a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dataronio/epigram2", "max_stars_repo_path": "models/LLev.agda", "max_stars_repo_stars_event_max_datetime": "2015-11-05T01:06:39.000Z", "max_stars_repo_stars_event_min_datetime": "2015-02-23T15:00:26.000Z", "num_tokens": 3379, "size": 8129 }
postulate A : Set a : A data D : Set where d : D data E : Set where e₀ : E e₁ : E → E e₂ : E → E → E _[_] : E → E → E e₀ [ y ] = y e₁ x [ y ] = e₁ x e₂ x₁ x₂ [ y ] = e₂ (x₁ [ y ]) (x₂ [ y ]) data P : E → Set where p₁ : ∀ x₁ x₂ → P x₁ → P x₂ → P (e₂ x₁ x₂) p₂ : ∀ x → P (x [ e₁ x ]) → P (e₁ x) p₃ : ∀ x → P (e₁ x) module M (_ : A) where record R (A B : Set) : Set where field f : A → B instance r₁ : R D D R.f r₁ d = d open M a open R ⦃ … ⦄ public r₂ : R D E R.f r₂ d = e₀ instance r₃ : {A : Set} ⦃ c : R A D ⦄ → R A E R.f (r₃ ⦃ c ⦄) x = R.f r₂ (R.f c x) f′ : {A : Set} ⦃ c : R A D ⦄ → A → E f′ = f postulate p : {A : Set} ⦃ c : R A D ⦄ (x : A) → P (f′ x) rejected : P (e₂ (e₁ e₀) (f d)) rejected = p₁ _ (f′ d) (p₂ _ (p₃ e₀)) (p d)
{ "alphanum_fraction": 0.4240903388, "avg_line_length": 15.0377358491, "ext": "agda", "hexsha": "005ba43879ccd647cff1652a25bf401487055e5c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue2296b.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue2296b.agda", "max_line_length": 48, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue2296b.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 419, "size": 797 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Semi-heterogeneous vector equality ------------------------------------------------------------------------ module Data.Vec.Equality where open import Data.Vec open import Data.Nat using (suc) open import Function open import Level using (_⊔_) open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) module Equality {s₁ s₂} (S : Setoid s₁ s₂) where private open module SS = Setoid S using () renaming (_≈_ to _≊_; Carrier to A) infix 4 _≈_ data _≈_ : ∀ {n¹} → Vec A n¹ → ∀ {n²} → Vec A n² → Set (s₁ ⊔ s₂) where []-cong : [] ≈ [] _∷-cong_ : ∀ {x¹ n¹} {xs¹ : Vec A n¹} {x² n²} {xs² : Vec A n²} (x¹≈x² : x¹ ≊ x²) (xs¹≈xs² : xs¹ ≈ xs²) → x¹ ∷ xs¹ ≈ x² ∷ xs² length-equal : ∀ {n¹} {xs¹ : Vec A n¹} {n²} {xs² : Vec A n²} → xs¹ ≈ xs² → n¹ ≡ n² length-equal []-cong = P.refl length-equal (_ ∷-cong eq₂) = P.cong suc $ length-equal eq₂ refl : ∀ {n} (xs : Vec A n) → xs ≈ xs refl [] = []-cong refl (x ∷ xs) = SS.refl ∷-cong refl xs sym : ∀ {n m} {xs : Vec A n} {ys : Vec A m} → xs ≈ ys → ys ≈ xs sym []-cong = []-cong sym (x¹≡x² ∷-cong xs¹≈xs²) = SS.sym x¹≡x² ∷-cong sym xs¹≈xs² trans : ∀ {n m l} {xs : Vec A n} {ys : Vec A m} {zs : Vec A l} → xs ≈ ys → ys ≈ zs → xs ≈ zs trans []-cong []-cong = []-cong trans (x≈y ∷-cong xs≈ys) (y≈z ∷-cong ys≈zs) = SS.trans x≈y y≈z ∷-cong trans xs≈ys ys≈zs _++-cong_ : ∀ {n₁¹ n₂¹} {xs₁¹ : Vec A n₁¹} {xs₂¹ : Vec A n₂¹} {n₁² n₂²} {xs₁² : Vec A n₁²} {xs₂² : Vec A n₂²} → xs₁¹ ≈ xs₁² → xs₂¹ ≈ xs₂² → xs₁¹ ++ xs₂¹ ≈ xs₁² ++ xs₂² []-cong ++-cong eq₃ = eq₃ (eq₁ ∷-cong eq₂) ++-cong eq₃ = eq₁ ∷-cong (eq₂ ++-cong eq₃) module DecidableEquality {d₁ d₂} (D : DecSetoid d₁ d₂) where private module DS = DecSetoid D open DS using () renaming (_≟_ to _≟′_ ; Carrier to A) open Equality DS.setoid open import Relation.Nullary _≟_ : ∀ {n m} (xs : Vec A n) (ys : Vec A m) → Dec (xs ≈ ys) _≟_ [] [] = yes []-cong _≟_ [] (y ∷ ys) = no (λ()) _≟_ (x ∷ xs) [] = no (λ()) _≟_ (x ∷ xs) (y ∷ ys) with xs ≟ ys | x ≟′ y ... | yes xs≈ys | yes x≊y = yes (x≊y ∷-cong xs≈ys) ... | no ¬xs≈ys | _ = no helper where helper : ¬ (x ∷ xs ≈ y ∷ ys) helper (_ ∷-cong xs≈ys) = ¬xs≈ys xs≈ys ... | _ | no ¬x≊y = no helper where helper : ¬ (x ∷ xs ≈ y ∷ ys) helper (x≊y ∷-cong _) = ¬x≊y x≊y module PropositionalEquality {a} {A : Set a} where open Equality (P.setoid A) public to-≡ : ∀ {n} {xs ys : Vec A n} → xs ≈ ys → xs ≡ ys to-≡ []-cong = P.refl to-≡ (P.refl ∷-cong xs¹≈xs²) = P.cong (_∷_ _) $ to-≡ xs¹≈xs² from-≡ : ∀ {n} {xs ys : Vec A n} → xs ≡ ys → xs ≈ ys from-≡ P.refl = refl _
{ "alphanum_fraction": 0.4715984148, "avg_line_length": 32.9130434783, "ext": "agda", "hexsha": "04f58b6b09fc89acf8d0456087800d067d1e81fb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Data/Vec/Equality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Data/Vec/Equality.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/Vec/Equality.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 1282, "size": 3028 }
open import Agda.Builtin.Nat open import Agda.Builtin.Strict foo : Nat → Nat foo n = primForce (n + n) (λ _ → 0) -- Don't get rid of the seq!
{ "alphanum_fraction": 0.64, "avg_line_length": 18.75, "ext": "agda", "hexsha": "01c6495638b5a1c20a455a3e269cc3fc95118c8e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue2908.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue2908.agda", "max_line_length": 35, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue2908.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 51, "size": 150 }
module Lec6 where open import CS410-Prelude open import CS410-Functor open import CS410-Monoid open import CS410-Nat data Maybe (X : Set) : Set where yes : X -> Maybe X no : Maybe X maybeFunctor : Functor Maybe maybeFunctor = record { map = \ { f (yes x) -> yes (f x) ; f no -> no } ; mapid = \ { (yes x) -> refl ; no -> refl } ; mapcomp = \ { f g (yes x) -> refl ; f g no -> refl } } open Functor maybeFunctor data List (X : Set) : Set where -- X scopes over the whole declaration... [] : List X -- ...so you can use it here... _::_ : X -> List X -> List X -- ...and here. infixr 3 _::_ may-take : {X : Set} -> Nat -> List X -> Maybe (List X) may-take zero xs = yes [] may-take (suc n) [] = no may-take (suc n) (x :: xs) = map (_::_ x) (may-take n xs) data Hutton : Set where val : Nat -> Hutton _+H_ : Hutton -> Hutton -> Hutton fail : Hutton maybeApplicative : Applicative Maybe maybeApplicative = record { pure = yes ; _<*>_ = \ { no mx -> no ; (yes f) no -> no ; (yes f) (yes x) -> yes (f x) } ; identity = \ {(yes x) -> refl ; no -> refl} ; composition = \ { (yes f) (yes g) (yes x) -> refl ; (yes f) (yes g) no -> refl ; (yes x) no mx -> refl ; no mg mx -> refl } ; homomorphism = \ f x -> refl ; interchange = \ { (yes f) y -> refl ; no y → refl } } module Eval where open Applicative maybeApplicative public eval : Hutton -> Maybe Nat eval (val x) = yes x eval (h +H h') = pure _+N_ <*> eval h <*> eval h' eval fail = no listTrav : forall {F} -> Applicative F -> forall {A B} -> (A -> F B) -> List A -> F (List B) listTrav {F} appF = trav where open Applicative appF trav : forall {A B} -> (A -> F B) -> List A -> F (List B) trav f [] = pure [] trav f (a :: as) = pure _::_ <*> f a <*> trav f as listTraversable : Traversable List listTraversable = record { traverse = listTrav } I : Set -> Set I X = X iApplicative : Applicative I iApplicative = record { pure = id ; _<*>_ = id ; identity = \ v -> refl ; composition = \ f g v -> refl ; homomorphism = \ f x -> refl ; interchange = \ u y -> refl } lmap : forall {A B} -> (A -> B) -> List A -> List B lmap = traverse iApplicative where open Traversable listTraversable MonCon : forall {X} -> Monoid X -> Applicative \_ -> X MonCon M = record { pure = {!!} ; _<*>_ = op ; identity = {!!} ; composition = {!!} ; homomorphism = {!!} ; interchange = {!!} } where open Monoid M lCombine : forall {A X} -> Monoid X -> (A -> X) -> List A -> X lCombine M = traverse (MonCon M) {B = One} where open Traversable listTraversable CurryApplicative : forall {E} -> Applicative \X -> E -> X CurryApplicative = record { pure = \ x e -> x -- K ; _<*>_ = \ ef ex e -> ef e (ex e) -- S ; identity = λ {X} v → refl ; composition = λ {X} {Y} {Z} u v w → refl ; homomorphism = λ {X} {Y} f x → refl ; interchange = λ {X} {Y} u y → refl }
{ "alphanum_fraction": 0.459406495, "avg_line_length": 30.5299145299, "ext": "agda", "hexsha": "988884cdb49fe34a5784330fdf08e6de3fa9adfe", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "clarkdm/CS410", "max_forks_repo_path": "Lec6.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "clarkdm/CS410", "max_issues_repo_path": "Lec6.agda", "max_line_length": 74, "max_stars_count": null, "max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "clarkdm/CS410", "max_stars_repo_path": "Lec6.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1047, "size": 3572 }
module Issue4267.A0 where record RA0 : Set₁ where field A : Set
{ "alphanum_fraction": 0.6901408451, "avg_line_length": 11.8333333333, "ext": "agda", "hexsha": "4afa2fbc13e35892d57703c71473c3561d3fa59b", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue4267/A0.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue4267/A0.agda", "max_line_length": 25, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4267/A0.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 24, "size": 71 }
{-# OPTIONS --cubical --no-import-sorts #-} module Number.InclusionModules where import Number.Postulates import Number.Inclusions -- NOTE: the following takes a very long time to typecheck -- see https://lists.chalmers.se/pipermail/agda-dev/2015-September/000201.html -- see https://github.com/agda/agda/issues/1646 -- Exponential module chain leads to infeasible scope checking module Isℕ↪ℤ = Number.Inclusions.IsROrderedCommSemiringInclusion Number.Postulates.ℕ↪ℤinc module Isℕ↪ℚ = Number.Inclusions.IsROrderedCommSemiringInclusion Number.Postulates.ℕ↪ℚinc module Isℕ↪ℂ = Number.Inclusions.Isℕ↪ℂ Number.Postulates.ℕ↪ℂinc module Isℕ↪ℝ = Number.Inclusions.IsROrderedCommSemiringInclusion Number.Postulates.ℕ↪ℝinc module Isℤ↪ℚ = Number.Inclusions.IsROrderedCommRingInclusion Number.Postulates.ℤ↪ℚinc module Isℤ↪ℝ = Number.Inclusions.IsROrderedCommRingInclusion Number.Postulates.ℤ↪ℝinc module Isℤ↪ℂ = Number.Inclusions.Isℤ↪ℂ Number.Postulates.ℤ↪ℂinc module Isℚ↪ℝ = Number.Inclusions.IsROrderedFieldInclusion Number.Postulates.ℚ↪ℝinc module Isℚ↪ℂ = Number.Inclusions.IsRFieldInclusion Number.Postulates.ℚ↪ℂinc module Isℝ↪ℂ = Number.Inclusions.IsRFieldInclusion Number.Postulates.ℝ↪ℂinc {- -- NOTE: the following is a little faster but does not help us module Isℕ↪ℤ = Number.Inclusions.IsROrderedCommSemiringInclusion module Isℕ↪ℚ = Number.Inclusions.IsROrderedCommSemiringInclusion module Isℕ↪ℂ = Number.Inclusions.Isℕ↪ℂ module Isℕ↪ℝ = Number.Inclusions.IsROrderedCommSemiringInclusion module Isℤ↪ℚ = Number.Inclusions.IsROrderedCommRingInclusion module Isℤ↪ℝ = Number.Inclusions.IsROrderedCommRingInclusion module Isℤ↪ℂ = Number.Inclusions.Isℤ↪ℂ module Isℚ↪ℝ = Number.Inclusions.IsROrderedFieldInclusion module Isℚ↪ℂ = Number.Inclusions.IsRFieldInclusion module Isℝ↪ℂ = Number.Inclusions.IsRFieldInclusion -}
{ "alphanum_fraction": 0.7842215256, "avg_line_length": 50.3684210526, "ext": "agda", "hexsha": "185e4d553236541997fc5b066df92f784b13ded5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_path": "agda/Number/InclusionModules.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_path": "agda/Number/InclusionModules.agda", "max_line_length": 89, "max_stars_count": 3, "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_path": "agda/Number/InclusionModules.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "num_tokens": 653, "size": 1914 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Conversion of binary operators to binary relations via the right -- natural order. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary open import Algebra.FunctionProperties using (Op₂) module Relation.Binary.Construct.NaturalOrder.Right {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) (_∙_ : Op₂ A) where open import Data.Product using (_,_; _×_) open import Data.Sum using (inj₁; inj₂) open import Relation.Nullary using (¬_) open import Algebra.FunctionProperties _≈_ open import Algebra.Structures _≈_ import Relation.Binary.Reasoning.Setoid as EqReasoning ------------------------------------------------------------------------ -- Definition infix 4 _≤_ _≤_ : Rel A ℓ x ≤ y = x ≈ (y ∙ x) ------------------------------------------------------------------------ -- Relational properties reflexive : IsMagma _∙_ → Idempotent _∙_ → _≈_ ⇒ _≤_ reflexive magma idem {x} {y} x≈y = begin x ≈⟨ sym (idem x) ⟩ x ∙ x ≈⟨ ∙-cong x≈y refl ⟩ y ∙ x ∎ where open IsMagma magma; open EqReasoning setoid refl : Symmetric _≈_ → Idempotent _∙_ → Reflexive _≤_ refl sym idem {x} = sym (idem x) antisym : IsEquivalence _≈_ → Commutative _∙_ → Antisymmetric _≈_ _≤_ antisym isEq comm {x} {y} x≤y y≤x = begin x ≈⟨ x≤y ⟩ y ∙ x ≈⟨ comm y x ⟩ x ∙ y ≈⟨ sym y≤x ⟩ y ∎ where open IsEquivalence isEq; open EqReasoning (record { isEquivalence = isEq }) total : Symmetric _≈_ → Transitive _≈_ → Selective _∙_ → Commutative _∙_ → Total _≤_ total sym trans sel comm x y with sel x y ... | inj₁ x∙y≈x = inj₁ (trans (sym x∙y≈x) (comm x y) ) ... | inj₂ x∙y≈y = inj₂ (sym x∙y≈y) trans : IsSemigroup _∙_ → Transitive _≤_ trans semi {x} {y} {z} x≤y y≤z = begin x ≈⟨ x≤y ⟩ y ∙ x ≈⟨ ∙-cong y≤z S.refl ⟩ (z ∙ y) ∙ x ≈⟨ assoc z y x ⟩ z ∙ (y ∙ x) ≈⟨ ∙-cong S.refl (sym x≤y) ⟩ z ∙ x ∎ where open module S = IsSemigroup semi; open EqReasoning S.setoid respʳ : IsMagma _∙_ → _≤_ Respectsʳ _≈_ respʳ magma {x} {y} {z} y≈z x≤y = begin x ≈⟨ x≤y ⟩ y ∙ x ≈⟨ ∙-cong y≈z M.refl ⟩ z ∙ x ∎ where open module M = IsMagma magma; open EqReasoning M.setoid respˡ : IsMagma _∙_ → _≤_ Respectsˡ _≈_ respˡ magma {x} {y} {z} y≈z y≤x = begin z ≈⟨ sym y≈z ⟩ y ≈⟨ y≤x ⟩ x ∙ y ≈⟨ ∙-cong M.refl y≈z ⟩ x ∙ z ∎ where open module M = IsMagma magma; open EqReasoning M.setoid resp₂ : IsMagma _∙_ → _≤_ Respects₂ _≈_ resp₂ magma = respʳ magma , respˡ magma dec : Decidable _≈_ → Decidable _≤_ dec _≟_ x y = x ≟ (y ∙ x) ------------------------------------------------------------------------ -- Structures isPreorder : IsBand _∙_ → IsPreorder _≈_ _≤_ isPreorder band = record { isEquivalence = isEquivalence ; reflexive = reflexive isMagma idem ; trans = trans isSemigroup } where open IsBand band hiding (reflexive; trans) isPartialOrder : IsSemilattice _∙_ → IsPartialOrder _≈_ _≤_ isPartialOrder semilattice = record { isPreorder = isPreorder isBand ; antisym = antisym isEquivalence comm } where open IsSemilattice semilattice isDecPartialOrder : IsSemilattice _∙_ → Decidable _≈_ → IsDecPartialOrder _≈_ _≤_ isDecPartialOrder semilattice _≟_ = record { isPartialOrder = isPartialOrder semilattice ; _≟_ = _≟_ ; _≤?_ = dec _≟_ } isTotalOrder : IsSemilattice _∙_ → Selective _∙_ → IsTotalOrder _≈_ _≤_ isTotalOrder latt sel = record { isPartialOrder = isPartialOrder latt ; total = total sym S.trans sel comm } where open module S = IsSemilattice latt isDecTotalOrder : IsSemilattice _∙_ → Selective _∙_ → Decidable _≈_ → IsDecTotalOrder _≈_ _≤_ isDecTotalOrder latt sel _≟_ = record { isTotalOrder = isTotalOrder latt sel ; _≟_ = _≟_ ; _≤?_ = dec _≟_ } ------------------------------------------------------------------------ -- Packages preorder : IsBand _∙_ → Preorder a ℓ ℓ preorder band = record { isPreorder = isPreorder band } poset : IsSemilattice _∙_ → Poset a ℓ ℓ poset latt = record { isPartialOrder = isPartialOrder latt } decPoset : IsSemilattice _∙_ → Decidable _≈_ → DecPoset a ℓ ℓ decPoset latt dec = record { isDecPartialOrder = isDecPartialOrder latt dec } totalOrder : IsSemilattice _∙_ → Selective _∙_ → TotalOrder a ℓ ℓ totalOrder latt sel = record { isTotalOrder = isTotalOrder latt sel } decTotalOrder : IsSemilattice _∙_ → Selective _∙_ → Decidable _≈_ → DecTotalOrder a ℓ ℓ decTotalOrder latt sel dec = record { isDecTotalOrder = isDecTotalOrder latt sel dec }
{ "alphanum_fraction": 0.5888108913, "avg_line_length": 30.1346153846, "ext": "agda", "hexsha": "533771dccc4dfa989c36c7d272f03d89fed9ad1b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NaturalOrder/Right.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NaturalOrder/Right.agda", "max_line_length": 84, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/NaturalOrder/Right.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1724, "size": 4701 }
-- Andreas, 2011-10-06 module Issue483b where data _≡_ {A : Set}(a : A) : A → Set where refl : a ≡ a postulate A : Set f : .A → A test : let X : .A → A X = _ in .(x : A) → X (f x) ≡ f x test x = refl -- this gave an internal error before because X _ = f x -- was solved by X = λ _ → f __IMPOSSIBLE__ -- -- Now one should get an unsolved meta
{ "alphanum_fraction": 0.5582655827, "avg_line_length": 20.5, "ext": "agda", "hexsha": "ac70d3a7c1c1678d05faaffdbefa64a3a8338127", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/Issue483b.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/Issue483b.agda", "max_line_length": 55, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/Issue483b.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 139, "size": 369 }
{- USES WITH -} {- A simple bidirectional type checker for simply typed lambda calculus which is sound by construction. -} module SimpleTypes where infix 10 _==_ data _==_ {A : Set}(x : A) : A -> Set where refl : x == x data Maybe (A : Set) : Set where nothing : Maybe A just : A -> Maybe A data Nat : Set where zero : Nat suc : Nat -> Nat data Fin : Nat -> Set where fzero : {n : Nat} -> Fin (suc n) fsuc : {n : Nat} -> Fin n -> Fin (suc n) data List (A : Set) : Set where ε : List A _,_ : List A -> A -> List A length : forall {A} -> List A -> Nat length ε = zero length (xs , x) = suc (length xs) infixl 25 _,_ -- Raw terms data Expr : Set where varʳ : Nat -> Expr _•ʳ_ : Expr -> Expr -> Expr ƛʳ_ : Expr -> Expr infixl 90 _•ʳ_ infix 50 ƛʳ_ -- Types data Type : Set where ι : Type _⟶_ : Type -> Type -> Type infixr 40 _⟶_ -- Typed terms Ctx = List Type data Var : Ctx -> Type -> Set where vz : forall {Γ τ} -> Var (Γ , τ) τ vs : forall {Γ τ σ} -> Var Γ τ -> Var (Γ , σ) τ data Term : Ctx -> Type -> Set where var : forall {Γ τ} -> Var Γ τ -> Term Γ τ _•_ : forall {Γ τ σ} -> Term Γ (τ ⟶ σ) -> Term Γ τ -> Term Γ σ ƛ_ : forall {Γ τ σ} -> Term (Γ , σ) τ -> Term Γ (σ ⟶ τ) infixl 90 _•_ infix 50 ƛ_ -- Type erasure ⌊_⌋ˣ : forall {Γ τ} -> Var Γ τ -> Nat ⌊ vz ⌋ˣ = zero ⌊ vs x ⌋ˣ = suc ⌊ x ⌋ˣ ⌊_⌋ : forall {Γ τ} -> Term Γ τ -> Expr ⌊ var v ⌋ = varʳ ⌊ v ⌋ˣ ⌊ s • t ⌋ = ⌊ s ⌋ •ʳ ⌊ t ⌋ ⌊ ƛ t ⌋ = ƛʳ ⌊ t ⌋ -- Type equality infix 30 _≟_ _≟_ : (σ τ : Type) -> Maybe (σ == τ) ι ≟ ι = just refl σ₁ ⟶ τ₁ ≟ σ₂ ⟶ τ₂ with σ₁ ≟ σ₂ | τ₁ ≟ τ₂ σ ⟶ τ ≟ .σ ⟶ .τ | just refl | just refl = just refl _ ⟶ _ ≟ _ ⟶ _ | _ | _ = nothing _ ≟ _ = nothing -- The type checked view -- ok : forall {Γ τ e} -> Check ⌊ e ⌋ -- unsolved metas with no range! data Check (Γ : Ctx)(τ : Type) : Expr -> Set where ok : (t : Term Γ τ) -> Check Γ τ ⌊ t ⌋ bad : {e : Expr} -> Check Γ τ e data Infer (Γ : Ctx) : Expr -> Set where yes : (τ : Type)(t : Term Γ τ) -> Infer Γ ⌊ t ⌋ no : {e : Expr} -> Infer Γ e data Lookup (Γ : Ctx) : Nat -> Set where found : (τ : Type)(x : Var Γ τ) -> Lookup Γ ⌊ x ⌋ˣ outofscope : {n : Nat} -> Lookup Γ n lookup : (Γ : Ctx)(n : Nat) -> Lookup Γ n lookup ε n = outofscope lookup (Γ , τ) zero = found τ vz lookup (Γ , σ) (suc n) with lookup Γ n lookup (Γ , σ) (suc .(⌊ x ⌋ˣ)) | found τ x = found τ (vs x) lookup (Γ , σ) (suc n) | outofscope = outofscope infix 20 _⊢_∋_ _⊢_∈ _⊢_∈ : (Γ : Ctx)(e : Expr) -> Infer Γ e _⊢_∋_ : (Γ : Ctx)(τ : Type)(e : Expr) -> Check Γ τ e Γ ⊢ ι ∋ ƛʳ e = bad Γ ⊢ (σ ⟶ τ) ∋ ƛʳ e with Γ , σ ⊢ τ ∋ e Γ ⊢ (σ ⟶ τ) ∋ ƛʳ .(⌊ t ⌋) | ok t = ok (ƛ t) Γ ⊢ (σ ⟶ τ) ∋ ƛʳ _ | bad = bad Γ ⊢ τ ∋ e with Γ ⊢ e ∈ Γ ⊢ τ ∋ .(⌊ t ⌋) | yes σ t with τ ≟ σ Γ ⊢ τ ∋ .(⌊ t ⌋) | yes .τ t | just refl = ok t Γ ⊢ τ ∋ .(⌊ t ⌋) | yes σ t | nothing = bad Γ ⊢ τ ∋ e | no = bad Γ ⊢ varʳ i ∈ with lookup Γ i Γ ⊢ varʳ .(⌊ x ⌋ˣ) ∈ | found τ x = yes τ (var x) Γ ⊢ varʳ _ ∈ | outofscope = no Γ ⊢ e₁ •ʳ e₂ ∈ with Γ ⊢ e₁ ∈ Γ ⊢ e₁ •ʳ e₂ ∈ | no = no Γ ⊢ .(⌊ t₁ ⌋) •ʳ e₂ ∈ | yes ι t₁ = no Γ ⊢ .(⌊ t₁ ⌋) •ʳ e₂ ∈ | yes (σ ⟶ τ) t₁ with Γ ⊢ σ ∋ e₂ Γ ⊢ .(⌊ t₁ ⌋) •ʳ .(⌊ t₂ ⌋) ∈ | yes (σ ⟶ τ) t₁ | ok t₂ = yes τ (t₁ • t₂) Γ ⊢ .(⌊ t₁ ⌋) •ʳ _ ∈ | yes (σ ⟶ τ) t₁ | bad = no Γ ⊢ ƛʳ e ∈ = no -- Proving completeness (for normal terms) -- Needs magic with {- mutual data Nf : forall {Γ τ} -> Term Γ τ -> Set where ƛ-nf : forall {Γ σ τ} -> {t : Term (Γ , σ) τ} -> Nf t -> Nf (ƛ t) ne-nf : forall {Γ τ} -> {t : Term Γ τ} -> Ne t -> Nf t data Ne : forall {Γ τ} -> Term Γ τ -> Set where •-ne : forall {Γ σ τ} -> {t₁ : Term Γ (σ ⟶ τ)} -> Ne t₁ -> {t₂ : Term Γ σ} -> Nf t₂ -> Ne (t₁ • t₂) var-ne : forall {Γ τ} -> {x : Var Γ τ} -> Ne (var x) mutual complete-check : forall {Γ τ} -> (t : Term Γ τ) -> Nf t -> Γ ⊢ τ ∋ ⌊ t ⌋ == ok t complete-check ._ (ƛ-nf t) = {! !} complete-check _ (ne-nf n) with complete-infer _ n complete-check t (ne-nf n) | p = {! !} complete-infer : forall {Γ τ} -> (t : Term Γ τ) -> Ne t -> Γ ⊢ ⌊ t ⌋ ∈ == yes τ t complete-infer t ne = {! !} -} -- Testing test1 = ε ⊢ ι ⟶ ι ∋ ƛʳ varʳ zero test2 = ε , ι , ι ⟶ ι ⊢ varʳ zero •ʳ varʳ (suc zero) ∈
{ "alphanum_fraction": 0.4784885044, "avg_line_length": 24.8192090395, "ext": "agda", "hexsha": "a8f2da37c342148d5072e87f5b6c7c7e8b91c6cf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejtokarcik/agda-semantics", "max_forks_repo_path": "tests/beyond/SimpleTypes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejtokarcik/agda-semantics", "max_issues_repo_path": "tests/beyond/SimpleTypes.agda", "max_line_length": 79, "max_stars_count": 3, "max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andrejtokarcik/agda-semantics", "max_stars_repo_path": "tests/beyond/SimpleTypes.agda", "max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z", "num_tokens": 2086, "size": 4393 }
module Prelude.Applicative.Indexed {i} {I : Set i} where open import Agda.Primitive open import Prelude.Unit open import Prelude.Functor open import Prelude.Function open import Prelude.Equality open import Prelude.Number open import Prelude.Semiring open import Prelude.Fractional record IApplicative {a b} (F : I → I → Set a → Set b) : Set (i ⊔ lsuc a ⊔ b) where infixl 4 _<*>_ _<*_ _*>_ field pure : ∀ {A i} → A → F i i A _<*>_ : ∀ {A B i j k} → F i j (A → B) → F j k A → F i k B overlap {{super}} : ∀ {i j} → Functor (F i j) _<*_ : ∀ {A B i j k} → F i j A → F j k B → F i k A a <* b = ⦇ const a b ⦈ _*>_ : ∀ {A B i j k} → F i j A → F j k B → F i k B a *> b = ⦇ (const id) a b ⦈ open IApplicative {{...}} public {-# DISPLAY IApplicative.pure _ = pure #-} {-# DISPLAY IApplicative._<*>_ _ = _<*>_ #-} {-# DISPLAY IApplicative._<*_ _ = _<*_ #-} {-# DISPLAY IApplicative._*>_ _ = _*>_ #-} -- Level polymorphic functors record IApplicative′ {a b} (F : ∀ {a} → I → I → Set a → Set a) : Set (i ⊔ lsuc (a ⊔ b)) where infixl 4 _<*>′_ field _<*>′_ : {A : Set a} {B : Set b} {i j k : I} → F i j (A → B) → F j k A → F i k B overlap {{super}} : ∀ {i j} → Functor′ {a} {b} (F i j) open IApplicative′ {{...}} public module _ {F : ∀ {a} → I → I → Set a → Set a} {{_ : ∀ {a} → IApplicative {a = a} F}} {{_ : ∀ {a b} → IApplicative′ {a = a} {b = b} F}} {a b} {A : Set a} {B : Set b} {i j k} where infixl 4 _<*′_ _*>′_ _<*′_ : F i j A → F j k B → F i k A a <*′ b = pure const <*>′ a <*>′ b _*>′_ : F i j A → F j k B → F i k B a *>′ b = pure (const id) <*>′ a <*>′ b
{ "alphanum_fraction": 0.5106512477, "avg_line_length": 31, "ext": "agda", "hexsha": "e18439020520e0fe2cd7c139b4439d8498819b1a", "lang": "Agda", "max_forks_count": 24, "max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z", "max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z", "max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_path": "src/Prelude/Applicative/Indexed.agda", "max_issues_count": 59, "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z", "max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "t-more/agda-prelude", "max_issues_repo_path": "src/Prelude/Applicative/Indexed.agda", "max_line_length": 93, "max_stars_count": 111, "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_path": "src/Prelude/Applicative/Indexed.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z", "num_tokens": 672, "size": 1643 }
------------------------------------------------------------------------ -- A very brief treatment of different kinds of term equivalences, -- including contextual equivalence and applicative bisimilarity ------------------------------------------------------------------------ module Lambda.Closure.Equivalences where open import Category.Monad.Partiality as Partiality using (_⊥; later⁻¹; laterˡ⁻¹; laterʳ⁻¹) open import Codata.Musical.Notation open import Data.Fin using (Fin; zero) open import Data.Maybe hiding (_>>=_) open import Data.Maybe.Relation.Binary.Pointwise as Maybe using (just; nothing) open import Data.Nat open import Data.Product as Prod open import Data.Unit open import Data.Vec using ([]; _∷_) open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (_⇔_; equivalence; module Equivalence) open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary open Partiality._⊥ private open module EP {A : Set} = Partiality.Equality (_≡_ {A = A}) open module RP {A : Set} = Partiality.Reasoning (P.isEquivalence {A = A}) open module RC {A : Set} = Partiality.Reasoning {_∼_ = λ (_ _ : A) → ⊤} _ using () renaming (_≈⟨_⟩_ to _≈○⟨_⟩_; _∎ to _∎○) open import Lambda.Closure.Functional open PF using (return; _>>=_; fail) open import Lambda.Syntax open Closure Tm ------------------------------------------------------------------------ -- Two equivalent notions of equivalence of partial values -- _≈○_ is a notion of weak bisimilarity which identifies all values. open module EC {A : Set} = Partiality.Equality (λ (_ _ : A) → ⊤) using () renaming (_≈_ to _≈○_) -- _≈○_ is equivalent to "terminates iff terminates". ≈○⇔⇓≈⇓ : {A : Set} {x y : A ⊥} → x ≈○ y ⇔ (x ⇓ ⇔ y ⇓) ≈○⇔⇓≈⇓ {A} = equivalence (λ x≈y → equivalence (h₁ x≈y) (h₁ (RC.sym x≈y))) (h₂ _ _) where h₁ : {x y : A ⊥} → x ≈○ y → x ⇓ → y ⇓ h₁ (EC.now _) (v , now P.refl) = -, now P.refl h₁ (EC.later x≈y) (v , laterˡ x⇓v) = Prod.map id laterˡ $ h₁ (♭ x≈y) (v , x⇓v) h₁ (EC.laterʳ x≈y) (v , x⇓v) = Prod.map id laterˡ $ h₁ x≈y (v , x⇓v) h₁ (EC.laterˡ x≈y) (v , laterˡ x⇓v) = h₁ x≈y (v , x⇓v) h₂ : (x y : A ⊥) → x ⇓ ⇔ y ⇓ → x ≈○ y h₂ (now v) y x⇓⇔y⇓ = now v ≈○⟨ EC.now _ ⟩ now _ ≈○⟨ Partiality.map _ (sym $ proj₂ $ Equivalence.to x⇓⇔y⇓ ⟨$⟩ (-, now P.refl)) ⟩ y ∎○ h₂ x (now v) x⇓⇔y⇓ = x ≈○⟨ Partiality.map _ ( proj₂ $ Equivalence.from x⇓⇔y⇓ ⟨$⟩ (-, now P.refl)) ⟩ now _ ≈○⟨ EC.now _ ⟩ now v ∎○ h₂ (later x) (later y) x⇓⇔y⇓ = EC.later (♯ h₂ (♭ x) (♭ y) (equivalence (lemma (_⟨$⟩_ (Equivalence.to x⇓⇔y⇓))) (lemma (_⟨$⟩_ (Equivalence.from x⇓⇔y⇓))))) where lemma : {A : Set} {x y : ∞ (A ⊥)} → (later x ⇓ → later y ⇓) → (♭ x ⇓ → ♭ y ⇓) lemma hyp (v , x⇓) = Prod.map id laterˡ⁻¹ $ hyp (v , laterˡ x⇓) ------------------------------------------------------------------------ -- Two equivalent definitions of contextual equivalence -- Context m n consists of contexts with zero or more holes. The holes -- expect terms of type Tm m, and if we fill those holes we get a term -- of type Tm n. infixl 9 _·_ data Context (m : ℕ) : ℕ → Set where • : Context m m con : ∀ {n} (i : ℕ) → Context m n var : ∀ {n} (x : Fin n) → Context m n ƛ : ∀ {n} (C : Context m (suc n)) → Context m n _·_ : ∀ {n} (C₁ C₂ : Context m n) → Context m n -- Fills all the holes. infix 10 _[_] _[_] : ∀ {m n} → Context m n → Tm m → Tm n • [ t ] = t con i [ t ] = con i var x [ t ] = var x ƛ C [ t ] = ƛ (C [ t ]) (C₁ · C₂) [ t ] = C₁ [ t ] · C₂ [ t ] -- Contextual equivalence. -- -- Termination is the only observation. This is perhaps a bit strange: -- there is no way to observe the difference between con i and con j -- for i ≢ j. infix 4 _≈C_ _≈C_ : ∀ {n} → Tm n → Tm n → Set t₁ ≈C t₂ = ∀ C → ⟦ C [ t₁ ] ⟧ [] ≈○ ⟦ C [ t₂ ] ⟧ [] -- Alternative definition of contextual equivalence. infix 4 _≈C′_ _≈C′_ : ∀ {n} → Tm n → Tm n → Set t₁ ≈C′ t₂ = ∀ C → ⟦ C [ t₁ ] ⟧ [] ⇓ ⇔ ⟦ C [ t₂ ] ⟧ [] ⇓ -- These definitions are equivalent. ≈C⇔≈C′ : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈C t₂ ⇔ t₁ ≈C′ t₂ ≈C⇔≈C′ = equivalence (λ t₁≈t₂ C → Equivalence.to ≈○⇔⇓≈⇓ ⟨$⟩ t₁≈t₂ C) (λ t₁≈t₂ C → Equivalence.from ≈○⇔⇓≈⇓ ⟨$⟩ t₁≈t₂ C) ------------------------------------------------------------------------ -- A very strict term equivalence -- A term equivalence defined directly on top of the semantics. infix 4 _≈!_ _≈!_ : ∀ {n} → Tm n → Tm n → Set t₁ ≈! t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈ ⟦ t₂ ⟧ ρ -- This equivalence is not compatible. -- -- Note that the proof does not use constants (con). ¬-compatible : ¬ ((t₁ t₂ : Tm 1) → t₁ ≈! t₂ → ƛ t₁ ≈! ƛ t₂) ¬-compatible ƛ-cong with ƛ-cong (ƛ (vr 1) · ƛ (ƛ (vr 0))) (ƛ (vr 1) · ƛ (vr 0)) (λ _ → later (♯ now P.refl)) [] ... | now () ------------------------------------------------------------------------ -- Incorrect definition of applicative bisimilarity -- The difference between this definition and the one below is that in -- this definition ƛ is inductive rather than coinductive. module Incorrect where infix 4 _≈mv_ _≈v_ -- _≈mv_, _≈c_ and _≈v_ are defined mutually (coinductively). data _≈v_ : Value → Value → Set -- Equivalence of possibly exceptional values. _≈mv_ : Maybe Value → Maybe Value → Set _≈mv_ = Maybe.Pointwise _≈v_ -- Equivalence of computations. open module EA = Partiality.Equality _≈mv_ using () renaming (_≈_ to _≈c_) -- Equivalence of values. data _≈v_ where con : ∀ {i} → con i ≈v con i ƛ : ∀ {n₁} {t₁ : Tm (1 + n₁)} {ρ₁} {n₂} {t₂ : Tm (1 + n₂)} {ρ₂} (t₁≈t₂ : ∀ v → ⟦ t₁ ⟧ (v ∷ ρ₁) ≈c ⟦ t₂ ⟧ (v ∷ ρ₂)) → ƛ t₁ ρ₁ ≈v ƛ t₂ ρ₂ -- Applicative bisimilarity. infix 4 _≈t_ _≈t_ : ∀ {n} → Tm n → Tm n → Set t₁ ≈t t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈c ⟦ t₂ ⟧ ρ -- This notion of applicative bisimilarity is not reflexive. -- -- Note that the definition above is a bit strange in Agda: it is -- subject to the quantifier inversion described by Thorsten -- Altenkirch and myself in "Termination Checking in the Presence of -- Nested Inductive and Coinductive Types". However, for this proof -- it does not matter if _≈c_ is seen as having the form -- μX.νY.μZ. F X Y Z or νX.μY. F X Y; the ν part is never used. mutual distinct-c : ¬ now (just (ƛ (var zero) [])) ≈c now (just (ƛ (var zero) [])) distinct-c (now eq) = distinct-mv eq distinct-mv : ¬ just (ƛ (var zero) []) ≈mv just (ƛ (var zero) []) distinct-mv (just eq) = distinct-v eq distinct-v : ¬ ƛ (var zero) [] ≈v ƛ (var zero) [] distinct-v (ƛ eq) = distinct-c (eq (ƛ (var zero) [])) distinct-t : ¬ ƛ (var zero) ≈t (Tm 0 ∋ ƛ (var zero)) distinct-t eq = distinct-c (eq []) ------------------------------------------------------------------------ -- Applicative bisimilarity infix 4 _≈mv_ _≈v_ -- _≈mv_, _≈c_ and _≈v_ are defined mutually (coinductively). data _≈v_ : Value → Value → Set -- Equivalence of possibly exceptional values. _≈mv_ : Maybe Value → Maybe Value → Set _≈mv_ = Maybe.Pointwise _≈v_ -- Equivalence of computations. open module EA = Partiality.Equality _≈mv_ using () renaming (_≈_ to _≈c_) -- Equivalence of values. data _≈v_ where con : ∀ {i} → con i ≈v con i ƛ : ∀ {n₁} {t₁ : Tm (1 + n₁)} {ρ₁} {n₂} {t₂ : Tm (1 + n₂)} {ρ₂} (t₁≈t₂ : ∀ v → ∞ (⟦ t₁ ⟧ (v ∷ ρ₁) ≈c ⟦ t₂ ⟧ (v ∷ ρ₂))) → ƛ t₁ ρ₁ ≈v ƛ t₂ ρ₂ -- Applicative bisimilarity. infix 4 _≈t_ _≈t_ : ∀ {n} → Tm n → Tm n → Set t₁ ≈t t₂ = ∀ ρ → ⟦ t₁ ⟧ ρ ≈c ⟦ t₂ ⟧ ρ -- Applicative bisimilarity is reflexive. mutual infix 3 _∎mv _∎c _∎v _∎mv : (v : Maybe Value) → v ≈mv v just v ∎mv = just (v ∎v) nothing ∎mv = nothing _∎c : (x : Maybe Value ⊥) → x ≈c x now mv ∎c = EA.now (mv ∎mv) later x ∎c = EA.later (♯ (♭ x ∎c)) _∎v : (v : Value) → v ≈v v con i ∎v = con ƛ t ρ ∎v = ƛ (λ v → ♯ (⟦ t ⟧ (v ∷ ρ) ∎c)) infix 3 _∎t _∎t : ∀ {n} (t : Tm n) → t ≈t t t ∎t = λ ρ → ⟦ t ⟧ ρ ∎c -- Applicative bisimilarity is symmetric. mutual sym-mv : ∀ {v₁ v₂} → v₁ ≈mv v₂ → v₂ ≈mv v₁ sym-mv (just v₁≈v₂) = just (sym-v v₁≈v₂) sym-mv nothing = nothing sym-c : ∀ {x₁ x₂} → x₁ ≈c x₂ → x₂ ≈c x₁ sym-c (EA.now v₁≈v₂) = EA.now (sym-mv v₁≈v₂) sym-c (EA.later x₁≈x₂) = EA.later (♯ sym-c (♭ x₁≈x₂)) sym-c (EA.laterˡ x₁≈x₂) = EA.laterʳ (sym-c x₁≈x₂) sym-c (EA.laterʳ x₁≈x₂) = EA.laterˡ (sym-c x₁≈x₂) sym-v : ∀ {v₁ v₂} → v₁ ≈v v₂ → v₂ ≈v v₁ sym-v con = con sym-v (ƛ t₁≈t₂) = ƛ (λ v → ♯ sym-c (♭ (t₁≈t₂ v))) sym-t : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈t t₂ → t₂ ≈t t₁ sym-t t₁≈t₂ = λ ρ → sym-c (t₁≈t₂ ρ) -- Applicative bisimilarity is transitive. mutual trans-mv : ∀ {v₁ v₂ v₃} → v₁ ≈mv v₂ → v₂ ≈mv v₃ → v₁ ≈mv v₃ trans-mv (just v₁≈v₂) (just v₂≈v₃) = just (trans-v v₁≈v₂ v₂≈v₃) trans-mv nothing nothing = nothing private now-trans-c : ∀ {x₁ x₂ v₃} → x₁ ≈c x₂ → x₂ ≈c now v₃ → x₁ ≈c now v₃ now-trans-c (EA.now v₁≈v₂) (EA.now v₂≈v₃) = EA.now (trans-mv v₁≈v₂ v₂≈v₃) now-trans-c (EA.laterˡ x₁≈x₂) x₂≈v₃ = EA.laterˡ (now-trans-c x₁≈x₂ x₂≈v₃) now-trans-c x₁≈lx₂ (EA.laterˡ x₂≈v₃) = now-trans-c (laterʳ⁻¹ x₁≈lx₂) x₂≈v₃ later-trans-c : ∀ {x₁ x₂ x₃} → x₁ ≈c x₂ → x₂ ≈c later x₃ → x₁ ≈c later x₃ later-trans-c (EA.later x₁≈x₂) lx₂≈lx₃ = EA.later (♯ trans-c (♭ x₁≈x₂) (later⁻¹ lx₂≈lx₃)) later-trans-c (EA.laterˡ x₁≈x₂) x₂≈lx₃ = EA.later (♯ trans-c x₁≈x₂ (laterʳ⁻¹ x₂≈lx₃)) later-trans-c (EA.laterʳ x₁≈x₂) lx₂≈lx₃ = later-trans-c x₁≈x₂ (laterˡ⁻¹ lx₂≈lx₃) later-trans-c x₁≈x₂ (EA.laterʳ x₂≈x₃) = EA.laterʳ ( trans-c x₁≈x₂ x₂≈x₃ ) trans-c : ∀ {x₁ x₂ x₃} → x₁ ≈c x₂ → x₂ ≈c x₃ → x₁ ≈c x₃ trans-c {x₃ = now v₃} x₁≈x₂ x₂≈v₃ = now-trans-c x₁≈x₂ x₂≈v₃ trans-c {x₃ = later z₃} x₁≈x₂ x₂≈lx₃ = later-trans-c x₁≈x₂ x₂≈lx₃ trans-v : ∀ {v₁ v₂ v₃} → v₁ ≈v v₂ → v₂ ≈v v₃ → v₁ ≈v v₃ trans-v con con = con trans-v (ƛ t₁≈t₂) (ƛ t₂≈t₃) = ƛ (λ v → ♯ trans-c (♭ (t₁≈t₂ v)) (♭ (t₂≈t₃ v))) trans-t : ∀ {n} {t₁ t₂ t₃ : Tm n} → t₁ ≈t t₂ → t₂ ≈t t₃ → t₁ ≈t t₃ trans-t t₁≈t₂ t₂≈t₃ = λ ρ → trans-c (t₁≈t₂ ρ) (t₂≈t₃ ρ) -- Bind preserves applicative bisimilarity. infixl 1 _>>=-cong-c_ _>>=-cong-c_ : ∀ {x₁ x₂ f₁ f₂} → x₁ ≈c x₂ → (∀ {v₁ v₂} → v₁ ≈v v₂ → f₁ v₁ ≈c f₂ v₂) → (x₁ >>= f₁) ≈c (x₂ >>= f₂) _>>=-cong-c_ {f₁ = f₁} {f₂} x₁≈x₂ f₁≈f₂ = Partiality._>>=-cong_ x₁≈x₂ helper where helper : ∀ {mv₁ mv₂} → mv₁ ≈mv mv₂ → maybe f₁ fail mv₁ ≈c maybe f₂ fail mv₂ helper nothing = EA.now nothing helper (just v₁≈v₂) = f₁≈f₂ v₁≈v₂ -- _≈!_ is stronger than applicative bisimilarity. ≈!⇒≈t : ∀ {n} {t₁ t₂ : Tm n} → t₁ ≈! t₂ → t₁ ≈t t₂ ≈!⇒≈t t₁≈t₂ = λ ρ → Partiality.map (λ {v₁} v₁≡v₂ → P.subst (_≈mv_ v₁) v₁≡v₂ (v₁ ∎mv)) (t₁≈t₂ ρ) ¬≈t⇒≈! : ¬ ((t₁ t₂ : Tm 0) → t₁ ≈t t₂ → t₁ ≈! t₂) ¬≈t⇒≈! hyp with hyp t₁ t₂ bisimilar [] where t₁ : Tm 0 t₁ = ƛ (ƛ (vr 0)) · con 0 t₂ : Tm 0 t₂ = ƛ (vr 0) bisimilar : t₁ ≈t t₂ bisimilar [] = EA.laterˡ (EA.now (just (ƛ (λ v → ♯ (return v ∎c))))) ... | laterˡ (now ())
{ "alphanum_fraction": 0.5307651622, "avg_line_length": 30.9945355191, "ext": "agda", "hexsha": "4b8f1b069d6877c006762621c00a3445df642b09", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/codata", "max_forks_repo_path": "Lambda/Closure/Equivalences.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/codata", "max_issues_repo_path": "Lambda/Closure/Equivalences.agda", "max_line_length": 103, "max_stars_count": 1, "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/codata", "max_stars_repo_path": "Lambda/Closure/Equivalences.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "num_tokens": 5065, "size": 11344 }
open import Data.Product using ( _×_ ; _,_ ) open import Relation.Unary using ( _∈_ ) open import Web.Semantic.DL.Role using ( Role ; ⟨_⟩ ; ⟨_⟩⁻¹ ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox.Interp using ( Interp ; Δ ; rol ; _⊨_≈_ ; rol-≈ ; ≈-refl ; ≈-sym ) open import Web.Semantic.DL.TBox.Interp.Morphism using ( _≲_ ; _≃_ ; ≲-resp-rol ; ≲-image² ; ≃-image ; ≃-image⁻¹ ; ≃-image² ; ≃-image²⁻¹ ; ≃-impl-≲ ; ≃-iso⁻¹ ) open import Web.Semantic.Util using ( Subset ; _⁻¹ ) module Web.Semantic.DL.Role.Model {Σ : Signature} where _⟦_⟧₂ : ∀ (I : Interp Σ) → Role Σ → Subset (Δ I × Δ I) I ⟦ ⟨ r ⟩ ⟧₂ = rol I r I ⟦ ⟨ r ⟩⁻¹ ⟧₂ = (rol I r)⁻¹ ⟦⟧₂-resp-≈ : ∀ I R {w x y z} → (I ⊨ w ≈ x) → ((x , y) ∈ I ⟦ R ⟧₂) → (I ⊨ y ≈ z) → ((w , z) ∈ I ⟦ R ⟧₂) ⟦⟧₂-resp-≈ I ⟨ r ⟩ w≈x xy∈⟦r⟧ y≈z = rol-≈ I r w≈x xy∈⟦r⟧ y≈z ⟦⟧₂-resp-≈ I ⟨ r ⟩⁻¹ w≈x yx∈⟦r⟧ y≈z = rol-≈ I r (≈-sym I y≈z) yx∈⟦r⟧ (≈-sym I w≈x) ⟦⟧₂-resp-≲ : ∀ {I J : Interp Σ} → (I≲J : I ≲ J) → ∀ {xy} R → (xy ∈ I ⟦ R ⟧₂) → (≲-image² I≲J xy ∈ J ⟦ R ⟧₂) ⟦⟧₂-resp-≲ I≲J {x , y} ⟨ r ⟩ xy∈⟦r⟧ = ≲-resp-rol I≲J xy∈⟦r⟧ ⟦⟧₂-resp-≲ I≲J {x , y} ⟨ r ⟩⁻¹ yx∈⟦r⟧ = ≲-resp-rol I≲J yx∈⟦r⟧ ⟦⟧₂-resp-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {xy} R → (xy ∈ I ⟦ R ⟧₂) → (≃-image² I≃J xy ∈ J ⟦ R ⟧₂) ⟦⟧₂-resp-≃ I≃J = ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) ⟦⟧₂-refl-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {xy} R → (≃-image²⁻¹ I≃J xy ∈ I ⟦ R ⟧₂) → (xy ∈ J ⟦ R ⟧₂) ⟦⟧₂-refl-≃ {I} {J} I≃J {x , y} R xy∈⟦R⟧ = ⟦⟧₂-resp-≈ J R (≈-sym J (≃-iso⁻¹ I≃J x)) (⟦⟧₂-resp-≃ I≃J R xy∈⟦R⟧) (≃-iso⁻¹ I≃J y) ⟦⟧₂-galois : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {x y} R → ((≃-image⁻¹ I≃J x , y) ∈ I ⟦ R ⟧₂) → ((x , ≃-image I≃J y) ∈ J ⟦ R ⟧₂) ⟦⟧₂-galois {I} {J} I≃J {x} R xy∈⟦R⟧ = ⟦⟧₂-resp-≈ J R (≈-sym J (≃-iso⁻¹ I≃J x)) (⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xy∈⟦R⟧) (≈-refl J)
{ "alphanum_fraction": 0.460874258, "avg_line_length": 44.119047619, "ext": "agda", "hexsha": "89de66d2d3d7bd734c58ee4e5fd17194d5bc9f20", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_path": "src/Web/Semantic/DL/Role/Model.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_path": "src/Web/Semantic/DL/Role/Model.agda", "max_line_length": 160, "max_stars_count": 9, "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_path": "src/Web/Semantic/DL/Role/Model.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "num_tokens": 1179, "size": 1853 }
-- Andreas, 2017-07-13, issue #2645 -- Agda accepted this definition: record S : Set₁ where postulate field f : Set -- Now: error raised here s : Set → S s A = record {f = A }
{ "alphanum_fraction": 0.609375, "avg_line_length": 16, "ext": "agda", "hexsha": "60d1d2f75d352433af3ea2b32e37d54cbc5bd1f9", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue2645.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue2645.agda", "max_line_length": 40, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue2645.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 64, "size": 192 }
-- Σ type (also used as existential) and -- cartesian product (also used as conjunction). {-# OPTIONS --without-K --safe #-} module Tools.Product where open import Data.Product public using (Σ; ∃; ∃₂; _×_; _,_; proj₁; proj₂)
{ "alphanum_fraction": 0.6842105263, "avg_line_length": 25.3333333333, "ext": "agda", "hexsha": "75df7c7281987ec0b658d804aaa0fc559bd1b497", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "fhlkfy/logrel-mltt", "max_forks_repo_path": "Tools/Product.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "fhlkfy/logrel-mltt", "max_issues_repo_path": "Tools/Product.agda", "max_line_length": 72, "max_stars_count": 30, "max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "fhlkfy/logrel-mltt", "max_stars_repo_path": "Tools/Product.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "num_tokens": 62, "size": 228 }
{-# OPTIONS --without-K --exact-split #-} module 05-identity-types where import 04-inductive-types open 04-inductive-types public -- Section 5.1 -- Definition 5.1.1 {- We introduce the identity type. -} data Id {i : Level} {A : UU i} (x : A) : A → UU i where refl : Id x x {- In the following definition we give a construction of path induction. However, in the development of this library we will mostly use Agda's built-in methods to give constructions by path induction. -} ind-Id : {i j : Level} {A : UU i} (x : A) (B : (y : A) (p : Id x y) → UU j) → (B x refl) → (y : A) (p : Id x y) → B y p ind-Id x B b y refl = b -- Section 5.2 The groupoid structure of types -- Definition 5.2.1 _∙_ : {i : Level} {A : UU i} {x y z : A} → Id x y → Id y z → Id x z refl ∙ q = q concat : {i : Level} {A : UU i} {x y : A} → Id x y → (z : A) → Id y z → Id x z concat p z q = p ∙ q -- Definition 5.2.2 inv : {i : Level} {A : UU i} {x y : A} → Id x y → Id y x inv refl = refl -- Definition 5.2.3 assoc : {i : Level} {A : UU i} {x y z w : A} (p : Id x y) (q : Id y z) (r : Id z w) → Id ((p ∙ q) ∙ r) (p ∙ (q ∙ r)) assoc refl q r = refl -- Definition 5.2.4 left-unit : {i : Level} {A : UU i} {x y : A} {p : Id x y} → Id (refl ∙ p) p left-unit = refl right-unit : {i : Level} {A : UU i} {x y : A} {p : Id x y} → Id (p ∙ refl) p right-unit {p = refl} = refl -- Definition 5.2.5 left-inv : {i : Level} {A : UU i} {x y : A} (p : Id x y) → Id ((inv p) ∙ p) refl left-inv refl = refl right-inv : {i : Level} {A : UU i} {x y : A} (p : Id x y) → Id (p ∙ (inv p)) refl right-inv refl = refl -- Section 5.3 The action on paths of functions -- Definition 5.3.1 ap : {i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A} (p : Id x y) → Id (f x) (f y) ap f refl = refl ap-id : {i : Level} {A : UU i} {x y : A} (p : Id x y) → Id (ap id p) p ap-id refl = refl ap-comp : {i j k : Level} {A : UU i} {B : UU j} {C : UU k} (g : B → C) (f : A → B) {x y : A} (p : Id x y) → Id (ap (g ∘ f) p) (ap g (ap f p)) ap-comp g f refl = refl -- Definition 5.3.2 ap-refl : {i j : Level} {A : UU i} {B : UU j} (f : A → B) (x : A) → Id (ap f (refl {_} {_} {x})) refl ap-refl f x = refl ap-concat : {i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y z : A} (p : Id x y) (q : Id y z) → Id (ap f (p ∙ q)) ((ap f p) ∙ (ap f q)) ap-concat f refl q = refl ap-inv : {i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A} (p : Id x y) → Id (ap f (inv p)) (inv (ap f p)) ap-inv f refl = refl -- Section 5.4 Transport -- Definition 5.4.1 tr : {i j : Level} {A : UU i} (B : A → UU j) {x y : A} (p : Id x y) → B x → B y tr B refl b = b -- Definition 5.4.2 apd : {i j : Level} {A : UU i} {B : A → UU j} (f : (x : A) → B x) {x y : A} (p : Id x y) → Id (tr B p (f x)) (f y) apd f refl = refl path-over : {i j : Level} {A : UU i} (B : A → UU j) {x x' : A} (p : Id x x') → B x → B x' → UU j path-over B p y y' = Id (tr B p y) y' refl-path-over : {i j : Level} {A : UU i} (B : A → UU j) (x : A) (y : B x) → path-over B refl y y refl-path-over B x y = refl -- Exercises -- Exercise 5.1 -- Exercise 5.2 distributive-inv-concat : {i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A} (q : Id y z) → Id (inv (p ∙ q)) ((inv q) ∙ (inv p)) distributive-inv-concat refl refl = refl -- Exercise 5.3 inv-con : {i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A} (q : Id y z) (r : Id x z) → (Id (p ∙ q) r) → Id q ((inv p) ∙ r) inv-con refl q r = id con-inv : {i : Level} {A : UU i} {x y : A} (p : Id x y) {z : A} (q : Id y z) (r : Id x z) → (Id (p ∙ q) r) → Id p (r ∙ (inv q)) con-inv p refl r = ( λ α → α ∙ (inv right-unit)) ∘ (concat (inv right-unit) r) -- Exercise 5.4 lift : {i j : Level} {A : UU i} {B : A → UU j} {x y : A} (p : Id x y) (b : B x) → Id (pair x b) (pair y (tr B p b)) lift refl b = refl -- Exercise 5.5 -- Exercise 5.5(a) abstract right-unit-law-add-ℕ : (x : ℕ) → Id (add-ℕ x zero-ℕ) x right-unit-law-add-ℕ x = refl left-unit-law-add-ℕ : (x : ℕ) → Id (add-ℕ zero-ℕ x) x left-unit-law-add-ℕ zero-ℕ = refl left-unit-law-add-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-add-ℕ x) left-successor-law-add-ℕ : (x y : ℕ) → Id (add-ℕ (succ-ℕ x) y) (succ-ℕ (add-ℕ x y)) left-successor-law-add-ℕ x zero-ℕ = refl left-successor-law-add-ℕ x (succ-ℕ y) = ap succ-ℕ (left-successor-law-add-ℕ x y) right-successor-law-add-ℕ : (x y : ℕ) → Id (add-ℕ x (succ-ℕ y)) (succ-ℕ (add-ℕ x y)) right-successor-law-add-ℕ x y = refl -- Exercise 5.5(b) abstract associative-add-ℕ : (x y z : ℕ) → Id (add-ℕ (add-ℕ x y) z) (add-ℕ x (add-ℕ y z)) associative-add-ℕ x y zero-ℕ = refl associative-add-ℕ x y (succ-ℕ z) = ap succ-ℕ (associative-add-ℕ x y z) abstract commutative-add-ℕ : (x y : ℕ) → Id (add-ℕ x y) (add-ℕ y x) commutative-add-ℕ zero-ℕ y = left-unit-law-add-ℕ y commutative-add-ℕ (succ-ℕ x) y = (left-successor-law-add-ℕ x y) ∙ (ap succ-ℕ (commutative-add-ℕ x y)) -- Exercise 5.5(c) abstract left-zero-law-mul-ℕ : (x : ℕ) → Id (mul-ℕ zero-ℕ x) zero-ℕ left-zero-law-mul-ℕ x = refl right-zero-law-mul-ℕ : (x : ℕ) → Id (mul-ℕ x zero-ℕ) zero-ℕ right-zero-law-mul-ℕ zero-ℕ = refl right-zero-law-mul-ℕ (succ-ℕ x) = ( right-unit-law-add-ℕ (mul-ℕ x zero-ℕ)) ∙ (right-zero-law-mul-ℕ x) abstract right-unit-law-mul-ℕ : (x : ℕ) → Id (mul-ℕ x one-ℕ) x right-unit-law-mul-ℕ zero-ℕ = refl right-unit-law-mul-ℕ (succ-ℕ x) = ap succ-ℕ (right-unit-law-mul-ℕ x) left-unit-law-mul-ℕ : (x : ℕ) → Id (mul-ℕ one-ℕ x) x left-unit-law-mul-ℕ zero-ℕ = refl left-unit-law-mul-ℕ (succ-ℕ x) = ap succ-ℕ (left-unit-law-mul-ℕ x) abstract left-successor-law-mul-ℕ : (x y : ℕ) → Id (mul-ℕ (succ-ℕ x) y) (add-ℕ (mul-ℕ x y) y) left-successor-law-mul-ℕ x y = refl right-successor-law-mul-ℕ : (x y : ℕ) → Id (mul-ℕ x (succ-ℕ y)) (add-ℕ x (mul-ℕ x y)) right-successor-law-mul-ℕ zero-ℕ y = refl right-successor-law-mul-ℕ (succ-ℕ x) y = ( ( ap (λ t → succ-ℕ (add-ℕ t y)) (right-successor-law-mul-ℕ x y)) ∙ ( ap succ-ℕ (associative-add-ℕ x (mul-ℕ x y) y))) ∙ ( inv (left-successor-law-add-ℕ x (add-ℕ (mul-ℕ x y) y))) -- Exercise 5.5(d) abstract commutative-mul-ℕ : (x y : ℕ) → Id (mul-ℕ x y) (mul-ℕ y x) commutative-mul-ℕ zero-ℕ y = inv (right-zero-law-mul-ℕ y) commutative-mul-ℕ (succ-ℕ x) y = ( commutative-add-ℕ (mul-ℕ x y) y) ∙ ( ( ap (add-ℕ y) (commutative-mul-ℕ x y)) ∙ ( inv (right-successor-law-mul-ℕ y x))) -- Exercise 5.5(e) abstract left-distributive-mul-add-ℕ : (x y z : ℕ) → Id (mul-ℕ x (add-ℕ y z)) (add-ℕ (mul-ℕ x y) (mul-ℕ x z)) left-distributive-mul-add-ℕ zero-ℕ y z = refl left-distributive-mul-add-ℕ (succ-ℕ x) y z = ( left-successor-law-mul-ℕ x (add-ℕ y z)) ∙ ( ( ap (λ t → add-ℕ t (add-ℕ y z)) (left-distributive-mul-add-ℕ x y z)) ∙ ( ( associative-add-ℕ (mul-ℕ x y) (mul-ℕ x z) (add-ℕ y z)) ∙ ( ( ap ( add-ℕ (mul-ℕ x y)) ( ( inv (associative-add-ℕ (mul-ℕ x z) y z)) ∙ ( ( ap (λ t → add-ℕ t z) (commutative-add-ℕ (mul-ℕ x z) y)) ∙ ( associative-add-ℕ y (mul-ℕ x z) z)))) ∙ ( inv (associative-add-ℕ (mul-ℕ x y) y (add-ℕ (mul-ℕ x z) z)))))) abstract right-distributive-mul-add-ℕ : (x y z : ℕ) → Id (mul-ℕ (add-ℕ x y) z) (add-ℕ (mul-ℕ x z) (mul-ℕ y z)) right-distributive-mul-add-ℕ x y z = ( commutative-mul-ℕ (add-ℕ x y) z) ∙ ( ( left-distributive-mul-add-ℕ z x y) ∙ ( ( ap (λ t → add-ℕ t (mul-ℕ z y)) (commutative-mul-ℕ z x)) ∙ ( ap (λ t → add-ℕ (mul-ℕ x z) t) (commutative-mul-ℕ z y)))) -- Exercise 5.5(f) abstract associative-mul-ℕ : (x y z : ℕ) → Id (mul-ℕ (mul-ℕ x y) z) (mul-ℕ x (mul-ℕ y z)) associative-mul-ℕ zero-ℕ y z = refl associative-mul-ℕ (succ-ℕ x) y z = ( right-distributive-mul-add-ℕ (mul-ℕ x y) y z) ∙ ( ap (λ t → add-ℕ t (mul-ℕ y z)) (associative-mul-ℕ x y z)) -- Exercise 5.6 Mac-Lane-pentagon : {i : Level} {A : UU i} {a b c d e : A} (p : Id a b) (q : Id b c) (r : Id c d) (s : Id d e) → let α₁ = (ap (λ t → t ∙ s) (assoc p q r)) α₂ = (assoc p (q ∙ r) s) α₃ = (ap (λ t → p ∙ t) (assoc q r s)) α₄ = (assoc (p ∙ q) r s) α₅ = (assoc p q (r ∙ s)) in Id ((α₁ ∙ α₂) ∙ α₃) (α₄ ∙ α₅) Mac-Lane-pentagon refl refl refl refl = refl {- The following code is an experiment that shows that constructions in an abstract environment do remember the specific definitions of previous definitions in abstract environments. -} abstract abstract-concat : {l : Level} {A : UU l} {x y z : A} → Id x y → Id y z → Id x z abstract-concat refl q = q abstract-left-unit-law : {l : Level} {A : UU l} {x y : A} (q : Id x y) → Id (abstract-concat refl q) q abstract-left-unit-law q = refl {- We just make some random definition to make sure that we are not in the same abstract envirnoment anymore. -} one : ℕ one = succ-ℕ zero-ℕ abstract abstract-right-unit-law : {l : Level} {A : UU l} {x y : A} (p : Id x y) → Id (abstract-concat p refl) p abstract-right-unit-law refl = refl {- The term refl should not be accepted if the definition of abstract-concat were forgotten. A definition that would work under all circumstances is abstract-left-unit refl. -} -- The ring axioms for ℤ abstract left-inverse-pred-ℤ : (k : ℤ) → Id (pred-ℤ (succ-ℤ k)) k left-inverse-pred-ℤ (inl zero-ℕ) = refl left-inverse-pred-ℤ (inl (succ-ℕ x)) = refl left-inverse-pred-ℤ (inr (inl star)) = refl left-inverse-pred-ℤ (inr (inr zero-ℕ)) = refl left-inverse-pred-ℤ (inr (inr (succ-ℕ x))) = refl right-inverse-pred-ℤ : (k : ℤ) → Id (succ-ℤ (pred-ℤ k)) k right-inverse-pred-ℤ (inl zero-ℕ) = refl right-inverse-pred-ℤ (inl (succ-ℕ x)) = refl right-inverse-pred-ℤ (inr (inl star)) = refl right-inverse-pred-ℤ (inr (inr zero-ℕ)) = refl right-inverse-pred-ℤ (inr (inr (succ-ℕ x))) = refl {- Exercise 6.12 (a) simply asks to prove the unit laws. The left unit law holds by judgmental equality. -} abstract left-unit-law-add-ℤ : (k : ℤ) → Id (add-ℤ zero-ℤ k) k left-unit-law-add-ℤ k = refl right-unit-law-add-ℤ : (k : ℤ) → Id (add-ℤ k zero-ℤ) k right-unit-law-add-ℤ (inl zero-ℕ) = refl right-unit-law-add-ℤ (inl (succ-ℕ x)) = ap pred-ℤ (right-unit-law-add-ℤ (inl x)) right-unit-law-add-ℤ (inr (inl star)) = refl right-unit-law-add-ℤ (inr (inr zero-ℕ)) = refl right-unit-law-add-ℤ (inr (inr (succ-ℕ x))) = ap succ-ℤ (right-unit-law-add-ℤ (inr (inr x))) {- Exercise 6.12 (b) asks to show the left and right predecessor and successor laws. These are helpful to give proofs of associativity and commutativity. -} abstract left-predecessor-law-add-ℤ : (x y : ℤ) → Id (add-ℤ (pred-ℤ x) y) (pred-ℤ (add-ℤ x y)) left-predecessor-law-add-ℤ (inl n) y = refl left-predecessor-law-add-ℤ (inr (inl star)) y = refl left-predecessor-law-add-ℤ (inr (inr zero-ℕ)) y = ( ap (λ t → add-ℤ t y) (left-inverse-pred-ℤ zero-ℤ)) ∙ ( inv (left-inverse-pred-ℤ y)) left-predecessor-law-add-ℤ (inr (inr (succ-ℕ x))) y = ( ap (λ t → (add-ℤ t y)) (left-inverse-pred-ℤ (inr (inr x)))) ∙ ( inv (left-inverse-pred-ℤ (add-ℤ (inr (inr x)) y))) right-predecessor-law-add-ℤ : (x y : ℤ) → Id (add-ℤ x (pred-ℤ y)) (pred-ℤ (add-ℤ x y)) right-predecessor-law-add-ℤ (inl zero-ℕ) n = refl right-predecessor-law-add-ℤ (inl (succ-ℕ m)) n = ap pred-ℤ (right-predecessor-law-add-ℤ (inl m) n) right-predecessor-law-add-ℤ (inr (inl star)) n = refl right-predecessor-law-add-ℤ (inr (inr zero-ℕ)) n = (right-inverse-pred-ℤ n) ∙ (inv (left-inverse-pred-ℤ n)) right-predecessor-law-add-ℤ (inr (inr (succ-ℕ x))) n = ( ap succ-ℤ (right-predecessor-law-add-ℤ (inr (inr x)) n)) ∙ ( ( right-inverse-pred-ℤ (add-ℤ (inr (inr x)) n)) ∙ ( inv (left-inverse-pred-ℤ (add-ℤ (inr (inr x)) n)))) abstract left-successor-law-add-ℤ : (x y : ℤ) → Id (add-ℤ (succ-ℤ x) y) (succ-ℤ (add-ℤ x y)) left-successor-law-add-ℤ (inl zero-ℕ) y = ( ap (λ t → add-ℤ t y) (right-inverse-pred-ℤ zero-ℤ)) ∙ ( inv (right-inverse-pred-ℤ y)) left-successor-law-add-ℤ (inl (succ-ℕ x)) y = ( inv (right-inverse-pred-ℤ (add-ℤ (inl x) y))) ∙ ( ap succ-ℤ (inv (left-predecessor-law-add-ℤ (inl x) y))) left-successor-law-add-ℤ (inr (inl star)) y = refl left-successor-law-add-ℤ (inr (inr x)) y = refl right-successor-law-add-ℤ : (x y : ℤ) → Id (add-ℤ x (succ-ℤ y)) (succ-ℤ (add-ℤ x y)) right-successor-law-add-ℤ (inl zero-ℕ) y = (left-inverse-pred-ℤ y) ∙ (inv (right-inverse-pred-ℤ y)) right-successor-law-add-ℤ (inl (succ-ℕ x)) y = ( ap pred-ℤ (right-successor-law-add-ℤ (inl x) y)) ∙ ( ( left-inverse-pred-ℤ (add-ℤ (inl x) y)) ∙ ( inv (right-inverse-pred-ℤ (add-ℤ (inl x) y)))) right-successor-law-add-ℤ (inr (inl star)) y = refl right-successor-law-add-ℤ (inr (inr zero-ℕ)) y = refl right-successor-law-add-ℤ (inr (inr (succ-ℕ x))) y = ap succ-ℤ (right-successor-law-add-ℤ (inr (inr x)) y) {- Exercise 6.12 (c) asks to prove associativity and commutativity. Note that we avoid an unwieldy amount of cases by only using induction on the first argument. The resulting proof term is fairly short, and we don't have to present ℤ as a certain quotient of ℕ × ℕ. -} abstract associative-add-ℤ : (x y z : ℤ) → Id (add-ℤ (add-ℤ x y) z) (add-ℤ x (add-ℤ y z)) associative-add-ℤ (inl zero-ℕ) y z = ( ap (λ t → add-ℤ t z) (left-predecessor-law-add-ℤ zero-ℤ y)) ∙ ( ( left-predecessor-law-add-ℤ y z) ∙ ( inv (left-predecessor-law-add-ℤ zero-ℤ (add-ℤ y z)))) associative-add-ℤ (inl (succ-ℕ x)) y z = ( ap (λ t → add-ℤ t z) (left-predecessor-law-add-ℤ (inl x) y)) ∙ ( ( left-predecessor-law-add-ℤ (add-ℤ (inl x) y) z) ∙ ( ( ap pred-ℤ (associative-add-ℤ (inl x) y z)) ∙ ( inv (left-predecessor-law-add-ℤ (inl x) (add-ℤ y z))))) associative-add-ℤ (inr (inl star)) y z = refl associative-add-ℤ (inr (inr zero-ℕ)) y z = ( ap (λ t → add-ℤ t z) (left-successor-law-add-ℤ zero-ℤ y)) ∙ ( ( left-successor-law-add-ℤ y z) ∙ ( inv (left-successor-law-add-ℤ zero-ℤ (add-ℤ y z)))) associative-add-ℤ (inr (inr (succ-ℕ x))) y z = ( ap (λ t → add-ℤ t z) (left-successor-law-add-ℤ (inr (inr x)) y)) ∙ ( ( left-successor-law-add-ℤ (add-ℤ (inr (inr x)) y) z) ∙ ( ( ap succ-ℤ (associative-add-ℤ (inr (inr x)) y z)) ∙ ( inv (left-successor-law-add-ℤ (inr (inr x)) (add-ℤ y z))))) abstract commutative-add-ℤ : (x y : ℤ) → Id (add-ℤ x y) (add-ℤ y x) commutative-add-ℤ (inl zero-ℕ) y = ( left-predecessor-law-add-ℤ zero-ℤ y) ∙ ( inv ( ( right-predecessor-law-add-ℤ y zero-ℤ) ∙ ( ap pred-ℤ (right-unit-law-add-ℤ y)))) commutative-add-ℤ (inl (succ-ℕ x)) y = ( ap pred-ℤ (commutative-add-ℤ (inl x) y)) ∙ ( inv (right-predecessor-law-add-ℤ y (inl x))) commutative-add-ℤ (inr (inl star)) y = inv (right-unit-law-add-ℤ y) commutative-add-ℤ (inr (inr zero-ℕ)) y = inv ( ( right-successor-law-add-ℤ y zero-ℤ) ∙ ( ap succ-ℤ (right-unit-law-add-ℤ y))) commutative-add-ℤ (inr (inr (succ-ℕ x))) y = ( ap succ-ℤ (commutative-add-ℤ (inr (inr x)) y)) ∙ ( inv (right-successor-law-add-ℤ y (inr (inr x)))) {- Exercise 6.12 (d) finally asks to show the inverse laws, completing the verification of the group laws. Combined with associativity and commutativity we conclude that (add-ℤ x) and (λ x → add-ℤ x y) are equivalences, for every x : ℤ and y : ℤ, respectively. -} abstract left-inverse-law-add-ℤ : (x : ℤ) → Id (add-ℤ (neg-ℤ x) x) zero-ℤ left-inverse-law-add-ℤ (inl zero-ℕ) = refl left-inverse-law-add-ℤ (inl (succ-ℕ x)) = ( ap succ-ℤ (right-predecessor-law-add-ℤ (inr (inr x)) (inl x))) ∙ ( ( right-inverse-pred-ℤ (add-ℤ (inr (inr x)) (inl x))) ∙ ( left-inverse-law-add-ℤ (inl x))) left-inverse-law-add-ℤ (inr (inl star)) = refl left-inverse-law-add-ℤ (inr (inr x)) = ( commutative-add-ℤ (inl x) (inr (inr x))) ∙ ( left-inverse-law-add-ℤ (inl x)) right-inverse-law-add-ℤ : (x : ℤ) → Id (add-ℤ x (neg-ℤ x)) zero-ℤ right-inverse-law-add-ℤ x = ( commutative-add-ℤ x (neg-ℤ x)) ∙ (left-inverse-law-add-ℤ x) -- Similar for multiplication on ℤ neg-neg-ℤ : (k : ℤ) → Id (neg-ℤ (neg-ℤ k)) k neg-neg-ℤ (inl n) = refl neg-neg-ℤ (inr (inl star)) = refl neg-neg-ℤ (inr (inr n)) = refl neg-pred-ℤ : (k : ℤ) → Id (neg-ℤ (pred-ℤ k)) (succ-ℤ (neg-ℤ k)) neg-pred-ℤ (inl x) = refl neg-pred-ℤ (inr (inl star)) = refl neg-pred-ℤ (inr (inr zero-ℕ)) = refl neg-pred-ℤ (inr (inr (succ-ℕ x))) = refl pred-neg-ℤ : (k : ℤ) → Id (pred-ℤ (neg-ℤ k)) (neg-ℤ (succ-ℤ k)) pred-neg-ℤ (inl zero-ℕ) = refl pred-neg-ℤ (inl (succ-ℕ x)) = refl pred-neg-ℤ (inr (inl star)) = refl pred-neg-ℤ (inr (inr x)) = refl right-negative-law-add-ℤ : (k l : ℤ) → Id (add-ℤ k (neg-ℤ l)) (neg-ℤ (add-ℤ (neg-ℤ k) l)) right-negative-law-add-ℤ (inl zero-ℕ) l = ( left-predecessor-law-add-ℤ zero-ℤ (neg-ℤ l)) ∙ ( pred-neg-ℤ l) right-negative-law-add-ℤ (inl (succ-ℕ x)) l = ( left-predecessor-law-add-ℤ (inl x) (neg-ℤ l)) ∙ ( ( ap pred-ℤ (right-negative-law-add-ℤ (inl x) l)) ∙ ( pred-neg-ℤ (add-ℤ (inr (inr x)) l))) right-negative-law-add-ℤ (inr (inl star)) l = refl right-negative-law-add-ℤ (inr (inr zero-ℕ)) l = inv (neg-pred-ℤ l) right-negative-law-add-ℤ (inr (inr (succ-ℕ n))) l = ( left-successor-law-add-ℤ (in-pos n) (neg-ℤ l)) ∙ ( ( ap succ-ℤ (right-negative-law-add-ℤ (inr (inr n)) l)) ∙ ( inv (neg-pred-ℤ (add-ℤ (inl n) l)))) distributive-neg-add-ℤ : (k l : ℤ) → Id (neg-ℤ (add-ℤ k l)) (add-ℤ (neg-ℤ k) (neg-ℤ l)) distributive-neg-add-ℤ (inl zero-ℕ) l = ( ap neg-ℤ (left-predecessor-law-add-ℤ zero-ℤ l)) ∙ ( neg-pred-ℤ l) distributive-neg-add-ℤ (inl (succ-ℕ n)) l = ( neg-pred-ℤ (add-ℤ (inl n) l)) ∙ ( ( ap succ-ℤ (distributive-neg-add-ℤ (inl n) l)) ∙ ( ap (λ t → add-ℤ t (neg-ℤ l)) (inv (neg-pred-ℤ (inl n))))) distributive-neg-add-ℤ (inr (inl star)) l = refl distributive-neg-add-ℤ (inr (inr zero-ℕ)) l = inv (pred-neg-ℤ l) distributive-neg-add-ℤ (inr (inr (succ-ℕ n))) l = ( inv (pred-neg-ℤ (add-ℤ (in-pos n) l))) ∙ ( ap pred-ℤ (distributive-neg-add-ℤ (inr (inr n)) l)) left-zero-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ zero-ℤ k) zero-ℤ left-zero-law-mul-ℤ k = refl right-zero-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k zero-ℤ) zero-ℤ right-zero-law-mul-ℤ (inl zero-ℕ) = refl right-zero-law-mul-ℤ (inl (succ-ℕ n)) = right-zero-law-mul-ℤ (inl n) right-zero-law-mul-ℤ (inr (inl star)) = refl right-zero-law-mul-ℤ (inr (inr zero-ℕ)) = refl right-zero-law-mul-ℤ (inr (inr (succ-ℕ n))) = right-zero-law-mul-ℤ (inr (inr n)) left-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ one-ℤ k) k left-unit-law-mul-ℤ k = refl right-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k one-ℤ) k right-unit-law-mul-ℤ (inl zero-ℕ) = refl right-unit-law-mul-ℤ (inl (succ-ℕ n)) = ap (add-ℤ (neg-one-ℤ)) (right-unit-law-mul-ℤ (inl n)) right-unit-law-mul-ℤ (inr (inl star)) = refl right-unit-law-mul-ℤ (inr (inr zero-ℕ)) = refl right-unit-law-mul-ℤ (inr (inr (succ-ℕ n))) = ap (add-ℤ one-ℤ) (right-unit-law-mul-ℤ (inr (inr n))) left-neg-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ neg-one-ℤ k) (neg-ℤ k) left-neg-unit-law-mul-ℤ k = refl right-neg-unit-law-mul-ℤ : (k : ℤ) → Id (mul-ℤ k neg-one-ℤ) (neg-ℤ k) right-neg-unit-law-mul-ℤ (inl zero-ℕ) = refl right-neg-unit-law-mul-ℤ (inl (succ-ℕ n)) = ap (add-ℤ one-ℤ) (right-neg-unit-law-mul-ℤ (inl n)) right-neg-unit-law-mul-ℤ (inr (inl star)) = refl right-neg-unit-law-mul-ℤ (inr (inr zero-ℕ)) = refl right-neg-unit-law-mul-ℤ (inr (inr (succ-ℕ n))) = ap (add-ℤ neg-one-ℤ) (right-neg-unit-law-mul-ℤ (inr (inr n))) left-successor-law-mul-ℤ : (k l : ℤ) → Id (mul-ℤ (succ-ℤ k) l) (add-ℤ l (mul-ℤ k l)) left-successor-law-mul-ℤ (inl zero-ℕ) l = inv (right-inverse-law-add-ℤ l) left-successor-law-mul-ℤ (inl (succ-ℕ n)) l = ( ( inv (left-unit-law-add-ℤ (mul-ℤ (inl n) l))) ∙ ( ap ( λ x → add-ℤ x (mul-ℤ (inl n) l)) ( inv (right-inverse-law-add-ℤ l)))) ∙ ( associative-add-ℤ l (neg-ℤ l) (mul-ℤ (inl n) l)) left-successor-law-mul-ℤ (inr (inl star)) l = inv (right-unit-law-add-ℤ l) left-successor-law-mul-ℤ (inr (inr n)) l = refl left-predecessor-law-mul-ℤ : (k l : ℤ) → Id (mul-ℤ (pred-ℤ k) l) (add-ℤ (neg-ℤ l) (mul-ℤ k l)) left-predecessor-law-mul-ℤ (inl n) l = refl left-predecessor-law-mul-ℤ (inr (inl star)) l = ( left-neg-unit-law-mul-ℤ l) ∙ ( inv (right-unit-law-add-ℤ (neg-ℤ l))) left-predecessor-law-mul-ℤ (inr (inr zero-ℕ)) l = inv (left-inverse-law-add-ℤ l) left-predecessor-law-mul-ℤ (inr (inr (succ-ℕ x))) l = ( ap ( λ t → add-ℤ t (mul-ℤ (in-pos x) l)) ( inv (left-inverse-law-add-ℤ l))) ∙ ( associative-add-ℤ (neg-ℤ l) l (mul-ℤ (in-pos x) l)) right-successor-law-mul-ℤ : (k l : ℤ) → Id (mul-ℤ k (succ-ℤ l)) (add-ℤ k (mul-ℤ k l)) right-successor-law-mul-ℤ (inl zero-ℕ) l = inv (pred-neg-ℤ l) right-successor-law-mul-ℤ (inl (succ-ℕ n)) l = ( left-predecessor-law-mul-ℤ (inl n) (succ-ℤ l)) ∙ ( ( ap (add-ℤ (neg-ℤ (succ-ℤ l))) (right-successor-law-mul-ℤ (inl n) l)) ∙ ( ( inv (associative-add-ℤ (neg-ℤ (succ-ℤ l)) (inl n) (mul-ℤ (inl n) l))) ∙ ( ( ap ( λ t → add-ℤ t (mul-ℤ (inl n) l)) { x = add-ℤ (neg-ℤ (succ-ℤ l)) (inl n)} { y = add-ℤ (inl (succ-ℕ n)) (neg-ℤ l)} ( ( right-successor-law-add-ℤ (neg-ℤ (succ-ℤ l)) (inl (succ-ℕ n))) ∙ ( ( ap succ-ℤ ( commutative-add-ℤ (neg-ℤ (succ-ℤ l)) (inl (succ-ℕ n)))) ∙ ( ( inv ( right-successor-law-add-ℤ ( inl (succ-ℕ n)) ( neg-ℤ (succ-ℤ l)))) ∙ ( ap ( add-ℤ (inl (succ-ℕ n))) ( ( ap succ-ℤ (inv (pred-neg-ℤ l))) ∙ ( right-inverse-pred-ℤ (neg-ℤ l)))))))) ∙ ( associative-add-ℤ (inl (succ-ℕ n)) (neg-ℤ l) (mul-ℤ (inl n) l))))) right-successor-law-mul-ℤ (inr (inl star)) l = refl right-successor-law-mul-ℤ (inr (inr zero-ℕ)) l = refl right-successor-law-mul-ℤ (inr (inr (succ-ℕ n))) l = ( left-successor-law-mul-ℤ (in-pos n) (succ-ℤ l)) ∙ ( ( ap (add-ℤ (succ-ℤ l)) (right-successor-law-mul-ℤ (inr (inr n)) l)) ∙ ( ( inv (associative-add-ℤ (succ-ℤ l) (in-pos n) (mul-ℤ (in-pos n) l))) ∙ ( ( ap ( λ t → add-ℤ t (mul-ℤ (in-pos n) l)) { x = add-ℤ (succ-ℤ l) (in-pos n)} { y = add-ℤ (in-pos (succ-ℕ n)) l} ( ( left-successor-law-add-ℤ l (in-pos n)) ∙ ( ( ap succ-ℤ (commutative-add-ℤ l (in-pos n))) ∙ ( inv (left-successor-law-add-ℤ (in-pos n) l))))) ∙ ( associative-add-ℤ (inr (inr (succ-ℕ n))) l (mul-ℤ (inr (inr n)) l))))) right-predecessor-law-mul-ℤ : (k l : ℤ) → Id (mul-ℤ k (pred-ℤ l)) (add-ℤ (neg-ℤ k) (mul-ℤ k l)) right-predecessor-law-mul-ℤ (inl zero-ℕ) l = ( left-neg-unit-law-mul-ℤ (pred-ℤ l)) ∙ ( neg-pred-ℤ l) right-predecessor-law-mul-ℤ (inl (succ-ℕ n)) l = ( left-predecessor-law-mul-ℤ (inl n) (pred-ℤ l)) ∙ ( ( ap (add-ℤ (neg-ℤ (pred-ℤ l))) (right-predecessor-law-mul-ℤ (inl n) l)) ∙ ( ( inv ( associative-add-ℤ (neg-ℤ (pred-ℤ l)) (in-pos n) (mul-ℤ (inl n) l))) ∙ ( ( ap ( λ t → add-ℤ t (mul-ℤ (inl n) l)) { x = add-ℤ (neg-ℤ (pred-ℤ l)) (inr (inr n))} { y = add-ℤ (neg-ℤ (inl (succ-ℕ n))) (neg-ℤ l)} ( ( ap (λ t → add-ℤ t (in-pos n)) (neg-pred-ℤ l)) ∙ ( ( left-successor-law-add-ℤ (neg-ℤ l) (in-pos n)) ∙ ( ( ap succ-ℤ (commutative-add-ℤ (neg-ℤ l) (in-pos n))) ∙ ( inv (left-successor-law-add-ℤ (in-pos n) (neg-ℤ l))))))) ∙ ( associative-add-ℤ (in-pos (succ-ℕ n)) (neg-ℤ l) (mul-ℤ (inl n) l))))) right-predecessor-law-mul-ℤ (inr (inl star)) l = refl right-predecessor-law-mul-ℤ (inr (inr zero-ℕ)) l = refl right-predecessor-law-mul-ℤ (inr (inr (succ-ℕ n))) l = ( left-successor-law-mul-ℤ (in-pos n) (pred-ℤ l)) ∙ ( ( ap (add-ℤ (pred-ℤ l)) (right-predecessor-law-mul-ℤ (inr (inr n)) l)) ∙ ( ( inv (associative-add-ℤ (pred-ℤ l) (inl n) (mul-ℤ (inr (inr n)) l))) ∙ ( ( ap ( λ t → add-ℤ t (mul-ℤ (in-pos n) l)) { x = add-ℤ (pred-ℤ l) (inl n)} { y = add-ℤ (neg-ℤ (in-pos (succ-ℕ n))) l} ( ( left-predecessor-law-add-ℤ l (inl n)) ∙ ( ( ap pred-ℤ (commutative-add-ℤ l (inl n))) ∙ ( inv (left-predecessor-law-add-ℤ (inl n) l))))) ∙ ( associative-add-ℤ (inl (succ-ℕ n)) l (mul-ℤ (inr (inr n)) l))))) right-distributive-mul-add-ℤ : (k l m : ℤ) → Id (mul-ℤ (add-ℤ k l) m) (add-ℤ (mul-ℤ k m) (mul-ℤ l m)) right-distributive-mul-add-ℤ (inl zero-ℕ) l m = ( left-predecessor-law-mul-ℤ l m) ∙ ( ap ( λ t → add-ℤ t (mul-ℤ l m)) ( inv ( ( left-predecessor-law-mul-ℤ zero-ℤ m) ∙ ( right-unit-law-add-ℤ (neg-ℤ m))))) right-distributive-mul-add-ℤ (inl (succ-ℕ x)) l m = ( left-predecessor-law-mul-ℤ (add-ℤ (inl x) l) m) ∙ ( ( ap (add-ℤ (neg-ℤ m)) (right-distributive-mul-add-ℤ (inl x) l m)) ∙ ( inv (associative-add-ℤ (neg-ℤ m) (mul-ℤ (inl x) m) (mul-ℤ l m)))) right-distributive-mul-add-ℤ (inr (inl star)) l m = refl right-distributive-mul-add-ℤ (inr (inr zero-ℕ)) l m = left-successor-law-mul-ℤ l m right-distributive-mul-add-ℤ (inr (inr (succ-ℕ n))) l m = ( left-successor-law-mul-ℤ (add-ℤ (in-pos n) l) m) ∙ ( ( ap (add-ℤ m) (right-distributive-mul-add-ℤ (inr (inr n)) l m)) ∙ ( inv (associative-add-ℤ m (mul-ℤ (in-pos n) m) (mul-ℤ l m)))) left-negative-law-mul-ℤ : (k l : ℤ) → Id (mul-ℤ (neg-ℤ k) l) (neg-ℤ (mul-ℤ k l)) left-negative-law-mul-ℤ (inl zero-ℕ) l = ( left-unit-law-mul-ℤ l) ∙ ( inv (neg-neg-ℤ l)) left-negative-law-mul-ℤ (inl (succ-ℕ n)) l = ( ap (λ t → mul-ℤ t l) (neg-pred-ℤ (inl n))) ∙ ( ( left-successor-law-mul-ℤ (neg-ℤ (inl n)) l) ∙ ( ( ap (add-ℤ l) (left-negative-law-mul-ℤ (inl n) l)) ∙ ( right-negative-law-add-ℤ l (mul-ℤ (inl n) l)))) left-negative-law-mul-ℤ (inr (inl star)) l = refl left-negative-law-mul-ℤ (inr (inr zero-ℕ)) l = refl left-negative-law-mul-ℤ (inr (inr (succ-ℕ n))) l = ( left-predecessor-law-mul-ℤ (inl n) l) ∙ ( ( ap (add-ℤ (neg-ℤ l)) (left-negative-law-mul-ℤ (inr (inr n)) l)) ∙ ( inv (distributive-neg-add-ℤ l (mul-ℤ (in-pos n) l)))) associative-mul-ℤ : (k l m : ℤ) → Id (mul-ℤ (mul-ℤ k l) m) (mul-ℤ k (mul-ℤ l m)) associative-mul-ℤ (inl zero-ℕ) l m = left-negative-law-mul-ℤ l m associative-mul-ℤ (inl (succ-ℕ n)) l m = ( right-distributive-mul-add-ℤ (neg-ℤ l) (mul-ℤ (inl n) l) m) ∙ ( ( ap (add-ℤ (mul-ℤ (neg-ℤ l) m)) (associative-mul-ℤ (inl n) l m)) ∙ ( ap ( λ t → add-ℤ t (mul-ℤ (inl n) (mul-ℤ l m))) ( left-negative-law-mul-ℤ l m))) associative-mul-ℤ (inr (inl star)) l m = refl associative-mul-ℤ (inr (inr zero-ℕ)) l m = refl associative-mul-ℤ (inr (inr (succ-ℕ n))) l m = ( right-distributive-mul-add-ℤ l (mul-ℤ (in-pos n) l) m) ∙ ( ap (add-ℤ (mul-ℤ l m)) (associative-mul-ℤ (inr (inr n)) l m)) commutative-mul-ℤ : (k l : ℤ) → Id (mul-ℤ k l) (mul-ℤ l k) commutative-mul-ℤ (inl zero-ℕ) l = inv (right-neg-unit-law-mul-ℤ l) commutative-mul-ℤ (inl (succ-ℕ n)) l = ( ap (add-ℤ (neg-ℤ l)) (commutative-mul-ℤ (inl n) l)) ∙ ( inv (right-predecessor-law-mul-ℤ l (inl n))) commutative-mul-ℤ (inr (inl star)) l = inv (right-zero-law-mul-ℤ l) commutative-mul-ℤ (inr (inr zero-ℕ)) l = inv (right-unit-law-mul-ℤ l) commutative-mul-ℤ (inr (inr (succ-ℕ n))) l = ( ap (add-ℤ l) (commutative-mul-ℤ (inr (inr n)) l)) ∙ ( inv (right-successor-law-mul-ℤ l (in-pos n)))
{ "alphanum_fraction": 0.5621999127, "avg_line_length": 37.001345895, "ext": "agda", "hexsha": "38ab03b1d54a573dbe12eac1de6edf820fed992d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_path": "Agda/05-identity-types.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_path": "Agda/05-identity-types.agda", "max_line_length": 81, "max_stars_count": null, "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_path": "Agda/05-identity-types.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 12417, "size": 27492 }
-- There was a bug when postponing a type checking problem under -- a non-empty context. Fixed now. module PostponedTypeChecking where data Unit : Set where unit : Unit record R : Set where field f : Unit data *_ (A : Set) : Set where <_> : A -> * A get : {A : Set} -> * A -> A get < x > = x mk : Unit -> Unit -> * R mk _ _ = < record { f = unit } > r : R r = get (mk unit unit) data IsUnit : Unit -> Set where isUnit : IsUnit unit foo : IsUnit (R.f r) foo = isUnit
{ "alphanum_fraction": 0.602484472, "avg_line_length": 16.1, "ext": "agda", "hexsha": "240de51d2164d501a35c7c46ce45d96027319958", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/PostponedTypeChecking.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/PostponedTypeChecking.agda", "max_line_length": 64, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/PostponedTypeChecking.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 158, "size": 483 }
{-# OPTIONS --without-K #-} -- Lifting the dependent axiom of choice to sums and products open import Type open import Function.NP open import Function.Extensionality open import Data.Nat open import Data.Product open import Data.Fin using (Fin) open import Explore.Core open import Explore.Properties open import Relation.Binary.PropositionalEquality.NP open import Type.Identities open import HoTT open ≡-Reasoning open Adequacy _≡_ module Explore.BigDistr {A B : ★₀} {Πᴬ : Product A} (adequate-Πᴬ : Adequate-product Πᴬ) {Σᴮ : Sum B} (adequate-Σᴮ : Adequate-sum Σᴮ) {Σᴬᴮ : Sum (A → B)} (adequate-Σᴬᴮ : Adequate-sum Σᴬᴮ) (F : A → B → ℕ) {{_ : UA}} {{_ : FunExt}} where big-distr : Πᴬ (Σᴮ ∘ F) ≡ Σᴬᴮ λ f → Πᴬ (F ˢ f) big-distr = Fin-injective ( Fin (Πᴬ (Σᴮ ∘ F)) ≡⟨ adequate-Πᴬ (Σᴮ ∘ F) ⟩ Π A (Fin ∘ Σᴮ ∘ F) ≡⟨ Π=′ A (adequate-Σᴮ ∘ F) ⟩ Π A (λ x → Σ B (Fin ∘ F x)) ≡⟨ ΠΣ-comm ⟩ Σ (Π A (const B)) (λ f → Π A (λ x → Fin (F x (f x)))) ≡⟨ Σ=′ (A → B) (λ f → ! (adequate-Πᴬ (F ˢ f))) ⟩ Σ (A → B) (λ f → Fin (Πᴬ (F ˢ f))) ≡⟨ ! (adequate-Σᴬᴮ (λ f → Πᴬ (F ˢ f))) ⟩ Fin (Σᴬᴮ (λ f → Πᴬ (F ˢ f))) ∎)
{ "alphanum_fraction": 0.4952727273, "avg_line_length": 29.8913043478, "ext": "agda", "hexsha": "e24ead9eaf202a2a65c15f96c2ad64f407f0df03", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/BigDistr.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/BigDistr.agda", "max_line_length": 61, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/BigDistr.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 589, "size": 1375 }
module FFI.Data.ByteString where {-# FOREIGN GHC import qualified Data.ByteString #-} postulate ByteString : Set {-# COMPILE GHC ByteString = type Data.ByteString.ByteString #-}
{ "alphanum_fraction": 0.7569060773, "avg_line_length": 22.625, "ext": "agda", "hexsha": "670c5234825fdba2a6aca247ad0185ebf8707233", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "XanderYZZ/luau", "max_forks_repo_path": "prototyping/FFI/Data/ByteString.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "XanderYZZ/luau", "max_issues_repo_path": "prototyping/FFI/Data/ByteString.agda", "max_line_length": 64, "max_stars_count": 1, "max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TheGreatSageEqualToHeaven/luau", "max_stars_repo_path": "prototyping/FFI/Data/ByteString.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z", "num_tokens": 32, "size": 181 }
module BadRefl where open import AgdaPrelude plus = natElim ( \ _ -> Nat -> Nat ) -- motive ( \ n -> n ) -- case for Zero ( \ p rec n -> Succ (rec n) ) -- case for Succ -- the other direction requires induction on N: postulate pNPlus0isN : (n : Nat) -> Eq Nat (plus n Zero) n -- the other direction requires induction on N: succPlus : (n : Nat) -> Eq Nat (Succ n) (plus (Succ n) Zero) succPlus = (\n -> pNPlus0isN (Succ n))
{ "alphanum_fraction": 0.5681341719, "avg_line_length": 25.1052631579, "ext": "agda", "hexsha": "09b6474bfa499cb9055fad4166abacf875289c5a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "JoeyEremondi/lambda-pi-constraint", "max_forks_repo_path": "thesisExamples/BadRefl.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "JoeyEremondi/lambda-pi-constraint", "max_issues_repo_path": "thesisExamples/BadRefl.agda", "max_line_length": 61, "max_stars_count": 16, "max_stars_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "JoeyEremondi/lambda-pi-constraint", "max_stars_repo_path": "thesisExamples/BadRefl.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-05T20:21:46.000Z", "max_stars_repo_stars_event_min_datetime": "2017-03-16T11:14:56.000Z", "num_tokens": 150, "size": 477 }
data ⊥ : Set where -- keep this on the first line!! Type = Set -- This should not be gobbled up under the data declaration -- Andreas, 2021-04-15, issue #1145 -- Allow stacking of layout keywords on the same line. -- This files contains tests for the new layout rules -- and also tests from debugging the original implementation. -- -- Some original failures where influenced by whether -- there were comments or black lines, so please don't -- "clean up" this file. postulate A : Set; B : Set C : Set -- First example private postulate -- Bar D : Set _>>_ : Set → Set → Set module _ where private {- this block comment removes the line breaks between the layout keywords -} postulate D1 : Set E1 : Set -- Second example private module PM where -- stack module PMM where private module PMPM1 where module PMPM2 where private -- stack module PMPM2M where module PMM2 where -- Testing whether do-notation still works test = do A; B C let-example = let X = A in B do-example = do Set where Y : Set Y = A F = Set private doey = do Set where postulate poey : Set E = Set
{ "alphanum_fraction": 0.6379310345, "avg_line_length": 19.3333333333, "ext": "agda", "hexsha": "9d049f1a803aff7cb721c35ade1b61ab1ed2b1cb", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "cagix/agda", "max_forks_repo_path": "test/Succeed/Issue1145.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "cagix/agda", "max_issues_repo_path": "test/Succeed/Issue1145.agda", "max_line_length": 71, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "cagix/agda", "max_stars_repo_path": "test/Succeed/Issue1145.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 327, "size": 1218 }
{-# OPTIONS --copatterns #-} module examplesPaperJFP.ExampleDrawingProgram where open import Size open import Data.Bool.Base open import Data.Char.Base open import Data.Nat.Base hiding (_⊓_; _+_; _*_) open import Data.List.Base hiding (_++_) open import Data.Integer.Base hiding (suc) open import Data.String.Base open import Data.Maybe.Base open import Agda.Builtin.Char using (primCharEquality) open import Function open import SizedIO.Base open import SizedIO.IOGraphicsLib hiding (translateIOGraphics) renaming (translateIOGraphicsLocal to translateNative) open import NativeInt --PrimTypeHelpers open import NativeIO open import examplesPaperJFP.triangleRightOperator integerLess : ℤ → ℤ → Bool integerLess x y with ∣(y - (x ⊓ y))∣ ... | zero = true ... | z = false line : Point → Point → Graphic line p newpoint = withColor red (polygon (nativePoint x y ∷ nativePoint a b ∷ nativePoint (a + xAddition) (b + yAddition) ∷ nativePoint (x + xAddition) (y + yAddition) ∷ [] ) ) where x = nativeProj1Point p y = nativeProj2Point p a = nativeProj1Point newpoint b = nativeProj2Point newpoint diffx = + ∣ (a - x) ∣ diffy = + ∣ (b - y) ∣ diffx*3 = diffx * (+ 3) diffy*3 = diffy * (+ 3) condition = (integerLess diffx diffy*3) ∧ (integerLess diffy diffx*3) xAddition = if condition then + 2 else + 1 yAddition = if condition then + 2 else + 1 State = Maybe Point mutual loop : ∀{i} → Window → State → IOGraphics i Unit force (loop w s) = exec' (getWindowEvent w) λ e → winEvtHandler w s e winEvtHandler : ∀{i} → Window → State → Event → IOGraphics i Unit winEvtHandler w s (Key c t) = if primCharEquality c 'x' then (exec (closeWindow w) return) else loop w s winEvtHandler w s (MouseMove p₂) = s ▹ λ { nothing → loop w (just p₂) ; (just p₁) → exec (drawInWindow w (line p₁ p₂)) λ _ → loop w (just p₂) } winEvtHandler w s _ = loop w s program : ∀{i} → IOGraphics i Unit program = exec (openWindow "Drawing Prog" nothing 1000 1000 nativeDrawGraphic nothing) λ win → loop win nothing translateIOGraphics : IOGraphics ∞ Unit → NativeIO Unit translateIOGraphics = translateIO translateNative main : NativeIO Unit main = nativeRunGraphics (translateIOGraphics program)
{ "alphanum_fraction": 0.6002269289, "avg_line_length": 31.1058823529, "ext": "agda", "hexsha": "35af9b9f4500759fd3d2fc930fe7c5898d6bfbad", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "examples/examplesPaperJFP/ExampleDrawingProgram.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "examples/examplesPaperJFP/ExampleDrawingProgram.agda", "max_line_length": 118, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "examples/examplesPaperJFP/ExampleDrawingProgram.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 720, "size": 2644 }
-- Andreas, 2015-08-18 Test case for COMPILED_DATA on record -- open import Common.String open import Common.IO infixr 4 _,_ infixr 2 _×_ record _×_ (A B : Set) : Set where constructor _,_ field proj₁ : A proj₂ : B open _×_ public {-# COMPILED_DATA _×_ (,) (,) #-} -- Note: could not get this to work for Σ. -- Also, the universe-polymorphic version of _×_ would require more trickery. swap : ∀{A B : Set} (p : A × B) → B × A swap (x , y) = y , x swap' : ∀{A B : Set} (p : A × B) → B × A swap' p = proj₂ p , proj₁ p main = putStrLn (proj₁ (swap (swap' (swap ("no" , "yes")))))
{ "alphanum_fraction": 0.602006689, "avg_line_length": 20.6206896552, "ext": "agda", "hexsha": "3b96e4cb7feae09f9e74d018b2b34aae68b57510", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Compiler/simple/CompiledRecord.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Compiler/simple/CompiledRecord.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Compiler/simple/CompiledRecord.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 217, "size": 598 }
module TooManyFields where postulate X : Set record D : Set where field x : X d : X -> D d x = record {x = x; y = x}
{ "alphanum_fraction": 0.5967741935, "avg_line_length": 10.3333333333, "ext": "agda", "hexsha": "df01cb6aff978530ee26aa1d5bc4fbe11d2f1bc4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/TooManyFields.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Fail/TooManyFields.agda", "max_line_length": 27, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Fail/TooManyFields.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 44, "size": 124 }
module FRP.JS.Level where infixl 6 _⊔_ postulate Level : Set zero : Level suc : Level → Level _⊔_ : Level → Level → Level {-# COMPILED_JS zero 0 #-} {-# COMPILED_JS suc function(x) { return x + 1; } #-} {-# COMPILED_JS _⊔_ function(x) { return function(y) { return Math.max(x,y); }; } #-} {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} {-# BUILTIN LEVELMAX _⊔_ #-}
{ "alphanum_fraction": 0.5894495413, "avg_line_length": 22.9473684211, "ext": "agda", "hexsha": "c1b9953dbcad1c2f097f7b6ec69de537d07565af", "lang": "Agda", "max_forks_count": 7, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z", "max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z", "max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_forks_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_forks_repo_name": "agda/agda-frp-js", "max_forks_repo_path": "src/agda/FRP/JS/Level.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_issues_repo_name": "agda/agda-frp-js", "max_issues_repo_path": "src/agda/FRP/JS/Level.agda", "max_line_length": 86, "max_stars_count": 63, "max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_stars_repo_licenses": [ "MIT", "BSD-3-Clause" ], "max_stars_repo_name": "agda/agda-frp-js", "max_stars_repo_path": "src/agda/FRP/JS/Level.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z", "num_tokens": 149, "size": 436 }
module CoPatWith where data Maybe (A : Set) : Set where nothing : Maybe A just : A -> Maybe A data _×_ (A B : Set) : Set where _,_ : A -> B -> A × B record CoList (A : Set) : Set where constructor inn field out : Maybe (A × CoList A) open CoList module With where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map f l) with out l out (map f l) | nothing = nothing out (map f l) | just (a , as) = just (f a , map f as) module NoWith where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map {A = A}{B = B} f l) = map' f l (out l) where outmap : (f : A -> B)(l : CoList A)(outl : Maybe (A × CoList A)) -> Maybe (B × CoList B) outmap f l nothing = nothing outmap f l (just (a , as)) = just (f a , map f as) module With2 where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map f (inn l)) with l out (map f (inn .nothing)) | nothing = nothing out (map f (inn .(just (a , as)))) | just (a , as) = just (f a , map f as) module NoWith2 where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map {A = A}{B = B} f l) = map' f l (out l) where outmap : (f : A -> B)(l : CoList A)(outl : Maybe (A × CoList A)) -> Maybe (B × CoList B) outmap f (inn .nothing) nothing = nothing outmap f (inn .(just (a , as))) (just (a , as)) = just (f a , map f as)
{ "alphanum_fraction": 0.5193253689, "avg_line_length": 30.9347826087, "ext": "agda", "hexsha": "7d2c99631d61f988504ef371bebb5808828bf0a7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/features/CoPatWith.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/features/CoPatWith.agda", "max_line_length": 98, "max_stars_count": 1, "max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "np/agda-git-experiment", "max_stars_repo_path": "test/features/CoPatWith.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 529, "size": 1423 }
module _ where open import Common.Prelude hiding (_>>=_) open import Common.Reflection infix -100 This:_ this:_ data This:_ {a} {A : Set a} : A → Set where this:_ : ∀ x → This: x macro runT : Tactic → Tactic runT m = m evalT : ∀ {a} {A : Set a} → TC A → Tactic evalT m hole = m >>= quoteTC >>= unify hole -- The context on the rhs of each of the two functions below is the same, a single String Γ = vArg (def (quote String) []) ∷ [] context-Γ₀ : String → This: Γ context-Γ₀ s = this: evalT getContext module _ (S : String) where context-Γ₁ : This: Γ context-Γ₁ = this: evalT getContext replicate : {A : Set} → Nat → A → List A replicate zero x = [] replicate (suc n) x = x ∷ replicate n x f-type : Term f-type = def (quote String) [] f-pats : Nat → List (Arg Pattern) f-pats n = replicate n (vArg (var "_")) f-term : Nat → Term f-term n = var n [] defineFresh : Nat → Nat → TC QName defineFresh #pats #term = freshName "f" >>= λ f → define (vArg f) (funDef f-type (clause (f-pats #pats) (f-term #term) ∷ [])) >>= λ _ → returnTC f freshFun : Nat → Nat → TC Bool freshFun #pats #term = catchTC (defineFresh #pats #term >>= λ _ → returnTC true) (returnTC false) -- Check that the pattern list must be of length 0 -- and the context features 1 available variable. define-Γ₀-0-0 : String → This: true define-Γ₀-0-0 s = this: evalT (freshFun 0 0) define-Γ₀-1-0 : String → This: false define-Γ₀-1-0 s = this: evalT (freshFun 1 0) define-Γ₀-1-1 : String → This: false define-Γ₀-1-1 s = this: evalT (freshFun 0 1) module _ (S : String) where define-Γ₁-0-0 : This: true define-Γ₁-0-0 = this: evalT (freshFun 0 0) define-Γ₁-0-1 : This: false define-Γ₁-0-1 = this: evalT (freshFun 0 1) define-Γ₁-1-0 : This: false define-Γ₁-1-0 = this: evalT (freshFun 1 0) f₀ : String → String f₀ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f []) f₁ : String → String f₁ = λ s → runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f []) f₂ : String → String f₂ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f []) where x = 0
{ "alphanum_fraction": 0.6303520457, "avg_line_length": 25.0238095238, "ext": "agda", "hexsha": "e0ed097006e690db524deea6bb30ffe866b89d6c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1833.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/Issue1833.agda", "max_line_length": 89, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/Issue1833.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 779, "size": 2102 }
open import Prelude open import Level using (_⊔_; Lift; lift) renaming (suc to ls; zero to lz) open import Data.String using (String) open import Data.Maybe using (Maybe; nothing; just) open import Data.Nat using (_≤_) open import RW.Data.RTrie.Decl module RW.Data.RTrie.Lookup where postulate trie-err : ∀{a}{A : Set a} → String → A open import RW.Utils.Monads open Monad {{...}} open Eq {{...}} import RW.Data.PMap (RTermᵢ ⊥) as IdxMap import RW.Data.PMap ℕ as ℕmap ------------------------------- -- Some type boilerplate Label : Set Label = ℕ ⊎ Name Lst : Set Lst = ℕmap.to (RTerm ⊥) × Maybe Label Lst-empty : Lst Lst-empty = ℕmap.empty , nothing Lst-open : Lst → (ℕmap.to (RTerm ⊥) × Maybe Name) Lst-open (e , l) = (e , lbl-join l) where lbl-join : Maybe Label → Maybe Name lbl-join nothing = nothing lbl-join (just (i1 _)) = nothing lbl-join (just (i2 a)) = just a --------------------------- -- Lookup monad L : Set → Set L = Reader (List Lst) ---------------------------- -- Rule application -- Note how a mismatch erases labels! applyBRule1 : Rule → Lst → Lst applyBRule1 (Gr x) (e , _) = e , just (i1 x) applyBRule1 (Tr x y) (e , just (i1 l)) with x ≟-ℕ l ...| yes _ = e , just (i1 y) ...| no _ = e , nothing applyBRule1 (Tr x y) (e , just (i2 _)) = e , nothing applyBRule1 (Fr x y) (e , just (i1 l)) with x ≟-ℕ l ...| yes _ = e , just (i2 y) ...| no _ = e , nothing applyBRule1 (Fr _ _) (e , just (i2 _)) = e , nothing applyBRule1 _ (e , nothing) = e , nothing applyBRule : Rule → L (List Lst) applyBRule r = reader-ask >>= return ∘ (Prelude.map (applyBRule1 r)) ruleList : List Rule → L (List Lst) ruleList rs = mapM applyBRule rs >>= return ∘ concat where isNothing : ∀{a}{A : Set a} → Maybe A → Bool isNothing nothing = true isNothing _ = false prune : List Lst → List Lst prune = Prelude.filter (isNothing ∘ p2) ------------------------------ -- Actual Lookup map-filter : ∀{a}{A B : Set a} → (B → Bool) → (A → B) → List A → List B map-filter p f = foldr (λ h r → let x = f h in ite (p x) (x ∷ r) r) [] where ite : ∀{a}{A : Set a} → Bool → A → A → A ite true t _ = t ite false _ e = e mutual -- TODO: refine this, only apply the rules after validating and adding bindings. lkup-inst1 : RTerm ⊥ → ℕ × List Rule → L (List Lst) lkup-inst1 k (s , r) = ruleList r >>= return ∘ map-filter (isValid s k) (addUnbound s k) where addUnbound : ℕ → RTerm ⊥ → Lst → Lst addUnbound s k (e , l) = (ℕmap.alter (maybe just (just k)) s e , l) toBool : ∀{a}{A : Set a} → Dec A → Bool toBool (yes _) = true toBool (no _) = false isValid : ℕ → RTerm ⊥ → Lst → Bool isValid s k (e , l) = toBool (ℕmap.lkup s e ≟2 just k) where _≟2_ : (a₁ a₂ : Maybe (RTerm ⊥)) → Dec (a₁ ≡ a₂) _≟2_ a b = Eq.cmp eq-Maybe a b -- Looks up a term given a list of instantiations. -- This is not, by far, a lookup function. We're just adding all possibilities together. lkup-inst : RTerm ⊥ → List (ℕ × List Rule) → L (List Lst) lkup-inst t [] = return [] lkup-inst t rs = mapM (lkup-inst1 t) rs >>= return ∘ concat -- Looks a list of RTerms in their respecive cells. {-# TERMINATING #-} lkup-list : List (RTerm ⊥ × Cell) → L (List Lst) lkup-list [] = return [] lkup-list ((t , (d , mh) , bs) ∷ ts) = lkup-aux t (Fork (((d , mh) , bs) ∷ [])) >>= λ s₁ → (reader-local (_++_ s₁) $ lkup-list ts) >>= return ∘ (_++_ s₁) lkup-aux : RTerm ⊥ → RTrie → L (List Lst) lkup-aux _ (Leaf r) = ruleList r lkup-aux k (Fork (((d , rs) , bs) ∷ [])) = let tid , tr = out k in lkup-inst k bs -- If tid ∉ mh, we run the lookup again, but in the default branch. -- Otherwise, we run a lkup-list. >>= λ r → maybe (lkup≡just tr) (lkup-aux k d) (IdxMap.lkup tid rs) >>= return ∘ (_++_ r) where lkup≡just : List (RTerm ⊥) → RTrie → L (List Lst) lkup≡just [] (Leaf r) = ruleList r lkup≡just _ (Leaf _) = return [] lkup≡just tr (Fork ms) = lkup-list (zip tr ms) lkup-aux _ _ = trie-err "lkup-aux takes 1-cell forks" -- Interfacing lookup : RTerm ⊥ → RTrie → List (ℕmap.to (RTerm ⊥) × Name) lookup t bt = accept (Prelude.map Lst-open (lkup-aux t bt (Lst-empty ∷ []))) where accept : ∀{a}{A : Set a} → List (A × Maybe Name) → List (A × Name) accept [] = [] accept ((a , just b) ∷ hs) = (a , b) ∷ accept hs accept (_ ∷ hs) = accept hs
{ "alphanum_fraction": 0.5326178451, "avg_line_length": 31.4701986755, "ext": "agda", "hexsha": "c4d55d13bcf341be47f723782eaef61516c89f9d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "VictorCMiraldo/agda-rw", "max_forks_repo_path": "RW/Data/RTrie/Lookup.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "VictorCMiraldo/agda-rw", "max_issues_repo_path": "RW/Data/RTrie/Lookup.agda", "max_line_length": 92, "max_stars_count": 16, "max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "VictorCMiraldo/agda-rw", "max_stars_repo_path": "RW/Data/RTrie/Lookup.agda", "max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z", "max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z", "num_tokens": 1667, "size": 4752 }
module _ where open import Agda.Builtin.Bool open import Agda.Builtin.Equality postulate A : Set f : .A → A g : A → A mutual X : Bool → .A → A X = _ Y : .A → A → A Y = _ -- should be solved! foo : .(x : A) {y : A} → X true x ≡ g (Y x y) foo _ = refl -- this prunes both x and y from Y, -- so later Y cannot be solved to \ .x y → f x bar : .(x : A){y : A} → f x ≡ Y x y bar _ = refl
{ "alphanum_fraction": 0.5228915663, "avg_line_length": 15.9615384615, "ext": "agda", "hexsha": "b02514239137258310806c03b3e52d64f94dd81c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue2450.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue2450.agda", "max_line_length": 48, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue2450.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 170, "size": 415 }
------------------------------------------------------------------------ -- Some derivable properties ------------------------------------------------------------------------ open import Algebra module Algebra.Props.Ring (r : Ring) where open Ring r import Relation.Binary.EqReasoning as EqR; open EqR setoid open import Data.Function open import Data.Product -‿*-distribˡ : ∀ x y → - x * y ≈ - (x * y) -‿*-distribˡ x y = begin - x * y ≈⟨ sym $ proj₂ +-identity _ ⟩ - x * y + 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₂ -‿inverse _) ⟩ - x * y + (x * y + - (x * y)) ≈⟨ sym $ +-assoc _ _ _ ⟩ - x * y + x * y + - (x * y) ≈⟨ sym (proj₂ distrib _ _ _) ⟨ +-pres-≈ ⟩ refl ⟩ (- x + x) * y + - (x * y) ≈⟨ (proj₁ -‿inverse _ ⟨ *-pres-≈ ⟩ refl) ⟨ +-pres-≈ ⟩ refl ⟩ 0# * y + - (x * y) ≈⟨ proj₁ zero _ ⟨ +-pres-≈ ⟩ refl ⟩ 0# + - (x * y) ≈⟨ proj₁ +-identity _ ⟩ - (x * y) ∎ -‿*-distribʳ : ∀ x y → x * - y ≈ - (x * y) -‿*-distribʳ x y = begin x * - y ≈⟨ sym $ proj₁ +-identity _ ⟩ 0# + x * - y ≈⟨ sym (proj₁ -‿inverse _) ⟨ +-pres-≈ ⟩ refl ⟩ - (x * y) + x * y + x * - y ≈⟨ +-assoc _ _ _ ⟩ - (x * y) + (x * y + x * - y) ≈⟨ refl ⟨ +-pres-≈ ⟩ sym (proj₁ distrib _ _ _) ⟩ - (x * y) + x * (y + - y) ≈⟨ refl ⟨ +-pres-≈ ⟩ (refl ⟨ *-pres-≈ ⟩ proj₂ -‿inverse _) ⟩ - (x * y) + x * 0# ≈⟨ refl ⟨ +-pres-≈ ⟩ proj₂ zero _ ⟩ - (x * y) + 0# ≈⟨ proj₂ +-identity _ ⟩ - (x * y) ∎
{ "alphanum_fraction": 0.3446601942, "avg_line_length": 44.5405405405, "ext": "agda", "hexsha": "4de1f3af998e6a211f94992e2cc7bd22a6308aae", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Algebra/Props/Ring.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Algebra/Props/Ring.agda", "max_line_length": 93, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Algebra/Props/Ring.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 636, "size": 1648 }
module Container.Foldable where open import Prelude record Foldable {a b w} (F : Set a → Set b) : Set (lsuc w ⊔ lsuc a ⊔ b) where field foldMap : ∀ {A}{W : Set w} {{MonW : Monoid W}} → (A → W) → F A → W overlap {{super}} : Functor F open Foldable {{...}} public fold : ∀ {a w} {W : Set w} {F : Set w → Set a} {{FoldF : Foldable F}} {{MonW : Monoid W}} → F W → W fold = foldMap id minimum : ∀ {a w} {W : Set w} {F : Set w → Set a} {{FoldF : Foldable F}} {{OrdW : Ord W}} → F W → Maybe W minimum = foldMap {{MonW = monoid}} just where monoid : Monoid _ Monoid.mempty monoid = nothing Monoid._<>_ monoid (just x) (just y) = just (min x y) Monoid._<>_ monoid (just x) nothing = just x Monoid._<>_ monoid nothing (just y) = just y Monoid._<>_ monoid nothing nothing = nothing maximum : ∀ {a w} {W : Set w} {F : Set w → Set a} {{FoldF : Foldable F}} {{OrdW : Ord W}} → F W → Maybe W maximum = foldMap {{MonW = monoid}} just where monoid : Monoid _ Monoid.mempty monoid = nothing Monoid._<>_ monoid (just x) (just y) = just (max x y) Monoid._<>_ monoid (just x) nothing = just x Monoid._<>_ monoid nothing (just y) = just y Monoid._<>_ monoid nothing nothing = nothing --- Instances --- instance FoldableList : ∀ {a w} → Foldable {a = a} {w = w} List foldMap {{FoldableList}} f = foldr (λ x w → f x <> w) mempty FoldableMaybe : ∀ {a w} → Foldable {a = a} {w = w} Maybe foldMap {{FoldableMaybe}} = maybe mempty
{ "alphanum_fraction": 0.5920431558, "avg_line_length": 33.7045454545, "ext": "agda", "hexsha": "f18c88900b3ced19729fdc8112ec9862e95871a0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lclem/agda-prelude", "max_forks_repo_path": "src/Container/Foldable.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lclem/agda-prelude", "max_issues_repo_path": "src/Container/Foldable.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lclem/agda-prelude", "max_stars_repo_path": "src/Container/Foldable.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 537, "size": 1483 }
module Bin where open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Naturals using (ℕ; zero; suc; _+_; _*_) -- 2進数の表現 data Bin : Set where ⟨⟩ : Bin _O : Bin → Bin _I : Bin → Bin -- 2進数のインクリメント inc : Bin → Bin inc ⟨⟩ = ⟨⟩ I inc (b O) = b I inc (b I) = inc b O _ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O _ = refl _ : inc (⟨⟩ O O O O) ≡ ⟨⟩ O O O I _ = refl _ : inc (⟨⟩ O O O I) ≡ ⟨⟩ O O I O _ = refl _ : inc (⟨⟩ O O I O) ≡ ⟨⟩ O O I I _ = refl _ : inc (⟨⟩ O O I I) ≡ ⟨⟩ O I O O _ = refl _ : inc (⟨⟩ O I O O) ≡ ⟨⟩ O I O I _ = refl -- 自然数から2進数への変換 to : ℕ → Bin to zero = ⟨⟩ O to (suc n) = inc (to n) _ : to 0 ≡ ⟨⟩ O _ = refl _ : to 1 ≡ ⟨⟩ I _ = refl _ : to 2 ≡ ⟨⟩ I O _ = refl _ : to 3 ≡ ⟨⟩ I I _ = refl _ : to 4 ≡ ⟨⟩ I O O _ = refl -- 2進数から自然数への変換 from : Bin → ℕ from ⟨⟩ = zero from (b O) = 2 * (from b) from (b I) = 2 * (from b) + 1 _ : from (⟨⟩ O) ≡ 0 _ = refl _ : from (⟨⟩ I) ≡ 1 _ = refl _ : from (⟨⟩ I O) ≡ 2 _ = refl _ : from (⟨⟩ I I) ≡ 3 _ = refl _ : from (⟨⟩ I O O) ≡ 4 _ = refl
{ "alphanum_fraction": 0.4773820982, "avg_line_length": 13.4935064935, "ext": "agda", "hexsha": "606ee96b5e3ea2f462c40c80253f2769611efb15", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "akiomik/plfa-solutions", "max_forks_repo_path": "part1/naturals/Bin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "akiomik/plfa-solutions", "max_issues_repo_path": "part1/naturals/Bin.agda", "max_line_length": 67, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "akiomik/plfa-solutions", "max_stars_repo_path": "part1/naturals/Bin.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z", "num_tokens": 550, "size": 1039 }
module TypeConstructorsWhichPreserveGuardedness3 where record ⊤ : Set where data _⊎_ (A B : Set) : Set where inj₁ : A → A ⊎ B inj₂ : B → A ⊎ B -- This should not be allowed. ℕ : Set ℕ = ⊤ ⊎ ℕ
{ "alphanum_fraction": 0.635, "avg_line_length": 15.3846153846, "ext": "agda", "hexsha": "249cb7455f47e2d1561b334eec776f14bbba372b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness3.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness3.agda", "max_line_length": 54, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness3.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 79, "size": 200 }
module plfa.Induction where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; sym) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_ ;_∎) open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_) -- @practice: exercise `operators` start -- -- 1. _+_ _*_: Unit (Zero), Associativity, Commutativity -- operator _*_ distributes over operator _+_ from the left and right. -- -- 2. x operator of matrices: Unit (Unit matrix), -- Associativity (Associativity of the Linear transformation) -- No Commutativity -- @practice: exercise `operators` end _ : (3 + 4) + 5 ≡ 3 + (4 + 5) _ = begin (3 + 4) + 5 ≡⟨⟩ 7 + 5 ≡⟨⟩ 12 ≡⟨⟩ 3 + 9 ≡⟨⟩ 3 + (4 + 5) ∎ +-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) ∎ -- examples start +-assoc-2 : ∀ (n p : ℕ) → (2 + n) + p ≡ 2 + (n + p) +-assoc-2 n p = begin (2 + n) + p ≡⟨⟩ suc (1 + n) + p ≡⟨⟩ suc ((1 + n) + p) ≡⟨ cong suc (+-assoc-1 n p) ⟩ suc (1 + (n + p)) ≡⟨⟩ 2 + (n + p) ∎ where +-assoc-1 : ∀ (n p : ℕ) → (1 + n) + p ≡ 1 + (n + p) +-assoc-1 n p = begin (1 + n) + p ≡⟨⟩ suc (0 + n) + p ≡⟨⟩ suc ((0 + n) + p) ≡⟨ cong suc (+-assoc-0 n p) ⟩ suc (0 + (n + p)) ≡⟨⟩ 1 + (n + p) ∎ where +-assoc-0 : ∀ (n p : ℕ) → (0 + n) + p ≡ 0 + (n + p) +-assoc-0 n p = begin (0 + n) + p ≡⟨⟩ n + p ≡⟨⟩ 0 + (n + p) ∎ -- examples end +-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 ∎ +-rearrange : ∀ (m n p q : ℕ) → (m + n) + (p + q) ≡ m + (n + p) + q +-rearrange m n p q = begin (m + n) + (p + q) ≡⟨ +-assoc m n (p + q) ⟩ m + (n + (p + q)) ≡⟨ cong ( m +_ ) (sym (+-assoc n p q)) ⟩ m + ((n + p) + q) ≡⟨ sym (+-assoc m (n + p) q)⟩ (m + (n + p)) + q ∎ -- @stretch: exercise `finite-+-assoc` start -- Day 0 -- Day 1 -- 0: ℕ --Day 2 -- 1: ℕ -- (0 + 0) + 0 ≡ 0 + (0 + 0) -- Day 3 -- 2: ℕ -- (0 + 0) + 1 ≡ 0 + (0 + 1) -- (0 + 1) + 0 ≡ 0 + (1 + 0) -- (0 + 1) + 1 ≡ 0 + (1 + 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) -- Day 4 -- 3 : ℕ -- (0 + 0) + 2 ≡ 0 + (0 + 2) -- (0 + 1) + 2 ≡ 0 + (1 + 2) -- (0 + 2) + 0 ≡ 0 + (2 + 0) -- (0 + 2) + 1 ≡ 0 + (2 + 1) -- (0 + 2) + 2 ≡ 0 + (2 + 2) -- (1 + 0) + 2 ≡ 1 + (0 + 2) -- (1 + 1) + 2 ≡ 1 + (1 + 2) -- (1 + 2) + 0 ≡ 1 + (2 + 0) -- (1 + 2) + 1 ≡ 1 + (2 + 1) -- (1 + 2) + 2 ≡ 1 + (2 + 2) -- (2 + 0) + 0 ≡ 2 + (0 + 0) -- (2 + 0) + 1 ≡ 2 + (0 + 1) -- (2 + 0) + 2 ≡ 2 + (0 + 2) -- (2 + 1) + 0 ≡ 2 + (1 + 0) -- (2 + 1) + 1 ≡ 2 + (1 + 1) -- (2 + 1) + 2 ≡ 2 + (1 + 2) -- (2 + 2) + 0 ≡ 2 + (2 + 0) -- (2 + 2) + 1 ≡ 2 + (2 + 1) -- (2 + 2) + 2 ≡ 2 + (2 + 2) -- @stretch: exercise `finite-+-assoc` end +-assoc' : ∀ ( m n p : ℕ ) → (m + n) + p ≡ m + (n + p) +-assoc' zero n p = refl +-assoc' (suc m) n p rewrite +-assoc' m n p = refl +-identity' : ∀ ( n : ℕ ) → n + zero ≡ n +-identity' zero = refl +-identity' (suc m) rewrite +-identity' m = refl +-suc' : ∀ ( m n : ℕ ) → m + suc n ≡ suc (m + n) +-suc' zero n = refl +-suc' (suc m) n rewrite +-suc' m n = refl +-comm' : ∀ ( m n : ℕ ) → m + n ≡ n + m +-comm' m zero rewrite +-identity' m = refl +-comm' m (suc n) rewrite +-suc' m n | +-comm' m n = refl -- with hole +-assoc'' : ∀ (m n p : ℕ ) → ( m + n ) + p ≡ m + (n + p) +-assoc'' zero n p = refl +-assoc'' (suc m) n p rewrite +-assoc'' m n p = refl -- @recommended: exercise `+-swap` start +-swap : ∀ ( m n p : ℕ ) → m + (n + p) ≡ n + (m + p) +-swap zero n p = refl +-swap (suc m) n p rewrite +-swap m n p | +-suc n (m + p) = refl -- @recommended: exercise `+-swap` end -- @recommended: exercise `*-distrib-+` start *-distrib-+ : ∀ ( m n p : ℕ ) → ( m + n ) * p ≡ m * p + n * p *-distrib-+ zero n p = refl *-distrib-+ (suc m) n p rewrite *-distrib-+ m n p | +-assoc p (m * p) (n * p) = refl -- @recommended: exercise `*-distrib-+` end -- @recommended: exercise `*-assoc` start *-assoc : ∀ ( m n p : ℕ ) → (m * n) * p ≡ m * ( n * p) *-assoc zero n p = refl *-assoc (suc m) n p rewrite *-distrib-+ n (m * n) p | *-assoc m n p = refl -- @recommended: exercise `*-assoc` end -- @practice: exercise `*-comm` start *-zeroʳ : ∀ ( m : ℕ ) → m * zero ≡ zero *-zeroʳ zero = refl *-zeroʳ ( suc m ) rewrite *-distrib-+ 1 m zero | *-zeroʳ m = refl *-suc : ∀ ( n m : ℕ ) → n + n * m ≡ n * suc m *-suc zero m = refl *-suc (suc n) m rewrite sym (*-suc n m) | sym (+-assoc m n ( n * m )) | sym ( +-assoc n m ( n * m )) | +-comm m n = refl *-comm : ∀ ( m n : ℕ ) → m * n ≡ n * m *-comm zero n rewrite *-zeroʳ n = refl *-comm (suc m) n rewrite *-distrib-+ 1 m n | +-identityʳ n | *-comm m n | *-suc n m = refl -- @practice: exercise `*-comm` end -- @practice: exercise `0∸n≡0` start 0∸n≡0 : ∀ ( n : ℕ ) → 0 ∸ n ≡ 0 0∸n≡0 zero = refl 0∸n≡0 (suc n) = refl -- @practice: exercise `0∸n≡0` end -- @practice: exercise `∸-|-assoc` start ∸-|-assoc : ∀ ( m n p : ℕ ) → m ∸ n ∸ p ≡ m ∸ ( n + p ) ∸-|-assoc zero n p rewrite 0∸n≡0 n | 0∸n≡0 p | 0∸n≡0 ( n + p ) = refl ∸-|-assoc (suc m) zero p = refl ∸-|-assoc (suc m) (suc n) p rewrite ∸-|-assoc m n p = refl -- @practice: exercise `∸-|-assoc` end -- @stretch: exercise `+*^` start ^-distribʳ-+-* : ∀ ( m n p : ℕ ) → m ^ ( n + p ) ≡ (m ^ n) * (m ^ p) ^-distribʳ-+-* m zero zero = refl ^-distribʳ-+-* m zero (suc p) rewrite +-identityʳ (m * (m ^ p)) = refl ^-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 ) ∎ ^-sucʳ : ∀ ( n p : ℕ ) → n ^ suc p ≡ n * n ^ p ^-sucʳ n p = refl ^-distribˡ-* : ∀ ( m n p : ℕ ) → (m * n) ^ p ≡ ( m ^ p ) * ( n ^ p) ^-distribˡ-* m n zero = refl ^-distribˡ-* m n (suc p) = begin (m * n) ^ ( suc p ) ≡⟨ ^-sucʳ (m * n) 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) ≡⟨ *-1234-[13][24] m n (m ^ p) (n ^ p) ⟩ (m * m ^ p ) * (n * n ^ p) ≡⟨ cong (_*_ (m * m ^ p)) (sym (^-sucʳ n p))⟩ (m * m ^ p ) * ( n ^ suc p) ≡⟨ cong (λ {x → x * (n ^ suc p)}) (^-sucʳ m p) ⟩ (m ^ suc p) * (n ^ suc p) ∎ where *-1234-[13][24] : ∀ ( a b c d : ℕ ) → a * b * c * d ≡ (a * c) * ( b * d ) *-1234-[13][24] a b c d rewrite *-assoc a b c | *-comm b c | sym (*-assoc a c b) | *-assoc (a * c) b d = refl ^-oneˡ : ∀ ( p : ℕ ) → 1 ^ p ≡ 1 ^-oneˡ zero = refl ^-oneˡ (suc p) rewrite ^-oneˡ p = refl ^-distribʳ-* : ∀ ( m n p : ℕ ) → m ^ (n * p) ≡ (m ^ n) ^ p ^-distribʳ-* m zero p rewrite ^-oneˡ p = refl ^-distribʳ-* m n zero rewrite *-zeroʳ n = refl ^-distribʳ-* m (suc n) (suc p) rewrite ^-distribʳ-+-* m p ( n * suc p) | ^-distribˡ-* m (m ^ n) p | ^-distribʳ-* m n (suc p) = begin m * ((m ^ p) * ((m ^ n) * ((m ^ n) ^ p))) ≡⟨ *-1[2[34]]-13[24] m (m ^ p) (m ^ n) ((m ^ n) ^ p) ⟩ m * (m ^ n) * ((m ^ p) * ((m ^ n) ^ p)) ∎ where *-1[2[34]]-13[24] : ∀ ( a b c d : ℕ ) → a * ( b * ( c * d ) ) ≡ a * c * ( b * d ) *-1[2[34]]-13[24] a b c d rewrite sym (*-assoc b c d) | *-comm b c | *-assoc c b d | sym (*-assoc a c (b * d)) = refl -- @stretch: exercise `+*^` end -- @stretch: exercise `Bin-laws` start data Bin : Set where ⟨⟩ : Bin _O : Bin → Bin _I : Bin → Bin inc : Bin → Bin inc (m O) = m I inc (m I) = (inc m) O inc ⟨⟩ = ⟨⟩ I to : ℕ → Bin to zero = ⟨⟩ O to (suc n) = inc (to n) from : Bin -> ℕ from (m O) = 2 * (from m) from (m I) = 2 * (from m) + 1 from ⟨⟩ = 0 comm-+-from : ∀ ( b : Bin ) → from (inc b) ≡ suc (from b) comm-+-from ⟨⟩ = refl comm-+-from (b O) rewrite sym ( +-suc' (from b) (from b + zero)) | +-assoc' (from b) (from b + 0) 1 | +-identityʳ (from b) | +-comm' (from b) 1 = refl comm-+-from (b I) rewrite +-identityʳ (from (inc b)) | +-identityʳ ( from b) | comm-+-from b | sym (+-comm' (from b) 1) | +-assoc' (from b) (from b) 1 = refl identity-to-from : ∀ ( n : ℕ ) → from (to n) ≡ n identity-to-from zero = refl identity-to-from (suc n) rewrite comm-+-from (to n) | identity-to-from n = refl -- ⟨⟩ !== ⟨⟩ O -- @todo: rewrite with ∃-syntax -- @stretch: exercise `Bin-laws` end -- import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
{ "alphanum_fraction": 0.4192869913, "avg_line_length": 22.8581730769, "ext": "agda", "hexsha": "e3d280d4f5040604de0303f636d36e8821745a60", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-15T01:26:23.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-15T01:26:23.000Z", "max_forks_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lonelyhentai/workspace", "max_forks_repo_path": "fp/agda/plfa/Induction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "lonelyhentai/workspace", "max_issues_repo_path": "fp/agda/plfa/Induction.agda", "max_line_length": 91, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2a996af58d6b9be5d608ed040267398bcf72403b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lonelyhentai/workspace", "max_stars_repo_path": "fp/agda/plfa/Induction.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-15T01:26:19.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-26T16:37:38.000Z", "num_tokens": 4620, "size": 9509 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Polynomials.UnivariateFun.Base where open import Cubical.Algebra.CommRing.Instances.Polynomials.UnivariatePolyFun public {- The Univariate Functional Polynomials over a CommRing A is a CommRing. The base type is define using almost null sequences ie functions. This definition enables to defined a direct sum indexed by ℕ. Thus base type and the AbGroup part of the CommRing is define an instance of the more general Direct Sum one which can be found here : -} open import Cubical.Algebra.DirectSum.DirectSumFun.Base {- On this definition of the Direct Sum, it is possible to raise a Graded Ring structure. Then complete it to be a CommRing. Those version of the polynomials are hence a instance of this graded ring structure. see : for the details of the constructions -} open import Cubical.Algebra.GradedRing.DirectSumFun
{ "alphanum_fraction": 0.8, "avg_line_length": 31.4285714286, "ext": "agda", "hexsha": "05b261f580d396bfef96cf7f2f0bda64a2df7459", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Algebra/Polynomials/UnivariateFun/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Algebra/Polynomials/UnivariateFun/Base.agda", "max_line_length": 86, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Algebra/Polynomials/UnivariateFun/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 197, "size": 880 }
{- Part 2: Transport and composition • Cubical transport • Subst as a special case of cubical transport • Path induction from subst • Homogeneous composition (hcomp) • Binary composition of paths as special case of hcomp -} {-# OPTIONS --cubical #-} module Part2 where open import Part1 -- While path types are great for reasoning about equality they don't -- let us transport along paths between types or even compose paths. -- Furthermore, as paths are not inductively defined we don't -- automatically get an induction principle for them. In order to -- remedy this Cubical Agda also has a built-in (generalized) -- transport operation and homogeneous composition operation from -- which the induction principle (and much more!) is derivable. -- The basic operation is called transp and we will soon explain it, -- but let's first focus on the special case of cubical transport: transport : A ≡ B → A → B transport p a = transp (λ i → p i) i0 a -- This is a more primitive operation than "transport" in HoTT as it -- only lets us turn a path into a function. However, the transport of -- HoTT can easily be proved from cubical transport and in order to -- avoid a name clash we call it "subst": subst : (B : A → Type ℓ') {x y : A} (p : x ≡ y) → B x → B y subst B p pa = transport (λ i → B (p i)) pa -- The transp operation is a generalized transport in the sense that -- it lets us specify where the transport is the identity function. -- The general type of transp is: -- -- transp : (A : I → Type ℓ) (r : I) (a : A i0) → A i1 -- -- There is an additional side condition which to be satisfied for -- Cubical Agda to typecheck "transp A r a". This is that A has to be -- "constant" on r. This means that A should be a constant function -- whenever r = i1 is satisfied. This side condition is vacuously true -- when r = i0, so there is nothing to check when writing transport as -- above. However, when r is equal to i1 the transp function will -- compute as the identity function. -- -- transp A i1 a = a -- -- Having this extra generality is useful for quite technical reasons, -- for instance we can easily relate a with its transport over p: transportFill : (p : A ≡ B) (a : A) → PathP (λ i → p i) a (transport p a) transportFill p a i = transp (λ j → p (i ∧ j)) (~ i) a -- Another result that follows easily from transp is that transporting -- in a constant family is the identity function (up to a path). Note -- that this is *not* proved by refl. This is maybe not surprising as -- transport is not defined by pattern-matching on p. transportRefl : (x : A) → transport refl x ≡ x transportRefl {A = A} x i = transp (λ _ → A) i x -- Having transp lets us prove many more useful lemmas like this. For -- details see: -- -- Cubical.Foundations.Transport -- -- For experts: the file -- -- Cubical.Foundations.CartesianKanOps -- -- contains a reformulation of these operations which might be useful -- for people familiar with "cartesian" cubical type theory. -- We can also define the J eliminator (aka path induction) J : {x : A} (P : (z : A) → x ≡ z → Type ℓ'') (d : P x refl) {y : A} (p : x ≡ y) → P y p J {x = x} P d p = subst (λ X → P (fst X) (snd X)) (isContrSingl x .snd (_ , p)) d -- Unfolded version: -- -- transport (λ i → P (p i) (λ j → p (i ∧ j))) d -- So J is provable, but it doesn't satisfy the computation rule of -- refl definitionally as _≡_ is not inductively defined. See -- exercises for how to prove it. Not having this hold definitionally -- is almost never a problem in practice as the cubical primitives -- satisfy many new definitional equalities (c.f. cong). -- As we now have J we can define path concatenation and many more -- things, however this is not the way to do things in Cubical -- Agda. One of the key features of cubical type theory is that the -- transp primitive reduces differently for different types formers -- (see CCHM or the Cubical Agda paper for details). For paths it -- reduces to another primitive operation called hcomp. This primitive -- is much better suited for concatenating paths than J as it is much -- more general. In particular, it lets us compose multiple higher -- dimensional cubes directly. We will explain it by example. -- In order to compose two paths we write: compPath : {x y z : A} → x ≡ y → y ≡ z → x ≡ z compPath {x = x} p q i = hcomp (λ j → λ { (i = i0) → x ; (i = i1) → q j }) (p i) -- This is best understood with the following drawing: -- -- x z -- ^ ^ -- ¦ ¦ -- x ¦ ¦ q j -- ¦ ¦ -- x ----------> y -- p i -- -- In the drawing the direction i goes left-to-right and j goes -- bottom-to-top. As we are constructing a path from x to z along i we -- have i : I in the context already and we put p i as bottom. The -- direction j that we are doing the composition in is abstracted in -- the first argument to hcomp. -- These are related to lifting conditions for Kan cubical sets. -- A more natural form of composition of paths in Cubical Agda is -- ternary composition: -- -- x w -- ^ ^ -- ¦ ¦ -- p (~ j) ¦ ¦ r j -- ¦ ¦ -- y ----------> z -- q i -- -- This is written p ∙∙ q ∙∙ r in the agda/cubical library (∙ is "\.") -- and implemented by: _∙∙_∙∙_ : {x y z w : A} → x ≡ y → y ≡ z → z ≡ w → x ≡ w (p ∙∙ q ∙∙ r) i = hcomp (λ j → λ { (i = i0) → p (~ j) ; (i = i1) → r j }) (q i) -- Note that we can easily define mixfix operators with many arguments -- in Agda. -- Using this we can define compPath much slicker: _∙_ : {x y z : A} → x ≡ y → y ≡ z → x ≡ z p ∙ q = refl ∙∙ p ∙∙ q -- To prove algebraic properties of this operation (in particular that -- it's a groupoid) we need to talk about filling using the hfill -- operation. There is no time for this today, but the interested -- reader can consult -- -- Cubical.Foundations.GroupoidLaws -- In case there is time I might show the following briefly: doubleCompPath-filler : {x y z w : A} (p : x ≡ y) (q : y ≡ z) (r : z ≡ w) → PathP (λ j → p (~ j) ≡ r j) q (p ∙∙ q ∙∙ r) doubleCompPath-filler p q r j i = hfill (λ j → λ { (i = i0) → p (~ j) ; (i = i1) → r j }) (inS (q i)) j compPath-filler : {x y z : A} (p : x ≡ y) (q : y ≡ z) → PathP (λ j → x ≡ q j) p (p ∙ q) compPath-filler p q = doubleCompPath-filler refl p q rUnit : {x y : A} (p : x ≡ y) → p ≡ p ∙ refl rUnit p i j = compPath-filler p refl i j -- Having hcomp as a primitive operation lets us prove many things -- very directly. For instance, we can prove that any proposition is -- also a set using a higher dimensional hcomp. isProp→isSet : isProp A → isSet A isProp→isSet h a b p q j i = hcomp (λ k → λ { (i = i0) → h a a k ; (i = i1) → h a b k ; (j = i0) → h a (p i) k ; (j = i1) → h a (q i) k }) a -- Geometric picture: start with a square with a everywhere as base, -- then change its sides so that they connect p with q over refl_a and -- refl_b. isPropIsProp : isProp (isProp A) isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i isPropIsSet : isProp (isSet A) isPropIsSet h1 h2 i x y = isPropIsProp (h1 x y) (h2 x y) i -- In order to understand what the second argument to hcomp is one -- should read about partial elements. We refer the interested reader -- to the Cubical Agda documentation: -- -- https://agda.readthedocs.io/en/v2.6.1.3/language/cubical.html#partial-elements -- -- However, for beginners one doesn't need to write hcomp to prove -- thing as the library provide many basic lemmas. In particular, the -- library provides equational reasoning combinators as in regular -- Agda which let us write things like: -- -- inverseUniqueness : (r : R) → isProp (Σ[ r' ∈ R ] r · r' ≡ 1r) -- inverseUniqueness r (r' , rr'≡1) (r'' , rr''≡1) = Σ≡Prop (λ _ → is-set _ _) path -- where -- path : r' ≡ r'' -- path = r' ≡⟨ sym (·Rid _) ⟩ -- r' · 1r ≡⟨ cong (r' ·_) (sym rr''≡1) ⟩ -- r' · (r · r'') ≡⟨ ·Assoc _ _ _ ⟩ -- (r' · r) · r'' ≡⟨ cong (_· r'') (·-comm _ _) ⟩ -- (r · r') · r'' ≡⟨ cong (_· r'') rr'≡1 ⟩ -- 1r · r'' ≡⟨ ·Lid _ ⟩ -- r'' ∎
{ "alphanum_fraction": 0.6134722387, "avg_line_length": 38.3954545455, "ext": "agda", "hexsha": "771033f3a4c14f012d0fe6465d7e2a0a4afd7961", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9a510959fb0e6da9bcc6b0faa0dea76a2821bbdb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "EgbertRijke/EPIT-2020", "max_forks_repo_path": "04-cubical-type-theory/material/Part2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9a510959fb0e6da9bcc6b0faa0dea76a2821bbdb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "EgbertRijke/EPIT-2020", "max_issues_repo_path": "04-cubical-type-theory/material/Part2.agda", "max_line_length": 83, "max_stars_count": 1, "max_stars_repo_head_hexsha": "34742c0409818f8fe581ffc92992d1b5f29f6b47", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bafain/EPIT-2020", "max_stars_repo_path": "04-cubical-type-theory/material/Part2.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-03T16:28:06.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-03T16:28:06.000Z", "num_tokens": 2581, "size": 8447 }
module GUIgeneric.loadAllRepository where open import GUIgeneric.GUI open import GUIgeneric.GUIDefinitions open import GUIgeneric.GUIExample open import GUIgeneric.GUIExampleBankAccount open import GUIgeneric.GUIExampleLib open import GUIgeneric.GUIFeatures open import GUIgeneric.GUIFeaturesPart2 open import GUIgeneric.GUIFeaturesPart3 open import GUIgeneric.GUIFeaturesPart4 open import GUIgeneric.GUIFeaturesPart5 open import GUIgeneric.GUIModel open import GUIgeneric.GUIModelExample open import GUIgeneric.Prelude
{ "alphanum_fraction": 0.8905950096, "avg_line_length": 32.5625, "ext": "agda", "hexsha": "89846f61ce704b911f705d2514cfd46e4e4b4c1e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "stephanadls/state-dependent-gui", "max_forks_repo_path": "examples/GUIgeneric/loadAllRepository.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "stephanadls/state-dependent-gui", "max_issues_repo_path": "examples/GUIgeneric/loadAllRepository.agda", "max_line_length": 44, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "stephanadls/state-dependent-gui", "max_stars_repo_path": "examples/GUIgeneric/loadAllRepository.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z", "num_tokens": 113, "size": 521 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT module homotopy.SuspensionLoopSpaceInverse where {- corollary about inversion in ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X))) -} private custom-path-alg : ∀ {l} {A : Type l} {n s : A} (p q : n == s) → ! (p ∙ ! q) == ! (! q) ∙ (! p ∙ q) ∙' ! q custom-path-alg p q@idp = ap ! (∙-unit-r p) ∙ ! (∙-unit-r (! p)) Ω-!-Susp-flip-seq : ∀ {i} (X : Ptd i) (x : de⊙ X) → ! (merid x ∙ ! (merid (pt X))) =-= Ω-fmap (⊙Susp-flip X) (σloop X x) Ω-!-Susp-flip-seq X x = ! (merid x ∙ ! (merid (pt X))) =⟪ custom-path-alg (merid x) (merid (pt X)) ⟫ ! (! (merid (pt X))) ∙ (! (merid x) ∙ merid (pt X)) ∙' ! (merid (pt X)) =⟪ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (! (Susp-flip-σloop X x)) ⟫ ! (! (merid (pt X))) ∙ ap Susp-flip (σloop X x) ∙' ! (merid (pt X)) =⟪ ! (Ω-fmap-β (⊙Susp-flip X) (merid x ∙ ! (merid (pt X)))) ⟫ Ω-fmap (⊙Susp-flip X) (σloop X x) ∎∎ Ω-!-Susp-flip' : ∀ {i} (X : Ptd i) → Ω-! ∘ σloop X ∼ Ω-fmap (⊙Susp-flip X) ∘ σloop X Ω-!-Susp-flip' X x = ↯ (Ω-!-Susp-flip-seq X x) ⊙Ω-!-Susp-flip' : ∀ {i} (X : Ptd i) → ⊙Ω-! ◃⊙∘ ⊙σloop X ◃⊙idf =⊙∘ ⊙Ω-fmap (⊙Susp-flip X) ◃⊙∘ ⊙σloop X ◃⊙idf ⊙Ω-!-Susp-flip' X = ⊙seq-λ= (Ω-!-Susp-flip' X) $ !ₛ $ ↯ (Ω-!-Susp-flip-seq X (pt X)) ◃∙ ap (Ω-fmap (⊙Susp-flip X)) (!-inv-r (merid (pt X))) ◃∙ snd (⊙Ω-fmap (⊙Susp-flip X)) ◃∎ =ₛ⟨ 0 & 1 & expand (Ω-!-Susp-flip-seq X (pt X)) ⟩ custom-path-alg (merid (pt X)) (merid (pt X)) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (! (Susp-flip-σloop X (pt X))) ◃∙ ! (Ω-fmap-β (⊙Susp-flip X) (merid (pt X) ∙ ! (merid (pt X)))) ◃∙ ap (Ω-fmap (⊙Susp-flip X)) (!-inv-r (merid (pt X))) ◃∙ snd (⊙Ω-fmap (⊙Susp-flip X)) ◃∎ =ₛ⟨ 2 & 2 & !ₛ $ homotopy-naturality (λ p → ! (! (merid (pt X))) ∙ ap Susp-flip p ∙' ! (merid (pt X))) (λ p → Ω-fmap (⊙Susp-flip X) p) (λ p → ! (Ω-fmap-β (⊙Susp-flip X) p)) (!-inv-r (merid (pt X))) ⟩ custom-path-alg (merid (pt X)) (merid (pt X)) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (! (Susp-flip-σloop X (pt X))) ◃∙ ap (λ p → ! (! (merid (pt X))) ∙ ap Susp-flip p ∙' ! (merid (pt X))) (!-inv-r (merid (pt X))) ◃∙ ! (Ω-fmap-β (⊙Susp-flip X) idp) ◃∙ snd (⊙Ω-fmap (⊙Susp-flip X)) ◃∎ =ₛ⟨ 3 & 2 & pre-rotate'-in $ Ω-fmap-pt (⊙Susp-flip X) ⟩ custom-path-alg (merid (pt X)) (merid (pt X)) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (! (Susp-flip-σloop X (pt X))) ◃∙ ap (λ p → ! (! (merid (pt X))) ∙ ap Susp-flip p ∙' ! (merid (pt X))) (!-inv-r (merid (pt X))) ◃∙ ap (! (! (merid (pt X))) ∙_) (∙'-unit-l (snd (⊙Susp-flip X))) ◃∙ !-inv-l (snd (⊙Susp-flip X)) ◃∎ =ₛ₁⟨ 2 & 1 & ap-∘ (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (ap Susp-flip) (!-inv-r (merid (pt X))) ⟩ custom-path-alg (merid (pt X)) (merid (pt X)) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (! (Susp-flip-σloop X (pt X))) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (ap (ap Susp-flip) (!-inv-r (merid (pt X)))) ◃∙ ap (! (! (merid (pt X))) ∙_) (∙'-unit-l (snd (⊙Susp-flip X))) ◃∙ !-inv-l (snd (⊙Susp-flip X)) ◃∎ =ₛ⟨ 1 & 2 & ap-seq-=ₛ (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) $ !ₛ $ post-rotate-out $ pre-rotate-in $ Susp-flip-σloop-pt X ⟩ custom-path-alg (merid (pt X)) (merid (pt X)) ◃∙ ap (λ q → ! (! (merid (pt X))) ∙ q ∙' ! (merid (pt X))) (!-inv-l (merid (pt X))) ◃∙ ap (! (! (merid (pt X))) ∙_) (∙'-unit-l (! (merid (pt X)))) ◃∙ !-inv-l (! (merid (pt X))) ◃∎ =ₛ⟨ custom-path-alg-coh (merid (pt X)) ⟩ ap ! (!-inv-r (merid (pt X))) ◃∎ =ₛ⟨ 1 & 0 & contract ⟩ ap ! (!-inv-r (merid (pt X))) ◃∙ idp ◃∎ ∎ₛ where custom-path-alg-coh : ∀ {l} {A : Type l} {n s : A} (p : n == s) → custom-path-alg p p ◃∙ ap (λ q → ! (! p) ∙ q ∙' ! p) (!-inv-l p) ◃∙ ap (! (! p) ∙_) (∙'-unit-l (! p)) ◃∙ !-inv-l (! p) ◃∎ =ₛ ap ! (!-inv-r p) ◃∎ custom-path-alg-coh p@idp = =ₛ-in idp ⊙Ω-!-⊙Susp-flip : ∀ {i} (X : Ptd i) (n : ℕ₋₂) → is-equiv (Trunc-fmap {n = n} (σloop X)) → ⊙Trunc-fmap {n = n} ⊙Ω-! == ⊙Trunc-fmap {n = n} (⊙Ω-fmap (⊙Susp-flip X)) ⊙Ω-!-⊙Susp-flip X n is-eq = –>-is-inj (pre⊙∘-equiv {Z = ⊙Trunc n (⊙Ω (⊙Susp (de⊙ X)))} (⊙Trunc-fmap {n = n} (⊙σloop X) , is-eq)) (⊙Trunc-fmap {n = n} ⊙Ω-!) (⊙Trunc-fmap {n = n} (⊙Ω-fmap (⊙Susp-flip X))) (=⊙∘-out (⊙Trunc-fmap-seq-=⊙∘ {n = n} (⊙Ω-!-Susp-flip' X)))
{ "alphanum_fraction": 0.4232067511, "avg_line_length": 41.9469026549, "ext": "agda", "hexsha": "97aa96dce8fc471bba26472044bcf6b53b4a6736", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_path": "theorems/homotopy/SuspensionLoopSpaceInverse.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_path": "theorems/homotopy/SuspensionLoopSpaceInverse.agda", "max_line_length": 82, "max_stars_count": 294, "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_path": "theorems/homotopy/SuspensionLoopSpaceInverse.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 2423, "size": 4740 }
{-# OPTIONS --cubical --safe #-} module Cubical.Structures.Monoid where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_) open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS) open import Cubical.Structures.Pointed open import Cubical.Structures.InftyMagma private variable ℓ : Level -- Now we're getting serious: Monoids raw-monoid-structure : Type ℓ → Type ℓ raw-monoid-structure X = X × (X → X → X) raw-monoid-iso : StrIso raw-monoid-structure ℓ raw-monoid-iso (M , e , _·_) (N , d , _∗_) f = (equivFun f e ≡ d) × ((x y : M) → equivFun f (x · y) ≡ (equivFun f x) ∗ (equivFun f y)) -- If we ignore the axioms we get something like a "raw" monoid, which -- essentially is the join of a pointed type and an ∞-magma raw-monoid-is-SNS : SNS {ℓ} raw-monoid-structure raw-monoid-iso raw-monoid-is-SNS = join-SNS pointed-structure pointed-iso pointed-is-SNS ∞-magma-structure ∞-magma-iso ∞-magma-is-SNS -- Now define monoids monoid-axioms : (X : Type ℓ) → raw-monoid-structure X → Type ℓ monoid-axioms X (e , _·_ ) = isSet X × ((x y z : X) → (x · (y · z)) ≡ ((x · y) · z)) × ((x : X) → (x · e) ≡ x) × ((x : X) → (e · x) ≡ x) monoid-structure : Type ℓ → Type ℓ monoid-structure = add-to-structure (raw-monoid-structure) monoid-axioms Monoids : Type (ℓ-suc ℓ) Monoids {ℓ} = TypeWithStr ℓ monoid-structure monoid-iso : StrIso monoid-structure ℓ monoid-iso = add-to-iso raw-monoid-structure raw-monoid-iso monoid-axioms -- We have to show that the monoid axioms are indeed propositions monoid-axioms-are-Props : (X : Type ℓ) (s : raw-monoid-structure X) → isProp (monoid-axioms X s) monoid-axioms-are-Props X (e , _·_) s = β s where α = s .fst -- TODO: it would be nice to have versions of this lemmas for higher arities β = isPropΣ isPropIsSet λ _ → isPropΣ (isPropPi (λ x → isPropPi (λ y → isPropPi (λ z → α (x · (y · z)) ((x · y) · z))))) λ _ → isPropΣ (isPropPi (λ x → α (x · e) x)) λ _ → isPropPi (λ x → α (e · x) x) monoid-is-SNS : SNS {ℓ} monoid-structure monoid-iso monoid-is-SNS = add-axioms-SNS raw-monoid-structure raw-monoid-iso monoid-axioms monoid-axioms-are-Props raw-monoid-is-SNS MonoidPath : (M N : Monoids {ℓ}) → (M ≃[ monoid-iso ] N) ≃ (M ≡ N) MonoidPath M N = SIP monoid-structure monoid-iso monoid-is-SNS M N -- Added for groups -- If there exists a inverse of an element it is unique inv-lemma : (X : Type ℓ) (e : X) (_·_ : X → X → X) → monoid-axioms X (e , _·_) → (x y z : X) → y · x ≡ e → x · z ≡ e → y ≡ z inv-lemma X e _·_ (is-set-X , assoc , runit , lunit) x y z left-inverse right-inverse = y ≡⟨ sym (runit y) ⟩ y · e ≡⟨ cong (y ·_) (sym right-inverse) ⟩ y · (x · z) ≡⟨ assoc y x z ⟩ (y · x) · z ≡⟨ cong (_· z) left-inverse ⟩ e · z ≡⟨ lunit z ⟩ z ∎
{ "alphanum_fraction": 0.6014143362, "avg_line_length": 37.4819277108, "ext": "agda", "hexsha": "9ae7d127a7998a3d1ff23c8b7f882c18c9e81fa1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "borsiemir/cubical", "max_forks_repo_path": "Cubical/Structures/Monoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "borsiemir/cubical", "max_issues_repo_path": "Cubical/Structures/Monoid.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "borsiemir/cubical", "max_stars_repo_path": "Cubical/Structures/Monoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1118, "size": 3111 }