Search is not available for this dataset
text
string
meta
dict
{- Name: Bowornmet (Ben) Hudson -- define the source language from the paper -} open import Preliminaries open import Preorder-withmax module Proofs where -- define the source language from the paper -- we want to focus on arrow, cross, and nat types data Tp : Set where unit : Tp nat : Tp susp : Tp → Tp _->s_ : Tp → Tp → Tp _×s_ : Tp → Tp → Tp data Cost : Set where 0c : Cost 1c : Cost _+c_ : Cost → Cost → Cost data Equals0c : Cost → Set where Eq0-0c : Equals0c 0c Eq0-+c : ∀ {c c'} → Equals0c c → Equals0c c' → Equals0c (c +c c') -- represent a context as a list of types Ctx = List Tp -- de Bruijn indices (for free variables) data _∈_ : Tp → Ctx → Set where i0 : ∀ {Γ τ} → τ ∈ (τ :: Γ) iS : ∀ {Γ τ τ1} → τ ∈ Γ → τ ∈ (τ1 :: Γ) data _|-_ : Ctx → Tp → Set where unit : ∀ {Γ} → Γ |- unit var : ∀ {Γ τ} → τ ∈ Γ → Γ |- τ z : ∀ {Γ} → Γ |- nat suc : ∀ {Γ} → (e : Γ |- nat) → Γ |- nat rec : ∀ {Γ τ} → Γ |- nat → Γ |- τ → (nat :: (susp τ :: Γ)) |- τ → Γ |- τ lam : ∀ {Γ τ ρ} → (ρ :: Γ) |- τ → Γ |- (ρ ->s τ) app : ∀ {Γ τ1 τ2} → Γ |- (τ2 ->s τ1) → Γ |- τ2 → Γ |- τ1 prod : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → Γ |- (τ1 ×s τ2) l-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×s τ2) → Γ |- τ1 r-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×s τ2) → Γ |- τ2 -- include split, delay/susp/force instead of usual elim rules for products delay : ∀ {Γ τ} → Γ |- τ → Γ |- susp τ force : ∀ {Γ τ} → Γ |- susp τ → Γ |- τ split : ∀ {Γ τ τ1 τ2} → Γ |- (τ1 ×s τ2) → (τ1 :: (τ2 :: Γ)) |- τ → Γ |- τ ------weakening and substitution lemmas -- renaming function rctx : Ctx → Ctx → Set rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ -- re: transferring variables in contexts lem1 : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ') lem1 d i0 = i0 lem1 d (iS x) = iS (d x) -- renaming lemma ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ ren unit d = unit ren (var x) d = var (d x) ren z d = z ren (suc e) d = suc (ren e d) ren (rec e e0 e1) d = rec (ren e d) (ren e0 d) (ren e1 (lem1 (lem1 d))) ren (lam e) d = lam (ren e (lem1 d)) ren (app e1 e2) d = app (ren e1 d) (ren e2 d) ren (prod e1 e2) d = prod (ren e1 d) (ren e2 d) ren (l-proj e) d = l-proj (ren e d) ren (r-proj e) d = r-proj (ren e d) ren (delay e) d = delay (ren e d) ren (force e) d = force (ren e d) ren (split e e1) d = split (ren e d) (ren e1 (lem1 (lem1 d))) -- substitution sctx : Ctx → Ctx → Set sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ -- weakening a context wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2 wkn e = ren e iS -- weakening also works with substitution wkn-s : ∀ {Γ τ1 Γ'} → sctx Γ Γ' → sctx (τ1 :: Γ) Γ' wkn-s d = λ f → wkn (d f) wkn-r : ∀ {Γ τ1 Γ'} → rctx Γ Γ' → rctx (τ1 :: Γ) Γ' wkn-r d = λ x → iS (d x) -- lem2 (need a lemma for subst like we did for renaming) lem2 : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ') lem2 d i0 = var i0 lem2 d (iS i) = wkn (d i) -- another substitution lemma lem3 : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ) lem3 e i0 = e lem3 e (iS i) = var i lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ') lem3' Θ e i0 = e lem3' Θ e (iS i) = Θ i -- one final lemma needed for the last stepping rule. Thank you Professor Licata! lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ)) lem4 e1 e2 i0 = e1 lem4 e1 e2 (iS i0) = e2 lem4 e1 e2 (iS (iS i)) = var i lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ')) lem4' Θ a b i0 = a lem4' Θ a b (iS i0) = b lem4' Θ a b (iS (iS i)) = Θ i lem5 : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×s τ2) → sctx Γ ((τ1 ×s τ2) :: (τ1 :: (τ2 :: Γ))) lem5 e i0 = e lem5 e (iS i0) = l-proj e lem5 e (iS (iS i0)) = r-proj e lem5 e (iS (iS (iS i))) = var i -- the 'real' substitution lemma (if (x : τ') :: Γ |- (e : τ) and Γ |- (e : τ') , then Γ |- e[x -> e'] : τ) subst : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ' |- τ → Γ |- τ subst d unit = unit subst d (var x) = d x subst d z = z subst d (suc x) = suc (subst d x) subst d (rec e e0 e1) = rec (subst d e) (subst d e0) (subst (lem2 (lem2 d)) e1) subst d (lam e) = lam (subst (lem2 d) e) subst d (app e1 e2) = app (subst d e1) (subst d e2) subst d (prod e1 e2) = prod (subst d e1) (subst d e2) subst d (l-proj e) = l-proj (subst d e) subst d (r-proj e) = r-proj (subst d e) subst d (delay e) = delay (subst d e) subst d (force e) = force (subst d e) subst d (split e e1) = split (subst d e) (subst (lem2 (lem2 d)) e1) subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) ) → subst (lem3 v) (subst (lem2 Θ) e) == subst (lem3' Θ v) e subst-compose Θ unit e = {!!} subst-compose Θ (var x) e = {!!} subst-compose Θ z e = {!!} subst-compose Θ (suc v) e = {!!} subst-compose Θ (rec v v₁ v₂) e = {!!} subst-compose Θ (lam v) e = {!!} subst-compose Θ (app v v₁) e = {!!} subst-compose Θ (prod v v₁) e = {!!} subst-compose Θ (l-proj v) e = {!!} subst-compose Θ (r-proj v) e = {!!} subst-compose Θ (delay v) e = {!!} subst-compose Θ (force v) e = {!!} subst-compose Θ (split v v₁) e = {!!}
{ "alphanum_fraction": 0.4715149295, "avg_line_length": 28.7315789474, "ext": "agda", "hexsha": "276659ce3a96e78db37c7f8a71da0d82c534e231", "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": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "benhuds/Agda", "max_forks_repo_path": "complexity-drafts/Proofs.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "benhuds/Agda", "max_issues_repo_path": "complexity-drafts/Proofs.agda", "max_line_length": 109, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "benhuds/Agda", "max_stars_repo_path": "complexity-drafts/Proofs.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z", "num_tokens": 2332, "size": 5459 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommSemiring.Instances.UpperNat where {- based on: https://github.com/DavidJaz/Cohesion/blob/master/UpperNaturals.agda and the slides here (for arithmetic operation): https://felix-cherubini.de/myers-slides-II.pdf -} open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Functions.Logic open import Cubical.Functions.Embedding open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.OrderedCommMonoid open import Cubical.Algebra.OrderedCommMonoid.PropCompletion open import Cubical.Algebra.OrderedCommMonoid.Instances open import Cubical.Algebra.CommSemiring open import Cubical.Data.Nat using (ℕ; ·-distribˡ) open import Cubical.Data.Nat.Order open import Cubical.Data.Empty hiding (⊥) open import Cubical.Data.Sigma open import Cubical.HITs.Truncation open import Cubical.HITs.PropositionalTruncation as PT private variable ℓ : Level {- The Upper Naturals An upper natural is an upward closed proposition on natural numbers. The interpretation is that an upper natural is a natural ``defined by its upper bounds'', in the sense that for the proposition N holding of a natural n means that n is an upper bound of N. The important bit about upper naturals is that they satisfy the well-ordering principle, constructively (no proof of that is given here). Example Application: The degree of a polynomial P=∑_{i=0}^{n} aᵢ · Xⁱ may be defined as an upper natural: deg(P) :≡ (λ n → all non-zero indices have index smaller n) Or: deg(∑_{i=0}^{n} aᵢ · Xⁱ) = λ (k : ℕ) → ∀ (k+1 ≤ i ≤ n) aᵢ≡0 This works even if a constructive definition of polynomial is used. However the upper naturals are a bit too unconstraint and do not even form a semiring, since they include 'infinity' elements like the proposition that is always false. This is different for the subtype of *bounded* upper naturals ℕ↑b. -} module ConstructionUnbounded where ℕ↑-+ = PropCompletion ℕ≤+ ℕ↑-· = PropCompletion ℕ≤· open OrderedCommMonoidStr (snd ℕ↑-+) hiding (_≤_; MonotoneL; MonotoneR) renaming (·Assoc to +Assoc; ·Comm to +Comm; ·IdR to +Rid; _·_ to _+_; ε to 0↑) open OrderedCommMonoidStr (snd ℕ≤·) using (MonotoneL; MonotoneR) open OrderedCommMonoidStr (snd ℕ≤+) hiding (_≤_) renaming (_·_ to _+ℕ_; MonotoneL to +MonotoneL; MonotoneR to +MonotoneR; ·Comm to ℕ+Comm) open OrderedCommMonoidStr ⦃...⦄ using (_·_ ; ·Assoc ; ·Comm ) renaming (·IdR to ·Rid) private instance _ : OrderedCommMonoidStr _ _ _ = snd ℕ↑-· _ : OrderedCommMonoidStr _ _ _ = snd ℕ≤· ℕ↑ : Type₁ ℕ↑ = fst ℕ↑-+ open PropCompletion ℓ-zero ℕ≤+ using (typeAt; pathFromImplications) open <-Reasoning using (_≤⟨_⟩_) +LDist· : (x y z : ℕ↑) → x · (y + z) ≡ (x · y) + (x · z) +LDist· x y z = pathFromImplications (x · (y + z)) ((x · y) + (x · z)) (⇒) ⇐ where ⇒ : (n : ℕ) → typeAt n (x · (y + z)) → typeAt n ((x · y) + (x · z)) ⇒ n = PT.rec isPropPropTrunc λ {((a , b) , xa , (y+zb , a·b≤n)) → PT.rec isPropPropTrunc (λ {((a' , b') , ya' , (zb' , a'+b'≤b)) → ∣ ((a · a') , (a · b')) , ∣ (a , a') , (xa , (ya' , ≤-refl)) ∣₁ , (∣ (a , b') , (xa , (zb' , ≤-refl)) ∣₁ , subst (_≤ n) (sym (·-distribˡ a a' b')) (≤-trans (MonotoneL {z = a} a'+b'≤b) a·b≤n)) ∣₁ }) y+zb} ⇐ : (n : ℕ) → _ ⇐ n = PT.rec isPropPropTrunc λ {((a , b) , x·ya , (x·zb , a+b≤n)) → PT.rec isPropPropTrunc (λ {((a' , b') , a'x , (b'y , a'·b'≤a)) → PT.rec isPropPropTrunc (λ {((a″ , b″) , a″x , (zb″ , a″·b″≤b)) → ∣ ≤CaseInduction {n = a'} {m = a″} (λ a'≤a″ → (a' , (b' +ℕ b″)) , a'x , (∣ (b' , b″) , (b'y , (zb″ , ≤-refl)) ∣₁ , (a' · (b' +ℕ b″) ≤⟨ subst (_≤ (a' · b') +ℕ (a' · b″)) (·-distribˡ a' b' b″) ≤-refl ⟩ (a' · b') +ℕ (a' · b″) ≤⟨ +MonotoneR a'·b'≤a ⟩ a +ℕ (a' · b″) ≤⟨ +MonotoneL (≤-trans (MonotoneR a'≤a″) a″·b″≤b) ⟩ a+b≤n )) ) (λ a″≤a' → (a″ , (b' +ℕ b″)) , (a″x , (∣ (b' , b″) , (b'y , (zb″ , ≤-refl)) ∣₁ , ((a″ · (b' +ℕ b″)) ≤⟨ subst (_≤ (a″ · b') +ℕ (a″ · b″)) (·-distribˡ a″ b' b″) ≤-refl ⟩ (a″ · b') +ℕ (a″ · b″) ≤⟨ +MonotoneR ((a″ · b') ≤⟨ MonotoneR a″≤a' ⟩ a'·b'≤a) ⟩ a +ℕ (a″ · b″) ≤⟨ +MonotoneL a″·b″≤b ⟩ a+b≤n))) ) ∣₁}) x·zb}) x·ya} module ConstructionBounded where ℕ↑-+b = BoundedPropCompletion ℕ≤+ ℕ↑-·b = BoundedPropCompletion ℕ≤· open OrderedCommMonoidStr (snd ℕ≤+) renaming (_·_ to _+ℕ_; ·IdR to +IdR; ·Comm to ℕ+Comm) open OrderedCommMonoidStr (snd ℕ↑-+b) renaming (_·_ to _+_; ε to 0↑) open OrderedCommMonoidStr (snd ℕ↑-·b) using (_·_) open PropCompletion ℓ-zero ℕ≤+ using (typeAt; pathFromImplications) ℕ↑b : Type₁ ℕ↑b = fst ℕ↑-+b AnnihilL : (x : ℕ↑b) → 0↑ · x ≡ 0↑ AnnihilL x = Σ≡Prop (λ s → PropCompletion.isPropIsBounded ℓ-zero ℕ≤+ s) (pathFromImplications (fst (0↑ · x)) (fst 0↑) (⇒) ⇐) where ⇒ : (n : ℕ) → typeAt n (fst (0↑ · x)) → typeAt n (fst 0↑) ⇒ n _ = n , ℕ+Comm n 0 ⇐ : (n : ℕ) → typeAt n (fst 0↑) → typeAt n (fst (0↑ · x)) ⇐ n _ = PT.rec isPropPropTrunc (λ {(m , mIsUpperBound) → ∣ (0 , m) , ((0 , refl) , (mIsUpperBound , n , +IdR n)) ∣₁}) (snd x) asCommSemiring : CommSemiring (ℓ-suc ℓ-zero) fst asCommSemiring = ℕ↑b CommSemiringStr.0r (snd asCommSemiring) = 0↑ CommSemiringStr.1r (snd asCommSemiring) = OrderedCommMonoidStr.ε (snd ℕ↑-·b) CommSemiringStr._+_ (snd asCommSemiring) = _+_ CommSemiringStr._·_ (snd asCommSemiring) = _·_ IsCommSemiring.+IsCommMonoid (CommSemiringStr.isCommSemiring (snd asCommSemiring)) = OrderedCommMonoidStr.isCommMonoid (snd ℕ↑-+b) IsCommSemiring.·IsCommMonoid (CommSemiringStr.isCommSemiring (snd asCommSemiring)) = OrderedCommMonoidStr.isCommMonoid (snd ℕ↑-·b) IsCommSemiring.·LDist+ (CommSemiringStr.isCommSemiring (snd asCommSemiring)) = λ x y z → Σ≡Prop (λ s → PropCompletion.isPropIsBounded ℓ-zero ℕ≤+ s) (ConstructionUnbounded.+LDist· (fst x) (fst y) (fst z)) IsCommSemiring.AnnihilL (CommSemiringStr.isCommSemiring (snd asCommSemiring)) = AnnihilL
{ "alphanum_fraction": 0.5100652884, "avg_line_length": 36.396039604, "ext": "agda", "hexsha": "701e300676df6463f3d2e80d7174d3da302c1539", "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/CommSemiring/Instances/UpperNat.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/CommSemiring/Instances/UpperNat.agda", "max_line_length": 99, "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/CommSemiring/Instances/UpperNat.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2497, "size": 7352 }
{-# OPTIONS --without-K #-} open import HoTT {- Proof that if [A] and [B] are two propositions, then so is [A * B]. -} module homotopy.PropJoinProp {i} (A : Type i) {pA : (a a' : A) → a == a'} {j} (B : Type j) {pB : (b b' : B) → b == b'} where {- We first prove that [left a == y] for all [a : A] and [y : A * B]. For that we will need the coherence condition [coh1] below. -} eq-left : (a : A) (y : A * B) → left a == y eq-left = EqLeft.f module M where coh1 : {b' : B} {a a' : A} (p : a == a') → ap left p ∙ glue (a' , b') == glue (a , b') :> (left a == right b' :> A * B) coh1 idp = idp module EqLeft (a : A) = PushoutElim (λ a' → ap left (pA a a')) (λ b' → glue (a , b')) (λ {(a' , b') → ↓-cst=idf-in (coh1 (pA a a'))}) open M {- Now we prove that [right b == y] for all [b : B] and [y : A * B]. We will again need some coherence condition [coh2]. -} eq-right : (b : B) (y : A * B) → right b == y eq-right = EqRight.f module M' where coh2 : {a' : A} {b b' : B} (p : b == b') → ! (glue (a' , b)) ∙ glue (a' , b') == ap right p :> (right b == right b' :> A * B) coh2 idp = !-inv-l (glue _) module EqRight (b : B) = PushoutElim (λ a' → ! (glue (a' , b))) (λ b' → ap right (pB b b')) (λ {(a' , b') → ↓-cst=idf-in (coh2 (pB b b'))}) open M' {- Then we prove the missing cases. For the cases [x == left a'] and [x == right b'] we will need the coherence conditions [coh3] and [coh4]. For the last case, we need a "2-dimensional" coherence condition [coh²], relating [coh1], [coh2], [coh3] and [coh4]. -} eq : (x y : A * B) → x == y eq = Pushout-elim eq-left eq-right (λ {(a , b) → ↓-cst→app-in (Pushout-elim (λ a' → ↓-idf=cst-in (coh3 (pA a a'))) (λ b' → ↓-idf=cst-in (coh4 (pB b b'))) (λ {(a' , b') → ↓-idf=cst-in=↓ (↓-=-in (coh3 (pA a a') ◃ apd (λ x → glue (a , b) ∙' eq-right b x) (glue (a' , b')) =⟨ apd∙' (λ x → glue (a , b)) (eq-right b) (glue (a' , b')) |in-ctx (λ u → coh3 (pA a a') ◃ u) ⟩ coh3 (pA a a') ◃ (apd (λ x → glue (a , b)) (glue (a' , b')) ∙'2ᵈ apd (eq-right b) (glue (a' , b'))) =⟨ EqRight.glue-β b (a' , b') |in-ctx (λ u → coh3 (pA a a') ◃ (apd (λ x → glue (a , b)) (glue (a' , b')) ∙'2ᵈ u)) ⟩ coh3 (pA a a') ◃ (apd (λ x → glue (a , b)) (glue (a' , b')) ∙'2ᵈ ↓-cst=idf-in {p = glue _} {u = ! (glue _)} (coh2 (pB b b'))) =⟨ coh² (pA a a') (pB b b') ⟩ ↓-cst=idf-in (coh1 (pA a a')) ▹ coh4 (pB b b') =⟨ ! (EqLeft.glue-β a (a' , b')) |in-ctx (λ u → u ▹ coh4 (pB b b')) ⟩ apd (eq-left a) (glue (a' , b')) ▹ coh4 (pB b b') ∎))}))}) where coh3 : {b : B} {a a' : A} (p : a == a') → ap left p == (glue (a , b) ∙' ! (glue (a' , b))) :> (left a == left a' :> A * B) coh3 idp = ! (!-inv-r (glue _)) ∙ ∙=∙' (glue _) (! (glue _)) coh4 : {a : A} {b b' : B} (p : b == b') → glue (a , b') == (glue (a , b) ∙' ap right p) :> (left a == right b' :> A * B) coh4 idp = idp {- Should go to lib.types.Paths -} ↓-idf=cst-in=↓ : ∀ {i} {A : Type i} {a a' : A} {p : a == a'} {a0 a0' : A} {p0 : a0 == a0'} {f : (a : A) → a0 == a} {g : (a : A) → a0' == a} {q : f a == p0 ∙' g a } {r : f a' == p0 ∙' g a'} → q == r [ (λ a → f a == p0 ∙' g a) ↓ p ] → ↓-idf=cst-in q == ↓-idf=cst-in r [ (λ a → f a == g a [ (λ x → x == a) ↓ p0 ]) ↓ p ] ↓-idf=cst-in=↓ {p = idp} {p0 = idp} idp = idp abstract coh² : {a a' : A} {b b' : B} (p : a == a') (q : b == b') → coh3 {b = b} p ◃ (apd (λ x → glue (a , b)) (glue (a' , b')) ∙'2ᵈ ↓-cst=idf-in {p = glue (a' , b')} {u = ! (glue (a' , b))} (coh2 q)) == ↓-cst=idf-in (coh1 p) ▹ coh4 q coh² idp idp = aux (glue _) where abstract aux : {x y : A * B} (p : x == y) → (! (!-inv-r p) ∙ ∙=∙' p (! p)) ◃ (apd (λ x → p) p ∙'2ᵈ ↓-cst=idf-in {p = p} {u = ! p} (!-inv-l p)) == ↓-cst=idf-in idp ▹ idp aux idp = idp
{ "alphanum_fraction": 0.420440485, "avg_line_length": 39.2330097087, "ext": "agda", "hexsha": "b429cda01739dad9dbb0c58dcb7cd23865cf6255", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "homotopy/PropJoinProp.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "homotopy/PropJoinProp.agda", "max_line_length": 141, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "homotopy/PropJoinProp.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 1793, "size": 4041 }
module Issue448 where postulate Unit : Set unit : Unit D : Set → Set d : (A : Set) → A → D A record R : Set₁ where field F : Set r : _ r = record { F = Unit } postulate D′ : R.F r → D (R.F r) → Set d′ : ∀ f τ → D′ f (d _ τ) data D″ (f : Unit) : D′ f (d Unit unit) → Set where d″ : ∀ (x : Unit) → D″ _ (d′ f unit) -- An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/MetaVars.hs:583
{ "alphanum_fraction": 0.5769230769, "avg_line_length": 18.72, "ext": "agda", "hexsha": "ae423f5d48ff2b70d3f0ddd5e2b1696b7d99cfbb", "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/Issue448.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/Issue448.agda", "max_line_length": 68, "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/Issue448.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": 171, "size": 468 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Names used in the reflection machinery ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Reflection.Name where open import Data.List.Base import Data.Product.Properties as Prodₚ import Data.Word.Properties as Wₚ open import Function open import Relation.Nullary.Decidable using (map′) open import Relation.Binary import Relation.Binary.Construct.On as On open import Relation.Binary.PropositionalEquality ---------------------------------------------------------------------- -- Re-export built-ins open import Agda.Builtin.Reflection public using (Name) renaming (primQNameToWord64s to toWords) open import Agda.Builtin.Reflection.Properties public renaming (primQNameToWord64sInjective to toWords-injective) ---------------------------------------------------------------------- -- More definitions ---------------------------------------------------------------------- Names : Set Names = List Name ---------------------------------------------------------------------- -- Decidable equality for names ---------------------------------------------------------------------- _≈_ : Rel Name _ _≈_ = _≡_ on toWords infix 4 _≈?_ _≟_ _≈?_ : Decidable _≈_ _≈?_ = On.decidable toWords _≡_ (Prodₚ.≡-dec Wₚ._≟_ Wₚ._≟_) _≟_ : DecidableEquality Name m ≟ n = map′ (toWords-injective _ _) (cong toWords) (m ≈? n)
{ "alphanum_fraction": 0.5013404826, "avg_line_length": 29.84, "ext": "agda", "hexsha": "26b579ea411fbc6ce6541b56ccdf93dbd856c8e8", "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/Reflection/Name.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/Reflection/Name.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Reflection/Name.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": 307, "size": 1492 }
import Agda.Builtin.FromNat as FromNat -- not opened open import Agda.Builtin.Nat -- Since fromNat is not in scope unqualified this should work without -- a Number instance for Nat. x : Nat x = 0 -- Renaming fromNat should not make a difference open FromNat renaming (fromNat to fromℕ) open import Agda.Builtin.Unit data MyNat : Set where mkNat : Nat → MyNat instance numMyNat : Number MyNat numMyNat .Number.Constraint _ = ⊤ numMyNat .fromℕ n = mkNat n y : MyNat y = 1
{ "alphanum_fraction": 0.7355371901, "avg_line_length": 20.1666666667, "ext": "agda", "hexsha": "7ef5a96f594444ac0d5c53f8f4b987dbe00688cb", "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/Issue4925.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/Issue4925.agda", "max_line_length": 69, "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/Issue4925.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": 149, "size": 484 }
-- Andreas, 2020-06-23, issue #4773 -- reported by gallais, originally reported on mailing list by mechvel -- Regression in 2.5.1: -- import directives applied to modules no longer warn -- when private names are mentioned -- {-# OPTIONS -v scope:40 #-} module _ where -- MWE: ------- module M where private X = Set Y = Set Z = Set module N = M using (X) renaming (Y to Y') hiding (Z) -- EXPECTED: warning about X, Y, Z -- Extended original example, using 'open M args' ------------------------------------------------- module A (X : Set₁) where Y = X module B (X : Set₁) where open A X using (Y) private Z = Set open B Set renaming (Y to Y') renaming (Z to Z') -- EXPECTED: warning about Y, Z -- Y' is not in scope -- test = Y'
{ "alphanum_fraction": 0.594488189, "avg_line_length": 18.5853658537, "ext": "agda", "hexsha": "8532cec5346f543f9ef4addf6aab45ab7b3045f5", "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/Issue4773.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/Issue4773.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4773.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": 220, "size": 762 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by strict partial orders ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Properties.StrictTotalOrder {s₁ s₂ s₃} (STO : StrictTotalOrder s₁ s₂ s₃) where open Relation.Binary.StrictTotalOrder STO import Relation.Binary.StrictToNonStrict as Conv open Conv _≈_ _<_ import Relation.Binary.Properties.StrictPartialOrder as SPO open import Relation.Binary.Consequences ------------------------------------------------------------------------ -- Strict total orders can be converted to decidable total orders decTotalOrder : DecTotalOrder _ _ _ decTotalOrder = record { isDecTotalOrder = record { isTotalOrder = record { isPartialOrder = SPO.isPartialOrder strictPartialOrder ; total = total compare } ; _≟_ = _≟_ ; _≤?_ = decidable' compare } } open DecTotalOrder decTotalOrder public
{ "alphanum_fraction": 0.5832540438, "avg_line_length": 30.0285714286, "ext": "agda", "hexsha": "7d7a83616f66003b325ba0d6acb619374e12b46c", "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/Binary/Properties/StrictTotalOrder.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/Binary/Properties/StrictTotalOrder.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/Binary/Properties/StrictTotalOrder.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": 218, "size": 1051 }
open import Nat open import Prelude open import core module lemmas-progress-checks where -- boxed values don't have an instruction transition boxedval-not-trans : ∀{d d'} → d boxedval → d →> d' → ⊥ boxedval-not-trans (BVVal VConst) () boxedval-not-trans (BVVal VLam) () boxedval-not-trans (BVArrCast x bv) (ITCastID) = x refl boxedval-not-trans (BVHoleCast () bv) (ITCastID) boxedval-not-trans (BVHoleCast () bv) (ITCastSucceed x₁) boxedval-not-trans (BVHoleCast GHole bv) (ITGround (MGArr x)) = x refl boxedval-not-trans (BVHoleCast x a) (ITExpand ()) boxedval-not-trans (BVHoleCast x x₁) (ITCastFail x₂ () x₄) -- indets don't have an instruction transition indet-not-trans : ∀{d d'} → d indet → d →> d' → ⊥ indet-not-trans IEHole () indet-not-trans (INEHole x) () indet-not-trans (IAp x₁ () x₂) (ITLam) indet-not-trans (IAp x (ICastArr x₁ ind) x₂) (ITApCast ) = x _ _ _ _ _ refl indet-not-trans (ICastArr x ind) (ITCastID) = x refl indet-not-trans (ICastGroundHole () ind) (ITCastID) indet-not-trans (ICastGroundHole x ind) (ITCastSucceed ()) indet-not-trans (ICastGroundHole GHole ind) (ITGround (MGArr x)) = x refl indet-not-trans (ICastHoleGround x ind ()) (ITCastID) indet-not-trans (ICastHoleGround x ind x₁) (ITCastSucceed x₂) = x _ _ refl indet-not-trans (ICastHoleGround x ind GHole) (ITExpand (MGArr x₂)) = x₂ refl indet-not-trans (ICastGroundHole x a) (ITExpand ()) indet-not-trans (ICastHoleGround x a x₁) (ITGround ()) indet-not-trans (ICastGroundHole x x₁) (ITCastFail x₂ () x₄) indet-not-trans (ICastHoleGround x x₁ x₂) (ITCastFail x₃ x₄ x₅) = x _ _ refl indet-not-trans (IFailedCast x x₁ x₂ x₃) () -- finals don't have an instruction transition final-not-trans : ∀{d d'} → d final → d →> d' → ⊥ final-not-trans (FBoxedVal x) = boxedval-not-trans x final-not-trans (FIndet x) = indet-not-trans x -- finals cast from a ground are still final final-gnd-cast : ∀{ d τ } → d final → τ ground → (d ⟨ τ ⇒ ⦇-⦈ ⟩) final final-gnd-cast (FBoxedVal x) gnd = FBoxedVal (BVHoleCast gnd x) final-gnd-cast (FIndet x) gnd = FIndet (ICastGroundHole gnd x) -- if an expression results from filling a hole in an evaluation context, -- the hole-filler must have been final final-sub-final : ∀{d ε x} → d final → d == ε ⟦ x ⟧ → x final final-sub-final x FHOuter = x final-sub-final (FBoxedVal (BVVal ())) (FHAp1 eps) final-sub-final (FBoxedVal (BVVal ())) (FHAp2 eps) final-sub-final (FBoxedVal (BVVal ())) (FHNEHole eps) final-sub-final (FBoxedVal (BVVal ())) (FHCast eps) final-sub-final (FBoxedVal (BVVal ())) (FHFailedCast y) final-sub-final (FBoxedVal (BVArrCast x₁ x₂)) (FHCast eps) = final-sub-final (FBoxedVal x₂) eps final-sub-final (FBoxedVal (BVHoleCast x₁ x₂)) (FHCast eps) = final-sub-final (FBoxedVal x₂) eps final-sub-final (FIndet (IAp x₁ x₂ x₃)) (FHAp1 eps) = final-sub-final (FIndet x₂) eps final-sub-final (FIndet (IAp x₁ x₂ x₃)) (FHAp2 eps) = final-sub-final x₃ eps final-sub-final (FIndet (INEHole x₁)) (FHNEHole eps) = final-sub-final x₁ eps final-sub-final (FIndet (ICastArr x₁ x₂)) (FHCast eps) = final-sub-final (FIndet x₂) eps final-sub-final (FIndet (ICastGroundHole x₁ x₂)) (FHCast eps) = final-sub-final (FIndet x₂) eps final-sub-final (FIndet (ICastHoleGround x₁ x₂ x₃)) (FHCast eps) = final-sub-final (FIndet x₂) eps final-sub-final (FIndet (IFailedCast x₁ x₂ x₃ x₄)) (FHFailedCast y) = final-sub-final x₁ y final-sub-not-trans : ∀{d d' d'' ε} → d final → d == ε ⟦ d' ⟧ → d' →> d'' → ⊥ final-sub-not-trans f sub step = final-not-trans (final-sub-final f sub) step
{ "alphanum_fraction": 0.6830146855, "avg_line_length": 53.8656716418, "ext": "agda", "hexsha": "ed72a4d3658363e4bc6fadf09ac46f0e5cb59088", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "lemmas-progress-checks.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "lemmas-progress-checks.agda", "max_line_length": 100, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "lemmas-progress-checks.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 1326, "size": 3609 }
module UnderscoresAsDataParam where data List (A : Set) : Set where nil : List _ cons : A -> List A -> List _
{ "alphanum_fraction": 0.6551724138, "avg_line_length": 19.3333333333, "ext": "agda", "hexsha": "d40bfb1d05345696afb9ba414466d1f4ea847fb2", "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/succeed/UnderscoresAsDataParam.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/succeed/UnderscoresAsDataParam.agda", "max_line_length": 35, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/UnderscoresAsDataParam.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": 36, "size": 116 }
module PartialOrder where open import Prelude record PartialOrder (A : Set) : Set1 where field _==_ : A -> A -> Set _≤_ : A -> A -> Set ==-def : forall {x y} -> (x == y) ⇐⇒ (x ≤ y) ∧ (y ≤ x) ≤-refl : forall {x} -> x ≤ x ≤-trans : forall {x y z} -> x ≤ y -> y ≤ z -> x ≤ z module POrder {A : Set}(ord : PartialOrder A) where private module POrd = PartialOrder ord open POrd public infix 60 _≤_ _==_ Monotone : (A -> A) -> Set Monotone f = forall {x y} -> x ≤ y -> f x ≤ f y Antitone : (A -> A) -> Set Antitone f = forall {x y} -> x ≤ y -> f y ≤ f x ≤-antisym : forall {x y} -> x ≤ y -> y ≤ x -> x == y ≤-antisym p q = snd ==-def (p , q) ==≤-L : forall {x y} -> x == y -> x ≤ y ==≤-L x=y = fst (fst ==-def x=y) ==≤-R : forall {x y} -> x == y -> y ≤ x ==≤-R x=y = snd (fst ==-def x=y) ==-refl : forall {x} -> x == x ==-refl = ≤-antisym ≤-refl ≤-refl ==-sym : forall {x y} -> x == y -> y == x ==-sym xy = snd ==-def (swap (fst ==-def xy)) ==-trans : forall {x y z} -> x == y -> y == z -> x == z ==-trans xy yz = ≤-antisym (≤-trans x≤y y≤z) (≤-trans z≤y y≤x) where x≤y = ==≤-L xy y≤z = ==≤-L yz y≤x = ==≤-R xy z≤y = ==≤-R yz Dual : PartialOrder A Dual = record { _==_ = _==_ ; _≤_ = \x y -> y ≤ x ; ==-def = (swap ∘ fst ==-def , snd ==-def ∘ swap) ; ≤-refl = ≤-refl ; ≤-trans = \yx zy -> ≤-trans zy yx }
{ "alphanum_fraction": 0.4208776596, "avg_line_length": 25.0666666667, "ext": "agda", "hexsha": "50f3c8c37e924e2c4b0e373478c3d99e84a1a60d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/lattice/PartialOrder.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/lattice/PartialOrder.agda", "max_line_length": 59, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/outdated-and-incorrect/lattice/PartialOrder.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": 646, "size": 1504 }
------------------------------------------------------------------------ -- Type checing of polymorphic and iso-recursive lambda terms ------------------------------------------------------------------------ module SystemF.TypeCheck where open import Data.Fin using (Fin; suc; zero; pred) open import Data.Nat as Nat using (ℕ; _+_) open import Data.Product open import Data.Vec using (_∷_; []; lookup) open import Function hiding (typeOf) open import Relation.Nullary open import Relation.Nullary.Negation open import Relation.Binary using (Decidable) open import Relation.Binary.PropositionalEquality hiding ([_]) open ≡-Reasoning open import SystemF.Type open import SystemF.Term open import SystemF.WtTerm open TypeSubst using () renaming (_[/_] to _[/tp_]) open CtxSubst using () renaming (weaken to weakenCtx) ------------------------------------------------------------------------ -- Decision procedures for equality of variable names and types -- This module contains two decision procedures for type checking: -- -- * the function typeOf synthesizes a type a for a given (untyped) -- term t and typing environment Γ, if possible; -- -- * the function check_⊢_∈_ checks whether a given triple Γ, t, a is -- in the well-typedness relation. -- -- The two functions correspond to a synthetic resp. analytic view of -- type-checking. Both produce evidence in the form of a typing -- derivation if type checking succeeds or a proof that no such -- derivation exists otherwise. infix 4 _≟n_ _≡tp_ _≟_ -- Equal successors have equal predecessors. ≡suc : ∀ {n} {x y : Fin n} → suc x ≡ suc y → x ≡ y ≡suc refl = refl -- A decision procedure for equality of variable names. _≟n_ : ∀ {n} → Decidable {A = Fin n} _≡_ zero ≟n zero = yes refl suc x ≟n suc y with x ≟n y ... | yes x≡y = yes (cong suc x≡y) ... | no x≢y = no (x≢y ∘ ≡suc) zero ≟n suc y = no λ() suc x ≟n zero = no λ() -- A shorthand for (syntactic) type equality. _≡tp_ : ∀ {n} → Type n → Type n → Set a ≡tp b = a ≡ b -- Equal type variables have equal names. ≡var : ∀ {n} {x y : Fin n} → var x ≡tp var y → x ≡ y ≡var refl = refl -- Equal function types have equal domains. ≡dom→ : ∀ {n} {a a′ b b′ : Type n} → a →' b ≡tp a′ →' b′ → a ≡ a′ ≡dom→ refl = refl -- Equal function types have equal codomains. ≡cod→ : ∀ {n} {a a′ b b′ : Type n} → a →' b ≡tp a′ →' b′ → b ≡ b′ ≡cod→ refl = refl -- Equal univeral types have equal bodies. ≡∀ : ∀ {n} {a a′ : Type (1 + n)} → ∀' a ≡tp ∀' a′ → a ≡ a′ ≡∀ refl = refl -- Equal recursive types have equal bodies. ≡μ : ∀ {n} {a a′ : Type (1 + n)} → μ a ≡tp μ a′ → a ≡ a′ ≡μ refl = refl -- A decision procedure for (syntactic) type equality _≟_ : ∀ {n} → Decidable {A = Type n} _≡_ var x ≟ var y with x ≟n y var x ≟ var .x | yes refl = yes refl var x ≟ var y | no x≢y = no (x≢y ∘ ≡var) var _ ≟ _ →' _ = no λ() var _ ≟ ∀' _ = no λ() var _ ≟ μ _ = no λ() a →' b ≟ var x = no λ() a →' b ≟ a′ →' b′ with a ≟ a′ | b ≟ b′ a →' b ≟ .a →' .b | yes refl | yes refl = yes refl a →' b ≟ a′ →' b′ | yes _ | no b≢b′ = no (b≢b′ ∘ ≡cod→) a →' b ≟ a′ →' b′ | no a≢a′ | _ = no (a≢a′ ∘ ≡dom→) a →' b ≟ ∀' _ = no λ() a →' b ≟ μ _ = no λ() ∀' _ ≟ var _ = no λ() ∀' _ ≟ _ →' _ = no λ() ∀' a ≟ ∀' a′ with a ≟ a′ ∀' a ≟ ∀' .a | yes refl = yes refl ∀' a ≟ ∀' a′ | no a≢a′ = no (a≢a′ ∘ ≡∀) ∀' _ ≟ μ _ = no λ() μ _ ≟ var _ = no λ() μ _ ≟ _ →' _ = no λ() μ _ ≟ ∀' _ = no λ() μ a ≟ μ a′ with a ≟ a′ μ a ≟ μ .a | yes refl = yes refl μ a ≟ μ a′ | no a≢a′ = no (a≢a′ ∘ ≡μ) ------------------------------------------------------------------------ -- Inversion and functionality of the well-typedness relation -- Inversion of type application typing. Λ-inversion : ∀ {m n} {Γ : Ctx m n} {t a} → Γ ⊢ Λ t ∈ a → ∃ λ a′ → (a ≡ ∀' a′) × (weakenCtx Γ ⊢ t ∈ a′) Λ-inversion {a = ∀' a′} (Λ t∈a) = a′ , (refl , t∈a) -- Inversion of term application typing. λ'-inversion : ∀ {m n} {Γ : Ctx m n} {t a a→b} → Γ ⊢ λ' a t ∈ a→b → ∃ λ b → (a→b ≡ a →' b) × (a ∷ Γ ⊢ t ∈ b) λ'-inversion {a→b = a →' b} (λ' .a t∈b) = b , (refl , t∈b) -- Inversion of recursive term typing. μ-inversion : ∀ {m n} {Γ : Ctx m n} {t a a′} → Γ ⊢ μ a t ∈ a′ → (a ≡ a′) × (a ∷ Γ ⊢ t ∈ a) μ-inversion (μ a t∈b) = refl , t∈b -- Inversion of type application. []-inversion : ∀ {m n} {Γ : Ctx m n} {t b a[/b]} → Γ ⊢ t [ b ] ∈ a[/b] → ∃ λ a → (a[/b] ≡ a [/tp b ]) × (Γ ⊢ t ∈ ∀' a) []-inversion (_[_] {a = a} t∈∀a b) = a , (refl , t∈∀a) -- Inversion of term application. ·-inversion : ∀ {m n} {Γ : Ctx m n} {s t b} → Γ ⊢ s · t ∈ b → ∃ λ a → (Γ ⊢ s ∈ a →' b) × (Γ ⊢ t ∈ a) ·-inversion (_·_ {a = a} s∈a→b t∈a) = a , (s∈a→b , t∈a) -- Inversion of recursive type folding. fold-inversion : ∀ {m n} {Γ : Ctx m n} {t a μa} → Γ ⊢ fold a t ∈ μa → (μa ≡ μ a) × (Γ ⊢ t ∈ a [/tp μ a ]) fold-inversion (fold a t∈a[/μa]) = refl , t∈a[/μa] -- Inversion of recursive type unfolding. unfold-inversion : ∀ {m n} {Γ : Ctx m n} {t a a[/μa]} → Γ ⊢ unfold a t ∈ a[/μa] → (a[/μa] ≡ a [/tp μ a ]) × (Γ ⊢ t ∈ μ a) unfold-inversion (unfold a t∈μa) = refl , t∈μa -- The relation _⊢_∈_ is functional in its last argument. functional : ∀ {m n} {Γ : Ctx m n} {t a a′} → Γ ⊢ t ∈ a → Γ ⊢ t ∈ a′ → a ≡ a′ functional (var x) (var .x) = refl functional (Λ t∈a) (Λ t∈a′) = cong ∀' (functional t∈a t∈a′) functional (λ' a t∈b) (λ' .a t∈b′) = cong (_→'_ a) (functional t∈b t∈b′) functional (μ a t∈a) (μ .a t∈a′) = functional t∈a t∈a′ functional (t∈∀a [ b ]) (t∈∀a′ [ .b ]) = cong (λ{ (∀' a) → a [/tp b ] ; a → a }) (functional t∈∀a t∈∀a′) functional (s∈a→b · _) (s∈a→b′ · _) = cong (λ{ (a →' b) → b ; a → a }) (functional s∈a→b s∈a→b′) functional (fold a t∈) (fold .a t∈′) = refl functional (unfold a t∈) (unfold .a t∈′) = refl -- A variant of functionality. functional′ : ∀ {m n} {Γ : Ctx m n} {t a a′} → Γ ⊢ t ∈ a → a ≢ a′ → Γ ⊢ t ∉ a′ functional′ t∈a = contraposition (functional t∈a) ------------------------------------------------------------------------ -- Type checking infix 5 check_⊢_∈_ -- A predicate for typable terms HasType : ∀ {m n} → Ctx m n → Term m n → Set HasType Γ t = ∃ λ a → Γ ⊢ t ∈ a -- Type checking viewed as a decision procedure for the existence of -- typings (i.e. type synthesis). Note that together with -- functionality, this proves that the well-typedness relation is a -- decidable partial function. typeOf : ∀ {m n} (Γ : Ctx m n) t → Dec (HasType Γ t) typeOf Γ (var x) = yes (lookup Γ x , var x) typeOf Γ (Λ t) with typeOf (weakenCtx Γ) t ... | yes (a , t∈a) = yes (∀' a , Λ t∈a) ... | no ∄a = no (∄a ∘ map id proj₂ ∘ Λ-inversion ∘ proj₂) typeOf Γ (λ' a t) with typeOf (a ∷ Γ) t ... | yes (b , t∈b) = yes (a →' b , λ' a t∈b) ... | no ∄b = no (∄b ∘ map id proj₂ ∘ λ'-inversion ∘ proj₂) typeOf Γ (μ a t) with typeOf (a ∷ Γ) t typeOf Γ (μ a t) | yes ( a′ , t∈a′) with a′ ≟ a typeOf Γ (μ a t) | yes (.a , t∈a′) | yes refl = yes (a , μ a t∈a′) ... | no a′≢a = no (a′≢a ∘ functional t∈a′ ∘ proj₂ ∘ μ-inversion ∘ proj₂) typeOf Γ (μ a t) | no ∄a′ = no (∄a′ ∘ map id (uncurry ⊢substTp ∘ μ-inversion)) typeOf Γ (t [ b ]) with typeOf Γ t typeOf Γ (t [ b ]) | yes (var _ , t∈x ) = no ((functional′ t∈x λ()) ∘ proj₂ ∘ proj₂ ∘ []-inversion ∘ proj₂) typeOf Γ (t [ b ]) | yes (_ →' _ , t∈a→b ) = no ((functional′ t∈a→b λ()) ∘ proj₂ ∘ proj₂ ∘ []-inversion ∘ proj₂) typeOf Γ (t [ b ]) | yes (∀' a , t∈∀a ) = yes (a [/tp b ] , t∈∀a [ b ]) typeOf Γ (t [ b ]) | yes (μ _ , t∈μa ) = no ((functional′ t∈μa λ()) ∘ proj₂ ∘ proj₂ ∘ []-inversion ∘ proj₂) typeOf Γ (t [ b ]) | no ∄a = no (∄a ∘ map ∀' proj₂ ∘ []-inversion ∘ proj₂) typeOf Γ (s · t) with typeOf Γ s | typeOf Γ t typeOf Γ (s · t) | yes (var _ , s∈x ) | _ = no ((functional′ s∈x λ()) ∘ proj₁ ∘ proj₂ ∘ ·-inversion ∘ proj₂) typeOf Γ (s · t) | yes (a →' b , s∈a→b) | yes ( a′ , t∈a) with a′ ≟ a typeOf Γ (s · t) | yes (a →' b , s∈a→b) | yes (.a , t∈a) | yes refl = yes (b , s∈a→b · t∈a) typeOf Γ (s · t) | yes (a →' b , s∈a→b) | yes ( a′ , t∈a) | no a′≢a = no (a′≢a ∘ helper) where helper : HasType Γ (s · t) → a′ ≡ a helper (b , s·t∈b) with ·-inversion s·t∈b ... | c , s∈c→b , t∈c = begin a′ ≡⟨ functional t∈a t∈c ⟩ c ≡⟨ ≡dom→ (functional s∈c→b s∈a→b) ⟩ a ∎ typeOf Γ (s · t) | yes (a →' b , s∈a→b) | no ∄a′ = no (∄a′ ∘ map id proj₂ ∘ ·-inversion ∘ proj₂) typeOf Γ (s · t) | yes (∀' _ , s∈∀a ) | _ = no ((functional′ s∈∀a λ()) ∘ proj₁ ∘ proj₂ ∘ ·-inversion ∘ proj₂) typeOf Γ (s · t) | yes (μ _ , s∈μa ) | _ = no ((functional′ s∈μa λ()) ∘ proj₁ ∘ proj₂ ∘ ·-inversion ∘ proj₂) typeOf Γ (s · t) | no ∄a | _ = no (∄a ∘ helper) where helper : HasType Γ (s · t) → HasType Γ s helper (b , s·t∈b) with ·-inversion s·t∈b ... | a , s∈a→b , _ = a →' b , s∈a→b typeOf Γ (fold a t) with typeOf Γ t typeOf Γ (fold a t) | yes (a′ , t∈a′) with a′ ≟ a [/tp μ a ] typeOf Γ (fold a t) | yes (._ , t∈a′) | yes refl = yes (μ a , fold a t∈a′) typeOf Γ (fold a t) | yes (a′ , t∈a′) | no a′≢a[/μa] = no (a′≢a[/μa] ∘ functional t∈a′ ∘ proj₂ ∘ fold-inversion ∘ proj₂) typeOf Γ (fold a t) | no ∄a′ = no (∄a′ ∘ map (const (a [/tp μ a ])) id ∘ fold-inversion ∘ proj₂) typeOf Γ (unfold a t) with typeOf Γ t typeOf Γ (unfold a t) | yes (a′ , t∈a′) with a′ ≟ μ a typeOf Γ (unfold a t) | yes (._ , t∈a′) | yes refl = yes (a [/tp μ a ] , unfold a t∈a′) typeOf Γ (unfold a t) | yes (a′ , t∈a′) | no a′≢μa = no (a′≢μa ∘ functional t∈a′ ∘ proj₂ ∘ unfold-inversion ∘ proj₂) typeOf Γ (unfold a t) | no ∄a′ = no (∄a′ ∘ map (const (μ a)) id ∘ unfold-inversion ∘ proj₂) -- Type checking as a decision procedure for the well-typedness -- relation. check_⊢_∈_ : ∀ {m n} (Γ : Ctx m n) t a → Dec (Γ ⊢ t ∈ a) check Γ ⊢ t ∈ a with typeOf Γ t check Γ ⊢ t ∈ a | yes ( a′ , t∈a′) with a′ ≟ a check Γ ⊢ t ∈ a | yes (.a , t∈a ) | yes refl = yes t∈a check Γ ⊢ t ∈ a | yes ( a′ , t∈a′) | no a′≢a = no (a′≢a ∘ functional t∈a′) check Γ ⊢ t ∈ a | no ∄a′ = no (∄a′ ∘ helper) where helper : ∀ {m n} {Γ : Ctx m n} {t a} → Γ ⊢ t ∈ a → HasType Γ t helper {a = a} t∈a = a , t∈a ------------------------------------------------------------------------ -- Some simple test cases private module TpOp = TypeOperators module TmOp = TermOperators module WtOp = WtTermOperators -- Test: synthesize the type of the polymorphic identity. test-typeOf-id : typeOf [] (TmOp.id {n = 0}) ≡ yes (TpOp.id , WtOp.id) test-typeOf-id = refl -- Test: check the type of the polymorphic identity. test-check-id : check [] ⊢ TmOp.id {n = 0} ∈ TpOp.id ≡ yes WtOp.id test-check-id = refl -- Using the agda2-mode one can also run the above decision procedures -- interactively in GNU/Emacs by typing C-x C-n <expression>. -- E.g. typing -- -- C-x C-n typeOf [] (Λ (λ' (var zero) (var zero))) -- -- should return -- -- yes (∀' (var zero →' var zero) , Λ (λ' (var zero) (var zero))) ------------------------------------------------------------------------ -- Uniqueness of typing derivations -- There is at most one typing derivation for each triple Γ, t, a. -- I.e. if there is an x : Γ ⊢ t ∈ a, it is unique. unique : ∀ {m n} {Γ : Ctx m n} {t a} (t∈a t∈a′ : Γ ⊢ t ∈ a) → t∈a ≡ t∈a′ unique (var x) (var .x) = refl unique (Λ t∈a) (Λ t∈a′) = cong Λ (unique t∈a t∈a′) unique (λ' a t∈a) (λ' .a t∈a′) = cong (λ' a) (unique t∈a t∈a′) unique (μ a t∈a) (μ .a t∈a′) = cong (μ a) (unique t∈a t∈a′) unique {Γ = Γ} {t [ b ]} (_[_] {a = a } t∈a .b) t∈a′[b] = helper t∈a′[b] refl where helper : ∀ {a′[/b]} (t∈a′[b] : Γ ⊢ t [ b ] ∈ a′[/b]) (a[/b]≡a′[/b] : a [/tp b ] ≡ a′[/b]) → ⊢substTp a[/b]≡a′[/b] (t∈a [ b ]) ≡ t∈a′[b] helper (_[_] {a = a′} t∈a′ .b) _ with functional t∈a t∈a′ helper (t∈a′ [ .b ]) refl | refl = cong _ (unique t∈a t∈a′) unique (_·_ {a = a} s∈a→b t∈a) (_·_ {a = a′} s∈a′→b t∈a′) with functional s∈a→b s∈a′→b unique (s∈a→b · t∈a) (s∈a′→b · t∈a′) | refl = cong₂ _·_ (unique s∈a→b s∈a′→b) (unique t∈a t∈a′) unique (fold a t∈a) (fold .a t∈a′) = cong (fold a) (unique t∈a t∈a′) unique (unfold a t∈a) (unfold .a t∈a′) = cong (unfold a) (unique t∈a t∈a′)
{ "alphanum_fraction": 0.4981911729, "avg_line_length": 40.3863636364, "ext": "agda", "hexsha": "feb38aee497bfeec68e0479d71271cc3c98132e6", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-07-06T23:12:48.000Z", "max_forks_repo_forks_event_min_datetime": "2015-05-29T12:24:46.000Z", "max_forks_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sstucki/system-f-agda", "max_forks_repo_path": "src/SystemF/TypeCheck.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_issues_repo_issues_event_max_datetime": "2019-05-11T19:23:26.000Z", "max_issues_repo_issues_event_min_datetime": "2017-05-30T06:43:04.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sstucki/system-f-agda", "max_issues_repo_path": "src/SystemF/TypeCheck.agda", "max_line_length": 78, "max_stars_count": 68, "max_stars_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "sstucki/system-f-agda", "max_stars_repo_path": "src/SystemF/TypeCheck.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-01T01:25:16.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-26T13:12:56.000Z", "num_tokens": 5341, "size": 12439 }
{-# OPTIONS --without-K --safe #-} open import Polynomial.Parameters open import Algebra module Polynomial.NormalForm.Operations {a ℓ} (coeffs : RawCoeff a ℓ) where open import Polynomial.Exponentiation (RawCoeff.coeffs coeffs) open import Data.Nat as ℕ using (ℕ; suc; zero; compare) open import Data.Nat.Properties using (z≤′n) open import Data.List using (_∷_; []) open import Data.Fin using (Fin) open import Data.Product using (_,_; map₁) open import Induction.WellFounded using (Acc; acc) open import Induction.Nat using (<′-wellFounded) open import Polynomial.NormalForm.InjectionIndex open import Polynomial.NormalForm.Definition coeffs open import Polynomial.NormalForm.Construction coeffs open RawCoeff coeffs ---------------------------------------------------------------------- -- Addition ---------------------------------------------------------------------- -- The reason the following code is so verbose is termination -- checking. For instance, in the third case for ⊞-coeffs, we call a -- helper function. Instead, you could conceivably use a with-block -- (on ℕ.compare p q): -- -- ⊞-coeffs ((x , p) ∷ xs) ((y , q) ∷ ys) with (ℕ.compare p q) -- ... | ℕ.less p k = (x , p) ∷ ⊞-coeffs xs ((y , k) ∷ ys) -- ... | ℕ.equal p = (fst~ x ⊞ fst~ y , p) ∷↓ ⊞-coeffs xs ys -- ... | ℕ.greater q k = (y , q) ∷ ⊞-coeffs ((x , k) ∷ xs) ys -- -- However, because the first and third recursive calls each rewrap -- a list that was already pattern-matched on, the recursive call -- does not strictly decrease the size of its argument. -- -- Interestingly, if --without-K is turned off, we don't need the -- helper function ⊞-coeffs; we could pattern match on _⊞_ directly. -- -- _⊞_ {zero} (lift x) (lift y) = lift (x + y) -- _⊞_ {suc n} [] ys = ys -- _⊞_ {suc n} (x ∷ xs) [] = x ∷ xs -- _⊞_ {suc n} ((x , p) ∷ xs) ((y , q) ∷ ys) = -- ⊞-zip (ℕ.compare p q) x xs y ys mutual infixl 6 _⊞_ _⊞_ : ∀ {n} → Poly n → Poly n → Poly n (xs Π i≤n) ⊞ (ys Π j≤n) = ⊞-match (inj-compare i≤n j≤n) xs ys ⊞-match : ∀ {i j n} → {i≤n : i ≤′ n} → {j≤n : j ≤′ n} → InjectionOrdering i≤n j≤n → FlatPoly i → FlatPoly j → Poly n ⊞-match (inj-eq i&j≤n) (Κ x) (Κ y) = Κ (x + y) Π i&j≤n ⊞-match (inj-eq i&j≤n) (Σ (x Δ i & xs)) (Σ (y Δ j & ys)) = ⊞-zip (compare i j) x xs y ys Π↓ i&j≤n ⊞-match (inj-lt i≤j-1 j≤n) xs (Σ ys) = ⊞-inj i≤j-1 xs ys Π↓ j≤n ⊞-match (inj-gt i≤n j≤i-1) (Σ xs) ys = ⊞-inj j≤i-1 ys xs Π↓ i≤n ⊞-inj : ∀ {i k} → (i ≤′ k) → FlatPoly i → Coeff k + → Coeff k * ⊞-inj i≤k xs (y Π j≤k ≠0 Δ zero & ys) = ⊞-match (inj-compare j≤k i≤k) y xs Δ zero ∷↓ ys ⊞-inj i≤k xs (y Δ suc j & ys) = xs Π i≤k Δ zero ∷↓ ∹ y Δ j & ys ⊞-coeffs : ∀ {n} → Coeff n * → Coeff n * → Coeff n * ⊞-coeffs (∹ x Δ i & xs) ys = ⊞-zip-r x i xs ys ⊞-coeffs [] ys = ys ⊞-zip : ∀ {p q n} → ℕ.Ordering p q → NonZero n → Coeff n * → NonZero n → Coeff n * → Coeff n * ⊞-zip (ℕ.less i k) x xs y ys = (∹ x Δ i & ⊞-zip-r y k ys xs) ⊞-zip (ℕ.greater j k) x xs y ys = (∹ y Δ j & ⊞-zip-r x k xs ys) ⊞-zip (ℕ.equal i ) x xs y ys = (x .poly ⊞ y .poly) Δ i ∷↓ ⊞-coeffs xs ys ⊞-zip-r : ∀ {n} → NonZero n → ℕ → Coeff n * → Coeff n * → Coeff n * ⊞-zip-r x i xs [] = ∹ x Δ i & xs ⊞-zip-r x i xs (∹ y Δ j & ys) = ⊞-zip (compare i j) x xs y ys {-# INLINE ⊞-zip #-} ---------------------------------------------------------------------- -- Negation ---------------------------------------------------------------------- -- recurse on acc directly -- https://github.com/agda/agda/issues/3190#issuecomment-416900716 ⊟-step : ∀ {n} → Acc _<′_ n → Poly n → Poly n ⊟-step (acc wf) (Κ x Π i≤n) = Κ (- x) Π i≤n ⊟-step (acc wf) (Σ xs Π i≤n) = poly-map (⊟-step (wf _ i≤n)) xs Π↓ i≤n ⊟_ : ∀ {n} → Poly n → Poly n ⊟_ = ⊟-step (<′-wellFounded _) {-# INLINE ⊟_ #-} ---------------------------------------------------------------------- -- Multiplication ---------------------------------------------------------------------- mutual ⊠-step′ : ∀ {n} → Acc _<′_ n → Poly n → Poly n → Poly n ⊠-step′ a (x Π i≤n) = ⊠-step a x i≤n ⊠-step : ∀ {i n} → Acc _<′_ n → FlatPoly i → i ≤′ n → Poly n → Poly n ⊠-step a (Κ x) _ = ⊠-Κ a x ⊠-step a (Σ xs) = ⊠-Σ a xs ⊠-Κ : ∀ {n} → Acc _<′_ n → Carrier → Poly n → Poly n ⊠-Κ (acc _ ) x (Κ y Π i≤n) = Κ (x * y) Π i≤n ⊠-Κ (acc wf) x (Σ xs Π i≤n) = ⊠-Κ-inj (wf _ i≤n) x xs Π↓ i≤n ⊠-Σ : ∀ {i n} → Acc _<′_ n → Coeff i + → i <′ n → Poly n → Poly n ⊠-Σ (acc wf) xs i≤n (Σ ys Π j≤n) = ⊠-match (acc wf) (inj-compare i≤n j≤n) xs ys ⊠-Σ (acc wf) xs i≤n (Κ y Π _) = ⊠-Κ-inj (wf _ i≤n) y xs Π↓ i≤n ⊠-Κ-inj : ∀ {i} → Acc _<′_ i → Carrier → Coeff i + → Coeff i * ⊠-Κ-inj a x xs = poly-map (⊠-Κ a x) (xs) ⊠-Σ-inj : ∀ {i k} → Acc _<′_ k → i <′ k → Coeff i + → Poly k → Poly k ⊠-Σ-inj (acc wf) i≤k x (Σ y Π j≤k) = ⊠-match (acc wf) (inj-compare i≤k j≤k) x y ⊠-Σ-inj (acc wf) i≤k x (Κ y Π j≤k) = ⊠-Κ-inj (wf _ i≤k) y x Π↓ i≤k ⊠-match : ∀ {i j n} → Acc _<′_ n → {i≤n : i <′ n} → {j≤n : j <′ n} → InjectionOrdering i≤n j≤n → Coeff i + → Coeff j + → Poly n ⊠-match (acc wf) (inj-eq i&j≤n) xs ys = ⊠-coeffs (wf _ i&j≤n) xs ys Π↓ i&j≤n ⊠-match (acc wf) (inj-lt i≤j-1 j≤n) xs ys = poly-map (⊠-Σ-inj (wf _ j≤n) i≤j-1 xs) (ys) Π↓ j≤n ⊠-match (acc wf) (inj-gt i≤n j≤i-1) xs ys = poly-map (⊠-Σ-inj (wf _ i≤n) j≤i-1 ys) (xs) Π↓ i≤n ⊠-coeffs : ∀ {n} → Acc _<′_ n → Coeff n + → Coeff n + → Coeff n * ⊠-coeffs a xs (y ≠0 Δ j & []) = poly-map (⊠-step′ a y) xs ⍓* j ⊠-coeffs a xs (y ≠0 Δ j & ∹ ys) = para (⊠-cons a y ys) xs ⍓* j ⊠-cons : ∀ {n} → Acc _<′_ n → Poly n → Coeff n + → Fold n -- ⊠-cons a y [] (x Π j≤n , xs) = ⊠-step a x j≤n y , xs ⊠-cons a y ys (x Π j≤n , xs) = ⊠-step a x j≤n y , ⊞-coeffs (poly-map (⊠-step a x j≤n) ys) xs {-# INLINE ⊠-Κ #-} {-# INLINE ⊠-coeffs #-} {-# INLINE ⊠-cons #-} infixl 7 _⊠_ _⊠_ : ∀ {n} → Poly n → Poly n → Poly n _⊠_ = ⊠-step′ (<′-wellFounded _) {-# INLINE _⊠_ #-} ---------------------------------------------------------------------- -- Constants and Variables ---------------------------------------------------------------------- -- The constant polynomial κ : ∀ {n} → Carrier → Poly n κ x = Κ x Π z≤′n {-# INLINE κ #-} -- A variable ι : ∀ {n} → Fin n → Poly n ι i = (κ 1# Δ 1 ∷↓ []) Π↓ Fin⇒≤ i {-# INLINE ι #-} ---------------------------------------------------------------------- -- Exponentiation ---------------------------------------------------------------------- -- We try very hard to never do things like multiply by 1 -- unnecessarily. That's what all the weirdness here is for. ⊡-mult : ∀ {n} → ℕ → Poly n → Poly n ⊡-mult zero xs = xs ⊡-mult (suc n) xs = ⊡-mult n xs ⊠ xs _⊡_+1 : ∀ {n} → Poly n → ℕ → Poly n (Κ x Π i≤n) ⊡ i +1 = Κ (x ^ i +1) Π i≤n (Σ (x Δ j & []) Π i≤n) ⊡ i +1 = x .poly ⊡ i +1 Δ (j ℕ.+ i ℕ.* j) ∷↓ [] Π↓ i≤n xs@(Σ (_ & ∹ _) Π i≤n) ⊡ i +1 = ⊡-mult i xs infixr 8 _⊡_ _⊡_ : ∀ {n} → Poly n → ℕ → Poly n _ ⊡ zero = κ 1# xs ⊡ suc i = xs ⊡ i +1 {-# INLINE _⊡_ #-}
{ "alphanum_fraction": 0.4533625531, "avg_line_length": 34.9330143541, "ext": "agda", "hexsha": "61772bc413c7b74f5e0ea4f665fd819ff5fed90b", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z", "max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z", "max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/agda-ring-solver", "max_forks_repo_path": "src/Polynomial/NormalForm/Operations.agda", "max_issues_count": 5, "max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/agda-ring-solver", "max_issues_repo_path": "src/Polynomial/NormalForm/Operations.agda", "max_line_length": 103, "max_stars_count": 36, "max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/agda-ring-solver", "max_stars_repo_path": "src/Polynomial/NormalForm/Operations.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z", "num_tokens": 3104, "size": 7301 }
{- Constructing List ErrorPart from format strings. Supported formats %s : String %d : Nat %t : Term %n : Name %e : List ErrorPart Examples at the bottom. -} module Tactic.Reflection.Printf where open import Prelude open import Prelude.Variables open import Builtin.Reflection private data Format (A : Set) : Set where fmtLit : A → Format A fmtStr : Format A fmtNat : Format A fmtTerm : Format A fmtName : Format A fmtErrs : Format A instance FunctorFormat : Functor Format FunctorFormat .fmap f (fmtLit x) = fmtLit (f x) FunctorFormat .fmap f fmtStr = fmtStr FunctorFormat .fmap f fmtNat = fmtNat FunctorFormat .fmap f fmtTerm = fmtTerm FunctorFormat .fmap f fmtName = fmtName FunctorFormat .fmap f fmtErrs = fmtErrs parseFormat : String → List (Format String) parseFormat = map (fmap packString) ∘ parse ∘ unpackString where cons : Char → List (Format (List Char)) → List (Format (List Char)) cons c (fmtLit cs ∷ fs) = fmtLit (c ∷ cs) ∷ fs cons c fs = fmtLit [ c ] ∷ fs parse : List Char → List (Format (List Char)) parse ('%' ∷ 's' ∷ fmt) = fmtStr ∷ parse fmt parse ('%' ∷ 'd' ∷ fmt) = fmtNat ∷ parse fmt parse ('%' ∷ 't' ∷ fmt) = fmtTerm ∷ parse fmt parse ('%' ∷ 'n' ∷ fmt) = fmtName ∷ parse fmt parse ('%' ∷ 'e' ∷ fmt) = fmtErrs ∷ parse fmt parse ('%' ∷ '%' ∷ fmt) = cons '%' (parse fmt) parse (c ∷ fmt) = cons c (parse fmt) parse [] = [] FormatErrorType : List (Format String) → Set ℓ → Set ℓ FormatErrorType [] Res = Res FormatErrorType (fmtLit _ ∷ fs) Res = FormatErrorType fs Res FormatErrorType (fmtStr ∷ fs) Res = String → FormatErrorType fs Res FormatErrorType (fmtNat ∷ fs) Res = Nat → FormatErrorType fs Res FormatErrorType (fmtTerm ∷ fs) Res = Term → FormatErrorType fs Res FormatErrorType (fmtName ∷ fs) Res = Name → FormatErrorType fs Res FormatErrorType (fmtErrs ∷ fs) Res = List ErrorPart → FormatErrorType fs Res -- Exported for library writers formatError : (List ErrorPart → A) → (fmt : String) → FormatErrorType (parseFormat fmt) A formatError {A = A} k = format [] ∘ parseFormat where format : List ErrorPart → (fmt : List (Format String)) → FormatErrorType fmt A format acc [] = k (reverse acc) format acc (fmtLit s ∷ fmt) = format (strErr s ∷ acc) fmt format acc (fmtStr ∷ fmt) s = format (strErr s ∷ acc) fmt format acc (fmtNat ∷ fmt) n = format (strErr (show n) ∷ acc) fmt format acc (fmtTerm ∷ fmt) t = format (termErr t ∷ acc) fmt format acc (fmtName ∷ fmt) x = format (nameErr x ∷ acc) fmt format acc (fmtErrs ∷ fmt) e = format (reverse e ++ acc) fmt -- Public API -- errorPartsFmt : (fmt : String) → FormatErrorType (parseFormat fmt) (List ErrorPart) errorPartsFmt = formatError id typeErrorFmt : (fmt : String) → FormatErrorType (parseFormat fmt) (TC A) typeErrorFmt = formatError typeError debugPrintFmt : String → Nat → (fmt : String) → FormatErrorType (parseFormat fmt) (TC ⊤) debugPrintFmt tag lvl = formatError (debugPrint tag lvl) -- Examples -- private _ : Name → Term → List ErrorPart _ = errorPartsFmt "%n : %t" _ : Name → Nat → Nat → TC A _ = typeErrorFmt "%n applied to %d arguments, expected %d" _ : Term → String → TC ⊤ _ = debugPrintFmt "tactic.foo" 10 "solving %t with %s"
{ "alphanum_fraction": 0.627994228, "avg_line_length": 34.3069306931, "ext": "agda", "hexsha": "5ba7cf8863a8f3380f34dc90d033bef2c4dd90d7", "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": "158d299b1b365e186f00d8ef5b8c6844235ee267", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "L-TChen/agda-prelude", "max_forks_repo_path": "src/Tactic/Reflection/Printf.agda", "max_issues_count": 59, "max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267", "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": "L-TChen/agda-prelude", "max_issues_repo_path": "src/Tactic/Reflection/Printf.agda", "max_line_length": 89, "max_stars_count": 111, "max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "L-TChen/agda-prelude", "max_stars_repo_path": "src/Tactic/Reflection/Printf.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": 1085, "size": 3465 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Bundles for homogeneous binary relations ------------------------------------------------------------------------ -- The contents of this module should be accessed via `Relation.Binary`. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Bundles where open import Level open import Relation.Nullary using (¬_) open import Relation.Binary.Core open import Relation.Binary.Definitions open import Relation.Binary.Structures ------------------------------------------------------------------------ -- Setoids ------------------------------------------------------------------------ record PartialSetoid a ℓ : Set (suc (a ⊔ ℓ)) where field Carrier : Set a _≈_ : Rel Carrier ℓ isPartialEquivalence : IsPartialEquivalence _≈_ open IsPartialEquivalence isPartialEquivalence public _≉_ : Rel Carrier _ x ≉ y = ¬ (x ≈ y) record Setoid c ℓ : Set (suc (c ⊔ ℓ)) where infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ isEquivalence : IsEquivalence _≈_ open IsEquivalence isEquivalence public partialSetoid : PartialSetoid c ℓ partialSetoid = record { isPartialEquivalence = isPartialEquivalence } open PartialSetoid partialSetoid public using (_≉_) record DecSetoid c ℓ : Set (suc (c ⊔ ℓ)) where infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ isDecEquivalence : IsDecEquivalence _≈_ open IsDecEquivalence isDecEquivalence public setoid : Setoid c ℓ setoid = record { isEquivalence = isEquivalence } open Setoid setoid public using (partialSetoid; _≉_) ------------------------------------------------------------------------ -- Preorders ------------------------------------------------------------------------ record Preorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _∼_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ -- The underlying equality. _∼_ : Rel Carrier ℓ₂ -- The relation. isPreorder : IsPreorder _≈_ _∼_ open IsPreorder isPreorder public hiding (module Eq) module Eq where setoid : Setoid c ℓ₁ setoid = record { isEquivalence = isEquivalence } open Setoid setoid public ------------------------------------------------------------------------ -- Partial orders ------------------------------------------------------------------------ record Poset c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _≤_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _≤_ : Rel Carrier ℓ₂ isPartialOrder : IsPartialOrder _≈_ _≤_ open IsPartialOrder isPartialOrder public hiding (module Eq) preorder : Preorder c ℓ₁ ℓ₂ preorder = record { isPreorder = isPreorder } open Preorder preorder public using (module Eq) record DecPoset c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _≤_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _≤_ : Rel Carrier ℓ₂ isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ private module DPO = IsDecPartialOrder isDecPartialOrder open DPO public hiding (module Eq) poset : Poset c ℓ₁ ℓ₂ poset = record { isPartialOrder = isPartialOrder } open Poset poset public using (preorder) module Eq where decSetoid : DecSetoid c ℓ₁ decSetoid = record { isDecEquivalence = DPO.Eq.isDecEquivalence } open DecSetoid decSetoid public record StrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _<_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _<_ : Rel Carrier ℓ₂ isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ open IsStrictPartialOrder isStrictPartialOrder public hiding (module Eq) module Eq where setoid : Setoid c ℓ₁ setoid = record { isEquivalence = isEquivalence } open Setoid setoid public record DecStrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _<_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _<_ : Rel Carrier ℓ₂ isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ private module DSPO = IsDecStrictPartialOrder isDecStrictPartialOrder open DSPO public hiding (module Eq) strictPartialOrder : StrictPartialOrder c ℓ₁ ℓ₂ strictPartialOrder = record { isStrictPartialOrder = isStrictPartialOrder } module Eq where decSetoid : DecSetoid c ℓ₁ decSetoid = record { isDecEquivalence = DSPO.Eq.isDecEquivalence } open DecSetoid decSetoid public ------------------------------------------------------------------------ -- Total orders ------------------------------------------------------------------------ record TotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _≤_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _≤_ : Rel Carrier ℓ₂ isTotalOrder : IsTotalOrder _≈_ _≤_ open IsTotalOrder isTotalOrder public hiding (module Eq) poset : Poset c ℓ₁ ℓ₂ poset = record { isPartialOrder = isPartialOrder } open Poset poset public using (module Eq; preorder) record DecTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _≤_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _≤_ : Rel Carrier ℓ₂ isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ private module DTO = IsDecTotalOrder isDecTotalOrder open DTO public hiding (module Eq) totalOrder : TotalOrder c ℓ₁ ℓ₂ totalOrder = record { isTotalOrder = isTotalOrder } open TotalOrder totalOrder public using (poset; preorder) decPoset : DecPoset c ℓ₁ ℓ₂ decPoset = record { isDecPartialOrder = isDecPartialOrder } open DecPoset decPoset public using (module Eq) -- Note that these orders are decidable. The current implementation -- of `Trichotomous` subsumes irreflexivity and asymmetry. Any reasonable -- definition capturing these three properties implies decidability -- as `Trichotomous` necessarily separates out the equality case. record StrictTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _<_ field Carrier : Set c _≈_ : Rel Carrier ℓ₁ _<_ : Rel Carrier ℓ₂ isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ open IsStrictTotalOrder isStrictTotalOrder public hiding (module Eq) strictPartialOrder : StrictPartialOrder c ℓ₁ ℓ₂ strictPartialOrder = record { isStrictPartialOrder = isStrictPartialOrder } open StrictPartialOrder strictPartialOrder public using (module Eq) decSetoid : DecSetoid c ℓ₁ decSetoid = record { isDecEquivalence = isDecEquivalence } {-# WARNING_ON_USAGE decSetoid "Warning: decSetoid was deprecated in v1.3. Please use Eq.decSetoid instead." #-}
{ "alphanum_fraction": 0.586328899, "avg_line_length": 25.6945454545, "ext": "agda", "hexsha": "136980fe558d0dc65061016063fc98aee879ece2", "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/Relation/Binary/Bundles.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/Relation/Binary/Bundles.agda", "max_line_length": 73, "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/Relation/Binary/Bundles.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": 2027, "size": 7066 }
------------------------------------------------------------------------ -- Indexed containers ------------------------------------------------------------------------ -- Some parts are based on "Indexed containers" by Altenkirch, Ghani, -- Hancock, McBride and Morris (JFP, 2015). {-# OPTIONS --sized-types #-} module Indexed-container where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude open import Prelude.Size open import Bijection equality-with-J as Bijection using (_↔_) import Equivalence equality-with-J as Eq open import Function-universe equality-with-J hiding (id; _∘_) open import H-level.Closure equality-with-J open import Surjection equality-with-J using (_↠_) open import Univalence-axiom equality-with-J open import Relation ------------------------------------------------------------------------ -- Containers -- Doubly indexed containers. record Container {ℓ} (I O : Type ℓ) : Type (lsuc ℓ) where constructor _◁_ field Shape : Rel ℓ O Position : ∀ {o} → Shape o → Rel ℓ I -- Interpretation of containers. ⟦_⟧ : ∀ {ℓ₁ ℓ₂} {I O : Type ℓ₁} → Container I O → Rel ℓ₂ I → Rel (ℓ₁ ⊔ ℓ₂) O ⟦ S ◁ P ⟧ A = λ o → ∃ λ (s : S o) → P s ⊆ A -- A map function. map : ∀ {ℓ₁ ℓ₂ ℓ₃} {I O : Type ℓ₁} (C : Container I O) {A : Rel ℓ₂ I} {B : Rel ℓ₃ I} → A ⊆ B → ⟦ C ⟧ A ⊆ ⟦ C ⟧ B map _ f (s , g) = (s , f ∘ g) -- Functor laws. map-id : ∀ {ℓ₁ ℓ₂} {I O : Type ℓ₁} {C : Container I O} {A : Rel ℓ₂ I} → _≡_ {A = ⟦ C ⟧ A ⊆ _} (map C id) id map-id = refl map-∘ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} {I O : Type ℓ₁} {C : Container I O} {D : Rel ℓ₂ I} {E : Rel ℓ₃ I} {F : Rel ℓ₄ I} (f : E ⊆ F) (g : D ⊆ E) → _≡_ {A = ⟦ C ⟧ D ⊆ _} (map C (f ∘ g)) (map C f ∘ map C g) map-∘ _ _ = refl -- A preservation lemma. ⟦⟧-cong : ∀ {k ℓ₁ ℓ₂ ℓ₃} {I O : Type ℓ₁} → Extensionality? k ℓ₁ (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) → (C : Container I O) {A : Rel ℓ₂ I} {B : Rel ℓ₃ I} → (∀ {i} → A i ↝[ k ] B i) → (∀ {o} → ⟦ C ⟧ A o ↝[ k ] ⟦ C ⟧ B o) ⟦⟧-cong ext (S ◁ P) {A} {B} A↝B {o} = (∃ λ (s : S o) → P s ⊆ A) ↝⟨ (∃-cong λ _ → ⊆-congʳ ext A↝B) ⟩□ (∃ λ (s : S o) → P s ⊆ B) □ -- The shapes of a container are in pointwise bijective correspondence -- with the interpretation of the container applied to the constant -- function yielding the unit type. -- -- (This lemma was suggested to me by an anonymous reviewer of another -- paper.) Shape↔⟦⟧⊤ : ∀ {ℓ} {I O : Type ℓ} (C : Container I O) {o} → Container.Shape C o ↔ ⟦ C ⟧ (λ _ → ⊤) o Shape↔⟦⟧⊤ C {o} = Shape C o ↝⟨ inverse $ drop-⊤-right (λ _ → →-right-zero) ⟩ (∃ λ (s : Shape C o) → ∃ (Position C s) → ⊤) ↝⟨ ∃-cong (λ _ → currying) ⟩ (∃ λ (s : Shape C o) → ∀ i → Position C s i → ⊤) ↝⟨ ∃-cong (λ _ → inverse Bijection.implicit-Π↔Π) ⟩□ (∃ λ (s : Shape C o) → Position C s ⊆ (λ _ → ⊤)) □ where open Container ------------------------------------------------------------------------ -- Least fixpoints mutual -- The least fixpoint of an indexed "endocontainer", expressed using -- sized types. μ : ∀ {ℓ} {X : Type ℓ} → Container X X → Size → Rel ℓ X μ C i = ⟦ C ⟧ (μ′ C i) data μ′ {ℓ} {X : Type ℓ} (C : Container X X) (i : Size) (x : X) : Type ℓ where ⟨_⟩ : {j : Size< i} → μ C j x → μ′ C i x -- The least fixpoint μ C ∞ is pointwise logically equivalent to -- μ′ C ∞. μ⇔μ′ : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x : X} → μ C ∞ x ⇔ μ′ C ∞ x μ⇔μ′ = record { to = ⟨_⟩ ; from = λ { ⟨ x ⟩ → x } } -- The least fixpoint is a post-fixpoint. μ-out : ∀ {ℓ} {X : Type ℓ} {C : Container X X} → μ C ∞ ⊆ ⟦ C ⟧ (μ C ∞) μ-out {C = C} = map C (_⇔_.from μ⇔μ′) -- The least fixpoint is a pre-fixpoint. μ-in : ∀ {ℓ} {X : Type ℓ} {C : Container X X} → ⟦ C ⟧ (μ C ∞) ⊆ μ C ∞ μ-in {C = C} = map C (_⇔_.to μ⇔μ′) -- The least fixpoint is smaller than or equal to every -- pre-fixpoint. fold : ∀ {ℓ₁ ℓ₂} {X : Type ℓ₁} (C : Container X X) {A : Rel ℓ₂ X} → ⟦ C ⟧ A ⊆ A → ∀ {i} → μ C i ⊆ A fold C f a = f (map C (λ { ⟨ a ⟩ → fold C f a }) a) ------------------------------------------------------------------------ -- Greatest fixpoints mutual -- The greatest fixpoint of an indexed "endocontainer", expressed -- using sized types. ν : ∀ {ℓ} {X : Type ℓ} → Container X X → Size → Rel ℓ X ν C i = ⟦ C ⟧ (ν′ C i) record ν′ {ℓ} {X : Type ℓ} (C : Container X X) (i : Size) (x : X) : Type ℓ where coinductive field force : {j : Size< i} → ν C j x open ν′ public -- The greatest fixpoint ν C ∞ is pointwise logically equivalent to -- ν′ C ∞. ν⇔ν′ : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x : X} → ν C ∞ x ⇔ ν′ C ∞ x ν⇔ν′ = record { to = λ { x .force → x } ; from = λ x → force x } -- The greatest fixpoint ν C ∞ is a post-fixpoint. ν-out : ∀ {ℓ} {X : Type ℓ} {i} {j : Size< i} (C : Container X X) → ν C i ⊆ ⟦ C ⟧ (ν C j) ν-out C = map C (λ x → force x) private ν-out-∞ : ∀ {ℓ} {X : Type ℓ} (C : Container X X) → ν C ∞ ⊆ ⟦ C ⟧ (ν C ∞) ν-out-∞ = ν-out -- The greatest fixpoint is a pre-fixpoint. ν-in : ∀ {ℓ} {X : Type ℓ} {i} (C : Container X X) → ⟦ C ⟧ (ν C i) ⊆ ν C i ν-in C = map C (λ x → λ { .force → x }) -- The greatest fixpoint is greater than or equal to every -- post-fixpoint. unfold : ∀ {ℓ₁ ℓ₂} {X : Type ℓ₁} {A : Rel ℓ₂ X} {i} (C : Container X X) → A ⊆ ⟦ C ⟧ A → A ⊆ ν C i unfold C f = map C (λ a → λ { .force → unfold C f a }) ∘ f -- A generalisation of unfold with more sized types. sized-unfold : ∀ {ℓ₁ ℓ₂} {X : Type ℓ₁} (C : Container X X) (A : Size → Rel ℓ₂ X) → (∀ {i} {j : Size< i} → A i ⊆ ⟦ C ⟧ (A j)) → ∀ {i} {j : Size< i} → A i ⊆ ν C j sized-unfold C A f = map C (λ a → λ { .force → sized-unfold C A f a }) ∘ f ------------------------------------------------------------------------ -- Bisimilarity -- A container corresponding to bisimilarity for a given container. Bisimilarity : ∀ {ℓ} {X : Type ℓ} {C : Container X X} → let P = ∃ λ x → ν C ∞ x × ν C ∞ x in Container P P Bisimilarity {C = C} = (λ { (_ , (s₁ , _) , (s₂ , _)) → s₁ ≡ s₂ }) ◁ (λ { {o = _ , (s₁ , f₁) , (s₂ , f₂)} eq (x , x₁ , x₂) → ∃ λ (p : Container.Position C s₁ x) → x₁ ≡ force (f₁ p) × x₂ ≡ force (f₂ (subst (λ s → Container.Position C s x) eq p)) }) -- Bisimilarity for ν. ν-bisimilar : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x} → Size → Rel₂ ℓ (ν C ∞ x) ν-bisimilar i p = ν Bisimilarity i (_ , p) ν′-bisimilar : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x} → Size → Rel₂ ℓ (ν′ C ∞ x) ν′-bisimilar i (x , y) = ν′ Bisimilarity i (_ , force x , force y) -- Lifts a family of binary relations from X to ⟦ C ⟧ X. ⟦_⟧₂ : ∀ {ℓ₁ ℓ₂} {I O : Type ℓ₁} {A : Rel ℓ₂ I} (C : Container I O) → (∀ {i} → Rel₂ ℓ₁ (A i)) → ∀ {o} → Rel₂ ℓ₁ (⟦ C ⟧ A o) ⟦ C ⟧₂ R ((s , f) , (t , g)) = ∃ λ (eq : s ≡ t) → ∀ {o} (p : Position C s o) → R (f p , g (subst (λ s → Position C s o) eq p)) where open Container -- An alternative characterisation of bisimilarity. ν-bisimilar↔ : ∀ {k ℓ} {X : Type ℓ} {C : Container X X} {x i} → Extensionality? k ℓ ℓ → (x y : ν C ∞ x) → ν-bisimilar i (x , y) ↝[ k ] ⟦ C ⟧₂ (ν′-bisimilar i) (x , y) ν-bisimilar↔ {C = C} {i = i} ext (s₁ , f₁) (s₂ , f₂) = ν-bisimilar i ((s₁ , f₁) , (s₂ , f₂)) ↔⟨⟩ (∃ λ (eq : s₁ ≡ s₂) → ∀ {x} → (∃ λ (p : Position C s₁ (proj₁ x)) → proj₁ (proj₂ x) ≡ force (f₁ p) × proj₂ (proj₂ x) ≡ force (f₂ (subst (λ s → Position C s (proj₁ x)) eq p))) → ν′ Bisimilarity i x) ↝⟨ ∃-cong lemma ⟩ (∃ λ (eq : s₁ ≡ s₂) → ∀ {x} (p : Position C s₁ x) → ν′-bisimilar i (f₁ p , f₂ (subst (λ s → Position C s x) eq p))) ↔⟨⟩ ⟦ C ⟧₂ (ν′-bisimilar i) ((s₁ , f₁) , (s₂ , f₂)) □ where open Container lemma = λ eq → (∀ {x} → (∃ λ (p : Position C s₁ (proj₁ x)) → proj₁ (proj₂ x) ≡ force (f₁ p) × proj₂ (proj₂ x) ≡ force (f₂ (subst (λ s → Position C s (proj₁ x)) eq p))) → ν′ Bisimilarity i x) ↔⟨ Bijection.implicit-Π↔Π ⟩ (∀ x → (∃ λ (p : Position C s₁ (proj₁ x)) → proj₁ (proj₂ x) ≡ force (f₁ p) × proj₂ (proj₂ x) ≡ force (f₂ (subst (λ s → Position C s (proj₁ x)) eq p))) → ν′ Bisimilarity i x) ↝⟨ (∀-cong ext λ _ → from-isomorphism currying) ⟩ (∀ x (p : Position C s₁ (proj₁ x)) → proj₁ (proj₂ x) ≡ force (f₁ p) × proj₂ (proj₂ x) ≡ force (f₂ (subst (λ s → Position C s (proj₁ x)) eq p)) → ν′ Bisimilarity i x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩ (∀ x (p : Position C s₁ (proj₁ x)) → proj₁ (proj₂ x) ≡ force (f₁ p) → proj₂ (proj₂ x) ≡ force (f₂ (subst (λ s → Position C s (proj₁ x)) eq p)) → ν′ Bisimilarity i x) ↔⟨ currying ⟩ (∀ x yz (p : Position C s₁ x) → proj₁ yz ≡ force (f₁ p) → proj₂ yz ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , yz)) ↝⟨ (∀-cong ext λ _ → from-isomorphism Π-comm) ⟩ (∀ x (p : Position C s₁ x) yz → proj₁ yz ≡ force (f₁ p) → proj₂ yz ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , yz)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism currying) ⟩ (∀ x (p : Position C s₁ x) y z → y ≡ force (f₁ p) → z ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , y , z)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism Π-comm) ⟩ (∀ x (p : Position C s₁ x) → ∀ y → y ≡ force (f₁ p) → ∀ z → z ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , y , z)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism $ inverse currying) ⟩ (∀ x (p : Position C s₁ x) → (y : ∃ λ y → y ≡ force (f₁ p)) → ∀ z → z ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , proj₁ y , z)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → drop-⊤-left-Π ext ( _⇔_.to contractible⇔↔⊤ $ singleton-contractible _)) ⟩ (∀ x (p : Position C s₁ x) → ∀ z → z ≡ force (f₂ (subst (λ s → Position C s x) eq p)) → ν′ Bisimilarity i (x , force (f₁ p) , z)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-isomorphism $ inverse currying) ⟩ (∀ x (p : Position C s₁ x) → (z : ∃ λ z → z ≡ force (f₂ (subst (λ s → Position C s x) eq p))) → ν′ Bisimilarity i (x , force (f₁ p) , proj₁ z)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → drop-⊤-left-Π ext ( _⇔_.to contractible⇔↔⊤ $ singleton-contractible _)) ⟩ (∀ x (p : Position C s₁ x) → ν′ Bisimilarity i (x , force (f₁ p) , force (f₂ (subst (λ s → Position C s x) eq p)))) ↔⟨ inverse $ Bijection.implicit-Π↔Π ⟩ (∀ {x} (p : Position C s₁ x) → ν′ Bisimilarity i (x , force (f₁ p) , force (f₂ (subst (λ s → Position C s x) eq p)))) ↔⟨⟩ (∀ {x} (p : Position C s₁ x) → ν′-bisimilar i (f₁ p , f₂ (subst (λ s → Position C s x) eq p))) □ module Bisimilarity {ℓ} {X : Type ℓ} {C : Container X X} {x i} (x y : ν C ∞ x) where -- A "constructor". ⟨_,_,_,_⟩ : (eq : proj₁ x ≡ proj₁ y) → (∀ {o} (p : Container.Position C (proj₁ x) o) → ν′-bisimilar i ( proj₂ x p , proj₂ y (subst (λ s → Container.Position C s o) eq p) )) → ν-bisimilar i (x , y) ⟨_,_,_,_⟩ = curry $ _⇔_.from (ν-bisimilar↔ _ x y) -- A "projection". split : ν-bisimilar i (x , y) → ⟦ C ⟧₂ (ν′-bisimilar i) (x , y) split = ν-bisimilar↔ _ x y -- Bisimilarity is reflexive. reflexive-ν : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x} (x : ν C ∞ x) {i} → ν-bisimilar i (x , x) reflexive-ν x = Bisimilarity.⟨ x , x , refl , (λ { p .force → reflexive-ν (force (proj₂ x p)) }) ⟩ -- Bisimilarity is symmetric. symmetric-ν : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x} (x y : ν C ∞ x) {i} → ν-bisimilar i (x , y) → ν-bisimilar i (y , x) symmetric-ν x y bisim with Bisimilarity.split x y bisim ... | refl , bisim′ = Bisimilarity.⟨ y , x , refl , (λ { p .force → symmetric-ν (force (proj₂ x p)) (force (proj₂ y p)) (force (bisim′ p)) }) ⟩ -- Bisimilarity is transitive. transitive-ν : ∀ {ℓ} {X : Type ℓ} {C : Container X X} {x} (x y z : ν C ∞ x) {i} → ν-bisimilar i (x , y) → ν-bisimilar i (y , z) → ν-bisimilar i (x , z) transitive-ν x y z bisim₁ bisim₂ with Bisimilarity.split x y bisim₁ | Bisimilarity.split y z bisim₂ ... | refl , bisim₁′ | refl , bisim₂′ = Bisimilarity.⟨ x , z , refl , (λ { p .force → transitive-ν (force (proj₂ x p)) (force (proj₂ y p)) (force (proj₂ z p)) (force (bisim₁′ p)) (force (bisim₂′ p)) }) ⟩ -- Extensionality for ν′ C: bisimilarity implies equality. -- -- Note that I have not, at the time of writing, determined whether -- this is a consistent assumption. Uses of this and similar -- assumptions are tracked using the type system. ν′-extensionality : ∀ {ℓ} {X : Type ℓ} → Container X X → Type ℓ ν′-extensionality C = ∀ {x} {y z : ν′ C ∞ x} → ν′-bisimilar ∞ (y , z) → y ≡ z -- The formulation of extensionality given above for ν′ can be used to -- derive a form of extensionality for ν (in the presence of -- extensionality for functions). ν-extensionality : ∀ {ℓ} {X : Type ℓ} {C : Container X X} → Extensionality ℓ ℓ → ν′-extensionality C → ∀ {x} {y z : ν C ∞ x} → ν-bisimilar ∞ (y , z) → y ≡ z ν-extensionality {C = C} ext ν′-ext {y = y@(s , f₁)} {z = z@(.s , f₂)} bisim@(refl , _) = $⟨ (λ _ → proj₂ $ Bisimilarity.split y z bisim) ⟩ (∀ x (p : Position C s x) → ν′-bisimilar ∞ (f₁ p , f₂ p)) ↝⟨ (ν′-ext ∘_) ∘_ ⟩ (∀ x (p : Position C s x) → f₁ p ≡ f₂ p) ↝⟨ implicit-extensionality ext ∘ (apply-ext ext ∘_) ⟩ (λ {_} → f₁) ≡ f₂ ↝⟨ cong (s ,_) ⟩□ y ≡ z □ where open Container ------------------------------------------------------------------------ -- More properties related to ν and ν′ -- The greatest fixpoint is a fixpoint in a different sense -- (assuming two kinds of extensionality and univalence). ν-fixpoint : ∀ {ℓ} → Extensionality ℓ (lsuc ℓ) → Univalence ℓ → {X : Type ℓ} (C : Container X X) → ν′-extensionality C → ν C ∞ ≡ ⟦ C ⟧ (ν C ∞) ν-fixpoint ext univ C ν′-ext = ν C ∞ ≡⟨⟩ ⟦ C ⟧ (ν′ C ∞) ≡⟨ cong ⟦ C ⟧ (apply-ext ext λ _ → ≃⇒≡ univ (Eq.↔⇒≃ ν′↔ν)) ⟩ ⟦ C ⟧ (ν C ∞) ∎ where ν′↔ν : ∀ {x} → ν′ C ∞ x ↔ ν C ∞ x ν′↔ν = record { surjection = record { logical-equivalence = record { to = λ x → force x ; from = λ x → record { force = x } } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ x → ν′-ext (record { force = reflexive-ν (force x) }) } -- The unfold function makes a certain diagram commute. unfold-commute : ∀ {ℓ₁ ℓ₂} {X : Type ℓ₁} (C : Container X X) {A : Rel ℓ₂ X} (f : A ⊆ ⟦ C ⟧ A) → ∀ {i x} (a : A x) → ν-bisimilar i ( unfold C f a , ν-in C (map C (unfold C f) (f a)) ) unfold-commute C f a = Bisimilarity.⟨ unfold C f a , ν-in C (map C (unfold C f) (f a)) , refl , (λ { p .force → reflexive-ν (unfold C f (proj₂ (f a) p)) }) ⟩ -- A uniqueness property for unfold. unfold-unique : ∀ {ℓ₁ ℓ₂} {X : Type ℓ₁} (C : Container X X) {A : Rel ℓ₂ X} (f : A ⊆ ⟦ C ⟧ A) (u : A ⊆ ν C ∞) {i} → (∀ {x} (a : A x) → ν-bisimilar i (u a , ν-in C (map C u (f a)))) → ∀ {x} (a : A x) → ν-bisimilar i (u a , unfold C f a) unfold-unique C f u bisim a with Bisimilarity.split (u a) (ν-in C (map C u (f a))) (bisim a) ... | eq , bisim′ = Bisimilarity.⟨ u a , unfold C f a , eq , (λ { p .force → let p′ = subst (λ s → Container.Position C s _) eq p in transitive-ν (force (proj₂ (u a) p)) (force (proj₂ (ν-in C (map C u (f a))) p′)) (force (proj₂ (unfold C f a) p′)) (force (bisim′ p)) (unfold-unique C f u bisim _) }) ⟩ ------------------------------------------------------------------------ -- An alternative definition of greatest fixpoints -- The greatest fixpoint of an indexed "endocontainer" (parametrised -- by a universe level). gfp : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} → Container X X → Rel (lsuc (ℓ₁ ⊔ ℓ₂)) X gfp {ℓ₁} ℓ₂ {X} C x = ∃ λ (R : Rel (ℓ₁ ⊔ ℓ₂) X) → R ⊆ ⟦ C ⟧ R × R x -- The greatest fixpoint is greater than or equal to every -- sufficiently small post-fixpoint. gfp-unfold : ∀ {ℓ₁ ℓ₂} ℓ₃ {X : Type ℓ₁} {C : Container X X} {A : Rel ℓ₂ X} → A ⊆ ⟦ C ⟧ A → A ⊆ gfp (ℓ₂ ⊔ ℓ₃) C gfp-unfold {ℓ₁} ℓ₃ {C = C} {A} f a = ↑ (ℓ₁ ⊔ ℓ₃) ∘ A , map C lift ∘ f ∘ lower , lift a -- The greatest fixpoint is a post-fixpoint. gfp-out : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} → gfp ℓ₂ C ⊆ ⟦ C ⟧ (gfp ℓ₂ C) gfp-out ℓ₂ {C = C} (R , R⊆CR , Ri) = map C (λ Ri → R , (λ {_} → R⊆CR) , Ri) (R⊆CR Ri) -- It is possible to use gfp-unfold ℓ₂ R⊆CR as the second argument -- to map above. However, the extra lifting would break the proof -- gfp⊆ν∘ν⊆gfp given below. -- The first definition of greatest fixpoints is contained in the -- second one. ν⊆gfp : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} → ν C ∞ ⊆ gfp ℓ₂ C ν⊆gfp ℓ₂ = gfp-unfold ℓ₂ (ν-out {i = ∞} _) -- The second definition of greatest fixpoints is contained in the -- first one. gfp⊆ν : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} {i} → gfp ℓ₂ C ⊆ ν C i gfp⊆ν ℓ₂ = unfold _ (gfp-out ℓ₂) -- Thus the two definitions of greatest fixpoints are pointwise -- logically equivalent. gfp⇔ν : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} {i} → gfp ℓ₂ C i ⇔ ν C ∞ i gfp⇔ν ℓ₂ = record { to = gfp⊆ν ℓ₂ ; from = ν⊆gfp ℓ₂ } -- The function gfp⊆ν is a left inverse of ν⊆gfp (up to pointwise -- bisimilarity). gfp⊆ν∘ν⊆gfp : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} {x} (x : ν C ∞ x) {i} → ν-bisimilar i (gfp⊆ν ℓ₂ (ν⊆gfp ℓ₂ x) , x) gfp⊆ν∘ν⊆gfp ℓ₂ {C = C} x = _⇔_.from (ν-bisimilar↔ _ (gfp⊆ν ℓ₂ (ν⊆gfp ℓ₂ x)) x) ( refl , (λ { p .force → gfp⊆ν∘ν⊆gfp ℓ₂ (force (proj₂ x p)) }) ) -- There is a split surjection from the second definition of greatest -- fixpoints to the first one (assuming two kinds of extensionality). gfp↠ν : ∀ {ℓ₁} → Extensionality ℓ₁ ℓ₁ → ∀ ℓ₂ {X : Type ℓ₁} {C : Container X X} → ν′-extensionality C → ∀ {x} → gfp ℓ₂ C x ↠ ν C ∞ x gfp↠ν ext ℓ₂ ν′-ext = record { logical-equivalence = gfp⇔ν ℓ₂ ; right-inverse-of = λ x → ν-extensionality ext ν′-ext (gfp⊆ν∘ν⊆gfp ℓ₂ x) } -- The larger versions of gfp are logically equivalent to the smallest -- one. larger⇔smallest : ∀ {ℓ₁} ℓ₂ {X : Type ℓ₁} {C : Container X X} {x} → gfp ℓ₂ C x ⇔ gfp lzero C x larger⇔smallest ℓ₂ {C = C} {x} = gfp ℓ₂ C x ↝⟨ gfp⇔ν ℓ₂ ⟩ ν C ∞ x ↝⟨ inverse $ gfp⇔ν lzero ⟩□ gfp lzero C x □
{ "alphanum_fraction": 0.4694699612, "avg_line_length": 33.1008130081, "ext": "agda", "hexsha": "946339f0e350cb0dce3c3073ec8629f9263936d8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Indexed-container.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Indexed-container.agda", "max_line_length": 140, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Indexed-container.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7922, "size": 20357 }
module Utilities.ExistsSyntax where open import Level using (Level ; _⊔_) open import Data.Product using (Σ) variable a b : Level A : Set a B : Set b ∃-syntax : (A : Set a) → (A → Set b) → Set (a ⊔ b) ∃-syntax = Σ syntax ∃-syntax A (λ x → B) = ∃ x ∶ A • B
{ "alphanum_fraction": 0.5939849624, "avg_line_length": 17.7333333333, "ext": "agda", "hexsha": "29e036e6086afaf8a3bfa714b25c3f4ddb02c530", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "armkeh/agda-computability", "max_forks_repo_path": "src/Utilities/ExistsSyntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "armkeh/agda-computability", "max_issues_repo_path": "src/Utilities/ExistsSyntax.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "armkeh/agda-computability", "max_stars_repo_path": "src/Utilities/ExistsSyntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 103, "size": 266 }
------------------------------------------------------------------------ -- An example showing how Container.Tree-sort can be used ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Container.Tree-sort.Example {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where open Derived-definitions-and-properties eq open import Prelude using (ℕ; zero; suc; Bool; true; false) open import Container eq open import Container.List eq -- Comparison function for natural numbers. _≤_ : ℕ → ℕ → Bool zero ≤ _ = true suc _ ≤ zero = false suc m ≤ suc n = m ≤ n open import Container.Tree-sort eq _≤_ -- The sort function seems to return an ordered list. ordered : sort (3 ∷ 1 ∷ 2 ∷ []) ≡ 1 ∷ 2 ∷ 3 ∷ [] ordered = refl _ -- The sort function definitely returns a list which is bag equivalent -- to the input. This property can be used to establish bag -- equivalences between concrete lists. a-bag-equivalence : 1 ∷ 2 ∷ 3 ∷ [] ≈-bag 3 ∷ 1 ∷ 2 ∷ [] a-bag-equivalence = sort≈ (3 ∷ 1 ∷ 2 ∷ [])
{ "alphanum_fraction": 0.5762081784, "avg_line_length": 27.5897435897, "ext": "agda", "hexsha": "e15721478d5fcd3e363c1dc66688ff8801da419d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Container/Tree-sort/Example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/Container/Tree-sort/Example.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Container/Tree-sort/Example.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 292, "size": 1076 }
------------------------------------------------------------------------ -- Inversion of (sub)typing in Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Typing.Inversion where open import Data.Product using (_,_; proj₁; proj₂; _×_; map) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Relation.Nullary using (¬_) open import FOmegaInt.Syntax open import FOmegaInt.Typing open import FOmegaInt.Typing.Validity open import FOmegaInt.Kinding.Declarative.Normalization open import FOmegaInt.Kinding.Canonical.Equivalence using (sound-<:; sound-<∷; complete-<∷; complete-<:-⋯) import FOmegaInt.Kinding.Canonical.Inversion as CanInv open Syntax open TermCtx hiding (map) open Typing open Substitution using (_[_]; weaken) open WfCtxOps using (lookup-tp) open TypedSubstitution open TypedNarrowing ------------------------------------------------------------------------ -- Generation/inversion of typing. infix 4 _⊢Tm-gen_∈_ -- The possible types of a term (i.e. the possible results of -- generating/inverting _⊢Tp_∈_). data _⊢Tm-gen_∈_ {n} (Γ : Ctx n) : Term n → Term n → Set where ∈-var : ∀ {a b} x → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢ a <: b ∈ * → Γ ⊢Tm-gen var x ∈ b ∈-∀-i : ∀ {k a b c} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tm a ∈ b → Γ ⊢ Π k b <: c ∈ * → Γ ⊢Tm-gen Λ k a ∈ c ∈-→-i : ∀ {a b c d} → Γ ⊢Tp a ∈ * → tp a ∷ Γ ⊢Tm b ∈ weaken c → Γ ⊢ a ⇒ c <: d ∈ * → Γ ⊢Tm-gen ƛ a b ∈ d ∈-∀-e : ∀ {a b k c d} → Γ ⊢Tm a ∈ Π k c → Γ ⊢Tp b ∈ k → Γ ⊢ c [ b ] <: d ∈ * → Γ ⊢Tm-gen a ⊡ b ∈ d ∈-→-e : ∀ {a b c d e} → Γ ⊢Tm a ∈ c ⇒ d → Γ ⊢Tm b ∈ c → Γ ⊢ d <: e ∈ * → Γ ⊢Tm-gen a · b ∈ e -- Generation/inversion of typing. Tm∈-gen : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tm a ∈ b → Γ ⊢Tm-gen a ∈ b Tm∈-gen (∈-var x Γ-ctx Γ[x]≡kd-a) = ∈-var x Γ-ctx Γ[x]≡kd-a (<:-refl (Tm∈-valid (∈-var x Γ-ctx Γ[x]≡kd-a))) Tm∈-gen (∈-∀-i k-kd a∈b) = ∈-∀-i k-kd a∈b (<:-refl (Tm∈-valid (∈-∀-i k-kd a∈b))) Tm∈-gen (∈-→-i a∈* b∈c c∈*) = ∈-→-i a∈* b∈c (<:-refl (Tm∈-valid (∈-→-i a∈* b∈c c∈*))) Tm∈-gen (∈-∀-e a∈∀kc b∈k) = ∈-∀-e a∈∀kc b∈k (<:-refl (Tm∈-valid (∈-∀-e a∈∀kc b∈k))) Tm∈-gen (∈-→-e a∈c⇒d b∈c) = ∈-→-e a∈c⇒d b∈c (<:-refl (Tm∈-valid (∈-→-e a∈c⇒d b∈c))) Tm∈-gen (∈-⇑ a∈b b<:c) with Tm∈-gen a∈b Tm∈-gen (∈-⇑ x∈b c<:d) | ∈-var x Γ-ctx Γ[x]≡kd-a a<:b = ∈-var x Γ-ctx Γ[x]≡kd-a (<:-trans a<:b c<:d) Tm∈-gen (∈-⇑ Λka∈b b<:c) | ∈-∀-i k-kd a∈d ∀kd<:b = ∈-∀-i k-kd a∈d (<:-trans ∀kd<:b b<:c) Tm∈-gen (∈-⇑ ƛab∈c c<:d) | ∈-→-i a∈* b∈c a⇒c<:d = ∈-→-i a∈* b∈c (<:-trans a⇒c<:d c<:d) Tm∈-gen (∈-⇑ a·b∈e e<:f) | ∈-∀-e a∈Πcd b∈c d[b]<:e = ∈-∀-e a∈Πcd b∈c (<:-trans d[b]<:e e<:f) Tm∈-gen (∈-⇑ a·b∈e e<:f) | ∈-→-e a∈c⇒d b∈c d<:e = ∈-→-e a∈c⇒d b∈c (<:-trans d<:e e<:f) ------------------------------------------------------------------------ -- Inversion of subtyping (in the empty context). -- NOTE. The following two lemmas only hold in the empty context -- because we can not invert instances of the interval projection -- rules (<:-⟨| and (<:-|⟩) in arbitrary contexts. This is because -- instances of these rules can reflect arbitrary subtyping -- assumptions into the subtyping relation. Consider, e.g. -- -- Γ, X :: ⊤..⊥ ctx Γ(X) = ⊥..⊤ -- ------------------------------- (∈-var) -- Γ, X :: ⊤..⊥ ⊢ X :: ⊤..⊥ -- -------------------------- (<:-⟨|, <:-|⟩) -- Γ, X :: ⊤..⊥ ⊢ ⊤ <: X <: ⊥ -- -- Which allows us to prove that ⊤ <: ⊥ using (<:-trans) under the -- assumption (X : ⊤..⊥). On the other hand, it is impossible to give -- a transitivity-free proof of ⊤ <: ⊥. In general, it is therefore -- impossible to invert subtyping statements in non-empty contexts, -- i.e. one cannot prove lemmas like (<:-→-inv) or (<:-∀-inv) below -- for arbitrary contexts. <:-∀-inv : ∀ {k₁ k₂ : Kind Term 0} {a₁ a₂} → [] ⊢ Π k₁ a₁ <: Π k₂ a₂ ∈ * → [] ⊢ k₂ <∷ k₁ × kd k₂ ∷ [] ⊢ a₁ <: a₂ ∈ * <:-∀-inv ∀k₁a₁<:∀k₂a₂∈* = let nf-∀k₁a₁<:nf-∀k₂a₂ = complete-<:-⋯ ∀k₁a₁<:∀k₂a₂∈* nf-k₂<∷nf-k₁ , nf-a₁<:nf-a₂ = CanInv.<:-∀-inv nf-∀k₁a₁<:nf-∀k₂a₂ ∀k₁a₁∈* , ∀k₂a₂∈* = <:-valid ∀k₁a₁<:∀k₂a₂∈* k₁≅nf-k₁∈* , a₁≃nf-a₁∈* = Tp∈-∀-≃-⌞⌟-nf ∀k₁a₁∈* k₂≅nf-k₂∈* , a₂≃nf-a₂∈* = Tp∈-∀-≃-⌞⌟-nf ∀k₂a₂∈* k₂<∷nf-k₂∈* = ≅⇒<∷ k₂≅nf-k₂∈* k₂<∷k₁ = <∷-trans (<∷-trans k₂<∷nf-k₂∈* (sound-<∷ nf-k₂<∷nf-k₁)) (≅⇒<∷ (≅-sym k₁≅nf-k₁∈*)) in k₂<∷k₁ , <:-trans (<:-trans (⇓-<: k₂<∷k₁ (≃⇒<: a₁≃nf-a₁∈*)) (⇓-<: k₂<∷nf-k₂∈* (sound-<: nf-a₁<:nf-a₂))) (≃⇒<: (≃-sym a₂≃nf-a₂∈*)) <:-→-inv : ∀ {a₁ a₂ b₁ b₂ : Term 0} → [] ⊢ a₁ ⇒ b₁ <: a₂ ⇒ b₂ ∈ * → [] ⊢ a₂ <: a₁ ∈ * × [] ⊢ b₁ <: b₂ ∈ * <:-→-inv a₁⇒b₁<:a₂⇒b₂∈* = let nf-a₁⇒b₁<:nf-a₂⇒b₂ = complete-<:-⋯ a₁⇒b₁<:a₂⇒b₂∈* nf-a₂<:nf-a₁ , nf-b₁<:nf-b₂ = CanInv.<:-→-inv nf-a₁⇒b₁<:nf-a₂⇒b₂ a₁⇒b₁∈* , a₂⇒b₂∈* = <:-valid a₁⇒b₁<:a₂⇒b₂∈* a₁≃nf-a₁∈* , b₁≃nf-b₁∈* = Tp∈-→-≃-⌞⌟-nf a₁⇒b₁∈* a₂≃nf-a₂∈* , b₂≃nf-b₂∈* = Tp∈-→-≃-⌞⌟-nf a₂⇒b₂∈* in <:-trans (<:-trans (≃⇒<: a₂≃nf-a₂∈*) (sound-<: nf-a₂<:nf-a₁)) (≃⇒<: (≃-sym a₁≃nf-a₁∈*)) , <:-trans (<:-trans (≃⇒<: b₁≃nf-b₁∈*) (sound-<: nf-b₁<:nf-b₂)) (≃⇒<: (≃-sym b₂≃nf-b₂∈*)) -- ⊤ is not a subtype of ⊥. ⊤-≮:-⊥ : ∀ {a : Term 0} → ¬ [] ⊢ ⊤ <: ⊥ ∈ * ⊤-≮:-⊥ ⊤<:⊥ with CanInv.⊤-<:-max (complete-<:-⋯ ⊤<:⊥) ⊤-≮:-⊥ ⊤<:⊥ | () -- Arrows are not canonical subtypes of universals and vice-versa. ⇒-≮:-Π : ∀ {a₁ b₁ : Term 0} {k₂ a₂} → ¬ [] ⊢ a₁ ⇒ b₁ <: Π k₂ a₂ ∈ * ⇒-≮:-Π a₁⇒b₁<:∀k₂a₂∈* = CanInv.⇒-≮:-Π (complete-<:-⋯ a₁⇒b₁<:∀k₂a₂∈*) Π-≮:-⇒ : ∀ {k₁ a₁} {a₂ b₂ : Term 0} → ¬ [] ⊢ Π k₁ a₁ <: a₂ ⇒ b₂ ∈ * Π-≮:-⇒ ∀k₁a₁<:a₂⇒b₂∈* = CanInv.Π-≮:-⇒ (complete-<:-⋯ ∀k₁a₁<:a₂⇒b₂∈*)
{ "alphanum_fraction": 0.4546545517, "avg_line_length": 42.268115942, "ext": "agda", "hexsha": "dc3f0d4782fc14c1cd3b9eb176646641c903aee7", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Typing/Inversion.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Typing/Inversion.agda", "max_line_length": 80, "max_stars_count": 12, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Typing/Inversion.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "num_tokens": 3035, "size": 5833 }
{-# OPTIONS --safe #-} module Cubical.Data.FinSet.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Foundations.Equiv open import Cubical.HITs.PropositionalTruncation open import Cubical.Data.Nat open import Cubical.Data.Fin open import Cubical.Data.Sigma private variable ℓ : Level A : Type ℓ isFinSet : Type ℓ → Type ℓ isFinSet A = ∃[ n ∈ ℕ ] A ≃ Fin n -- finite sets are sets isFinSet→isSet : isFinSet A → isSet A isFinSet→isSet = rec isPropIsSet (λ (_ , p) → isOfHLevelRespectEquiv 2 (invEquiv p) isSetFin) isPropIsFinSet : isProp (isFinSet A) isPropIsFinSet = isPropPropTrunc -- the type of finite sets FinSet : (ℓ : Level) → Type (ℓ-suc ℓ) FinSet ℓ = TypeWithStr _ isFinSet
{ "alphanum_fraction": 0.7496886675, "avg_line_length": 22.9428571429, "ext": "agda", "hexsha": "b1911f03ede20f1d722200af93f23c93056bae8d", "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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/Data/FinSet/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/Data/FinSet/Base.agda", "max_line_length": 93, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/Data/FinSet/Base.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 267, "size": 803 }
open import Haskell.Prim open import Agda.Builtin.Nat data _≤_ : Nat → Nat → Set where instance zero-≤ : ∀ {n} → zero ≤ n suc-≤ : ∀ {m n} → @0 {{m ≤ n}} → suc m ≤ suc n data Tree {l u : Nat} : Set where Leaf : @0 {{l ≤ u}} → Tree {l} {u} Node : (x : Nat) → Tree {l} {x} → Tree {x} {u} → Tree {l} {u} {-# COMPILE AGDA2HS Tree #-}
{ "alphanum_fraction": 0.5100864553, "avg_line_length": 26.6923076923, "ext": "agda", "hexsha": "7baa4280264d9399d5410d0c7bde34d00507cd42", "lang": "Agda", "max_forks_count": 18, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z", "max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "seanpm2001/agda2hs", "max_forks_repo_path": "test/Tree.agda", "max_issues_count": 63, "max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z", "max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "seanpm2001/agda2hs", "max_issues_repo_path": "test/Tree.agda", "max_line_length": 64, "max_stars_count": 55, "max_stars_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda2hs", "max_stars_repo_path": "test/Tree.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z", "num_tokens": 145, "size": 347 }
module Serializer.Bool where open import Data.Bool open import Data.Fin hiding (_+_) open import Data.Nat open import Relation.Binary open import Relation.Binary.EqReasoning open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; cong ; setoid ) import Relation.Binary.Indexed as I open import Function.Equality using (_⟶_ ; _⟨$⟩_ ; Π ) open import Function.LeftInverse hiding (_∘_) open import Function.Injection open import Function.Surjection open import Function.Bijection open import Serializer fromBool : Bool -> Fin 2 fromBool true = zero fromBool false = suc zero toBool : Fin 2 -> Bool toBool zero = true toBool (suc x) = false bool-cong : Setoid._≈_ (setoid Bool) I.=[ fromBool ]⇒ Setoid._≈_ (setoid (Fin 2)) bool-cong refl = refl bool-cong-inv : Setoid._≈_ (setoid (Fin 2)) I.=[ toBool ]⇒ Setoid._≈_ (setoid (Bool)) bool-cong-inv refl = refl from-bool-preserves-eq : setoid Bool ⟶ setoid (Fin 2) from-bool-preserves-eq = record { _⟨$⟩_ = fromBool ; cong = bool-cong } from-bool-injective : Injective from-bool-preserves-eq from-bool-injective {true} {true} refl = refl from-bool-injective {true} {false} () from-bool-injective {false} {true} () from-bool-injective {false} {false} refl = refl bool-preserves-eq-inv : setoid (Fin 2) ⟶ setoid Bool bool-preserves-eq-inv = record { _⟨$⟩_ = toBool ; cong = bool-cong-inv } bool-inv : bool-preserves-eq-inv RightInverseOf from-bool-preserves-eq bool-inv zero = refl bool-inv (suc zero) = refl bool-inv (suc (suc ())) from-bool-surjective : Surjective from-bool-preserves-eq from-bool-surjective = record { from = bool-preserves-eq-inv ; right-inverse-of = bool-inv } bool-bijection : Bijection (setoid Bool) (setoid (Fin 2)) bool-bijection = record { to = from-bool-preserves-eq ; bijective = record { injective = from-bool-injective ; surjective = from-bool-surjective } } instance serializerBool : Serializer Bool serializerBool = record { size = 2 ; from = fromBool ; to = toBool ; bijection = bool-bijection }
{ "alphanum_fraction": 0.7224146462, "avg_line_length": 32.5967741935, "ext": "agda", "hexsha": "1505715a7081aee3983857d16cb01e8b98e03f6a", "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": "cb95986b772b7a01195619be5e8e590f2429c759", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mathijsb/generic-in-agda", "max_forks_repo_path": "Serializer/Bool.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "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": "mathijsb/generic-in-agda", "max_issues_repo_path": "Serializer/Bool.agda", "max_line_length": 149, "max_stars_count": 6, "max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mathijsb/generic-in-agda", "max_stars_repo_path": "Serializer/Bool.agda", "max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z", "num_tokens": 617, "size": 2021 }
module Fail.QualifiedRecordProjections where record Test (a : Set) : Set where field one : a {-# COMPILE AGDA2HS Test #-}
{ "alphanum_fraction": 0.6923076923, "avg_line_length": 16.25, "ext": "agda", "hexsha": "709999a1c4d3102d81910816315bcc38f47cafd5", "lang": "Agda", "max_forks_count": 18, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z", "max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "seanpm2001/agda2hs", "max_forks_repo_path": "test/Fail/QualifiedRecordProjections.agda", "max_issues_count": 63, "max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6", "max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z", "max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "seanpm2001/agda2hs", "max_issues_repo_path": "test/Fail/QualifiedRecordProjections.agda", "max_line_length": 44, "max_stars_count": 55, "max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dxts/agda2hs", "max_stars_repo_path": "test/Fail/QualifiedRecordProjections.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z", "num_tokens": 37, "size": 130 }
{-# OPTIONS --instance-search-depth=10 #-} module _ where module _ {A : Set} (B₁ : A → Set) (B₂ : A → Set) (f : A → A) where type = ∀ {x : A} → B₁ x → B₂ (f x) record Class : Set where field method : type method : {{_ : Class}} → type method {{I}} = Class.method I id : ∀ {A : Set} → A → A id x = x Ext : {A : Set} (B : A → Set) → A → Set Ext B x = B x → B x postulate Foo : Set instance _ : {A : Set} {B : A → Set} {{_ : Class (Ext B) (Ext B) id}} → Class (Ext B) (Ext (λ _ → Foo)) id module _ {A : Set} (B : A → Set) {{_ : Class (Ext B) (Ext B) id}} {y} (R : B y → Set) where postulate _ : let Point = λ (f : B y → B y) → ∀ x → R (f x) in Class Point Point (method (Ext _) (Ext _) id)
{ "alphanum_fraction": 0.4689922481, "avg_line_length": 17.2, "ext": "agda", "hexsha": "84ffc212ba7577478d83f21dad31232b7175fcc0", "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/Issue2690.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/Issue2690.agda", "max_line_length": 56, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue2690.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": 300, "size": 774 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Rings.Definition open import Rings.Ideals.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Rings.Ideals.Maximal.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} {c : _} {pred : A → Set c} (i : Ideal R pred) where record MaximalIdeal {d : _} : Set (a ⊔ b ⊔ c ⊔ lsuc d) where field notContained : A notContainedIsNotContained : (pred notContained) → False isMaximal : {bigger : A → Set d} → Ideal R bigger → ({a : A} → pred a → bigger a) → (Sg A (λ a → bigger a && (pred a → False))) → ({a : A} → bigger a)
{ "alphanum_fraction": 0.6305555556, "avg_line_length": 42.3529411765, "ext": "agda", "hexsha": "4567c7809cbb6b449476ee5883c95f7b7bfbcafa", "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": "Rings/Ideals/Maximal/Definition.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": "Rings/Ideals/Maximal/Definition.agda", "max_line_length": 178, "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": "Rings/Ideals/Maximal/Definition.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": 249, "size": 720 }
module Utilities.VecSplit where -- Standard libraries imports ---------------------------------------- open import Data.Nat using (ℕ ; _+_) open import Data.Vec using (Vec ; _++_) open import Relation.Binary.PropositionalEquality using (_≡_) open import Relation.Binary.HeterogeneousEquality using (_≅_) ---------------------------------------------------------------------- record Split {A : Set} {n : ℕ} (xs : Vec A n) : Set where field {m₁} {m₂} : ℕ n≡m₁+m₂ : n ≡ m₁ + m₂ ys : Vec A m₁ zs : Vec A m₂ xs≅ys++zs : xs ≅ ys ++ zs
{ "alphanum_fraction": 0.5161290323, "avg_line_length": 27.9, "ext": "agda", "hexsha": "de0ff2a4d2084e6696abca917f71bb941368b53a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "armkeh/agda-computability", "max_forks_repo_path": "src/Utilities/VecSplit.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "armkeh/agda-computability", "max_issues_repo_path": "src/Utilities/VecSplit.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "f6a6845a54aed7ecc6841ff5ad89643b553cbd77", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "armkeh/agda-computability", "max_stars_repo_path": "src/Utilities/VecSplit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 158, "size": 558 }
{-# OPTIONS --allow-unsolved-metas #-} module x05-842Isomorphism-hc where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; cong-app; sym; subst) -- added last open Eq.≡-Reasoning open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _^_) open import Data.Nat.Properties using (+-comm; +-suc; +-identityʳ) -- added last ------------------------------------------------------------------------------ open import x02-842Induction-hc-2 hiding (+-suc; +-identityʳ) ------------------------------------------------------------------------------ -- Function composition. _∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) (g ∘ f) x = g (f x) _∘′_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) g ∘′ f = λ x → g (f x) ------------------------------------------------------------------------------ -- EXTENSIONALITY postulate extensionality : ∀ {A B : Set} {f g : A → B} → (∀ (x : A) → f x ≡ g x) ----------------------- → f ≡ g -- def of + that matches on right _+′_ : ℕ → ℕ → ℕ m +′ zero = m m +′ suc n = suc (m +′ n) same-app : ∀ (m n : ℕ) → m +′ n ≡ m + n same-app m zero -- (m +′ zero) ≡ m + zero -- m ≡ m + zero rewrite +-identityʳ m -- m ≡ m = refl same-app m (suc n) -- (m +′ suc n) ≡ m + suc n -- suc (m +′ n) ≡ m + suc n rewrite +-suc m n -- suc (m +′ n) ≡ suc (m + n) | same-app m n -- suc (m + n) ≡ suc (m + n) = refl -- requires extensionality +′-same-as-+ : _+′_ ≡ _+_ +′-same-as-+ = extensionality λ m → extensionality λ n → same-app m n ------------------------------------------------------------------------------ -- ISOMORPHISM infix 0 _≃_ record _≃_ (A B : Set) : Set where constructor mk-≃ -- added, not in PLFA field to : A → B from : B → A from∘to : ∀ (x : A) → from (to x) ≡ x to∘from : ∀ (y : B) → to (from y) ≡ y open _≃_ -- RECORD def equivalent to DATA def and functions: data _≃′_ (A B : Set): Set where mk-≃′ : ∀ (to : A → B) → ∀ (from : B → A) → ∀ (from∘to : (∀ (x : A) → from (to x) ≡ x)) → ∀ (to∘from : (∀ (y : B) → to (from y) ≡ y)) → A ≃′ B to′ : ∀ {A B : Set} → (A ≃′ B) → (A → B) to′ (mk-≃′ f g g∘f f∘g) = f from′ : ∀ {A B : Set} → (A ≃′ B) → (B → A) from′ (mk-≃′ f g g∘f f∘g) = g from∘to′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (x : A) → from′ A≃B (to′ A≃B x) ≡ x) from∘to′ (mk-≃′ f g g∘f f∘g) = g∘f to∘from′ : ∀ {A B : Set} → (A≃B : A ≃′ B) → (∀ (y : B) → to′ A≃B (from′ A≃B y) ≡ y) to∘from′ (mk-≃′ f g g∘f f∘g) = f∘g -- End of equivalent formulation (records are faster!) ------------------------------------------------------------------------------ -- PROPERTIES OF ISOMORPHISM : AN EQUIVALENCE RELATION (i.e., reflexive, symmetric and transitive) -- reflexive ≃-refl : ∀ {A : Set} ----- → A ≃ A -- in empty hole, split on result, get COPATTERNS (not in PLFA) to ≃-refl x = x from ≃-refl x = x from∘to ≃-refl x = refl to∘from ≃-refl x = refl -- symmetric ≃-sym : ∀ {A B : Set} → A ≃ B ----- → B ≃ A to (≃-sym A≃B) = from A≃B from (≃-sym A≃B) = to A≃B from∘to (≃-sym A≃B) = to∘from A≃B to∘from (≃-sym A≃B) = from∘to A≃B -- transitive ≃-trans : ∀ {A B C : Set} → A ≃ B → B ≃ C ----- → A ≃ C to (≃-trans A≃B B≃C) = to B≃C ∘ to A≃B from (≃-trans A≃B B≃C) = from A≃B ∘ from B≃C from∘to (≃-trans A≃B B≃C) x rewrite from∘to B≃C (to A≃B x) = from∘to A≃B x to∘from (≃-trans A≃B B≃C) x rewrite to∘from A≃B (from B≃C x) = to∘from B≃C x -- syntax for isomorphic equational reasoning module ≃-Reasoning where infix 1 ≃-begin_ infixr 2 _≃⟨_⟩_ infix 3 _≃-∎ ≃-begin_ : ∀ {A B : Set} → A ≃ B ----- → A ≃ B ≃-begin A≃B = A≃B _≃⟨_⟩_ : ∀ (A : Set) {B C : Set} → A ≃ B → B ≃ C ----- → A ≃ C A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C _≃-∎ : ∀ (A : Set) ----- → A ≃ A A ≃-∎ = ≃-refl open ≃-Reasoning ------------------------------------------------------------------------------ -- EMBEDDING (weaker than isomorphism) infix 0 _≲_ record _≲_ (A B : Set) : Set where field to : A → B from : B → A from∘to : ∀ (x : A) → from (to x) ≡ x open _≲_ ≲-refl : ∀ {A : Set} → A ≲ A to ≲-refl x = x from ≲-refl x = x from∘to ≲-refl x = refl ≲-trans : ∀ {A B C : Set} → A ≲ B → B ≲ C → A ≲ C to (≲-trans A≲B B≲C) = to B≲C ∘ to A≲B from (≲-trans A≲B B≲C) = from A≲B ∘ from B≲C from∘to (≲-trans A≲B B≲C) x rewrite from∘to B≲C (to A≲B x) = from∘to A≲B x ≲-antisym : ∀ {A B : Set} → (A≲B : A ≲ B) → (B≲A : B ≲ A) → (to A≲B ≡ from B≲A) → (from A≲B ≡ to B≲A) ------------------- → A ≃ B to (≲-antisym A≲B B≲A to≡from from≡to) = to A≲B from (≲-antisym A≲B B≲A to≡from from≡to) = from A≲B from∘to (≲-antisym A≲B B≲A to≡from from≡to) x = from∘to A≲B x to∘from (≲-antisym A≲B B≲A to≡from from≡to) y rewrite from≡to | to≡from = from∘to B≲A y -- equational reasoning for embedding module ≲-Reasoning where infix 1 ≲-begin_ infixr 2 _≲⟨_⟩_ infix 3 _≲-∎ ≲-begin_ : ∀ {A B : Set} → A ≲ B ----- → A ≲ B ≲-begin A≲B = A≲B _≲⟨_⟩_ : ∀ (A : Set) {B C : Set} → A ≲ B → B ≲ C ----- → A ≲ C A ≲⟨ A≲B ⟩ B≲C = ≲-trans A≲B B≲C _≲-∎ : ∀ (A : Set) ----- → A ≲ A A ≲-∎ = ≲-refl open ≲-Reasoning ------------------------------------------------------------------------------ -- isomorphism implies embedding ≃-implies-≲ : ∀ {A B : Set} → A ≃ B ----- → A ≲ B to (≃-implies-≲ a≃b) = to a≃b from (≃-implies-≲ a≃b) = from a≃b from∘to (≃-implies-≲ a≃b) = from∘to a≃b ------------------------------------------------------------------------------ -- PROPOSITIONAL EQUIVALENCE (weaker than embedding) - aka IFF -- an equivalence relation record _⇔_ (A B : Set) : Set where field to : A → B from : B → A open _⇔_ -- added ⇔-refl : ∀ {A : Set} ----- → A ⇔ A _⇔_.to ⇔-refl x = x _⇔_.from ⇔-refl x = x ⇔-sym : ∀ {A B : Set} → A ⇔ B ----- → B ⇔ A _⇔_.to (⇔-sym A⇔B) = from A⇔B _⇔_.from (⇔-sym A⇔B) = to A⇔B ⇔-trans : ∀ {A B C : Set} → A ⇔ B → B ⇔ C ----- → A ⇔ C to (⇔-trans A⇔B B⇔C) = to B⇔C ∘ to A⇔B from (⇔-trans A⇔B B⇔C) = from A⇔B ∘ from B⇔C {- ------------------------------------------------------------------------------ -- 842 extended exercise: Canonical bitstrings. -- Modified and extended from Bin-predicates exercise in PLFA Relations. cannot prove ∀ {n : Bin-ℕ} → tob (fromb n) ≡ n because of possibility of leading zeroes in Bin-ℕ value (e.g., 'bits x0 x0 x1') It s true for Bin-ℕ without leading zeroes -} -- Predicate that states: -- value of type One n is evidence that n has a leading one. data One : Bin-ℕ → Set where [bitsx1] : One (bits x1) _[x0] : ∀ {b : Bin-ℕ} → One b → One (b x0) _[x1] : ∀ {b : Bin-ℕ} → One b → One (b x1) -- proof that 'bits x1 x0 x0' has leading one _ : One (bits x1 x0 x0) _ = [bitsx1] [x0] [x0] -- There is no value of type One (bits x0 x0 x1). -- Can't state and prove yet, because negation not covered until Connectives chapter. -- Canonical binary representation is either zero or has a leading one. data Can : Bin-ℕ → Set where [zero] : Can bits [pos] : ∀ {b : Bin-ℕ} → One b → Can b _ : Can bits _ = [zero] _ : Can (bits x1 x0) _ = [pos] ([bitsx1] [x0]) -- PLFA Relations Bin-predicates exercise gives three properties of canonicity. -- First : increment of a canonical number is canonical. -- Most of the work is done in the following lemma. -- IncCanOne : increment of a canonical number has a leading one. one-inc : ∀ {b : Bin-ℕ} → Can b → One (inc b) one-inc [zero] = [bitsx1] -- note: 'n' is bound to 'bits' one-inc ([pos] [bitsx1]) = [bitsx1] [x0] one-inc ([pos] (b [x0])) = b [x1] one-inc ([pos] (b [x1])) = one-inc ([pos] b) [x0] -- OneInc : 1st canonicity property is now a corollary. can-inc : ∀ {b : Bin-ℕ} → Can b → Can (inc b) can-inc cb = [pos] (one-inc cb) -- CanToB : 2nd canonicity property : converting unary to binary produces a canonical number. to-can : ∀ (n : ℕ) → Can (tob n) to-can zero = [zero] to-can (suc n) = can-inc (to-can n) -- OneDblbX0 : relates binary double to the x0 constructor, for numbers with a leading one. dblb-x0 : ∀ {b : Bin-ℕ} → One b → dblb b ≡ b x0 dblb-x0 [bitsx1] = refl dblb-x0 (on [x0]) rewrite dblb-x0 on = refl dblb-x0 (on [x1]) rewrite dblb-x0 on = refl dblb-x1 : ∀ {b : Bin-ℕ} → One b → inc (dblb b) ≡ b x1 dblb-x1 [bitsx1] = refl dblb-x1 (on [x0]) -- inc (dblb (b x0)) ≡ ((b x0) x1) -- (dblb b x1) ≡ ((b x0) x1) rewrite sym (dblb-x0 on) -- (dblb b x1) ≡ (dblb b x1) = refl dblb-x1 (on [x1]) -- inc (dblb (b x1)) ≡ ((b x1) x1) -- (inc (dblb b) x1) ≡ ((b x1) x1) rewrite dblb-x1 on -- ((b x1) x1) ≡ ((b x1) x1) = refl -- To prove 3rd property, use lemmas from 842Induction -- 'one-to∘from' below and some new ones you define. one-bits-to-nat : ∀ {b : Bin-ℕ} → One b → ℕ one-bits-to-nat {b} _ = fromb b one-to∘from : ∀ {b : Bin-ℕ} → One b → tob (fromb b) ≡ b one-to∘from [bitsx1] = refl one-to∘from {b} (on [x0]) -- tob (fromb (b x0)) ≡ (b x0) -- tob (dbl (fromb b )) ≡ (b x0) rewrite sym (dblb-x0 on) -- tob (dbl (fromb b )) ≡ dblb b | to∘dbl (one-bits-to-nat on) -- dblb (tob (fromb b₁)) ≡ dblb b₁ | one-to∘from on -- dblb lhs ≡ dblb lhs = refl one-to∘from {b} (on [x1]) -- tob (fromb (b₁ x1)) ≡ (b₁ x1) -- inc (tob (dbl (fromb b₁))) ≡ (b₁ x1) rewrite to∘dbl (one-bits-to-nat on) -- inc (dblb (tob (fromb b₁))) ≡ (b₁ x1) | one-to∘from on -- inc (dblb lhs) ≡ (lhs x1) | dblb-x1 on -- (lhs x1) ≡ (lhs x1) = refl -- 3rd canonicity property : -- converting a canonical number from binary and back to unary produces the same number. -- CanToFrom can-to∘from : ∀ {b : Bin-ℕ} → Can b → tob (fromb b) ≡ b can-to∘from [zero] = refl can-to∘from ([pos] b) = one-to∘from b -- Proofs of positivity are unique. one-unique : ∀ {b : Bin-ℕ} → (ox oy : One b) → ox ≡ oy one-unique [bitsx1] [bitsx1] = refl one-unique (ox [x0]) (oy [x0]) with one-unique ox oy ... | refl = refl one-unique (ox [x1]) (oy [x1]) with one-unique ox oy ... | refl = refl -- Proofs of canonicity are unique. can-unique : ∀ {b : Bin-ℕ} → (cx cy : Can b) → cx ≡ cy can-unique [zero] [zero] = refl can-unique ([pos] ox) ([pos] oy) with one-unique ox oy ... | refl = refl ------------------------------------------------------------------------------ -- There is NOT an isomorphism between ℕ (unary) and canonical binary representations. -- Because Can is not a set, but a family of sets, it does not fit into framework for isomorphism. -- It is possible to roll all the values into one set which is isomorphic to ℕ. -- A CanR VALUE wraps a Bin-ℕ and proof it has a canonical representation. data CanR : Set where wrap : ∀ (b : Bin-ℕ) → Can b → CanR -- IsoNCanR : Prove an isomorphism between ℕ and CanR. iso-ℕ-CanR : ℕ ≃ CanR to iso-ℕ-CanR n = wrap (tob n) (to-can n) -- -- Goal: CanR; n : ℕ from iso-ℕ-CanR (wrap b cb) = fromb b -- Goal: ℕ; cb : Can b, b : Bin-ℕ -- Constraints -- fromb (tob n) = ?0 (b = (tob n)) (cb = (to-can n)) : ℕ from∘to iso-ℕ-CanR n = from∘tob n -- Goal: fromb (tob n) ≡ n; n : ℕ to∘from iso-ℕ-CanR (wrap b cb) -- Goal: to iso-ℕ-CanR (from iso-ℕ-CanR (wrap b cb)) ≡ wrap b cb -- Goal: wrap (tob (fromb b)) (to-can (fromb b)) ≡ wrap b cb -- cb : Can b, b : Bin-ℕ with to-can (fromb b) | can-to∘from cb ... | tcfb | ctfcb -- Goal: wrap (tob (fromb b)) tcfb ≡ wrap b cb -- ctfcb : tob (fromb b) ≡ b, tcfb : Can (tob (fromb b)) rewrite ctfcb -- Goal: wrap b tcfb ≡ wrap b cb | can-unique cb tcfb -- Goal: wrap b tcfb ≡ wrap b tcfb = refl ------------------------------------------------------------------------------ -- BIJECTIVE BINARY NUMBERING -- TODO -- Isomorphism between ℕ and some binary encoding (without awkward non-canonical values). -- Via using digits 1 and 2 (instead of 0 and 1) where the multiplier/base is still 2. -- e.g., <empty>, 1, 2, 11, 12, 21, 22, 111, ... data Bij-ℕ : Set where bits : Bij-ℕ _x1 : Bij-ℕ → Bij-ℕ _x2 : Bij-ℕ → Bij-ℕ -------------------------------------------------- incBij-ℕ : Bij-ℕ → Bij-ℕ incBij-ℕ bits = bits x1 incBij-ℕ (bj x1) = bj x2 incBij-ℕ (bj x2) = (incBij-ℕ bj) x1 _ : incBij-ℕ bits ≡ bits x1 _ = refl _ : incBij-ℕ (bits x1) ≡ bits x2 _ = refl _ : incBij-ℕ (bits x2) ≡ bits x1 x1 _ = refl _ : incBij-ℕ (bits x1 x1) ≡ bits x1 x2 _ = refl _ : incBij-ℕ (bits x1 x2) ≡ bits x2 x1 _ = refl _ : incBij-ℕ (bits x2 x1) ≡ bits x2 x2 _ = refl _ : incBij-ℕ (bits x2 x2) ≡ bits x1 x1 x1 _ = refl -------------------------------------------------- toBij-ℕ : ℕ → Bij-ℕ toBij-ℕ zero = bits toBij-ℕ (suc n) = incBij-ℕ (toBij-ℕ n) _ : toBij-ℕ 0 ≡ bits _ = refl _ : toBij-ℕ 1 ≡ bits x1 _ = refl _ : toBij-ℕ 2 ≡ bits x2 _ = refl _ : toBij-ℕ 3 ≡ bits x1 x1 _ = refl _ : toBij-ℕ 4 ≡ bits x1 x2 _ = refl _ : toBij-ℕ 5 ≡ bits x2 x1 _ = refl _ : toBij-ℕ 6 ≡ bits x2 x2 _ = refl _ : toBij-ℕ 7 ≡ bits x1 x1 x1 _ = refl _ : toBij-ℕ 8 ≡ bits x1 x1 x2 _ = refl _ : toBij-ℕ 9 ≡ bits x1 x2 x1 _ = refl _ : toBij-ℕ 10 ≡ bits x1 x2 x2 _ = refl _ : toBij-ℕ 11 ≡ bits x2 x1 x1 _ = refl _ : toBij-ℕ 12 ≡ bits x2 x1 x2 _ = refl _ : toBij-ℕ 14 ≡ bits x2 x2 x2 _ = refl _ : toBij-ℕ 16 ≡ bits x1 x1 x1 x2 _ = refl _ : toBij-ℕ 18 ≡ bits x1 x1 x2 x2 _ = refl _ : toBij-ℕ 20 ≡ bits x1 x2 x1 x2 _ = refl ------------------------- _ : toBij-ℕ 0 ≡ bits _ = refl _ : toBij-ℕ 0 ≡ bits _ = refl ------------------------- _ : toBij-ℕ 1 ≡ bits x1 _ = refl _ : toBij-ℕ 2 ≡ bits x2 _ = refl ------------------------- _ : toBij-ℕ 2 ≡ bits x2 _ = refl _ : toBij-ℕ 4 ≡ bits x1 x2 _ = refl ------------------------- _ : toBij-ℕ 3 ≡ bits x1 x1 _ = refl _ : toBij-ℕ 6 ≡ bits x2 x2 _ = refl ------------------------- _ : toBij-ℕ 4 ≡ bits x1 x2 _ = refl _ : toBij-ℕ 8 ≡ bits x1 x1 x2 _ = refl ------------------------- _ : toBij-ℕ 5 ≡ bits x2 x1 _ = refl _ : toBij-ℕ 10 ≡ bits x1 x2 x2 _ = refl ------------------------- _ : toBij-ℕ 6 ≡ bits x2 x2 _ = refl _ : toBij-ℕ 12 ≡ bits x2 x1 x2 _ = refl ------------------------- _ : toBij-ℕ 7 ≡ bits x1 x1 x1 _ = refl _ : toBij-ℕ 14 ≡ bits x2 x2 x2 _ = refl ------------------------- _ : toBij-ℕ 8 ≡ bits x1 x1 x2 _ = refl _ : toBij-ℕ 16 ≡ bits x1 x1 x1 x2 _ = refl ------------------------- _ : toBij-ℕ 9 ≡ bits x1 x2 x1 _ = refl _ : toBij-ℕ 18 ≡ bits x1 x1 x2 x2 _ = refl ------------------------- _ : toBij-ℕ 10 ≡ bits x1 x2 x2 _ = refl _ : toBij-ℕ 20 ≡ bits x1 x2 x1 x2 _ = refl ------------------------- -------------------------------------------------- fromBij-ℕ : Bij-ℕ → ℕ fromBij-ℕ bj = fbj bj 0 where fbj : Bij-ℕ → ℕ → ℕ fbj bits _ = zero fbj (bj x1) n = (1 * (2 ^ n)) + fbj bj (n + 1) fbj (bj x2) n = (2 * (2 ^ n)) + fbj bj (n + 1) _ : fromBij-ℕ (bits) ≡ 0 _ = refl _ : fromBij-ℕ (bits x1) ≡ 1 _ = refl _ : fromBij-ℕ (bits x2) ≡ 2 _ = refl _ : fromBij-ℕ (bits x1 x1) ≡ 3 _ = refl _ : fromBij-ℕ (bits x1 x2) ≡ 4 _ = refl _ : fromBij-ℕ (bits x2 x1) ≡ 5 _ = refl _ : fromBij-ℕ (bits x2 x2) ≡ 6 _ = refl _ : fromBij-ℕ (bits x1 x1 x1) ≡ 7 _ = refl _ : fromBij-ℕ (bits x1 x1 x2) ≡ 8 _ = refl _ : fromBij-ℕ (bits x1 x2 x1) ≡ 9 _ = refl _ : fromBij-ℕ (bits x1 x2 x2) ≡ 10 _ = refl _ : fromBij-ℕ (bits x1 x2 x1 x2) ≡ 20 _ = refl -------------------------------------------------- doubleBij-ℕ : Bij-ℕ → Bij-ℕ doubleBij-ℕ bits = bits doubleBij-ℕ (bj x1) = {!!} doubleBij-ℕ (bj x2) = {!!} -------------------------------------------------- xxx : ∀ {n : ℕ} → fromBij-ℕ (toBij-ℕ n) ≡ n xxx {zero} = refl xxx {suc n} = {! !} -------------------------------------------------- -- Prove the isomorphism between ℕ and Bij-ℕ. -- Largely follows outline of above. iso-ℕ-Bij-ℕ : ℕ ≃ Bij-ℕ to iso-ℕ-Bij-ℕ n = toBij-ℕ n from iso-ℕ-Bij-ℕ bjn = fromBij-ℕ bjn from∘to iso-ℕ-Bij-ℕ n = {!!} to∘from iso-ℕ-Bij-ℕ bjn = {!!}
{ "alphanum_fraction": 0.4582630446, "avg_line_length": 28.8924369748, "ext": "agda", "hexsha": "3c919c1e0edac9d92ac0442de79f018e11ee5323", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x05-842Isomorphism-hc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "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": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x05-842Isomorphism-hc.agda", "max_line_length": 109, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x05-842Isomorphism-hc.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 7121, "size": 17191 }
module 010-false-true where -- In Agda, types are theorems, and instances of types are proofs. The -- simplest theorem is the theorem which has no proof, and is useful -- to represent any contradictory situation. We declare False as an -- algebraic data type without constructors. If "False" has no -- constructors, then it also has no instances, and thereby perfectly -- serves our purpose. Note that what we call here "False" is also -- sometimes also called bottom and is denoted by ⊥. data False : Set where -- The next simplest theorem is the trivial theorem which is always -- true. We declare it as an algebraic data type "True", with one -- constructor named "trivial". data True : Set where trivial : True
{ "alphanum_fraction": 0.7506925208, "avg_line_length": 38, "ext": "agda", "hexsha": "16614eee8cbdc71d71e5accfe0a94b010beb8d36", "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": "76fe404b25210258810641cc6807feecf0ff8d6c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mcmtroffaes/agda-proofs", "max_forks_repo_path": "010-false-true.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c", "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": "mcmtroffaes/agda-proofs", "max_issues_repo_path": "010-false-true.agda", "max_line_length": 70, "max_stars_count": 2, "max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mcmtroffaes/agda-proofs", "max_stars_repo_path": "010-false-true.agda", "max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z", "num_tokens": 172, "size": 722 }
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.ZCohomology.Groups.KleinBottle where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Properties open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Function open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2) open import Cubical.Data.Nat hiding (+-assoc) open import Cubical.Algebra.Group renaming (Int to IntGroup ; Bool to BoolGroup ; Unit to UnitGroup) open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Transport open import Cubical.ZCohomology.Groups.Unit open import Cubical.ZCohomology.Groups.Sn open import Cubical.Data.Sigma open import Cubical.Foundations.Isomorphism open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.Equiv open import Cubical.Homotopy.Connected open import Cubical.Data.Empty renaming (rec to ⊥-rec) open import Cubical.Data.Bool open import Cubical.Data.Int renaming (+-comm to +-commℤ ; _+_ to _+ℤ_) open import Cubical.HITs.KleinBottle open import Cubical.Data.Empty open import Cubical.Foundations.Path open import Cubical.Homotopy.Loopspace open IsGroupHom open Iso characFunSpace𝕂² : ∀ {ℓ} (A : Type ℓ) → Iso (KleinBottle → A) (Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) fun (characFunSpace𝕂² A) f = (f point) , ((cong f line1) , (cong f line2 , fst (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)))) inv (characFunSpace𝕂² A) (x , p , q , sq) point = x inv (characFunSpace𝕂² A) (x , p , q , sq) (line1 i) = p i inv (characFunSpace𝕂² A) (x , p , q , sq) (line2 i) = q i inv (characFunSpace𝕂² A) (x , p , q , sq) (square i j) = invEq (Square≃doubleComp q q (sym p) p) sq i j rightInv (characFunSpace𝕂² A) (x , (p , (q , sq))) = ΣPathP (refl , (ΣPathP (refl , (ΣPathP (refl , secEq (Square≃doubleComp q q (sym p) p) sq))))) leftInv (characFunSpace𝕂² A) f _ point = f point leftInv (characFunSpace𝕂² A) f _ (line1 i) = f (line1 i) leftInv (characFunSpace𝕂² A) f _ (line2 i) = f (line2 i) leftInv (characFunSpace𝕂² A) f z (square i j) = retEq (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)) z i j private movePathLem : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → (p ∙∙ q ∙∙ p ≡ q) ≡ ((p ∙ p) ∙ q ≡ q) movePathLem p q comm = cong (_≡ q) (doubleCompPath-elim' p q p ∙∙ cong (p ∙_) (comm q p) ∙∙ assoc _ _ _) movePathLem2 : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → (((p ∙ p) ∙ q) ∙ sym q ≡ q ∙ sym q) ≡ (p ∙ p ≡ refl) movePathLem2 p q = cong₂ _≡_ (sym (assoc (p ∙ p) q (sym q)) ∙∙ cong ((p ∙ p) ∙_) (rCancel q) ∙∙ sym (rUnit (p ∙ p))) (rCancel q) movePathIso : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → Iso (p ∙∙ q ∙∙ p ≡ q) (p ∙ p ≡ refl) movePathIso {x = x} p q comm = compIso (pathToIso (movePathLem p q comm)) (compIso (helper (p ∙ p)) (pathToIso (movePathLem2 p q))) where helper : (p : x ≡ x) → Iso (p ∙ q ≡ q) ((p ∙ q) ∙ sym q ≡ q ∙ sym q) helper p = congIso (equivToIso (_ , compPathr-isEquiv (sym q))) ------ H¹(𝕂²) ≅ 0 -------------- H⁰-𝕂² : GroupIso (coHomGr 0 KleinBottle) IntGroup fun (fst H⁰-𝕂²) = sRec isSetInt λ f → f point inv (fst H⁰-𝕂²) x = ∣ (λ _ → x) ∣₂ rightInv (fst H⁰-𝕂²) _ = refl leftInv (fst H⁰-𝕂²) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → cong ∣_∣₂ (funExt (λ {point → refl ; (line1 i) j → isSetInt (f point) (f point) refl (cong f line1) j i ; (line2 i) j → isSetInt (f point) (f point) refl (cong f line2) j i ; (square i j) z → helper f i j z})) where helper : (f : KleinBottle → Int) → Cube (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z (~ i)) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z i) refl λ i j → f (square i j) helper f = isGroupoid→isGroupoid' (isOfHLevelSuc 2 isSetInt) _ _ _ _ _ _ snd H⁰-𝕂² = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _) λ _ _ → refl) ------ H¹(𝕂¹) ≅ ℤ ------------ {- Step one : H¹(𝕂²) := ∥ 𝕂² → K₁ ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ x ∈ K₁ ] (x ≡ x) ∥₂ (p ∙ p ≡ refl forces p ≡ refl. Also, p ∙ p ≡ refl is an hProp) -} nilpotent→≡0 : (x : Int) → x +ℤ x ≡ 0 → x ≡ 0 nilpotent→≡0 (pos zero) p = refl nilpotent→≡0 (pos (suc n)) p = ⊥-rec (negsucNotpos _ _ (sym (cong (_- 1) (cong sucInt (sym (helper2 n)) ∙ p)))) where helper2 : (n : ℕ) → pos (suc n) +pos n ≡ pos (suc (n + n)) helper2 zero = refl helper2 (suc n) = cong sucInt (sym (sucInt+pos n (pos (suc n)))) ∙∙ cong (sucInt ∘ sucInt) (helper2 n) ∙∙ cong (pos ∘ suc ∘ suc) (sym (+-suc n n)) nilpotent→≡0 (negsuc n) p = ⊥-rec (negsucNotpos _ _ (helper2 n p)) where helper2 : (n : ℕ) → (negsuc n +negsuc n) ≡ pos 0 → negsuc n ≡ pos (suc n) helper2 n p = cong (negsuc n +ℤ_) (sym (helper3 n)) ∙ +-assoc (negsuc n) (negsuc n) (pos (suc n)) ∙∙ cong (_+ℤ (pos (suc n))) p ∙∙ cong sucInt (+-commℤ (pos 0) (pos n)) where helper3 : (n : ℕ) → negsuc n +pos (suc n) ≡ 0 helper3 zero = refl helper3 (suc n) = cong sucInt (sucInt+pos n (negsuc (suc n))) ∙ helper3 n nilpotent→≡refl : (x : coHomK 1) (p : x ≡ x) → p ∙ p ≡ refl → p ≡ refl nilpotent→≡refl = trElim (λ _ → isGroupoidΠ2 λ _ _ → isOfHLevelPlus {n = 1} 2 (isOfHLevelTrunc 3 _ _ _ _)) (toPropElim (λ _ → isPropΠ2 λ _ _ → isOfHLevelTrunc 3 _ _ _ _) λ p pId → sym (rightInv (Iso-Kn-ΩKn+1 0) p) ∙∙ cong (Kn→ΩKn+1 0) (nilpotent→≡0 (ΩKn+1→Kn 0 p) (sym (ΩKn+1→Kn-hom 0 p p) ∙ cong (ΩKn+1→Kn 0) pId)) ∙∙ Kn→ΩKn+10ₖ 0) Iso-H¹-𝕂²₁ : Iso (Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl) (Σ[ x ∈ coHomK 1 ] x ≡ x) fun Iso-H¹-𝕂²₁ (x , (_ , (q , _))) = x , q inv Iso-H¹-𝕂²₁ (x , q) = x , (refl , (q , (sym (rUnit refl)))) rightInv Iso-H¹-𝕂²₁ _ = refl leftInv Iso-H¹-𝕂²₁ (x , (p , (q , P))) = ΣPathP (refl , (ΣPathP (sym (nilpotent→≡refl x p P) , toPathP (Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _) (transportRefl q))))) {- But this is precisely the type (minus set-truncation) of H¹(S¹) -} Iso-H¹-𝕂²₂ : Iso (Σ[ x ∈ coHomK 1 ] x ≡ x) (S¹ → coHomK 1) Iso-H¹-𝕂²₂ = invIso IsoFunSpaceS¹ H¹-𝕂²≅ℤ : GroupIso (coHomGr 1 KleinBottle) IntGroup H¹-𝕂²≅ℤ = compGroupIso theGroupIso (Hⁿ-Sⁿ≅ℤ 0) where theIso : Iso (coHom 1 KleinBottle) (coHom 1 S¹) theIso = setTruncIso ( compIso (characFunSpace𝕂² (coHomK 1)) (compIso (Σ-cong-iso-snd (λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → movePathIso p q (isCommΩK-based 1 x))) (compIso Iso-H¹-𝕂²₁ Iso-H¹-𝕂²₂))) is-hom : IsGroupHom (coHomGr 1 KleinBottle .snd) (fun theIso) (coHomGr 1 S¹ .snd) is-hom = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f g → cong ∣_∣₂ (funExt λ {base → refl ; (loop i) → refl})) theGroupIso : GroupIso (coHomGr 1 KleinBottle) (coHomGr 1 S¹) theGroupIso = (theIso , is-hom) ------ H²(𝕂²) ≅ ℤ/2ℤ (represented here by BoolGroup) ------- -- It suffices to show that H²(Klein) is equivalent to Bool as types {- Step one : H²(𝕂²) := ∥ 𝕂² → K₂ ∥₂ ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (connectedness of K₂) -} Iso-H²-𝕂²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl ∥₂ fun Iso-H²-𝕂²₁ = sRec setTruncIsSet (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet) (sphereElim _ (λ _ → isSetΠ λ _ → setTruncIsSet) λ y → ∣ fst y , snd (snd y) ∣₂))) inv Iso-H²-𝕂²₁ = sMap λ p → (0ₖ 2) , ((fst p) , (refl , (snd p))) rightInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ p → refl leftInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ λ _ → setTruncIsSet _ _) λ {(p , (q , sq)) → trRec (setTruncIsSet _ _) (λ qid → cong ∣_∣₂ (ΣPathP (refl , (ΣPathP (refl , (ΣPathP (sym qid , refl))))))) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPathKn 1 (0ₖ 2) (0ₖ 2)) ∣ q ∣ ∣ refl ∣))}))) {- Step two : ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ -} Iso-H²-𝕂²₂ : Iso ∥ (Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl) ∥₂ ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Iso-H²-𝕂²₂ = setTruncIso (Σ-cong-iso {B' = λ x → x +ₖ x ≡ 0ₖ 1} (invIso (Iso-Kn-ΩKn+1 1)) λ p → compIso (congIso (invIso (Iso-Kn-ΩKn+1 1))) (pathToIso λ i → ΩKn+1→Kn-hom 1 p p i ≡ 0ₖ 1)) {- Step three : ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ ≡ Bool We begin by defining the a map Σ[ x ∈ K₁ ] x + x ≡ 0 → Bool. For a point (0 , p) we map it to true if winding(p) is even and false if winding(p) is odd. We also have to show that this map respects the loop -} ΣKₙNilpot→Bool : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool ΣKₙNilpot→Bool = uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool) λ {base p → isEven (ΩKn+1→Kn 0 p) ; (loop i) p → hcomp (λ k → λ { (i = i0) → respectsLoop p k ; (i = i1) → isEven (ΩKn+1→Kn 0 p)}) (isEven (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i p)))}) where isEven-2 : (x : Int) → isEven (-2 +ℤ x) ≡ isEven x isEven-2 (pos zero) = refl isEven-2 (pos (suc zero)) = refl isEven-2 (pos (suc (suc n))) = cong isEven (cong sucInt (sucInt+pos _ _) ∙∙ sucInt+pos _ _ ∙∙ +-commℤ 0 (pos n)) ∙ lossy n where lossy : (n : ℕ) → isEven (pos n) ≡ isEven (pos n) lossy n = refl isEven-2 (negsuc zero) = refl isEven-2 (negsuc (suc n)) = cong isEven (predInt+negsuc n _ ∙ +-commℤ -3 (negsuc n)) ∙ lossy2 n where lossy2 : (n : ℕ) → isEven (negsuc (suc (suc (suc n)))) ≡ isEven (pos n) lossy2 n = refl respectsLoop : (p : 0ₖ 1 ≡ 0ₖ 1) → isEven (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p)) ≡ isEven (ΩKn+1→Kn 0 p) respectsLoop p = cong isEven (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1)) (lUnit p))) ∙∙ cong isEven (cong (ΩKn+1→Kn 0) λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j ((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p)) ∙∙ cong isEven (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p) ∙ isEven-2 (ΩKn+1→Kn 0 p) {- We show that for any x : Int we have ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , refl) ∣₂ when x is even and ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ when x is odd This is done by induction on x. For the inductive step we define a multiplication _*_ on ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ which is just ∣ (0 , p) ∣₂ * ∣ (0 , q) ∣₂ ≡ ∣ (0 , p ∙ q) ∣₂ when x is 0 -} private _*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ _*_ = sRec (isSetΠ (λ _ → setTruncIsSet)) λ a → sRec setTruncIsSet λ b → *' (fst a) (fst b) (snd a) (snd b) where *' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ *' = trElim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 setTruncIsSet) (wedgeconFun _ _ (λ _ _ → isSetΠ2 λ _ _ → setTruncIsSet) (λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂) (λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂) (funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _)))))) *=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂ *=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q))) isEvenNegsuc : (n : ℕ) → isEven (pos (suc n)) ≡ true → isEven (negsuc n) ≡ true isEvenNegsuc zero p = ⊥-rec (true≢false (sym p)) isEvenNegsuc (suc n) p = p ¬isEvenNegSuc : (n : ℕ) → isEven (pos (suc n)) ≡ false → isEven (negsuc n) ≡ false ¬isEvenNegSuc zero p = refl ¬isEvenNegSuc (suc n) p = p evenCharac : (x : Int) → isEven x ≡ true → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , refl) ∣₂ evenCharac (pos zero) isisEven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂ evenCharac (pos (suc zero)) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (pos (suc (suc zero))) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i)) ∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣))) evenCharac (pos (suc (suc (suc n)))) isisEven = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2))) ∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) isisEven) (evenCharac 2 refl)) evenCharac (negsuc zero) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (negsuc (suc zero)) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁) (inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i)) ∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣)) evenCharac (negsuc (suc (suc n))) isisEven = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (evenCharac (negsuc n) (isEvenNegsuc n isisEven)) (evenCharac -2 refl) oddCharac : (x : Int) → isEven x ≡ false → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ oddCharac (pos zero) isOdd = ⊥-rec (true≢false isOdd) oddCharac (pos (suc zero)) isOdd i = ∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j) (inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂ oddCharac (pos (suc (suc n))) isOdd = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2)) ∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl) oddCharac (negsuc zero) isOdd = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i)) ∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k) ; (i = i1) → loop j ; (j = i1) → base}) (loop (j ∨ ~ i)) ∣)) oddCharac (negsuc (suc zero)) isOdd = ⊥-rec (true≢false isOdd) oddCharac (negsuc (suc (suc n))) isOdd = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (oddCharac (negsuc n) (¬isEvenNegSuc n isOdd)) (evenCharac (negsuc 1) refl) {- We now have all we need to establish the Iso -} Bool→ΣKₙNilpot : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool→ΣKₙNilpot false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂ Bool→ΣKₙNilpot true = ∣ 0ₖ 1 , refl ∣₂ testIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool fun testIso = sRec isSetBool ΣKₙNilpot→Bool inv testIso = Bool→ΣKₙNilpot rightInv testIso false = refl rightInv testIso true = refl leftInv testIso = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _)) (toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _)) (λ p → path p (isEven (ΩKn+1→Kn 0 p)) refl)))) where path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (isEven (ΩKn+1→Kn 0 p) ≡ b) → Bool→ΣKₙNilpot (ΣKₙNilpot→Bool (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂ path p false q = (cong Bool→ΣKₙNilpot q) ∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i path p true q = cong Bool→ΣKₙNilpot q ∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i H²-𝕂²≅Bool : GroupIso (coHomGr 2 KleinBottle) BoolGroup H²-𝕂²≅Bool = invGroupIso (≅Bool theIso) where theIso : Iso _ _ theIso = compIso (setTruncIso (compIso (characFunSpace𝕂² (coHomK 2)) (Σ-cong-iso-snd λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → (movePathIso p q (isCommΩK-based 2 x))))) (compIso Iso-H²-𝕂²₁ (compIso Iso-H²-𝕂²₂ testIso)) ------ Hⁿ(𝕂²) ≅ 0 , n ≥ 3 ------ isContrHⁿ-𝕂² : (n : ℕ) → isContr (coHom (3 + n) KleinBottle) isContrHⁿ-𝕂² n = isOfHLevelRetractFromIso 0 (setTruncIso (characFunSpace𝕂² (coHomK _))) isContrΣ-help where helper : (x : coHomK (3 + n))(p : x ≡ x) → (refl ≡ p) → (q : x ≡ x) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ x , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ helper = trElim (λ _ → isProp→isOfHLevelSuc (4 + n) (isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _) λ p → J (λ p _ → (q : 0ₖ _ ≡ 0ₖ _) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ q → J (λ q _ → (P : refl ∙∙ q ∙∙ refl ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , refl , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ P → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _)) (λ P≡rUnitrefl i → ∣ 0ₖ (3 + n) , refl , refl , P≡rUnitrefl i ∣₂) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPath _ (isConnectedPathKn (2 + n) _ _) (refl ∙∙ refl ∙∙ refl) refl) ∣ P ∣ ∣ sym (rUnit refl) ∣))) isContrΣ-help : isContr ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ fst isContrΣ-help = ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ snd isContrΣ-help = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(x , p , q , P) → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ pId → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ qId → sym (helper x p pId q qId P)) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ q ∣))) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ p ∣))} Hⁿ⁺³-𝕂²≅0 : (n : ℕ) → GroupIso (coHomGr (3 + n) KleinBottle) UnitGroup Hⁿ⁺³-𝕂²≅0 n = contrGroupIsoUnit (isContrHⁿ-𝕂² n)
{ "alphanum_fraction": 0.5052897669, "avg_line_length": 46.9494505495, "ext": "agda", "hexsha": "8b9da05a701dd7e75f911e0d16fa84453396b849", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-03-12T20:08:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-03-12T20:08:45.000Z", "max_forks_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "LuuBluum/cubical", "max_forks_repo_path": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "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": "LuuBluum/cubical", "max_issues_repo_path": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_line_length": 141, "max_stars_count": null, "max_stars_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "LuuBluum/cubical", "max_stars_repo_path": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 9306, "size": 21362 }
{-# OPTIONS --cubical #-} module Cubical.Codata.Everything where open import Cubical.Codata.EverythingSafe public --- Modules making assumptions that might be incompatible with other -- flags or make use of potentially unsafe features. -- Assumes --guardedness open import Cubical.Codata.Stream public open import Cubical.Codata.Conat public open import Cubical.Codata.M public -- Also uses {-# TERMINATING #-}. open import Cubical.Codata.M.Bisimilarity public
{ "alphanum_fraction": 0.7803837953, "avg_line_length": 24.6842105263, "ext": "agda", "hexsha": "2802bb300bb5d3c72bb766de22713f09daf70071", "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/Codata/Everything.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/Codata/Everything.agda", "max_line_length": 68, "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/Codata/Everything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 107, "size": 469 }
{-# OPTIONS --safe #-} module Cubical.Categories.Instances.Poset where open import Cubical.Foundations.Prelude open import Cubical.Relation.Binary.Poset open import Cubical.Categories.Category open Category private variable ℓ ℓ' : Level module _ (P : Poset ℓ ℓ') where open PosetStr (snd P) PosetCategory : Category ℓ ℓ' ob PosetCategory = fst P Hom[_,_] PosetCategory = _≤_ id PosetCategory = is-refl _ _⋆_ PosetCategory = is-trans _ _ _ ⋆IdL PosetCategory _ = is-prop-valued _ _ _ _ ⋆IdR PosetCategory _ = is-prop-valued _ _ _ _ ⋆Assoc PosetCategory _ _ _ = is-prop-valued _ _ _ _ isSetHom PosetCategory = isProp→isSet (is-prop-valued _ _)
{ "alphanum_fraction": 0.6717241379, "avg_line_length": 25, "ext": "agda", "hexsha": "720326e9b81345656579f53e104e0c0c25e42acb", "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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/Categories/Instances/Poset.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/Categories/Instances/Poset.agda", "max_line_length": 64, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/Categories/Instances/Poset.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 226, "size": 725 }
open import FRP.JS.Bool using ( Bool ; true ; false ) module FRP.JS.Maybe where -- Data.Maybe doesn't have bindings for JavaScript, so we define Maybe here. -- We'd like to use JavaScript's built-in null as the -- representation of nothing, and use x as the representation of just -- x. Unfortunately this doens't work for nested Maybes, as it -- identifies nothing and just nothing at type Maybe Maybe A, which in -- turn breaks parametericity. Instead, we link to a JS library which -- provides functions box and unbox such that box(x) !== null, -- unbox(box(x)) === x, and if x !== box^n (null) then x == -- box(x). Note that for never-null types (e.g. String), values -- of type Maybe T are either null or values of type T, which -- corresponds to the JavaScript idiom (for example, a lookup in an -- array of strings can be translated to native array lookup). data Maybe {α} (A : Set α) : Set α where just : (a : A) → Maybe A nothing : Maybe A {-# COMPILED_JS Maybe function(x,v) { if (x === null) { return v.nothing(); } else { return v.just(require("agda.box").unbox(x)); } } #-} {-# COMPILED_JS just require("agda.box").box #-} {-# COMPILED_JS nothing null #-} _≟[_]_ : ∀ {α β A B} → Maybe {α} A → (A → B → Bool) → Maybe {β} B → Bool just a ≟[ p ] just b = p a b just a ≟[ p ] nothing = false nothing ≟[ p ] just b = false nothing ≟[ p ] nothing = true
{ "alphanum_fraction": 0.6606367583, "avg_line_length": 39.4857142857, "ext": "agda", "hexsha": "722e756ba8aa966dd3352de7f62df70a19e12d2d", "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/Maybe.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/Maybe.agda", "max_line_length": 76, "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/Maybe.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": 403, "size": 1382 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature module Fragment.Algebra.Homomorphism.Base (Σ : Signature) where open import Fragment.Algebra.Algebra Σ open import Fragment.Algebra.Homomorphism.Definitions Σ open import Fragment.Setoid.Morphism as Morphism hiding (id; ∣_∣; ∣_∣-cong) open import Level using (Level; _⊔_) open import Function using (_∘_; _$_) open import Data.Vec using (map) open import Data.Vec.Properties using (map-id; map-∘) import Data.Vec.Relation.Binary.Equality.Setoid as VecSetoid open import Relation.Binary using (IsEquivalence) import Relation.Binary.Reasoning.Setoid as Reasoning private variable a b c ℓ₁ ℓ₂ ℓ₃ : Level module _ (A : Algebra {a} {ℓ₁}) (B : Algebra {b} {ℓ₂}) where infixr 1 _⟿_ record _⟿_ : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where field ∣_∣⃗ : ∥ A ∥/≈ ↝ ∥ B ∥/≈ ∣_∣-hom : Homomorphic A B (Morphism.∣_∣ ∣_∣⃗) ∣_∣ : ∥ A ∥ → ∥ B ∥ ∣_∣ = Morphism.∣_∣ ∣_∣⃗ ∣_∣-cong : Congruent ≈[ A ] ≈[ B ] ∣_∣ ∣_∣-cong = Morphism.∣_∣-cong ∣_∣⃗ open _⟿_ public module _ {A : Algebra {a} {ℓ₁}} where private ∣id∣-hom : Homomorphic A A (λ x → x) ∣id∣-hom {n} f xs = A ⟦ f ⟧-cong $ reflexive (map-id xs) where open VecSetoid ∥ A ∥/≈ open IsEquivalence (≋-isEquivalence n) using (reflexive) id : A ⟿ A id = record { ∣_∣⃗ = Morphism.id ; ∣_∣-hom = ∣id∣-hom } module _ {A : Algebra {a} {ℓ₁}} {B : Algebra {b} {ℓ₂}} {C : Algebra {c} {ℓ₃}} (g : B ⟿ C) (f : A ⟿ B) where private ⊙-hom : Homomorphic A C (∣ g ∣ ∘ ∣ f ∣) ⊙-hom {n} op xs = begin C ⟦ op ⟧ (map (∣ g ∣ ∘ ∣ f ∣) xs) ≈⟨ C ⟦ op ⟧-cong $ reflexive (map-∘ ∣ g ∣ ∣ f ∣ xs) ⟩ C ⟦ op ⟧ (map ∣ g ∣ (map ∣ f ∣ xs)) ≈⟨ ∣ g ∣-hom op (map ∣ f ∣ xs) ⟩ ∣ g ∣ (B ⟦ op ⟧ (map ∣ f ∣ xs)) ≈⟨ ∣ g ∣-cong (∣ f ∣-hom op xs) ⟩ ∣ g ∣ (∣ f ∣ (A ⟦ op ⟧ xs)) ∎ where open Reasoning ∥ C ∥/≈ open VecSetoid ∥ C ∥/≈ open IsEquivalence (≋-isEquivalence n) using (reflexive) infixr 9 _⊙_ _⊙_ : A ⟿ C _⊙_ = record { ∣_∣⃗ = ∣ g ∣⃗ · ∣ f ∣⃗ ; ∣_∣-hom = ⊙-hom }
{ "alphanum_fraction": 0.5261496844, "avg_line_length": 24.3736263736, "ext": "agda", "hexsha": "c2cc4054120f1a9238d97be66f19a7ea26582e8d", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Algebra/Homomorphism/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Algebra/Homomorphism/Base.agda", "max_line_length": 68, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Algebra/Homomorphism/Base.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 997, "size": 2218 }
module CategoryTheory.CartesianStrength where open import CategoryTheory.Categories open import CategoryTheory.Functor open import CategoryTheory.BCCCs.Cartesian open import CategoryTheory.Monad open import CategoryTheory.Comonad -- Type class for Cartesian functors record CartesianFunctor {n} {ℂ : Category n} {𝔻 : Category n} (Fn : Functor ℂ 𝔻) (ℂ-cart : Cartesian ℂ) (𝔻-cart : Cartesian 𝔻) : Set (lsuc n) where private module ℂ = Category ℂ private module 𝔻 = Category 𝔻 open Category 𝔻 open Functor Fn renaming (omap to F) open Cartesian ℂ-cart renaming ( ⊤ to ⊤ᶜ ; _⊗_ to _⊗ᶜ_ ; _*_ to _*ᶜ_ ; assoc-right to αᶜ ; unit-left to λᶜ ; unit-right to ρᶜ) open Cartesian 𝔻-cart renaming ( ⊤ to ⊤ᵈ ; _⊗_ to _⊗ᵈ_ ; _*_ to _*ᵈ_; assoc-right to αᵈ ; unit-left to λᵈ ; unit-right to ρᵈ) field -- | Data -- F preserves terminal objects (0-ary products) u : ⊤ᵈ ~> F ⊤ᶜ -- F preserves binary products m : ∀(A B : ℂ.obj) -> F A ⊗ᵈ F B ~> F (A ⊗ᶜ B) -- | Laws -- Naturality conditions m-nat₁ : ∀{A B C : ℂ.obj} (f : A ℂ.~> B) -> fmap (f *ᶜ ℂ.id) ∘ m A C ≈ m B C ∘ fmap f *ᵈ id m-nat₂ : ∀{A B C : ℂ.obj} (f : A ℂ.~> B) -> fmap (ℂ.id *ᶜ f) ∘ m C A ≈ m C B ∘ id *ᵈ fmap f -- Monoid laws associative : ∀{A B C : ℂ.obj} -> m A (B ⊗ᶜ C) ∘ (id *ᵈ m B C) ∘ αᵈ ≈ fmap αᶜ ∘ m (A ⊗ᶜ B) C ∘ (m A B *ᵈ id) unital-right : ∀{A : ℂ.obj} -> fmap ρᶜ ∘ m A ⊤ᶜ ∘ (id *ᵈ u) ≈ ρᵈ unital-left : ∀{B : ℂ.obj} -> fmap λᶜ ∘ m ⊤ᶜ B ∘ (u *ᵈ id) ≈ λᵈ -- Canonical distribution morphism m⁻¹ : ∀(A B : ℂ.obj) -> F (A ⊗ᶜ B) ~> F A ⊗ᵈ F B m⁻¹ A B = Cartesian.⟨_,_⟩ 𝔻-cart (fmap (Cartesian.π₁ ℂ-cart)) (fmap (Cartesian.π₂ ℂ-cart)) -- Type class for Cartesian comonads record CartesianComonad {n} {ℂ : Category n} (C : Comonad ℂ) (ℂ-cart : Cartesian ℂ) : Set (lsuc n) where open Category ℂ open Comonad C open Functor W renaming (omap to F) open Cartesian ℂ-cart field -- Cartesian comonads are Cartesian functors cart-fun : CartesianFunctor W ℂ-cart ℂ-cart open CartesianFunctor cart-fun field -- | Laws u-ε : u ∘ ε.at ⊤ ≈ id u-δ : δ.at ⊤ ∘ u ≈ fmap u ∘ u m-ε : ∀{A B : obj} -> ε.at (A ⊗ B) ∘ m A B ≈ ε.at A * ε.at B m-δ : ∀{A B : obj} -> fmap (m A B) ∘ m (F A) (F B) ∘ δ.at A * δ.at B ≈ δ.at (A ⊗ B) ∘ m A B -- Type class for W-strong monads (for a Cartesian comonad W) record WStrongMonad {n} {ℂ : Category n} (ℂ-cart : Cartesian ℂ) {Co : Comonad ℂ} (Mo : Monad ℂ) (W-cart-com : CartesianComonad Co ℂ-cart) : Set (lsuc n) where open Category ℂ open Comonad Co open Monad Mo open Functor W renaming (omap to C ; fmap to C-f) open Functor T renaming (omap to M ; fmap to M-f) open Cartesian ℂ-cart open CartesianComonad W-cart-com open CartesianFunctor cart-fun λᶜ : ∀(A : obj) -> C ⊤ ⊗ A ~> A λᶜ _ = π₂ αᶜ : ∀(A B D : obj) -> (C (A ⊗ B) ⊗ D) ~> (C A ⊗ (C B ⊗ D)) αᶜ A B D = assoc-right ∘ m⁻¹ A B * id field -- C-tensorial strength st : ∀(A B : obj) -> C A ⊗ M B ~> M (C A ⊗ B) -- | Laws -- Naturality conditions st-nat₁ : ∀{A B D : obj} (f : A ~> B) -> M-f (C-f f * id) ∘ st A D ≈ st B D ∘ C-f f * id st-nat₂ : ∀{A B D : obj} (f : A ~> B) -> M-f (id * f) ∘ st D A ≈ st D B ∘ id * M-f f -- Strength and left unit st-λ : ∀{A} -> M-f (λᶜ A) ∘ st ⊤ A ≈ λᶜ (M A) -- Strength and associativity st-α : ∀{A B D} -> st A (C B ⊗ D) ∘ id * st B D ∘ αᶜ A B (M D) ≈ M-f (αᶜ A B D) ∘ st (A ⊗ B) D -- Strength and unit st-η : ∀{A B} -> st A B ∘ id * η.at B ≈ η.at (C A ⊗ B) -- Strength and multiplication st-μ : ∀{A B} -> μ.at (C A ⊗ B) ∘ M-f (st A B) ∘ st A (M B) ≈ st A B ∘ (id * μ.at B)
{ "alphanum_fraction": 0.4967446347, "avg_line_length": 36.0608695652, "ext": "agda", "hexsha": "bcf8514786260562a5279e61c5f18cc08f5dc585", "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": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_path": "src/CategoryTheory/CartesianStrength.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "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": "DimaSamoz/temporal-type-systems", "max_issues_repo_path": "src/CategoryTheory/CartesianStrength.agda", "max_line_length": 76, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_path": "src/CategoryTheory/CartesianStrength.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "num_tokens": 1641, "size": 4147 }
module Example where open import Agda.Builtin.Nat open import Agda.Builtin.List open import Agda.Builtin.Equality downFrom : Nat → List Nat downFrom zero = [] downFrom (suc n) = n ∷ downFrom n sum-rec : List Nat → Nat sum-rec [] = 0 sum-rec (x ∷ xs) = x + sum-rec xs sum-acc : Nat → List Nat → Nat sum-acc z [] = z sum-acc z (x ∷ xs) = sum-acc (z + x) xs sum-acc! : Nat → List Nat → Nat sum-acc! z [] = z sum-acc! 0 (x ∷ xs) = sum-acc! x xs sum-acc! z (x ∷ xs) = sum-acc! (z + x) xs n = 10000 bench-rec = sum-rec (downFrom n) bench-acc = sum-acc 0 (downFrom n) bench-acc! = sum-acc! 0 (downFrom n)
{ "alphanum_fraction": 0.6112903226, "avg_line_length": 21.3793103448, "ext": "agda", "hexsha": "bc77c726792e2f99c61f38da9f5fc19b2852c338", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-01-25T06:10:26.000Z", "max_forks_repo_forks_event_min_datetime": "2021-02-05T18:49:17.000Z", "max_forks_repo_head_hexsha": "cf0043a64d2913ad19a58f2b4bcc075138bb911f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "L-TChen/agda-bench", "max_forks_repo_path": "examples/Example.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "cf0043a64d2913ad19a58f2b4bcc075138bb911f", "max_issues_repo_issues_event_max_datetime": "2021-02-09T05:59:42.000Z", "max_issues_repo_issues_event_min_datetime": "2021-02-05T18:44:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "L-TChen/agda-bench", "max_issues_repo_path": "examples/Example.agda", "max_line_length": 41, "max_stars_count": 13, "max_stars_repo_head_hexsha": "cf0043a64d2913ad19a58f2b4bcc075138bb911f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "L-TChen/agda-bench", "max_stars_repo_path": "examples/Example.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-22T10:57:58.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-18T10:31:12.000Z", "num_tokens": 245, "size": 620 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Agda.ISetoids.Cocomplete where open import Level open import Relation.Binary using (Setoid; module Setoid; Preorder; module Preorder; Rel; _=[_]⇒_) open import Data.Product using (Σ; _,_) -- import Relation.Binary.EqReasoning as EqReasoning open import Categories.Support.Equivalence using (module I→R-Wrapper; setoid-i→r) renaming (Setoid to ISetoid; module Setoid to ISetoid) open import Categories.Support.SetoidFunctions using (module _⟶_) open import Categories.Support.PropositionalEquality import Categories.Support.ZigZag as ZigZag open import Categories.Category open import Categories.Functor open import Categories.Agda open import Categories.Colimit open import Categories.Object.Initial open import Categories.Cocones open import Categories.Cocone open import Categories.Agda.ISetoids.Cocomplete.Helpers open I→R-Wrapper ISetoidsCocomplete : ∀ {o ℓ e c ℓ′} → Cocomplete o ℓ e (ISetoids (c ⊔ ding (o ⊔ ℓ ⊔ e)) (c ⊔ ℓ′ ⊔ ding (o ⊔ ℓ ⊔ e))) ISetoidsCocomplete {o} {ℓ} {e} {c} {cℓ} = record { colimit = colimit } where c′ = c ⊔ ding (o ⊔ ℓ ⊔ e) ℓ′ = c ⊔ cℓ ⊔ ding (o ⊔ ℓ ⊔ e) C = ISetoids c′ ℓ′ colimit : ∀ {J : Category o ℓ e} (F : Functor J C) → Colimit F colimit {J} F = record { initial = my-initial-cocone } where module J = Category J open Functor F open ISetoid open _⟶_ open ColimitCocone {c = c} {cℓ} {J} F .my-!-unique : (A : Cocone F) (φ : CoconeMorphism ⊥ A) (x : vertex-carrier) → (_≈_ (Cocone.N A) (CoconeMorphism.f (! {A}) ⟨$⟩ x) (CoconeMorphism.f φ ⟨$⟩ x)) my-!-unique A φ (X , x) = sym (Cocone.N A) (CoconeMorphism.commute φ (refl (F₀ X))) my-initial-cocone : Initial (Cocones F) my-initial-cocone = record { ⊥ = ⊥ ; ! = ! ; !-unique = λ {A} φ {x} {y} x≡y → trans (Cocone.N A) (my-!-unique A φ x) (cong (CoconeMorphism.f φ) x≡y) }
{ "alphanum_fraction": 0.6728134879, "avg_line_length": 38.7346938776, "ext": "agda", "hexsha": "91263a27bb2560a38acf5727f2dbf77208d79570", "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/Agda/ISetoids/Cocomplete.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/Agda/ISetoids/Cocomplete.agda", "max_line_length": 160, "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/Agda/ISetoids/Cocomplete.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": 655, "size": 1898 }
{-# OPTIONS --without-K #-} module distinct where open import Type open import Type.Identities open import Algebra.FunctionProperties.Eq renaming (Injective to is-injective) open import Function.NP open import Function.Extensionality open import Data.Fin.NP using (Fin; Fin▹ℕ; _==_) open import Data.Vec.NP open import Data.Vec.Properties open import Data.Product renaming (proj₁ to fst; proj₂ to snd) hiding (map) open import Data.Zero open import Data.One open import Data.Two hiding (_==_) open import Data.Sum hiding (map) open import Data.Nat.NP hiding (_==_) open import Data.Nat.Properties import Data.List as L import Data.List.Properties as LP open L using (List; []; _∷_) open import Relation.Binary.PropositionalEquality.NP open import HoTT open Equivalences --open import Explore.Fin is-distinct : {A : Set}{n : ℕ} → Vec A n → Set is-distinct {n = n} v = is-injective (_‼_ v) -- is-distinct {n = n} v = {p q : Fin n}(e : v ‼ p ≡ v ‼ q) → p ≡ q Distinct : (A : Set)(n : ℕ) → Set Distinct A n = Σ (Vec A n) is-distinct Injection : (A B : Set) → Set Injection A B = Σ (A → B) is-injective Auto : (A : Set) → Set Auto A = Injection A A Perm : (n : ℕ) → Set Perm n = Distinct (Fin n) n module _ {n} {{_ : FunExt}} where Perm→Auto : Perm n → Auto (Fin n) Perm→Auto (v , v-dist) = _‼_ v , v-dist tabulate-dist : (f : Fin n → Fin n) (f-inj : Injective f) → is-distinct tabulate-dist f f-inj e = f-inj (! lookup∘tabulate f _ ∙ e ∙ lookup∘tabulate f _) Auto→Perm : Auto (Fin n) → Perm n Auto→Perm (f , f-inj) = tabulate f , λ e → f-inj (! lookup∘tabulate f _ ∙ e ∙ lookup∘tabulate f _) Goal: tr is-injective (λ= (lookup∘tabulate f)) (snd (Auto→Perm (f , f-inj))) ≡ f-inj Perm→Auto→Perm : ∀ a → Perm→Auto (Auto→Perm a) ≡ a Perm→Auto→Perm (f , f-inj) = pair= (λ= (lookup∘tabulate f)) {!!} Auto→Perm→Auto : ∀ π → Auto→Perm (Perm→Auto π) ≡ π Auto→Perm→Auto (v , v-dist) = pair= (tabulate∘lookup v) {!!} Perm≃Auto : Perm n ≃ Auto (Fin n) Perm≃Auto = equiv Perm→Auto Auto→Perm Perm→Auto→Perm Auto→Perm→Auto Arr : (n : ℕ) → Set Arr n = Vec (Fin n) n Sum : Set → Set Sum A = (A → ℕ) → ℕ Prod = Sum postulate sumFin : (n : ℕ) → Sum (Fin n) prodFin : (n : ℕ) → Prod (Fin n) -- sumVec : (A : Set)(n : ℕ) (f : Vec A n → ℕ) → ℕ sumArr : (n : ℕ) → Sum (Arr n) prodFinEq : {n : ℕ}(x y : Fin n) → Prod (x ≡ y) distinctℕ : (n : ℕ) → (sumArr n λ v → prodFin n λ p → prodFin n λ q → prodFinEq p q λ e → 𝟚▹ℕ (p == q)) ≡ {!!} distinctℕ = {!!} {- ℕ< : ℕ → Set ℕ< n = Σ ℕ λ x → x < n sum< : (n : ℕ) (f : ℕ< n → ℕ) → ℕ sum< n f = {!!} prod< : (n : ℕ) (f : ℕ< n → ℕ) → ℕ prod< n f = {!!} {- foo : ∀ n a x → sumFin n λ i → a i * x ^ i foo = ? bar : ∀ n a x → sumFin n λ i → a i * x ^ i bar = ? -} baz : ∀ n (u : ℕ< n → ℕ) → (sum< n λ { (i , p) → prod< i (λ { (j , q) → u (j , <-trans q p) }) }) ≡ {!!} baz = {!!} module _ n (u : ℕ< n → Set) {{_ : UA}} {{_ : FunExt}} where open ≡-Reasoning Baz : _ ≡ _ Baz = (Σ (ℕ< n) λ { (i , p) → Π (ℕ< i) λ { (j , q) → u (j , <-trans q p) } }) ≡⟨ ! Σ-assoc ⟩ (Σ ℕ λ i → Σ (i < n) λ p → Π (ℕ< i) λ { (j , q) → u (j , <-trans q p) }) ≡⟨ Σ=′ ℕ (λ i → Σ=′ (i < n) λ p → ΠΣ-curry) ⟩ (Σ ℕ λ i → Σ (i < n) λ p → Π ℕ λ j → Π (j < i) λ q → u (j , <-trans q p)) ∎ module DataVersion (A : ★) where open import Data.Tree.Binary data T : BinTree A → ★ where empty : T empty _⊕_ : ∀ {t u} → (𝟙 ⊎ T t × T u) → T (fork t u) module TypeVersion where ε = 𝟙 _⊕_ : ★ → ★ → ★ _⊕_ = λ u z → ε ⊎ u × z module ListVersion where open L open ≡-Reasoning map-∘ = LP.map-compose sum-lin : ∀ k xs → sum (map (_*_ k) xs) ≡ k * sum xs sum-lin k [] = ℕ°.*-comm 0 k sum-lin k (x ∷ xs) = k * x + sum (map (_*_ k) xs) ≡⟨ ap (_+_ (k * x)) (sum-lin k xs) ⟩ k * x + k * sum xs ≡⟨ ! fst ℕ°.distrib k x (sum xs) ⟩ k * (x + sum xs) ∎ lemma : ∀ x xss → sum (map product (map (_∷_ x) xss)) ≡ x * sum (map product xss) lemma x xss = sum (map product (map (_∷_ x) xss)) ≡⟨ ap sum (! map-∘ xss) ⟩ sum (map (product ∘ _∷_ x) xss) ≡⟨by-definition⟩ sum (map (_*_ x ∘ product) xss) ≡⟨ ap sum (map-∘ xss) ⟩ sum (map (_*_ x) (map product xss)) ≡⟨ sum-lin x (map product xss) ⟩ x * sum (map product xss) ∎ ε = 1 _⊕_ = λ u z → ε + u * z t3 = ∀ xs → sum (map product (inits xs)) ≡ foldr _⊕_ ε xs t4 : t3 t4 [] = refl t4 (x ∷ xs) = ap suc (lemma x (inits xs) ∙ ap (_*_ x) (t4 xs)) -- -} -- -} -- -} -- -} -- -}
{ "alphanum_fraction": 0.4904510362, "avg_line_length": 29.2976190476, "ext": "agda", "hexsha": "24274591ddb7256af1fae1206fe0af13c47a059f", "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": "experiments/distinct.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": "experiments/distinct.agda", "max_line_length": 104, "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": "experiments/distinct.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": 1895, "size": 4922 }
unquoteDef x = ?
{ "alphanum_fraction": 0.6470588235, "avg_line_length": 8.5, "ext": "agda", "hexsha": "3faa37d347ba6c50d182a3919f1d3d98d886fab4", "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/Issue1389.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/Issue1389.agda", "max_line_length": 16, "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/Issue1389.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": 6, "size": 17 }
module Helper.Fin where open import Data.Fin hiding (_+_) open import Data.Nat open import Relation.Binary.PropositionalEquality open import Relation.Nullary open import Relation.Nullary.Negation ------------------------------------------------------------------------ -- Fin magic ------------------------------------------------------------------------ +₁ : (x y : ℕ) (i : Fin x) -> Fin (x + y) +₁ zero y () +₁ (suc x) y zero = zero +₁ (suc x) y (suc i) = suc (+₁ x y i) +₂ : (x y : ℕ) (j : Fin y) -> Fin (x + y) +₂ zero y j = j +₂ (suc x) y j = suc (+₂ x y j) data Fin+ (x y : ℕ) : Fin (x + y) -> Set where is+₁ : (i : Fin x) -> Fin+ x y (+₁ x y i) is+₂ : (j : Fin y) -> Fin+ x y (+₂ x y j) ⨁ : (x y : ℕ) (i : Fin (x + y)) -> Fin+ x y i ⨁ zero y i = is+₂ i ⨁ (suc x) y zero = is+₁ zero ⨁ (suc x) y (suc i) with ⨁ x y i ⨁ (suc x) y (suc ._) | is+₁ i = is+₁ (suc i) ⨁ (suc x) y (suc ._) | is+₂ j = is+₂ j [_,_] : {X : Set} {x y : ℕ} (l : Fin x -> X) (r : Fin y -> X) -> {s : Fin (x + y)} -> Fin+ x y s -> X [_,_] l r {._} (is+₁ i) = l i [_,_] l r {._} (is+₂ j) = r j {- [_,_] : {X : Set} {x y : ℕ} (l : Fin x -> X) (r : Fin y -> X) -> (s : Fin (x + y)) -> X [_,_] {X} {x} {y} l r s with ⨁ x y s [_,_] l r ._ | is+₁ i = l i [_,_] l r ._ | is+₂ j = r j -} × : (x y : ℕ) (i : Fin x) (j : Fin y) -> Fin (x * y) × zero _ () _ × (suc x) y zero j = +₁ y (x * y) j × (suc x) y (suc i) j = +₂ y (x * y) (× x y i j) data Fin* (x y : ℕ) : Fin (x * y) -> Set where is× : (i : Fin x) (j : Fin y) -> Fin* x y (× x y i j) ⨂ : (x y : ℕ) (i : Fin (x * y)) -> Fin* x y i ⨂ zero y () ⨂ (suc x) y i with ⨁ y (x * y) i ⨂ (suc x) y ._ | is+₁ i = is× zero i ⨂ (suc x) y ._ | is+₂ j with ⨂ x y j ⨂ (suc x) y ._ | is+₂ ._ | is× i j = is× (suc i) j ------------------------------------------------------------------------ -- Fin lemma's ------------------------------------------------------------------------ suc-eq : {n : ℕ} {x x₁ : Fin n} -> ((Data.Fin.suc x) ≡ (Data.Fin.suc x₁)) -> (x ≡ x₁) suc-eq refl = refl +-eq : {n n₁ : ℕ} {x x₁ : Fin n} -> (m : Fin n₁) -> ((m Data.Fin.+ x) ≡ (m Data.Fin.+ x₁)) -> (x ≡ x₁) +-eq zero p = p +-eq (suc m) p = +-eq m (suc-eq p) +-eq₁ : {n n₁ : ℕ} {x x₁ : Fin n} -> (+₁ n n₁ x ≡ +₁ n n₁ x₁) -> (x ≡ x₁) +-eq₁ {x = zero} {x₁ = zero} p = refl +-eq₁ {x = zero} {suc x₁} () +-eq₁ {x = suc x} {zero} () +-eq₁ {x = suc x} {x₁ = suc x₁} p with +-eq (fromℕ 1) p ... | p1 with +-eq₁ p1 ... | p2 = cong suc p2 +-eq₂ : {n n₁ : ℕ} {x x₁ : Fin n₁} -> (+₂ n n₁ x ≡ +₂ n n₁ x₁) -> (x ≡ x₁) +-eq₂ {zero} refl = refl +-eq₂ {suc n} {suc n₁} {zero} {zero} refl = refl +-eq₂ {suc n} {suc n₁} {zero} {suc x₁} p with suc-eq p ... | p1 = +-eq₂ {n} {suc n₁} p1 +-eq₂ {suc n} {suc n₁} {suc x} {zero} p with suc-eq p ... | p1 = +-eq₂ {n} {suc n₁} p1 +-eq₂ {suc n} {suc n₁} {suc x} {suc x₁} p with suc-eq p ... | p1 = +-eq₂ {n} {suc n₁} p1 ¬+-eq₁ : {n m : ℕ} {x : Fin n} {y : Fin m} -> ¬( (+₁ n m) x ≡ (+₂ n m) y) ¬+-eq₁ {zero} {zero} {()} ¬+-eq₁ {zero} {suc m} {()} ¬+-eq₁ {suc n} {zero} {y = ()} ¬+-eq₁ {suc n} {suc m} {zero} () ¬+-eq₁ {suc n} {suc m} {suc x} {zero} with ¬+-eq₁ {n} {suc m} {x} {zero} ... | p1 = contraposition suc-eq p1 ¬+-eq₁ {suc n} {suc m} {suc x} {suc y} with ¬+-eq₁ {n} {suc m} {x} {suc y} ... | p1 = contraposition suc-eq p1 ¬+-eq₂ : {n m : ℕ} {x : Fin n} {y : Fin m} -> ¬( (+₂ n m) y ≡ (+₁ n m) x) ¬+-eq₂ {zero} {zero} {()} x₁ ¬+-eq₂ {zero} {suc m} {()} x₁ ¬+-eq₂ {suc n} {zero} {zero} () ¬+-eq₂ {suc n} {zero} {suc x} {()} ¬+-eq₂ {suc n} {suc m} {zero} {zero} () ¬+-eq₂ {suc n} {suc m} {zero} {suc y} () ¬+-eq₂ {suc n} {suc m} {suc x} {zero} with ¬+-eq₂ {n} {suc m} {x} {zero} ... | p1 = contraposition suc-eq p1 ¬+-eq₂ {suc n} {suc m} {suc x} {suc y} = contraposition suc-eq (¬+-eq₂ {n} {suc m} {x} {suc y}) ×-equal₁ : ∀ {n m : ℕ} {x₁ x₂ : Fin n} {y₁ y₂ : Fin m} -> (× n m x₁ y₁) ≡ (× n m x₂ y₂) -> (y₁ ≡ y₂) ×-equal₁ {zero} {x₁ = ()} x ×-equal₁ {suc n} {zero} {y₁ = ()} x ×-equal₁ {suc n} {suc m} {zero} {zero} p = +-eq₁ p ×-equal₁ {suc n} {suc m} {zero} {suc x₂} {zero} () ×-equal₁ {suc n} {suc m} {zero} {suc x₂} {suc y₁} p with suc-eq p ... | p1 with ¬+-eq₁ {m} {(n * suc m)} p1 ×-equal₁ {suc n} {suc m} {zero} {suc x₂} {suc y₁} p | p1 | () ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {zero} {zero} p = refl ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {zero} {suc y₂} p with suc-eq p ... | p1 with ¬+-eq₂ p1 ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {zero} {suc y₂} p | p1 | () ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {suc y₁} {zero} () ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {suc y₁} {suc y₂} p with suc-eq p ... | p1 with ¬+-eq₂ p1 ×-equal₁ {suc n} {suc m} {suc x₁} {zero} {suc y₁} {suc y₂} p | p1 | () ×-equal₁ {suc n} {suc m} {suc x₁} {suc x₂} p with suc-eq p ... | p2 with +-eq₂ {suc m} {(n * suc m)} p ... | p3 = ×-equal₁ {n} {suc m} p3 ×-equal₂ : ∀ {n m : ℕ} {x₁ x₂ : Fin n} {y₁ y₂ : Fin m} -> (× n m x₁ y₁) ≡ (× n m x₂ y₂) -> (x₁ ≡ x₂) ×-equal₂ {zero} {x₁ = ()} x ×-equal₂ {suc n} {zero} {y₁ = ()} x ×-equal₂ {suc n} {suc m} {zero} {zero} x = refl ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {zero} {zero} () ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {zero} {suc y₂} () ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {suc y₁} {zero} p with suc-eq p ... | p1 with ¬+-eq₁ p1 ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {suc y₁} {zero} p | p1 | () ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {suc y₁} {suc y₂} p with suc-eq p ... | p1 with ¬+-eq₁ p1 ×-equal₂ {suc n} {suc m} {zero} {suc x₂} {suc y₁} {suc y₂} p | p1 | () ×-equal₂ {suc n} {suc m} {suc x₁} {zero} {y₂ = zero} () ×-equal₂ {suc n} {suc m} {suc x₁} {zero} {zero} {suc y₂} p with suc-eq p ... | p1 with ¬+-eq₂ p1 ×-equal₂ {suc n} {suc m} {suc x₁} {zero} {zero} {suc y₂} p | p1 | () ×-equal₂ {suc n} {suc m} {suc x₁} {zero} {suc y₁} {suc y₂} p with suc-eq p ... | p1 with ¬+-eq₂ p1 ×-equal₂ {suc n} {suc m} {suc x₁} {zero} {suc y₁} {suc y₂} p | p1 | () ×-equal₂ {suc n} {suc m} {suc x₁} {suc x₂} p with suc-eq p ... | p1 with +-eq₂ {m} {(n * suc m)} p1 ... | p2 with ×-equal₂ {n} {suc m} p2 ... | p3 = cong suc p3
{ "alphanum_fraction": 0.4580634446, "avg_line_length": 39.6118421053, "ext": "agda", "hexsha": "ca93689d17690a9bc79ba18543f81833c0259019", "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": "cb95986b772b7a01195619be5e8e590f2429c759", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mathijsb/generic-in-agda", "max_forks_repo_path": "Helper/Fin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "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": "mathijsb/generic-in-agda", "max_issues_repo_path": "Helper/Fin.agda", "max_line_length": 102, "max_stars_count": 6, "max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mathijsb/generic-in-agda", "max_stars_repo_path": "Helper/Fin.agda", "max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z", "num_tokens": 3021, "size": 6021 }
{- Copyright 2019 Lisandra Silva Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -} open import Prelude open import Data.Fin hiding (_≟_; _<_; _+_; pred; _≤_; lift) open import Data.List open import Data.List.Properties open import Relation.Nullary.Negation using (contradiction ; contraposition) open import StateMachineModel module Examples.ProducerConsumer2 (Message : Set) -- Message type where ----------------------------------------------------------------------------- -- SPECIFICATION ----------------------------------------------------------------------------- record State : Set where field produced : List Message consumed : List Message open State data MyEvent : Set where produce : Message → MyEvent consume : Message → MyEvent data MyEnabled : MyEvent → State → Set where prodEnabled : ∀ {st : State} {msg} -- always enabled → MyEnabled (produce msg) st consEnabled : ∀ {st : State} {msg} → (cons<prod : length (consumed st) < length (produced st) ) → msg ≡ lookup (produced st) (fromℕ≤ cons<prod) → MyEnabled (consume msg) st MyAction : ∀ {preState : State} {event : MyEvent} → MyEnabled event preState → State MyAction {preSt} {produce m} enabled = record preSt { produced = produced preSt ++ [ m ] } MyAction {preSt} {consume m} enabled = record preSt { consumed = consumed preSt ++ [ m ] } initialState : State initialState = record { produced = [] ; consumed = [] } MyStateMachine : StateMachine State MyEvent MyStateMachine = record { initial = λ st → produced st ≡ [] × consumed st ≡ [] ; enabled = MyEnabled ; action = MyAction } MyEventSet : EventSet {Event = MyEvent} MyEventSet (produce m) = ⊥ MyEventSet (consume m) = ⊤ data MyWeakFairness : EventSet → Set where wf : MyWeakFairness MyEventSet MySystem : System State MyEvent MySystem = record { stateMachine = MyStateMachine ; weakFairness = MyWeakFairness } ----------------------------------------------------------------------------- -- PROOFS ----------------------------------------------------------------------------- open LeadsTo State MyEvent MySystem myWFR : ∀ {n} → Z → State → Set myWFR {n} d st = d + length (consumed st) ≡ n × n ≤ length (produced st) length-suc : ∀ {x : Message} l → length (l ++ [ x ]) ≡ 1 + length l length-suc {x} l rewrite length-++ l {[ x ]} | +-comm (length l) 1 = refl <⇒≤-l : ∀ {n} (m : Message) (l : List Message) → length l < n → length (l ++ [ m ]) ≤ n <⇒≤-l m l l<n rewrite length-suc {m} l = l<n suc-+-l : ∀ {w} (m : Message) (l : List Message) → w + length (l ++ m ∷ []) ≡ suc (w + length l) suc-+-l {w} m l rewrite length-suc {m} l = +-suc w (length l) inv-cons≤prod : Invariant MyStateMachine λ state → length (consumed state) ≤ length (produced state) inv-cons≤prod (init (refl , refl)) = z≤n inv-cons≤prod (step {st} {produce m} rs enEv) rewrite length-suc {m} (produced st) = ≤-step (inv-cons≤prod rs) inv-cons≤prod (step {st} {consume m} rs (consEnabled c<p x₁)) = <⇒≤-l m (consumed st) c<p --subst (_≤ length (produced st)) (sym (length-suc {m} (consumed st))) c<p m≤n⇒m≡n⊎m<n : ∀ {m n} → m ≤ n → m < n ⊎ m ≡ n m≤n⇒m≡n⊎m<n {0} {0} z≤n = inj₂ refl m≤n⇒m≡n⊎m<n {0} {suc n} x = inj₁ (s≤s z≤n) m≤n⇒m≡n⊎m<n {suc m} {suc n} (s≤s x) with m≤n⇒m≡n⊎m<n x ... | inj₁ m<n = inj₁ (s≤s m<n) ... | inj₂ refl = inj₂ refl [Q∪Fx] : ∀ {st : State} {n} → length (produced st) ≡ n → length (consumed st) ≤ n → length (consumed st) ≡ n ⊎ ∃[ x ] myWFR {n} x st [Q∪Fx] {st} {n} refl cons≤n with m≤n⇒m≡n⊎m<n cons≤n ... | inj₂ cons≡n = inj₁ cons≡n ... | inj₁ cons<n = inj₂ ( n ∸ length (consumed st) , m∸n+n≡m cons≤n , ≤-refl ) wfr-l++ : ∀ {m : Message} {n} l → n < length l → length (l ++ [ m ]) ∸ 1 ∸ n + n ≡ length l × length l ≤ length (l ++ [ m ]) wfr-l++ {m} {n} l n<l rewrite length-suc {m} l = (m∸n+n≡m (<⇒≤ n<l)) , ≤-step ≤-refl {- [P]l-t[Q∪Fx] : ∀ {n} → λ preSt → length (produced preSt) ≡ n × length (consumed preSt) < n l-t (λ posSt → length (consumed posSt) ≡ n) ∪ [∃ x ∶ myWFR {n} x ] -} [P]l-t[Q∪Fx] : ∀ {n} → (_≡ n) ∘ length ∘ produced ∩ (_< n) ∘ length ∘ consumed l-t (_≡ n) ∘ length ∘ consumed ∪ [∃ x ∶ myWFR {n} x ] [P]l-t[Q∪Fx] = viaEvSet MyEventSet wf ( λ { (consume m) evSet → hoare λ { {st} (p≡n , c<p) enEv → let state = MyAction {st} enEv cons = consumed st c≤p = <⇒≤-l m cons c<p in [Q∪Fx] {state} p≡n c≤p } } ) (λ { (produce m) x → hoare λ { {st} (refl , c<p) enEv → let l = length (produced st ++ [ m ]) ∸ 1 c = length (consumed st) in inj₂ (inj₂ ( l ∸ c , wfr-l++ (produced st) c<p))} ; (consume x₁) ⊥ → ⊥-elim (⊥ tt) } ) λ { {state} rs (refl , c<p) → consume (lookup (produced state) (fromℕ≤ c<p)) , tt , (consEnabled c<p refl) } m+n<o⇒n<o : ∀ {l} w m → w + m < l → m < l m+n<o⇒n<o w m w+m<l rewrite sym (+-suc w m) = m+n≤o⇒n≤o w w+m<l mono-l++ : ∀ {n} (m : Message) l → n ≤ length l → n ≤ length (l ++ [ m ]) mono-l++ m l n<l rewrite length-suc {m} l = ≤-step n<l {-[Fw]l-t[Q∪Fx] : ∀ {w n} → myWFR {n} w l-t (λ posSt → length (consumed posSt) ≡ n) ∪ [∃ x ⇒ _< w ∶ myWFR {n} x ] -} [Fw]l-t[Q∪Fx] : ∀ {n} w → myWFR {n} w l-t (_≡ n) ∘ length ∘ consumed ∪ [∃ x ⇒ _< w ∶ myWFR {n} x ] [Fw]l-t[Q∪Fx] 0 = viaInv λ { rs (c≡n , c<p) → inj₁ c≡n } [Fw]l-t[Q∪Fx] (suc w) = viaEvSet MyEventSet wf (λ { (consume m) ⊤ → hoare λ { {st} (refl , c<p) (consEnabled cons<prod x) → inj₂ (w , ≤-refl , suc-+-l m (consumed st) , c<p)} } ) (λ { (produce m) ⊥ → hoare λ { {st} (c≡n , n≤p) enEv → inj₁ (c≡n , mono-l++ m (produced st) n≤p) } ; (consume m) ⊥ → ⊥-elim (⊥ tt) } ) λ { {st} rs (refl , n<p) → let c<l = m+n<o⇒n<o w (length (consumed st)) n<p in consume (lookup (produced st) (fromℕ≤ c<l)) , tt , (consEnabled c<l refl) } {-P2-l-t-Q : ∀ {n} → λ preSt → length (produced preSt) ≡ n × length (consumed preSt) < n l-t λ posSt → length (consumed posSt) ≡ n -} cons<n-l-t-cons≡n : ∀ {n} → (_≡ n) ∘ length ∘ produced ∩ (_< n) ∘ length ∘ consumed l-t (_≡ n) ∘ length ∘ consumed cons<n-l-t-cons≡n = viaWFR myWFR [P]l-t[Q∪Fx] [Fw]l-t[Q∪Fx] P⊆P1∪P2 : ∀ {m n : ℕ} {ℓ} { P : Set ℓ } → P × m ≤ n → P × m ≡ n ⊎ P × m < n P⊆P1∪P2 {m} {n} (p , m≤n) with m ≟ n ... | yes prf = inj₁ (p , prf) ... | no imp = inj₂ (p , (≤∧≢⇒< m≤n imp)) {-c≢n-l-t-c<n : ∀ {n} → ( λ preSt → length (produced preSt) ≡ n × length (consumed preSt) ≢ n ) l-t ( λ posSt → length (produced posSt) ≡ n × length (consumed posSt) < n ) -} p≡n-l-t-c≤n : ∀ {n} → (_≡ n) ∘ length ∘ produced l-t (_≡ n) ∘ length ∘ produced ∩ (_≤ n) ∘ length ∘ consumed p≡n-l-t-c≤n = viaInv (λ { {st} rs refl → refl , (inv-cons≤prod rs) }) progressOnLength : ∀ n → (_≡ n) ∘ length ∘ produced l-t (_≡ n) ∘ length ∘ consumed progressOnLength n = viaTrans p≡n-l-t-c≤n (viaDisj (λ { {st} (p≡n , c≤n) → P⊆P1∪P2 (p≡n , c≤n) }) (viaInv (λ { {st} rs (_ , c≡n) → c≡n })) cons<n-l-t-cons≡n ) lookup-++ : ∀ {n} {m : Message} l₁ l₂ → (finl₁ : n < length l₁) → (finl₂ : n < length l₂) → (fin++ : n < length (l₂ ++ [ m ])) → lookup l₁ (fromℕ≤ finl₁) ≡ lookup l₂ (fromℕ≤ finl₂) → lookup l₁ (fromℕ≤ finl₁) ≡ lookup (l₂ ++ [ m ]) (fromℕ≤ fin++) lookup-++ {zero} (x ∷ l₁) (x₁ ∷ l₂) finl₁ finl₂ fin++ ll₁≡ll₂ = ll₁≡ll₂ lookup-++ {suc n} (x ∷ l₁) (x₁ ∷ l₂) finl₁ finl₂ fin++ ll₁≡ll₂ = lookup-++ l₁ l₂ (≤-pred finl₁) (≤-pred finl₂) (≤-pred fin++) ll₁≡ll₂ n≤l++⇒n≤l⊎n≡l : ∀ {m : Message} {n} l → n ≤ length (l ++ [ m ]) → n ≤ length l ⊎ n ≡ 1 + length l n≤l++⇒n≤l⊎n≡l {m} l n≤l++ rewrite length-suc {m} l with m≤n⇒m≡n⊎m<n n≤l++ ... | inj₁ 1+n≤1+l = inj₁ (≤-pred 1+n≤1+l) ... | inj₂ n≡1+l = inj₂ n≡1+l lookup-length : ∀ {m : Message} l → (prf : length l < length (l ++ [ m ])) → lookup (l ++ [ m ]) (fromℕ≤ prf) ≡ m lookup-length [] prf = refl lookup-length (x ∷ l) prf = lookup-length l (≤-pred prf) <-refl-l : ∀ {m : Message} l → length l < length (l ++ [ m ]) <-refl-l [] = s≤s z≤n <-refl-l (x ∷ l) = s≤s (<-refl-l l) lookup-c≡lookup-p : ∀ {n} → Invariant MyStateMachine λ st → (prfC : n < length (consumed st)) → (prfP : n < length (produced st)) → lookup (consumed st) (fromℕ≤ prfC) ≡ lookup (produced st) (fromℕ≤ prfP) lookup-c≡lookup-p {n} (init (refl , refl)) () () lookup-c≡lookup-p {n} (step {st} {produce x} rs enEv) prfC prfP = let c<p = <-transˡ prfC (inv-cons≤prod rs) in lookup-++ (consumed st) (produced st) prfC c<p prfP (lookup-c≡lookup-p rs prfC c<p) lookup-c≡lookup-p {n} (step {st} {consume m} rs enEv) prfC prfP with enEv ... | consEnabled cons<prod m≡lookup with n≤l++⇒n≤l⊎n≡l (consumed st) prfC ... | inj₁ n<c = sym (lookup-++ (produced st) (consumed st) prfP n<c prfC (sym (lookup-c≡lookup-p rs n<c prfP))) ... | inj₂ refl = trans (lookup-length (consumed st) (<-refl-l (consumed st))) m≡lookup -- TODO : Generalize all functions about lists take-n-l++ : ∀ {n} (l₁ l₂ : List Message) → n ≤ length l₁ → take n l₁ ≡ take n (l₁ ++ l₂) take-n-l++ {zero} l₁ l₂ n≤l₁ = refl take-n-l++ {suc n} (x ∷ l₁) l₂ n≤l₁ rewrite take-n-l++ l₁ l₂ (≤-pred n≤l₁) = refl l₁≡l₂ : ∀ {m₁ m₂ : Message} {l₁ l₂} → m₁ ∷ l₁ ≡ m₂ ∷ l₂ → m₁ ≡ m₂ × l₁ ≡ l₂ l₁≡l₂ refl = refl , refl m₁≡m∧l₁≡l₂₂⇒l≡l : ∀ {m₁ m₂ : Message} {l₁ l₂} → m₁ ≡ m₂ → l₁ ≡ l₂ → m₁ ∷ l₁ ≡ m₂ ∷ l₂ m₁≡m∧l₁≡l₂₂⇒l≡l refl refl = refl taken×lookup : ∀ {m : Message} l₁ l₂ → (prf : length l₁ < length l₂) → l₁ ≡ take (length l₁) l₂ → m ≡ lookup l₂ (fromℕ≤ prf) → l₁ ++ [ m ] ≡ take (suc (length l₁)) l₂ taken×lookup [] (x₂ ∷ l₂) l₁<l₂ l₁≡take refl = refl taken×lookup (x₂ ∷ l₁) (x₃ ∷ l₂) l₁<l₂ l₁≡tk m≡lkp rewrite taken×lookup l₁ l₂ (≤-pred l₁<l₂) (proj₂ (l₁≡l₂ l₁≡tk)) m≡lkp = m₁≡m∧l₁≡l₂₂⇒l≡l (proj₁ (l₁≡l₂ l₁≡tk)) refl take1+l≡takel++m : ∀ {m : Message} {n} l → n ≡ 1 + length l → take n (l ++ [ m ]) ≡ l ++ [ m ] take1+l≡takel++m [] refl = refl take1+l≡takel++m {m} (x₁ ∷ l) refl rewrite take1+l≡takel++m {m} l refl = refl take-length≡l : ∀ (l : List Message) → take (length l) l ≡ l take-length≡l [] = refl take-length≡l (x ∷ l) rewrite take-length≡l l = refl [c]-prefix-[p] : ∀ {n} → Invariant MyStateMachine λ st → n ≤ length (consumed st) → take n (consumed st) ≡ take n (produced st) [c]-prefix-[p] {n} (init (refl , refl)) n<lc = refl [c]-prefix-[p] {n} (step {st} {produce m} rs enEv) n<lc = trans ([c]-prefix-[p] rs n<lc) (take-n-l++ (produced st) ([ m ]) (≤-trans n<lc (inv-cons≤prod rs))) [c]-prefix-[p] {n} (step {st} {consume m} rs enEv) n≤c++ with enEv ... | consEnabled cons<prod m≡lookup with n≤l++⇒n≤l⊎n≡l (consumed st) n≤c++ ... | inj₁ n≤c = trans (sym (take-n-l++ (consumed st) [ m ] n≤c)) ([c]-prefix-[p] rs n≤c) ... | inj₂ refl = let tc≡tp = [c]-prefix-[p] rs ≤-refl in trans (take1+l≡takel++m (consumed st) refl) (taken×lookup (consumed st) (produced st) cons<prod (trans (sym (take-length≡l (consumed st))) tc≡tp) m≡lookup) take-presrv-prfix : ∀ {l₁ l₂} {m : Message} → take (length l₂) l₁ ≡ l₂ → take (length l₂) (l₁ ++ [ m ]) ≡ l₂ take-presrv-prfix {[]} {[]} {m} tl₁≡l₂ = refl take-presrv-prfix {m₁ ∷ l₁} {[]} {m} tl₁≡l₂ = refl take-presrv-prfix {m₁ ∷ l₁} {m₂ ∷ l₂} {m} tl₁≡l₂ with l₁≡l₂ tl₁≡l₂ ... | m₁≡m₂ , tll₁≡l₂ with take-presrv-prfix {m = m} tll₁≡l₂ ... | tl₁+m≡l₂ = m₁≡m∧l₁≡l₂₂⇒l≡l m₁≡m₂ tl₁+m≡l₂ stable-produced : ∀ {msgs} → Stable MyStateMachine λ st → take (length msgs) (produced st) ≡ msgs stable-produced {msgs} {st} {produce m} enEv tkp≡m = take-presrv-prfix tkp≡m stable-produced {msgs} {st} {consume x₁} enEv tkp≡m = tkp≡m aux : ∀ {n m} {l₁ l₂ : List Message} → n ≡ m → take n l₁ ≡ take n l₂ → take n l₁ ≡ take m l₂ aux refl prf = prf lc≡lm-l-t-c≡m : ∀ {msgs} → (λ preSt → length (consumed preSt) ≡ length msgs × take (length msgs) (produced preSt) ≡ msgs ) l-t λ posSt → consumed posSt ≡ msgs lc≡lm-l-t-c≡m {msgs} = viaInv (λ { {st} rs (lc≡lm , tp≡msgs) → trans (trans (sym (take-length≡l (consumed st))) (aux lc≡lm ([c]-prefix-[p] rs ≤-refl))) tp≡msgs }) msgsPrefixProd : ∀ {msgs} → (λ st → produced st ≡ msgs) l-t (λ st → length (produced st) ≡ length msgs × take (length msgs) (produced st) ≡ msgs) msgsPrefixProd = viaInv (λ { {st} rs refl → refl , take-length≡l (produced st) }) progress : ∀ {msgs} → (_≡ msgs) ∘ produced l-t (_≡ msgs) ∘ consumed progress {msgs} = viaStable stable-produced msgsPrefixProd (progressOnLength (length msgs)) lc≡lm-l-t-c≡m {- Another way of proving without the viaStable rule progressOnLength' : ∀ {msgs} → (λ st₁ → length (produced st₁) ≡ length msgs × take (length msgs) (produced st₁) ≡ msgs) l-t λ st₂ → length (consumed st₂) ≡ length msgs × take (length msgs) (produced st₂) ≡ msgs progress : ∀ {msgs} → (_≡ msgs) ∘ produced l-t (_≡ msgs) ∘ consumed progress {msgs} = viaTrans (viaInv inv-prodPrefix) (viaTrans progressOnLength' lc≡lm-l-t-c≡m) -}
{ "alphanum_fraction": 0.4450565725, "avg_line_length": 33.2958579882, "ext": "agda", "hexsha": "e61471dbdef301aeb809ff75cd86e0e76b68f95f", "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": "391e148f391dc2d246249193788a0d203285b38e", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "lisandrasilva/agda-liveness", "max_forks_repo_path": "src/Examples/ProducerConsumer2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e", "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": "lisandrasilva/agda-liveness", "max_issues_repo_path": "src/Examples/ProducerConsumer2.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "lisandrasilva/agda-liveness", "max_stars_repo_path": "src/Examples/ProducerConsumer2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5996, "size": 16881 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.NType2 -- [Subtype] is defined in lib.NType. module lib.types.Subtype where infix 40 _⊆_ _⊆_ : ∀ {i j₁ j₂} {A : Type i} → SubtypeProp A j₁ → SubtypeProp A j₂ → Type (lmax i (lmax j₁ j₂)) P₁ ⊆ P₂ = ∀ a → SubtypeProp.prop P₁ a → SubtypeProp.prop P₂ a infix 80 _∘sub_ _∘sub_ : ∀ {i j k} {A : Type i} {B : Type j} → SubtypeProp B k → (A → B) → SubtypeProp A k P ∘sub f = SubtypeProp.prop P ∘ f , level where abstract level = SubtypeProp.level P ∘ f Subtype-has-dec-eq : ∀ {i j} {A : Type i} (subProp : SubtypeProp A j) → has-dec-eq A → has-dec-eq (Subtype subProp) Subtype-has-dec-eq subProp dec s₁ s₂ with dec (fst s₁) (fst s₂) ... | inl s₁=s₂ = inl (Subtype=-out subProp s₁=s₂) ... | inr s₁≠s₂ = inr λ s₁=s₂ → s₁≠s₂ (ap fst s₁=s₂) {- Dependent paths in a Σ-type -} module _ {i j k} {A : Type i} {B : A → Type j} (subB : (a : A) → SubtypeProp (B a) k) where ↓-Subtype-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : SubtypeProp.prop (subB x) r} {s' : SubtypeProp.prop (subB x') r'} (q : r == r' [ B ↓ p ]) → (r , s) == (r' , s') [ (λ x → Subtype (subB x)) ↓ p ] ↓-Subtype-in {p = idp} q = Subtype=-out (subB _) q
{ "alphanum_fraction": 0.5787337662, "avg_line_length": 34.2222222222, "ext": "agda", "hexsha": "481d5fcd1c2f16d33315733e64a7e24992088dd5", "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": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Subtype.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "timjb/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Subtype.agda", "max_line_length": 85, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Subtype.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": 525, "size": 1232 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Pointed.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Data.Sigma open import Cubical.Foundations.Structure open import Cubical.Foundations.Structure using (typ) public open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism private variable ℓ ℓ' : Level Pointed : (ℓ : Level) → Type (ℓ-suc ℓ) Pointed ℓ = TypeWithStr ℓ (λ x → x) pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙ pt = str Pointed₀ = Pointed ℓ-zero {- Pointed functions -} _→∙_ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ') _→∙_ A B = Σ[ f ∈ (typ A → typ B) ] f (pt A) ≡ pt B _→∙_∙ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ') A →∙ B ∙ = (A →∙ B) , (λ x → pt B) , refl idfun∙ : ∀ {ℓ} (A : Pointed ℓ) → A →∙ A idfun∙ A = (λ x → x) , refl -- Pointed equivalences _≃∙_ : (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ') A ≃∙ B = Σ[ (f , p) ∈ A →∙ B ] isEquiv f ≃∙→≃ : {A : Pointed ℓ} {B : Pointed ℓ'} (f : A ≃∙ B) → typ A ≃ typ B ≃∙→≃ f = fst (fst f) , snd f idEquiv∙ : (A : Pointed ℓ) → A ≃∙ A idEquiv∙ (A , ⋆) = (idfun∙ (A , ⋆)) , record { equiv-proof = λ a → p a } where module _ (a : A) where p : isContr (Σ[ a' ∈ A ] a' ≡ a) p = isContrRespectEquiv (Σ-cong-equiv-snd (λ a₁ → isoToEquiv (iso sym sym (λ _ → refl) λ _ → refl))) (isContrSingl a) {- HIT allowing for pattern matching on pointed types -} data Pointer {ℓ} (A : Pointed ℓ) : Type ℓ where pt₀ : Pointer A ⌊_⌋ : typ A → Pointer A id : ⌊ pt A ⌋ ≡ pt₀ IsoPointedPointer : ∀ {ℓ} {A : Pointed ℓ} → Iso (typ A) (Pointer A) Iso.fun IsoPointedPointer = ⌊_⌋ Iso.inv (IsoPointedPointer {A = A}) pt₀ = pt A Iso.inv IsoPointedPointer ⌊ x ⌋ = x Iso.inv (IsoPointedPointer {A = A}) (id i) = pt A Iso.rightInv IsoPointedPointer pt₀ = id Iso.rightInv IsoPointedPointer ⌊ x ⌋ = refl Iso.rightInv IsoPointedPointer (id i) j = id (i ∧ j) Iso.leftInv IsoPointedPointer x = refl
{ "alphanum_fraction": 0.6162086633, "avg_line_length": 30.2394366197, "ext": "agda", "hexsha": "13b0d37c1110068e13511c1edabc1d246612df36", "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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Schippmunk/cubical", "max_issues_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_line_length": 125, "max_stars_count": null, "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_path": "Cubical/Foundations/Pointed/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 893, "size": 2147 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category using (Category; module Commutation) open import Categories.Category.Monoidal.Core using (Monoidal) open import Categories.Category.Monoidal.Symmetric using (Symmetric) -- Extra identities that hold only for symmetric monoidal categories. module Categories.Category.Monoidal.Interchange.Symmetric {o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (S : Symmetric M) where open import Data.Product using (_,_) import Categories.Category.Construction.Core C as Core import Categories.Category.Monoidal.Braided.Properties as BraidedProps open import Categories.Category.Monoidal.Interchange using (HasInterchange) import Categories.Category.Monoidal.Interchange.Braided as BraidedInterchange using (module swapInner; swapInner-braiding) import Categories.Category.Monoidal.Reasoning M as MonoidalReasoning import Categories.Category.Monoidal.Utilities M as MonoidalUtilities open import Categories.Category.Product using (_⁂_; assocˡ) open import Categories.Functor using (_∘F_) open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_; niHelper) open import Categories.Morphism.IsoEquiv C using (to-unique) open import Categories.Morphism.Reasoning C using (elim-center; pushˡ; pullʳ; cancelInner; switch-fromtoˡ) open Category C using (Obj; _⇒_; _∘_; id; sym-assoc; ∘-resp-≈ʳ; module Equiv) open Commutation C open MonoidalReasoning open MonoidalUtilities using (_⊗ᵢ_) open Symmetric S renaming (associator to α; braided to B) open BraidedInterchange B open Core.Shorthands -- for idᵢ, _∘ᵢ_, ... open MonoidalUtilities.Shorthands -- for λ⇒, ρ⇒, α⇒, ... open BraidedProps.Shorthands B -- for σ⇒, ... private variable W W₁ W₂ X X₁ X₂ Y Y₁ Y₂ Z Z₁ Z₂ : Obj f g h i : X ⇒ Y private i⇒ = swapInner.from i⇐ = swapInner.to swapInner-commutative : [ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ⇒ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ]⟨ i⇒ ⇒⟨ (X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂) ⟩ i⇒ ≈ id ⟩ swapInner-commutative = begin i⇒ ∘ i⇒ ≈⟨ pullʳ (cancelInner α.isoʳ) ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ (∘-resp-≈ʳ sym-assoc ○ α[σ⊗1]α⁻¹.isoʳ) ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ id ∘ α⇒ ≈⟨ elim-center ⊗.identity ○ α.isoˡ ⟩ id ∎ where module α[σ⊗1]α⁻¹ = _≅_ (α ∘ᵢ braided-iso ⊗ᵢ idᵢ ∘ᵢ α ⁻¹) using (isoʳ) swapInner-iso : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) swapInner-iso = record { from = i⇒ ; to = i⇒ ; iso = record { isoˡ = swapInner-commutative ; isoʳ = swapInner-commutative } } swapInner-selfInverse : [ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ⇒ (X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂) ]⟨ i⇒ ≈ i⇐ ⟩ swapInner-selfInverse = to-unique (iso swapInner-iso) swapInner.iso Equiv.refl swapInner-braiding′ : [ (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ⇒ (Y ⊗₀ W) ⊗₀ (Z ⊗₀ X) ]⟨ i⇒ ⇒⟨ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) ⟩ σ⇒ ⊗₁ σ⇒ ≈ σ⇒ ⇒⟨ (Y ⊗₀ Z) ⊗₀ (W ⊗₀ X) ⟩ i⇒ ⟩ swapInner-braiding′ = switch-fromtoˡ swapInner-iso swapInner-braiding
{ "alphanum_fraction": 0.5656678801, "avg_line_length": 41.0459770115, "ext": "agda", "hexsha": "134da1111ee7ed224badfe210ecd18a0d9b9d7fb", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Category/Monoidal/Interchange/Symmetric.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Category/Monoidal/Interchange/Symmetric.agda", "max_line_length": 138, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Category/Monoidal/Interchange/Symmetric.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 1311, "size": 3571 }
-- This code is based on https://github.com/agda/agda-stdlib/pull/800/files {-# OPTIONS --without-K --safe #-} module Experiment.Categories.Solver.Category.Reflection where open import Data.Nat open import Data.List open import Data.Maybe using (Maybe; nothing; just; maybe) open import Data.Product open import Data.Bool open import Function using (_⟨_⟩_) open import Agda.Builtin.Reflection as Builtin open import Categories.Category open import Experiment.Categories.Solver.Category hiding (solve) _==_ = Builtin.primQNameEquality {-# INLINE _==_ #-} _>>=_ = bindTC {-# INLINE _>>=_ #-} infixr 5 _⟨∷⟩_ _⟅∷⟆_ pattern _⟨∷⟩_ x xs = arg (arg-info visible relevant) x ∷ xs pattern _⟅∷⟆_ x xs = arg (arg-info hidden relevant) x ∷ xs infixr 5 _⋯⟅∷⟆_ _⋯⟅∷⟆_ : ℕ → List (Arg Term) → List (Arg Term) zero ⋯⟅∷⟆ xs = xs suc i ⋯⟅∷⟆ xs = unknown ⟅∷⟆ i ⋯⟅∷⟆ xs {-# INLINE _⋯⟅∷⟆_ #-} getName : Term → Maybe Name getName (con c args) = just c getName (def f args) = just f getName _ = nothing getArgs : Term → Maybe (Term × Term) getArgs (def _ xs) = go xs where go : List (Arg Term) → Maybe (Term × Term) go (x ⟨∷⟩ y ⟨∷⟩ []) = just (x , y) go (x ∷ xs) = go xs go _ = nothing getArgs _ = nothing record CategoryNames : Set where field is-∘ : Name → Bool is-id : Name → Bool findCategoryNames : Term → TC CategoryNames findCategoryNames cat = do ∘-name ← normalise (quote Category._∘_ ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ []) id-name ← normalise (quote Category.id ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ []) returnTC record { is-∘ = buildMatcher (quote Category._∘_) (getName ∘-name) ; is-id = buildMatcher (quote Category.id) (getName id-name) } where buildMatcher : Name → Maybe Name → Name → Bool buildMatcher n = maybe (λ m x → n == x ∨ m == x) (n ==_) :id′ : Term :id′ = quote :id ⟨ con ⟩ [] ∥_∥′ : Term → Term ∥_∥′ t = quote ∥_∥ ⟨ con ⟩ (t ⟨∷⟩ []) module _ (names : CategoryNames) where open CategoryNames names :∘′ : List (Arg Term) → Term E′ : Term → Term :∘′ (x ⟨∷⟩ y ⟨∷⟩ []) = quote _:∘_ ⟨ con ⟩ E′ x ⟨∷⟩ E′ y ⟨∷⟩ [] :∘′ (x ∷ xs) = :∘′ xs :∘′ _ = unknown E′ t@(def n xs) = if is-∘ n then :∘′ xs else if is-id n then :id′ else ∥ t ∥′ E′ t@(con n xs) = if is-∘ n then :∘′ xs else if is-id n then :id′ else ∥ t ∥′ E′ t = ∥ t ∥′ constructSoln : Term → CategoryNames → Term → Term → Term constructSoln cat names lhs rhs = quote Category.Equiv.trans ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ (quote Category.Equiv.sym ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ (quote ⟦e⟧N≈⟦e⟧ ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ E′ names lhs ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ (quote ⟦e⟧N≈⟦e⟧ ⟨ def ⟩ 2 ⋯⟅∷⟆ cat ⟨∷⟩ E′ names rhs ⟨∷⟩ []) ⟨∷⟩ [] macro solve : Term → Term → TC _ solve cat = λ hole → do hole′ ← inferType hole >>= normalise names ← findCategoryNames cat just (lhs , rhs) ← returnTC (getArgs hole′) where nothing → typeError (termErr hole′ ∷ []) let soln = constructSoln cat names lhs rhs unify hole soln -- Example module _ {o l e} (C : Category o l e) where open Category C _ : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → (h ∘ id ∘ g) ∘ f ≈ id ∘ h ∘ (g ∘ f ∘ id) _ = solve C _ : ∀ {A} {f g h i j : A ⇒ A} → id ∘ (f ∘ id ∘ g) ∘ id ∘ (h ∘ id ∘ i) ∘ id ∘ j ≈ f ∘ (g ∘ h) ∘ (i ∘ j) _ = solve C
{ "alphanum_fraction": 0.5556220096, "avg_line_length": 27.1869918699, "ext": "agda", "hexsha": "e3c9de6f5373dd08e8ac80d84b55b29d88cce862", "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/Categories/Solver/Category/Reflection.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/Categories/Solver/Category/Reflection.agda", "max_line_length": 76, "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/Categories/Solver/Category/Reflection.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": 1348, "size": 3344 }
-- Basic intuitionistic propositional calculus, without ∨ or ⊥. -- Hilbert-style formalisation of closed syntax. -- Nested terms. module BasicIPC.Syntax.ClosedHilbert where open import BasicIPC.Syntax.Common public -- Derivations. infix 3 ⊢_ data ⊢_ : Ty → Set where app : ∀ {A B} → ⊢ A ▻ B → ⊢ A → ⊢ B ci : ∀ {A} → ⊢ A ▻ A ck : ∀ {A B} → ⊢ A ▻ B ▻ A cs : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C cpair : ∀ {A B} → ⊢ A ▻ B ▻ A ∧ B cfst : ∀ {A B} → ⊢ A ∧ B ▻ A csnd : ∀ {A B} → ⊢ A ∧ B ▻ B unit : ⊢ ⊤ infix 3 ⊢⋆_ ⊢⋆_ : Cx Ty → Set ⊢⋆ ∅ = 𝟙 ⊢⋆ Ξ , A = ⊢⋆ Ξ × ⊢ A -- Cut and multicut. cut : ∀ {A B} → ⊢ A → ⊢ A ▻ B → ⊢ B cut t u = app u t multicut : ∀ {Ξ A} → ⊢⋆ Ξ → ⊢ Ξ ▻⋯▻ A → ⊢ A multicut {∅} ∙ u = u multicut {Ξ , B} (ts , t) u = app (multicut ts u) t -- Contraction. ccont : ∀ {A B} → ⊢ (A ▻ A ▻ B) ▻ A ▻ B ccont = app (app cs cs) (app ck ci) cont : ∀ {A B} → ⊢ A ▻ A ▻ B → ⊢ A ▻ B cont t = app ccont t -- Exchange, or Schönfinkel’s C combinator. cexch : ∀ {A B C} → ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C cexch = app (app cs (app (app cs (app ck cs)) (app (app cs (app ck ck)) cs))) (app ck ck) exch : ∀ {A B C} → ⊢ A ▻ B ▻ C → ⊢ B ▻ A ▻ C exch t = app cexch t -- Composition, or Schönfinkel’s B combinator. ccomp : ∀ {A B C} → ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C ccomp = app (app cs (app ck cs)) ck comp : ∀ {A B C} → ⊢ B ▻ C → ⊢ A ▻ B → ⊢ A ▻ C comp t u = app (app ccomp t) u -- Useful theorems in functional form. pair : ∀ {A B} → ⊢ A → ⊢ B → ⊢ A ∧ B pair t u = app (app cpair t) u fst : ∀ {A B} → ⊢ A ∧ B → ⊢ A fst t = app cfst t snd : ∀ {A B} → ⊢ A ∧ B → ⊢ B snd t = app csnd t -- Convertibility. data _⋙_ : ∀ {A} → ⊢ A → ⊢ A → Set where refl⋙ : ∀ {A} → {t : ⊢ A} → t ⋙ t trans⋙ : ∀ {A} → {t t′ t″ : ⊢ A} → t ⋙ t′ → t′ ⋙ t″ → t ⋙ t″ sym⋙ : ∀ {A} → {t t′ : ⊢ A} → t ⋙ t′ → t′ ⋙ t congapp⋙ : ∀ {A B} → {t t′ : ⊢ A ▻ B} → {u u′ : ⊢ A} → t ⋙ t′ → u ⋙ u′ → app t u ⋙ app t′ u′ congi⋙ : ∀ {A} → {t t′ : ⊢ A} → t ⋙ t′ → app ci t ⋙ app ci t′ congk⋙ : ∀ {A B} → {t t′ : ⊢ A} → {u u′ : ⊢ B} → t ⋙ t′ → u ⋙ u′ → app (app ck t) u ⋙ app (app ck t′) u′ congs⋙ : ∀ {A B C} → {t t′ : ⊢ A ▻ B ▻ C} → {u u′ : ⊢ A ▻ B} → {v v′ : ⊢ A} → t ⋙ t′ → u ⋙ u′ → v ⋙ v′ → app (app (app cs t) u) v ⋙ app (app (app cs t′) u′) v′ congpair⋙ : ∀ {A B} → {t t′ : ⊢ A} → {u u′ : ⊢ B} → t ⋙ t′ → u ⋙ u′ → app (app cpair t) u ⋙ app (app cpair t′) u′ congfst⋙ : ∀ {A B} → {t t′ : ⊢ A ∧ B} → t ⋙ t′ → app cfst t ⋙ app cfst t′ congsnd⋙ : ∀ {A B} → {t t′ : ⊢ A ∧ B} → t ⋙ t′ → app csnd t ⋙ app csnd t′ -- TODO: Verify this. beta▻ₖ⋙ : ∀ {A B} → {t : ⊢ A} → {u : ⊢ B} → app (app ck t) u ⋙ t -- TODO: Verify this. beta▻ₛ⋙ : ∀ {A B C} → {t : ⊢ A ▻ B ▻ C} → {u : ⊢ A ▻ B} → {v : ⊢ A} → app (app (app cs t) u) v ⋙ app (app t v) (app u v) -- TODO: What about eta for ▻? beta∧₁⋙ : ∀ {A B} → {t : ⊢ A} → {u : ⊢ B} → app cfst (app (app cpair t) u) ⋙ t beta∧₂⋙ : ∀ {A B} → {t : ⊢ A} → {u : ⊢ B} → app csnd (app (app cpair t) u) ⋙ u eta∧⋙ : ∀ {A B} → {t : ⊢ A ∧ B} → t ⋙ app (app cpair (app cfst t)) (app csnd t) eta⊤⋙ : ∀ {t : ⊢ ⊤} → t ⋙ unit
{ "alphanum_fraction": 0.3520299145, "avg_line_length": 26.3661971831, "ext": "agda", "hexsha": "4c4a643ae3f3ef72593d4bc2a6f7d72a6a6eeffe", "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": "BasicIPC/Syntax/ClosedHilbert.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": "BasicIPC/Syntax/ClosedHilbert.agda", "max_line_length": 81, "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": "BasicIPC/Syntax/ClosedHilbert.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": 1740, "size": 3744 }
{-# OPTIONS --without-K #-} module algebra.monoid.core where open import level open import algebra.semigroup open import equality.core open import sum record IsMonoid {i} (M : Set i) : Set i where field instance sgrp : IsSemigroup M open IsSemigroup sgrp public field e : M lunit : (x : M) → e * x ≡ x runit : (x : M) → x * e ≡ x Monoid : ∀ i → Set (lsuc i) Monoid i = Σ (Set i) IsMonoid
{ "alphanum_fraction": 0.6361445783, "avg_line_length": 19.7619047619, "ext": "agda", "hexsha": "af2323e90725f2a075d41f50b9971fddf4e1e8cd", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/algebra/monoid/core.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/algebra/monoid/core.agda", "max_line_length": 45, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/algebra/monoid/core.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 141, "size": 415 }
module Nats.Add.Assoc where open import Equality open import Nats open import Function ------------------------------------------------------------------------ -- internal stuffs private a+/b+c/=/a+b/+c : ∀ a b c → a + b + c ≡ a + (b + c) a+/b+c/=/a+b/+c zero b c = refl a+/b+c/=/a+b/+c (suc a) b c = cong suc $ a+/b+c/=/a+b/+c a b c ------------------------------------------------------------------------ -- public aliases nat-add-assoc : ∀ a b c → a + b + c ≡ a + (b + c) nat-add-assoc = a+/b+c/=/a+b/+c
{ "alphanum_fraction": 0.3881453155, "avg_line_length": 23.7727272727, "ext": "agda", "hexsha": "1bcdde20205ceafbcfc62c9537988f47d2de6403", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ice1k/Theorems", "max_forks_repo_path": "src/Nats/Add/Assoc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ice1k/Theorems", "max_issues_repo_path": "src/Nats/Add/Assoc.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ice1k/Theorems", "max_stars_repo_path": "src/Nats/Add/Assoc.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z", "num_tokens": 162, "size": 523 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Optics.All open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.KVMap open import LibraBFT.Base.PKCS open import LibraBFT.Hash open import LibraBFT.Impl.Base.Types open import LibraBFT.Impl.Consensus.Types open import LibraBFT.Impl.Util.Crypto open import LibraBFT.Impl.Handle sha256 sha256-cr open import LibraBFT.Concrete.System.Parameters open EpochConfig open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK -- This module contains placeholders for the future analog of the -- corresponding VotesOnce property. Defining the implementation -- obligation and proving that it is an invariant of an implementation -- is a substantial undertaking. We are working first on proving the -- simpler VotesOnce property to settle down the structural aspects -- before tackling the harder semantic issues. module LibraBFT.Concrete.Properties.LockedRound where -- TODO-3: define the implementation obligation ImplObligation₁ : Set ImplObligation₁ = Unit -- Next, we prove that given the necessary obligations, module Proof (sps-corr : StepPeerState-AllValidParts) (Impl-LR1 : ImplObligation₁) where -- Any reachable state satisfies the LR rule for any epoch in the system. module _ {e}(st : SystemState e)(r : ReachableSystemState st)(eid : Fin e) where -- Bring in 'unwind', 'ext-unforgeability' and friends open Structural sps-corr -- Bring in IntSystemState open import LibraBFT.Concrete.System sps-corr open PerState st r open PerEpoch eid open import LibraBFT.Concrete.Obligations.LockedRound 𝓔 (ConcreteVoteEvidence 𝓔) as LR postulate -- TODO-3: prove it lrr : LR.Type IntSystemState
{ "alphanum_fraction": 0.7746478873, "avg_line_length": 40.5714285714, "ext": "agda", "hexsha": "d13d7c7dc90158a38568a0580d31c881b32f3d28", "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": "34e4627855fb198665d0c98f377403a906ba75d7", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "haroldcarr/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Concrete/Properties/LockedRound.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7", "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": "haroldcarr/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Concrete/Properties/LockedRound.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "haroldcarr/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Concrete/Properties/LockedRound.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 537, "size": 1988 }
{-# OPTIONS --without-K #-} data D : Set where @0 c : D data P : D → Set where d : P c
{ "alphanum_fraction": 0.5161290323, "avg_line_length": 11.625, "ext": "agda", "hexsha": "b2fc507b2a3eaf45ace0fc0cc8e9d754facd6e32", "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": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/Issue5920b.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Fail/Issue5920b.agda", "max_line_length": 27, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/Issue5920b.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 33, "size": 93 }
------------------------------------------------------------------------ -- Unary relations ------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Adapted from the Agda standard library. module Common.Relation.Unary where infix 4 _∈_ _⊆_ ------------------------------------------------------------------------ -- Unary relations Pred : Set → Set₁ Pred A = A → Set _∈_ : ∀ {A} → A → Pred A → Set x ∈ P = P x -- P ⊆ Q means that P is a subset of Q. _⊆_ : ∀ {A} → Pred A → Pred A → Set P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
{ "alphanum_fraction": 0.3697478992, "avg_line_length": 26.4444444444, "ext": "agda", "hexsha": "4560accfd883dac3e48135414b498543f23008ee", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/Common/Relation/Unary.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/Common/Relation/Unary.agda", "max_line_length": 72, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/Common/Relation/Unary.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 169, "size": 714 }
open import Prelude open import Nat module contexts where -- variables are named with naturals in ė. therefore we represent -- contexts as functions from names for variables (nats) to possible -- bindings. _ctx : Set → Set A ctx = Nat → Maybe A -- convenient shorthand for the (unique up to fun. ext.) empty context ∅ : {A : Set} → A ctx ∅ _ = None infixr 100 ■_ -- the domain of a context is those naturals which cuase it to emit some τ dom : {A : Set} → A ctx → Nat → Set dom {A} Γ x = Σ[ τ ∈ A ] (Γ x == Some τ) -- membership, or presence, in a context _∈_ : {A : Set} (p : Nat × A) → (Γ : A ctx) → Set (x , y) ∈ Γ = (Γ x) == Some y -- this packages up an appeal to context memebership into a form that -- lets us retain more information ctxindirect : {A : Set} (Γ : A ctx) (n : Nat) → Σ[ a ∈ A ] (Γ n == Some a) + (Γ n == None) ctxindirect Γ n with Γ n ctxindirect Γ n | Some x = Inl (x , refl) ctxindirect Γ n | None = Inr refl -- apartness for contexts _#_ : {A : Set} (n : Nat) → (Γ : A ctx) → Set x # Γ = (Γ x) == None -- disjoint contexts are those which share no mappings _##_ : {A : Set} → A ctx → A ctx → Set _##_ {A} Γ Γ' = ((n : Nat) → dom Γ n → n # Γ') × ((n : Nat) → dom Γ' n → n # Γ) -- contexts give at most one binding for each variable ctxunicity : {A : Set} → {Γ : A ctx} {n : Nat} {t t' : A} → (n , t) ∈ Γ → (n , t') ∈ Γ → t == t' ctxunicity {n = n} p q with natEQ n n ctxunicity p q | Inl refl = someinj (! p · q) ctxunicity _ _ | Inr x≠x = abort (x≠x refl) -- warning: this is union, but it assumes WITHOUT CHECKING that the -- domains are disjoint. this is inherently asymmetric, and that's -- reflected throughout the development that follows _∪_ : {A : Set} → A ctx → A ctx → A ctx (C1 ∪ C2) x with C1 x (C1 ∪ C2) x | Some x₁ = Some x₁ (C1 ∪ C2) x | None = C2 x -- the singleton context ■_ : {A : Set} → (Nat × A) → A ctx (■ (x , a)) y with natEQ x y (■ (x , a)) .x | Inl refl = Some a ... | Inr _ = None -- context extension -- Note that if x is not apart from Γ, this relies on the asymmetry -- of union to set Γ x = t. _,,_ : {A : Set} → A ctx → (Nat × A) → A ctx (Γ ,, (x , t)) = (■ (x , t)) ∪ Γ infixl 10 _,,_ extend-empty : {A : Set} (x : Nat) (t : A) → ∅ ,, (x , t) == ■ (x , t) extend-empty x t = funext eq where eq : (y : Nat) → (∅ ,, (x , t)) y == (■ (x , t)) y eq y with natEQ x y ... | Inl refl = refl ... | Inr x≠y = refl -- used below in proof of ∪ commutativity and associativity lem-dom-union1 : {A : Set} {C1 C2 : A ctx} {x : Nat} → C1 ## C2 → dom C1 x → (C1 ∪ C2) x == C1 x lem-dom-union1 {A} {C1} {C2} {x} (d1 , d2) D with C1 x lem-dom-union1 (d1 , d2) D | Some x₁ = refl lem-dom-union1 (d1 , d2) D | None = abort (somenotnone (! (π2 D))) lem-dom-union2 : {A : Set} {C1 C2 : A ctx} {x : Nat} → C1 ## C2 → dom C1 x → (C2 ∪ C1) x == C1 x lem-dom-union2 {A} {C1} {C2} {x} (d1 , d2) D with ctxindirect C2 x lem-dom-union2 {A} {C1} {C2} {x} (d1 , d2) D | Inl x₁ = abort (somenotnone (! (π2 x₁) · d1 x D )) lem-dom-union2 {A} {C1} {C2} {x} (d1 , d2) D | Inr x₁ with C2 x lem-dom-union2 (d1 , d2) D | Inr x₂ | Some x₁ = abort (somenotnone x₂) lem-dom-union2 (d1 , d2) D | Inr x₁ | None = refl -- if the contexts in question are disjoint, then union is commutative ∪comm : {A : Set} → (C1 C2 : A ctx) → C1 ## C2 → (C1 ∪ C2) == (C2 ∪ C1) ∪comm C1 C2 (d1 , d2)= funext guts where lem-apart-union1 : {A : Set} (C1 C2 : A ctx) (x : Nat) → x # C1 → x # C2 → x # (C1 ∪ C2) lem-apart-union1 C1 C2 x apt1 apt2 with C1 x lem-apart-union1 C1 C2 x apt1 apt2 | Some x₁ = abort (somenotnone apt1) lem-apart-union1 C1 C2 x apt1 apt2 | None = apt2 lem-apart-union2 : {A : Set} (C1 C2 : A ctx) (x : Nat) → x # C1 → x # C2 → x # (C2 ∪ C1) lem-apart-union2 C1 C2 x apt1 apt2 with C2 x lem-apart-union2 C1 C2 x apt1 apt2 | Some x₁ = abort (somenotnone apt2) lem-apart-union2 C1 C2 x apt1 apt2 | None = apt1 guts : (x : Nat) → (C1 ∪ C2) x == (C2 ∪ C1) x guts x with ctxindirect C1 x | ctxindirect C2 x guts x | Inl (π1 , π2) | Inl (π3 , π4) = abort (somenotnone (! π4 · d1 x (π1 , π2))) guts x | Inl x₁ | Inr x₂ = tr (λ qq → qq == (C2 ∪ C1) x) (! (lem-dom-union1 (d1 , d2) x₁)) (tr (λ qq → C1 x == qq) (! (lem-dom-union2 (d1 , d2) x₁)) refl) guts x | Inr x₁ | Inl x₂ = tr (λ qq → (C1 ∪ C2) x == qq) (! (lem-dom-union1 (d2 , d1) x₂)) (tr (λ qq → qq == C2 x) (! (lem-dom-union2 (d2 , d1) x₂)) refl) guts x | Inr x₁ | Inr x₂ = tr (λ qq → qq == (C2 ∪ C1) x) (! (lem-apart-union1 C1 C2 x x₁ x₂)) (tr (λ qq → None == qq) (! (lem-apart-union2 C1 C2 x x₁ x₂)) refl) -- an element in the left of a union is in the union x∈∪l : {A : Set} → (Γ Γ' : A ctx) (n : Nat) (x : A) → (n , x) ∈ Γ → (n , x) ∈ (Γ ∪ Γ') x∈∪l Γ Γ' n x xin with Γ n x∈∪l Γ Γ' n x₁ xin | Some x = xin x∈∪l Γ Γ' n x () | None -- an element in the right of a union is in the union as long as it is not in the left; -- this asymmetry reflects the asymmetry in the definition of union x∈∪r : {A : Set} → (Γ Γ' : A ctx) (n : Nat) (x : A) → (n , x) ∈ Γ' → n # Γ → (n , x) ∈ (Γ ∪ Γ') x∈∪r Γ Γ' n x nx∈ apt with Γ n ... | None = nx∈ -- an element is in the context formed with just itself x∈■ : {A : Set} (n : Nat) (a : A) → (n , a) ∈ (■ (n , a)) x∈■ n a with natEQ n n x∈■ n a | Inl refl = refl x∈■ n a | Inr x = abort (x refl) -- if an index is in the domain of a singleton context, it's the only -- index in the context lem-dom-eq : {A : Set} {y : A} {n m : Nat} → dom (■ (m , y)) n → n == m lem-dom-eq {n = n} {m = m} (π1 , π2) with natEQ m n lem-dom-eq (π1 , π2) | Inl refl = refl lem-dom-eq (π1 , π2) | Inr x = abort (somenotnone (! π2)) -- a singleton context formed with an index apart from a context is -- disjoint from that context lem-apart-sing-disj : {A : Set} {n : Nat} {a : A} {Γ : A ctx} → n # Γ → (■ (n , a)) ## Γ lem-apart-sing-disj {A} {n} {a} {Γ} apt = asd1 , asd2 where asd1 : (n₁ : Nat) → dom (■ (n , a)) n₁ → n₁ # Γ asd1 m d with lem-dom-eq d asd1 .n d | refl = apt asd2 : (n₁ : Nat) → dom Γ n₁ → n₁ # (■ (n , a)) asd2 m (π1 , π2) with natEQ n m asd2 .n (π1 , π2) | Inl refl = abort (somenotnone (! π2 · apt )) asd2 m (π1 , π2) | Inr x = refl -- the only index of a singleton context is in its domain lem-domsingle : {A : Set} (p : Nat) (q : A) → dom (■ (p , q)) p lem-domsingle p q with natEQ p p lem-domsingle p q | Inl refl = q , refl lem-domsingle p q | Inr x₁ = abort (x₁ refl) -- dual of above lem-disj-sing-apart : {A : Set} {n : Nat} {a : A} {Γ : A ctx} → (■ (n , a)) ## Γ → n # Γ lem-disj-sing-apart {A} {n} {a} {Γ} (d1 , d2) = d1 n (lem-domsingle n a) -- the singleton context can only produce one non-none result lem-insingeq : {A : Set} {x x' : Nat} {τ τ' : A} → (■ (x , τ)) x' == Some τ' → τ == τ' lem-insingeq {A} {x} {x'} {τ} {τ'} eq with lem-dom-eq (τ' , eq) lem-insingeq {A} {x} {.x} {τ} {τ'} eq | refl with natEQ x x lem-insingeq refl | refl | Inl refl = refl lem-insingeq eq | refl | Inr x₁ = abort (somenotnone (! eq)) -- if an index doesn't appear in a context, and the union of that context -- with a singleton does produce a result, it must have come from the singleton lem-apart-union-eq : {A : Set} {Γ : A ctx} {x x' : Nat} {τ τ' : A} → x' # Γ → (Γ ∪ ■ (x , τ)) x' == Some τ' → τ == τ' lem-apart-union-eq {A} {Γ} {x} {x'} {τ} {τ'} apart eq with Γ x' lem-apart-union-eq apart eq | Some x = abort (somenotnone apart) lem-apart-union-eq apart eq | None = lem-insingeq eq -- if an index not in a singleton context produces a result from that -- singleton unioned with another context, the result must have come from -- the other context lem-neq-union-eq : {A : Set} {Γ : A ctx} {x x' : Nat} {τ τ' : A} → x' ≠ x → (Γ ∪ ■ (x , τ)) x' == Some τ' → Γ x' == Some τ' lem-neq-union-eq {A} {Γ} {x} {x'} {τ} {τ'} neq eq with Γ x' lem-neq-union-eq neq eq | Some x = eq lem-neq-union-eq {A} {Γ} {x} {x'} {τ} {τ'} neq eq | None with natEQ x x' lem-neq-union-eq neq eq | None | Inl x₁ = abort ((flip neq) x₁) lem-neq-union-eq neq eq | None | Inr x₁ = abort (somenotnone (! eq)) -- extending a context with a new index produces the result paired with -- that index. ctx-top : {A : Set} → (Γ : A ctx) (n : Nat) (a : A) → (n # Γ) → (n , a) ∈ (Γ ,, (n , a)) ctx-top Γ n a apt with natEQ n n ... | Inl refl = refl ... | Inr n≠n = abort (n≠n refl) -- if a union of a singleton and a ctx produces no result, the argument -- index must be apart from the ctx and disequal to the index of the -- singleton lem-union-none : {A : Set} {Γ : A ctx} {a : A} {x x' : Nat} → (Γ ∪ ■ (x , a)) x' == None → (x ≠ x') × (x' # Γ) lem-union-none {A} {Γ} {a} {x} {x'} emp with ctxindirect Γ x' lem-union-none {A} {Γ} {a} {x} {x'} emp | Inl (π1 , π2) with Γ x' lem-union-none emp | Inl (π1 , π2) | Some x = abort (somenotnone emp) lem-union-none {A} {Γ} {a} {x} {x'} emp | Inl (π1 , π2) | None with natEQ x x' lem-union-none emp | Inl (π1 , π2) | None | Inl x₁ = abort (somenotnone (! π2)) lem-union-none emp | Inl (π1 , π2) | None | Inr x₁ = x₁ , refl lem-union-none {A} {Γ} {a} {x} {x'} emp | Inr y with Γ x' lem-union-none emp | Inr y | Some x = abort (somenotnone emp) lem-union-none {A} {Γ} {a} {x} {x'} emp | Inr y | None with natEQ x x' lem-union-none emp | Inr y | None | Inl refl = abort (somenotnone emp) lem-union-none emp | Inr y | None | Inr x₁ = x₁ , refl --- lemmas building up to a proof of associativity of ∪ ctxignore1 : {A : Set} (x : Nat) (C1 C2 : A ctx) → x # C1 → (C1 ∪ C2) x == C2 x ctxignore1 x C1 C2 apt with ctxindirect C1 x ctxignore1 x C1 C2 apt | Inl x₁ = abort (somenotnone (! (π2 x₁) · apt)) ctxignore1 x C1 C2 apt | Inr x₁ with C1 x ctxignore1 x C1 C2 apt | Inr x₂ | Some x₁ = abort (somenotnone (x₂)) ctxignore1 x C1 C2 apt | Inr x₁ | None = refl ctxignore2 : {A : Set} (x : Nat) (C1 C2 : A ctx) → x # C2 → (C1 ∪ C2) x == C1 x ctxignore2 x C1 C2 apt with ctxindirect C2 x ctxignore2 x C1 C2 apt | Inl x₁ = abort (somenotnone (! (π2 x₁) · apt)) ctxignore2 x C1 C2 apt | Inr x₁ with C1 x ctxignore2 x C1 C2 apt | Inr x₂ | Some x₁ = refl ctxignore2 x C1 C2 apt | Inr x₁ | None = x₁ ctxcollapse1 : {A : Set} → (C1 C2 C3 : A ctx) (x : Nat) → (x # C3) → (C2 ∪ C3) x == C2 x → (C1 ∪ (C2 ∪ C3)) x == (C1 ∪ C2) x ctxcollapse1 C1 C2 C3 x apt eq with C2 x ctxcollapse1 C1 C2 C3 x apt eq | Some x₁ with C1 x ctxcollapse1 C1 C2 C3 x apt eq | Some x₂ | Some x₁ = refl ctxcollapse1 C1 C2 C3 x apt eq | Some x₁ | None with C2 x ctxcollapse1 C1 C2 C3 x apt eq | Some x₂ | None | Some x₁ = refl ctxcollapse1 C1 C2 C3 x apt eq | Some x₁ | None | None = apt ctxcollapse1 C1 C2 C3 x apt eq | None with C1 x ctxcollapse1 C1 C2 C3 x apt eq | None | Some x₁ = refl ctxcollapse1 C1 C2 C3 x apt eq | None | None with C2 x ctxcollapse1 C1 C2 C3 x apt eq | None | None | Some x₁ = refl ctxcollapse1 C1 C2 C3 x apt eq | None | None | None = eq ctxcollapse2 : {A : Set} → (C1 C2 C3 : A ctx) (x : Nat) → (x # C2) → (C2 ∪ C3) x == C3 x → (C1 ∪ (C2 ∪ C3)) x == (C1 ∪ C3) x ctxcollapse2 C1 C2 C3 x apt eq with C1 x ctxcollapse2 C1 C2 C3 x apt eq | Some x₁ = refl ctxcollapse2 C1 C2 C3 x apt eq | None with C2 x ctxcollapse2 C1 C2 C3 x apt eq | None | Some x₁ = eq ctxcollapse2 C1 C2 C3 x apt eq | None | None = refl ctxcollapse3 : {A : Set} → (C1 C2 C3 : A ctx) (x : Nat) → (x # C2) → ((C1 ∪ C2) ∪ C3) x == (C1 ∪ C3) x ctxcollapse3 C1 C2 C3 x apt with C1 x ctxcollapse3 C1 C2 C3 x apt | Some x₁ = refl ctxcollapse3 C1 C2 C3 x apt | None with C2 x ctxcollapse3 C1 C2 C3 x apt | None | Some x₁ = abort (somenotnone apt) ctxcollapse3 C1 C2 C3 x apt | None | None = refl ∪assoc : {A : Set} (C1 C2 C3 : A ctx) → (C2 ## C3) → (C1 ∪ C2) ∪ C3 == C1 ∪ (C2 ∪ C3) ∪assoc C1 C2 C3 (d1 , d2) = funext guts where case2 : (x : Nat) → x # C3 → dom C2 x → ((C1 ∪ C2) ∪ C3) x == (C1 ∪ (C2 ∪ C3)) x case2 x apt dom = (ctxignore2 x (C1 ∪ C2) C3 apt) · ! (ctxcollapse1 C1 C2 C3 x apt (lem-dom-union1 (d1 , d2) dom)) case34 : (x : Nat) → x # C2 → ((C1 ∪ C2) ∪ C3) x == (C1 ∪ (C2 ∪ C3)) x case34 x apt = ctxcollapse3 C1 C2 C3 x apt · ! (ctxcollapse2 C1 C2 C3 x apt (ctxignore1 x C2 C3 apt)) guts : (x : Nat) → ((C1 ∪ C2) ∪ C3) x == (C1 ∪ (C2 ∪ C3)) x guts x with ctxindirect C2 x | ctxindirect C3 x guts x | Inl (π1 , π2) | Inl (π3 , π4) = abort (somenotnone (! π4 · d1 x (π1 , π2))) guts x | Inl x₁ | Inr x₂ = case2 x x₂ x₁ guts x | Inr x₁ | Inl x₂ = case34 x x₁ guts x | Inr x₁ | Inr x₂ = case34 x x₁ -- if x is apart from either part of a union, the answer comes from the other one lem-dom-union-apt1 : {A : Set} {Δ1 Δ2 : A ctx} {x : Nat} {y : A} → x # Δ1 → ((Δ1 ∪ Δ2) x == Some y) → (Δ2 x == Some y) lem-dom-union-apt1 {A} {Δ1} {Δ2} {x} {y} apt xin with Δ1 x lem-dom-union-apt1 apt xin | Some x₁ = abort (somenotnone apt) lem-dom-union-apt1 apt xin | None = xin lem-dom-union-apt2 : {A : Set} {Δ1 Δ2 : A ctx} {x : Nat} {y : A} → x # Δ2 → ((Δ1 ∪ Δ2) x == Some y) → (Δ1 x == Some y) lem-dom-union-apt2 {A} {Δ1} {Δ2} {x} {y} apt xin with Δ1 x lem-dom-union-apt2 apt xin | Some x₁ = xin lem-dom-union-apt2 apt xin | None = abort (somenotnone (! xin · apt)) -- if x is in the union , it is in one of the parts lem-dom-union : {A : Set} {Δ1 Δ2 : A ctx} {x : Nat} {y : A} → (x , y) ∈ (Δ1 ∪ Δ2) → ((x , y) ∈ Δ1) + ((x , y) ∈ Δ2) lem-dom-union {Δ1 = Δ1} {Δ2 = Δ2} {x = x} ∈∪ with Δ1 x ... | Some x₁ = Inl ∈∪ ... | None = Inr ∈∪ update : {A : Set} (Γ : A ctx) (x : Nat) (τ1 τ2 : A) → Γ ,, (x , τ1) ,, (x , τ2) == Γ ,, (x , τ2) update Γ x τ1 τ2 = funext eq where eq : (y : Nat) → (Γ ,, (x , τ1) ,, (x , τ2)) y == (Γ ,, (x , τ2)) y eq y with natEQ x y ... | Inl refl = refl ... | Inr x≠y with natEQ x y ... | Inl refl = abort (x≠y refl) ... | Inr x≠y' = refl
{ "alphanum_fraction": 0.5153398572, "avg_line_length": 45.0119047619, "ext": "agda", "hexsha": "8d53ee4eb72d006fb1379ef5acce353fb2c30209", "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": "contexts.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": "contexts.agda", "max_line_length": 166, "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": "contexts.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6152, "size": 15124 }
{-# OPTIONS --cubical --safe #-} open import Algebra module Algebra.Construct.OrderedMonoid {ℓ} (monoid : Monoid ℓ) where open import Prelude open import Relation.Binary open import Path.Reasoning open Monoid monoid infix 4 _≤_ _≥_ _<_ _>_ _≤_ : 𝑆 → 𝑆 → Type ℓ x ≤ y = ∃ z × (y ≡ x ∙ z) _<_ : 𝑆 → 𝑆 → Type ℓ x < y = ∃ z × (z ≢ ε) × (y ≡ x ∙ z) _>_ = flip _<_ _≥_ = flip _≤_ ≤-refl : Reflexive _≤_ ≤-refl = ε , sym (∙ε _) ≤-trans : Transitive _≤_ ≤-trans {x} {y} {z} (k₁ , y≡x∙k₁) (k₂ , z≡y∙k₂) = k₁ ∙ k₂ ,_ $ z ≡⟨ z≡y∙k₂ ⟩ y ∙ k₂ ≡⟨ cong (_∙ k₂) y≡x∙k₁ ⟩ (x ∙ k₁) ∙ k₂ ≡⟨ assoc x k₁ k₂ ⟩ x ∙ (k₁ ∙ k₂) ∎ ε≤x : ∀ x → ε ≤ x ε≤x x = x , sym (ε∙ x) ∙-cong : ∀ x {y z} → y ≤ z → x ∙ y ≤ x ∙ z ∙-cong x (k , z≡y∙k) = k , cong (x ∙_) z≡y∙k ; sym (assoc x _ k) -- Trichotomous : Type _ -- Trichotomous = (x y : 𝑆) → Tri _<_ _≡_ _>_ x y
{ "alphanum_fraction": 0.5153301887, "avg_line_length": 20.6829268293, "ext": "agda", "hexsha": "086b3d2deaec1087a76e4e52a6f1461ea7886468", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Algebra/Construct/OrderedMonoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Algebra/Construct/OrderedMonoid.agda", "max_line_length": 68, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Algebra/Construct/OrderedMonoid.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 470, "size": 848 }
{-# OPTIONS --without-K #-} open import lib.Basics module lib.types.Empty where ⊥ = Empty ⊥-elim : ∀ {i} {A : ⊥ → Type i} → ((x : ⊥) → A x) ⊥-elim = Empty-elim Empty-rec : ∀ {i} {A : Type i} → (Empty → A) Empty-rec = Empty-elim ⊥-rec : ∀ {i} {A : Type i} → (⊥ → A) ⊥-rec = Empty-rec Empty-is-prop : is-prop Empty Empty-is-prop = Empty-elim ⊥-is-prop : is-prop ⊥ ⊥-is-prop = Empty-is-prop
{ "alphanum_fraction": 0.5580808081, "avg_line_length": 17.2173913043, "ext": "agda", "hexsha": "3f8f1534b1b0059942b4105c5fe509afad3c1903", "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": "lib/types/Empty.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": "lib/types/Empty.agda", "max_line_length": 49, "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": "lib/types/Empty.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 162, "size": 396 }
module UnequalSorts where data One : Set where one : One data One' : Set1 where one' : One' err : One err = one'
{ "alphanum_fraction": 0.6554621849, "avg_line_length": 11.9, "ext": "agda", "hexsha": "310dff09c69121a8929557ecdbb3d472c1e5fa27", "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/UnequalSorts.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/UnequalSorts.agda", "max_line_length": 34, "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/UnequalSorts.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": 39, "size": 119 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Functor.Bifunctor module Categories.Diagram.Wedge {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F : Bifunctor (Category.op C) C D) where private module C = Category C module D = Category D open D open HomReasoning variable A : Obj open import Level open import Categories.Functor hiding (id) open import Categories.Functor.Construction.Constant open import Categories.NaturalTransformation.Dinatural open Functor F record Wedge : Set (levelOfTerm F) where field E : Obj dinatural : DinaturalTransformation (const E) F module dinatural = DinaturalTransformation dinatural Wedge-∘ : (W : Wedge) → A ⇒ Wedge.E W → Wedge Wedge-∘ {A = A} W f = record { E = A ; dinatural = extranaturalʳ (λ X → dinatural.α X ∘ f) (sym-assoc ○ ∘-resp-≈ˡ (extranatural-commʳ dinatural) ○ assoc) } where open Wedge W record Wedge-Morphism (W₁ W₂ : Wedge) : Set (levelOfTerm F) where private module W₁ = Wedge W₁ module W₂ = Wedge W₂ open DinaturalTransformation field u : W₁.E ⇒ W₂.E commute : ∀ {C} → W₂.dinatural.α C ∘ u ≈ W₁.dinatural.α C Wedge-id : ∀ {W} → Wedge-Morphism W W Wedge-id {W} = record { u = D.id ; commute = D.identityʳ } Wedge-Morphism-∘ : {A B C : Wedge} → Wedge-Morphism B C → Wedge-Morphism A B → Wedge-Morphism A C Wedge-Morphism-∘ M N = record { u = u M ∘ u N ; commute = sym-assoc ○ (∘-resp-≈ˡ (commute M) ○ commute N) } where open Wedge-Morphism open HomReasoning
{ "alphanum_fraction": 0.6547619048, "avg_line_length": 28, "ext": "agda", "hexsha": "d28a452b7fcd39d84fa0b603f140c27dce27abb7", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Diagram/Wedge.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Diagram/Wedge.agda", "max_line_length": 108, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Diagram/Wedge.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 545, "size": 1596 }
-- Andreas, 2016-10-11, AIM XXIV, issue #2248 -- COMPILED_TYPE should only work on postulates data Unit : Set where unit : Unit postulate IO : Set → Set {-# BUILTIN IO IO #-} {-# COMPILE GHC IO = type IO #-} abstract IO' : Set → Set IO' A = A doNothing : IO' Unit doNothing = unit {-# COMPILE GHC IO' = type IO #-} postulate toIO : {A : Set} → IO' A → IO A {-# COMPILE GHC toIO = \ _ x -> x #-} main : IO Unit main = toIO doNothing
{ "alphanum_fraction": 0.6, "avg_line_length": 15.6896551724, "ext": "agda", "hexsha": "ecbdc6366e70c1bd009387178b10a61c046f1075", "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": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Blaisorblade/Agda", "max_forks_repo_path": "test/Fail/Issue2248_COMPILED_TYPE.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "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": "Blaisorblade/Agda", "max_issues_repo_path": "test/Fail/Issue2248_COMPILED_TYPE.agda", "max_line_length": 47, "max_stars_count": 3, "max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "Blaisorblade/Agda", "max_stars_repo_path": "test/Fail/Issue2248_COMPILED_TYPE.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": 154, "size": 455 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Naturals open import Numbers.Naturals.EuclideanAlgorithm open import Semirings.Definition open import Orders.Total.Definition module Numbers.Modulo.ModuloFunction where open TotalOrder ℕTotalOrder private notBigger : (a : ℕ) {n : ℕ} → succ a +N n ≡ a → False notBigger (succ a) {n} pr = notBigger a {n} (succInjective pr) notBigger' : (a : ℕ) {n : ℕ} → succ a +N n ≡ n → False notBigger' (succ a) {succ n} pr rewrite Semiring.commutative ℕSemiring a (succ n) | Semiring.commutative ℕSemiring n a = notBigger' _ (succInjective pr) mod : (n : ℕ) → .(pr : 0 <N n) → (a : ℕ) → ℕ mod (succ n) 0<n a = divisionAlgResult.rem (divisionAlg (succ n) a) abstract modIsMod : {n : ℕ} → .(pr : 0 <N n) → (a : ℕ) → a <N n → mod n pr a ≡ a modIsMod {succ n} 0<n a a<n with divisionAlg (succ n) a modIsMod {succ n} 0<n a a<n | record { quot = zero ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } rewrite multiplicationNIsCommutative n 0 = pr modIsMod {succ n} 0<n a (le x proof) | record { quot = succ quot ; rem = rem ; pr = pr ; remIsSmall = inl rem<sn ; quotSmall = quotSmall } = exFalso (notBigger a v) where t : ((succ (a +N x)) *N succ quot) +N rem ≡ a t rewrite Semiring.commutative ℕSemiring a x = transitivity (applyEquality (λ i → (i *N succ quot) +N rem) proof) pr u : (succ quot *N succ (a +N x)) +N rem ≡ a u = transitivity (applyEquality (_+N rem) (multiplicationNIsCommutative (succ quot) _)) t v : succ a +N ((x +N quot *N succ (a +N x)) +N rem) ≡ a v = transitivity (applyEquality succ (transitivity (Semiring.+Associative ℕSemiring a _ rem) (applyEquality (_+N rem) (Semiring.+Associative ℕSemiring a x _)))) u mod<N : {n : ℕ} → .(pr : 0 <N n) → (a : ℕ) → (mod n pr a) <N n mod<N {succ n} pr a with divisionAlg (succ n) a mod<N {succ n} 0<n a | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x ; quotSmall = quotSmall } = x modIdempotent : {n : ℕ} → .(pr : 0 <N n) → (a : ℕ) → mod n pr (mod n pr a) ≡ mod n pr a modIdempotent 0<n a = modIsMod 0<n (mod _ 0<n a) (mod<N 0<n a) modAnd+n : {n : ℕ} → .(pr : 0 <N n) → (a : ℕ) → mod n pr (n +N a) ≡ mod n pr a modAnd+n {succ n} 0<sn a with divisionAlg (succ n) (succ n +N a) modAnd+n {succ n} 0<sn a | record { quot = 0 ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl q } rewrite multiplicationNIsCommutative n 0 | pr = exFalso (notBigger (succ n) (transitivity (applyEquality succ (transitivity (applyEquality succ (Semiring.+Associative ℕSemiring n a _)) (Semiring.commutative ℕSemiring (succ (n +N a)) _))) (_<N_.proof remIsSmall))) modAnd+n {succ n} 0<sn a | record { quot = succ quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl q } = modIsUnique (record { quot = quot ; rem = rem ; pr = t ; remIsSmall = inl remIsSmall ; quotSmall = inl q }) (divisionAlg (succ n) a) where g : succ n +N ((quot *N succ n) +N rem) ≡ succ n +N a g = transitivity (Semiring.+Associative ℕSemiring (succ n) _ rem) (transitivity (applyEquality (_+N rem) (multiplicationNIsCommutative (succ quot) _)) pr) h : (quot *N succ n) +N rem ≡ a h = canSubtractFromEqualityLeft g t : (succ n *N quot) +N rem ≡ a t = transitivity (applyEquality (_+N rem) (multiplicationNIsCommutative (succ n) quot)) h modExtracts : {n : ℕ} → .(pr : 0 <N n) → (a b : ℕ) → mod n pr (a +N b) ≡ mod n pr (mod n pr a +N mod n pr b) modExtracts {succ n} 0<sn a b with divisionAlg (succ n) a modExtracts {succ n} 0<sn a b | record { quot = sn/a ; rem = sn%a ; pr = prA ; remIsSmall = remIsSmallA ; quotSmall = quotSmallA } with divisionAlg (succ n) b modExtracts {succ n} 0<sn a b | record { quot = sn/a ; rem = sn%a ; pr = prA ; remIsSmall = remIsSmallA ; quotSmall = quotSmallA } | record { quot = sn/b ; rem = sn%b ; pr = prB ; remIsSmall = remIsSmallB ; quotSmall = quotSmallB } with divisionAlg (succ n) (a +N b) modExtracts {succ n} 0<sn a b | record { quot = sn/a ; rem = sn%a ; pr = prA ; remIsSmall = remIsSmallA ; quotSmall = quotSmallA } | record { quot = sn/b ; rem = sn%b ; pr = prB ; remIsSmall = remIsSmallB ; quotSmall = quotSmallB } | record { quot = sn/a+b ; rem = sn%a+b ; pr = prA+B ; remIsSmall = remIsSmallA+B ; quotSmall = quotSmallA+B } with divisionAlg (succ n) (sn%a +N sn%b) modExtracts {succ n} 0<sn a b | record { quot = sn/a ; rem = sn%a ; pr = prA ; remIsSmall = inl sn%a<sn ; quotSmall = inl _ } | record { quot = sn/b ; rem = sn%b ; pr = prB ; remIsSmall = inl sn%b<sn ; quotSmall = inl _ } | record { quot = sn/a+b ; rem = sn%a+b ; pr = prA+B ; remIsSmall = inl sn%a+b<sn ; quotSmall = inl _ } | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = inl _ } = equalityCommutative whoa where t : ((succ n *N sn/a) +N sn%a) +N ((succ n *N sn/b) +N sn%b) ≡ a +N b t = +NWellDefined prA prB t' : (succ n *N (sn/a +N sn/b)) +N (sn%a +N sn%b) ≡ a +N b t' = transitivity (transitivity (Semiring.+Associative ℕSemiring (succ n *N (sn/a +N sn/b)) sn%a sn%b) (transitivity (applyEquality (_+N sn%b) (transitivity (transitivity (applyEquality (_+N sn%a) (transitivity (applyEquality (succ n *N_) (Semiring.commutative ℕSemiring sn/a sn/b)) (Semiring.+DistributesOver* ℕSemiring (succ n) sn/b sn/a))) (equalityCommutative (Semiring.+Associative ℕSemiring (succ n *N sn/b) (succ n *N sn/a) sn%a))) (Semiring.commutative ℕSemiring (succ n *N sn/b) ((succ n *N sn/a) +N sn%a)))) (equalityCommutative (Semiring.+Associative ℕSemiring ((succ n *N sn/a) +N sn%a) (succ n *N sn/b) sn%b)))) t thing : ((succ n) *N quot) +N rem ≡ sn%a +N sn%b thing = pr t'' : (succ n *N ((sn/a +N sn/b) +N quot)) +N rem ≡ a +N b t'' rewrite Semiring.+DistributesOver* ℕSemiring (succ n) (sn/a +N sn/b) quot | equalityCommutative (Semiring.+Associative ℕSemiring (succ n *N (sn/a +N sn/b)) (succ n *N quot) rem) | thing = t' whoa : rem ≡ sn%a+b whoa = modUniqueLemma _ _ remIsSmall sn%a+b<sn (transitivity t'' (equalityCommutative prA+B)) modAddition : {n : ℕ} → .(pr : 0 <N n) → {a b : ℕ} → (a <N n) → (b <N n) → (a +N b ≡ mod n pr (a +N b)) || (a +N b ≡ n +N mod n pr (a +N b)) modAddition {succ n} 0<sn {a} {b} a<n b<n with divisionAlg (succ n) (a +N b) modAddition {succ n} 0<sn {a} {b} a<n b<n | record { quot = zero ; rem = rem ; pr = pr ; remIsSmall = inl rem<sn ; quotSmall = inl _ } = inl (equalityCommutative (transitivity (applyEquality (_+N rem) (multiplicationNIsCommutative 0 n)) pr)) modAddition {succ n} 0<sn {a} {b} a<n b<n | record { quot = succ zero ; rem = rem ; pr = pr ; remIsSmall = inl rem<sn ; quotSmall = inl _ } = inr (transitivity (equalityCommutative pr) (applyEquality (λ i → succ i +N rem) (transitivity (multiplicationNIsCommutative n 1) (Semiring.sumZeroRight ℕSemiring n)))) modAddition {succ n} 0<sn {a} {b} (le x prA) (le y prB) | record { quot = succ (succ quot) ; rem = 0 ; pr = pr ; remIsSmall = inl rem<sn ; quotSmall = inl _ } rewrite Semiring.sumZeroRight ℕSemiring (succ n *N succ (succ quot)) | multiplicationNIsCommutative (succ n) (succ (succ quot)) = exFalso (notBigger' ((x +N succ y) +N (quot *N succ n)) u) where t : ((succ x +N a) +N succ (y +N b)) +N (quot *N succ n) ≡ a +N b t = transitivity (transitivity (applyEquality (_+N quot *N succ n) (+NWellDefined prA prB)) (equalityCommutative (Semiring.+Associative ℕSemiring (succ n) (succ n) (quot *N succ n)))) pr u : ((succ x +N succ y) +N (quot *N succ n)) +N (a +N b) ≡ a +N b u rewrite Semiring.commutative ℕSemiring ((x +N succ y) +N quot *N succ n) (a +N b) | Semiring.+Associative ℕSemiring (succ a +N b) (x +N succ y) (quot *N succ n) = transitivity (applyEquality (λ i → succ i +N quot *N succ n) (transitivity (Semiring.commutative ℕSemiring (a +N b) _) (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring x (succ y) _)) (transitivity (applyEquality (x +N_) (transitivity (Semiring.+Associative ℕSemiring (succ y) a b) (transitivity (applyEquality (_+N b) (Semiring.commutative ℕSemiring _ a)) (equalityCommutative (Semiring.+Associative ℕSemiring a (succ y) b))))) (Semiring.+Associative ℕSemiring x a _))))) t modAddition {succ n} 0<sn {a} {b} a<n b<n | record { quot = succ (succ quot) ; rem = succ rem ; pr = pr ; remIsSmall = inl rem<sn ; quotSmall = inl _ } = exFalso (irreflexive (<Transitive u t)) where t : (succ n *N succ (succ quot) +N succ rem) <N succ n +N succ n t = identityOfIndiscernablesLeft _<N_ (addStrongInequalities a<n b<n) (equalityCommutative pr) lemm : {a c d : ℕ} → (a +N a) <N (a *N succ (succ c)) +N succ d lemm {a} {c} {d} = le (a *N c +N d) f where f : succ ((a *N c +N d) +N (a +N a)) ≡ a *N succ (succ c) +N succ d f rewrite multiplicationNIsCommutative a (succ (succ c)) | Semiring.+Associative ℕSemiring a a (c *N a) | multiplicationNIsCommutative c a | Semiring.commutative ℕSemiring (a *N c +N d) (a +N a) | Semiring.+Associative ℕSemiring (a +N a) (a *N c) d | Semiring.commutative ℕSemiring ((a +N a) +N a *N c) (succ d) = applyEquality succ (Semiring.commutative ℕSemiring _ d) u : (succ n +N succ n) <N (succ n *N succ (succ quot) +N succ rem) u = lemm {succ n} modN : {n : ℕ} → .(0<n : 0 <N n) → mod n 0<n n ≡ 0 modN {succ n} 0<n = modIsUnique (divisionAlg (succ n) (succ n)) record { quot = 1 ; rem = zero ; pr = ans ; remIsSmall = inl (le n (Semiring.sumZeroRight ℕSemiring (succ n))) ; quotSmall = inl (le n (Semiring.sumZeroRight ℕSemiring (succ n))) } where ans : succ (n *N 1 +N 0) ≡ succ n ans rewrite multiplicationNIsCommutative n 1 | Semiring.sumZeroRight ℕSemiring n | Semiring.sumZeroRight ℕSemiring n = refl
{ "alphanum_fraction": 0.6344292053, "avg_line_length": 97.2156862745, "ext": "agda", "hexsha": "85c817de037e614bf1448c8e893794c5287066c0", "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": "Numbers/Modulo/ModuloFunction.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": "Numbers/Modulo/ModuloFunction.agda", "max_line_length": 663, "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": "Numbers/Modulo/ModuloFunction.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": 3655, "size": 9916 }
-- 2011-09-15 by Nisse -- {-# OPTIONS -v tc.lhs.unify:15 #-} module Issue292-17 where data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ postulate I : Set U : I → Set El : ∀ {i} → U i → Set mutual infixl 5 _▻_ data Ctxt : Set where _▻_ : (Γ : Ctxt) (σ : Type Γ) → Ctxt Type : Ctxt → Set Type Γ = Σ I (λ i → Env Γ → U i) Env : Ctxt → Set Env (Γ ▻ σ) = Σ (Env Γ) λ γ → El (proj₂ σ γ) postulate Γ : Ctxt σ : Type Γ data D : Type (Γ ▻ σ) → Set where d : (τ : Type Γ) → D (proj₁ τ , λ γ → proj₂ τ (proj₁ γ)) record [D] : Set where constructor [d] field τ : Type (Γ ▻ σ) x : D τ Foo : {τ₁ τ₂ : Type Γ} → [d] (proj₁ τ₁ , λ γ → proj₂ τ₁ (proj₁ γ)) (d τ₁) ≡ [d] (proj₁ τ₂ , λ γ → proj₂ τ₂ (proj₁ γ)) (d τ₂) → Set₁ Foo refl = Set
{ "alphanum_fraction": 0.5098684211, "avg_line_length": 17.5384615385, "ext": "agda", "hexsha": "39c2a0f1de8bc4c184a47475c0076a4870c4ad89", "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/Issue292-17.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/Issue292-17.agda", "max_line_length": 58, "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/Issue292-17.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": 409, "size": 912 }
{-# OPTIONS --safe --cubical #-} module Prelude where open import Level public open import Data.Sigma public open import Function.Fiber public open import Data.Empty public open import Data.Unit public open import Data.Nat public using (ℕ; suc; zero) open import Data.Bool public using (Bool; true; false; bool; if_then_else_; T; _and_; _or_; not) open import Data.Maybe public using (Maybe; just; nothing) open import HITs.PropositionalTruncation public using (∥_∥; ∣_∣) open import Function.Surjective public using (Surjective; SplitSurjective; _↠!_; _↠_) open import Data.Pi public open import Function.Isomorphism public open import Path public open import Function public open import Relation.Nullary.Decidable public open import Relation.Nullary.Discrete public using (Discrete) open import Relation.Nullary.Discrete.Properties public using (Discrete→isSet) open import HLevels public open import Data.Sum public open import Equiv public open import Data.Lift public open import Function.Biconditional public open import Relation.Unary public open import Strict public open import Instance public
{ "alphanum_fraction": 0.802690583, "avg_line_length": 31.8571428571, "ext": "agda", "hexsha": "a9bd7aaf182d1eedd90a06d7854d83d7a6dd35f1", "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": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Prelude.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Prelude.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Prelude.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 275, "size": 1115 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Various forms of induction for natural numbers ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Nat.Induction where open import Function open import Data.Nat.Base open import Data.Nat.Properties using (≤⇒≤′) open import Data.Product open import Data.Unit open import Induction open import Induction.WellFounded as WF open import Level using (Lift) open import Relation.Binary.PropositionalEquality open import Relation.Unary ------------------------------------------------------------------------ -- Re-export accessability open WF public using (Acc; acc) ------------------------------------------------------------------------ -- Ordinary induction Rec : ∀ ℓ → RecStruct ℕ ℓ ℓ Rec ℓ P zero = Lift ℓ ⊤ Rec ℓ P (suc n) = P n recBuilder : ∀ {ℓ} → RecursorBuilder (Rec ℓ) recBuilder P f zero = _ recBuilder P f (suc n) = f n (recBuilder P f n) rec : ∀ {ℓ} → Recursor (Rec ℓ) rec = build recBuilder ------------------------------------------------------------------------ -- Complete induction CRec : ∀ ℓ → RecStruct ℕ ℓ ℓ CRec ℓ P zero = Lift ℓ ⊤ CRec ℓ P (suc n) = P n × CRec ℓ P n cRecBuilder : ∀ {ℓ} → RecursorBuilder (CRec ℓ) cRecBuilder P f zero = _ cRecBuilder P f (suc n) = f n ih , ih where ih = cRecBuilder P f n cRec : ∀ {ℓ} → Recursor (CRec ℓ) cRec = build cRecBuilder ------------------------------------------------------------------------ -- Complete induction based on _<′_ <′-Rec : ∀ {ℓ} → RecStruct ℕ ℓ ℓ <′-Rec = WfRec _<′_ mutual <′-wellFounded : WellFounded _<′_ <′-wellFounded n = acc (<′-wellFounded′ n) <′-wellFounded′ : ∀ n → <′-Rec (Acc _<′_) n <′-wellFounded′ (suc n) .n ≤′-refl = <′-wellFounded n <′-wellFounded′ (suc n) m (≤′-step m<n) = <′-wellFounded′ n m m<n module _ {ℓ} where open WF.All <′-wellFounded ℓ public renaming ( wfRecBuilder to <′-recBuilder ; wfRec to <′-rec ) hiding (wfRec-builder) ------------------------------------------------------------------------ -- Complete induction based on _<_ <-Rec : ∀ {ℓ} → RecStruct ℕ ℓ ℓ <-Rec = WfRec _<_ <-wellFounded : WellFounded _<_ <-wellFounded = Subrelation.wellFounded ≤⇒≤′ <′-wellFounded module _ {ℓ} where open WF.All <-wellFounded ℓ public renaming ( wfRecBuilder to <-recBuilder ; wfRec to <-rec ) hiding (wfRec-builder) ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 rec-builder = recBuilder {-# WARNING_ON_USAGE rec-builder "Warning: rec-builder was deprecated in v0.15. Please use recBuilder instead." #-} cRec-builder = cRecBuilder {-# WARNING_ON_USAGE cRec-builder "Warning: cRec-builder was deprecated in v0.15. Please use cRecBuilder instead." #-} <′-rec-builder = <′-recBuilder {-# WARNING_ON_USAGE <′-rec-builder "Warning: <′-rec-builder was deprecated in v0.15. Please use <′-recBuilder instead." #-} <-rec-builder = <-recBuilder {-# WARNING_ON_USAGE <-rec-builder "Warning: <-rec-builder was deprecated in v0.15. Please use <-recBuilder instead." #-} <′-well-founded = <′-wellFounded {-# WARNING_ON_USAGE <′-well-founded "Warning: <′-well-founded was deprecated in v0.15. Please use <′-wellFounded instead." #-} <′-well-founded′ = <′-wellFounded′ {-# WARNING_ON_USAGE <′-well-founded′ "Warning: <′-well-founded′ was deprecated in v0.15. Please use <′-wellFounded′ instead." #-} <-well-founded = <-wellFounded {-# WARNING_ON_USAGE <-well-founded "Warning: <-well-founded was deprecated in v0.15. Please use <-wellFounded instead." #-}
{ "alphanum_fraction": 0.5547015117, "avg_line_length": 28.2826086957, "ext": "agda", "hexsha": "e597ae9ca9a5235fc70a2bb98f9e86cbfa887636", "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/Nat/Induction.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/Nat/Induction.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/Nat/Induction.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": 1060, "size": 3903 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category import Categories.Category.Monoidal as M -- Properties of Monoidal Categories module Categories.Category.Monoidal.Properties {o ℓ e} {C : Category o ℓ e} (MC : M.Monoidal C) where open import Data.Product using (_,_; Σ; uncurry′) open Category C open M.Monoidal MC open import Categories.Category.Monoidal.Utilities MC import Categories.Category.Monoidal.Reasoning as MonR open import Categories.Category.Construction.Core C open import Categories.Category.Product using (Product) open import Categories.Functor using (Functor) open import Categories.Functor.Bifunctor open import Categories.Functor.Properties open import Categories.Category.Groupoid using (IsGroupoid) open import Categories.Morphism C open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟) open import Categories.Morphism.Isomorphism C import Categories.Morphism.Reasoning as MR open import Categories.NaturalTransformation.NaturalIsomorphism.Properties using (push-eq) private module C = Category C variable A B : Obj ⊗-iso : Bifunctor Core Core Core ⊗-iso = record { F₀ = uncurry′ _⊗₀_ ; F₁ = λ where (f , g) → f ⊗ᵢ g ; identity = refl⊗refl≃refl ; homomorphism = ⌞ homomorphism ⌟ ; F-resp-≈ = λ where (⌞ eq₁ ⌟ , ⌞ eq₂ ⌟) → ⌞ F-resp-≈ (eq₁ , eq₂) ⌟ } where open Functor ⊗ open _≃_ _⊗ᵢ- : Obj → Functor Core Core X ⊗ᵢ- = appˡ ⊗-iso X -⊗ᵢ_ : Obj → Functor Core Core -⊗ᵢ X = appʳ ⊗-iso X -- Coherence laws due to Mac Lane (1963) the were subsequently proven -- admissible by Max Kelly (1964). See -- https://ncatlab.org/nlab/show/monoidal+category#other_coherence_conditions -- for more details. module Kelly's where open Functor open IsGroupoid.Commutation Core-isGroupoid private assoc′ = IsGroupoid.assoc Core-isGroupoid variable f f′ g h h′ i i′ j k : A ≅ B module _ {X Y : Obj} where open IsGroupoid.HomReasoning Core-isGroupoid -- TS: following three isos commute ua : unit ⊗₀ (unit ⊗₀ X) ⊗₀ Y ≅ unit ⊗₀ unit ⊗₀ X ⊗₀ Y ua = ≅.refl ⊗ᵢ associator u[λY] : unit ⊗₀ (unit ⊗₀ X) ⊗₀ Y ≅ unit ⊗₀ X ⊗₀ Y u[λY] = ≅.refl ⊗ᵢ unitorˡ ⊗ᵢ ≅.refl uλ : unit ⊗₀ unit ⊗₀ X ⊗₀ Y ≅ unit ⊗₀ X ⊗₀ Y uλ = ≅.refl ⊗ᵢ unitorˡ -- setups perimeter : [ ((unit ⊗₀ unit) ⊗₀ X) ⊗₀ Y ⇒ unit ⊗₀ X ⊗₀ Y ]⟨ (unitorʳ ⊗ᵢ ≅.refl) ⊗ᵢ ≅.refl ⇒⟨ (unit ⊗₀ X) ⊗₀ Y ⟩ associator ≈ associator ⇒⟨ (unit ⊗₀ unit) ⊗₀ X ⊗₀ Y ⟩ associator ⇒⟨ unit ⊗₀ unit ⊗₀ X ⊗₀ Y ⟩ uλ ⟩ perimeter = ⟺ (glue◃◽′ triangle-iso (sym (lift-square′ (Equiv.trans assoc-commute-from (∘-resp-≈ˡ (F-resp-≈ ⊗ (Equiv.refl , identity ⊗))))))) where open MR Core [uλ]Y : (unit ⊗₀ (unit ⊗₀ X)) ⊗₀ Y ≅ (unit ⊗₀ X) ⊗₀ Y [uλ]Y = (≅.refl ⊗ᵢ unitorˡ) ⊗ᵢ ≅.refl aY : ((unit ⊗₀ unit) ⊗₀ X) ⊗₀ Y ≅ (unit ⊗₀ unit ⊗₀ X) ⊗₀ Y aY = associator ⊗ᵢ ≅.refl [ρX]Y : ((unit ⊗₀ unit) ⊗₀ X) ⊗₀ Y ≅ (unit ⊗₀ X) ⊗₀ Y [ρX]Y = (unitorʳ ⊗ᵢ ≅.refl) ⊗ᵢ ≅.refl tri : [uλ]Y ∘ᵢ aY ≃ [ρX]Y tri = lift-triangle′ ([ appʳ ⊗ Y ]-resp-∘ triangle) sq : associator ∘ᵢ [uλ]Y ≃ u[λY] ∘ᵢ associator sq = lift-square′ assoc-commute-from -- proofs perimeter′ : [ ((unit ⊗₀ unit) ⊗₀ X) ⊗₀ Y ⇒ unit ⊗₀ X ⊗₀ Y ]⟨ (unitorʳ ⊗ᵢ ≅.refl) ⊗ᵢ ≅.refl ⇒⟨ (unit ⊗₀ X) ⊗₀ Y ⟩ associator ≈ aY ⇒⟨ (unit ⊗₀ (unit ⊗₀ X)) ⊗₀ Y ⟩ associator ⇒⟨ unit ⊗₀ (unit ⊗₀ X) ⊗₀ Y ⟩ ua ⇒⟨ unit ⊗₀ unit ⊗₀ X ⊗₀ Y ⟩ uλ ⟩ perimeter′ = begin associator ∘ᵢ (unitorʳ ⊗ᵢ ≅.refl) ⊗ᵢ ≅.refl ≈⟨ perimeter ⟩ uλ ∘ᵢ associator ∘ᵢ associator ≈˘⟨ refl⟩∘⟨ pentagon-iso ⟩ uλ ∘ᵢ ua ∘ᵢ associator ∘ᵢ aY ∎ top-face : uλ ∘ᵢ ua ≃ u[λY] top-face = elim-triangleˡ′ (sym perimeter′) (glue◽◃ (sym sq) tri) where open MR Core coherence-iso₁ : [ (unit ⊗₀ X) ⊗₀ Y ⇒ X ⊗₀ Y ]⟨ associator ⇒⟨ unit ⊗₀ X ⊗₀ Y ⟩ unitorˡ ≈ unitorˡ ⊗ᵢ ≅.refl ⟩ coherence-iso₁ = triangle-prism top-face square₁ square₂ square₃ where square₁ : [ unit ⊗₀ X ⊗₀ Y ⇒ unit ⊗₀ X ⊗₀ Y ]⟨ ≅.sym unitorˡ ∘ᵢ unitorˡ ≈ ≅.refl ⊗ᵢ unitorˡ ∘ᵢ ≅.sym unitorˡ ⟩ square₁ = lift-square′ unitorˡ-commute-to square₂ : [ (unit ⊗₀ X) ⊗₀ Y ⇒ unit ⊗₀ unit ⊗₀ X ⊗₀ Y ]⟨ ≅.sym unitorˡ ∘ᵢ associator ≈ ≅.refl ⊗ᵢ associator ∘ᵢ ≅.sym unitorˡ ⟩ square₂ = lift-square′ unitorˡ-commute-to square₃ : [ (unit ⊗₀ X) ⊗₀ Y ⇒ unit ⊗₀ X ⊗₀ Y ]⟨ ≅.sym unitorˡ ∘ᵢ unitorˡ ⊗ᵢ ≅.refl ≈ ≅.refl ⊗ᵢ unitorˡ ⊗ᵢ ≅.refl ∘ᵢ ≅.sym unitorˡ ⟩ square₃ = lift-square′ unitorˡ-commute-to coherence₁ : unitorˡ.from ∘ associator.from ≈ unitorˡ.from {X} ⊗₁ C.id {Y} coherence₁ = project-triangle coherence-iso₁ -- another coherence property -- TS : the following three commute ρu : ((X ⊗₀ Y) ⊗₀ unit) ⊗₀ unit ≅ (X ⊗₀ Y) ⊗₀ unit ρu = unitorʳ ⊗ᵢ ≅.refl au : ((X ⊗₀ Y) ⊗₀ unit) ⊗₀ unit ≅ (X ⊗₀ Y ⊗₀ unit) ⊗₀ unit au = associator ⊗ᵢ ≅.refl [Xρ]u : (X ⊗₀ Y ⊗₀ unit) ⊗₀ unit ≅ (X ⊗₀ Y) ⊗₀ unit [Xρ]u = (≅.refl ⊗ᵢ unitorʳ) ⊗ᵢ ≅.refl perimeter″ : [ ((X ⊗₀ Y) ⊗₀ unit) ⊗₀ unit ⇒ X ⊗₀ Y ⊗₀ unit ]⟨ associator ⇒⟨ (X ⊗₀ Y) ⊗₀ unit ⊗₀ unit ⟩ associator ⇒⟨ X ⊗₀ Y ⊗₀ unit ⊗₀ unit ⟩ ≅.refl ⊗ᵢ ≅.refl ⊗ᵢ unitorˡ ≈ ρu ⇒⟨ (X ⊗₀ Y) ⊗₀ unit ⟩ associator ⟩ perimeter″ = glue▹◽ triangle-iso (sym (lift-square′ (Equiv.trans (∘-resp-≈ʳ (F-resp-≈ ⊗ (Equiv.sym (identity ⊗) , Equiv.refl))) assoc-commute-from))) where open MR Core perimeter‴ : [ ((X ⊗₀ Y) ⊗₀ unit) ⊗₀ unit ⇒ X ⊗₀ Y ⊗₀ unit ]⟨ associator ⊗ᵢ ≅.refl ⇒⟨ (X ⊗₀ (Y ⊗₀ unit)) ⊗₀ unit ⟩ (associator ⇒⟨ X ⊗₀ (Y ⊗₀ unit) ⊗₀ unit ⟩ ≅.refl ⊗ᵢ associator ⇒⟨ X ⊗₀ Y ⊗₀ unit ⊗₀ unit ⟩ ≅.refl ⊗ᵢ ≅.refl ⊗ᵢ unitorˡ) ≈ ρu ⇒⟨ (X ⊗₀ Y) ⊗₀ unit ⟩ associator ⟩ perimeter‴ = let α = associator in let λλ = unitorˡ in begin (≅.refl ⊗ᵢ ≅.refl ⊗ᵢ λλ ∘ᵢ ≅.refl ⊗ᵢ α ∘ᵢ α) ∘ᵢ α ⊗ᵢ ≅.refl ≈⟨ assoc′ ⟩ ≅.refl ⊗ᵢ ≅.refl ⊗ᵢ λλ ∘ᵢ (≅.refl ⊗ᵢ α ∘ᵢ α) ∘ᵢ α ⊗ᵢ ≅.refl ≈⟨ refl⟩∘⟨ assoc′ ⟩ ≅.refl ⊗ᵢ ≅.refl ⊗ᵢ λλ ∘ᵢ ≅.refl ⊗ᵢ α ∘ᵢ α ∘ᵢ α ⊗ᵢ ≅.refl ≈⟨ refl⟩∘⟨ pentagon-iso ⟩ ≅.refl ⊗ᵢ ≅.refl ⊗ᵢ λλ ∘ᵢ α ∘ᵢ α ≈⟨ perimeter″ ⟩ α ∘ᵢ ρu ∎ top-face′ : [Xρ]u ∘ᵢ au ≃ ρu top-face′ = cut-squareʳ perimeter‴ (sym (glue◃◽′ tri′ (sym (lift-square′ assoc-commute-from)))) where open MR Core tri′ : [ X ⊗₀ (Y ⊗₀ unit) ⊗₀ unit ⇒ X ⊗₀ Y ⊗₀ unit ]⟨ (≅.refl ⊗ᵢ ≅.refl ⊗ᵢ unitorˡ ∘ᵢ ≅.refl ⊗ᵢ associator) ≈ ≅.refl ⊗ᵢ unitorʳ ⊗ᵢ ≅.refl ⟩ tri′ = lift-triangle′ ([ X ⊗- ]-resp-∘ triangle) coherence-iso₂ : [ (X ⊗₀ Y) ⊗₀ unit ⇒ X ⊗₀ Y ]⟨ ≅.refl ⊗ᵢ unitorʳ ∘ᵢ associator ≈ unitorʳ ⟩ coherence-iso₂ = triangle-prism top-face′ square₁ square₂ (lift-square′ unitorʳ-commute-to) where square₁ : [ X ⊗₀ Y ⊗₀ unit ⇒ (X ⊗₀ Y) ⊗₀ unit ]⟨ ≅.sym unitorʳ ∘ᵢ ≅.refl ⊗ᵢ unitorʳ ≈ (≅.refl ⊗ᵢ unitorʳ) ⊗ᵢ ≅.refl ∘ᵢ ≅.sym unitorʳ ⟩ square₁ = lift-square′ unitorʳ-commute-to square₂ : [ (X ⊗₀ Y) ⊗₀ unit ⇒ (X ⊗₀ Y ⊗₀ unit) ⊗₀ unit ]⟨ ≅.sym unitorʳ ∘ᵢ associator ≈ associator ⊗ᵢ ≅.refl ∘ᵢ ≅.sym unitorʳ ⟩ square₂ = lift-square′ unitorʳ-commute-to coherence₂ : C.id {X} ⊗₁ unitorʳ.from {Y} ∘ associator.from ≈ unitorʳ.from coherence₂ = project-triangle coherence-iso₂ -- A third coherence condition (Lemma 2.3) coherence₃ : unitorˡ.from {unit} ≈ unitorʳ.from coherence₃ = push-eq unitorˡ-naturalIsomorphism (begin C.id ⊗₁ unitorˡ.from ≈˘⟨ cancelʳ associator.isoʳ ⟩ (C.id ⊗₁ unitorˡ.from ∘ associator.from) ∘ associator.to ≈⟨ triangle ⟩∘⟨refl ⟩ unitorʳ.from ⊗₁ C.id ∘ associator.to ≈⟨ unitor-coherenceʳ ⟩∘⟨refl ⟩ unitorʳ.from ∘ associator.to ≈˘⟨ coherence₂ ⟩∘⟨refl ⟩ (C.id ⊗₁ unitorʳ.from ∘ associator.from) ∘ associator.to ≈⟨ cancelʳ associator.isoʳ ⟩ C.id ⊗₁ unitorʳ.from ∎) where open MR C hiding (push-eq) open C.HomReasoning coherence-iso₃ : [ unit ⊗₀ unit ⇒ unit ]⟨ unitorˡ ≈ unitorʳ ⟩ coherence-iso₃ = ⌞ coherence₃ ⌟ open Kelly's using (coherence₁; coherence-iso₁; coherence₂; coherence-iso₂) public
{ "alphanum_fraction": 0.4962523423, "avg_line_length": 38.7338709677, "ext": "agda", "hexsha": "5dbd772d77df95623614db502e50e993228cb027", "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": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_path": "src/Categories/Category/Monoidal/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "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": "MirceaS/agda-categories", "max_issues_repo_path": "src/Categories/Category/Monoidal/Properties.agda", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_path": "src/Categories/Category/Monoidal/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3890, "size": 9606 }
module NoSuchBuiltinName where postulate X : Set {-# BUILTIN FOOBAR X #-}
{ "alphanum_fraction": 0.7142857143, "avg_line_length": 11, "ext": "agda", "hexsha": "ca620217e738d7e9e74d3e77159d8b86f8ba3e50", "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/NoSuchBuiltinName.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/NoSuchBuiltinName.agda", "max_line_length": 30, "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/NoSuchBuiltinName.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": 21, "size": 77 }
-- Andreas, 2020-06-24, issue #4775 reported by JakobBruenker -- Non-record patterns in lets and lambdas lead to internal error -- {-# OPTIONS -v tc.term.lambda:30 #-} -- {-# OPTIONS -v tc.lhs:15 #-} -- {-# OPTIONS -v tc.term.let.pattern:30 #-} -- -- {-# OPTIONS -v tc.term.let.pattern:80 #-} open import Agda.Builtin.Nat open import Agda.Builtin.Sigma data IsSuc : Nat → Set where isSuc : ∀ y → IsSuc (suc y) test : Σ Nat IsSuc → Set test = λ (y1 , isSuc y2) → Nat -- ERROR NOW: -- Expected record pattern -- when checking the let binding y1 , isSuc y2 = .patternInTele0 -- (Talks about desugaring; could still be improved.)
{ "alphanum_fraction": 0.667192429, "avg_line_length": 27.5652173913, "ext": "agda", "hexsha": "81daabece9589ba94537f39ae19e808691a85489", "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/Issue4775.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/Issue4775.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/Issue4775.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": 199, "size": 634 }
-- This file defines the Euclidean Domain structure. {-# OPTIONS --without-K --safe #-} module EuclideanDomain where -- We comply to the definition format in stdlib, i.e. define an -- IsSomething predicate then define the bundle. open import Relation.Binary using (Rel; Setoid; IsEquivalence) module Structures {a ℓ} {A : Set a} -- The underlying set (_≈_ : Rel A ℓ) -- The underlying equality relation where open import Algebra.Structures _≈_ open import Algebra.Core open import Algebra.Definitions _≈_ import Algebra.Consequences.Setoid as Consequences open import Data.Product using (_,_; proj₁; proj₂) open import Level using (_⊔_) open import Data.Nat using (ℕ ; _<_) open import Data.Product using (∃ ; _×_) open import Relation.Nullary using (¬_) -- We only require leftcancellative since we have required the -- domain to be commutative. An Euclidean domain is a commutative -- domain with a div, mod, and rank function satisfy euc-eq and -- euc-rank. record IsEuclideanDomain (+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where field isCommutativeRing : IsCommutativeRing + * - 0# 1# *-alc : AlmostLeftCancellative 0# * div : ∀ (n d : A) -> ¬ d ≈ 0# -> A mod : ∀ (n d : A) -> ¬ d ≈ 0# -> A rank : A → ℕ euc-eq : ∀ (n d : A) -> (n0 : ¬ d ≈ 0#) -> let r = mod n d n0 in let q = div n d n0 in n ≈ + r (* q d) euc-rank : ∀ (n d : A) -> (n0 : ¬ d ≈ 0#) -> let r = mod n d n0 in let q = div n d n0 in rank r < rank d module Bundles where open Structures open import Algebra.Core open import Algebra.Structures open import Relation.Binary open import Function.Base import Relation.Nullary as N open import Level record EuclideanDomainBundle c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 -_ infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier -_ : Op₁ Carrier 0# : Carrier 1# : Carrier isEuclideanDomain : IsEuclideanDomain _≈_ _+_ _*_ -_ 0# 1# open IsEuclideanDomain isEuclideanDomain public
{ "alphanum_fraction": 0.5606247431, "avg_line_length": 33.3287671233, "ext": "agda", "hexsha": "7c8fc7167b9f7de8de6de4fd41a4580244548b5f", "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": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "onestruggler/EucDomain", "max_forks_repo_path": "EuclideanDomain.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "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": "onestruggler/EucDomain", "max_issues_repo_path": "EuclideanDomain.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "onestruggler/EucDomain", "max_stars_repo_path": "EuclideanDomain.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 716, "size": 2433 }
------------------------------------------------------------------------ -- Some results related to an LTS from Section 6.2.5 of "Enhancements -- of the bisimulation proof method" by Pous and Sangiorgi, -- implemented using the coinductive definition of bisimilarity ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude module Bisimilarity.6-2-5 {Name : Type} where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude.Size open import Function-universe equality-with-J hiding (id; _∘_) import Bisimilarity.Equational-reasoning-instances open import Equational-reasoning open import Indexed-container using (⟦_⟧) open import Labelled-transition-system.6-2-5 Name open import Relation open import Bisimilarity 6-2-5 open import Bisimilarity.Up-to 6-2-5 -- Some simple lemmas. The first two are stated by Pous and Sangiorgi, -- and the third one is a generalisation of a result stated by Pous -- and Sangiorgi. op·∅ : ∀ {a} → op (a · ∅) ∼ ∅ op·∅ {a} = ⟨ lr , (λ ()) ⟩ where lr : ∀ {P′ μ} → op (a · ∅) [ μ ]⟶ P′ → ∃ λ Q′ → ∅ [ μ ]⟶ Q′ × P′ ∼′ Q′ lr (op action ()) op··∅ : ∀ {a} → op (a · a · ∅) ∼ a · ∅ op··∅ {a} = ⟨ lr , rl ⟩ where lr : ∀ {P′ μ b} → op (a · b · ∅) [ μ ]⟶ P′ → ∃ λ Q′ → b · ∅ [ μ ]⟶ Q′ × P′ ∼′ Q′ lr (op action action) = _ , action , reflexive rl : ∀ {Q′ μ} → a · ∅ [ μ ]⟶ Q′ → ∃ λ P′ → op (a · a · ∅) [ μ ]⟶ P′ × P′ ∼′ Q′ rl action = _ , op action action , reflexive a≁b·c : ∀ {a b c} → ¬ (a · ∅ ∼ b · c · ∅) a≁b·c a∼b·c with right-to-left a∼b·c action ... | .∅ , action , ∅∼a with right-to-left (force ∅∼a) action ... | _ , () , _ -- Pous and Sangiorgi note that every context preserves bisimilarity. -- One can prove that a ·_ preserves bisimilarity in a size-preserving -- way. ·-cong : ∀ {i a P Q} → [ i ] P ∼ Q → [ i ] a · P ∼ a · Q ·-cong {i} {a} P∼Q = ⟨ lr P∼Q , Σ-map id (Σ-map id symmetric) ∘ lr (symmetric P∼Q) ⟩ where lr : ∀ {P P′ Q μ} → [ i ] P ∼ Q → a · P [ μ ]⟶ P′ → ∃ λ Q′ → a · Q [ μ ]⟶ Q′ × [ i ] P′ ∼′ Q′ lr P∼Q action = _ , action , convert P∼Q -- The operator op also preserves bisimilarity, but this lemma is not -- claimed to be size-preserving. op-cong : ∀ {i} {j : Size< i} {P Q} → [ i ] P ∼ Q → [ j ] op P ∼ op Q op-cong {i} {j} P∼Q = ⟨ lr P∼Q , Σ-map id (Σ-map id symmetric) ∘ lr (symmetric P∼Q) ⟩ where lr : ∀ {P P′ Q μ} → [ i ] P ∼ Q → op P [ μ ]⟶ P′ → ∃ λ Q′ → op Q [ μ ]⟶ Q′ × [ j ] P′ ∼′ Q′ lr P∼Q (op P⟶P′ P′⟶P″) = let Q′ , Q⟶Q′ , P′∼Q′ = left-to-right P∼Q P⟶P′ Q″ , Q′⟶Q″ , P″∼Q″ = left-to-right (force P′∼Q′) P′⟶P″ in Q″ , op Q⟶Q′ Q′⟶Q″ , P″∼Q″ -- Let us assume that the Name type is inhabited. In that case op-cong -- /cannot/ preserve the size of its argument. -- -- The proof is based on an argument presented by Pous and Sangiorgi. op-cong-cannot-preserve-size : Name → ¬ (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) op-cong-cannot-preserve-size a op-cong = a≁b·c a∼a·a where op-cong′ : ∀ {i P Q} → [ i ] P ∼′ Q → [ i ] op P ∼′ op Q force (op-cong′ P∼′Q) = op-cong (force P∼′Q) a∼a·a : ∀ {i} → [ i ] a · ∅ ∼ a · a · ∅ a∼a·a {i} = ⟨ lr , rl ⟩ where a∼′a·a : ∀ {i} → [ i ] a · ∅ ∼′ a · a · ∅ force a∼′a·a = a∼a·a lemma = ∅ ∼⟨ symmetric op·∅ ⟩ op (a · ∅) ∼⟨ op-cong′ (a∼′a·a {i = i}) ⟩ op (a · a · ∅) ∼⟨ op··∅ ⟩■ a · ∅ lr : ∀ {P′ μ} → a · ∅ [ μ ]⟶ P′ → ∃ λ Q′ → a · a · ∅ [ μ ]⟶ Q′ × [ i ] P′ ∼′ Q′ lr action = a · ∅ , action , lemma rl : ∀ {Q′ μ} → a · a · ∅ [ μ ]⟶ Q′ → ∃ λ P′ → a · ∅ [ μ ]⟶ P′ × [ i ] P′ ∼′ Q′ rl action = ∅ , action , lemma -- Up to context (for monadic contexts). Up-to-context : Trans₂ (# 0) Proc Up-to-context R (P , Q) = ∃ λ (C : Context 1) → ∃ λ P′ → ∃ λ Q′ → P ≡ C [ (λ _ → P′) ] × Q ≡ C [ (λ _ → Q′) ] × R (P′ , Q′) -- Up to context is monotone. up-to-context-monotone : Monotone Up-to-context up-to-context-monotone R⊆S = Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id R⊆S -- Up to bisimilarity and context. Up-to-bisimilarity-and-context : Trans₂ (# 0) Proc Up-to-bisimilarity-and-context = Up-to-bisimilarity ∘ Up-to-context -- Up to bisimilarity and context is monotone. up-to-bisimilarity-and-context-monotone : Monotone Up-to-bisimilarity-and-context up-to-bisimilarity-and-context-monotone = up-to-bisimilarity-monotone ∘ up-to-context-monotone -- Up to bisimilarity and context is not sound (assuming that Name is -- inhabited). -- -- This result is due to Pous and Sangiorgi. ¬-up-to-bisimilarity-and-context : Name → ¬ Up-to-technique Up-to-bisimilarity-and-context ¬-up-to-bisimilarity-and-context a = Up-to-technique Up-to-bisimilarity-and-context ↝⟨ _$ R⊆ ⟩ R ⊆ Bisimilarity ∞ ↝⟨ R⊈∼ ⟩□ ⊥ □ where data R : Rel₂ (# 0) Proc where base : R (a · ∅ , a · a · ∅) lemma : Up-to-bisimilarity-and-context R (∅ , a · ∅) lemma = op (a · ∅) , symmetric op·∅ , op (a · a · ∅) , (op (hole fzero) , a · ∅ , a · a · ∅ , refl , refl , base) , op··∅ R⊆ : R ⊆ ⟦ StepC ⟧ (Up-to-bisimilarity-and-context R) R⊆ base = ⟨ (λ { action → a · ∅ , action , lemma }) , (λ { action → ∅ , action , lemma }) ⟩ R⊈∼ : ¬ R ⊆ Bisimilarity ∞ R⊈∼ = R ⊆ Bisimilarity ∞ ↝⟨ (λ R⊆∼ → R⊆∼ base) ⟩ a · ∅ ∼ a · a · ∅ ↝⟨ a≁b·c ⟩□ ⊥ □ -- The last result above can be used to give another proof showing -- that op-cong cannot preserve the size of its argument (assuming -- that Name is inhabited). op-cong-cannot-preserve-size′ : Name → ¬ (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) op-cong-cannot-preserve-size′ a = (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) ↝⟨ (λ op-cong C P∼Q → []-cong op-cong C (λ _ → P∼Q)) ⟩ (∀ {i P Q} (C : Context 1) → [ i ] P ∼ Q → [ i ] C [ (λ _ → P) ] ∼ C [ (λ _ → Q) ]) ↝⟨ (λ []-cong → λ where {x = P , Q} (_ , P∼C[R₁] , _ , (C , R₁ , R₂ , refl , refl , R₁∼R₂) , C[R₂]∼Q) → P ∼⟨ P∼C[R₁] ⟩ C [ (λ _ → R₁) ] ∼⟨ []-cong C R₁∼R₂ ⟩ C [ (λ _ → R₂) ] ∼⟨ C[R₂]∼Q ⟩■ Q) ⟩ (∀ {i} → Up-to-bisimilarity-and-context (Bisimilarity i) ⊆ Bisimilarity i) ↝⟨ _⇔_.from (monotone→⇔ up-to-bisimilarity-and-context-monotone) ⟩ Size-preserving Up-to-bisimilarity-and-context ↝⟨ size-preserving→up-to ⟩ Up-to-technique Up-to-bisimilarity-and-context ↝⟨ ¬-up-to-bisimilarity-and-context a ⟩□ ⊥ □ where []-cong : (∀ {i P Q} → [ i ] P ∼ Q → [ i ] op P ∼ op Q) → ∀ {i n Ps Qs} (C : Context n) → (∀ x → [ i ] Ps x ∼ Qs x) → [ i ] C [ Ps ] ∼ C [ Qs ] []-cong op-cong (hole x) Ps∼Qs = Ps∼Qs x []-cong op-cong (op C) Ps∼Qs = op-cong ([]-cong op-cong C Ps∼Qs) []-cong op-cong (a · C) Ps∼Qs = ·-cong ([]-cong op-cong C Ps∼Qs) []-cong op-cong ∅ Ps∼Qs = reflexive
{ "alphanum_fraction": 0.463356974, "avg_line_length": 32.961038961, "ext": "agda", "hexsha": "229635ced01e9962eed274e0f6685ff47c754d92", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Bisimilarity/6-2-5.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Bisimilarity/6-2-5.agda", "max_line_length": 129, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Bisimilarity/6-2-5.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3003, "size": 7614 }
open import Relation.Binary.Core module SelectSort.Everything {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) (trans≤ : Transitive _≤_) where open import SelectSort.Correctness.Order _≤_ tot≤ trans≤ open import SelectSort.Correctness.Permutation _≤_ tot≤
{ "alphanum_fraction": 0.608974359, "avg_line_length": 31.2, "ext": "agda", "hexsha": "d2a8da0c3408cf13ac2a52ff654850b48836ae6c", "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": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/SelectSort/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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": "bgbianchi/sorting", "max_issues_repo_path": "agda/SelectSort/Everything.agda", "max_line_length": 56, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/SelectSort/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 91, "size": 312 }
------------------------------------------------------------------------ -- Trees ------------------------------------------------------------------------ -- This example is based on one in Wadler's "A prettier printer". {-# OPTIONS --guardedness #-} module Examples.Tree where open import Codata.Musical.Notation open import Data.List open import Data.List.NonEmpty as List⁺ open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Examples.Identifier import Grammar.Infinite import Pretty open import Renderer open import Utilities data Tree : Set where node : Identifier → List Tree → Tree module _ where open Grammar.Infinite mutual tree : Grammar Tree tree = node <$> identifier-w ⊛ brackets brackets : Grammar (List Tree) brackets = return [] ∣ List⁺.toList <$> (symbol′ "[" ⊛> ♯ trees <⊛ symbol′ "]") trees : Grammar (List⁺ Tree) trees = _∷_ <$> tree ⊛ commas-and-trees commas-and-trees : Grammar (List Tree) commas-and-trees = (symbol′ "," ⊛> tree) ⋆ open Pretty -- Wadler presents two pretty-printers for trees in his final code -- listing (§11.7). I've included corresponding, but not quite -- identical, implementations here. -- -- (One of Wadler's implementations is buggy: recursive calls to -- showTree/showTrees should most likely have referred to -- showTree'/showTrees'. The code below is intended to match a -- corrected version of Wadler's.) module Printer₁ where mutual tree-printer : Pretty-printer tree tree-printer (node s ts) = group (<$> identifier-w-printer s ⊛ nest (List⁺.length s) (brackets-printer ts)) brackets-printer : Pretty-printer brackets brackets-printer [] = left nil brackets-printer (t ∷ ts) = right (<$> (symbol ⊛> nest 1 (trees-printer (t ∷ ts)) <⊛ symbol)) trees-printer : Pretty-printer trees trees-printer (t ∷ ts) = <$> tree-printer t ⊛ commas-and-trees-printer ts commas-and-trees-printer : Pretty-printer commas-and-trees commas-and-trees-printer [] = nil-⋆ commas-and-trees-printer (t ∷ ts) = cons-⋆ (symbol-line ⊛> tree-printer t) (commas-and-trees-printer ts) module Printer₂ where mutual tree-printer : Pretty-printer tree tree-printer (node s ts) = <$> identifier-w-printer s ⊛ brackets-printer ts brackets-printer : Pretty-printer brackets brackets-printer [] = left nil brackets-printer (t ∷ ts) = right (<$> bracket 7 (trees-printer (t ∷ ts))) trees-printer : Pretty-printer trees trees-printer (t ∷ ts) = <$> tree-printer t ⊛ commas-and-trees-printer ts commas-and-trees-printer : Pretty-printer commas-and-trees commas-and-trees-printer [] = nil-⋆ commas-and-trees-printer (t ∷ ts) = cons-⋆ (symbol-line ⊛> tree-printer t) (commas-and-trees-printer ts) t : Tree t = node (str⁺ "aaa") (node (str⁺ "bbbbb") (node (str⁺ "ccc") [] ∷ node (str⁺ "dd") [] ∷ []) ∷ node (str⁺ "eee") [] ∷ node (str⁺ "ffff") (node (str⁺ "gg") [] ∷ node (str⁺ "hhh") [] ∷ node (str⁺ "ii") [] ∷ []) ∷ []) test₁ : render 0 (Printer₁.tree-printer t) ≡ "aaa[bbbbb[ccc,\n dd],\n eee,\n ffff[gg,\n hhh,\n ii]]" test₁ = refl test₂ : render 30 (Printer₁.tree-printer t) ≡ "aaa[bbbbb[ccc, dd],\n eee,\n ffff[gg, hhh, ii]]" test₂ = refl test₃ : render 0 (Printer₂.tree-printer t) ≡ "aaa[\n bbbbb[\n ccc,\n dd\n ],\n eee,\n ffff[\n gg,\n hhh,\n ii\n ]\n]" test₃ = refl test₄ : render 80 (Printer₂.tree-printer t) ≡ "aaa[ bbbbb[ ccc, dd ], eee, ffff[ gg, hhh, ii ] ]" test₄ = refl
{ "alphanum_fraction": 0.5826730058, "avg_line_length": 28.9007633588, "ext": "agda", "hexsha": "c38a6a8cb11bc8ed5f566dcb7f2cf7a6d99105a4", "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": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/pretty", "max_forks_repo_path": "Examples/Tree.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "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/pretty", "max_issues_repo_path": "Examples/Tree.agda", "max_line_length": 100, "max_stars_count": null, "max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/pretty", "max_stars_repo_path": "Examples/Tree.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1127, "size": 3786 }
open import Agda.Primitive open import Agda.Builtin.Equality renaming (_≡_ to _==_) --(( If I want to rename the built-in equality )) -- What follows is an attempt to formalize multicategories. For this purpose, we also need to define lists, since the source of a multimap in a multicategory is a list. -- For the moment, I do not try to prove that the lists an the associated concatenation form a monoid (because I do not know if this is useful or not). module MultiCategories where -- ** Function extensionality ** postulate funext : ∀ {X : Set} {Y : X → Set} {f g : ∀ (x : X) → (Y x)} → (∀ (x : X) → ((f x) == (g x))) → (f == g) -- ** Lists ** -- We first define lists data List {l : Level} (A : Set l) : Set l where [] : List A _::_ : A → List A → List A infixr 30 _::_ open List -- We define equality on lists, that extends the built-in equality (since for the moment, we dont need other definitions of equality → but maybe we could do something more general by asking the "equality" as a parameter ?) data _≡ᴸ_ {l : Level} {A : Set l} : (u v : List {l} A) → Set (lsuc l) where eq-nil : [] ≡ᴸ [] eq-cons : ∀ (x y : A) (su sv : List A) → (x == y) → (su ≡ᴸ sv) → ( (x :: su) ≡ᴸ (y :: sv)) -- We define the mapping of lists list-map : ∀ {l : Level} {A B : Set l} → (f : A → B) → List A → List B list-map f [] = [] list-map f (x :: u) = ((f x) :: (list-map f u)) -- We define the concatenation of lists _++_ : ∀ {l}{A : Set l} → List A → List A → List A [] ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) -- We define a fold function fold : ∀ {l : Level} {A B : Set l} → (A → B → B) → B → List A → B fold _⊗_ e [] = e fold _⊗_ e (x :: xs) = x ⊗ (fold _⊗_ e xs) -- We define a flatten function flatten : ∀ {l : Level} {A : Set l} → (u : List ( List A)) → (List A) flatten [] = [] flatten (x :: xs) = x ++ (flatten xs) -- (I wanted to do this with the above fold function, which would be more elegant, but I don't know why, I miserably failed at it - must be tired) -- We define a function that takes a list of functions and a list of arguments and apply the functions point to point list-apply : ∀ {l : Level} {A B : Set l} → (list-f : List (A → B)) → (list-arg : List A) → List B list-apply [] [] = [] list-apply (f :: fs) [] = [] list-apply [] (x :: xs) = [] list-apply (f :: fs) (x :: xs) = (f x) :: (list-apply fs xs) -- The two cases in the middle should be forbidden, but I don't know how to do this -- ** Multicategories ** -- -- We first define the multimaps on a set -- data Multimap {l : Level} {O : Setl l} : Set l where -- map : () record MultiCategory {l : Level} : Set (lsuc l) where field -- Objects and maps object : Set l multimap : Set l sources : ∀ (m : multimap) → List object target : ∀ (m : multimap) → object -- Composition and associated equations / conditions _∘_ : ∀ (f : multimap) → (list : List multimap) → multimap plug : ∀ {g : multimap} → {f : multimap} → {list : List multimap} → {g == (f ∘ list)} → (sources f) ≡ᴸ (list-map target list) dom-comp : ∀ {f : multimap} → {list : List multimap} → ((flatten (list-map sources list)) ≡ᴸ (sources (f ∘ list))) comp-codom : ∀ (f : multimap) → (list : List multimap) → (target f == target (f ∘ list)) -- Identities and associated equations / conditions id : ∀ (o : object) → multimap id-dom-codom : ∀ (o : object) → (sources (id o) == o :: [] ) id-codom : ∀ (o : object) → (target (id o) == o) id-left : ∀ {o : object} {f : multimap} → {f == id o} → (list : List multimap) → ( (f ∘ list) == f) id-rigth : ∀ {f : multimap} {list : List multimap} → {list ≡ᴸ (list-map id (sources f))} → ((f ∘ list) == f) -- Associativity assoc : ∀ {f : multimap} {list-g : List multimap} {list-h : List (List multimap)} → (f ∘ (list-apply (list-map _∘_ list-g) list-h)) == ( (f ∘ list-g) ∘ (flatten list-h)) open MultiCategory -- List over a list data ListOver {l : Level} {A : Set l} (B : A → Set l) : List A → Set l where [[]] : ListOver B [] _:::_ : ∀ {x xs} → (y : B x) → (ys : ListOver B xs) → ListOver B (x :: xs) infixr 25 _:::_ over-map : ∀ {l : Level} {A : Set l} {B : A → Set l} {xs} {C : Set l} → (∀ {x} → B x → C) → ListOver B xs → List C over-map f [[]] = [] over-map f (y ::: ys) = f y :: over-map f ys over-over-map : ∀ {l : Level} {A : Set l} {B : A → Set l} {xs} {C : A → Set l} → (∀ {x} → B x → C x) → ListOver B xs → ListOver C xs over-over-map f [[]] = [[]] over-over-map f (y ::: ys) = f y ::: over-over-map f ys over-lift : ∀ {l : Level} {A : Set l} (list : List A) → ListOver (λ x → A) list over-lift [] = [[]] over-lift (y :: ys) = y ::: (over-lift ys) over-flatten : ∀ {l : Level} {A B : Set l} {list : List A} (list-ov : ListOver (λ x → List B) list) → List B over-flatten [[]] = [] over-flatten (x ::: xs) = x ++ (over-flatten xs) -- Dependent sum record Σ {l} (A : Set l) (B : A → Set l) : Set l where constructor ⟨_,_⟩ field π₁ : A π₂ : B π₁ open Σ -- Shortcuts to map the projections on lists when the dependent sum is a "product" list-π₁ : ∀ {l : Level} {A : Set l} {B} (list : List ( Σ {l} A B)) → List A list-π₁ list = list-map π₁ list list-π₂ : ∀ {l : Level} {A C : Set l} (list : List ( Σ {l} A ( λ x → C))) → List C list-π₂ list = list-map π₂ list -- A more dependent attempt at multicategories record MultiCategory2 {l : Level} : Set (lsuc l) where field object : Set l multimap : List object → object → Set l 𝟙 : ∀ {x} → multimap (x :: []) x _•_ : ∀ {ys x} → multimap ys x → ∀ (gs : ListOver (λ y → Σ (List object) (λ zs → multimap zs y)) ys) → multimap (flatten (over-map π₁ gs)) x -- Another attempt to define multimaps, "putting the dependance elsewhere" _●_ : ∀ {x : object} {ys : List (Σ (List object) (λ x → object))} → multimap (list-π₂ ys) x → ListOver (λ y → multimap (π₁ y) (π₂ y)) ys → multimap (flatten (list-π₁ ys)) x -- here complications start -- 𝟙-left : ∀ {ys x} → (f : multimap ys x) → 𝟙 • (⟨ ys , f ⟩ ::: [[]]) == f -- 𝟙-right : ∀ {ys x} → (f : multimap ys x) → f • (over-over-map ? (over-lift ys)) == f --(ListOver ( λ y → ⟨ x ::: [[]] , 𝟙 ⟩ ) ys) == f -- Attempt with the alternative composition 𝟙-left-● : ∀ {x ys} → (f : multimap ys x) → 𝟙 ● (f ::: [[]]) == f -- Here it seems that we have a lemma to prove to say that ys = (ys ++ flatten (list-map π₁ [])). Do we do it locally or would it be useful to have a more genral lemma ? -- Here I tried to fix 𝟙-left and to define 𝟙-right, but I did not manage to do it, it both cases. Maybe we should revise the definition of _•_ ? -- Agda seems to struggle with the fact that thnigs that should be equal are not equal by definition (conversion/reduction problems). Maybe there are some lemmas to prove here. -- Also, I do not understand why we use the "over-map" : it would feel more natural to me if, once we lift a list to a dependent one, and use dependant lists, we only use dependeant lists, that's why I defined over-lift and over-over-map. (I also defined an "over-flatten" but don't know if it's useful)
{ "alphanum_fraction": 0.5673525377, "avg_line_length": 48.2781456954, "ext": "agda", "hexsha": "efeb175ca824876233bf98b933f03ef3d3ba58f5", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_path": "src/Experimental/MultiCategories.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_path": "src/Experimental/MultiCategories.agda", "max_line_length": 303, "max_stars_count": 21, "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_path": "src/Experimental/MultiCategories.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "num_tokens": 2512, "size": 7290 }
module NotLinearPat where data Nat : Set where zero : Nat succ : Nat -> Nat bad : Nat -> Nat -> Nat bad x x = zero bad x y = succ zero
{ "alphanum_fraction": 0.6267605634, "avg_line_length": 12.9090909091, "ext": "agda", "hexsha": "8172146b67775af45dd30910214a63930d16a20a", "lang": "Agda", "max_forks_count": 5, "max_forks_repo_forks_event_max_datetime": "2021-08-16T07:47:36.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-30T00:17:04.000Z", "max_forks_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/miniagda", "max_forks_repo_path": "examples/NotLinearPat.agda", "max_issues_count": 7, "max_issues_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_issues_repo_issues_event_max_datetime": "2020-03-17T08:09:01.000Z", "max_issues_repo_issues_event_min_datetime": "2016-12-16T15:48:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/miniagda", "max_issues_repo_path": "examples/NotLinearPat.agda", "max_line_length": 25, "max_stars_count": 85, "max_stars_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/miniagda", "max_stars_repo_path": "examples/NotLinearPat.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-12T16:54:56.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-16T15:53:24.000Z", "num_tokens": 45, "size": 142 }
------------------------------------------------------------------------ -- agda-misc -- All modules ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module AgdaMiscEverything where ------------------------------------------------------------------------ -- Algorithms -- Insertion sort import Algorithms.List.Sort.Insertion import Algorithms.List.Sort.Insertion.Properties -- Quicksort import Algorithms.List.Sort.Quick import Algorithms.List.Sort.Quick.Properties ------------------------------------------------------------------------ -- Constructive mathematics -- Definitions of Axioms that are nonconstructive import Constructive.Axiom import Constructive.Axiom.Properties import Constructive.Axiom.Properties.Base import Constructive.Axiom.Properties.Base.Lemma import Constructive.Axiom.Properties.Bool import Constructive.Axiom.Properties.Transport -- Alternative proof of LLPO => MP∨ import Constructive.Axiom.Properties.Alternative -- Combinators for reasoning import Constructive.Combinators import Constructive.Common -- Searchable set import Constructive.Searchable -- Experiment -- Category theory import Experiment.Categories.Solver.Category import Experiment.Categories.Solver.Category.Example import Experiment.Categories.Solver.Category.Cartesian import Experiment.Categories.Solver.Category.Cartesian.Example import Experiment.Categories.Solver.Functor import Experiment.Categories.Solver.Functor.Example import Experiment.Categories.Solver.MultiFunctor import Experiment.Categories.Solver.MultiFunctor.Example ------------------------------------------------------------------------ -- Formal language import Math.FormalLanguage ------------------------------------------------------------------------ -- Googology import Math.Googology.Function import Math.Googology.Function.Properties ------------------------------------------------------------------------ -- Number theory -- Fibonacci number import Math.NumberTheory.Fibonacci.Generic import Math.NumberTheory.Fibonacci.Nat import Math.NumberTheory.Fibonacci.Nat.Properties -- Summation import Math.NumberTheory.Summation.Generic import Math.NumberTheory.Summation.Generic.Properties import Math.NumberTheory.Summation.Nat import Math.NumberTheory.Summation.Nat.Properties -- Product import Math.NumberTheory.Product.Generic import Math.NumberTheory.Product.Generic.Properties import Math.NumberTheory.Product.Nat import Math.NumberTheory.Product.Nat.Properties ------------------------------------------------------------------------ -- Type theory -- Natural number import TypeTheory.Nat.Operations import TypeTheory.Nat.Properties import TypeTheory.Nat.Instance -- Homotopy Type Theory import TypeTheory.HoTT.Base import TypeTheory.HoTT.Data.Empty.Properties import TypeTheory.HoTT.Data.Sum.Properties import TypeTheory.HoTT.Function.Properties import TypeTheory.HoTT.Relation.Nullary.Negation.Properties -- Identity type import TypeTheory.Identity
{ "alphanum_fraction": 0.6717055537, "avg_line_length": 23.053030303, "ext": "agda", "hexsha": "5998309b4ff1b739b700fb6625265b5e05f29721", "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": "AgdaMiscEverything.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": "AgdaMiscEverything.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rei1024/agda-misc", "max_stars_repo_path": "AgdaMiscEverything.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": 536, "size": 3043 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommAlgebra.Ideal where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Ideal renaming (IdealsIn to IdealsInCommRing; makeIdeal to makeIdealCommRing) open import Cubical.Algebra.CommAlgebra private variable ℓ : Level module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) where IdealsIn : Type _ IdealsIn = IdealsInCommRing (CommAlgebra→CommRing A) open CommAlgebraStr (snd A) makeIdeal : (I : fst A → hProp ℓ) → (+-closed : {x y : fst A} → x ∈ I → y ∈ I → (x + y) ∈ I) → (0-closed : 0a ∈ I) → (·-closedLeft : {x : fst A} → (r : fst A) → x ∈ I → r · x ∈ I) → IdealsIn makeIdeal = makeIdealCommRing {R = CommAlgebra→CommRing A}
{ "alphanum_fraction": 0.624602333, "avg_line_length": 33.6785714286, "ext": "agda", "hexsha": "8176c3c7a9fe31cc03b29339a56d734f65677968", "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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_path": "Cubical/Algebra/CommAlgebra/Ideal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "howsiyu/cubical", "max_issues_repo_path": "Cubical/Algebra/CommAlgebra/Ideal.agda", "max_line_length": 84, "max_stars_count": null, "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_path": "Cubical/Algebra/CommAlgebra/Ideal.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 282, "size": 943 }
-- Copyright: (c) 2016 Ertugrul Söylemez -- License: BSD3 -- Maintainer: Ertugrul Söylemez <[email protected]> module Algebra.Group.Monoid where open import Algebra.Category open import Algebra.Group.Semigroup open import Core -- A monoid is a semigroup with an identity element. record IsMonoid {a r} (S : Semigroup {a} {r}) : Set (a ⊔ r) where open Semigroup S field id : A left-id : ∀ x → id ⋄ x ≈ x right-id : ∀ x → x ⋄ id ≈ x category : Category category = record { semigroupoid = semigroupoid; id = id; left-id = left-id; right-id = right-id } open Category category public using (id-unique; Iso) record Monoid {a r} : Set (lsuc (a ⊔ r)) where field semigroup : Semigroup {a} {r} isMonoid : IsMonoid semigroup open Semigroup semigroup public open IsMonoid isMonoid public -- A monoid morphism is a function that maps the elements of one monoid -- to another while preserving the compositional structure as well as -- identity. record MonoidMorphism {ma mr na nr} (M : Monoid {ma} {mr}) (N : Monoid {na} {nr}) : Set (ma ⊔ mr ⊔ na ⊔ nr) where private module M = Monoid M module N = Monoid N field semigroupMorphism : SemigroupMorphism M.semigroup N.semigroup open SemigroupMorphism semigroupMorphism public field id-preserving : map M.id N.≈ N.id functor : Functor M.category N.category functor = record { semifunctor = semifunctor; id-preserving = id-preserving } open Functor functor public using (Iso-preserving) -- An equivalence relation on monoid morphisms that considers monoid -- morphisms to be equal iff they map every element in the domain to the -- same element in the codomain. MonoidMorphismEq : ∀ {ma mr na nr} {M : Monoid {ma} {mr}} {N : Monoid {na} {nr}} → Equiv (MonoidMorphism M N) MonoidMorphismEq {N = N} = record { _≈_ = λ F G → let module F = MonoidMorphism F module G = MonoidMorphism G in ∀ x → F.map x ≈ G.map x; refl = λ _ → refl; sym = λ x≈y x → sym (x≈y x); trans = λ x≈y y≈z x → trans (x≈y x) (y≈z x) } where module N = Monoid N open Equiv N.Eq -- Category of monoids. Monoids : ∀ {a r} → Category Monoids {a} {r} = record { semigroupoid = record { Ob = Monoid {a} {r}; Hom = MonoidMorphism; Eq = MonoidMorphismEq; _∘_ = _∘_; ∘-cong = λ {_} {_} {_} {f1} {f2} {g1} {g2} → ∘-cong {f1 = f1} {f2} {g1} {g2}; assoc = assoc }; id = id; left-id = left-id; right-id = right-id } where open module MyEquiv {M : Monoid} {N : Monoid} = Equiv (MonoidMorphismEq {M = M} {N}) id : ∀ {M} → MonoidMorphism M M id {M} = record { semigroupMorphism = record { map = Sets.id; map-cong = Sets.id; ⋄-preserving = λ x y → M.refl }; id-preserving = M.refl } where module M = Monoid M _∘_ : ∀ {M N O} → MonoidMorphism N O → MonoidMorphism M N → MonoidMorphism M O _∘_ {M} {N} {O} f g = record { semigroupMorphism = f.semigroupMorphism Semigroups.∘ g.semigroupMorphism; id-preserving = O.begin f.map (g.map M.id) O.≈[ f.map-cong g.id-preserving ] f.map N.id O.≈[ f.id-preserving ] O.id O.qed } where module f = MonoidMorphism f module g = MonoidMorphism g module M = Monoid M module N = Monoid N module O = Monoid O ∘-cong : ∀ {M N O} {f1 f2 : MonoidMorphism N O} {g1 g2 : MonoidMorphism M N} → f1 ≈ f2 → g1 ≈ g2 → f1 ∘ g1 ≈ f2 ∘ g2 ∘-cong {O = O} {f1} {f2} {g1} {g2} f1≈f2 g1≈g2 x = O.begin f1.map (g1.map x) O.≈[ f1.map-cong (g1≈g2 x) ] f1.map (g2.map x) O.≈[ f1≈f2 (g2.map x) ] f2.map (g2.map x) O.qed where module O = Monoid O module f1 = MonoidMorphism f1 module f2 = MonoidMorphism f2 module g1 = MonoidMorphism g1 module g2 = MonoidMorphism g2 assoc : ∀ {M N O P} (f : MonoidMorphism O P) (g : MonoidMorphism N O) (h : MonoidMorphism M N) → (f ∘ g) ∘ h ≈ f ∘ (g ∘ h) assoc {P = P} _ _ _ _ = P.refl where module P = Monoid P left-id : ∀ {M N} (f : MonoidMorphism M N) → id ∘ f ≈ f left-id {N = N} _ _ = N.refl where module N = Monoid N right-id : ∀ {M N} (f : MonoidMorphism M N) → f ∘ id ≈ f right-id {N = N} _ _ = N.refl where module N = Monoid N
{ "alphanum_fraction": 0.571460177, "avg_line_length": 23.2989690722, "ext": "agda", "hexsha": "46dedee4474f766cde5d6ae894ca49644208275b", "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": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "esoeylemez/agda-simple", "max_forks_repo_path": "Algebra/Group/Monoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": "esoeylemez/agda-simple", "max_issues_repo_path": "Algebra/Group/Monoid.agda", "max_line_length": 86, "max_stars_count": 1, "max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "esoeylemez/agda-simple", "max_stars_repo_path": "Algebra/Group/Monoid.agda", "max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z", "num_tokens": 1628, "size": 4520 }
open import Agda.Primitive open import Semigroup module Monoid where record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field proj₁ : A proj₂ : B proj₁ Σ-syntax : ∀ {a b} (A : Set a) → (A → Set b) → Set (a ⊔ b) Σ-syntax = Σ syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B _×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b) A × B = Σ[ x ∈ A ] B record Monoid {A : Set} (_∙_ : A → A → A) (ε : A) : Set where field semigroup : Semigroup _∙_ identity : (∀ x → ε ∙ x ≡ x) × (∀ x → x ∙ ε ≡ x)
{ "alphanum_fraction": 0.4832451499, "avg_line_length": 23.625, "ext": "agda", "hexsha": "862d933cc9ea62dbfd272f756bd252c2d5b8bfb5", "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": "382fcfae193079783621fc5cf54b6588e22ef759", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "cantsin/agda-experiments", "max_forks_repo_path": "Monoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "382fcfae193079783621fc5cf54b6588e22ef759", "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": "cantsin/agda-experiments", "max_issues_repo_path": "Monoid.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "382fcfae193079783621fc5cf54b6588e22ef759", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "cantsin/agda-experiments", "max_stars_repo_path": "Monoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 245, "size": 567 }
{-# OPTIONS --cubical-compatible --rewriting --confluence-check #-} open import Issue1719.Common open import Issue1719.Spans open import Issue1719.Pushouts module _ {d : Span} {l} {P : Pushout d → Set l} (left* : (a : Span.A d) → P (left a)) (right* : (b : Span.B d) → P (right b)) (glue* : (c : Span.C d) → left* (Span.f d c) == right* (Span.g d c) [ P ↓ glue c ]) where test : (a : Span.A d) → Pushout-elim {P = P} left* right* glue* (left a) ↦ left* a test a = idr
{ "alphanum_fraction": 0.5933609959, "avg_line_length": 32.1333333333, "ext": "agda", "hexsha": "aaabbf1358b9c5a1d28f78084bdec6f02ee43dd3", "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": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Succeed/Issue1719.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Succeed/Issue1719.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Succeed/Issue1719.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 177, "size": 482 }
-- Andreas, 2017-05-17, issue #2574 reported by G. Allais -- This module is intentionally without name. module _ where private postulate A : Set
{ "alphanum_fraction": 0.7266666667, "avg_line_length": 16.6666666667, "ext": "agda", "hexsha": "e356fcd2bc39acd4ba07aa52eaad39ec3861bf75", "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/Issue2574Import.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/Issue2574Import.agda", "max_line_length": 57, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue2574Import.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": 43, "size": 150 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Instantiates the ring solver with two copies of the same ring with -- decidable equality ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Algebra.Solver.Ring.AlmostCommutativeRing open import Relation.Binary open import Relation.Binary.Consequences using (dec⟶weaklyDec) module Algebra.Solver.Ring.Simple {r₁ r₂} (R : AlmostCommutativeRing r₁ r₂) (_≟_ : Decidable (AlmostCommutativeRing._≈_ R)) where open AlmostCommutativeRing R import Algebra.Solver.Ring as RS open RS rawRing R (-raw-almostCommutative⟶ R) (dec⟶weaklyDec _≟_) public
{ "alphanum_fraction": 0.5965147453, "avg_line_length": 33.9090909091, "ext": "agda", "hexsha": "cbda26e3165bb31bc38a08ca87d23206509b5683", "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/Algebra/Solver/Ring/Simple.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/Algebra/Solver/Ring/Simple.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring/Simple.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 171, "size": 746 }
import Lvl open import Structure.Operator.Vector open import Structure.Setoid open import Type module Structure.Operator.Vector.Subspaces.DirectSum {ℓᵥ ℓₛ ℓᵥₑ ℓₛₑ} {V : Type{ℓᵥ}} ⦃ equiv-V : Equiv{ℓᵥₑ}(V) ⦄ {S : Type{ℓₛ}} ⦃ equiv-S : Equiv{ℓₛₑ}(S) ⦄ {_+ᵥ_ : V → V → V} {_⋅ₛᵥ_ : S → V → V} {_+ₛ_ _⋅ₛ_ : S → S → S} ⦃ vectorSpace : VectorSpace(_+ᵥ_)(_⋅ₛᵥ_)(_+ₛ_)(_⋅ₛ_) ⦄ where open VectorSpace(vectorSpace) open import Data.Tuple as Tuple using (_,_) open import Logic.Propositional open import Logic.Predicate import Lvl open import Sets.ExtensionalPredicateSet as PredSet using (PredSet ; _∈_ ; [∋]-binaryRelator) open import Structure.Container.SetLike using (SetElement) private open module SetLikeFunctionProperties{ℓ} = Structure.Container.SetLike.FunctionProperties{C = PredSet{ℓ}(V)}{E = V}(_∈_) open import Structure.Operator open import Structure.Operator.Proofs.Util open import Structure.Operator.Properties open import Structure.Operator.Vector open import Structure.Operator.Vector.Subspace ⦃ vectorSpace = vectorSpace ⦄ open import Syntax.Transitivity private variable ℓ ℓ₁ ℓ₂ ℓₗ : Lvl.Level module _ where module _ where -- TODO: This operator can also be constructed for vector spaces, not just subspaces _+ˢᵘᵇ_ : SubspaceObject{ℓ₁} → SubspaceObject{ℓ₂} → SubspaceObject ([∃]-intro V₁ ⦃ p₁ ⦄) +ˢᵘᵇ ([∃]-intro V₂ ⦃ p₂ ⦄) = [∃]-intro (PredSet.map₂(_+ᵥ_) V₁ V₂) ⦃ p ⦄ where p : Subspace(PredSet.map₂(_+ᵥ_) V₁ V₂) ∃.witness (Structure.Container.SetLike.FunctionProperties._closed-under₂_.proof (Subspace.add-closure p) ([∃]-intro(a₁ , a₂)) ([∃]-intro(b₁ , b₂))) = ((a₁ +ᵥ b₁) , (a₂ +ᵥ b₂)) ∃.proof (Structure.Container.SetLike.FunctionProperties._closed-under₂_.proof (Subspace.add-closure p) {a}{b} ([∃]-intro ([∧]-intro a₁ a₂) ⦃ [∧]-intro ([∧]-intro a₁V₁ a₂V₂) a₁a₂a ⦄) ([∃]-intro (b₁ , b₂) ⦃ [∧]-intro ([∧]-intro b₁V₁ b₂V₂) b₁b₂b ⦄)) = [∧]-intro ([∧]-intro l₁ l₂) r where l₁ : (a₁ +ᵥ b₁) ∈ V₁ l₁ = (V₁ closureUnder₂(_+ᵥ_)) a₁V₁ b₁V₁ l₂ : (a₂ +ᵥ b₂) ∈ V₂ l₂ = (V₂ closureUnder₂(_+ᵥ_)) a₂V₂ b₂V₂ r : (a₁ +ᵥ b₁) +ᵥ (a₂ +ᵥ b₂) ≡ a +ᵥ b r = (a₁ +ᵥ b₁) +ᵥ (a₂ +ᵥ b₂) 🝖[ _≡_ ]-[ One.associate-commute4-c {_▫_ = _+ᵥ_} ⦃ op = [+ᵥ]-binary-operator ⦄ ⦃ assoc = [+ᵥ]-associativity ⦄ ⦃ comm = [+ᵥ]-commutativity ⦄ ] -- TODO: Why are the instances not inferred? (a₁ +ᵥ a₂) +ᵥ (b₁ +ᵥ b₂) 🝖[ _≡_ ]-[ congruence₂(_+ᵥ_) ⦃ [+ᵥ]-binary-operator ⦄ a₁a₂a b₁b₂b ] a +ᵥ b 🝖-end ∃.witness (Structure.Container.SetLike.FunctionProperties._closed-under₁_.proof (Subspace.mul-closure p {s}) ([∃]-intro(v₁ , v₂))) = ((s ⋅ₛᵥ v₁) , (s ⋅ₛᵥ v₂)) ∃.proof (Structure.Container.SetLike.FunctionProperties._closed-under₁_.proof (Subspace.mul-closure p {s}) {v} ([∃]-intro(v₁ , v₂) ⦃ [∧]-intro ([∧]-intro v₁V₁ v₂V₂) v₁v₂v ⦄)) = [∧]-intro ([∧]-intro l₁ l₂) r where l₁ : (s ⋅ₛᵥ v₁) ∈ V₁ l₁ = (V₁ closureUnder₁(s ⋅ₛᵥ_)) v₁V₁ l₂ : (s ⋅ₛᵥ v₂) ∈ V₂ l₂ = (V₂ closureUnder₁(s ⋅ₛᵥ_)) v₂V₂ r : (s ⋅ₛᵥ v₁) +ᵥ (s ⋅ₛᵥ v₂) ≡ (s ⋅ₛᵥ v) r = (s ⋅ₛᵥ v₁) +ᵥ (s ⋅ₛᵥ v₂) 🝖[ _≡_ ]-[ distributivityₗ(_⋅ₛᵥ_)(_+ᵥ_) ]-sym s ⋅ₛᵥ (v₁ +ᵥ v₂) 🝖[ _≡_ ]-[ congruence₂ᵣ(_⋅ₛᵥ_)(s) v₁v₂v ] s ⋅ₛᵥ v 🝖-end -- TODO: Formulate -- [⊕ˢᵘᵇ]-span-vectorSpace : (V₁ ⊕ V₂ ⊕ … ≡ₛ 𝐔) ↔ (∀{v₁}{v₂}{…} → (v₁ ∈ V₁) → (v₂ ∈ V₂) → … → (v₁ + v₂ + … ≡ 𝟎ᵥ) → ((v₁ ≡ 𝟎ᵥ) ∧ (v₂ ≡ 𝟎ᵥ) ∧ …)) -- [⊕ˢᵘᵇ]-span-existence-finite-space : Finite → ∃(\{(V₁ , V₂ , …) → V₁ ⊕ V₂ ⊕ … ≡ₛ 𝐔}) -- TODO: Just take the "standard" "axis aligned" subspaces
{ "alphanum_fraction": 0.601650619, "avg_line_length": 55.0757575758, "ext": "agda", "hexsha": "283ed7e05f05afbd25496e60aaab6560815f4514", "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/Operator/Vector/Subspaces/DirectSum.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/Operator/Vector/Subspaces/DirectSum.agda", "max_line_length": 290, "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/Operator/Vector/Subspaces/DirectSum.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": 1726, "size": 3635 }
-- {-# OPTIONS -v tc.with:100 #-} module Issue818 where data ⊤ : Set where tt : ⊤ Foo : {x : ⊤} → Set₁ Foo with tt Foo {x = _} | tt = Set -- Panic: wrong number of arguments in with clause: given 1, expected -- 0 -- when checking that the clause -- Foo with tt -- Foo {x = _} | tt = Set -- has type {⊤} → Set₁ -- The code above type-checks using Agda 2.3.0.1, but not with Agda -- 2.3.2. -- Andreas, 2013-03-08: same error thrown by -- foo : ⊤ → Set₁ -- foo with tt -- foo x | tt = Set -- Implicit arguments are no longer eagerly introduced (see release notes -- for 2.3.2, text for issue 679). -- Should now throw a proper error message (not a panic).
{ "alphanum_fraction": 0.6304675716, "avg_line_length": 21.3870967742, "ext": "agda", "hexsha": "bbc909d42bcd764bea0b73bc516c552dd5644760", "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/Issue818.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/Issue818.agda", "max_line_length": 73, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/fail/Issue818.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": 225, "size": 663 }
open import Algebra.Apartness using (HeytingField) module Data.Real.Abstract.Structures {c ℓ₁ ℓ₂} (f : HeytingField c ℓ₁ ℓ₂) where open HeytingField f open import Relation.Binary using (Rel; IsStrictTotalOrder) open import Level using (_⊔_) open import Data.Product using (_×_; ∃-syntax) import Data.Nat as ℕ open ℕ using (ℕ; zero; suc) record IsOrderedHeytingField {r} (_<_ : Rel Carrier r) : Set (c ⊔ ℓ₁ ⊔ r) where field isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ ordered : ∀ a b c → a < b → (a + c) < (b + c) × (c + a) < (c + b) _ℕ*_ : ℕ → Carrier → Carrier zero ℕ* x = 1# suc n ℕ* x = x * (n ℕ* x) record IsArchimedanHeytingField {r} (_<_ : Rel Carrier r) : Set (c ⊔ ℓ₁ ⊔ r) where field dense : ∀ a b → a < b → ∃[ c ] (a < c) × (c < b) archimedan : ∀ a b → 0# < a → 0# < b → ∃[ n ] (b < (n ℕ* a))
{ "alphanum_fraction": 0.6002358491, "avg_line_length": 24.9411764706, "ext": "agda", "hexsha": "f45defd4d933f9af13c5106893649f46c95e1c75", "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": "a193aeebf1326f960975b19d3e31b46fddbbfaa2", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "cspollard/reals", "max_forks_repo_path": "src/Data/Real/Abstract/Structures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2", "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": "cspollard/reals", "max_issues_repo_path": "src/Data/Real/Abstract/Structures.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "cspollard/reals", "max_stars_repo_path": "src/Data/Real/Abstract/Structures.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 327, "size": 848 }
-- Proof of: ∀ (x : ND ℕ) → always (even (double (eo x))) ≡ tt module even-double-eo where open import bool open import nat open import eq open import nat-thms open import nondet open import nondet-thms open import functions ---------------------------------------------------------------------- -- A definition of double with addition. double : ℕ → ℕ double x = x + x -- even is a deterministic predicate: even : ℕ → 𝔹 even zero = tt even (suc 0) = ff even (suc (suc x)) = even x -- eo yields an even and odd number close to the input value: eo : ℕ → ND ℕ eo n = Val n ?? Val (suc n) -- auxiliary property for x+x instead of double: even-x+x : (x : ℕ) → even (x + x) ≡ tt even-x+x zero = refl even-x+x (suc x) rewrite +suc x x | even-x+x x = refl -- (even (double x)) is always true: even-double-is-true : ∀ (x : ℕ) → even (double x) ≡ tt even-double-is-true x rewrite even-x+x x = refl -- Proof of main result: even-double-eo-true : (n : ℕ) → always ((even ∘ double) $* (eo n)) ≡ tt even-double-eo-true n = always-$* (even ∘ double) (eo n) even-double-is-true -- Alternative statement and proof: double-eo-satisfy-even : ∀ (n : ℕ) → (double $* (eo n)) satisfy even ≡ tt double-eo-satisfy-even n rewrite even-double-is-true n | +suc n n | even-double-is-true n = refl ----------------------------------------------------------------------
{ "alphanum_fraction": 0.582717873, "avg_line_length": 27.6326530612, "ext": "agda", "hexsha": "c6929b0908a0beb9ce9d1b3248bf3416c93cc671", "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": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "mihanus/curry-agda", "max_forks_repo_path": "nondet/even-double-eo.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "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": "mihanus/curry-agda", "max_issues_repo_path": "nondet/even-double-eo.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "mihanus/curry-agda", "max_stars_repo_path": "nondet/even-double-eo.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 403, "size": 1354 }
{-# OPTIONS --without-K --safe #-} open import Polynomial.Parameters module Polynomial.Solver {c r₁ r₂ r₃} (homo : Homomorphism c r₁ r₂ r₃) where open import Data.Vec as Vec using (Vec) open import Polynomial.Expr public open import Algebra.Solver.Ring.AlmostCommutativeRing open Homomorphism homo open Eval homo open import Polynomial.NormalForm.Definition coeffs using (Poly) open import Polynomial.NormalForm.Operations coeffs using (_⊞_; _⊠_; ⊟_; _⊡_; κ; ι) norm : ∀ {n} → Expr Raw.Carrier n → Poly n norm (Κ x) = κ x norm (Ι x) = ι x norm (x ⊕ y) = norm x ⊞ norm y norm (x ⊗ y) = norm x ⊠ norm y norm (x ⊛ i) = norm x ⊡ i norm (⊝ x) = ⊟ norm x open import Polynomial.NormalForm.Semantics homo renaming (⟦_⟧ to ⟦_⟧ₚ) ⟦_⇓⟧ : ∀ {n} → Expr Raw.Carrier n → Vec Carrier n → Carrier ⟦ x ⇓⟧ = ⟦ norm x ⟧ₚ import Polynomial.Homomorphism homo as Hom open import Function correct : ∀ {n} (e : Expr Raw.Carrier n) ρ → ⟦ e ⇓⟧ ρ ≈ ⟦ e ⟧ ρ correct (Κ x) ρ = Hom.κ-hom x ρ correct (Ι x) ρ = Hom.ι-hom x ρ correct (x ⊕ y) ρ = Hom.⊞-hom (norm x) (norm y) ρ ⟨ trans ⟩ (correct x ρ ⟨ +-cong ⟩ correct y ρ) correct (x ⊗ y) ρ = Hom.⊠-hom (norm x) (norm y) ρ ⟨ trans ⟩ (correct x ρ ⟨ *-cong ⟩ correct y ρ) correct (x ⊛ i) ρ = Hom.⊡-hom (norm x) i ρ ⟨ trans ⟩ (Hom.pow-cong i (correct x ρ)) correct (⊝ x) ρ = Hom.⊟-hom (norm x) ρ ⟨ trans ⟩ -‿cong (correct x ρ) open import Relation.Binary.Reflection setoid Ι ⟦_⟧ ⟦_⇓⟧ correct public
{ "alphanum_fraction": 0.6441973593, "avg_line_length": 29.3673469388, "ext": "agda", "hexsha": "c4220bb2e136ab908e74eabb68f0d84935413f9b", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z", "max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z", "max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/agda-ring-solver", "max_forks_repo_path": "src/Polynomial/Solver.agda", "max_issues_count": 5, "max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/agda-ring-solver", "max_issues_repo_path": "src/Polynomial/Solver.agda", "max_line_length": 96, "max_stars_count": 36, "max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/agda-ring-solver", "max_stars_repo_path": "src/Polynomial/Solver.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z", "num_tokens": 589, "size": 1439 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.Product.Relation.Binary.Pointwise.Dependent directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Product.Relation.Pointwise.Dependent where open import Data.Product.Relation.Binary.Pointwise.Dependent public
{ "alphanum_fraction": 0.520361991, "avg_line_length": 34, "ext": "agda", "hexsha": "450566909771eff9909c3ccac7963b524b21d92d", "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/Product/Relation/Pointwise/Dependent.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/Product/Relation/Pointwise/Dependent.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/Relation/Pointwise/Dependent.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 69, "size": 442 }
module WellScopedTerms where open import Library open import Categories open import Functors open import Categories.Sets open import Functors.Fin hiding (lift) open import RMonads open import Relation.Binary.HeterogeneousEquality open Cat open Fun data Tm : ℕ → Set where var : ∀{n} → Fin n → Tm n lam : ∀{n} → Tm (suc n) → Tm n app : ∀{n} → Tm n → Tm n → Tm n Ren : ℕ → ℕ → Set Ren m n = Fin m → Fin n -- Weakening a renaming (to push it under a lambda) wk : ∀{m n} → Ren m n → Ren (suc m) (suc n) wk f zero = zero wk f (suc i) = suc (f i) -- Performing a renaming on an expression ren : ∀{m n} → Ren m n → Tm m → Tm n ren f (var i) = var (f i) ren f (app t u) = app (ren f t) (ren f u) ren f (lam t) = lam (ren (wk f) t) -- Identity renaming renId : ∀{n} → Ren n n renId = id -- Composition of renamings renComp : ∀{m n o} → Ren n o → Ren m n → Ren m o renComp f g = f ∘ g -- we prove that wk is an endofunctor wkid : ∀{n}(i : Fin (suc n)) → wk renId i ≅ id i wkid zero = refl wkid (suc i) = refl wkcomp : ∀{m n o}(f : Ren n o)(g : Ren m n)(i : Fin (suc m)) → wk (renComp f g) i ≅ renComp (wk f) (wk g) i wkcomp f g zero = refl wkcomp f g (suc i) = refl -- we prove that renamings is a functor renid : ∀{n}(t : Tm n) → ren renId t ≅ t renid (var i) = refl renid (app t u) = cong₂ app (renid t) (renid u) renid (lam t) = proof lam (ren (wk renId) t) ≅⟨ cong (λ f → lam (ren f t)) (ext wkid) ⟩ lam (ren renId t) ≅⟨ cong lam (renid t) ⟩ lam t ∎ rencomp : ∀{m n o}(f : Ren n o)(g : Ren m n)(t : Tm m) → ren (renComp f g) t ≅ ren f (ren g t) rencomp f g (var i) = refl rencomp f g (app t u) = cong₂ app (rencomp f g t) (rencomp f g u) rencomp f g (lam t) = proof lam (ren (wk (renComp f g)) t) ≅⟨ cong (λ f → lam (ren f t)) (ext (wkcomp f g)) ⟩ lam (ren (renComp (wk f) (wk g)) t) ≅⟨ cong lam (rencomp (wk f) (wk g) t) ⟩ lam (ren (wk f) (ren (wk g) t)) ∎ -- Substitutions Sub : ℕ → ℕ → Set Sub m n = Fin m → Tm n -- Weaken a substitution to push it under a lambda lift : ∀{m n} → Sub m n → Sub (suc m) (suc n) lift f zero = var zero lift f (suc i) = ren suc (f i) -- Perform substitution on an expression sub : ∀{m n} → Sub m n → Tm m → Tm n sub f (var i) = f i sub f (app t u) = app (sub f t) (sub f u) sub f (lam t) = lam (sub (lift f) t) -- Identity substitution subId : ∀{n} → Sub n n subId = var -- Composition of substitutions subComp : ∀{m n o} → Sub n o → Sub m n → Sub m o subComp f g = sub f ∘ g -- lift is an endofunctor on substitutions and sub is a functor, we -- need some auxilary lemmas for the composition cases -- the conditions for identity are easy liftid : ∀{n}(i : Fin (suc n)) → lift subId i ≅ subId i liftid zero = refl liftid (suc i) = refl subid : ∀{n}(t : Tm n) → sub subId t ≅ id t subid (var i) = refl subid (app t u) = proof app (sub subId t) (sub subId u) ≅⟨ cong₂ app (subid t) (subid u) ⟩ app t u ∎ subid (lam t) = proof lam (sub (lift subId) t) ≅⟨ cong lam (cong (λ f → sub f t) (ext liftid)) ⟩ lam (sub subId t) ≅⟨ cong lam (subid t) ⟩ lam t ∎ -- for composition of subs (subcomp) and lifts (liftcomp) we need two -- lemmas about how renaming and subs interact for these two lemmas we -- need two lemmas about how lift and wk interact. liftwk : ∀{m n o}(f : Sub n o)(g : Ren m n)(i : Fin (suc m)) → (lift f ∘ wk g) i ≅ lift (f ∘ g) i liftwk f g zero = refl liftwk f g (suc i) = refl subren : ∀{m n o}(f : Sub n o)(g : Ren m n)(t : Tm m) → (sub f ∘ ren g) t ≅ sub (f ∘ g) t subren f g (var i) = refl subren f g (app t u) = proof app (sub f (ren g t)) (sub f (ren g u)) ≅⟨ cong₂ app (subren f g t) (subren f g u) ⟩ app (sub (f ∘ g) t) (sub (f ∘ g) u) ∎ subren f g (lam t) = proof lam (sub (lift f) (ren (wk g) t)) ≅⟨ cong lam (subren (lift f) (wk g) t) ⟩ lam (sub (lift f ∘ wk g) t) ≅⟨ cong lam (cong (λ f₁ → sub f₁ t) (ext (liftwk f g))) ⟩ lam (sub (lift (f ∘ g)) t) ∎ renwklift : ∀{m n o}(f : Ren n o)(g : Sub m n)(i : Fin (suc m)) → (ren (wk f) ∘ lift g) i ≅ lift (ren f ∘ g) i renwklift f g zero = refl renwklift f g (suc i) = proof ren (wk f) (ren suc (g i)) ≅⟨ sym (rencomp (wk f) suc (g i)) ⟩ ren (wk f ∘ suc) (g i) ≡⟨⟩ ren (suc ∘ f) (g i) ≅⟨ rencomp suc f (g i) ⟩ ren suc (ren f (g i)) ∎ rensub : ∀{m n o}(f : Ren n o)(g : Sub m n)(t : Tm m) → (ren f ∘ sub g) t ≅ sub (ren f ∘ g) t rensub f g (var i) = refl rensub f g (app t u) = proof app (ren f (sub g t)) (ren f (sub g u)) ≅⟨ cong₂ app (rensub f g t) (rensub f g u) ⟩ app (sub (ren f ∘ g) t) (sub (ren f ∘ g) u) ∎ rensub f g (lam t) = proof lam (ren (wk f) (sub (lift g) t)) ≅⟨ cong lam (rensub (wk f) (lift g) t) ⟩ lam (sub (ren (wk f) ∘ (lift g)) t) ≅⟨ cong (λ f → lam (sub f t)) (ext (renwklift f g)) ⟩ lam (sub (lift (ren f ∘ g)) t) ∎ liftcomp : ∀{m n o}(f : Sub n o)(g : Sub m n)(i : Fin (suc m)) → lift (subComp f g) i ≅ subComp (lift f) (lift g) i liftcomp f g zero = refl liftcomp f g (suc i) = proof ren suc (sub f (g i)) ≅⟨ rensub suc f (g i) ⟩ sub (ren suc ∘ f) (g i) ≅⟨ sym (subren (lift f) suc (g i)) ⟩ sub (lift f) (ren suc (g i)) ∎ subcomp : ∀{m n o}(f : Sub n o)(g : Sub m n)(t : Tm m) → sub (subComp f g) t ≅ (sub f ∘ sub g) t subcomp f g (var i) = refl subcomp f g (app t u) = proof app (sub (subComp f g) t) (sub (subComp f g) u) ≅⟨ cong₂ app (subcomp f g t) (subcomp f g u) ⟩ app (sub f (sub g t)) (sub f (sub g u)) ∎ subcomp f g (lam t) = proof lam (sub (lift (subComp f g)) t) ≅⟨ cong (λ f → lam (sub f t)) (ext (liftcomp f g)) ⟩ lam (sub (subComp (lift f)(lift g)) t) ≅⟨ cong lam (subcomp (lift f) (lift g) t) ⟩ lam (sub (lift f) (sub (lift g) t)) ∎ TmRMonad : RMonad FinF TmRMonad = record { T = Tm; η = var; bind = sub; law1 = ext subid; law2 = refl; law3 = ext (subcomp _ _)} -- module open import RMonads.Modules -- any functor is a relative monad over itself (including FinF) FinMonad : RMonad FinF FinMonad = trivRM FinF -- TM is module for Fin Monad This is not exactly the same as the TmModFin : Mod FinMonad TmModFin = mod Tm ren (ext renid) (ext (rencomp _ _)) -- in fact, any suitable functor is a module over FinMonad FModFin' : (F : Fun Nats Sets) → Mod FinMonad FModFin' F = ModF (\ h → h , refl) id F
{ "alphanum_fraction": 0.5562093527, "avg_line_length": 25.9357429719, "ext": "agda", "hexsha": "d518da91052747bdea51fd2ec3eabd569e662381", "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": "WellScopedTerms.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": "WellScopedTerms.agda", "max_line_length": 70, "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": "WellScopedTerms.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": 2727, "size": 6458 }
{-# OPTIONS --rewriting #-} {-# OPTIONS --confluence-check #-} open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite record R : Set where eta-equality constructor c R' = R postulate D : Set d : D f : R' → D -- = R → D x : R r : f x ≡ d {-# REWRITE r #-} -- SUCCEEDS: _ : f c ≡ d _ = refl -- FAILS: _ : f x ≡ d _ = refl -- (*) cong : (y : R') → x ≡ y → f x ≡ f y cong _ refl = refl -- SUCCEEDS: _ : f x ≡ f c _ = cong c refl -- FAILS: _ : f x ≡ f c _ = refl -- = cong c refl
{ "alphanum_fraction": 0.5313092979, "avg_line_length": 13.175, "ext": "agda", "hexsha": "ac1197f7f158a086db003326ff992ff7f2bf1382", "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/Issue4382.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/Issue4382.agda", "max_line_length": 41, "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/Issue4382.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": 207, "size": 527 }
------------------------------------------------------------------------ -- "Lenses" defined using bijections ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} import Equality.Path as P module Lens.Non-dependent.Bijection {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Prelude open import Bijection equality-with-J using (_↔_) open import Equality.Path.Isomorphisms eq hiding (univ) open import Equivalence equality-with-J as Eq using (_≃_) open import Function-universe equality-with-J as F open import H-level equality-with-J open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq open import Surjection equality-with-J using (_↠_) open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq import Lens.Non-dependent.Higher eq as Higher import Lens.Non-dependent.Traditional eq as Traditional private variable a b : Level -- A "naive" definition of lenses using a bijection. -- -- This definition is not in general isomorphic to Higher.Lens A B, -- not even if A and B are sets (consider the case in which A and B -- are empty; see ¬Higher-lens↠Lens below). Lens : Set a → Set b → Set (lsuc (a ⊔ b)) Lens {a = a} {b = b} A B = ∃ λ (R : Set (a ⊔ b)) → A ↔ (R × B) instance -- The lenses defined above have getters and setters. has-getter-and-setter : Has-getter-and-setter (Lens {a = a} {b = b}) has-getter-and-setter = record { get = λ (_ , bij) a → proj₂ (_↔_.to bij a) ; set = λ (_ , bij) a b → _↔_.from bij (proj₁ (_↔_.to bij a) , b) } -- Lens ⊥ ⊥ is isomorphic to Set something. Lens-⊥-⊥↔Set : Lens (⊥ {ℓ = a}) (⊥ {ℓ = b}) ↔ Set (a ⊔ b) Lens-⊥-⊥↔Set = Lens ⊥ ⊥ ↔⟨ (∃-cong λ _ → Eq.↔↔≃ ext (mono₁ 1 ⊥-propositional)) ⟩ (∃ λ R → ⊥ ≃ (R × ⊥)) ↔⟨ (∃-cong λ _ → Eq.≃-preserves-bijections ext F.id ×-right-zero) ⟩ (∃ λ R → ⊥ ≃ ⊥₀) ↔⟨ (∃-cong λ _ → ≃⊥≃¬ ext) ⟩ (∃ λ R → ¬ ⊥) ↔⟨ drop-⊤-right (λ _ → ¬⊥↔⊤ {k = bijection} ext) ⟩□ Set _ □ -- There is a split surjection from Lens A B to Higher.Lens A B -- (assuming univalence). Lens↠Higher-lens : {A : Set a} {B : Set b} → Univalence (a ⊔ b) → Lens A B ↠ Higher.Lens A B Lens↠Higher-lens {A = A} {B} univ = record { logical-equivalence = record { to = λ { (R , A↔R×B) → Higher.isomorphism-to-lens A↔R×B } ; from = λ { l → R l , _≃_.bijection (equiv l) } } ; right-inverse-of = λ { l → _↔_.from (Higher.equality-characterisation₂ univ) ( (R l × ∥ B ∥ ↔⟨ drop-⊤-right (λ r → inhabited⇒∥∥↔⊤ (inhabited l r)) ⟩□ R l □) , λ _ → refl _ ) } } where open Higher.Lens -- However, there is in general no split surjection in the other -- direction, not even for sets (assuming univalence). ¬Higher-lens↠Lens : Univalence (a ⊔ b) → ¬ ({A : Set a} {B : Set b} → Is-set A → Is-set B → Higher.Lens A B ↠ Lens A B) ¬Higher-lens↠Lens univ surj = ⊥-elim (subst F.id ⊤≡⊥ _) where ⊥-is-set : ∀ {ℓ} → Is-set (⊥ {ℓ = ℓ}) ⊥-is-set = mono₁ 1 ⊥-propositional ⊤↠Set = ⊤ ↔⟨ inverse $ Higher.lens-from-⊥↔⊤ univ ⟩ Higher.Lens ⊥ ⊥ ↝⟨ surj ⊥-is-set ⊥-is-set ⟩ Lens ⊥ ⊥ ↔⟨ Lens-⊥-⊥↔Set ⟩□ Set _ □ ⊤≡⊥ : ↑ _ ⊤ ≡ ⊥ ⊤≡⊥ = ↑ _ ⊤ ≡⟨ sym $ right-inverse-of _ ⟩ to (from (↑ _ ⊤)) ≡⟨⟩ to (from ⊥) ≡⟨ right-inverse-of _ ⟩∎ ⊥ ∎ where open _↠_ ⊤↠Set -- The split surjection Lens↠Higher-lens preserves getters and -- setters. Lens↠Higher-lens-preserves-getters-and-setters : {A : Set a} {B : Set b} (univ : Univalence (a ⊔ b)) → Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence (Lens↠Higher-lens univ)) Lens↠Higher-lens-preserves-getters-and-setters univ = (λ _ → refl _ , refl _) , (λ _ → refl _ , refl _)
{ "alphanum_fraction": 0.5570995452, "avg_line_length": 30.921875, "ext": "agda", "hexsha": "441f9fca32ab031c44c4d9129fc9ffc6cc9b31a8", "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": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Saizan/dependent-lenses", "max_forks_repo_path": "src/Lens/Non-dependent/Bijection.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "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": "Saizan/dependent-lenses", "max_issues_repo_path": "src/Lens/Non-dependent/Bijection.agda", "max_line_length": 92, "max_stars_count": null, "max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Saizan/dependent-lenses", "max_stars_repo_path": "src/Lens/Non-dependent/Bijection.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1465, "size": 3958 }
module STLCRef.Semantics where -- This file contains the definitional interpreter for STLC+Ref -- described in Section 3 of the paper. open import Agda.Primitive open import Data.Unit open import Data.Nat hiding (_⊔_ ; _^_) open import Data.Integer hiding (_⊔_) open import Data.List open import Data.List.Properties.Extra open import Data.List.All.Properties.Extra open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any open import Data.List.Relation.Unary.All as All open import Data.List.Prefix open import Data.Product open import Data.Maybe hiding (_>>=_) open import Function open import Common.Weakening ------------ -- SYNTAX -- ------------ -- These definitions correspond to Section 3.1, except we have -- included numbers (integers) and integer operations in the language. data Ty : Set Ctx = List Ty data Ty where _⇒_ : (a b : Ty) → Ty unit : Ty int : Ty ref : Ty -> Ty data Expr (Γ : List Ty) : Ty → Set where unit : Expr Γ unit var : ∀ {t} → t ∈ Γ → Expr Γ t ƛ : ∀ {a b} → Expr (a ∷ Γ) b → Expr Γ (a ⇒ b) _·_ : ∀ {a b} → Expr Γ (a ⇒ b) → Expr Γ a → Expr Γ b num : ℤ → Expr Γ int iop : (ℤ → ℤ → ℤ) → (l r : Expr Γ int) → Expr Γ int ifz : ∀ {t} → Expr Γ int → Expr Γ t → Expr Γ t → Expr Γ t ref : ∀ {t} → Expr Γ t → Expr Γ (ref t) !_ : ∀ {t} → Expr Γ (ref t) → Expr Γ t _≔_ : ∀ {t} → Expr Γ (ref t) → Expr Γ t → Expr Γ unit ----------------------- -- STORES AND VALUES -- ----------------------- StoreTy = List Ty mutual data Val : Ty → (Σ : StoreTy) → Set where loc : ∀ {Σ t} → t ∈ Σ → Val (ref t) Σ unit : ∀ {Σ} → Val unit Σ ⟨_,_⟩ : ∀ {Σ Γ a b} → Expr (a ∷ Γ) b → Env Γ Σ → Val (a ⇒ b) Σ num : ∀ {Σ} → ℤ → Val int Σ Env : (Γ : Ctx)(Σ : StoreTy) → Set Env Γ Σ = All (λ t → Val t Σ) Γ Store : (Σ : StoreTy) → Set Store Σ = All (λ t → Val t Σ) Σ -- The `lookup-store` function is defined in terms of the `lookup` -- function from `Data.List.All` in the Agda Standard Library. lookup-store : ∀ {Σ t} → t ∈ Σ → Store Σ → Val t Σ lookup-store x μ = All.lookup μ x -- The `update-store` function is defined in terms of the update -- function for the `All` type: `_All[_]≔'_` from the Standard Library -- extension (contained in the `lib/*` folder of this artifact). update-store : ∀ {Σ t} → t ∈ Σ → Val t Σ → Store Σ → Store Σ update-store ptr v μ = μ All.[ ptr ]≔ v ----------- -- MONAD -- ----------- -- These definitions correspond to Section 3.3. M : ∀ {i}(Γ : Ctx) → (p : StoreTy → Set i) → (Σ : StoreTy) → Set i M Γ p Σ = Env Γ Σ → Store Σ → Maybe (∃ λ Σ' → Store Σ' × p Σ' × Σ ⊑ Σ') mutual weaken-val : ∀ {a}{Σ Σ' : StoreTy} → Σ ⊑ Σ' → Val a Σ → Val a Σ' weaken-val ext unit = unit weaken-val ext (loc l) = loc (∈-⊒ l ext) weaken-val ext ⟨ e , E ⟩ = ⟨ e , weaken-env ext E ⟩ weaken-val ext (num z) = num z weaken-env : ∀ {Γ}{Σ Σ' : StoreTy} → Σ ⊑ Σ' → Env Γ Σ → Env Γ Σ' weaken-env ext (v ∷ vs) = weaken-val ext v ∷ weaken-env ext vs weaken-env ext [] = [] -- The definition below asserts that values can be weakened, by adding -- an instance argument of `Weakenable (Val t)`. -- -- Here, `Weakenable` is defined as in the paper Section 3.4; see -- `Common.Weakening` in this artifact. instance weaken-val' : ∀ {t} → Weakenable (Val t) weaken-val' = record { wk = weaken-val } return : ∀ {Σ Γ}{p : List Ty → Set} → p Σ → M Γ p Σ return x E μ = just (_ , μ , x , ⊑-refl) _>>=_ : ∀ {Σ Γ}{p q : StoreTy → Set} →   (f : M Γ p Σ) → (g : ∀ {Σ'} → p Σ' → M Γ q Σ') → M Γ q Σ (f >>= c) E μ = case (f E μ) of λ{ nothing → nothing ; (just (_ , μ' , x , ext)) → case (c x (weaken-env ext E) μ') of λ{ nothing → nothing ; (just (_ , μ'' , y , ext')) → just (_ , μ'' , y , ext ⊚ ext') }} getEnv : ∀ {Σ Γ} → M Γ (Env Γ) Σ getEnv E = return E E usingEnv : ∀ {Σ Γ Γ'}{p : List Ty → Set} → Env Γ Σ → M Γ p Σ → M Γ' p Σ usingEnv E f _ = f E timeout : ∀ {Σ Γ}{p : List Ty → Set} → M Γ p Σ timeout _ _ = nothing store : ∀ {Σ t Γ} → Val t Σ → M Γ (Val (ref t)) Σ store {Σ} {t} v _ μ = let ext = ∷ʳ-⊒ t Σ v' = loc (∈-∷ʳ Σ t) μ' = (All.map (weaken-val ext) μ) all-∷ʳ (weaken-val ext v) in just (_ , μ' , v' , ext) deref : ∀ {Σ Γ t} → t ∈ Σ → M Γ (Val t) Σ deref x E μ = return (All.lookup μ x) E μ update : ∀ {Σ Γ t} → t ∈ Σ → Val t Σ → M Γ (λ _ → ⊤) Σ update x v E μ = return tt E (update-store x v μ) weaken : ∀ {i}{p : List Ty → Set i}⦃ w : Weakenable p ⦄ → ∀ {Σ Σ'} → Σ ⊑ Σ' → p Σ → p Σ' weaken ⦃ w ⦄ ext v = Weakenable.wk w ext v -------------------------------- -- STRONG MONADIC INTERPRETER -- -------------------------------- -- These definitions correspond to Section 3.4. -- -- The definition of `_^_` below is defined in terms of the `_⊗_` -- type, which is defined in `Common.Weakening` in this artifact. _^_ : ∀ {Σ Γ}{p q : StoreTy → Set} → ⦃ w : Weakenable q ⦄ → M Γ p Σ → q Σ → M Γ (p ⊗ q) Σ (f ^ x) E μ = case (f E μ) of λ { nothing → nothing ; (just (Σ , μ' , y , ext)) → just (Σ , μ' , (y , weaken ext x) , ext) } eval : ℕ → ∀ {Σ Γ t} → Expr Γ t → M Γ (Val t) Σ eval zero _ = timeout eval (suc k) unit = return unit eval (suc k) (var x) = getEnv >>= λ E → return (All.lookup E x) eval (suc k) (ƛ e) = getEnv >>= λ E → return ⟨ e , E ⟩ eval (suc k) (l · r) = eval k l >>= λ{ ⟨ e , E ⟩ → (eval k r ^ E) >>= λ{ (v , E) → usingEnv (v ∷ E) (eval k e) }} eval (suc k) (num x) = return (num x) eval (suc k) (iop f l r) = eval k l >>= λ{ (num vₗ) → eval k r >>= λ{ (num vᵣ) → return (num (f vₗ vᵣ)) }} eval (suc k) (ifz c t e) = eval k c >>= λ{ (num z) → case z of λ{ (+ zero) → eval k t ; _ → eval k e }} eval (suc k) (ref e) = eval k e >>= λ v → store v eval (suc k) (! e) = eval k e >>= λ{ (loc l) → deref l } eval (suc k) (r ≔ e) = eval k r >>= λ{ (loc l) → (eval k e ^ l) >>= λ{ (v , l) → update l v >>= λ _ → return unit }}
{ "alphanum_fraction": 0.5277823851, "avg_line_length": 29.5539215686, "ext": "agda", "hexsha": "d65c794a1b64626984615d7f0229d9529d077f11", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/STLCRef/Semantics.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/STLCRef/Semantics.agda", "max_line_length": 90, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/STLCRef/Semantics.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 2349, "size": 6029 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Setoids.Setoids open import Functions.Definition open import Groups.Definition open import Sets.EquivalenceRelations open import Groups.Homomorphisms.Definition module Groups.Homomorphisms.Examples where identityHom : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+A_ : A → A → A} (G : Group S _+A_) → GroupHom G G id GroupHom.groupHom (identityHom {S = S} G) = Equivalence.reflexive (Setoid.eq S) GroupHom.wellDefined (identityHom G) = id
{ "alphanum_fraction": 0.7297830375, "avg_line_length": 36.2142857143, "ext": "agda", "hexsha": "71fb1fe2c81b8c5dcafc731ce8a6a6a5c3bfa3b8", "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": "Groups/Homomorphisms/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": "Groups/Homomorphisms/Examples.agda", "max_line_length": 114, "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": "Groups/Homomorphisms/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": 155, "size": 507 }
module RMonads.Restriction where open import Library open import Categories open import Functors open import Naturals open import Monads open import RMonads open Cat open Fun restrictM : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}(J : Fun C D) → Monad D → RMonad J restrictM J M = record { T = T ∘ OMap J; η = η; bind = bind; law1 = law1; law2 = law2; law3 = law3} where open Monad M open import Monads.MonadMorphs open import RMonads.RMonadMorphs restrictMM : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{M M' : Monad D} (J : Fun C D) → MonadMorph M M' → RMonadMorph (restrictM J M) (restrictM J M') restrictMM J MM = record { morph = λ{X} → morph {OMap J X}; lawη = lawη; lawbind = lawbind} where open MonadMorph MM open import Adjunctions open import RAdjunctions restrictA : ∀{a b c d e f}{C : Cat {a}{b}}{D : Cat {c}{d}}{E : Cat {e}{f}} (J : Fun C D) → Adj D E → RAdj J E restrictA J A = record{ L = L ○ J; R = R; left = left; right = right; lawa = lawa; lawb = lawb; natleft = natleft ∘ HMap J; natright = natright ∘ HMap J} where open Adj A
{ "alphanum_fraction": 0.5794785534, "avg_line_length": 23.78, "ext": "agda", "hexsha": "ea822d01db394524a904b9463dd4fc60d88dd27a", "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": "RMonads/Restriction.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": "RMonads/Restriction.agda", "max_line_length": 74, "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": "RMonads/Restriction.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": 434, "size": 1189 }
------------------------------------------------------------------------ -- Pure type systems (PTS) ------------------------------------------------------------------------ -- This file contains some core definitions which are reexported by -- Pts.Typing module Pts.Core where open import Data.Fin.Substitution.Typed open import Data.Product using (∃) import Pts.Syntax -- Instances of pure type systems. record PTS : Set₁ where -- The following predicates represent the set of sorts, axioms and -- rules, respectively. field Sort : Set -- sorts Axiom : Sort → Sort → Set -- axioms Rule : Sort → Sort → Sort → Set -- rules -- Convenience aliases of modules in Pts.Syntax. module Syntax = Pts.Syntax.Syntax Sort module Substitution = Pts.Syntax.Substitution Sort module Ctx = Pts.Syntax.Ctx Sort open Syntax open Ctx -- Abstract well-formed typing contexts. module WfCtx (_⊢_∈_ : Typing Term Term Term) where -- Well-formedness of terms/types. _⊢_wf : Wf Term Γ ⊢ a wf = ∃ λ s → Γ ⊢ a ∈ sort s -- FIXME: the following definition should not be necessary. -- -- Instead, it should be sufficient to directly open the module -- WellFormedContext like so: -- -- open WellFormedContext _⊢_wf public -- -- but there is currently a bug that prevents us from doing so. -- See https://github.com/agda/agda/issues/2901 _wf : ∀ {n} → Ctx n → Set _wf = WellFormedContext._wf _⊢_wf open WellFormedContext _⊢_wf public hiding (_wf)
{ "alphanum_fraction": 0.5879396985, "avg_line_length": 29.4814814815, "ext": "agda", "hexsha": "27aa86a7c3c7acb640c8f708a27eb7c09de2dd90", "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/Core.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/Core.agda", "max_line_length": 72, "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/Core.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": 404, "size": 1592 }
-- Andreas, 2016-02-09, issue reported by Anton Setzer -- {-# OPTIONS -v tc.conv.infer:30 -v tc.deftype:30 #-} {-# OPTIONS --allow-unsolved-metas #-} data ⊥ : Set where data MaybeSet : Set₁ where nothing : MaybeSet just : Set → MaybeSet -- not injective FromJust : MaybeSet → Set FromJust nothing = ⊥ FromJust (just A) = A R0 : ⊥ → Set R0 () data C1 (A : Set) : Set where c1 : ⊥ → C1 A -- R1 is projection-like R1 : (A : Set) → C1 A → Set R1 A (c1 c) = R0 c -- R1 A (c1 ()) -- no int. err. record Iface : Set₁ where field Command : Set Response : Command → Set I1 : (A : Set) → Iface Iface.Command (I1 A) = C1 A Iface.Response (I1 A) = R1 A -- Iface.Response (I1 A) (c1 c) = R0 c -- no int.err. -- I1 A = record { Command = C1 A; Response = R1 A } -- no. int. err postulate IO : Iface → Set data C2 (s : MaybeSet) : Set₁ where c2 : (FromJust s → IO (I1 (FromJust s))) → C2 s data IOˢ : MaybeSet → Set₁ where do : {s : MaybeSet} (c : C2 s) → IOˢ s postulate bla : Set → ⊥ → IO (I1 ⊥) test : IOˢ nothing test = do (c2 (bla {!!}))
{ "alphanum_fraction": 0.5849582173, "avg_line_length": 20.320754717, "ext": "agda", "hexsha": "2793605da3c3cedb90a9830653b5d543c90be2aa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Succeed/Issue1825.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Succeed/Issue1825.agda", "max_line_length": 68, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/Issue1825.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": 425, "size": 1077 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Cocones where open import Level open import Categories.Category open import Categories.Functor hiding (_∘_; _≡_; equiv; id; assoc; identityˡ; identityʳ; ∘-resp-≡) open import Categories.Cocone record CoconeMorphism {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} {F : Functor J C} (c₁ c₂ : Cocone F) : Set (ℓ ⊔ e ⊔ o′ ⊔ ℓ′) where module c₁ = Cocone c₁ module c₂ = Cocone c₂ module C = Category C module J = Category J open C field f : C [ c₁.N , c₂.N ] .commute : ∀ {X} → f ∘ c₁.ψ X ≡ c₂.ψ X Cocones : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} (F : Functor J C) → Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′) (ℓ ⊔ e ⊔ o′ ⊔ ℓ′) e Cocones {C = C} F = record { Obj = Obj′ ; _⇒_ = Hom′ ; _≡_ = _≡′_ ; _∘_ = _∘′_ ; id = record { f = id; commute = identityˡ } ; assoc = assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; equiv = record { refl = Equiv.refl ; sym = Equiv.sym ; trans = Equiv.trans } ; ∘-resp-≡ = ∘-resp-≡ } where open Category C open Cocone open CoconeMorphism open Functor F infixr 9 _∘′_ infix 4 _≡′_ Obj′ = Cocone F Hom′ : Obj′ → Obj′ → Set _ Hom′ = CoconeMorphism _≡′_ : ∀ {A B} → Hom′ A B → Hom′ A B → Set _ F ≡′ G = f F ≡ f G _∘′_ : ∀ {A B C} → Hom′ B C → Hom′ A B → Hom′ A C _∘′_ {A} {B} {C} F G = record { f = f F ∘ f G ; commute = commute′ } where .commute′ : ∀ {X} → (f F ∘ f G) ∘ ψ A X ≡ ψ C X commute′ {X} = begin (f F ∘ f G) ∘ ψ A X ↓⟨ assoc ⟩ f F ∘ (f G ∘ ψ A X) ↓⟨ ∘-resp-≡ʳ (CoconeMorphism.commute G) ⟩ f F ∘ ψ B X ↓⟨ CoconeMorphism.commute F ⟩ ψ C X ∎ where open HomReasoning
{ "alphanum_fraction": 0.5154867257, "avg_line_length": 24.4324324324, "ext": "agda", "hexsha": "dd6842bd75db848e3b5471ccb0aff8815d7f1e20", "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/Cocones.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/Cocones.agda", "max_line_length": 152, "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/Cocones.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": 799, "size": 1808 }
open import Agda.Builtin.Bool open import Agda.Builtin.Equality record R : Set₁ where field fun : (A : Set) → A → Bool → A ≡ Bool → Bool rule : ∀ x → fun Bool false x refl ≡ false open R test : R fun test .Bool true true refl = true fun test _ _ _ _ = false rule test x = refl
{ "alphanum_fraction": 0.6237623762, "avg_line_length": 21.6428571429, "ext": "agda", "hexsha": "a82eb4ec40fd9dcf4df684a530b4093eb08ba24d", "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/Issue2964.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/Issue2964.agda", "max_line_length": 49, "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/Issue2964.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": 99, "size": 303 }
module Data.Vec.Any.Membership.Properties where open import Relation.Binary open import Data.Vec module SingleSetoid {a ℓ} (S : Setoid a ℓ) where open Setoid S renaming (Carrier to A) open import Data.Vec.Any open import Data.Vec.Any.Membership S open import Function using (flip) open import Data.Vec.Equality using (module Equality) open Equality S renaming (_≈_ to _≋_; trans to ≋-trans) ⊆-reflexive : ∀ {n m} {xs : Vec A n} {ys : Vec A m} → xs ≋ ys → xs ⊆ ys ⊆-reflexive []-cong () ⊆-reflexive (x₁≈x₂ ∷-cong eq) (here x≈x₁) = here (trans x≈x₁ x₁≈x₂) ⊆-reflexive (_ ∷-cong eq) (there p) = there (⊆-reflexive eq p) ∈′-resp-≈ : ∀ {x} → (x ≈_) Respects _≈_ ∈′-resp-≈ = flip trans ∈′-resp-≋ : ∀ {n₁ n₂ x}{xs₁ : Vec A n₁}{xs₂ : Vec A n₂} → xs₁ ≋ xs₂ → x ∈′ xs₁ → x ∈′ xs₂ ∈′-resp-≋ {xs₁ = .[]} {.[]} []-cong () ∈′-resp-≋ {xs₁ = .(_ ∷ _)} {.(_ ∷ _)} (x¹≈x² ∷-cong eq) (here x≈x₁) = here (trans x≈x₁ x¹≈x²) ∈′-resp-≋ {xs₁ = .(_ ∷ _)} {.(_ ∷ _)} (x¹≈x² ∷-cong eq) (there p) = there (∈′-resp-≋ eq p) open SingleSetoid public module DoubleSetoid {a₁ a₂ ℓ₁ ℓ₂} (S₁ : Setoid a₁ ℓ₁) (S₂ : Setoid a₂ ℓ₂) where open import Data.Vec.Any.Properties import Data.Vec.Any as Any open import Data.Product hiding (map) open Setoid S₁ renaming (Carrier to A₁; _≈_ to _≈₁_; refl to refl₁) open Setoid S₂ renaming (Carrier to A₂; _≈_ to _≈₂_) open import Data.Vec.Any.Membership S₁ renaming (_∈′_ to _∈′₁_) using (find′) open import Data.Vec.Any.Membership S₂ renaming (_∈′_ to _∈′₂_) using () ∈′-map⁺ : ∀ {n x}{xs : Vec A₁ n} {f} → f Preserves _≈₁_ ⟶ _≈₂_ → x ∈′₁ xs → f x ∈′₂ map f xs ∈′-map⁺ pres x∈′xs = map⁺ (Any.map pres x∈′xs) ∈′-map⁻ : ∀ {n y}{xs : Vec A₁ n} {f} → y ∈′₂ map f xs → ∃ λ x → x ∈′₁ xs × y ≈₂ f x ∈′-map⁻ y∈′map with find′ (map⁻ y∈′map) ... | _ , x∈xs , px = , x∈xs , px open DoubleSetoid public
{ "alphanum_fraction": 0.5518444666, "avg_line_length": 37.8490566038, "ext": "agda", "hexsha": "06a9091556abe6834f1c2e4853df7126003420e7", "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": "1a60f72b9ea1dd61845311ee97dc380aa542b874", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tizmd/agda-vector-any", "max_forks_repo_path": "src/Data/Vec/Any/Membership/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1a60f72b9ea1dd61845311ee97dc380aa542b874", "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": "tizmd/agda-vector-any", "max_issues_repo_path": "src/Data/Vec/Any/Membership/Properties.agda", "max_line_length": 97, "max_stars_count": null, "max_stars_repo_head_hexsha": "1a60f72b9ea1dd61845311ee97dc380aa542b874", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tizmd/agda-vector-any", "max_stars_repo_path": "src/Data/Vec/Any/Membership/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 851, "size": 2006 }
open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures module MLib.Matrix.Pow {c ℓ} (struct : Struct bimonoidCode c ℓ) where open import MLib.Prelude open import MLib.Matrix.Core open import MLib.Matrix.Equality struct open import MLib.Matrix.Mul struct open import MLib.Matrix.Plus struct open import MLib.Matrix.Bimonoid struct open FunctionProperties module _ {n} where open import MLib.Algebra.Operations (matrixStruct n) pow : Matrix S n n → ℕ → Matrix S n n pow M zero = 1● pow M (suc p) = M ⊗ pow M p pstar : Matrix S n n → ℕ → Matrix S n n pstar M zero = 0● pstar M (suc p) = 1● ⊕ M ⊗ pstar M p pstar′ : Matrix S n n → ℕ → Matrix S n n pstar′ M p = ∑[ q < p ] pow M (Fin.toℕ q) pstar′-unfold : ∀ {M : Matrix S n n} {p} → pstar′ M (suc p) ≈ 1● ⊕ M ⊗ pstar′ M p pstar′-unfold {M} {p} = begin pstar′ M (suc p) ≡⟨⟩ pow M (Fin.toℕ (zero {p})) ⊕ ∑[ q < p ] pow M (Fin.toℕ (suc q)) ≡⟨⟩ 1● ⊕ ∑[ q < p ] pow M (suc (Fin.toℕ q)) ≡⟨⟩ 1● ⊕ ∑[ q < p ] (M ⊗ pow M (Fin.toℕ q)) ≈⟨ ⊕-cong refl (sym (sumDistribˡ ⦃ {!!} ⦄ {p} M _)) ⟩ 1● ⊕ M ⊗ ∑[ q < p ] pow M (Fin.toℕ q) ≡⟨⟩ 1● ⊕ M ⊗ pstar′ M p ∎ where open EqReasoning setoid -- pstar-pstar′ : ∀ {M : Matrix S n n} {p} → pstar M p ≈ pstar′ M p -- pstar-pstar′ {p = zero} _ _ = S.refl -- pstar-pstar′ {M = M} {suc p} = -- begin -- ((1● ⊕ M) ⊗ pstar M p) ≈⟨ {!!} ⟩ -- pow M (Fin.toℕ (zero {p})) ⊕ (Table.foldr {n = p} _⊕_ 0● (tabulate (pow M ∘ Fin.toℕ ∘ suc))) ≡⟨⟩ -- pstar′ M (suc p) ∎ -- where open EqReasoning setoid
{ "alphanum_fraction": 0.5070185289, "avg_line_length": 37.1041666667, "ext": "agda", "hexsha": "831e34795080f77adb1ec39322788dfad68db6f4", "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": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bch29/agda-matrices", "max_forks_repo_path": "src/MLib/Matrix/Pow.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "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": "bch29/agda-matrices", "max_issues_repo_path": "src/MLib/Matrix/Pow.agda", "max_line_length": 124, "max_stars_count": null, "max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bch29/agda-matrices", "max_stars_repo_path": "src/MLib/Matrix/Pow.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 706, "size": 1781 }
------------------------------------------------------------------------------ -- Common stuff used by the gcd example ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.GCD.Total.Definitions where open import FOTC.Base open import FOTC.Data.Nat.Divisibility.By0 open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Type ------------------------------------------------------------------------------ -- Common divisor. CD : D → D → D → Set CD m n cd = cd ∣ m ∧ cd ∣ n {-# ATP definition CD #-} -- Divisible for any common divisor. Divisible : D → D → D → Set Divisible m n gcd = ∀ cd → N cd → CD m n cd → cd ∣ gcd {-# ATP definition Divisible #-} -- Greatest common divisor specification. -- The gcd is a common divisor and the gcd is divided by any common -- divisor, thefore the gcd is the greatest common divisor -- according to the partial order _∣_. gcdSpec : D → D → D → Set gcdSpec m n gcd = CD m n gcd ∧ Divisible m n gcd {-# ATP definition gcdSpec #-}
{ "alphanum_fraction": 0.5258333333, "avg_line_length": 33.3333333333, "ext": "agda", "hexsha": "53cde532c9bf70e5406df44ebbdf4c3411740929", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/GCD/Total/Definitions.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/GCD/Total/Definitions.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/GCD/Total/Definitions.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 264, "size": 1200 }
{-# OPTIONS --without-K #-} open import HoTT open import lib.cubical.elims.CubeMove module lib.cubical.elims.CofWedge where cof-wedge-path-rec : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {C : Type k} {D : Type l} {f : X ∨ Y → C} {d₁ d₂ : D} → (p : d₁ == d₂) → (q : C → d₁ == d₂) → ((x : fst X) → p == q (f (winl x))) → ((y : fst Y) → p == q (f (winr y))) → ((κ : Cofiber f) → d₁ == d₂) cof-wedge-path-rec {X = X} {Y = Y} {f = f} base* cod* winl* winr* = CofiberRec.f _ base* cod* (WedgeElim.f winl* (λ y → (winl* (snd X) ∙ ap (cod* ∘ f) wglue) ∙ ! (winr* (snd Y)) ∙ winr* y) (↓-cst=app-from-square $ disc-to-square $ ! $ ap (λ w → (winl* (snd X) ∙ ap (cod* ∘ f) wglue) ∙ w) (!-inv-l (winr* (snd Y))) ∙ ∙-unit-r _)) cof-wedge-path-elim : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {C : Type k} {D : Type l} {f : X ∨ Y → C} (g h : Cofiber f → D) → (p : g (cfbase _) == h (cfbase _)) → (q : (c : C) → g (cfcod _ c) == h (cfcod _ c)) → ((x : fst X) → Square p (ap g (cfglue _ (winl x))) (ap h (cfglue _ (winl x))) (q (f (winl x)))) → ((y : fst Y) → Square p (ap g (cfglue _ (winr y))) (ap h (cfglue _ (winr y))) (q (f (winr y)))) → ((κ : Cofiber f) → g κ == h κ) cof-wedge-path-elim {X = X} {Y = Y} {f = f} g h base* cod* winl* winr* = Cofiber-elim _ base* cod* (↓-='-from-square ∘ Wedge-elim winl* (λ y → fst fill ⊡h winr* y) (cube-to-↓-square $ cube-right-from-front _ (winr* (snd Y)) (snd fill))) where fill : Σ (Square base* idp idp base*) (λ sq' → Cube (winl* (snd X)) sq' (natural-square (λ _ → base*) wglue) (square-push-rb _ _ (natural-square (ap g ∘ cfglue _) wglue)) (square-push-rb _ _ (natural-square (ap h ∘ cfglue _) wglue)) (natural-square (cod* ∘ f) wglue ⊡h' !□h (winr* (snd Y)))) fill = fill-cube-right _ _ _ _ _ {- Note, only squares with constant endpoints. General case? -} cof-wedge-square-elim : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {C : Type k} {D : Type l} {f : X ∨ Y → C} {d₀₀ d₀₁ d₁₀ d₁₁ : D} (p₀₋ : (κ : Cofiber f) → d₀₀ == d₀₁) (p₋₀ : (κ : Cofiber f) → d₀₀ == d₁₀) (p₋₁ : (κ : Cofiber f) → d₀₁ == d₁₁) (p₁₋ : (κ : Cofiber f) → d₁₀ == d₁₁) → (base* : Square (p₀₋ (cfbase _)) (p₋₀ (cfbase _)) (p₋₁ (cfbase _)) (p₁₋ (cfbase _))) → (cod* : (c : C) → Square (p₀₋ (cfcod _ c)) (p₋₀ (cfcod _ c)) (p₋₁ (cfcod _ c)) (p₁₋ (cfcod _ c))) → ((x : fst X) → Cube base* (cod* (f (winl x))) (natural-square p₀₋ (cfglue _ (winl x))) (natural-square p₋₀ (cfglue _ (winl x))) (natural-square p₋₁ (cfglue _ (winl x))) (natural-square p₁₋ (cfglue _ (winl x)))) → ((y : fst Y) → Cube base* (cod* (f (winr y))) (natural-square p₀₋ (cfglue _ (winr y))) (natural-square p₋₀ (cfglue _ (winr y))) (natural-square p₋₁ (cfglue _ (winr y))) (natural-square p₁₋ (cfglue _ (winr y)))) → ((κ : Cofiber f) → Square (p₀₋ κ) (p₋₀ κ) (p₋₁ κ) (p₁₋ κ)) cof-wedge-square-elim p₀₋ p₋₀ p₋₁ p₁₋ base* cod* winl* winr* = disc-to-square ∘ cof-wedge-path-elim _ _ (square-to-disc base*) (square-to-disc ∘ cod*) (cube-to-disc-square ∘ winl*) (cube-to-disc-square ∘ winr*)
{ "alphanum_fraction": 0.4730242053, "avg_line_length": 38.9659090909, "ext": "agda", "hexsha": "34e53ea0ef51703a4acc35bf2906e2780fb499ad", "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": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_path": "lib/cubical/elims/CofWedge.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "danbornside/HoTT-Agda", "max_issues_repo_path": "lib/cubical/elims/CofWedge.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_path": "lib/cubical/elims/CofWedge.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1420, "size": 3429 }
{-# OPTIONS --safe #-} module Cubical.Categories.Functor.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.Sigma open import Cubical.Categories.Category private variable ℓC ℓC' ℓD ℓD' : Level record Functor (C : Category ℓC ℓC') (D : Category ℓD ℓD') : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where no-eta-equality open Category field F-ob : C .ob → D .ob F-hom : {x y : C .ob} → C [ x , y ] → D [ F-ob x , F-ob y ] F-id : {x : C .ob} → F-hom (C .id) ≡ D .id {x = F-ob x} F-seq : {x y z : C .ob} (f : C [ x , y ]) (g : C [ y , z ]) → F-hom (f ⋆⟨ C ⟩ g) ≡ (F-hom f) ⋆⟨ D ⟩ (F-hom g) isFull = (x y : _) (F[f] : D [ F-ob x , F-ob y ]) → ∃[ f ∈ C [ x , y ] ] F-hom f ≡ F[f] isFaithful = (x y : _) (f g : C [ x , y ]) → F-hom f ≡ F-hom g → f ≡ g isEssentiallySurj = (d : D .ob) → Σ[ c ∈ C .ob ] CatIso D (F-ob c) d F-square : {x y u v : C .ob} {f : C [ x , y ]} {g : C [ x , u ]} {h : C [ u , v ]} {k : C [ y , v ]} → f ⋆⟨ C ⟩ k ≡ g ⋆⟨ C ⟩ h → (F-hom f) ⋆⟨ D ⟩ (F-hom k) ≡ (F-hom g) ⋆⟨ D ⟩ (F-hom h) F-square Csquare = sym (F-seq _ _) ∙∙ cong F-hom Csquare ∙∙ F-seq _ _ private variable ℓ ℓ' : Level C D E : Category ℓ ℓ' open Category open Functor Functor≡ : {F G : Functor C D} → (h : ∀ (c : ob C) → F-ob F c ≡ F-ob G c) → (∀ {c c' : ob C} (f : C [ c , c' ]) → PathP (λ i → D [ h c i , h c' i ]) (F-hom F f) (F-hom G f)) → F ≡ G F-ob (Functor≡ hOb hHom i) c = hOb c i F-hom (Functor≡ hOb hHom i) f = hHom f i F-id (Functor≡ {C = C} {D = D} {F = F} {G = G} hOb hHom i) = isProp→PathP (λ j → isSetHom D (hHom (C .id) j) (D .id)) (F-id F) (F-id G) i F-seq (Functor≡ {C = C} {D = D} {F = F} {G = G} hOb hHom i) f g = isProp→PathP (λ j → isSetHom D (hHom (f ⋆⟨ C ⟩ g) j) ((hHom f j) ⋆⟨ D ⟩ (hHom g j))) (F-seq F f g) (F-seq G f g) i -- Helpful notation -- action on objects infix 30 _⟅_⟆ _⟅_⟆ : (F : Functor C D) → C .ob → D .ob _⟅_⟆ = F-ob -- action on morphisms infix 30 _⟪_⟫ -- same infix level as on objects since these will never be used in the same context _⟪_⟫ : (F : Functor C D) → ∀ {x y} → C [ x , y ] → D [(F ⟅ x ⟆) , (F ⟅ y ⟆)] _⟪_⟫ = F-hom -- Functor constructions 𝟙⟨_⟩ : ∀ (C : Category ℓ ℓ') → Functor C C 𝟙⟨ C ⟩ .F-ob x = x 𝟙⟨ C ⟩ .F-hom f = f 𝟙⟨ C ⟩ .F-id = refl 𝟙⟨ C ⟩ .F-seq _ _ = refl -- functor composition funcComp : ∀ (G : Functor D E) (F : Functor C D) → Functor C E (funcComp G F) .F-ob c = G ⟅ F ⟅ c ⟆ ⟆ (funcComp G F) .F-hom f = G ⟪ F ⟪ f ⟫ ⟫ (funcComp G F) .F-id = cong (G ⟪_⟫) (F .F-id) ∙ G .F-id (funcComp G F) .F-seq f g = cong (G ⟪_⟫) (F .F-seq _ _) ∙ G .F-seq _ _ infixr 30 funcComp syntax funcComp G F = G ∘F F _^opF : Functor C D → Functor (C ^op) (D ^op) (F ^opF) .F-ob = F .F-ob (F ^opF) .F-hom = F .F-hom (F ^opF) .F-id = F .F-id (F ^opF) .F-seq f g = F .F-seq g f
{ "alphanum_fraction": 0.4805414552, "avg_line_length": 29.2574257426, "ext": "agda", "hexsha": "161edd56a8b8402c3312c7a7ce364956159ce2e7", "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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_path": "Cubical/Categories/Functor/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "howsiyu/cubical", "max_issues_repo_path": "Cubical/Categories/Functor/Base.agda", "max_line_length": 116, "max_stars_count": null, "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_path": "Cubical/Categories/Functor/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1397, "size": 2955 }
module STLC.Kovacs.PresheafRefinement where open import STLC.Kovacs.Substitution public open import STLC.Kovacs.Normalisation public open import Category -------------------------------------------------------------------------------- -- (Tyᴺ-idₑ) idacc : ∀ {A Γ} → (a : Γ ⊩ A) → acc idₑ a ≡ a idacc {⎵} M = idrenⁿᶠ M idacc {A ⇒ B} f = fext¡ (fext! (λ η → f & lid○ η)) -- (Tyᴺ-∘ₑ) acc○ : ∀ {A Γ Γ′ Γ″} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (a : Γ ⊩ A) → acc (η₂ ○ η₁) a ≡ (acc η₁ ∘ acc η₂) a acc○ {⎵} η₁ η₂ M = renⁿᶠ○ η₁ η₂ M acc○ {A ⇒ B} η₁ η₂ f = fext¡ (fext! (λ η′ → f & assoc○ η′ η₁ η₂)) -- (Conᴺ-idₑ) lid⬖ : ∀ {Γ Ξ} → (ρ : Γ ⊩⋆ Ξ) → ρ ⬖ idₑ ≡ ρ lid⬖ ∅ = refl lid⬖ (ρ , a) = _,_ & lid⬖ ρ ⊗ idacc a -- (Conᴺ-∘ₑ) comp⬖○ : ∀ {Γ Γ′ Γ″ Ξ} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (ρ : Γ ⊩⋆ Ξ) → (ρ ⬖ η₂) ⬖ η₁ ≡ ρ ⬖ (η₂ ○ η₁) comp⬖○ η₁ η₂ ∅ = refl comp⬖○ η₁ η₂ (ρ , a) = _,_ & comp⬖○ η₁ η₂ ρ ⊗ (acc○ η₁ η₂ a ⁻¹) -- (∈ᴺ-nat) get⬖ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (ρ : Γ ⊩⋆ Ξ) (i : Ξ ∋ A) → getᵥ (ρ ⬖ η) i ≡ (acc η ∘ getᵥ ρ) i get⬖ η (ρ , a) zero = refl get⬖ η (ρ , a) (suc i) = get⬖ η ρ i -------------------------------------------------------------------------------- -- (Tyᴾ) 𝒰 : ∀ {A Γ} → Γ ⊩ A → Set 𝒰 {⎵} {Γ} M = ⊤ 𝒰 {A ⇒ B} {Γ} f = ∀ {Γ′} → (η : Γ′ ⊇ Γ) {a : Γ′ ⊩ A} (u : 𝒰 a) → (∀ {Γ″} → (η′ : Γ″ ⊇ Γ′) → (f (η ○ η′) ∘ acc η′) a ≡ (acc η′ ∘ f η) a) × 𝒰 (f η a) -- (Tyᴾₑ) acc𝒰 : ∀ {A Γ Γ′} → {a : Γ ⊩ A} → (η : Γ′ ⊇ Γ) → 𝒰 a → 𝒰 (acc η a) acc𝒰 {⎵} {a = M} η tt = tt acc𝒰 {A ⇒ B} {a = f} η u = λ η′ {a} u′ → let natf , u″ = u (η ○ η′) u′ in (λ η″ → (λ η‴ → (f η‴ ∘ acc η″) a) & (assoc○ η″ η′ η ⁻¹) ⦙ natf η″) , u″ -- (Conᴾ ; ∙ ; _,_) data 𝒰⋆ : ∀ {Γ Ξ} → Γ ⊩⋆ Ξ → Set where ∅ : ∀ {Γ} → 𝒰⋆ (∅ {Γ}) _,_ : ∀ {Γ Ξ A} → {ρ : Γ ⊩⋆ Ξ} {a : Γ ⊩ A} → (υ : 𝒰⋆ ρ) (u : 𝒰 a) → 𝒰⋆ (ρ , a) -- (Conᴾₑ) -- NOTE _⬖𝒰_ = acc𝒰⋆ _⬖𝒰_ : ∀ {Γ Γ′ Ξ} → {ρ : Γ ⊩⋆ Ξ} → 𝒰⋆ ρ → (η : Γ′ ⊇ Γ) → 𝒰⋆ (ρ ⬖ η) ∅ ⬖𝒰 η = ∅ (υ , u) ⬖𝒰 η = υ ⬖𝒰 η , acc𝒰 η u -------------------------------------------------------------------------------- -- (∈ᴾ) get𝒰 : ∀ {Γ Ξ A} → {ρ : Γ ⊩⋆ Ξ} → 𝒰⋆ ρ → (i : Ξ ∋ A) → 𝒰 (getᵥ ρ i) get𝒰 (υ , u) zero = u get𝒰 (υ , u) (suc i) = get𝒰 υ i mutual -- (Tmᴾ) eval𝒰 : ∀ {Γ Ξ A} → {ρ : Γ ⊩⋆ Ξ} → 𝒰⋆ ρ → (M : Ξ ⊢ A) → 𝒰 (eval ρ M) eval𝒰 {ρ = ρ} υ (𝓋 i) = get𝒰 υ i eval𝒰 {ρ = ρ} υ (ƛ M) = λ η {a} u → (λ η′ → (λ ρ′ → eval (ρ′ , acc η′ a) M) & (comp⬖○ η′ η ρ ⁻¹) ⦙ eval⬖ η′ (υ ⬖𝒰 η , u) M) , eval𝒰 (υ ⬖𝒰 η , u) M eval𝒰 {ρ = ρ} υ (M ∙ N) = proj₂ (eval𝒰 υ M idₑ (eval𝒰 υ N)) -- (Tmᴺ-nat) eval⬖ : ∀ {Γ Γ′ Ξ A} → {ρ : Γ ⊩⋆ Ξ} → (η : Γ′ ⊇ Γ) → 𝒰⋆ ρ → (M : Ξ ⊢ A) → eval (ρ ⬖ η) M ≡ (acc η ∘ eval ρ) M eval⬖ {ρ = ρ} η υ (𝓋 i) = get⬖ η ρ i eval⬖ {ρ = ρ} η υ (ƛ M) = fext¡ (fext! (λ η′ → fext! (λ a → (λ ρ′ → eval ρ′ M) & ((_, a) & comp⬖○ η′ η ρ)))) eval⬖ {ρ = ρ} η υ (M ∙ N) rewrite eval⬖ η υ M | eval⬖ η υ N = (λ η′ → eval ρ M η′ (acc η (eval ρ N))) & (rid○ η ⦙ lid○ η ⁻¹) ⦙ proj₁ (eval𝒰 υ M idₑ (eval𝒰 υ N)) η mutual -- (uᴾ) reflect𝒰 : ∀ {A Γ} → (M : Γ ⊢ⁿᵉ A) → 𝒰 (reflect M) reflect𝒰 {⎵} M = tt reflect𝒰 {A ⇒ B} M = λ η {a} u → (λ η′ → (λ M′ N′ → reflect (M′ ∙ N′)) & renⁿᵉ○ η′ η M ⊗ (natreify η′ a u) ⦙ natreflect η′ (renⁿᵉ η M ∙ reify a)) , reflect𝒰 (renⁿᵉ η M ∙ reify a) -- (qᴺ-nat) natreify : ∀ {A Γ Γ′} → (η : Γ′ ⊇ Γ) (a : Γ ⊩ A) → 𝒰 a → (reify ∘ acc η) a ≡ (renⁿᶠ η ∘ reify) a natreify {⎵} η M u = refl natreify {A ⇒ B} η f u = let natf , u′ = u (wkₑ idₑ) (reflect𝒰 0) in ƛ & ( reify & ( f & (wkₑ & ( rid○ η ⦙ lid○ η ⁻¹ )) ⊗ natreflect (liftₑ η) 0 ⦙ natf (liftₑ η) ) ⦙ natreify (liftₑ η) (f (wkₑ idₑ) (reflect 0)) u′ ) -- (uᴺ-nat) natreflect : ∀ {A Γ Γ′} → (η : Γ′ ⊇ Γ) (M : Γ ⊢ⁿᵉ A) → (reflect ∘ renⁿᵉ η) M ≡ (acc η ∘ reflect) M natreflect {⎵} η M = refl natreflect {A ⇒ B} η M = fext¡ (fext! (λ η′ → fext! (λ a → (λ M′ → reflect (M′ ∙ reify a)) & (renⁿᵉ○ η′ η M ⁻¹)))) -- (uᶜᴾ) id𝒰 : ∀ {Γ} → 𝒰⋆ (idᵥ {Γ}) id𝒰 {∅} = ∅ id𝒰 {Γ , A} = id𝒰 ⬖𝒰 wkₑ idₑ , reflect𝒰 0 -------------------------------------------------------------------------------- -- (OPEᴺ) _⬗_ : ∀ {Γ Ξ Ξ′} → Ξ′ ⊇ Ξ → Γ ⊩⋆ Ξ′ → Γ ⊩⋆ Ξ done ⬗ ρ = ρ wkₑ η ⬗ (ρ , a) = η ⬗ ρ liftₑ η ⬗ (ρ , a) = η ⬗ ρ , a -- (OPEᴺ-nat) nat⬗ : ∀ {Γ Γ′ Ξ Ξ′} → (η₁ : Γ′ ⊇ Γ) (ρ : Γ ⊩⋆ Ξ′) (η₂ : Ξ′ ⊇ Ξ) → η₂ ⬗ (ρ ⬖ η₁) ≡ (η₂ ⬗ ρ) ⬖ η₁ nat⬗ η₁ ρ done = refl nat⬗ η₁ (ρ , a) (wkₑ η₂) = nat⬗ η₁ ρ η₂ nat⬗ η₁ (ρ , a) (liftₑ η₂) = (_, acc η₁ a) & nat⬗ η₁ ρ η₂ -- (OPEᴺ-idₑ) lid⬗ : ∀ {Γ Ξ} → (ρ : Γ ⊩⋆ Ξ) → idₑ ⬗ ρ ≡ ρ lid⬗ ∅ = refl lid⬗ (ρ , a) = (_, a) & lid⬗ ρ -------------------------------------------------------------------------------- -- (∈ₑᴺ) get⬗ : ∀ {Γ Ξ Ξ′ A} → (ρ : Γ ⊩⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (i : Ξ ∋ A) → getᵥ (η ⬗ ρ) i ≡ (getᵥ ρ ∘ getₑ η) i get⬗ ρ done i = refl get⬗ (ρ , a) (wkₑ η) i = get⬗ ρ η i get⬗ (ρ , a) (liftₑ η) zero = refl get⬗ (ρ , a) (liftₑ η) (suc i) = get⬗ ρ η i -- (Tmₑᴺ) eval⬗ : ∀ {Γ Ξ Ξ′ A} → (ρ : Γ ⊩⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ ⊢ A) → eval (η ⬗ ρ) M ≡ (eval ρ ∘ ren η) M eval⬗ ρ η (𝓋 i) = get⬗ ρ η i eval⬗ ρ η (ƛ M) = fext¡ (fext! (λ η′ → fext! (λ a → (λ ρ′ → eval (ρ′ , a) M) & nat⬗ η′ ρ η ⁻¹ ⦙ eval⬗ (ρ ⬖ η′ , a) (liftₑ η) M))) eval⬗ ρ η (M ∙ N) rewrite eval⬗ ρ η M | eval⬗ ρ η N = refl -------------------------------------------------------------------------------- -- (Subᴺ) -- NOTE: _◆_ = eval⋆ _◆_ : ∀ {Γ Ξ Φ} → Ξ ⊢⋆ Φ → Γ ⊩⋆ Ξ → Γ ⊩⋆ Φ ∅ ◆ ρ = ∅ (σ , M) ◆ ρ = σ ◆ ρ , eval ρ M -- (Subᴺ-nat) comp◆⬖ : ∀ {Γ Γ′ Ξ Φ} → {ρ : Γ ⊩⋆ Ξ} → (η : Γ′ ⊇ Γ) → 𝒰⋆ ρ → (σ : Ξ ⊢⋆ Φ) → (σ ◆ ρ) ⬖ η ≡ σ ◆ (ρ ⬖ η) comp◆⬖ η υ ∅ = refl comp◆⬖ η υ (σ , M) = _,_ & comp◆⬖ η υ σ ⊗ (eval⬖ η υ M ⁻¹) -- (Subᴺ-ₛ∘ₑ) comp◆⬗ : ∀ {Γ Ξ Ξ′ Φ} → (ρ : Γ ⊩⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (σ : Ξ ⊢⋆ Φ) → (σ ◐ η) ◆ ρ ≡ σ ◆ (η ⬗ ρ) comp◆⬗ ρ η ∅ = refl comp◆⬗ ρ η (σ , M) = _,_ & comp◆⬗ ρ η σ ⊗ (eval⬗ ρ η M ⁻¹) -- (∈ₛᴺ) get◆ : ∀ {Γ Ξ Φ A} → (ρ : Γ ⊩⋆ Ξ) (σ : Ξ ⊢⋆ Φ) (i : Φ ∋ A) → getᵥ (σ ◆ ρ) i ≡ (eval ρ ∘ getₛ σ) i get◆ ρ (σ , M) zero = refl get◆ ρ (σ , M) (suc i) = get◆ ρ σ i -- (Subᴺ-idₛ) lid◆ : ∀ {Γ Ξ} → (ρ : Γ ⊩⋆ Ξ) → idₛ ◆ ρ ≡ ρ lid◆ ∅ = refl lid◆ (ρ , a) = (_, a) & ( comp◆⬗ (ρ , a) (wkₑ idₑ) idₛ ⦙ lid◆ (idₑ ⬗ ρ) ⦙ lid⬗ ρ ) -------------------------------------------------------------------------------- accPsh : 𝒯 → Presheaf₀ 𝗢𝗣𝗘 accPsh A = record { Fₓ = _⊩ A ; F = acc ; idF = fext! idacc ; F⋄ = λ η₁ η₂ → fext! (acc○ η₂ η₁) } flip⬖Psh : 𝒞 → Presheaf₀ 𝗢𝗣𝗘 flip⬖Psh Ξ = record { Fₓ = _⊩⋆ Ξ ; F = flip _⬖_ ; idF = fext! lid⬖ ; F⋄ = λ η₁ η₂ → fext! (λ ρ → comp⬖○ η₂ η₁ ρ ⁻¹) } getᵥNT : ∀ {Ξ A} → (i : Ξ ∋ A) → NaturalTransformation (flip⬖Psh Ξ) (accPsh A) getᵥNT i = record { N = flip getᵥ i ; natN = λ η → fext! (λ ρ → get⬖ η ρ i) } -- TODO -- evalNT : ∀ {Ξ A} → (M : Ξ ⊢ A) -- → NaturalTransformation (flip⬖Psh Ξ) (accPsh A) -- evalNT M = -- record -- { N = flip eval M -- ; natN = λ η → fext! (λ ρ → eval⬖ {ρ = ρ} η {!!} M) -- } -- TODO -- reifyNT : ∀ {A} → NaturalTransformation (accPsh A) (renⁿᶠPsh A) -- reifyNT = -- record -- { N = reify -- ; natN = λ η → fext! (λ a → natreify η a {!!}) -- } reflectNT : ∀ {A} → NaturalTransformation (renⁿᵉPsh A) (accPsh A) reflectNT = record { N = reflect ; natN = λ η → fext! (λ M → natreflect η M) } --------------------------------------------------------------------------------
{ "alphanum_fraction": 0.2991278131, "avg_line_length": 29.8617363344, "ext": "agda", "hexsha": "1e2c532eae2879425f07a0e4b1703d6863d2ff87", "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": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/coquand-kovacs", "max_forks_repo_path": "src/STLC/Kovacs/PresheafRefinement.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/coquand-kovacs", "max_issues_repo_path": "src/STLC/Kovacs/PresheafRefinement.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/coquand-kovacs", "max_stars_repo_path": "src/STLC/Kovacs/PresheafRefinement.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4709, "size": 9287 }
------------------------------------------------------------------------ -- A combinator for running two (independent) computations in sequence ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Delay-monad.Sequential where open import Equality.Propositional as Eq using (_≡_) open import Prelude hiding (_+_) open import Prelude.Size open import Conat Eq.equality-with-J as Conat using (zero; suc; force; _+_) open import Delay-monad open import Delay-monad.Bisimilarity open import Delay-monad.Bisimilarity.Kind open import Delay-monad.Monad private variable a : Level A B C : Type a i : Size k : Kind f₁ f₂ : Delay (A → B) ∞ x x₁ x₂ y y₁ y₂ : Delay A ∞ f′ : Delay′ (A → B) ∞ x′ : Delay′ A ∞ h : A → B z : A ------------------------------------------------------------------------ -- The _⊛_ operator -- Sequential composition of computations. infixl 6 _⊛_ _⊛_ : Delay (A → B) i → Delay A i → Delay B i f ⊛ x = f >>=′ λ f → x >>=′ λ x → now (f x) -- The number of later constructors in f ⊛ x is bisimilar to the sum -- of the number of later constructors in f and the number of later -- constructors in x. steps-⊛∼steps-+-steps : (f : Delay (A → B) ∞) → Conat.[ i ] steps (f ⊛ x) ∼ steps f + steps x steps-⊛∼steps-+-steps {x = now _} (now _) = zero steps-⊛∼steps-+-steps {x = later _} (now _) = suc λ { .force → steps-⊛∼steps-+-steps (now _) } steps-⊛∼steps-+-steps (later f) = suc λ { .force → steps-⊛∼steps-+-steps (f .force) } -- A rearrangement lemma for _⊛_. later-⊛∼⊛-later : [ i ] later f′ ⊛ x′ .force ∼ f′ .force ⊛ later x′ later-⊛∼⊛-later = lemma _ Eq.refl where lemma : ∀ f → f′ .force ≡ f → [ i ] later f′ ⊛ x′ .force ∼ f ⊛ later x′ lemma {f′ = f′} {x′ = x′} (now f) eq = later λ { .force → f′ .force ⊛ x′ .force ≡⟨ Eq.cong (_⊛ x′ .force) eq ⟩ now f ⊛ x′ .force ∎ } lemma {f′ = f′} {x′ = x′} (later f) eq = later λ { .force → f′ .force ⊛ x′ .force ≡⟨ Eq.cong (_⊛ x′ .force) eq ⟩ later f ⊛ x′ .force ∼⟨ later-⊛∼⊛-later ⟩∼ f .force ⊛ later x′ ∎ } -- The _⊛_ operator preserves strong and weak bisimilarity and -- expansion. infixl 6 _⊛-cong_ _⊛-cong_ : [ i ] f₁ ⟨ k ⟩ f₂ → [ i ] x₁ ⟨ k ⟩ x₂ → [ i ] f₁ ⊛ x₁ ⟨ k ⟩ f₂ ⊛ x₂ p ⊛-cong q = p >>=-cong λ _ → q >>=-cong λ _ → now -- The _⊛_ operator is (kind of) commutative. ⊛-comm : (f : Delay (A → B) ∞) (x : Delay A ∞) → [ i ] f ⊛ x ∼ map′ (flip _$_) x ⊛ f ⊛-comm (now f) (now x) = reflexive _ ⊛-comm (now f) (later x) = later λ { .force → ⊛-comm (now f) (x .force) } ⊛-comm (later f) (now x) = later λ { .force → ⊛-comm (f .force) (now x) } ⊛-comm (later f) (later x) = later λ { .force → f .force ⊛ later x ∼⟨ symmetric later-⊛∼⊛-later ⟩ later f ⊛ x .force ∼⟨ ⊛-comm (later f) (x .force) ⟩∼ map′ (flip _$_) (x .force) ⊛ later f ∎ } -- The function map′ can be expressed using _⊛_. map∼now-⊛ : (x : Delay A ∞) → [ i ] map′ h x ∼ now h ⊛ x map∼now-⊛ {h = h} x = map′ h x ∼⟨ map∼>>=-now _ ⟩ (x >>=′ now ∘ h) ∼⟨⟩ (now h >>=′ λ h → x >>=′ now ∘ h) ∼⟨⟩ now h ⊛ x ∎ -- The applicative functor laws hold up to strong bisimilarity. now-id-⊛ : [ i ] now id ⊛ x ∼ x now-id-⊛ {x = now x} = now now-id-⊛ {x = later x} = later λ { .force → now-id-⊛ } now-∘-⊛-⊛-⊛ : (f : Delay (B → C) ∞) (g : Delay (A → B) ∞) (x : Delay A ∞) → [ i ] now (λ f → f ∘_) ⊛ f ⊛ g ⊛ x ∼ f ⊛ (g ⊛ x) now-∘-⊛-⊛-⊛ (now _) (now _) (now _) = now now-∘-⊛-⊛-⊛ (now _) (now _) (later x) = later λ { .force → now-∘-⊛-⊛-⊛ (now _) (now _) (x .force) } now-∘-⊛-⊛-⊛ (now _) (later g) x = later λ { .force → now-∘-⊛-⊛-⊛ (now _) (g .force) x } now-∘-⊛-⊛-⊛ (later f) g x = later λ { .force → now-∘-⊛-⊛-⊛ (f .force) g x } now-⊛-now : [ i ] now h ⊛ now z ∼ now (h z) now-⊛-now = now ⊛-now : (f : Delay (A → B) ∞) → [ i ] f ⊛ now z ∼ now (λ f → f z) ⊛ f ⊛-now (now f) = now ⊛-now (later f) = later λ { .force → ⊛-now (f .force) } ------------------------------------------------------------------------ -- The _∣_ operator -- Sequential composition of computations. infix 10 _∣_ _∣_ : Delay A i → Delay B i → Delay (A × B) i x ∣ y = map′ _,_ x ⊛ y -- The number of later constructors in x ∣ y is bisimilar to the sum -- of the number of later constructors in x and the number of later -- constructors in y. steps-∣∼max-steps-steps : Conat.[ i ] steps (x ∣ y) ∼ steps x + steps y steps-∣∼max-steps-steps {x = x} {y = y} = steps (x ∣ y) Conat.∼⟨ Conat.reflexive-∼ _ ⟩ steps (map′ _,_ x ⊛ y) Conat.∼⟨ steps-⊛∼steps-+-steps (map′ _,_ x) ⟩ steps (map′ _,_ x) + steps y Conat.∼⟨ steps-map′ x Conat.+-cong Conat.reflexive-∼ _ ⟩∎ steps x + steps y ∎∼ -- The _∣_ operator preserves strong and weak bisimilarity and -- expansion. infix 10 _∣-cong_ _∣-cong_ : [ i ] x₁ ⟨ k ⟩ x₂ → [ i ] y₁ ⟨ k ⟩ y₂ → [ i ] x₁ ∣ y₁ ⟨ k ⟩ x₂ ∣ y₂ p ∣-cong q = map-cong _,_ p ⊛-cong q -- The _∣_ operator is commutative (up to swapping of results). ∣-comm : [ i ] x ∣ y ∼ map′ swap (y ∣ x) ∣-comm {x = x} {y = y} = x ∣ y ∼⟨⟩ map′ _,_ x ⊛ y ∼⟨ ⊛-comm (map′ _,_ x) y ⟩ map′ (flip _$_) y ⊛ map′ _,_ x ∼⟨ map∼now-⊛ y ⊛-cong map∼now-⊛ x ⟩ now (flip _$_) ⊛ y ⊛ (now _,_ ⊛ x) ∼⟨ symmetric (now-∘-⊛-⊛-⊛ (now _ ⊛ y) (now _) x) ⟩ now (λ f → f ∘_) ⊛ (now (flip _$_) ⊛ y) ⊛ now _,_ ⊛ x ∼⟨ symmetric (now-∘-⊛-⊛-⊛ (now _) (now _) y) ⊛-cong (now _ ∎) ⊛-cong (x ∎) ⟩ now _∘_ ⊛ now (λ f → f ∘_) ⊛ now (flip _$_) ⊛ y ⊛ now _,_ ⊛ x ∼⟨⟩ now (λ x f y → f y x) ⊛ y ⊛ now _,_ ⊛ x ∼⟨ ⊛-now (now (λ x f y → f y x) ⊛ y) ⊛-cong (x ∎) ⟩ now (_$ _,_) ⊛ (now (λ x f y → f y x) ⊛ y) ⊛ x ∼⟨ symmetric (now-∘-⊛-⊛-⊛ (now _) (now _) y) ⊛-cong (x ∎) ⟩ now _∘_ ⊛ now (_$ _,_) ⊛ now (λ x f y → f y x) ⊛ y ⊛ x ∼⟨⟩ now (curry swap) ⊛ y ⊛ x ∼⟨⟩ now _∘_ ⊛ now (swap ∘_) ⊛ now _,_ ⊛ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ (now _) (now _) y ⊛-cong (x ∎) ⟩ now (swap ∘_) ⊛ (now _,_ ⊛ y) ⊛ x ∼⟨ (now _ ∎) ⊛-cong symmetric (map∼now-⊛ y) ⊛-cong (x ∎) ⟩ now (swap ∘_) ⊛ map′ _,_ y ⊛ x ∼⟨⟩ now _∘_ ⊛ now swap ⊛ map′ _,_ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ (now _) (map′ _,_ y) x ⟩ now swap ⊛ (map′ _,_ y ⊛ x) ∼⟨ symmetric (map∼now-⊛ _) ⟩ map′ swap (map′ _,_ y ⊛ x) ∼⟨⟩ map′ swap (y ∣ x) ∎ -- The _∣_ operator can be expressed using other functions. ∣-∼ : [ i ] x ∣ y ∼ (x >>=′ λ x → y >>=′ λ y → now (x , y)) ∣-∼ {x = x} {y = y} = (map′ _,_ x >>=′ λ f → y >>=′ λ y → now (f y)) ∼⟨ (map∼>>=-now x >>=-cong λ _ → _ ∎) ⟩ ((x >>=′ λ x → now (x ,_)) >>=′ λ f → y >>=′ λ y → now (f y)) ∼⟨ symmetric $ associativity′ x (λ x → now (x ,_)) (λ f → y >>=′ λ y → now (f y)) ⟩ (x >>=′ λ x → now (x ,_) >>=′ λ f → y >>=′ λ y → now (f y)) ∼⟨⟩ (x >>=′ λ x → y >>=′ λ y → now (x , y)) ∎
{ "alphanum_fraction": 0.4291020029, "avg_line_length": 39.4712041885, "ext": "agda", "hexsha": "8cdda2dc6013c33d0a700cb59e055c73be482cf8", "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": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_path": "src/Delay-monad/Sequential.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/delay-monad", "max_issues_repo_path": "src/Delay-monad/Sequential.agda", "max_line_length": 148, "max_stars_count": null, "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_path": "src/Delay-monad/Sequential.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3206, "size": 7539 }
{-# OPTIONS --universe-polymorphism --guardedness #-} -- {-# OPTIONS --verbose tc.constr.findInScope:15 #-} -- {-# OPTIONS --verbose tc.meta.eta:20 #-} -- {-# OPTIONS --verbose tc.conv.term:20 #-} -- {-# OPTIONS --verbose tc.meta.assign:70 #-} -- {-# OPTIONS --verbose tc.eta.rec:70 #-} -- {-# OPTIONS --verbose tc.sig.inst:30 #-} module InstanceArguments.11-monads where open import Effect.Monad using (RawMonad; module RawMonad) open import Effect.Monad.Indexed using (RawIMonad; module RawIMonad) --open import Effect.Applicative.Indexed using () -- identityMonad often makes monadic code ambiguous. --open import Effect.Monad.Identity using (IdentityMonad) open import Effect.Monad.Partiality using (_⊥; now; isNow; never; run_for_steps) renaming (monad to partialityMonad) open import Effect.Monad.State using (StateMonad) open import Effect.Applicative.Indexed using (IFun) open import Function using (_$_) open import Function.Reasoning open import Level using (zero; Level) --open import Data.Unit hiding (_≟_) open import Data.Bool using (if_then_else_) open import Data.Nat using (ℕ; _≟_; _+_; suc; _*_) open import Relation.Nullary.Decidable using (⌊_⌋) open import Data.List using (List; _∷_; []; [_]; null) open import Data.List.Effectful using () renaming (monad to listMonad) --open import Data.Product module RawMonadExt {li f} {I : Set li} {M : IFun I f} (m : RawIMonad M) where -- _>>=_ : ∀ {i j k A B} → M i j A → (A → M j k B) → M i k B -- _>>=_ {i} {j} {k} {A} {B} = RawIMonad._>>=_ {li} {f} {I} {M} m {i} {j} {k} {A} {B} instance i⊥ = partialityMonad iList = listMonad stateMonad = StateMonad ℕ nToList : ℕ → List ℕ nToList 0 = [ 0 ] nToList (suc n) = n ∷ nToList n test′ : ℕ → (List ℕ) ⊥ test′ k = let open RawMonad partialityMonad in do x ← return (k ∷ k + 1 ∷ []) return x test2′ : ℕ → (List ℕ) ⊥ test2′ k = let open RawMonad partialityMonad open RawMonad listMonad using () renaming (_>>=_ to _l>>=_) in do x ← return [ k ] if ⌊ k ≟ 4 ⌋ then return (x l>>= nToList) else never open RawMonad {{...}} open RawMonadExt {{...}} test1 : ℕ → ℕ ⊥ test1 k = do x ← return k if ⌊ x ≟ 4 ⌋ then return 10 else never test2 : ℕ → (List ℕ) ⊥ test2 k = do x ← return [ k ] if ⌊ k ≟ 4 ⌋ then return ((x ∶ List ℕ) >>= nToList) else never test' : ℕ → (List ℕ) ⊥ test' k = do x ← return (k ∷ k + 1 ∷ []) if null x then never else return (x >>= nToList) test3 : List ℕ test3 = do x ← 1 ∷ 2 ∷ 3 ∷ [] return $ x + 1
{ "alphanum_fraction": 0.6216951788, "avg_line_length": 36.2253521127, "ext": "agda", "hexsha": "f0e0318269a906a0b098c31dd7190825733c4a14", "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": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/LibSucceed/InstanceArguments/11-monads.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/LibSucceed/InstanceArguments/11-monads.agda", "max_line_length": 116, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/LibSucceed/InstanceArguments/11-monads.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 826, "size": 2572 }