{"text": "-- Andreas, 2015-03-17\n-- Andreas, 2020-10-26 conform to Issue1428a\n\nopen import Agda.Builtin.Size\n\ndata ⊥ : Set where\n\ndata SizeLt (i : Size) : Set where\n wrap : Size< i → SizeLt i\n\n-- This definition of size predecessor should be forbidden...\nmodule _ (i : Size) where\n postulate\n pred : Size< i\n\n-- ...otherwise the injectivity test loops here.\niter : ∀ i → SizeLt i → ⊥\niter i (wrap j) = iter j (wrap (pred j))\n\nloop : Size → ⊥\nloop i = iter i (wrap (pred i))\n\nabsurd : ⊥\nabsurd = FIXME loop ∞\n\n-- Testcase temporarily mutilated, original error:\n--\n-- -Issue1428c.agda:...\n-- -We don't like postulated sizes in parametrized modules.\n--\n-- +Issue1428c.agda:...\n-- +Not in scope:\n-- + FIXME at Issue1428c.agda:...\n-- +when scope checking FIXME\n", "meta": {"hexsha": "8a5a573d330de89fa5ecbbc07d19daa66206ede1", "size": 752, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue1428c.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/Fail/Issue1428c.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/Fail/Issue1428c.agda", "max_forks_repo_name": "shlevy/agda", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4857142857, "max_line_length": 61, "alphanum_fraction": 0.6595744681, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.37022537869825406, "lm_q1q2_score": 0.19954526699110245}} {"text": "module par-swap.dpg-pot where\n\nopen import Data.Empty\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Bool\nopen import Data.List using ([] ; [_] ; _∷_ ; List ; _++_)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_ ; refl ; sym)\nopen import Data.Maybe using ()\nopen import Data.List.Any using (here ; there)\nopen import Data.List.Any.Properties using ( ++-comm ; ++⁻ ; ++⁺ˡ ; ++⁺ʳ )\nopen import Data.Nat as Nat using (ℕ)\n\nopen import par-swap\nopen import par-swap.properties\n\nopen import Esterel.Lang.CanFunction\nopen import Esterel.Lang\nopen import Esterel.Lang.Properties\nopen import Esterel.Lang.CanFunction.Plug\nopen import Esterel.Environment as Env\nopen import Esterel.Context\n\nopen import utility\n\nopen import sn-calculus\nopen import context-properties -- get view, E-views\nopen import sn-calculus-props\n\nopen import Esterel.Variable.Signal as Signal\n using (Signal ; _ₛ)\nopen import Esterel.Variable.Shared as SharedVar\n using (SharedVar ; _ₛₕ)\nopen import Esterel.Variable.Sequential as SeqVar\n using (SeqVar ; _ᵥ)\nopen import Esterel.CompletionCode as Code\n using () renaming (CompletionCode to Code)\n\n\n\ncanₛ-par :\n ∀ r₁ r₂ -> ∀ (θ : Env) (S : ℕ) →\n S ∈ Canₛ (r₂ ∥ r₁) θ →\n S ∈ Canₛ (r₁ ∥ r₂) θ\ncanₛ-par r₁ r₂ θ S S∈r₂∥r₁\n = ++-comm (proj₁ (Can r₂ θ)) (proj₁ (Can r₁ θ)) S∈r₂∥r₁\n\ncanₖ-par :\n ∀ r₁ r₂ -> ∀ (θ : Env) (k : Code) →\n k ∈ Canₖ (r₂ ∥ r₁) θ →\n k ∈ Canₖ (r₁ ∥ r₂) θ\ncanₖ-par\n = \\ {r₁ r₂ θ S S∈r₂∥r₁ ->\n thing S\n (proj₁ (proj₂ (Can r₁ θ)))\n (proj₁ (proj₂ (Can r₂ θ)))\n S∈r₂∥r₁} where\n\n simplify-foldr++-[] : ∀ (l2 : List Code) ->\n (Data.List.foldr{A = (List Code)}\n _++_\n []\n (Data.List.map (λ (k : Code) → []) l2)) ≡ []\n simplify-foldr++-[] [] = refl\n simplify-foldr++-[] (x ∷ l2) = simplify-foldr++-[] l2\n\n whatevs-left : ∀ S (whatevs : Code -> Code) l1 l2 ->\n Data.List.Any.Any (_≡_ S)\n (Data.List.foldr _++_ []\n (Data.List.map (λ k → Data.List.map (Code._⊔_ k) l2) l1))\n ->\n Data.List.Any.Any (_≡_ S)\n (Data.List.foldr _++_ []\n (Data.List.map (λ k → (whatevs k) ∷ Data.List.map (Code._⊔_ k) l2) l1))\n whatevs-left S whatevs [] l2 ()\n whatevs-left S whatevs (x ∷ l1) l2 blob\n with ++⁻ (Data.List.map (Code._⊔_ x) l2) blob\n ... | inj₁ y = there (++⁺ˡ y)\n ... | inj₂ y\n with whatevs-left S whatevs l1 l2 y\n ... | R = there (++⁺ʳ (Data.List.map (Code._⊔_ x) l2) R)\n\n whatevs-right :\n ∀ S (whatevs : Code -> List Code) x l1 ->\n Data.List.Any.Any (_≡_ S) (Data.List.map (Code._⊔_ x) l1)\n ->\n Data.List.Any.Any (_≡_ S)\n (Data.List.foldr _++_ []\n (Data.List.map (λ k → (k Code.⊔ x) ∷ whatevs k)\n l1))\n whatevs-right S whatevs x [] blob = blob\n whatevs-right S whatevs x (x₁ ∷ l1) (here px)\n rewrite px = here (Code.⊔-comm x x₁)\n whatevs-right S whatevs x (x₁ ∷ l1) (there blob)\n = there (++⁺ʳ (whatevs x₁) (whatevs-right S whatevs x l1 blob))\n\n thing : ∀ S l1 l2 ->\n Data.List.Any.Any (_≡_ S)\n (Data.List.foldr _++_ []\n (Data.List.map\n (λ k → Data.List.map (Code._⊔_ k) l1)\n l2))\n ->\n Data.List.Any.Any (_≡_ S)\n (Data.List.foldr _++_ []\n (Data.List.map\n (λ k → Data.List.map (Code._⊔_ k) l2)\n l1))\n\n thing S l1 [] blob\n rewrite simplify-foldr++-[] l1\n = blob\n\n thing S l1 (x ∷ l2) blob\n with ++⁻ (Data.List.map (Code._⊔_ x) l1) blob\n thing S l1 (x ∷ l2) _ | inj₁ y =\n whatevs-right S (λ { k → Data.List.map (Code._⊔_ k) l2 }) x l1 y\n thing S l1 (x ∷ l2) _ | inj₂ y =\n whatevs-left S (\\ { k -> (k Code.⊔ x)}) l1 l2 (thing S l1 l2 y)\n\ncanₛₕ-par :\n ∀ r₁ r₂ -> ∀ (θ : Env) →\n Canₛₕ (r₂ ∥ r₁) θ ⊆¹ Canₛₕ (r₁ ∥ r₂) θ\ncanₛₕ-par r₁ r₂ θ S S∈r₂∥r₁\n = ++-comm (proj₂ (proj₂ (Can r₂ θ))) (proj₂ (proj₂ (Can r₁ θ))) S∈r₂∥r₁\n\ncanθₛ-C-par : ∀ sigs S'' -> ∀ {C p r₁ r₂} ->\n p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->\n ∀ {θ} S' ->\n S' ∉ Canθₛ sigs S'' p θ ->\n S' ∉ Canθₛ sigs S'' (C ⟦ r₂ ∥ r₁ ⟧c) θ\ncanθₛ-C-par sigs S'' {C} {p} {r₁} {r₂} pC {θ} S' S'∉Canθₛ[p] S'∈Canθₛ[C⟦r₂∥r₁⟧c]\n with canθₛ-plug S'' sigs C (r₁ ∥ r₂) (r₂ ∥ r₁)\n (canₛ-par r₁ r₂) (canₖ-par r₁ r₂) θ S'\n... | r₂r₁->r₁r₂ rewrite sym (unplugc pC) = S'∉Canθₛ[p] (r₂r₁->r₁r₂ S'∈Canθₛ[C⟦r₂∥r₁⟧c])\n\ncanθₛₕ-C-par : ∀ sigs S' -> ∀ {C p r₁ r₂} ->\n p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->\n ∀ {θ} s' ->\n s' ∉ Canθₛₕ sigs S' p θ ->\n s' ∉ Canθₛₕ sigs S' (C ⟦ r₂ ∥ r₁ ⟧c) θ\ncanθₛₕ-C-par sigs S' {C} {p} {r₁} {r₂} pC {θ} s' s'∉Canθₛₕ[p] s'∈Canθₛₕ[C⟦r₂∥r₁⟧c]\n with canθₛₕ-plug S' sigs C (r₁ ∥ r₂) (r₂ ∥ r₁)\n (canₛₕ-par r₁ r₂) (canₖ-par r₁ r₂) (canₛ-par r₁ r₂) θ s'\n... | r₂r₁->r₁r₂ rewrite sym (unplugc pC) = s'∉Canθₛₕ[p] (r₂r₁->r₁r₂ s'∈Canθₛₕ[C⟦r₂∥r₁⟧c])\n\n\nDPG-pot-view :\n ∀ {C r₁ r₂ p q θ θ' A A'} ->\n p ≐ C ⟦ r₁ ∥ r₂ ⟧c ->\n (psn⟶₁q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A' ⟩· q) ->\n (p≡q : p ≡ q) ->\n (A≡A' : A ≡ A') ->\n ->pot-view psn⟶₁q p≡q A≡A' ->\n Σ[ dd′ ∈ Term × Term ]\n (ρ⟨ θ , A ⟩· C ⟦ r₂ ∥ r₁ ⟧c sn⟶ (proj₂ dd′))\n ×\n ((proj₂ dd′) sn⟶* (proj₁ dd′))\n ×\n ((ρ⟨ θ' , A' ⟩· q) ∥R* (proj₁ dd′))\nDPG-pot-view pC (ris-present S∈ x x₁) p≡q A≡A' ()\nDPG-pot-view pC (ris-absent S∈ x x₁) p≡q A≡A' ()\nDPG-pot-view pC (remit S∈ ¬S≡a x) p≡q A≡A' ()\nDPG-pot-view pC (rraise-shared e' x) p≡q A≡A' ()\nDPG-pot-view pC (rset-shared-value-old e' s∈ x x₁) p≡q A≡A' ()\nDPG-pot-view pC (rset-shared-value-new e' s∈ x x₁) p≡q A≡A' ()\nDPG-pot-view pC (rraise-var e' x₁) p≡q A≡A' ()\nDPG-pot-view pC (rset-var x∈ e' x₁) p≡q A≡A' ()\nDPG-pot-view pC (rif-false x∈ x₁ x₂) p≡q A≡A' ()\nDPG-pot-view pC (rif-true x∈ x₁ x₂) p≡q A≡A' ()\nDPG-pot-view pC (rabsence{θ}{_}{S} S∈ x x₁) .refl .refl (vabsence .S .S∈ .x .x₁)\n = _ , rcontext [] dchole\n (rabsence{θ}{_}{S} S∈ x (canθₛ-C-par (sig θ) 0 pC (Signal.unwrap S) x₁)) ,\n rrefl ,\n Context1-∥R* (cenv _ _) (∥Rn (∥Rstep pC) ∥R0)\nDPG-pot-view pC (rreadyness{θ}{_}{s} s∈ x x₁) .refl .refl (vreadyness .s .s∈ .x .x₁)\n = _ , rcontext [] dchole\n (rreadyness{s = s} s∈ x (canθₛₕ-C-par (sig θ) 0 pC (SharedVar.unwrap s) x₁)) ,\n rrefl ,\n Context1-∥R* (cenv _ _) (∥Rn (∥Rstep pC) ∥R0)\nDPG-pot-view pC (rmerge x) p≡q A≡A' ()\n\n", "meta": {"hexsha": "103a873656a066d756994221ed57155022748f09", "size": 6039, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/par-swap/dpg-pot.agda", "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_issues_repo_path": "agda/par-swap/dpg-pot.agda", "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "agda/par-swap/dpg-pot.agda", "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "avg_line_length": 32.8206521739, "max_line_length": 90, "alphanum_fraction": 0.5636694817, "num_tokens": 2855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.36296921241058616, "lm_q1q2_score": 0.19844911642067464}} {"text": "-- Everything is strictly positive, but Agda doesn't see this.\n{-# OPTIONS --no-positivity-check #-}\n\nmodule Generic.Core where\n\nopen import Generic.Lib.Prelude public\n\ninfix 4 _≤ℓ_\ninfixr 5 _⇒_ _⊛_\n\n_≤ℓ_ : Level -> Level -> Set\nα ≤ℓ β = α ⊔ β ≡ β\n\nmutual\n Binder : ∀ {ι} α β γ -> ArgInfo -> ι ⊔ lsuc (α ⊔ β) ≡ γ -> Set ι -> Set γ\n Binder α β γ i q I = Coerce q (∃ λ (A : Set α) -> < relevance i > A -> Desc I β)\n\n data Desc {ι} (I : Set ι) β : Set (ι ⊔ lsuc β) where\n var : I -> Desc I β\n π : ∀ {α} i\n -> (q : α ≤ℓ β)\n -> Binder α β _ i (cong (λ αβ -> ι ⊔ lsuc αβ) q) I\n -> Desc I β\n _⊛_ : Desc I β -> Desc I β -> Desc I β\n\npattern DPi i A D = π i refl (coerce (A , D))\n\n{-# DISPLAY π i refl (coerce (A , D)) = DPi i A D #-}\n\npattern explRelDPi A D = DPi explRelInfo A D\npattern explIrrDPi A D = DPi explIrrInfo A D\npattern implRelDPi A D = DPi implRelInfo A D\npattern implIrrDPi A D = DPi implIrrInfo A D\npattern instRelDPi A D = DPi instRelInfo A D\npattern instIrrDPi A D = DPi instIrrInfo A D\n\n{-# DISPLAY DPi explRelInfo A D = explRelDPi A D #-}\n{-# DISPLAY DPi explIrrInfo A D = explIrrDPi A D #-}\n{-# DISPLAY DPi implRelInfo A D = implRelDPi A D #-}\n{-# DISPLAY DPi implIrrInfo A D = implIrrDPi A D #-}\n{-# DISPLAY DPi instRelInfo A D = instRelDPi A D #-}\n{-# DISPLAY DPi instIrrInfo A D = instIrrDPi A D #-}\n\n_⇒_ : ∀ {ι α β} {I : Set ι} {{q : α ≤ℓ β}} -> Set α -> Desc I β -> Desc I β\n_⇒_ {{q}} A D = π (explRelInfo) q (qcoerce (A , λ _ -> D))\n\nmutual\n ⟦_⟧ : ∀ {ι β} {I : Set ι} -> Desc I β -> (I -> Set β) -> Set β\n ⟦ var i ⟧ B = B i\n ⟦ π i q C ⟧ B = ⟦ i / C ⟧ᵇ q B\n ⟦ D ⊛ E ⟧ B = ⟦ D ⟧ B × ⟦ E ⟧ B\n\n ⟦_/_⟧ᵇ : ∀ {α ι β γ q} {I : Set ι} i\n -> Binder α β γ i q I -> α ≤ℓ β -> (I -> Set β) -> Set β\n ⟦ i / coerce (A , D) ⟧ᵇ q B = Coerce′ q $ Pi i A λ x -> ⟦ D x ⟧ B\n\nmutual\n Extend : ∀ {ι β} {I : Set ι} -> Desc I β -> (I -> Set β) -> I -> Set β\n Extend (var i) B j = Lift _ (i ≡ j)\n Extend (π i q C) B j = Extendᵇ i C q B j\n Extend (D ⊛ E) B j = ⟦ D ⟧ B × Extend E B j\n\n Extendᵇ : ∀ {ι α β γ q} {I : Set ι} i\n -> Binder α β γ i q I -> α ≤ℓ β -> (I -> Set β) -> I -> Set β\n Extendᵇ i (coerce (A , D)) q B j = Coerce′ q $ ∃ λ x -> Extend (D x) B j\n\nmodule _ {ι β} {I : Set ι} (D : Data (Desc I β)) where\n mutual\n data μ j : Set β where\n node : Node D j -> μ j\n\n Node : Data (Desc I β) -> I -> Set β\n Node D j = Any (λ C -> Extend C μ j) (consTypes D)\n\nmutual\n Cons : ∀ {ι β} {I : Set ι} -> (I -> Set β) -> Desc I β -> Set β\n Cons B (var i) = B i\n Cons B (π i q C) = Consᵇ B i C q\n Cons B (D ⊛ E) = ⟦ D ⟧ B -> Cons B E\n\n Consᵇ : ∀ {ι α β γ q} {I : Set ι}\n -> (I -> Set β) -> ∀ i -> Binder α β γ i q I -> α ≤ℓ β -> Set β\n Consᵇ B i (coerce (A , D)) q = Coerce′ q $ Pi i A λ x -> Cons B (D x)\n\ncons : ∀ {ι β} {I : Set ι} {D} -> (D₀ : Data (Desc I β)) -> D ∈ consTypes D₀ -> Cons (μ D₀) D\ncons {D = D} D₀ p = go D λ e ->\n node (mapAny (consTypes D₀) (λ q -> subst (λ E -> Extend E _ _) q e) p) where\n mutual\n go : ∀ {ι β} {I : Set ι} {B : I -> Set β}\n -> (D : Desc I β) -> (∀ {j} -> Extend D B j -> B j) -> Cons B D\n go (var i) k = k lrefl\n go (π a q C) k = goᵇ a C k\n go (D ⊛ E) k = λ x -> go E (k ∘ _,_ x)\n\n goᵇ : ∀ {ι α β γ q q′} {I : Set ι} {B : I -> Set β} i\n -> (C : Binder α β γ i q′ I) -> (∀ {j} -> Extendᵇ i C q B j -> B j) -> Consᵇ B i C q\n goᵇ {q = q} i (coerce (A , D)) k =\n coerce′ q $ lamPi i λ x -> go (D x) (k ∘ coerce′ q ∘ _,_ x)\n\nallCons : ∀ {ι β} {I : Set ι} -> (D : Data (Desc I β)) -> All (Cons (μ D)) (consTypes D)\nallCons D = allIn _ (cons D)\n\nnode-inj : ∀ {i β} {I : Set i} {D : Data (Desc I β)} {j} {e₁ e₂ : Node D D j}\n -> node {D = D} e₁ ≡ node e₂ -> e₁ ≡ e₂\nnode-inj refl = refl\n\nμ′ : ∀ {β} -> Data (Desc ⊤₀ β) -> Set β\nμ′ D = μ D tt\n\npos : ∀ {β} -> Desc ⊤₀ β\npos = var tt\n\npattern #₀ p = node (inj₁ p)\npattern #₁ p = node (inj₂ (inj₁ p))\npattern #₂ p = node (inj₂ (inj₂ (inj₁ p)))\npattern #₃ p = node (inj₂ (inj₂ (inj₂ (inj₁ p))))\npattern #₄ p = node (inj₂ (inj₂ (inj₂ (inj₂ (inj₁ p)))))\npattern #₅ p = node (inj₂ (inj₂ (inj₂ (inj₂ (inj₂ (inj₁ p))))))\n\npattern !#₀ p = node p\npattern !#₁ p = node (inj₂ p)\npattern !#₂ p = node (inj₂ (inj₂ p))\npattern !#₃ p = node (inj₂ (inj₂ (inj₂ p)))\npattern !#₄ p = node (inj₂ (inj₂ (inj₂ (inj₂ p))))\npattern !#₅ p = node (inj₂ (inj₂ (inj₂ (inj₂ (inj₂ p)))))\n", "meta": {"hexsha": "5de26d9e58db44a08e38116a6497c41994468a87", "size": 4401, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generic/Core.agda", "max_stars_repo_name": "turion/Generic", "max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z", "max_issues_repo_path": "src/Generic/Core.agda", "max_issues_repo_name": "turion/Generic", "max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z", "max_forks_repo_path": "src/Generic/Core.agda", "max_forks_repo_name": "turion/Generic", "max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z", "avg_line_length": 34.9285714286, "max_line_length": 94, "alphanum_fraction": 0.5051124744, "num_tokens": 1961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.3702253925955866, "lm_q1q2_score": 0.19810702581556874}} {"text": "open import MJ.Types\nimport MJ.Classtable.Core as Core\n\nmodule MJ.Classtable.Code {c}(Ct : Core.Classtable c) where\n\nopen import Prelude\nopen import Data.Maybe as Maybe using (Maybe; just; nothing)\nopen import Data.Star as Star\nopen import Data.List\nopen import Data.List.Relation.Unary.All hiding (construct)\nopen import Data.List.Properties.Extra as List+\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary.Decidable\nopen import Data.String\n\nimport Data.Vec.Relation.Unary.All as Vec∀\n\nopen Core c\nopen Classtable Ct\nopen import MJ.Classtable.Membership Ct\nopen import MJ.LexicalScope c\nopen import MJ.Syntax Ct\n\ndata Body (I : Ctx) : Ty c → Set where\n body : ∀ {r}{O : Ctx} → Stmts I r O → Expr O r → Body I r\n\n{-\nA helper to generate the shape of the context for method bodies\n-}\nmethodctx : Cid c → List (Ty c) → Ctx\nmethodctx cid as = (ref cid ∷ as)\n\n{-\nA helper to generate the shape of the context for constructors\n-}\nconstrctx : Cid c → Ctx\nconstrctx cid = let cl = Σ cid in (ref cid ∷ Class.constr cl)\n\n-- A method is either just a body, or a body prefixed by a super call.\ndata Method (cid : Cid c)(m : String) : Sig c → Set where\n super_⟨_⟩then_ : ∀ {as b} →\n let\n pid = Class.parent (Σ cid)\n Γ = methodctx cid as\n in\n -- must have a super to call, with the same signature\n AccMember pid METHOD m (as , b) →\n -- super call arguments\n All (Expr Γ) as →\n -- body\n Body (Γ +local b) b → Method cid m (as , b)\n body : ∀ {as b} → Body (methodctx cid as) b → Method cid m (as , b)\n\n-- Constructors are similar\ndata Constructor (cid : Cid c) : Set where\n super_then_ : let\n pid = Class.parent (Σ cid)\n pclass = Σ pid\n Γ = constrctx cid\n in\n -- super call arguments\n All (Expr Γ) (Class.constr pclass) →\n -- body\n Body Γ void →\n Constructor cid\n body : Body (constrctx cid) void → Constructor cid\n\n{-\nA class implementation consists of a constructor and a body for every\nMETHOD declaration.\n-}\nrecord Implementation (cid : Cid c) : Set where\n constructor implementation\n open Class (Σ cid) public\n field\n construct : Constructor cid\n mbodies : All (λ{ (name , sig) → Method cid name sig }) (decls METHOD)\n\n-- Code is a lookup table for class implementations for every class identifier\nCode = ∀ cid → Implementation cid\n\n-- Mirroring `IsMember METHOD` we define the notion of an inherited method body.\nInheritedMethod : ∀ (cid : Cid c)(m : String) → Sig c → Set\nInheritedMethod cid m s = ∃ λ pid → Σ ⊢ cid <: pid × Method pid m s\n", "meta": {"hexsha": "c6d04e2fb0189d42c5aae81963f9188d229c7bda", "size": 2812, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MJ/Classtable/Code.agda", "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_issues_repo_path": "src/MJ/Classtable/Code.agda", "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_forks_repo_path": "src/MJ/Classtable/Code.agda", "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "avg_line_length": 33.0823529412, "max_line_length": 80, "alphanum_fraction": 0.622688478, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.3380771241500058, "lm_q1q2_score": 0.19780931554987746}} {"text": "------------------------------------------------------------------------\n-- Compiler correctness\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --sized-types #-}\n\nmodule Lambda.Delay-monad.Compiler-correctness where\n\nimport Equality.Propositional as E\nopen import Prelude\nopen import Prelude.Size\n\nopen import Maybe E.equality-with-J hiding (_>>=′_)\nopen import Monad E.equality-with-J\nopen import Vec.Function E.equality-with-J\n\nopen import Delay-monad.Bisimilarity\nopen import Delay-monad.Monad\n\nopen import Lambda.Compiler\nopen import Lambda.Delay-monad.Interpreter\nopen import Lambda.Delay-monad.Virtual-machine\nopen import Lambda.Syntax hiding ([_])\nopen import Lambda.Virtual-machine\n\nprivate\n module C = Closure Code\n module T = Closure Tm\n\n-- Bind preserves strong bisimilarity.\n\ninfixl 5 _>>=-congM_\n\n_>>=-congM_ :\n ∀ {i ℓ} {A B : Type ℓ} {x y : M ∞ A} {f g : A → M ∞ B} →\n [ i ] run x ∼ run y →\n (∀ z → [ i ] run (f z) ∼ run (g z)) →\n [ i ] run (x >>= f) ∼ run (y >>= g)\np >>=-congM q = p >>=-cong [ (λ _ → run fail ∎) , q ]\n\n-- Bind is associative.\n\nassociativityM :\n ∀ {ℓ} {A B C : Type ℓ} (x : M ∞ A) (f : A → M ∞ B) (g : B → M ∞ C) →\n run (x >>= (λ x → f x >>= g)) ∼ run (x >>= f >>= g)\nassociativityM x f g =\n run (x >>= λ x → f x >>= g) ∼⟨⟩\n\n run x >>=′ maybe (λ x → run (f x >>= g)) (return nothing) ∼⟨ (run x ∎) >>=-cong [ (λ _ → run fail ∎) , (λ x → run (f x >>= g) ∎) ] ⟩\n\n run x >>=′ (λ x → maybe (MaybeT.run ∘ f) (return nothing) x >>=′\n maybe (MaybeT.run ∘ g) (return nothing)) ∼⟨ associativity′ (run x) _ _ ⟩\n\n run x >>=′ maybe (MaybeT.run ∘ f) (return nothing)\n >>=′ maybe (MaybeT.run ∘ g) (return nothing) ∼⟨⟩\n\n run (x >>= f >>= g) ∎\n\n-- Compiler correctness.\n\nmutual\n\n ⟦⟧-correct :\n ∀ {i n} t {ρ : T.Env n} {c s} {k : T.Value → M ∞ C.Value} →\n (∀ v → [ i ] run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈\n run (k v)) →\n [ i ] run (exec ⟨ comp t c , s , comp-env ρ ⟩) ≈ run (⟦ t ⟧ ρ >>= k)\n\n ⟦⟧-correct (con i) {ρ} {c} {s} {k} hyp =\n run (exec ⟨ con i ∷ c , s , comp-env ρ ⟩) ≳⟨⟩\n run (exec ⟨ c , val (comp-val (T.con i)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (T.con i) ⟩∼\n run (k (T.con i)) ∼⟨⟩\n run (⟦ con i ⟧ ρ >>= k) ∎\n\n ⟦⟧-correct (var x) {ρ} {c} {s} {k} hyp =\n run (exec ⟨ var x ∷ c , s , comp-env ρ ⟩) ≳⟨⟩\n run (exec ⟨ c , val (comp-val (ρ x)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (ρ x) ⟩∼\n run (k (ρ x)) ∼⟨⟩\n run (⟦ var x ⟧ ρ >>= k) ∎\n\n ⟦⟧-correct (ƛ t) {ρ} {c} {s} {k} hyp =\n run (exec ⟨ clo (comp t (ret ∷ [])) ∷ c , s , comp-env ρ ⟩) ≳⟨⟩\n run (exec ⟨ c , val (comp-val (T.ƛ t ρ)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (T.ƛ t ρ) ⟩∼\n run (k (T.ƛ t ρ)) ∼⟨⟩\n run (⟦ ƛ t ⟧ ρ >>= k) ∎\n\n ⟦⟧-correct (t₁ · t₂) {ρ} {c} {s} {k} hyp =\n run (exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩) ≈⟨ (⟦⟧-correct t₁ λ v₁ → ⟦⟧-correct t₂ λ v₂ → ∙-correct v₁ v₂ hyp) ⟩∼\n\n run (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∼⟨ (run (⟦ t₁ ⟧ ρ) ∎) >>=-congM (λ _ → associativityM (⟦ t₂ ⟧ ρ) _ _) ⟩\n\n run (⟦ t₁ ⟧ ρ >>= λ v₁ → (⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂) >>= k) ∼⟨ associativityM (⟦ t₁ ⟧ ρ) _ _ ⟩\n\n run (⟦ t₁ · t₂ ⟧ ρ >>= k) ∎\n\n ∙-correct :\n ∀ {i n} v₁ v₂ {ρ : T.Env n} {c s} {k : T.Value → M ∞ C.Value} →\n (∀ v → [ i ] run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈\n run (k v)) →\n [ i ] run (exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s\n , comp-env ρ\n ⟩) ≈\n run (v₁ ∙ v₂ >>= k)\n ∙-correct (T.con i) v₂ {ρ} {c} {s} {k} hyp =\n run (exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (C.con i) ∷ s\n , comp-env ρ\n ⟩) ∼⟨⟩\n\n run fail ∼⟨⟩\n\n run (T.con i ∙ v₂ >>= k) ∎\n\n ∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =\n run (exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s\n , comp-env ρ\n ⟩) ≈⟨ later (λ { .force →\n\n run (exec ⟨ comp t₁ (ret ∷ [])\n , ret c (comp-env ρ) ∷ s\n , cons (comp-val v₂) (comp-env ρ₁)\n ⟩) ≡⟨ E.cong (λ ρ′ → run (exec ⟨ comp t₁ (ret ∷ []) ,\n ret c (comp-env ρ) ∷ s , ρ′ ⟩))\n (E.sym comp-cons) ⟩\n run (exec ⟨ comp t₁ (ret ∷ [])\n , ret c (comp-env ρ) ∷ s\n , comp-env (cons v₂ ρ₁)\n ⟩) ≈⟨ ⟦⟧-correct t₁ (λ v →\n\n run (exec ⟨ ret ∷ []\n , val (comp-val v) ∷ ret c (comp-env ρ) ∷ s\n , comp-env (cons v₂ ρ₁)\n ⟩) ≳⟨⟩\n\n run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈⟨ hyp v ⟩∎\n\n run (k v) ∎) ⟩∼\n\n run (⟦ t₁ ⟧ (cons v₂ ρ₁) >>= k) ∎ }) ⟩∎\n\n run (T.ƛ t₁ ρ₁ ∙ v₂ >>= k) ∎\n\n-- Note that the equality that is used here is syntactic.\n\ncorrect :\n ∀ t →\n exec ⟨ comp t [] , [] , nil ⟩ ≈M\n ⟦ t ⟧ nil >>= λ v → return (comp-val v)\ncorrect t =\n run (exec ⟨ comp t [] , [] , nil ⟩) ≡⟨ E.cong (λ ρ → run (exec ⟨ comp t [] , [] , ρ ⟩)) $ E.sym comp-nil ⟩\n run (exec ⟨ comp t [] , [] , comp-env nil ⟩) ≈⟨ ⟦⟧-correct t (λ v → return (just (comp-val v)) ∎) ⟩\n run (⟦ t ⟧ nil >>= λ v → return (comp-val v)) ∎\n", "meta": {"hexsha": "2c4ef6523addfa70a15f83da309f307080174818", "size": 6295, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda", "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_issues_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda", "max_issues_repo_name": "nad/partiality-monad", "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda", "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.6129032258, "max_line_length": 142, "alphanum_fraction": 0.3644162033, "num_tokens": 2218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.33111973302838926, "lm_q1q2_score": 0.19749078416042504}} {"text": "-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.\n-- Tarski-style semantics with context pairs as concrete worlds, and glueing for α, ▻, and □.\n-- Hilbert-style syntax.\n\nmodule BasicIS4.Semantics.TarskiOvergluedDyadicHilbert where\n\nopen import BasicIS4.Syntax.Common public\nopen import Common.Semantics public\n\n\n-- Intuitionistic Tarski models.\n\nrecord Model : Set₁ where\n infix 3 _⊩ᵅ_ _[⊢]_\n field\n -- Forcing for atomic propositions; monotonic.\n _⊩ᵅ_ : Cx² Ty Ty → Atom → Set\n mono²⊩ᵅ : ∀ {P Π Π′} → Π ⊆² Π′ → Π ⊩ᵅ P → Π′ ⊩ᵅ P\n\n -- Hilbert-style syntax representation; monotonic.\n _[⊢]_ : Cx² Ty Ty → Ty → Set\n mono²[⊢] : ∀ {A Π Π′} → Π ⊆² Π′ → Π [⊢] A → Π′ [⊢] A\n [var] : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ [⊢] A\n [app] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B → Γ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] B\n [ci] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] A ▻ A\n [ck] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A\n [cs] : ∀ {A B C Γ Δ} → Γ ⁏ Δ [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C\n [mvar] : ∀ {A Γ Δ} → A ∈ Δ → Γ ⁏ Δ [⊢] A\n [box] : ∀ {A Γ Δ} → ∅ ⁏ Δ [⊢] A → Γ ⁏ Δ [⊢] □ A\n [cdist] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] □ (A ▻ B) ▻ □ A ▻ □ B\n [cup] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ □ □ A\n [cdown] : ∀ {A Γ Δ} → Γ ⁏ Δ [⊢] □ A ▻ A\n [cpair] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ▻ B ▻ A ∧ B\n [cfst] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ A\n [csnd] : ∀ {A B Γ Δ} → Γ ⁏ Δ [⊢] A ∧ B ▻ B\n [unit] : ∀ {Γ Δ} → Γ ⁏ Δ [⊢] ⊤\n\n -- NOTE: [mlam] is necessary for [mmulticut], which is necessary for eval.\n [mlam] : ∀ {A B Γ Δ} → Γ ⁏ Δ , A [⊢] B → Γ ⁏ Δ [⊢] □ A ▻ B\n\n infix 3 _[⊢]⋆_\n _[⊢]⋆_ : Cx² Ty Ty → Cx Ty → Set\n Π [⊢]⋆ ∅ = 𝟙\n Π [⊢]⋆ Ξ , A = Π [⊢]⋆ Ξ × Π [⊢] A\n\nopen Model {{…}} public\n\n\n-- Forcing in a particular model.\n\nmodule _ {{_ : Model}} where\n infix 3 _⊩_\n _⊩_ : Cx² Ty Ty → Ty → Set\n Π ⊩ α P = Glue (Π [⊢] α P) (Π ⊩ᵅ P)\n Π ⊩ A ▻ B = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] A ▻ B) (Π′ ⊩ A → Π′ ⊩ B)\n Π ⊩ □ A = ∀ {Π′} → Π ⊆² Π′ → Glue (Π′ [⊢] □ A) (Π′ ⊩ A)\n Π ⊩ A ∧ B = Π ⊩ A × Π ⊩ B\n Π ⊩ ⊤ = 𝟙\n\n infix 3 _⊩⋆_\n _⊩⋆_ : Cx² Ty Ty → Cx Ty → Set\n Π ⊩⋆ ∅ = 𝟙\n Π ⊩⋆ Ξ , A = Π ⊩⋆ Ξ × Π ⊩ A\n\n\n-- Monotonicity with respect to context inclusion.\n\nmodule _ {{_ : Model}} where\n mono²⊩ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊩ A → Π′ ⊩ A\n mono²⊩ {α P} ψ s = mono²[⊢] ψ (syn s) ⅋ mono²⊩ᵅ ψ (sem s)\n mono²⊩ {A ▻ B} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)\n mono²⊩ {□ A} ψ s = λ ψ′ → s (trans⊆² ψ ψ′)\n mono²⊩ {A ∧ B} ψ s = mono²⊩ {A} ψ (π₁ s) , mono²⊩ {B} ψ (π₂ s)\n mono²⊩ {⊤} ψ s = ∙\n\n mono²⊩⋆ : ∀ {Ξ Π Π′} → Π ⊆² Π′ → Π ⊩⋆ Ξ → Π′ ⊩⋆ Ξ\n mono²⊩⋆ {∅} ψ ∙ = ∙\n mono²⊩⋆ {Ξ , A} ψ (ts , t) = mono²⊩⋆ ψ ts , mono²⊩ {A} ψ t\n\n\n-- Extraction of syntax representation in a particular model.\n\nmodule _ {{_ : Model}} where\n reifyʳ : ∀ {A Π} → Π ⊩ A → Π [⊢] A\n reifyʳ {α P} s = syn s\n reifyʳ {A ▻ B} s = syn (s refl⊆²)\n reifyʳ {□ A} s = syn (s refl⊆²)\n reifyʳ {A ∧ B} s = [app] ([app] [cpair] (reifyʳ {A} (π₁ s))) (reifyʳ {B} (π₂ s))\n reifyʳ {⊤} s = [unit]\n\n reifyʳ⋆ : ∀ {Ξ Π} → Π ⊩⋆ Ξ → Π [⊢]⋆ Ξ\n reifyʳ⋆ {∅} ∙ = ∙\n reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t\n\n\n-- Useful theorems in functional form.\n\nmodule _ {{_ : Model}} where\n [mmulticut] : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ [⊢]⋆ □⋆ Ξ → Γ ⁏ Ξ [⊢] A → Γ ⁏ Δ [⊢] A\n [mmulticut] {∅} ∙ u = mono²[⊢] (refl⊆ , bot⊆) u\n [mmulticut] {Ξ , B} (ts , t) u = [app] ([mmulticut] ts ([mlam] u)) t\n\n\n-- Additional useful equipment.\n\nmodule _ {{_ : Model}} where\n _⟪$⟫_ : ∀ {A B Π} → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ B\n s ⟪$⟫ a = sem (s refl⊆²) a\n\n ⟪K⟫ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A\n ⟪K⟫ {A} a ψ = let a′ = mono²⊩ {A} ψ a\n in [app] [ck] (reifyʳ a′) ⅋ K a′\n\n ⟪S⟫ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ A ▻ B → Π ⊩ A → Π ⊩ C\n ⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)\n\n ⟪S⟫′ : ∀ {A B C Π} → Π ⊩ A ▻ B ▻ C → Π ⊩ (A ▻ B) ▻ A ▻ C\n ⟪S⟫′ {A} {B} {C} s₁ ψ = let s₁′ = mono²⊩ {A ▻ B ▻ C} ψ s₁\n t = syn (s₁′ refl⊆²)\n in [app] [cs] t ⅋ λ s₂ ψ′ →\n let s₁″ = mono²⊩ {A ▻ B ▻ C} (trans⊆² ψ ψ′) s₁\n s₂′ = mono²⊩ {A ▻ B} ψ′ s₂\n t′ = syn (s₁″ refl⊆²)\n u = syn (s₂′ refl⊆²)\n in [app] ([app] [cs] t′) u ⅋ ⟪S⟫ s₁″ s₂′\n\n _⟪D⟫_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A → Π ⊩ □ B\n (s₁ ⟪D⟫ s₂) ψ = let t ⅋ s₁′ = s₁ ψ\n u ⅋ a = s₂ ψ\n in [app] ([app] [cdist] t) u ⅋ s₁′ ⟪$⟫ a\n\n _⟪D⟫′_ : ∀ {A B Π} → Π ⊩ □ (A ▻ B) → Π ⊩ □ A ▻ □ B\n _⟪D⟫′_ {A} {B} s₁ ψ = let s₁′ = mono²⊩ {□ (A ▻ B)} ψ s₁\n in [app] [cdist] (reifyʳ (λ {_} ψ′ → s₁′ ψ′)) ⅋ _⟪D⟫_ s₁′\n\n ⟪↑⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ □ □ A\n ⟪↑⟫ {A} s ψ = [app] [cup] (syn (s ψ)) ⅋ λ ψ′ → s (trans⊆² ψ ψ′)\n\n ⟪↓⟫ : ∀ {A Π} → Π ⊩ □ A → Π ⊩ A\n ⟪↓⟫ s = sem (s refl⊆²)\n\n _⟪,⟫′_ : ∀ {A B Π} → Π ⊩ A → Π ⊩ B ▻ A ∧ B\n _⟪,⟫′_ {A} a ψ = let a′ = mono²⊩ {A} ψ a\n in [app] [cpair] (reifyʳ a′) ⅋ _,_ a′\n\n\n-- Forcing in a particular world of a particular model, for sequents.\n\nmodule _ {{_ : Model}} where\n infix 3 _⊩_⇒_\n _⊩_⇒_ : Cx² Ty Ty → Cx² Ty Ty → Ty → Set\n Π ⊩ Γ ⁏ Δ ⇒ A = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩ A\n\n infix 3 _⊩_⇒⋆_\n _⊩_⇒⋆_ : Cx² Ty Ty → Cx² Ty Ty → Cx Ty → Set\n Π ⊩ Γ ⁏ Δ ⇒⋆ Ξ = Π ⊩⋆ Γ → Π ⊩⋆ □⋆ Δ → Π ⊩⋆ Ξ\n\n\n-- Entailment, or forcing in all worlds of all models, for sequents.\n\ninfix 3 _⊨_\n_⊨_ : Cx² Ty Ty → Ty → Set₁\nΠ ⊨ A = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒ A\n\ninfix 3 _⊨⋆_\n_⊨⋆_ : Cx² Ty Ty → Cx Ty → Set₁\nΠ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : Cx² Ty Ty} → w ⊩ Π ⇒⋆ Ξ\n\n\n-- Additional useful equipment, for sequents.\n\nmodule _ {{_ : Model}} where\n lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩⋆ Γ → w ⊩ A\n lookup top (γ , a) = a\n lookup (pop i) (γ , b) = lookup i γ\n\n mlookup : ∀ {A Δ w} → A ∈ Δ → w ⊩⋆ □⋆ Δ → w ⊩ A\n mlookup top (γ , s) = sem (s refl⊆²)\n mlookup (pop i) (γ , s) = mlookup i γ\n\n -- TODO: More equipment.\n", "meta": {"hexsha": "4a48984c7523257967d806e0ce874e7f5c18adbb", "size": 6010, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda", "max_stars_repo_name": "mietek/hilbert-gentzen", "max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_stars_repo_licenses": ["X11"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z", "max_issues_repo_path": "BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda", "max_issues_repo_name": "mietek/hilbert-gentzen", "max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_issues_repo_licenses": ["X11"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z", "max_forks_repo_path": "BasicIS4/Semantics/TarskiOvergluedDyadicHilbert.agda", "max_forks_repo_name": "mietek/hilbert-gentzen", "max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_forks_repo_licenses": ["X11"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.021978022, "max_line_length": 93, "alphanum_fraction": 0.403327787, "num_tokens": 3468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.3486451285660856, "lm_q1q2_score": 0.19733959986958727}} {"text": "open import Prelude\n\nmodule Implicits.Resolution.Termination.Lemmas.SizeMeasures\n where\n\nopen import Induction.WellFounded\nopen import Induction.Nat\nopen import Data.Vec\nopen import Data.Fin.Substitution\nopen import Extensions.Vec\nopen import Implicits.Syntax\nopen import Implicits.Syntax.Type.Unification\nopen import Implicits.Substitutions\nopen import Implicits.Substitutions.Lemmas\nopen import Data.Nat hiding (_<_)\nopen import Data.Nat.Properties\nopen import Relation.Binary using (module DecTotalOrder)\nopen DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl)\nopen import Extensions.Nat\nopen import Implicits.Resolution.Termination.SizeMeasures\n\n-- we can show that our size measure a ρ< b is well founded\n-- by relating it to the well-foundedness proof of _<'_\nopen import Induction.WellFounded\nρ<-well-founded : Well-founded _ρ<_\nρ<-well-founded = sub.well-founded (image.well-founded <-well-founded)\n where\n open import Induction.Nat\n open import Data.Nat\n open import Data.Nat.Properties\n module sub = Inverse-image (λ{ (_ , a ) → || a ||})\n module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′\n\nopen import Induction.WellFounded\nhρ<-well-founded : Well-founded _hρ<_\nhρ<-well-founded = sub.well-founded (image.well-founded <-well-founded)\n where\n open import Induction.Nat\n open import Data.Nat\n open import Data.Nat.Properties\n module sub = Inverse-image (λ{ (_ , a ) → h|| a ||})\n module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′\n\nm<-well-founded : Well-founded _m<_\nm<-well-founded = sub.well-founded (image.well-founded <-well-founded)\n where\n module sub = Inverse-image (λ{ (_ , _ , a) → m|| a ||})\n module image = Subrelation {A = ℕ} {_<_} {_<′_} ≤⇒≤′\n\nmodule TypeSubstSizeLemmas where\n open MetaTypeTypeSubst\n\n mutual\n ||a/Var|| : ∀ {m ν μ} (a : MetaType m ν) (s : Sub Fin ν μ) →\n m|| a /Var s || ≡ m|| a ||\n ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| (∀' a) s = cong (λ u → 1 + u) (||a/Var|| a (s VarSubst.↑))\n ||a/Var|| (simpl (tvar x)) s = refl\n ||a/Var|| (simpl (mvar x)) s = refl\n ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| (simpl (tc c)) s = refl\n\n ||weaken-a|| : ∀ {m ν} (a : MetaType m ν) → m|| weaken a || ≡ m|| a ||\n ||weaken-a|| {m} {ν} a = begin\n m|| weaken a ||\n ≡⟨ refl ⟩\n m|| a /Var VarSubst.wk ||\n ≡⟨ ||a/Var|| a VarSubst.wk ⟩\n m|| a || ∎\n\n ||s↑|| : ∀ {m ν μ} (s : Sub (MetaType m) ν μ) →\n (∀ (x : Fin ν) → m|| lookup x s || ≡ 1) →\n ∀ y → m|| lookup y (s ↑) || ≡ 1\n ||s↑|| s p zero = refl\n ||s↑|| s p (suc y) = begin\n m|| lookup y (map weaken s) ||\n ≡⟨ cong m||_|| (sym $ lookup⋆map s weaken y) ⟩\n m|| weaken (lookup y s) ||\n ≡⟨ ||weaken-a|| (lookup y s) ⟩\n m|| (lookup y s) ||\n ≡⟨ p y ⟩\n 1 ∎\n\n ||a/s|| : ∀ {m ν μ} (a : MetaType m ν) (s : Sub (MetaType m) ν μ) →\n (∀ x → m|| lookup x s || ≡ 1) →\n m|| a / s || ≡ m|| a ||\n ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (s ↑) (||s↑|| s p))\n ||a/s|| {m} {ν} (simpl (tvar x)) s p = begin\n m|| (simpl (tvar x)) / s ||\n ≡⟨ cong m||_|| (MetaTypeTypeLemmas.var-/ {x = x}) ⟩\n m|| lookup x s ||\n ≡⟨ p x ⟩\n 1 ∎\n ||a/s|| (simpl (mvar x)) s p = refl\n ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (simpl (tc c)) s p = refl\n\nmodule MetaSubstSizeLemmas where\n open MetaTypeMetaSubst hiding (open-meta)\n\n mutual\n ||a/Var|| : ∀ {ν m n} (a : MetaType m ν) (s : Sub Fin m n) →\n m|| a /Var s || ≡ m|| a ||\n ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| {ν = ν} (∀' a) s =\n cong (λ u → 1 + u) (||a/Var|| a ((varLift MetaLift.↑tp) {ν = ν} s))\n ||a/Var|| (simpl (tvar x)) s = refl\n ||a/Var|| (simpl (mvar x)) s = refl\n ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| (simpl (tc c)) s = refl\n\n ||weaken-a|| : ∀ {m ν} (a : MetaType m ν) → m|| weaken a || ≡ m|| a ||\n ||weaken-a|| {m} {ν} a = begin\n m|| weaken a ||\n ≡⟨ refl ⟩\n m|| a /Var VarSubst.wk ||\n ≡⟨ ||a/Var|| a VarSubst.wk ⟩\n m|| a || ∎\n\n ||s↑|| : ∀ {m ν μ} (s : Sub (MetaType m) ν μ) →\n (∀ (x : Fin ν) → m|| lookup x s || ≡ 1) →\n ∀ y → m|| lookup y (s ↑) || ≡ 1\n ||s↑|| s p zero = refl\n ||s↑|| s p (suc y) = begin\n m|| lookup y (map weaken s) ||\n ≡⟨ cong m||_|| (sym $ lookup⋆map s weaken y) ⟩\n m|| weaken (lookup y s) ||\n ≡⟨ ||weaken-a|| (lookup y s) ⟩\n m|| (lookup y s) ||\n ≡⟨ p y ⟩\n 1 ∎\n\n ||a/s|| : ∀ {m ν n} (a : MetaType m ν) (s : Sub (flip MetaType ν) m n) →\n (∀ x → m|| lookup x s || ≡ 1) →\n m|| a / s || ≡ m|| a ||\n ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (map MetaTypeTypeSubst.weaken s) lem)\n where\n lem : ∀ x → m|| lookup x (map MetaTypeTypeSubst.weaken s) || ≡ 1\n lem x = begin\n m|| lookup x (map MetaTypeTypeSubst.weaken s) ||\n ≡⟨ cong m||_|| (sym $ lookup⋆map s _ x) ⟩\n m|| MetaTypeTypeSubst.weaken (lookup x s) ||\n ≡⟨ TypeSubstSizeLemmas.||weaken-a|| (lookup x s) ⟩\n m|| lookup x s ||\n ≡⟨ p x ⟩\n 1 ∎\n ||a/s|| {m} {ν} (simpl (mvar x)) s p = begin\n m|| (simpl (mvar x)) / s ||\n ≡⟨ cong m||_|| (MetaTypeTypeLemmas.var-/ {x = x}) ⟩\n m|| lookup x s ||\n ≡⟨ p x ⟩\n 1 ∎\n ||a/s|| (simpl (tvar x)) s p = refl\n ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (simpl (tc c)) s p = refl\n\n ||open-meta-a||≡a : ∀ {m ν} (a : MetaType m (suc ν)) → m|| open-meta a || ≡ m|| a ||\n ||open-meta-a||≡a {m} {ν} a = begin\n m|| open-meta a ||\n ≡⟨ TypeSubstSizeLemmas.||a/s|| (MMS.weaken a) (MTS.sub (simpl (mvar zero))) lem ⟩\n m|| (MMS.weaken a) ||\n ≡⟨ ||weaken-a|| a ⟩\n m|| a || ∎\n where\n module MMS = MetaTypeMetaSubst\n module MTS = MetaTypeTypeSubst\n lem : ∀ (x : Fin (suc ν)) → m|| lookup x (MetaTypeTypeSubst.sub (simpl (mvar zero))) || ≡ 1\n lem zero = refl\n lem (suc x) =\n cong m||_|| (MetaTypeTypeLemmas.lookup-sub-↑⋆ {t = (simpl (mvar zero))} zero x)\n\nmodule SubstSizeLemmas where\n open TypeLemmas\n\n mutual\n ||a|| : ∀ {ν} (a : Type ν) → || a || ≥ 1\n ||a|| (simpl (tc x)) = s≤s z≤n\n ||a|| (simpl (tvar n)) = s≤s z≤n\n ||a|| (simpl (a →' b)) = s≤s z≤n\n ||a|| (a ⇒ b) = s≤s z≤n\n ||a|| (∀' a) = s≤s z≤n\n\n ||a/Var|| : ∀ {ν μ} (a : Type ν) (s : Sub Fin ν μ) → || a /Var s || ≡ || a ||\n ||a/Var|| (a ⇒ b) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| (∀' a) s = cong (λ u → 1 + u) (||a/Var|| a (s VarSubst.↑))\n ||a/Var|| (simpl (tvar x)) s = refl\n ||a/Var|| (simpl (a →' b)) s = cong₂ (λ u v → 1 + u + v) (||a/Var|| a s) (||a/Var|| b s)\n ||a/Var|| (simpl (tc c)) s = refl\n\n ||weaken-a|| : ∀ {ν} (a : Type ν) → || weaken a || ≡ || a ||\n ||weaken-a|| {ν} a = begin\n || weaken a ||\n ≡⟨ refl ⟩\n || a /Var VarSubst.wk ||\n ≡⟨ ||a/Var|| a VarSubst.wk ⟩\n || a || ∎\n\n ||s↑|| : ∀ {ν μ} (s : Sub Type ν μ) →\n (∀ (x : Fin ν) → || lookup x s || ≡ 1) →\n ∀ y → || lookup y (s ↑) || ≡ 1\n ||s↑|| s p zero = refl\n ||s↑|| s p (suc y) = begin\n || lookup y (map weaken s) ||\n ≡⟨ cong ||_|| (sym $ lookup⋆map s weaken y) ⟩\n || weaken (lookup y s) ||\n ≡⟨ ||weaken-a|| (lookup y s) ⟩\n || (lookup y s) ||\n ≡⟨ p y ⟩\n 1 ∎\n\n ||a/s|| : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) →\n (∀ x → || lookup x s || ≡ 1) →\n || a / s || ≡ || a ||\n ||a/s|| (a ⇒ b) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (∀' a) s p = cong (λ u → 1 + u) (||a/s|| a (s ↑) (||s↑|| s p))\n ||a/s|| {m} {ν} (simpl (tvar x)) s p = begin\n || (simpl (tvar x)) / s ||\n ≡⟨ cong ||_|| (var-/ {x = x}) ⟩\n || lookup x s ||\n ≡⟨ p x ⟩\n 1 ∎\n ||a/s|| (simpl (a →' b)) s p = cong₂ (λ u v → 1 + u + v) (||a/s|| a s p) (||a/s|| b s p)\n ||a/s|| (simpl (tc c)) s p = refl\n\n ||a/wk↑k|| : ∀ {ν} k (a : Type (k + ν)) → || a / wk ↑⋆ k || ≡ || a ||\n ||a/wk↑k|| k a = ||a/s|| a (wk ↑⋆ k) (λ x → cong ||_|| (lookup-wk-↑⋆ k x))\n\n ||a/s||' : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) → || a || ≤ || a / s ||\n ||a/s||' (simpl (tc x)) s = s≤s z≤n\n ||a/s||' (simpl (tvar n)) s = ||a|| (lookup n s)\n ||a/s||' (simpl (a →' b)) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s))\n ||a/s||' (a ⇒ b) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s))\n ||a/s||' (∀' b) s = s≤s (||a/s||' b (s TypeSubst.↑))\n\n h||a/s|| : ∀ {ν μ} (a : Type ν) (s : Sub Type ν μ) → (, a) hρ≤ (, a / s)\n h||a/s|| (simpl (tc x)) s = s≤s z≤n\n h||a/s|| (simpl (tvar n)) s = ||a|| (proj₂ (lookup n s ◁))\n h||a/s|| (simpl (a →' b)) s = s≤s (<-+ (||a/s||' a s) (||a/s||' b s))\n h||a/s|| (a ⇒ b) s = h||a/s|| b s\n h||a/s|| (∀' b) s = h||a/s|| b (s TypeSubst.↑)\n\na-ρ<-∀a : ∀ {n} a → (suc n , a) ρ< (, ∀' a)\na-ρ<-∀a _ = ≤-refl\n\nb-ρ<-a⇒b : ∀ {ν} (a b : Type ν) → (_ , b) ρ< (_ , a ⇒ b)\nb-ρ<-a⇒b a b = s≤s (≤-steps || a || ≤-refl)\n\nb-hρ≤-a⇒b : ∀ {ν} (a b : Type ν) → (_ , b) hρ≤ (_ , a ⇒ b)\nb-hρ≤-a⇒b a b = subst (λ u → u ≤ h|| a ⇒ b ||) refl ≤-refl\n\na-m<-∀a : ∀ {m ν} a → (m , suc ν , a) m< (m , ν , ∀' a)\na-m<-∀a a = ≤-refl\n\nb-m<-a⇒b : ∀ {m ν} a b → (m , ν , b) m< (m , ν , a ⇒ b)\nb-m<-a⇒b a b = s≤s (≤-steps m|| a || ≤-refl)\n\nopen-meta-a-m<-∀'a : ∀ {m ν} a → (suc m , ν , open-meta a) m< (m , ν , ∀' a)\nopen-meta-a-m<-∀'a a = subst (λ x → x < m|| ∀' a ||)\n (sym $ MetaSubstSizeLemmas.||open-meta-a||≡a a) (a-m<-∀a a)\n", "meta": {"hexsha": "b06c1a6af3c7f6fc8230055b4301c292fbf2af54", "size": 10160, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_issues_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Implicits/Resolution/Termination/Lemmas/SizeMeasures.agda", "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.7786259542, "max_line_length": 101, "alphanum_fraction": 0.4380905512, "num_tokens": 4374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5428632831725051, "lm_q2_score": 0.3629692055196168, "lm_q1q2_score": 0.19704265459889495}} {"text": "module Generic.Lib.Reflection.Core where\n\nopen import Agda.Builtin.Reflection using (withNormalisation; Relevance; Visibility; clause) public\nopen import Reflection\n renaming (visible to expl; hidden to impl; instance′ to inst;\n relevant to rel; irrelevant to irr; pi to absPi; lam to absLam; def to appDef)\n hiding (Arg-info; var; con; meta; visibility; relevance; _≟_; return; _>>=_; _>>_) public\nopen import Reflection.Argument.Information using (ArgInfo; visibility; relevance) public\nimport Reflection.Name\nopen Term using () renaming (var to appVar; con to appCon; meta to appMeta) public\nopen Pattern using () renaming (var to patVar; con to patCon) public\nopen Literal using () renaming (meta to litMeta) public\nopen Sort public\n\nopen import Generic.Lib.Intro\nopen import Generic.Lib.Equality.Propositional\nopen import Generic.Lib.Decidable\nopen import Generic.Lib.Category\nopen import Generic.Lib.Data.Nat\nopen import Generic.Lib.Data.String\nopen import Generic.Lib.Data.Maybe\nopen import Generic.Lib.Data.Product\nopen import Generic.Lib.Data.List\n\nopen import Data.Vec using (toList)\nopen import Data.Vec.N-ary using (N-ary; curryⁿ)\n\ninfixr 5 _‵→_\ninfixl 3 _·_\n\nlistCurryⁿ : ∀ {α β} {A : Set α} {B : Set β} n -> (List A -> B) -> N-ary n A B\nlistCurryⁿ n f = curryⁿ {n = n} (f ∘ toList)\n\nnamed : String -> String\nnamed s = if s == \"_\" then \"x\" else s\n\nrecord Reify {α} (A : Set α) : Set α where\n field reify : A -> Term\n\n macro\n reflect : A -> Term -> TC _\n reflect = unify ∘ reify\nopen Reify {{...}} public\n\npattern pureVar n = appVar n []\npattern pureCon c = appCon c []\npattern pureDef f = appDef f []\npattern pureMeta m = appMeta m []\n\n{-# DISPLAY appVar i [] = pureVar i #-}\n{-# DISPLAY appCon c [] = pureCon c #-}\n{-# DISPLAY appDef f [] = pureDef f #-}\n{-# DISPLAY appMeta m [] = pureMeta m #-}\n\npattern explInfo r = arg-info expl r\npattern implInfo r = arg-info impl r\npattern instInfo r = arg-info inst r\n\n{-# DISPLAY arg-info expl r = explInfo r #-}\n{-# DISPLAY arg-info impl r = implInfo r #-}\n{-# DISPLAY arg-info inst r = instInfo r #-}\n\npattern explRelInfo = explInfo rel\npattern explIrrInfo = explInfo irr\npattern implRelInfo = implInfo rel\npattern implIrrInfo = implInfo irr\npattern instRelInfo = instInfo rel\npattern instIrrInfo = instInfo irr\n\n{-# DISPLAY explInfo rel = explRelInfo #-}\n{-# DISPLAY explInfo irr = explIrrInfo #-}\n{-# DISPLAY implInfo rel = implRelInfo #-}\n{-# DISPLAY implInfo irr = implIrrInfo #-}\n{-# DISPLAY instInfo rel = instRelInfo #-}\n{-# DISPLAY instInfo irr = instIrrInfo #-}\n\npattern explArg r x = arg (explInfo r) x\npattern implArg r x = arg (implInfo r) x\npattern instArg r x = arg (instInfo r) x\n\n{-# DISPLAY arg (explInfo r) = explArg r #-}\n{-# DISPLAY arg (implInfo r) = implArg r #-}\n{-# DISPLAY arg (instInfo r) = instArg r #-}\n\npattern explRelArg x = explArg rel x\npattern implRelArg x = implArg rel x\npattern instRelArg x = instArg rel x\n\n{-# DISPLAY explArg rel x = explRelArg x #-}\n{-# DISPLAY implArg rel x = implRelArg x #-}\n{-# DISPLAY instArg rel x = instRelArg x #-}\n\npattern pi s a b = absPi a (abs s b)\n\n{-# DISPLAY absPi a (abs s b) = pi s a b #-}\n\npattern explPi r s a b = pi s (explArg r a) b\npattern implPi r s a b = pi s (implArg r a) b\npattern instPi r s a b = pi s (instArg r a) b\n\n{-# DISPLAY pi (explArg r a) s b = explPi r s a b #-}\n{-# DISPLAY pi (implArg r a) s b = implPi r s a b #-}\n{-# DISPLAY pi (instArg r a) s b = instPi r s a b #-}\n\npattern explRelPi s a b = explPi rel a s b\npattern explIrrPi s a b = explPi irr a s b\npattern implRelPi s a b = implPi rel a s b\npattern implIrrPi s a b = implPi irr a s b\npattern instRelPi s a b = instPi rel a s b\npattern instIrrPi s a b = instPi irr a s b\n\n{-# DISPLAY explPi rel a s b = explRelPi s a b #-}\n{-# DISPLAY explPi irr a s b = explIrrPi s a b #-}\n{-# DISPLAY implPi rel a s b = implRelPi s a b #-}\n{-# DISPLAY implPi irr a s b = implIrrPi s a b #-}\n{-# DISPLAY instPi rel a s b = instRelPi s a b #-}\n{-# DISPLAY instPi irr a s b = instIrrPi s a b #-}\n\npattern lam v s t = absLam v (abs s t)\n\n{-# DISPLAY absLam v (abs s t) = lam v s t #-}\n\npattern explLam s t = lam expl s t\npattern implLam s t = lam impl s t\npattern instLam s t = lam inst s t\n\n{-# DISPLAY lam expl s t = explLam s t #-}\n{-# DISPLAY lam impl s t = implLam s t #-}\n{-# DISPLAY lam inst s t = instLam s t #-}\n\npattern _‵→_ a b = pi \"_\" (explRelArg a) b\n\n-- No longer parses for whatever reason.\n-- {-# DISPLAY pi \"_\" (explRelArg a) b = a ‵→ b #-}\n\nmutual\n <_>_ : ∀ {α} -> Relevance -> Set α -> Set α\n <_>_ = flip RelValue\n\n data RelValue {α} (A : Set α) : Relevance -> Set α where\n relv : A -> < rel > A\n irrv : .A -> < irr > A\n\nelimRelValue : ∀ {r α π} {A : Set α}\n -> (P : ∀ {r} -> < r > A -> Set π)\n -> (∀ x -> P (relv x))\n -> (∀ .x -> P (irrv x))\n -> (x : < r > A)\n -> P x\nelimRelValue P f g (relv x) = f x\nelimRelValue P f g (irrv x) = g x\n\nunrelv : ∀ {α} {A : Set α} -> < rel > A -> A\nunrelv (relv x) = x\n\n-- Is it possible to handle this in some other way that doesn't require a postulate?\n-- See the `appRel` function below. Or is the postulate fine?\npostulate\n .unirrv : ∀ {α} {A : Set α} -> < irr > A -> A\n\n<_>_~>_ : ∀ {α β} -> Relevance -> Set α -> Set β -> Set (α ⊔ β)\n< rel > A ~> B = A -> B\n< irr > A ~> B = .A -> B\n\nlamRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A -> B) -> < r > A ~> B\nlamRel {rel} f = λ x -> f (relv x)\nlamRel {irr} f = λ x -> f (irrv x)\n\n-- The laziness is intentional.\nappRel : ∀ {r α β} {A : Set α} {B : Set β} -> (< r > A ~> B) -> < r > A -> B\nappRel {rel} f rx = f (unrelv rx)\nappRel {irr} f rx = f (unirrv rx)\n\nPi : ∀ {α β} i -> (A : Set α) -> (< relevance i > A -> Set β) -> Set (α ⊔ β)\nPi explRelInfo A B = (x : A) -> B (relv x)\nPi explIrrInfo A B = . (x : A) -> B (irrv x)\nPi implRelInfo A B = {x : A} -> B (relv x)\nPi implIrrInfo A B = . {x : A} -> B (irrv x)\nPi instRelInfo A B = {{x : A}} -> B (relv x)\nPi instIrrInfo A B = .{{x : A}} -> B (irrv x)\n\nlamPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> (∀ x -> B x) -> Pi i A B\nlamPi explRelInfo f = λ x -> f (relv x)\nlamPi explIrrInfo f = λ x -> f (irrv x)\nlamPi implRelInfo f = f _\nlamPi implIrrInfo f = f _\nlamPi instRelInfo f = f _\nlamPi instIrrInfo f = f _\n\nappPi : ∀ {α β} {A : Set α} i {B : < relevance i > A -> Set β} -> Pi i A B -> ∀ x -> B x\nappPi explRelInfo f (relv x) = f x\nappPi explIrrInfo f (irrv x) = f x\nappPi implRelInfo y (relv x) = y\nappPi implIrrInfo y (irrv x) = y\nappPi instRelInfo y (relv x) = y {{x}}\nappPi instIrrInfo y (irrv x) = y {{x}}\n\nRelEq : ∀ {α} -> Relevance -> Set α -> Set α\nRelEq rel A = Eq A\nRelEq irr A = ⊤\n\nvis : {A : Set} -> (A -> List (Arg Term) -> Term) -> A -> List Term -> Term\nvis k x = k x ∘ map explRelArg\n\nvis# : ∀ {A : Set} n -> (A -> List (Arg Term) -> Term) -> A -> N-ary n Term Term\nvis# n k = listCurryⁿ n ∘ vis k\n\nisRelevant : Relevance -> Bool\nisRelevant rel = true\nisRelevant irr = false\n\nargInfo : ∀ {α} {A : Set α} -> Arg A -> _\nargInfo (arg i x) = i\n\nargVal : ∀ {α} {A : Set α} -> Arg A -> A\nargVal (arg i x) = x\n\nunExpl : ∀ {α} {A : Set α} -> Arg A -> Maybe A\nunExpl (explArg r x) = just x\nunExpl _ = nothing\n\nabsName : ∀ {α} {A : Set α} -> Abs A -> String\nabsName (abs s x) = s\n\nabsVal : ∀ {α} {A : Set α} -> Abs A -> A\nabsVal (abs s x) = x\n\npatVars : List String -> List (Arg Pattern)\npatVars = map (explRelArg ∘ patVar ∘ named)\n\nrecord Data {α} (A : Set α) : Set α where\n no-eta-equality\n constructor packData\n field\n dataName : Name\n parsTele : Type\n indsTele : Type\n consTypes : List A\n consNames : All (const Name) consTypes\nopen Data public\n\ninstance\n NameEq : Eq Name\n NameEq = viaBase Reflection.Name._≟_\n\n EqRelValue : ∀ {α r} {A : Set α} {{aEq : RelEq r A}} -> Eq (< r > A)\n EqRelValue {A = A} {{aEq}} = record\n { _≟_ = go\n } where\n relv-inj : {x y : A} -> relv x ≡ relv y -> x ≡ y\n relv-inj refl = refl\n\n go : ∀ {r} {{aEq : RelEq r A}} -> IsSet (< r > A)\n go (relv x) (relv y) = dcong relv relv-inj (x ≟ y)\n go (irrv x) (irrv y) = yes refl\n\n ArgFunctor : ∀ {α} -> RawFunctor {α} Arg\n ArgFunctor = record\n { _<$>_ = λ{ f (arg i x) -> arg i (f x) }\n }\n\n AbsFunctor : ∀ {α} -> RawFunctor {α} Abs\n AbsFunctor = record\n { _<$>_ = λ{ f (abs s x) -> abs s (f x) }\n }\n\n TCMonad : ∀ {α} -> RawMonad {α} TC\n TCMonad = record\n { return = Reflection.return\n ; _>>=_ = Reflection._>>=_\n }\n\n TCApplicative : ∀ {α} -> RawApplicative {α} TC\n TCApplicative = rawIApplicative\n\n TCFunctor : ∀ {α} -> RawFunctor {α} TC\n TCFunctor = rawFunctor\n\nkeep : (ℕ -> ℕ) -> ℕ -> ℕ\nkeep ι 0 = 0\nkeep ι (suc n) = suc (ι n)\n\n{-# TERMINATING #-}\nmutual\n ren : (ℕ -> ℕ) -> Term -> Term\n ren ι (appVar v xs) = appVar (ι v) (rens ι xs)\n ren ι (appCon c xs) = appCon c (rens ι xs)\n ren ι (appDef f xs) = appDef f (rens ι xs)\n ren ι (lam v s t) = lam v s (ren (keep ι) t)\n ren ι (pat-lam cs xs) = undefined where postulate undefined : _\n ren ι (pi s a b) = pi s (ren ι <$> a) (ren (keep ι) b)\n ren ι (agda-sort s) = agda-sort (renSort ι s)\n ren ι (lit l) = lit l\n ren ι (appMeta x xs) = appMeta x (rens ι xs)\n ren ι unknown = unknown\n\n rens : (ℕ -> ℕ) -> List (Arg Term) -> List (Arg Term)\n rens ι = map (fmap (ren ι))\n\n renSort : (ℕ -> ℕ) -> Sort -> Sort\n renSort ι (set t) = set (ren ι t)\n renSort ι (lit n) = lit n\n renSort ι unknown = unknown\n\nshiftBy : ℕ -> Term -> Term\nshiftBy = ren ∘ _+_\n\nshift : Term -> Term\nshift = shiftBy 1\n\nunshiftBy : ℕ -> Term -> Term\nunshiftBy n = ren (_∸ n)\n\nisSomeName : Name -> Term -> Bool\nisSomeName n (appDef m _) = n == m\nisSomeName n (appCon m _) = n == m\nisSomeName n t = false\n\n{-# TERMINATING #-}\nmutual\n mapName : (ℕ -> List (Arg Term) -> Term) -> Name -> Term -> Term\n mapName f n (appVar v xs) = appVar v (mapNames f n xs)\n mapName f n (appCon m xs) = (if n == m then f 0 else appCon m) (mapNames f n xs)\n mapName f n (appDef m xs) = (if n == m then f 0 else appDef m) (mapNames f n xs)\n mapName f n (lam v s t) = lam v s (mapName (f ∘ suc) n t)\n mapName f n (pat-lam cs xs) = undefined where postulate undefined : _\n mapName f n (pi s a b) = pi s (mapName f n <$> a) (mapName (f ∘ suc) n b)\n mapName f n (agda-sort s) = agda-sort (mapNameSort f n s)\n mapName f n (lit l) = lit l\n mapName f n (appMeta x xs) = appMeta x (mapNames f n xs)\n mapName f n unknown = unknown\n\n mapNames : (ℕ -> List (Arg Term) -> Term) -> Name -> List (Arg Term) -> List (Arg Term)\n mapNames f n = map (fmap (mapName f n))\n\n mapNameSort : (ℕ -> List (Arg Term) -> Term) -> Name -> Sort -> Sort\n mapNameSort f n (set t) = set (mapName f n t)\n mapNameSort f n (lit l) = lit l\n mapNameSort f n unknown = unknown\n\nexplsOnly : List (Arg Term) -> List Term\nexplsOnly = mapMaybe unExpl\n\ninitType : Type -> Type\ninitType (pi s a b) = pi s a (initType b)\ninitType b = unknown\n\nlastType : Type -> Type\nlastType (pi s a b) = lastType b\nlastType b = b\n\n-- These two should return just `Type` like everything else.\ntakePis : ℕ -> Type -> Maybe Type\ntakePis 0 a = just unknown\ntakePis (suc n) (pi s a b) = pi s a <$> takePis n b\ntakePis _ _ = nothing\n\ndropPis : ℕ -> Type -> Maybe Type\ndropPis 0 a = just a\ndropPis (suc n) (pi s a b) = dropPis n b\ndropPis _ _ = nothing\n\nmonoLastType : Type -> Type\nmonoLastType = go 0 where\n go : ℕ -> Type -> Type\n go n (pi s a b) = go (suc n) b\n go n b = unshiftBy n b\n\nappendType : Type -> Type -> Type\nappendType (pi s a b) c = pi s a (appendType b c)\nappendType b c = c\n\nexplLamsBy : Type -> Term -> Term\nexplLamsBy (explPi r s a b) t = explLam s (explLamsBy b t)\nexplLamsBy (pi s a b) t = explLamsBy b t\nexplLamsBy b t = t\n\nimplicitize : Type -> Type\nimplicitize (explPi r s a b) = implPi r s a (implicitize b)\nimplicitize (pi s a b) = pi s a (implicitize b)\nimplicitize b = b\n\nleadImpls : Type -> List (Abs Term)\nleadImpls (implPi r s a b) = abs s a ∷ leadImpls b\nleadImpls b = []\n\npisToAbsArgTypes : Type -> List (Abs (Arg Type))\npisToAbsArgTypes (pi s a b) = abs s a ∷ pisToAbsArgTypes b\npisToAbsArgTypes b = []\n\nexplPisToAbsTypes : Type -> List (Abs Type)\nexplPisToAbsTypes (explPi r s a b) = abs s a ∷ explPisToAbsTypes b\nexplPisToAbsTypes (pi s a b) = explPisToAbsTypes b\nexplPisToAbsTypes b = []\n\nexplPisToNames : Type -> List String\nexplPisToNames = map absName ∘ explPisToAbsTypes\n\ncountPis : Type -> ℕ\ncountPis = length ∘ pisToAbsArgTypes\n\ncountExplPis : Type -> ℕ\ncountExplPis = length ∘ explPisToAbsTypes\n\npisToAbsArgVars : ℕ -> Type -> List (Abs (Arg Term))\npisToAbsArgVars (suc n) (pi s (arg i a) b) = abs s (arg i (pureVar n)) ∷ pisToAbsArgVars n b\npisToAbsArgVars n b = []\n\npisToArgVars : ℕ -> Type -> List (Arg Term)\npisToArgVars = map absVal % ∘ pisToAbsArgVars\n\nexplPisToAbsVars : ℕ -> Type -> List (Abs Term)\nexplPisToAbsVars (suc n) (explPi r s a b) = abs s (pureVar n) ∷ explPisToAbsVars n b\nexplPisToAbsVars (suc n) (pi s a b) = explPisToAbsVars n b\nexplPisToAbsVars n b = []\n\nthrow : ∀ {α} {A : Set α} -> String -> TC A\nthrow s = typeError (strErr s ∷ [])\n\npanic : ∀ {α} {A : Set α} -> String -> TC A\npanic s = throw $ \"panic: \" ++ˢ s\n\n-- I'll merge these later.\nmacro\n sate : Name -> Term -> TC _\n sate f ?r =\n getType f >>= λ a ->\n let res = λ app -> quoteTC (vis# (countExplPis a) app f) >>= unify ?r in\n getDefinition f >>= λ\n { (data-cons _) -> res appCon\n ; _ -> res appDef\n }\n\n sateMacro : Name -> Term -> TC _\n sateMacro f ?r =\n getType f >>= λ a ->\n quoteTC (vis# (pred (countExplPis a)) appDef f) >>= unify ?r\n\n_·_ : Term -> Term -> Term\n_·_ = sate _$_\n\nunshift′ : Term -> Term\nunshift′ t = explLam \"_\" t · sate tt₀\n\n-- A note for myself: `foldℕ (sate lsuc) (sate lzero) n` is not `reify n`:\n-- it's damn `lsuc` -- not `suc`.\ntermLevelOf : Term -> Maybe Term\ntermLevelOf (agda-sort (set t)) = just t\ntermLevelOf (agda-sort (lit n)) = just (foldℕ (sate lsuc) (sate lzero) n)\ntermLevelOf (agda-sort unknown) = just unknown\ntermLevelOf _ = nothing\n\ninstance\n TermReify : Reify Term\n TermReify = record\n { reify = id\n }\n\n NameReify : Reify Name\n NameReify = record\n { reify = lit ∘′ name\n }\n\n VisibilityReify : Reify Visibility\n VisibilityReify = record\n { reify = λ\n { expl -> sate expl\n ; impl -> sate impl\n ; inst -> sate inst\n }\n }\n\n RelevanceReify : Reify Relevance\n RelevanceReify = record\n { reify = λ\n { rel -> sate rel\n ; irr -> sate irr\n }\n }\n\n ArgInfoReify : Reify ArgInfo\n ArgInfoReify = record\n { reify = λ{ (arg-info v r) -> sate arg-info (reify v) (reify r) }\n }\n\n ProdReify : ∀ {α β} {A : Set α} {B : A -> Set β}\n {{aReify : Reify A}} {{bReify : ∀ {x} -> Reify (B x)}} -> Reify (Σ A B)\n ProdReify = record\n { reify = uncurry λ x y -> sate _,_ (reify x) (reify y)\n }\n\n ℕReify : Reify ℕ\n ℕReify = record\n { reify = foldℕ (sate suc) (sate zero)\n }\n\n ListReify : ∀ {α} {A : Set α} {{aReify : Reify A}} -> Reify (List A)\n ListReify = record\n { reify = foldr (sate _∷_ ∘ reify) (sate [])\n }\n\n AllReify : ∀ {α β} {A : Set α} {B : A -> Set β} {xs} {{bReify : ∀ {x} -> Reify (B x)}}\n -> Reify (All B xs)\n AllReify {B = B} {{bReify}} = record\n { reify = go _\n } where\n go : ∀ xs -> All B xs -> Term\n go [] tt = sate tt₀\n go (x ∷ xs) (y , ys) = sate _,_ (reify {{bReify}} y) (go xs ys)\n\ntoTuple : List Term -> Term\ntoTuple = foldr₁ (sate _,_) (sate tt₀)\n\ncurryBy : Type -> Term -> Term\ncurryBy = go 0 where\n go : ℕ -> Type -> Term -> Term\n go n (pi s (arg (arg-info v r) a) b) t = lam v s $ go (suc n) b t\n go n _ t = shiftBy n t · toTuple (map pureVar (downFrom n))\n\nexplUncurryBy : Type -> Term -> Term\nexplUncurryBy a f = explLam \"x\" $ appDef (quote id) (explArg rel (shift f) ∷ go a (pureVar 0)) where\n go : Term -> Term -> List (Arg Term)\n go (explPi r s a b@(pi _ _ _)) p = explArg r (sate proj₁ p) ∷ go b (sate proj₂ p)\n go (pi s a b@(pi _ _ _)) p = go b (sate proj₂ p)\n go (explPi r s a b) x = explArg r x ∷ []\n go _ t = []\n\ndefineTerm : Name -> Term -> TC _\ndefineTerm n t =\n getType n >>= λ a ->\n defineFun n (clause (map (implRelArg ∘ patVar ∘ named ∘ absName) (leadImpls a)) t ∷ [])\n\n-- Able to normalize a Setω.\nnormalize : Term -> TC Term\nnormalize (pi s (arg i a) b) =\n pi s ∘ arg i <$> normalize a <*> extendContext (arg i a) (normalize b)\nnormalize t = normalise t\n\ngetNormType : Name -> TC Type\ngetNormType = getType >=> normalize\n\ninferNormType : Term -> TC Type\ninferNormType = inferType >=> normalize\n\ngetData : Name -> TC (Data Type)\ngetData d = getNormType d >>= λ ab -> getDefinition d >>= λ\n { (data-type p cs) ->\n mapM (λ c -> _,_ c ∘ dropPis p <$> getNormType c) cs >>= λ mans ->\n case takePis p ab ⊗ (dropPis p ab ⊗ (mapM (uncurry λ c ma -> flip _,_ c <$> ma) mans)) of λ\n { nothing -> panic \"getData: data\"\n ; (just (a , b , acs)) -> return ∘ uncurry (packData d a b) $ splitList acs\n }\n ; (record-type c _) -> getNormType c >>= dropPis (countPis ab) >>> λ\n { nothing -> panic \"getData: record\"\n ; (just a′) -> return $ packData d (initType ab) (lastType ab) (a′ ∷ []) (c , tt)\n }\n ; _ -> throw \"not a data\"\n }\n\nmacro\n TypeOf : Term -> Term -> TC _\n TypeOf t ?r = inferNormType t >>= unify ?r\n\n runTC : ∀ {α} {A : Set α} -> TC A -> Term -> TC _\n runTC a ?r = bindTC a quoteTC >>= unify ?r\n", "meta": {"hexsha": "30fea146a6d6e5903ddecb82df959621a9086c13", "size": 17849, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generic/Lib/Reflection/Core.agda", "max_stars_repo_name": "turion/Generic", "max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z", "max_issues_repo_path": "src/Generic/Lib/Reflection/Core.agda", "max_issues_repo_name": "turion/Generic", "max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z", "max_forks_repo_path": "src/Generic/Lib/Reflection/Core.agda", "max_forks_repo_name": "turion/Generic", "max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z", "avg_line_length": 31.535335689, "max_line_length": 100, "alphanum_fraction": 0.5834500532, "num_tokens": 6335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.3812195662561499, "lm_q1q2_score": 0.19507638209139164}} {"text": "module Untyped.Abstract where\n\nopen import Function\n\nopen import Data.String\nopen import Data.Nat\nopen import Data.Unit\nopen import Data.Product\nopen import Data.List\nopen import Data.Sum as Sum\nopen import Data.Maybe\nopen import Strict\n\nopen import Debug.Trace\nopen import Category.Monad\n\nopen import Untyped.Monads\n\npostulate fail : ∀ {a : Set} → a\n\nwillneverhappenipromise : ∀ {a : Set} → String → a\nwillneverhappenipromise m = trace m fail\n\nmodule _ where\n\n Var = ℕ\n Chan = ℕ\n\n mutual\n record Closure : Set where\n inductive\n constructor ⟨_⊢_⟩\n field\n env : Env\n body : Exp\n\n data Val : Set where\n tt : Val\n nat : ℕ → Val\n chan : Chan → Val\n ⟨_,_⟩ : Val → Val → Val -- pairs\n clos : Closure → Val -- closures\n\n Env = List Val\n\n data Exp : Set where\n -- the functional core\n nat : ℕ → Exp\n var : Var → Exp\n ƛ : Exp → Exp\n _·_ : Exp → Exp → Exp\n\n -- products\n pair : Exp → Exp → Exp\n letp : Exp → Exp → Exp\n\n -- communication\n close : Exp → Exp\n receive : Exp → Exp\n send : (ch : Exp) → (v : Exp) → Exp\n\n -- threading\n fork : Exp → Exp\n\n extend : Val → Env → Env\n extend = _∷_\n\n unsafeLookup : ∀ {a} → ℕ → List a → a\n unsafeLookup _ [] = willneverhappenipromise \"lookup fail\"\n unsafeLookup zero (x ∷ xs) = x\n unsafeLookup (suc n) (x ∷ xs) = unsafeLookup n xs\n\n unsafeUpdate : ∀ {a} → ℕ → List a → a → List a\n unsafeUpdate n [] a = willneverhappenipromise \"update fail\"\n unsafeUpdate zero (x ∷ xs) a = a ∷ xs\n unsafeUpdate (suc n) (x ∷ xs) a = x ∷ unsafeUpdate n xs a\n\n -- Ideally this should be two different dispatch sets\n data Comm : Set where\n -- communication\n send : Chan → Val → Comm\n recv : Chan → Comm\n clos : Chan → Comm\n\n data Threading : Set where\n -- threading\n fork : Closure → Threading\n yield : Threading\n\n Cmd = Comm ⊎ Threading\n\n ⟦_⟧-comm : Comm → Set\n ⟦ clos x ⟧-comm = ⊤\n ⟦ send x x₁ ⟧-comm = ⊤\n ⟦ recv x ⟧-comm = Val\n\n ⟦_⟧-thr : Threading → Set\n ⟦ fork x ⟧-thr = Chan\n ⟦ yield ⟧-thr = ⊤\n\n ⟦_⟧ : Cmd → Set\n ⟦ inj₁ x ⟧ = ⟦ x ⟧-comm\n ⟦ inj₂ y ⟧ = ⟦ y ⟧-thr\n\n data Thread : Set where\n thread : Free Cmd ⟦_⟧ Val → Thread\n\n ThreadPool = List Thread\n\n Links = Chan → Chan\n\n data Blocked : Set where\n blocked : Blocked\n \n {- Free an expression from its earthly -}\n module _ {m}\n ⦃ m-monad : RawMonad m ⦄\n ⦃ m-read : MonadReader m Env ⦄\n ⦃ m-res : MonadResumption m Closure Chan ⦄\n ⦃ m-comm : MonadComm m Chan Val ⦄\n where\n\n open M\n\n {-# NON_TERMINATING #-}\n eval : Exp → m Val\n eval (nat n) = do\n return (nat n)\n eval (var x) = do\n asks (unsafeLookup x) \n eval (ƛ e) = do\n asks (clos ∘ ⟨_⊢ e ⟩)\n eval (f · e) = do\n clos ⟨ env ⊢ body ⟩ ← eval f\n where _ → willneverhappenipromise \"not a closure\"\n v ← eval e\n local (λ _ → extend v env) (eval body)\n\n -- products\n eval (pair e₁ e₂) = do\n v₁ ← eval e₁\n v₂ ← eval e₂\n return ⟨ v₁ , v₂ ⟩\n \n eval (letp b e) = do\n ⟨ v₁ , v₂ ⟩ ← eval b\n where _ → willneverhappenipromise \"not a pair\"\n local (extend v₂ ∘ extend v₁) $ eval e\n\n -- communication\n eval (close e) = do\n chan c ← eval e\n where _ → willneverhappenipromise \"not a channel to close\"\n M.close c\n return tt\n eval (receive e) = do\n chan c ← eval e\n where _ → willneverhappenipromise \"not a channel to receive on\"\n M.recv c\n eval (send e₁ e₂) = do\n chan c ← eval e₁\n where _ → willneverhappenipromise \"not a channel to send on\"\n v ← eval e₂\n M.send c v\n return tt\n\n -- threading\n eval (fork e) = do\n clos cl ← eval e\n where _ → willneverhappenipromise \"not a closure to fork\"\n c ← M.fork cl\n return (chan c)\n\n {- Interpreting communication commands -}\n module _ {com}\n ⦃ com-comm : MonadComm com Chan Val ⦄ where\n\n communicate : (cmd : Comm) → com ⟦ cmd ⟧-comm\n communicate (Comm.send c v) = M.send c v\n communicate (Comm.recv x) = M.recv x\n communicate (clos x) = M.close x\n\n {- Interpreting threading commands -}\n module _ {thr}\n ⦃ thr-res : MonadResumption thr Closure Chan ⦄ where\n\n threading : (cmd : Threading) → thr ⟦ cmd ⟧-thr\n threading (Threading.fork cl) = M.fork cl\n threading Threading.yield = M.yield\n\n module _ {cmd}\n ⦃ cmd-comm : MonadComm cmd Chan Val ⦄\n ⦃ cmd-res : MonadResumption cmd Closure Chan ⦄ where\n\n handle : (c : Cmd) → cmd ⟦ c ⟧\n handle = Sum.[ communicate , threading ]\n\n {- Round robin scheduling -}\n module _ {w : Set} {m}\n\n ⦃ monad : RawMonad m ⦄\n ⦃ read : MonadState m (List w) ⦄\n\n (atomic : w → m ⊤) where\n\n open M\n\n {-# NON_TERMINATING #-}\n robin : m ⊤\n robin = do\n (h ∷ tl) ← get\n where [] → return tt\n put tl\n atomic h\n robin\n", "meta": {"hexsha": "975825aef52e29f4143f4427232f89a86433c718", "size": 4969, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Untyped/Abstract.agda", "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_issues_repo_path": "src/Untyped/Abstract.agda", "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Untyped/Abstract.agda", "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "avg_line_length": 23.0046296296, "max_line_length": 71, "alphanum_fraction": 0.5655061381, "num_tokens": 1639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.3849121444839335, "lm_q1q2_score": 0.19395960471703508}} {"text": "open import Nat\nopen import Prelude\nopen import List\n\nopen import contexts\nopen import core\n\nopen import lemmas-env\nopen import lemmas-progress\nopen import decidability\nopen import results-checks\n\n-- TODO we're forced to prove this weaker version, since the strong version is\n-- unprovable. That said, this weak version is still disappointing, so we\n-- should come up with some more thoerems to shore up its deficiencies -\n-- in particular, we should do something to mitigate the fact that an e\n-- may succeed for every even n and fail for every odd n\n-- - also, that evaluation may return different results for different n\n-- TODO complete, then delete\n-- e => r → ∀{n} e [n]=> r\n-- something similar for =>∅ ?\n-- (Σ[r] (e => r) ∧ e => ∅) → ⊥\n-- ∀{k} → Σ[r] (e [k]=> r) ∨ e [k]=> ∅\nmodule progress where\n progress : ∀{Δ Σ' Γ E e τ n} →\n Δ , Σ' , Γ ⊢ E →\n Δ , Σ' , Γ ⊢ e :: τ →\n -- Either there's some properly-typed result that e will eval to ...\n Σ[ r ∈ result ] Σ[ k ∈ constraints ] (\n (E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒ r ⊣ k) ∧\n Δ , Σ' ⊢ r ·: τ)\n -- ... or evaluation will have a constraint failure\n ∨ E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒∅\n\n xc-progress : ∀{Δ Σ' r1 r2 τ n} →\n Δ , Σ' ⊢ r1 ·: τ →\n Δ , Σ' ⊢ r2 ·: τ →\n Σ[ k ∈ constraints ] Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:= k\n ∨ Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:=∅\n\n xb-progress : ∀{Δ Σ' r ex τ n} →\n Δ , Σ' ⊢ r ·: τ →\n Δ , Σ' ⊢ ex :· τ →\n Σ[ k ∈ constraints ] (r ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:= k)\n ∨ r ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:=∅\n\n rule-fails : {n↓ : Nat} {E : env} {r : result} {ex : ex} → Set\n rule-fails {n↓} {E} {r} {ex} =\n Σ[ c-j ∈ Nat ] Σ[ x-j ∈ Nat ] Σ[ e-j ∈ exp ] (\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:=∅\n ∨ Σ[ k1 ∈ constraints ] (\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒∅)\n ∨ Σ[ k1 ∈ constraints ] Σ[ k2 ∈ constraints ] Σ[ r-j ∈ result ] (\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ 1+ n↓ ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒ r-j ⊣ k2 ∧ r-j ⇐ ex ⌊ ⛽⟨ n↓ ⟩ ⌋:=∅))\n\n lemma-xb-progress-case : ∀{Δ Σ' E r rules ex τ n n↓} →\n (n == 1+ n↓) →\n (len : Nat) →\n (unchecked : rule ctx) →\n len == ∥ unchecked ∥ →\n (failed : (rule-fails {n↓} {E} {r} {ex}) ctx) →\n (∀{c rule} → (c , rule) ∈ unchecked → (c , rule) ∈ rules) →\n (∀{c c-j x-j e-j p-j} →\n (c , c-j , x-j , e-j , p-j) ∈ failed →\n c == c-j ∧ (c , |C x-j => e-j) ∈ rules) →\n (∀{c} → dom rules c → dom unchecked c ∨ dom failed c) →\n Δ , Σ' ⊢ [ E ]case r of⦃· rules ·⦄ ·: τ →\n Δ , Σ' ⊢ ex :· τ →\n ex ≠ ¿¿ →\n Σ[ k ∈ constraints ] ([ E ]case r of⦃· rules ·⦄ ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:= k)\n ∨ [ E ]case r of⦃· rules ·⦄ ⇐ ex ⌊ ⛽⟨ n ⟩ ⌋:=∅\n\n progress {n = Z} Γ⊢E ta\n = Inl (_ , _ , ELimit , π2 (typ-inhabitance-pres Γ⊢E ta))\n progress {n = 1+ n} Γ⊢E ta'@(TAFix ta) = Inl (_ , _ , EFix , TAFix Γ⊢E ta')\n progress {n = 1+ n} Γ⊢E (TAVar x∈Γ)\n with env-all-Γ Γ⊢E x∈Γ\n ... | _ , x∈E , ta = Inl (_ , _ , EVar x∈E , ta)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg)\n with progress Γ⊢E ta-arg\n ... | Inr arg-fails = Inr (EFAppArg arg-fails)\n ... | Inl (rarg , _ , arg-evals , ta-rarg)\n with progress Γ⊢E ta-f\n ... | Inr f-fails = Inr (EFAppFun f-fails)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]fix f ⦇·λ x => ef ·⦈ , _ , f-evals , ta'@(TAFix Γ'⊢E' (TAFix ta-ef)))\n with progress {n = n} (EnvInd (EnvInd Γ'⊢E' ta') ta-rarg) ta-ef\n ... | Inr ef-fails = Inr (EFAppFixEval CF⛽ refl f-evals arg-evals ef-fails)\n ... | Inl (ref , _ , ef-evals , ta-ref) = Inl (_ , _ , EAppFix CF⛽ refl f-evals arg-evals ef-evals , ta-ref)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]??[ u ] , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ((rf-f ∘ rf-arg) , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl (fst _ , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl (snd _ , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ([ E' ]case rf of⦃· rules ·⦄ , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E (TAApp _ ta-f ta-arg) | Inl (rarg , _ , arg-evals , ta-rarg) | Inl ((C⁻[ _ ] _) , _ , f-evals , ta-rf)\n = Inl (_ , _ , EAppUnfinished f-evals (λ ()) arg-evals , TAApp ta-rf ta-rarg)\n progress {n = 1+ n} Γ⊢E TAUnit = Inl (_ , _ , EUnit , TAUnit)\n progress {n = 1+ n} Γ⊢E (TAPair _ ta1 ta2)\n with progress Γ⊢E ta1\n ... | Inr fails = Inr (EFPair1 fails)\n ... | Inl (_ , _ , evals1 , ta-r1)\n with progress Γ⊢E ta2\n ... | Inr fails = Inr (EFPair2 fails)\n ... | Inl (_ , _ , evals2 , ta-r2) = Inl (_ , _ , EPair evals1 evals2 , TAPair ta-r1 ta-r2)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta)\n with progress Γ⊢E ta\n ... | Inr fails = Inr (EFFst fails)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (⟨ r1 , r2 ⟩ , _ , evals , TAPair ta-r1 ta-r2)\n = Inl (_ , _ , EFst evals , ta-r1)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , evals , TAFix _ ())\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ((C⁻[ x ] q) , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]??[ x₁ ] , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ((q ∘ q₁) , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (fst q , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl (snd q , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TAFst ta) | Inl ([ x ]case q of⦃· x₁ ·⦄ , _ , evals , ta-r)\n = Inl (_ , _ , EFstUnfinished evals (λ ()) , TAFst ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta)\n with progress Γ⊢E ta\n ... | Inr fails = Inr (EFSnd fails)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (⟨ r1 , r2 ⟩ , _ , evals , TAPair ta-r1 ta-r2)\n = Inl (_ , _ , ESnd evals , ta-r2)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , evals , TAFix _ ())\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ((C⁻[ x ] q) , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]??[ x₁ ] , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ((q ∘ q₁) , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (fst q , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl (snd q , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {Δ} {Σ'} {E = E} {τ = τ} {1+ n} Γ⊢E (TASnd ta) | Inl ([ x ]case q of⦃· x₁ ·⦄ , _ , evals , ta-r)\n = Inl (_ , _ , ESndUnfinished evals (λ ()) , TASnd ta-r)\n progress {n = 1+ n} Γ⊢E (TACtor d∈Σ' c∈d ta)\n with progress Γ⊢E ta\n ... | Inr e-fails = Inr (EFCtor e-fails)\n ... | Inl (_ , _ , e-evals , ta-r) = Inl (_ , _ , ECtor e-evals , TACtor d∈Σ' c∈d ta-r)\n progress {Σ' = Σ'} {n = 1+ n} Γ⊢E (TACase d∈σ' e-ta cctx⊆rules h-rules)\n with progress Γ⊢E e-ta\n ... | Inr e-fails = Inr (EFMatchScrut e-fails)\n ... | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , _ , e-evals , TAFix _ ())\n ... | Inl ([ x ]??[ x₁ ] , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl ((re ∘ re₁) , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl (fst _ , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl (snd _ , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl ([ x ]case re of⦃· x₁ ·⦄ , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl ((C⁻[ _ ] _) , _ , e-evals , ta-re)\n = Inl (_ , _ , EMatchUnfinished e-evals (λ ()) , TACase d∈σ' Γ⊢E ta-re cctx⊆rules (λ form →\n let _ , _ , _ , c∈cctx , ec-ta = h-rules form in\n _ , c∈cctx , ec-ta))\n ... | Inl ((C[ c ] re) , _ , e-evals , TACtor d∈'σ' c∈cctx' ta-re)\n rewrite ctxunicity d∈'σ' d∈σ'\n with π2 (cctx⊆rules (_ , c∈cctx'))\n ... | form\n with h-rules form\n ... | _ , _ , _ , c∈cctx , ec-ta\n rewrite ctxunicity c∈cctx c∈cctx'\n with progress {n = n} (EnvInd Γ⊢E ta-re) ec-ta\n ... | Inr ec-fails = Inr (EFMatchRule CF⛽ form e-evals ec-fails)\n ... | Inl (_ , _ , ec-evals , ta-rec) = Inl (_ , _ , EMatch CF⛽ form e-evals ec-evals , ta-rec)\n progress {n = 1+ n} Γ⊢E (TAHole u∈Δ) = Inl (_ , _ , EHole , TAHole u∈Δ Γ⊢E)\n progress {n = 1+ n} Γ⊢E (TAAsrt _ ta1 ta2)\n with progress Γ⊢E ta1\n ... | Inr e1-fails = Inr (EFAsrtL e1-fails)\n ... | Inl (r1 , _ , e1-evals , ta-r1)\n with progress Γ⊢E ta2\n ... | Inr e2-fails = Inr (EFAsrtR e2-fails)\n ... | Inl (r2 , _ , e2-evals , ta-r2)\n with xc-progress ta-r1 ta-r2\n ... | Inl (_ , c-succ) = Inl (_ , _ , EAsrt e1-evals e2-evals c-succ , TAUnit)\n ... | Inr c-fail = Inr (EFAsrt e1-evals e2-evals c-fail)\n\n lemma-xc-no-coerce : ∀{Δ Σ' r1 r2 τ n} →\n Δ , Σ' ⊢ r1 ·: τ →\n Δ , Σ' ⊢ r2 ·: τ →\n r1 ≠ r2 →\n (∀{ex} → Coerce r1 := ex → ⊥) →\n r1 ≠ ⟨⟩ →\n (∀{r'1 r'2} → r1 ≠ ⟨ r'1 , r'2 ⟩) →\n (∀{c r} → r1 ≠ (C[ c ] r)) →\n Σ[ k ∈ constraints ] Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:= k\n ∨ Constraints⦃ r1 , r2 ⦄⌊ ⛽⟨ n ⟩ ⌋:=∅\n lemma-xc-no-coerce ta1 (TAFix x x₁) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 (TAApp ta2 ta3) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 TAUnit r1≠r2 no-coerce not-unit not-pair not-ctor\n with xb-progress ta1 TAUnit\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) CoerceUnit xb))\n ... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) CoerceUnit xb-fails)\n lemma-xc-no-coerce ta1 ta2@(TAPair _ _) r1≠r2 no-coerce not-unit not-pair not-ctor\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ {c-r2 → nc (_ , c-r2)})\n ... | Inl (_ , c-r2)\n with xb-progress ta1 (Coerce-preservation ta2 c-r2)\n ... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb))\n lemma-xc-no-coerce ta1 (TAFst ta2) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 (TASnd ta2) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 ta2@(TACtor _ _ _) r1≠r2 no-coerce not-unit not-pair not-ctor\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ {c-r2 → nc (_ , c-r2)})\n ... | Inl (_ , c-r2)\n with xb-progress ta1 (Coerce-preservation ta2 c-r2)\n ... | Inr xb-fails = Inr (XCFXB1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp1 r1≠r2 (Inl not-pair) (Inl not-ctor) c-r2 xb))\n lemma-xc-no-coerce ta1 (TAUnwrapCtor x x₁ ta2) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 (TACase x x₁ ta2 x₂ x₃) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n lemma-xc-no-coerce ta1 (TAHole x x₁) r1≠r2 no-coerce not-unit not-pair not-ctor\n = Inr (XCFNoCoerce r1≠r2 (Inl not-pair) (Inl not-ctor) no-coerce λ ())\n\n xc-progress {r1 = r1} {r2} ta1 ta2\n with result-==-dec r1 r2\n ... | Inl refl = Inl (_ , XCExRefl)\n xc-progress {r1 = _} {_} ta1@(TAFix x x₁) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress {r1 = _} {_} ta1@(TAApp _ _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress {r1 = _} {_} TAUnit ta2 | Inr r1≠r2\n with xb-progress ta2 TAUnit\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inl (λ ())) (Inl (λ ())) CoerceUnit xb))\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inl (λ ())) (Inl (λ ())) CoerceUnit xb-fails)\n xc-progress (TAPair ta1a ta1b) (TAPair ta2a ta2b) | Inr r1≠r2\n with xc-progress ta1a ta2a\n ... | Inr xca-fails = Inr (XCFPair1 xca-fails)\n ... | Inl (_ , xca)\n with xc-progress ta1b ta2b\n ... | Inr xcb-fails = Inr (XCFPair2 xcb-fails)\n ... | Inl (_ , xcb) = Inl (_ , XCPair r1≠r2 xca xcb)\n xc-progress ta1@(TAPair _ _) ta2@(TAApp _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAPair _ _) ta2@(TAFst _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAPair _ _) ta2@(TASnd _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAPair _ _) ta2@(TAUnwrapCtor _ _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAPair _ _) ta2@(TACase _ _ _ _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAPair _ _) ta2@(TAHole _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TAFst _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress {r1 = _} {_} ta1@(TASnd _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress (TACtor {c = c1} d∈σ1 c1∈cctx ta1) (TACtor {c = c2} d∈σ2 c2∈cctx ta2) | Inr r1≠r2\n with natEQ c1 c2\n ... | Inr ne = Inr (XCFCtorMM ne)\n ... | Inl refl\n rewrite ctxunicity d∈σ1 d∈σ2 | ctxunicity c1∈cctx c2∈cctx\n with xc-progress ta1 ta2\n ... | Inr xc-fails = Inr (XCFCtor xc-fails)\n ... | Inl (_ , xc) = Inl (_ , XCCtor (λ where refl → r1≠r2 refl) xc)\n xc-progress ta1@(TACtor _ _ _) ta2@(TAApp _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TACtor _ _ _) ta2@(TAFst _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TACtor _ _ _) ta2@(TASnd _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TACtor _ _ _) ta2@(TAUnwrapCtor _ _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TACtor _ _ _) ta2@(TACase _ _ _ _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress ta1@(TACtor _ _ _) ta2@(TAHole _ _) | Inr r1≠r2\n with Coerce-dec\n ... | Inr nc = Inr (XCFNoCoerce r1≠r2 (Inr (λ ())) (Inr (λ ())) (λ {c-r1 → nc (_ , c-r1)}) λ ())\n ... | Inl (_ , c-r1)\n with xb-progress ta2 (Coerce-preservation ta1 c-r1)\n ... | Inr xb-fails = Inr (XCFXB2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb-fails)\n ... | Inl (_ , xb) = Inl (_ , (XCBackProp2 r1≠r2 (Inr (λ ())) (Inr (λ ())) c-r1 xb))\n xc-progress {r1 = _} {_} ta1@(TAUnwrapCtor _ _ _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress {r1 = _} {_} ta1@(TACase _ _ _ _ _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n xc-progress {r1 = _} {_} ta1@(TAHole _ _) ta2 | Inr r1≠r2\n = lemma-xc-no-coerce ta1 ta2 r1≠r2 (λ ()) (λ ()) (λ ()) λ ()\n\n xb-progress {n = Z} _ _ = Inl (_ , XBLimit)\n xb-progress {ex = ex} {n = 1+ n} ta-r ta-ex\n with ex-¿¿-dec {ex}\n ... | Inl refl = Inl (_ , XBNone)\n xb-progress {n = 1+ n} ta-f@(TAFix Γ⊢E (TAFix ta-e)) (TAMap _ ta-v ta-ex) | Inr ne\n with progress {n = n} (EnvInd (EnvInd Γ⊢E ta-f) ta-v) ta-e\n ... | Inr fails = Inr (XBFFixEval CF⛽ refl fails)\n ... | Inl (_ , _ , evals , ta)\n with xb-progress {n = n} ta ta-ex\n ... | Inr fails = Inr (XBFFix CF⛽ refl evals fails)\n ... | Inl (_ , xb) = Inl (_ , XBFix CF⛽ refl evals xb)\n xb-progress (TAFix x (TAFix _)) TADC | Inr ne = Inl (_ , XBNone)\n xb-progress (TAApp {arg = v} ta-rf ta-rarg) ta-ex | Inr ne\n with value-dec {v}\n ... | Inr nv = Inr (XBFAppNonVal ne nv)\n ... | Inl val\n with xb-progress ta-rf (TAMap val ta-rarg ta-ex)\n ... | Inr fails = Inr (XBFApp ne val fails)\n ... | Inl (_ , xb) = Inl (_ , XBApp ne val xb)\n xb-progress TAUnit TAUnit | Inr ne = Inl (_ , XBUnit)\n xb-progress TAUnit TADC | Inr ne = Inl (_ , XBNone)\n xb-progress (TAPair ta-r1 ta-r2) (TAPair ta-ex1 ta-ex2) | Inr ne\n with xb-progress ta-r1 ta-ex1\n ... | Inr fails = Inr (XBFPair1 fails)\n ... | Inl (_ , xb1)\n with xb-progress ta-r2 ta-ex2\n ... | Inr fails = Inr (XBFPair2 fails)\n ... | Inl (_ , xb2) = Inl (_ , XBPair xb1 xb2)\n xb-progress (TAPair ta-r1 ta-r2) TADC | Inr ne = Inl (_ , XBNone)\n xb-progress (TAFst ta-r) ta-ex | Inr ne\n with xb-progress ta-r (TAPair ta-ex TADC)\n ... | Inr fails = Inr (XBFFst ne fails)\n ... | Inl (_ , xb) = Inl (_ , XBFst ne xb)\n xb-progress (TASnd ta-r) ta-ex | Inr ne\n with xb-progress ta-r (TAPair TADC ta-ex)\n ... | Inr fails = Inr (XBFSnd ne fails)\n ... | Inl (_ , xb) = Inl (_ , XBSnd ne xb)\n xb-progress (TACtor {c = c1} h1a h1b ta-r) (TACtor {c = c2} h2a h2b ta-ex) | Inr ne\n with natEQ c1 c2\n ... | Inr ne' = Inr (XBFCtorMM ne')\n ... | Inl refl\n rewrite ctxunicity h1a h2a | ctxunicity h1b h2b\n with xb-progress ta-r ta-ex\n ... | Inr fails = Inr (XBFCtor fails)\n ... | Inl (_ , xb) = Inl (_ , XBCtor xb)\n xb-progress (TACtor x x₁ ta-r) TADC | Inr ne = Inl (_ , XBNone)\n xb-progress (TAUnwrapCtor h1 h2 ta-r) ta-ex | Inr ne\n with xb-progress ta-r (TACtor h1 h2 ta-ex)\n ... | Inr fails = Inr (XBFUnwrapCtor ne fails)\n ... | Inl (_ , xb) = Inl (_ , XBUnwrapCtor ne xb)\n xb-progress {n = 1+ n} ta-C@(TACase {rules = rules} x x₁ ta-r x₂ x₃) ta-ex | Inr ne\n = lemma-xb-progress-case {n = 1+ n} {n} refl ∥ rules ∥ rules refl ∅ (λ y → y) (λ ()) Inl ta-C ta-ex ne\n xb-progress (TAHole x x₁) TAUnit | Inr ne\n = Inl (_ , XBHole ne λ ())\n xb-progress (TAHole x x₁) (TAPair ta-ex ta-ex₁) | Inr ne\n = Inl (_ , XBHole ne λ ())\n xb-progress (TAHole x x₁) (TACtor x₂ x₃ ta-ex) | Inr ne\n = Inl (_ , XBHole ne λ ())\n xb-progress (TAHole x x₁) TADC | Inr ne = Inl (_ , XBNone)\n xb-progress (TAHole x x₁) (TAMap x₂ x₃ ta-ex) | Inr ne\n = Inr XBFHole\n\n lemma-xb-progress-case {E = E} {r} {rules} {ex} {n = n} {n↓} refl Z [] len-unchecked failed unchecked-wf failed-wf exh ta-C ta-ex n¿¿\n = Inr (XBFMatch CF⛽ n¿¿ all-failed)\n where\n all-failed : ∀{c-j x-j : Nat} {e-j : exp} →\n (c-j , |C x-j => e-j) ∈ rules →\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:=∅\n ∨ Σ[ k1 ∈ constraints ] (\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒∅)\n ∨ Σ[ k1 ∈ constraints ] Σ[ k2 ∈ constraints ] Σ[ r-j ∈ result ] (\n r ⇐ C[ c-j ] ¿¿ ⌊ ⛽⟨ n ⟩ ⌋:= k1 ∧ (E ,, (x-j , C⁻[ c-j ] r)) ⊢ e-j ⌊ ⛽⟨ n↓ ⟩ ⌋⇒ r-j ⊣ k2 ∧ r-j ⇐ ex ⌊ ⛽⟨ n↓ ⟩ ⌋:=∅)\n all-failed c-j∈rules\n with exh (_ , c-j∈rules)\n ... | Inl (_ , ())\n ... | Inr ((c-j , x-j , e-j , p-j) , c-j∈f)\n with failed-wf c-j∈f\n ... | refl , c-j∈'rules\n with ctxunicity c-j∈rules c-j∈'rules\n ... | refl = p-j\n lemma-xb-progress-case {n = 1+ n↓} {n↓} refl (1+ len) unchecked len-unchecked failed unchecked-wf failed-wf exh ta-C@(TACase {rules = rules} d∈σ' Γ⊢E ta-r _ ta-rules) ta-ex n¿¿\n with ctx-elim {Γ = unchecked}\n ... | Inl refl = abort (0≠1+n (! len-unchecked))\n ... | Inr (c , |C x-j => e-j , unchecked' , refl , c#unchecked')\n with unchecked-wf (x,a∈Γ,,x,a {Γ = unchecked'})\n ... | c∈rules\n with ta-rules c∈rules\n ... | _ , c∈cctx , ta-be\n with xb-progress ta-r (TACtor d∈σ' c∈cctx TADC)\n ... | Inr fails\n = lemma-xb-progress-case\n refl\n len\n unchecked'\n (1+inj (len-unchecked · ctx-decreasing c#unchecked'))\n (failed ,, (c , fail))\n unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿\n where\n fail = c , x-j , e-j , (Inl fails)\n unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules\n unchecked-wf' {c' = c'} c'∈uc'\n with natEQ c c'\n ... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))\n ... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')\n failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →\n (c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →\n c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)\n failed-wf' {c' = c'} {c-j'} c'∈f+\n with natEQ c c'\n ... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)\n ... | Inl refl\n with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})\n ... | refl = refl , c∈rules\n exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'\n exh' {c' = c'} c'∈rules\n with natEQ c c'\n ... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})\n ... | Inr cne\n with exh c'∈rules\n ... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))\n ... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)\n ... | Inl (_ , xb-r)\n with progress {n = n↓} (EnvInd Γ⊢E (TAUnwrapCtor d∈σ' c∈cctx ta-r)) ta-be\n ... | Inr fails\n = lemma-xb-progress-case\n refl\n len\n unchecked'\n (1+inj (len-unchecked · ctx-decreasing c#unchecked'))\n (failed ,, (c , fail))\n unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿\n where\n fail = c , x-j , e-j , (Inr (Inl (_ , xb-r , fails)))\n unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules\n unchecked-wf' {c' = c'} c'∈uc'\n with natEQ c c'\n ... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))\n ... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')\n failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →\n (c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →\n c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)\n failed-wf' {c' = c'} {c-j'} c'∈f+\n with natEQ c c'\n ... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)\n ... | Inl refl\n with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})\n ... | refl = refl , c∈rules\n exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'\n exh' {c' = c'} c'∈rules\n with natEQ c c'\n ... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})\n ... | Inr cne\n with exh c'∈rules\n ... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))\n ... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)\n ... | Inl (_ , _ , evals , ta-br)\n with xb-progress {n = n↓} ta-br ta-ex\n ... | Inr fails\n = lemma-xb-progress-case\n refl\n len\n unchecked'\n (1+inj (len-unchecked · ctx-decreasing c#unchecked'))\n (failed ,, (c , fail))\n unchecked-wf' failed-wf' exh' ta-C ta-ex n¿¿\n where\n fail = c , x-j , e-j , (Inr (Inr (_ , _ , _ , xb-r , evals , fails)))\n unchecked-wf' : ∀{c' rule'} → (c' , rule') ∈ unchecked' → (c' , rule') ∈ rules\n unchecked-wf' {c' = c'} c'∈uc'\n with natEQ c c'\n ... | Inl refl = abort (c#unchecked' (_ , c'∈uc'))\n ... | Inr cne = unchecked-wf (x∈Γ→x∈Γ+ (flip cne) c'∈uc')\n failed-wf' : ∀{c' c-j' x-j' e-j' p-j'} →\n (c' , c-j' , x-j' , e-j' , p-j') ∈ (failed ,, (c , fail)) →\n c' == c-j' ∧ ((c' , (|C x-j' => e-j')) ∈ rules)\n failed-wf' {c' = c'} {c-j'} c'∈f+\n with natEQ c c'\n ... | Inr cne = failed-wf (x∈Γ+→x∈Γ (flip cne) c'∈f+)\n ... | Inl refl\n with ctxunicity c'∈f+ (x,a∈Γ,,x,a {Γ = failed})\n ... | refl = refl , c∈rules\n exh' : ∀{c'} → dom rules c' → dom unchecked' c' ∨ dom (failed ,, (c , fail)) c'\n exh' {c' = c'} c'∈rules\n with natEQ c c'\n ... | Inl refl = Inr (_ , x,a∈Γ,,x,a {Γ = failed})\n ... | Inr cne\n with exh c'∈rules\n ... | Inl (_ , c'∈uc) = Inl (_ , (x∈Γ+→x∈Γ (flip cne) c'∈uc))\n ... | Inr (_ , c'∈f) = Inr (_ , x∈Γ→x∈Γ+ (flip cne) c'∈f)\n ... | Inl (_ , xb)\n = Inl (_ , (XBMatch CF⛽ n¿¿ c∈rules xb-r evals xb))\n\n{- TODO delete - this strong version is unprovable\nmodule progress where\n progress : ∀{Δ Σ' Γ E e τ} →\n Δ , Σ' , Γ ⊢ E →\n Δ , Σ' , Γ ⊢ e :: τ →\n -- Either there's some properly-typed result that e will eval to\n -- for any beta reduction limit ...\n Σ[ r ∈ result ] (\n Δ , Σ' ⊢ r ·: τ ∧\n ∀{n} → Σ[ k ∈ constraints ] (E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒ r ⊣ k))\n ∨\n -- ... or evaluation will have a constraint failure for any\n -- beta reduction limit\n (∀{n} → E ⊢ e ⌊ ⛽⟨ n ⟩ ⌋⇒∅)\n progress Γ⊢E ta'@(TALam _ ta) = Inl (_ , TALam Γ⊢E ta' , (_ , EFun))\n progress Γ⊢E ta'@(TAFix _ _ ta) = Inl (_ , TAFix Γ⊢E ta' , (_ , EFix))\n progress Γ⊢E (TAVar x∈Γ)\n with env-all-Γ Γ⊢E x∈Γ\n ... | _ , x∈E , ta = Inl (_ , ta , (_ , EVar x∈E))\n progress Γ⊢E (TAApp _ ta-f ta-arg)\n with progress Γ⊢E ta-arg\n ... | Inr arg-fails = Inr (EFAppArg arg-fails)\n ... | Inl (_ , ta-rarg , arg-evals)\n with progress Γ⊢E ta-f\n ... | Inr f-fails = Inr (EFAppFun f-fails)\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl (([ E' ]λ x => ef) , TALam Γ'⊢E' (TALam x#Γ' ta-ef) , f-evals)\n with progress (EnvInd Γ'⊢E' ta-rarg) ta-ef\n ... | q = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ E' ]fix f ⦇·λ x => ef ·⦈ , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ x ]??[ x₁ ] , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ((rf ∘ rf₁) , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ((get[ x th-of x₁ ] rf) , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl ([ x ]case rf of⦃· x₁ ·⦄ , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TAApp _ ta-f ta-arg) | Inl (_ , ta-rarg , arg-evals) | Inl (PF x , ta-rf , f-evals) = {!!}\n progress Γ⊢E (TATpl ∥es∥==∥τs∥ _ tas) = {!!}\n progress {Δ} {Σ'} {E = E} {τ = τ} Γ⊢E (TAGet {i = i} {len} {e} len==∥τs∥ i<∥τs∥ ta)\n with progress Γ⊢E ta\n ... | Inr e-fails = Inr (EFGet e-fails)\n ... | Inl (⟨ rs ⟩ , TATpl ∥rs∥==∥τs∥ tas , e-evals)\n = let i<∥rs∥ = tr (λ y → i < y) (! ∥rs∥==∥τs∥) i<∥τs∥ in\n Inl (_ , tas i<∥rs∥ i<∥τs∥ , _ , EGet (len==∥τs∥ · ! ∥rs∥==∥τs∥) i<∥rs∥ (π2 e-evals))\n ... | Inl (([ x ]λ x₁ => x₂) , TALam _ () , e-evals)\n ... | Inl ([ x ]fix x₁ ⦇·λ x₂ => x₃ ·⦈ , TAFix _ () , e-evals)\n ... | Inl ([ x ]??[ x₁ ] , ta-r , e-evals)\n rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())\n ... | Inl ((r ∘ r₁) , ta-r , e-evals)\n rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())\n ... | Inl ((get[ x th-of x₁ ] r) , ta-r , e-evals)\n rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())\n ... | Inl ([ x ]case r of⦃· x₁ ·⦄ , ta-r , e-evals)\n rewrite len==∥τs∥ = Inl (_ , TAGet i<∥τs∥ ta-r , _ , EGetUnfinished (π2 e-evals) λ ())\n ... | Inl (PF x , TAPF () , e-evals)\n progress Γ⊢E (TACtor d∈Σ' c∈d ta)\n with progress Γ⊢E ta\n ... | Inl (_ , ta-r , e-evals) = Inl (_ , TACtor d∈Σ' c∈d ta-r , _ , ECtor (π2 e-evals))\n ... | Inr e-fails = Inr (EFCtor e-fails)\n progress Γ⊢E (TACase x ta x₁ x₂) = {!!}\n progress Γ⊢E (TAHole u∈Δ) = Inl (_ , TAHole u∈Δ Γ⊢E , (_ , EHole))\n progress Γ⊢E (TAPF ta) = Inl (_ , TAPF ta , (_ , EPF))\n progress Γ⊢E (TAAsrt x ta ta₁) = {!!}\n-}\n", "meta": {"hexsha": "52fb06fae80e92039df97af7fdbb93888573d42d", "size": 34925, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "progress.agda", "max_stars_repo_name": "hazelgrove/hazelnat-myth-", "max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z", "max_issues_repo_path": "progress.agda", "max_issues_repo_name": "hazelgrove/hazelnat-myth-", "max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "progress.agda", "max_forks_repo_name": "hazelgrove/hazelnat-myth-", "max_forks_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.6964285714, "max_line_length": 178, "alphanum_fraction": 0.4787115247, "num_tokens": 15241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.3174262591305011, "lm_q1q2_score": 0.19170382274945477}} {"text": "{-# OPTIONS --safe #-}\n\nmodule Definition.Conversion.EqRelInstance where\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties using (wkSingleSubstId)\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.Weakening using (_∷_⊆_; wkEq; step; id)\nopen import Definition.Conversion\nopen import Definition.Conversion.Reduction\nopen import Definition.Conversion.Universe\nopen import Definition.Conversion.Stability\nopen import Definition.Conversion.Soundness\nopen import Definition.Conversion.Lift\nopen import Definition.Conversion.Conversion\nopen import Definition.Conversion.Transitivity\nopen import Definition.Conversion.Weakening\nopen import Definition.Conversion.Whnf\nopen import Definition.Typed.EqualityRelation\nopen import Definition.Typed.Consequences.Syntactic\nopen import Definition.Typed.Consequences.Substitution\nopen import Definition.Typed.Consequences.Injectivity\nopen import Definition.Typed.Consequences.Equality\nopen import Definition.Typed.Consequences.Reduction\nopen import Definition.Conversion.Symmetry\n\nopen import Tools.Nat\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\nopen import Tools.Function\n\n\n-- Algorithmic equality of neutrals with injected conversion.\ndata _⊢_~_∷_^_ (Γ : Con Term) (k l A : Term) (r : TypeInfo) : Set where\n ↑ : ∀ {B} → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ↑ B ^ r → Γ ⊢ k ~ l ∷ A ^ r\n\n-- Properties of algorithmic equality of neutrals with injected conversion.\n\n~-var : ∀ {x A r Γ} → Γ ⊢ var x ∷ A ^ r → Γ ⊢ var x ~ var x ∷ A ^ r\n~-var x =\n let ⊢A = syntacticTerm x\n in ↑ (refl ⊢A) (var-refl′ x)\n\n~-app : ∀ {f g a b F G Γ rF lF lG lΠ}\n → Γ ⊢ f ~ g ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ]\n → Γ ⊢ a [genconv↑] b ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ f ∘ a ^ lΠ ~ g ∘ b ^ lΠ ∷ G [ a ] ^ [ ! , ι lG ]\n~-app {rF = !} (↑ A≡B (~↑! x)) x₁ =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ΠFG≡B′ = trans A≡B (subset* (red D))\n H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′\n F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)\n _ , ⊢f , _ = syntacticEqTerm (soundnessConv↑Term x₁)\n in ↑ (substTypeEq G≡E (refl ⊢f))\n (app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)\n B≡ΠHE ([~] _ (red D) whnfB′ x))\n (convConvTerm x₁ F≡H))\n~-app {rF = %} (↑ A≡B (~↑! x)) x₁ =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ΠFG≡B′ = trans A≡B (subset* (red D))\n H , E , B≡ΠHE = Π≡A ΠFG≡B′ whnfB′\n F≡H , _ , _ , _ , G≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) B≡ΠHE ΠFG≡B′)\n _ , ⊢f , _ = syntacticEqTerm (proj₂ (proj₂ (soundness~↑% x₁)))\n in ↑ (substTypeEq G≡E (genRefl ⊢f))\n (app-cong′ (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _)\n B≡ΠHE ([~] _ (red D) whnfB′ x))\n (conv~↑% x₁ F≡H))\n~-natrec : ∀ {z z′ s s′ n n′ F F′ Γ lF}\n → (Γ ∙ ℕ ^ [ ! , ι ⁰ ]) ⊢ F [conv↑] F′ ^ [ ! , ι lF ] →\n Γ ⊢ z [conv↑] z′ ∷ (F [ zero ]) ^ ι lF →\n Γ ⊢ s [conv↑] s′ ∷ (Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF) ° lF ° lF) ^ ι lF →\n Γ ⊢ n ~ n′ ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ natrec lF F z s n ~ natrec lF F′ z′ s′ n′ ∷ (F [ n ]) ^ [ ! , ι lF ]\n~-natrec {n = n} {n′ = n′} x x₁ x₂ (↑ A≡B (~↑! x₄)) =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ℕ≡B′ = trans A≡B (subset* (red D))\n B≡ℕ = ℕ≡A ℕ≡B′ whnfB′\n k~l′ = PE.subst (λ x → _ ⊢ n ~ n′ ↓! x ^ _) B≡ℕ\n ([~] _ (red D) whnfB′ x₄)\n ⊢F , _ = syntacticEq (soundnessConv↑ x)\n _ , ⊢n , _ = syntacticEqTerm (soundness~↓! k~l′)\n in ↑ (refl (substType ⊢F ⊢n)) (natrec-cong′ x x₁ x₂ k~l′)\n\n\n~-Emptyrec : ∀ {e e' F F′ Γ l lEmpty}\n → Γ ⊢ F [conv↑] F′ ^ [ ! , ι l ] →\n Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ] →\n Γ ⊢ e' ∷ Empty lEmpty ^ [ % , ι lEmpty ] →\n Γ ⊢ Emptyrec l lEmpty F e ~ Emptyrec l lEmpty F′ e' ∷ F ^ [ ! , ι l ]\n~-Emptyrec {e = e} {e' = e'} x ⊢e ⊢e' =\n let k~l′ = %~↑ ⊢e ⊢e'\n ⊢F , _ = syntacticEq (soundnessConv↑ x)\n in ↑ (refl ⊢F) (Emptyrec-cong′ x k~l′)\n\n~-IdCong : ∀ {A A' : Term} {l : Level} {t t' u u' : Term} {Γ : Con Term} →\n Γ ⊢ A ~ A' ∷ Univ ! l ^ [ ! , next l ] →\n Γ ⊢ t [conv↑] t' ∷ A ^ ι l →\n Γ ⊢ u [conv↑] u' ∷ A ^ ι l →\n Γ ⊢ Id A t u ~ Id A' t' u' ∷ SProp l ^ [ ! , next l ]\n~-IdCong (↑ A≡B (~↑! x)) t~t' u~u' =\n let ⊢Γ = wfEqTerm (soundnessConv↑Term t~t')\n _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n A~A′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-cong A~A′ t~t' u~u'))\n\n~-Idℕ : ∀ {t t' u u' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ u [genconv↑] u' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ Id ℕ t u ~ Id ℕ t' u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n~-Idℕ ⊢Γ (↑ A≡B (~↑! x)) u~u' =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ℕ≡B′ = trans A≡B (subset* (red D))\n B≡ℕ = ℕ≡A ℕ≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ t~t′ u~u'))\n\n~-Idℕ0 : ∀ {u u' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ Id ℕ zero u ~ Id ℕ zero u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n~-Idℕ0 ⊢Γ (↑ A≡B (~↑! x)) =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ℕ≡B′ = trans A≡B (subset* (red D))\n B≡ℕ = ℕ≡A ℕ≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕ0 t~t′))\n\n~-IdℕS : ∀ {t t' u u' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ Id ℕ (suc t) u ~ Id ℕ (suc t') u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n~-IdℕS ⊢Γ X (↑ A≡B (~↑! x)) =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n ℕ≡B′ = trans A≡B (subset* (red D))\n B≡ℕ = ℕ≡A ℕ≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-ℕS X t~t′))\n\n~-IdU : ∀ {t t' u u' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ t ~ t' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ u [genconv↑] u' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) t' u' ∷ SProp ¹ ^ [ ! , next ¹ ]\n~-IdU ⊢Γ (↑ A≡B (~↑! x)) X =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-U t~t′ X))\n\n~-IdUℕ : ∀ {u u' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) ℕ u' ∷ SProp ¹ ^ [ ! , next ¹ ]\n~-IdUℕ ⊢Γ (↑ A≡B (~↑! x)) =\n let _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-Uℕ t~t′))\n\n~-IdUΠ : ∀ {A : Term} {rA : Relevance} {B A' B' u u' : Term}\n {Γ : Con Term} →\n Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~\n Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰) u' ∷ SProp ¹ ^ [ ! , next ¹ ]\n~-IdUΠ X (↑ A≡B (~↑! x)) =\n let ⊢Γ = wfEqTerm (soundnessConv↑Term X)\n _ , ⊢B = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (Ugenⱼ ⊢Γ)) (~↑! (Id-UΠ X t~t′))\n\n~-castcong : ∀ {A A' B B' e e' t t' : Term} {Γ : Con Term} →\n Γ ⊢ A ~ A' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ B [genconv↑] B' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ A ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) A B ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) A' B' ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ A B e t ~ cast ⁰ A' B' e' t' ∷ B ^ [ ! , ι ⁰ ]\n~-castcong (↑ A≡B (~↑! x)) X Y ⊢e ⊢e' =\n let _ , ⊢B , _ = syntacticEqTerm (soundnessConv↑Term X)\n _ , ⊢B' = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B'\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n in ↑ (refl (univ ⊢B)) (~↑! (cast-cong t~t′ X Y ⊢e ⊢e'))\n\n~-castℕ : ∀ {B B' e e' t t' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) ℕ B ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) ℕ B' ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ ℕ B' e' t' ∷ B ^ [ ! , ι ⁰ ]\n~-castℕ ⊢Γ (↑ A≡B (~↑! x)) X ⊢e ⊢e' =\n let _ , ⊢B' = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B'\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n _ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)\n in ↑ (refl (univ ⊢B)) (~↑! (cast-ℕ t~t′ X ⊢e ⊢e'))\n\n~-castℕℕ : ∀ {e e' t t' : Term} {Γ : Con Term} →\n ⊢ Γ →\n Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]\n~-castℕℕ ⊢Γ (↑ A≡B (~↑! x)) ⊢e ⊢e' =\n let _ , ⊢B' = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B'\n ℕ≡B′ = trans A≡B (subset* (red D))\n B≡ℕ = ℕ≡A ℕ≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ\n ([~] _ (red D) whnfB′ x)\n _ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)\n in ↑ (refl (univ (ℕⱼ ⊢Γ))) (~↑! (cast-ℕℕ t~t′ ⊢e ⊢e'))\n\n~-castΠ : ∀ {A A' : Term} {rA : Relevance} {P P' B B' e e' t t' : Term}\n {Γ : Con Term} →\n Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B e t ~ cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) B' e' t' ∷ B ^ [ ! , ι ⁰ ]\n~-castΠ X (↑ A≡B (~↑! x)) Y ⊢e ⊢e' =\n let _ , ⊢B' = syntacticEq A≡B\n B′ , whnfB′ , D = whNorm ⊢B'\n U≡B′ = trans A≡B (subset* (red D))\n B≡U = U≡A-whnf U≡B′ whnfB′\n t~t′ = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡U\n ([~] _ (red D) whnfB′ x)\n _ , ⊢B , _ = syntacticEqTerm (soundness~↓! t~t′)\n in ↑ (refl (univ ⊢B)) (~↑! (cast-Π X t~t′ Y ⊢e ⊢e'))\n\n~-castℕΠ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}\n {Γ : Con Term} →\n Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ ℕ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) e' t' ∷\n Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]\n~-castℕΠ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢A ▹ ⊢P))) (~↑! (cast-ℕΠ X Y ⊢e ⊢e'))\n\n~-castΠℕ : ∀ {A A' : Term} {rA : Relevance} {P P' e e' t t' : Term}\n {Γ : Con Term} →\n Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ A ^ [ rA , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰\n ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ e t ~\n cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]\n~-castΠℕ ⊢A ⊢P X Y ⊢e ⊢e' = ↑ (refl (univ (ℕⱼ (wfTerm ⊢A)))) (~↑! (cast-Πℕ X Y ⊢e ⊢e'))\n\n~-castΠΠ%! : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →\n Γ ⊢ A ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ A ^ [ % , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ B ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ B ^ [ ! , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~\n cast ⁰ (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]\n~-castΠΠ%! ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))\n (~↑! (cast-ΠΠ%! X Y t~t' ⊢e ⊢e'))\n\n~-castΠΠ!% : ∀ {A A' P P' B B' Q Q' e e' t t' : Term} {Γ : Con Term} →\n Γ ⊢ A ∷ Univ ! ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ A ^ [ ! , ι ⁰ ]) ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ [genconv↑] Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ B ∷ Univ % ⁰ ^ [ ! , next ⁰ ] →\n (Γ ∙ B ^ [ % , ι ⁰ ]) ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ [genconv↑] Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ] →\n Γ ⊢ t [genconv↑] t' ∷ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ] →\n Γ ⊢ e ∷ Id (U ⁰) (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ e' ∷ Id (U ⁰) (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) ^ [ % , next ⁰ ] →\n Γ ⊢ cast ⁰ (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~\n cast ⁰ (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]\n~-castΠΠ!% ⊢A ⊢P X ⊢B ⊢Q Y t~t' ⊢e ⊢e' = ↑ (refl (univ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢B ▹ ⊢Q)))\n (~↑! (cast-ΠΠ!% X Y t~t' ⊢e ⊢e'))\n\n~-sym : {k l A : Term} {r : TypeInfo} {Γ : Con Term} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ k ∷ A ^ r\n~-sym (↑ A≡B x) =\n let ⊢Γ = wfEq A≡B\n B , A≡B′ , l~k = sym~↑ (reflConEq ⊢Γ) x\n in ↑ (trans A≡B A≡B′) l~k\n\n~-trans : {k l m A : Term} {r : TypeInfo} {Γ : Con Term}\n → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ m ∷ A ^ r\n → Γ ⊢ k ~ m ∷ A ^ r\n~-trans (↑ x (~↑! x₁)) (↑ x₂ (~↑! x₃)) =\n let ⊢Γ = wfEq x\n k~m , _ = trans~↑! PE.refl (reflConEq ⊢Γ) x₁ x₃\n in ↑ x (~↑! k~m)\n~-trans (↑ x (~↑% x₁)) (↑ x₂ (~↑% x₃)) =\n let ⊢Γ = wfEq x\n k~m = trans~↑% (reflConEq ⊢Γ) x₁ (conv~↑% x₃ (trans (sym x₂) x))\n in ↑ x (~↑% k~m)\n\n~-wk : {k l A : Term} {r : TypeInfo} {ρ : Wk} {Γ Δ : Con Term} →\n ρ ∷ Δ ⊆ Γ →\n ⊢ Δ → Γ ⊢ k ~ l ∷ A ^ r → Δ ⊢ wk ρ k ~ wk ρ l ∷ wk ρ A ^ r\n~-wk x x₁ (↑ x₂ x₃) = ↑ (wkEq x x₁ x₂) (wk~↑ x x₁ x₃)\n\n\n~-conv : {k l A B : Term} {r : TypeInfo} {Γ : Con Term} →\n Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ∷ B ^ r\n~-conv (↑ x x₁) x₂ = ↑ (trans (sym x₂) x) x₁\n\n~-to-conv : {k l A : Term} {Γ : Con Term} {r : TypeInfo} →\n Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ k [genconv↑] l ∷ A ^ r\n~-to-conv {r = [ ! , ll ]} (↑ x x₁) = convConvTerm (lift~toConv↑ x₁) (sym x)\n~-to-conv {r = [ % , ll ]} (↑ x (~↑% x₁)) = conv~↑% x₁ (sym x)\n\nun-univConv : ∀ {A B : Term} {r : Relevance} {l : Level} {Γ : Con Term} →\n Γ ⊢ A [conv↑] B ^ [ r , ι l ] →\n Γ ⊢ A [conv↑] B ∷ Univ r l ^ next l\nun-univConv {A} {B} {r} {l} ([↑] A′ B′ D D′ whnfA′ whnfB′ (univ x)) =\n let ⊢Γ = wfEqTerm (soundnessConv↓Term x)\n in [↑]ₜ (Univ r l) A′ B′ (id (Ugenⱼ ⊢Γ)) (un-univ⇒* D) (un-univ⇒* D′) Uₙ whnfA′ whnfB′ x\n\n\nΠₜ-cong : ∀ {F G H E rF rG lF lG lΠ Γ}\n → lF ≤ lΠ\n → lG ≤ lΠ\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ⊢ F [conv↑] H ∷ Univ rF lF ^ next lF\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ G [conv↑] E ∷ Univ rG lG ^ next lG\n → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ [conv↑] Π H ^ rF ° lF ▹ E ° lG ° lΠ ∷ Univ rG lΠ ^ next lΠ\nΠₜ-cong lF< lG< x x₁ x₂ = liftConvTerm (Π-cong PE.refl PE.refl PE.refl PE.refl lF< lG< x x₁ x₂)\n\n~-irrelevance : {k l A : Term} {Γ : Con Term} {ll : TypeLevel}\n → Γ ⊢ k ∷ A ^ [ % , ll ]\n → Γ ⊢ l ∷ A ^ [ % , ll ]\n → Γ ⊢ k ~ l ∷ A ^ [ % , ll ]\n~-irrelevance ⊢k ⊢l =\n let X = ~↑% (%~↑ ⊢k ⊢l)\n ⊢A = syntacticTerm ⊢k\n in ↑ (refl ⊢A) X\n\nsoundnessgenConv : ∀ {a b A r Γ} → Γ ⊢ a [genconv↑] b ∷ A ^ r → Γ ⊢ a ≡ b ∷ A ^ r\nsoundnessgenConv {r = [ ! , l ]} = soundnessConv↑Term\nsoundnessgenConv {r = [ % , l ]} x = proj₂ (proj₂ (soundness~↑% x))\n\nsymgenConv : ∀ {t u A r Γ} → Γ ⊢ t [genconv↑] u ∷ A ^ r → Γ ⊢ u [genconv↑] t ∷ A ^ r\nsymgenConv {r = [ ! , l ]} = symConvTerm\nsymgenConv {r = [ % , l ]} t<>u = let ⊢Γ = wfEqTerm (proj₂ (proj₂ (soundness~↑% t<>u)))\n in sym~↑% (reflConEq ⊢Γ) t<>u\n\nwkgenConv↑Term : ∀ {ρ t u A Γ r Δ} ([ρ] : ρ ∷ Δ ⊆ Γ) → ⊢ Δ\n → Γ ⊢ t [genconv↑] u ∷ A ^ r\n → Δ ⊢ wk ρ t [genconv↑] wk ρ u ∷ wk ρ A ^ r\nwkgenConv↑Term {r = [ ! , l ]} = wkConv↑Term\nwkgenConv↑Term {r = [ % , l ]} = wk~↑%\n\nconvgenconv : ∀ {t u A B : Term} {r : TypeInfo} {Γ : Con Term} →\n Γ ⊢ t [genconv↑] u ∷ A ^ r →\n Γ ⊢ A ≡ B ^ r → Γ ⊢ t [genconv↑] u ∷ B ^ r\nconvgenconv {r = [ ! , l ]} = convConvTerm\nconvgenconv {r = [ % , l ]} = conv~↑%\n\ntransgenConv : ∀ {t u v A : Term} {r : TypeInfo} {Γ : Con Term} →\n Γ ⊢ t [genconv↑] u ∷ A ^ r →\n Γ ⊢ u [genconv↑] v ∷ A ^ r → Γ ⊢ t [genconv↑] v ∷ A ^ r\ntransgenConv {r = [ ! , l ]} = transConvTerm\ntransgenConv {r = [ % , l ]} = trans~↑!Term\n\n\n-- Algorithmic equality instance of the generic equality relation.\ninstance eqRelInstance : EqRelSet\neqRelInstance = eqRel _⊢_[conv↑]_^_ _⊢_[genconv↑]_∷_^_ _⊢_~_∷_^_\n ~-to-conv soundnessConv↑ soundnessgenConv\n univConv↑ un-univConv\n symConv symgenConv ~-sym\n transConv transgenConv ~-trans\n convgenconv ~-conv\n wkConv↑ wkgenConv↑Term ~-wk\n reductionConv↑ reductionConv↑Term\n (liftConv ∘ᶠ (U-refl PE.refl)) ( liftConvTerm ∘ᶠ (U-refl PE.refl))\n (liftConvTerm ∘ᶠ ℕ-refl)\n (liftConvTerm ∘ᶠ (Empty-refl PE.refl))\n Πₜ-cong\n (λ x x₁ x₂ → liftConvTerm (∃-cong PE.refl x x₁ x₂))\n (liftConvTerm ∘ᶠ zero-refl)\n (liftConvTerm ∘ᶠ suc-cong)\n (λ l< l<' x x₁ x₂ x₃ x₄ x₅ → liftConvTerm (η-eq l< l<' x x₁ x₂ x₃ x₄ x₅))\n ~-var ~-app ~-natrec ~-Emptyrec\n ~-IdCong ~-Idℕ ~-Idℕ0 ~-IdℕS ~-IdU ~-IdUℕ ~-IdUΠ\n ~-castcong ~-castℕ ~-castℕℕ ~-castΠ ~-castℕΠ ~-castΠℕ ~-castΠΠ%! ~-castΠΠ!%\n ~-irrelevance\n", "meta": {"hexsha": "23b885835d11ce4b6f841f69f86c60c163125035", "size": 19533, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion/EqRelInstance.agda", "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_issues_repo_path": "Definition/Conversion/EqRelInstance.agda", "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Definition/Conversion/EqRelInstance.agda", "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "avg_line_length": 45.4255813953, "max_line_length": 116, "alphanum_fraction": 0.4106384068, "num_tokens": 10148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5117166047041652, "lm_q2_score": 0.3738758227716966, "lm_q1q2_score": 0.19131846660970883}} {"text": "module subst where\n\nopen import lib\n\nopen import cedille-types\nopen import ctxt-types\nopen import is-free\nopen import rename\nopen import general-util\nopen import syntax-util\n\nsubsth-ret-t : Set → Set\nsubsth-ret-t T = ∀ {ed} → ctxt → renamectxt → trie ⟦ ed ⟧ → T → T\n\nsubsth : ∀ {ed} → substh-ret-t ⟦ ed ⟧\nsubsth-term : substh-ret-t term\nsubsth-type : substh-ret-t type\nsubsth-kind : substh-ret-t kind\nsubsth-tk : substh-ret-t tk\nsubsth-optClass : substh-ret-t optClass\nsubsth-optGuide : substh-ret-t optGuide\nsubsth-optTerm : substh-ret-t optTerm\nsubsth-optType : substh-ret-t optType\nsubsth-liftingType : substh-ret-t liftingType\nsubsth-arg : substh-ret-t arg\nsubsth-args : substh-ret-t args\nsubsth-params : substh-ret-t params\nsubsth-cases : substh-ret-t cases\nsubsth-varargs : {ed : exprd} → ctxt → renamectxt → trie ⟦ ed ⟧ → varargs → varargs × renamectxt\n\nsubsth{TERM} = substh-term\nsubsth{TYPE} = substh-type\nsubsth{KIND} = substh-kind\nsubsth{LIFTINGTYPE} = substh-liftingType\nsubsth{TK} = substh-tk\nsubsth{ARG} = substh-arg\nsubsth{QUALIF} = λ Γ ρ σ q → q\n\nsubst-rename-var-if : {ed : exprd} → ctxt → renamectxt → var → trie ⟦ ed ⟧ → var\nsubst-rename-var-if Γ ρ \"_\" σ = \"_\"\nsubst-rename-var-if Γ ρ x σ =\n {- rename bound variable x iff it is one of the vars being substituted for, \n or if x occurs free in one of the terms we are substituting for vars, \n or if it is the renamed version of any variable -}\n if trie-contains σ x || trie-any (is-free-in check-erased x) σ || renamectxt-in-range ρ x || ctxt-binds-var Γ x then \n rename-away-from x (λ s → ctxt-binds-var Γ s || trie-contains σ s) ρ\n else\n x\n\nsubsth-term Γ ρ σ (App t m t') = App (substh-term Γ ρ σ t) m (substh-term Γ ρ σ t')\nsubsth-term Γ ρ σ (AppTp t tp) = AppTp (substh-term Γ ρ σ t) (substh-type Γ ρ σ tp)\nsubsth-term Γ ρ σ (Hole x₁) = Hole x₁\nsubsth-term Γ ρ σ (Lam _ b _ x oc t) =\n let x' = subst-rename-var-if Γ ρ x σ in\n Lam posinfo-gen b posinfo-gen x' (substh-optClass Γ ρ σ oc) \n (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t)\nsubsth-term Γ ρ σ (Let _ (DefTerm _ x m t) t') =\n let x' = subst-rename-var-if Γ ρ x σ in\n (Let posinfo-gen (DefTerm posinfo-gen x' (substh-optType Γ ρ σ m) (substh-term Γ ρ σ t))\n (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t'))\nsubsth-term Γ ρ σ (Let _ (DefType _ x k t) t') =\n let x' = subst-rename-var-if Γ ρ x σ in\n (Let posinfo-gen (DefType posinfo-gen x' (substh-kind Γ ρ σ k) (substh-type Γ ρ σ t))\n (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t'))\nsubsth-term Γ ρ σ (Open _ x t) = Open posinfo-gen x (substh-term Γ ρ σ t)\nsubsth-term Γ ρ σ (Parens _ t _) = substh-term Γ ρ σ t\nsubsth-term{TERM} Γ ρ σ (Var _ x) =\n let x' = renamectxt-rep ρ x in\n trie-lookup-else (Var posinfo-gen x') σ x'\nsubsth-term{ARG} Γ ρ σ (Var _ x) =\n let x' = renamectxt-rep ρ x in\n inst-lookup-term σ x'\nsubsth-term{QUALIF} Γ ρ σ (Var _ x) =\n let x' = renamectxt-rep ρ x in\n qualif-lookup-term σ x'\nsubsth-term Γ ρ σ (Var _ x) = Var posinfo-gen (renamectxt-rep ρ x)\nsubsth-term Γ ρ σ (Beta _ ot ot') = Beta posinfo-gen (substh-optTerm Γ ρ σ ot) (substh-optTerm Γ ρ σ ot')\nsubsth-term Γ ρ σ (IotaPair _ t1 t2 og pi') = IotaPair posinfo-gen (substh-term Γ ρ σ t1) (substh-term Γ ρ σ t2) (substh-optGuide Γ ρ σ og) pi'\nsubsth-term Γ ρ σ (IotaProj t n _) = IotaProj (substh-term Γ ρ σ t) n posinfo-gen\nsubsth-term Γ ρ σ (Epsilon _ lr m t) = Epsilon posinfo-gen lr m (substh-term Γ ρ σ t)\nsubsth-term Γ ρ σ (Sigma _ t) = Sigma posinfo-gen (substh-term Γ ρ σ t)\nsubsth-term Γ ρ σ (Phi _ t t₁ t₂ _) = Phi posinfo-gen (substh-term Γ ρ σ t) (substh-term Γ ρ σ t₁) (substh-term Γ ρ σ t₂) posinfo-gen\nsubsth-term Γ ρ σ (Rho _ op on t og t') = Rho posinfo-gen op on (substh-term Γ ρ σ t) (substh-optGuide Γ ρ σ og) (substh-term Γ ρ σ t')\nsubsth-term Γ ρ σ (Chi _ T t') = Chi posinfo-gen (substh-optType Γ ρ σ T) (substh-term Γ ρ σ t')\nsubsth-term Γ ρ σ (Delta _ T t') = Delta posinfo-gen (substh-optType Γ ρ σ T) (substh-term Γ ρ σ t')\nsubsth-term Γ ρ σ (Theta _ θ t ls) = Theta posinfo-gen (substh-theta θ) (substh-term Γ ρ σ t) (substh-lterms ls)\n where substh-lterms : lterms → lterms\n substh-lterms (LtermsNil pi) = LtermsNil pi\n substh-lterms (LtermsCons m t ls) = LtermsCons m (substh-term Γ ρ σ t) (substh-lterms ls)\n substh-vars : vars → vars\n substh-vars (VarsStart x) = VarsStart (renamectxt-rep ρ x)\n substh-vars (VarsNext x xs) = VarsNext (renamectxt-rep ρ x) (substh-vars xs)\n substh-theta : theta → theta\n substh-theta (AbstractVars xs) = AbstractVars (substh-vars xs)\n substh-theta θ = θ\nsubsth-term Γ ρ σ (Mu _ x t ot _ cs _) =\n let x' = subst-rename-var-if Γ ρ x σ in\n let ρ' = renamectxt-insert ρ x x' in\n Mu posinfo-gen x' (substh-term (ctxt-var-decl x' Γ) ρ' σ t) (substh-optType Γ ρ σ ot) posinfo-gen (substh-cases Γ ρ' σ cs) posinfo-gen\nsubsth-term Γ ρ σ (Mu' _ t ot _ cs _) = Mu' posinfo-gen (substh-term Γ ρ σ t) (substh-optType Γ ρ σ ot) posinfo-gen (substh-cases Γ ρ σ cs) posinfo-gen\n\nsubsth-cases Γ ρ σ NoCase = NoCase\nsubsth-cases Γ ρ σ (SomeCase _ x varargs t cs) =\n let res = substh-varargs Γ ρ σ varargs in\n SomeCase posinfo-gen x (fst res) (substh-term Γ (snd res) σ t) (substh-cases Γ ρ σ cs)\n\nsubsth-varargs Γ ρ σ NoVarargs = NoVarargs , ρ\nsubsth-varargs Γ ρ σ (NormalVararg x varargs) =\n let x' = subst-rename-var-if Γ ρ x σ in\n let ρ' = renamectxt-insert ρ x x' in\n let res = substh-varargs Γ ρ' σ varargs in\n NormalVararg x' (fst res) , snd res\nsubsth-varargs Γ ρ σ (ErasedVararg x varargs) =\n let x' = subst-rename-var-if Γ ρ x σ in\n let ρ' = renamectxt-insert ρ x x' in\n let res = substh-varargs Γ ρ' σ varargs in\n ErasedVararg x' (fst res) , snd res\nsubsth-varargs Γ ρ σ (TypeVararg x varargs) =\n let x' = subst-rename-var-if Γ ρ x σ in\n let ρ' = renamectxt-insert ρ x x' in\n let res = substh-varargs Γ ρ' σ varargs in\n TypeVararg x' (fst res) , snd res\n\nsubsth-type Γ ρ σ (Abs _ b _ x atk t) =\n let x' = subst-rename-var-if Γ ρ x σ in\n Abs posinfo-gen b posinfo-gen x' (substh-tk Γ ρ σ atk)\n (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t)\nsubsth-type Γ ρ σ (TpLambda _ _ x atk t) =\n let x' = subst-rename-var-if Γ ρ x σ in\n TpLambda posinfo-gen posinfo-gen x' (substh-tk Γ ρ σ atk) \n (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t)\nsubsth-type Γ ρ σ (Iota _ _ x m t) =\n let x' = subst-rename-var-if Γ ρ x σ in\n Iota posinfo-gen posinfo-gen x' (substh-type Γ ρ σ m)\n (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t)\nsubsth-type Γ ρ σ (Lft _ _ x t l) =\n let x' = subst-rename-var-if Γ ρ x σ in\n Lft posinfo-gen posinfo-gen x' (substh-term (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t) \n (substh-liftingType Γ ρ σ l)\nsubsth-type Γ ρ σ (TpApp tp tp₁) = TpApp (substh-type Γ ρ σ tp) (substh-type Γ ρ σ tp₁)\nsubsth-type Γ ρ σ (TpAppt tp t) = TpAppt (substh-type Γ ρ σ tp) (substh-term Γ ρ σ t)\nsubsth-type Γ ρ σ (TpArrow tp arrowtype tp₁) = TpArrow (substh-type Γ ρ σ tp) arrowtype (substh-type Γ ρ σ tp₁)\nsubsth-type Γ ρ σ (TpEq _ x₁ x₂ _) = TpEq posinfo-gen (substh-term Γ ρ σ x₁) (substh-term Γ ρ σ x₂) posinfo-gen\nsubsth-type Γ ρ σ (TpParens _ tp _) = substh-type Γ ρ σ tp\nsubsth-type Γ ρ σ (NoSpans tp _) = substh-type Γ ρ σ tp\nsubsth-type{TYPE} Γ ρ σ (TpVar _ x) =\n let x' = renamectxt-rep ρ x in\n trie-lookup-else (TpVar posinfo-gen x') σ x'\nsubsth-type{ARG} Γ ρ σ (TpVar _ x) =\n let x' = renamectxt-rep ρ x in\n inst-lookup-type σ x'\nsubsth-type{QUALIF} Γ ρ σ (TpVar _ x) =\n let x' = renamectxt-rep ρ x in\n qualif-lookup-type σ x'\nsubsth-type Γ ρ σ (TpVar _ x) = TpVar posinfo-gen (renamectxt-rep ρ x)\nsubsth-type Γ ρ σ (TpHole _) = TpHole posinfo-gen --ACG\nsubsth-type Γ ρ σ (TpLet _ (DefTerm _ x m t) t') =\n let x' = subst-rename-var-if Γ ρ x σ in\n (TpLet posinfo-gen (DefTerm posinfo-gen x' (substh-optType Γ ρ σ m) (substh-term Γ ρ σ t))\n (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t'))\nsubsth-type Γ ρ σ (TpLet _ (DefType _ x k t) t') =\n let x' = subst-rename-var-if Γ ρ x σ in\n (TpLet posinfo-gen (DefType posinfo-gen x' (substh-kind Γ ρ σ k) (substh-type Γ ρ σ t))\n (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ t'))\nsubsth-kind Γ ρ σ (KndArrow k k₁) = KndArrow (substh-kind Γ ρ σ k) (substh-kind Γ ρ σ k₁)\nsubsth-kind Γ ρ σ (KndParens x₁ k x₂) = substh-kind Γ ρ σ k\nsubsth-kind Γ ρ σ (KndPi _ _ x atk k) =\n let x' = subst-rename-var-if Γ ρ x σ in\n KndPi posinfo-gen posinfo-gen x' (substh-tk Γ ρ σ atk)\n (substh-kind (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ k)\nsubsth-kind Γ ρ σ (KndTpArrow t k) = KndTpArrow (substh-type Γ ρ σ t) (substh-kind Γ ρ σ k)\nsubsth-kind{QUALIF} Γ ρ σ (KndVar _ x xs) =\n qualif-lookup-kind (substh-args Γ ρ σ xs) σ x\nsubsth-kind Γ ρ σ (KndVar _ x xs) = KndVar posinfo-gen x (substh-args Γ ρ σ xs)\nsubsth-kind Γ ρ σ (Star _) = Star posinfo-gen\n\nsubsth-arg Γ ρ σ (TermArg me t) = TermArg me (substh-term Γ ρ σ t)\nsubsth-arg Γ ρ σ (TypeArg T) = TypeArg (substh-type Γ ρ σ T)\n\nsubsth-args Γ ρ σ (ArgsCons a as) = ArgsCons (substh-arg Γ ρ σ a) (substh-args Γ ρ σ as)\nsubsth-args Γ ρ σ ArgsNil = ArgsNil\n\nsubsth-params{QUALIF} Γ ρ σ (ParamsCons (Decl _ pi me x atk _) ps) =\n ParamsCons (Decl posinfo-gen posinfo-gen me (pi % x) (substh-tk Γ ρ σ atk) posinfo-gen)\n (substh-params Γ (renamectxt-insert ρ x (pi % x)) (trie-remove σ (pi % x)) ps)\nsubsth-params Γ ρ σ (ParamsCons (Decl _ _ me x atk _) ps) =\n ParamsCons (Decl posinfo-gen posinfo-gen me x (substh-tk Γ ρ σ atk) posinfo-gen)\n (substh-params Γ (renamectxt-insert ρ x x) (trie-remove σ x) ps)\nsubsth-params Γ ρ σ ParamsNil = ParamsNil\n\nsubsth-tk Γ ρ σ (Tkk k) = Tkk (substh-kind Γ ρ σ k)\nsubsth-tk Γ ρ σ (Tkt t) = Tkt (substh-type Γ ρ σ t)\n\nsubsth-optClass Γ ρ σ NoClass = NoClass\nsubsth-optClass Γ ρ σ (SomeClass atk) = SomeClass (substh-tk Γ ρ σ atk)\nsubsth-liftingType Γ ρ σ (LiftArrow l l₁) = LiftArrow (substh-liftingType Γ ρ σ l) (substh-liftingType Γ ρ σ l₁)\nsubsth-liftingType Γ ρ σ (LiftParens _ l _) = substh-liftingType Γ ρ σ l\nsubsth-liftingType Γ ρ σ (LiftPi _ x tp l) =\n let x' = subst-rename-var-if Γ ρ x σ in \n LiftPi posinfo-gen x' (substh-type Γ ρ σ tp) \n (substh-liftingType (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ l)\nsubsth-liftingType Γ ρ σ (LiftStar _) = LiftStar posinfo-gen\nsubsth-liftingType Γ ρ σ (LiftTpArrow tp l) = \n LiftTpArrow (substh-type Γ ρ σ tp) (substh-liftingType Γ ρ σ l)\n\nsubsth-optType Γ ρ σ NoType = NoType\nsubsth-optType Γ ρ σ (SomeType T) = SomeType (substh-type Γ ρ σ T)\n\nsubsth-optTerm Γ ρ σ NoTerm = NoTerm\nsubsth-optTerm Γ ρ σ (SomeTerm t _) = (SomeTerm (substh-term Γ ρ σ t) posinfo-gen)\n\nsubsth-optGuide Γ ρ σ NoGuide = NoGuide\nsubsth-optGuide Γ ρ σ (Guide _ x T) =\n let x' = subst-rename-var-if Γ ρ x σ in\n Guide posinfo-gen x' (substh-type (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') σ T)\n\n\nsubst-ret-t : Set → Set\nsubst-ret-t T = {ed : exprd} → ctxt → ⟦ ed ⟧ → var → T → T\n\nsubst : ∀ {ed} → subst-ret-t ⟦ ed ⟧\nsubst Γ t x = substh Γ empty-renamectxt (trie-single x t)\n\nsubst-term = subst {TERM}\nsubst-type = subst {TYPE}\nsubst-kind = subst {KIND}\nsubst-liftingType = subst {LIFTINGTYPE}\nsubst-tk = subst {TK}\n\n\nsubst-renamectxt : ∀ {ed : exprd} → ctxt → renamectxt → ⟦ ed ⟧ → ⟦ ed ⟧\nsubst-renamectxt {ed} Γ ρ = substh {ed} {ed} Γ ρ empty-trie\n\nrename-var : ∀ {ed} → ctxt → var → var → ⟦ ed ⟧ → ⟦ ed ⟧\nrename-var Γ x x' = subst-renamectxt Γ (renamectxt-single x x')\n\n\nsubsts-ret-t : Set → Set\nsubsts-ret-t T = ∀ {ed} → ctxt → trie ⟦ ed ⟧ → T → T\n\nsubsts : ∀ {ed} → substs-ret-t ⟦ ed ⟧\nsubsts Γ = substh Γ empty-renamectxt\n\nsubsts-term = substs {TERM}\nsubsts-type = substs {TYPE}\nsubsts-kind = substs {KIND}\nsubsts-liftingType = substs {LIFTINGTYPE}\nsubsts-tk = substs {TK}\n\nsubsts-args : substs-ret-t args\nsubsts-args Γ = substh-args Γ empty-renamectxt\n\nsubsts-params : substs-ret-t params\nsubsts-params Γ = substh-params Γ empty-renamectxt\n\nsubst-params-args : ∀ {ed} → ctxt → params → args → ⟦ ed ⟧ → ⟦ ed ⟧ × params × args\nsubst-params-args Γ (ParamsCons (Decl _ _ me x atk _) ps) (ArgsCons a as) t =\n subst-params-args Γ (substs-params Γ (trie-single x a) ps) as (subst Γ a x t)\nsubst-params-args Γ ps as t = t , ps , as\n", "meta": {"hexsha": "9ad27d2de1a2488628dd53cc4ade751da395d44a", "size": 12315, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/subst.agda", "max_stars_repo_name": "xoltar/cedille", "max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/subst.agda", "max_issues_repo_name": "xoltar/cedille", "max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/subst.agda", "max_forks_repo_name": "xoltar/cedille", "max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.3653846154, "max_line_length": 151, "alphanum_fraction": 0.6647990256, "num_tokens": 4686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.334589441253186, "lm_q1q2_score": 0.19066668512177046}} {"text": "------------------------------------------------------------------------------\n-- ABP auxiliary lemma\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOT.FOTC.Program.ABP.StrongerInductionPrinciple.LemmaI where\n\nopen import Common.FOL.Relation.Binary.EqReasoning\n\nopen import FOTC.Base\nopen import FOTC.Base.PropertiesI\nopen import FOTC.Base.List\nopen import FOTC.Base.Loop\nopen import FOTC.Base.List.PropertiesI\nopen import FOTC.Data.Bool\nopen import FOTC.Data.Bool.PropertiesI\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesI\nopen import FOTC.Program.ABP.ABP\nopen import FOTC.Program.ABP.Fair.Type\nopen import FOTC.Program.ABP.Fair.PropertiesI\nopen import FOTC.Program.ABP.PropertiesI\nopen import FOTC.Program.ABP.Terms\n\n------------------------------------------------------------------------------\n-- Helper function for the auxiliary lemma\n\nmodule Helper where\n\n helper : ∀ {b i' is' os₁ os₂ as bs cs ds js} →\n Bit b →\n Fair os₂ →\n S b (i' ∷ is') os₁ os₂ as bs cs ds js →\n ∀ ft₁ os₁' → F*T ft₁ → Fair os₁' → os₁ ≡ ft₁ ++ os₁' →\n ∃[ js' ] js ≡ i' ∷ js'\n helper {b} {i'} {is'} {os₁} {os₂} {as} {bs} {cs} {ds} {js} Bb Fos₂\n (asS , bsS , csS , dsS , jsS)\n .(T ∷ []) os₁' f*tnil Fos₁' os₁-eq = js' , js-eq\n where\n os₁-eq-helper : os₁ ≡ T ∷ os₁'\n os₁-eq-helper = os₁ ≡⟨ os₁-eq ⟩\n (T ∷ []) ++ os₁' ≡⟨ ++-∷ T [] os₁' ⟩\n T ∷ ([] ++ os₁') ≡⟨ ∷-rightCong (++-leftIdentity os₁') ⟩\n T ∷ os₁' ∎\n\n as' : D\n as' = await b i' is' ds\n\n as-eq : as ≡ < i' , b > ∷ as'\n as-eq = trans asS (send-eq b i' is' ds)\n\n bs' : D\n bs' = corrupt os₁' · as'\n\n bs-eq : bs ≡ ok < i' , b > ∷ bs'\n bs-eq =\n bs ≡⟨ bsS ⟩\n corrupt os₁ · as\n ≡⟨ ·-rightCong as-eq ⟩\n corrupt os₁ · (< i' , b > ∷ as')\n ≡⟨ ·-leftCong (corruptCong os₁-eq-helper) ⟩\n corrupt (T ∷ os₁') · (< i' , b > ∷ as')\n ≡⟨ corrupt-T os₁' < i' , b > as' ⟩\n ok < i' , b > ∷ corrupt os₁' · as'\n ≡⟨ refl ⟩\n ok < i' , b > ∷ bs' ∎\n\n cs' : D\n cs' = ack (not b) · bs'\n\n js' : D\n js' = out (not b) · bs'\n\n js-eq : js ≡ i' ∷ js'\n js-eq = js ≡⟨ jsS ⟩\n out b · bs ≡⟨ ·-rightCong bs-eq ⟩\n out b · (ok < i' , b > ∷ bs') ≡⟨ out-ok≡ b b i' bs' refl ⟩\n i' ∷ out (not b) · bs' ≡⟨ refl ⟩\n i' ∷ js' ∎\n\n ds' : D\n ds' = ds\n\n helper {b} {i'} {is'} {os₁} {os₂} {as} {bs} {cs} {ds} {js}\n Bb Fos₂ (asS , bsS , csS , dsS , jsS)\n .(F ∷ ft₁^) os₁' (f*tcons {ft₁^} FTft₁^) Fos₁' os₁-eq =\n helper Bb (tail-Fair Fos₂) ihS ft₁^ os₁' FTft₁^ Fos₁' refl\n\n where\n os₁^ : D\n os₁^ = ft₁^ ++ os₁'\n\n os₂^ : D\n os₂^ = tail₁ os₂\n\n os₁-eq-helper : os₁ ≡ F ∷ os₁^\n os₁-eq-helper = os₁ ≡⟨ os₁-eq ⟩\n (F ∷ ft₁^) ++ os₁' ≡⟨ ++-∷ F ft₁^ os₁' ⟩\n F ∷ ft₁^ ++ os₁' ≡⟨ refl ⟩\n F ∷ os₁^ ∎\n\n as^ : D\n as^ = await b i' is' ds\n\n as-eq : as ≡ < i' , b > ∷ as^\n as-eq = trans asS (send-eq b i' is' ds)\n\n bs^ : D\n bs^ = corrupt os₁^ · as^\n\n bs-eq : bs ≡ error ∷ bs^\n bs-eq =\n bs\n ≡⟨ bsS ⟩\n corrupt os₁ · as\n ≡⟨ ·-rightCong as-eq ⟩\n corrupt os₁ · (< i' , b > ∷ as^)\n ≡⟨ ·-leftCong (corruptCong os₁-eq-helper) ⟩\n corrupt (F ∷ os₁^) · (< i' , b > ∷ as^)\n ≡⟨ corrupt-F os₁^ < i' , b > as^ ⟩\n error ∷ corrupt os₁^ · as^\n ≡⟨ refl ⟩\n error ∷ bs^ ∎\n\n cs^ : D\n cs^ = ack b · bs^\n\n cs-eq : cs ≡ not b ∷ cs^\n cs-eq = cs ≡⟨ csS ⟩\n ack b · bs ≡⟨ ·-rightCong bs-eq ⟩\n ack b · (error ∷ bs^) ≡⟨ ack-error b bs^ ⟩\n not b ∷ ack b · bs^ ≡⟨ refl ⟩\n not b ∷ cs^ ∎\n\n ds^ : D\n ds^ = corrupt os₂^ · cs^\n\n ds-eq-helper₁ : os₂ ≡ T ∷ tail₁ os₂ → ds ≡ ok (not b) ∷ ds^\n ds-eq-helper₁ h =\n ds ≡⟨ dsS ⟩\n corrupt os₂ · cs ≡⟨ ·-rightCong cs-eq ⟩\n corrupt os₂ · (not b ∷ cs^) ≡⟨ ·-leftCong (corruptCong h) ⟩\n corrupt (T ∷ os₂^) · (not b ∷ cs^) ≡⟨ corrupt-T os₂^ (not b) cs^ ⟩\n ok (not b) ∷ corrupt os₂^ · cs^ ≡⟨ refl ⟩\n ok (not b) ∷ ds^ ∎\n\n ds-eq-helper₂ : os₂ ≡ F ∷ tail₁ os₂ → ds ≡ error ∷ ds^\n ds-eq-helper₂ h =\n ds ≡⟨ dsS ⟩\n corrupt os₂ · cs ≡⟨ ·-rightCong cs-eq ⟩\n corrupt os₂ · (not b ∷ cs^) ≡⟨ ·-leftCong (corruptCong h) ⟩\n corrupt (F ∷ os₂^) · (not b ∷ cs^) ≡⟨ corrupt-F os₂^ (not b) cs^ ⟩\n error ∷ corrupt os₂^ · cs^ ≡⟨ refl ⟩\n error ∷ ds^ ∎\n\n ds-eq : ds ≡ ok (not b) ∷ ds^ ∨ ds ≡ error ∷ ds^\n ds-eq = case (λ h → inj₁ (ds-eq-helper₁ h))\n (λ h → inj₂ (ds-eq-helper₂ h))\n (head-tail-Fair Fos₂)\n\n as^-eq-helper₁ : ds ≡ ok (not b) ∷ ds^ → as^ ≡ send b · (i' ∷ is') · ds^\n as^-eq-helper₁ h =\n await b i' is' ds\n ≡⟨ awaitCong₄ h ⟩\n await b i' is' (ok (not b) ∷ ds^)\n ≡⟨ await-ok≢ b (not b) i' is' ds^ (x≢not-x Bb) ⟩\n < i' , b > ∷ await b i' is' ds^\n ≡⟨ sym (send-eq b i' is' ds^) ⟩\n send b · (i' ∷ is') · ds^ ∎\n\n as^-eq-helper₂ : ds ≡ error ∷ ds^ → as^ ≡ send b · (i' ∷ is') · ds^\n as^-eq-helper₂ h =\n await b i' is' ds ≡⟨ awaitCong₄ h ⟩\n await b i' is' (error ∷ ds^) ≡⟨ await-error b i' is' ds^ ⟩\n < i' , b > ∷ await b i' is' ds^ ≡⟨ sym (send-eq b i' is' ds^) ⟩\n send b · (i' ∷ is') · ds^ ∎\n\n as^-eq : as^ ≡ send b · (i' ∷ is') · ds^\n as^-eq = case as^-eq-helper₁ as^-eq-helper₂ ds-eq\n\n js-eq : js ≡ out b · bs^\n js-eq = js ≡⟨ jsS ⟩\n out b · bs ≡⟨ ·-rightCong bs-eq ⟩\n out b · (error ∷ bs^) ≡⟨ out-error b bs^ ⟩\n out b · bs^ ∎\n\n ihS : S b (i' ∷ is') os₁^ os₂^ as^ bs^ cs^ ds^ js\n ihS = as^-eq , refl , refl , refl , js-eq\n\n------------------------------------------------------------------------------\n-- From Dybjer and Sander's paper: From the assumption that os₁ ∈ Fair\n-- and hence by unfolding Fair, we conclude that there are ft₁ :  F*T\n-- and os₁' : Fair, such that os₁ = ft₁ ++ os₁'.\n--\n-- We proceed by induction on ft₁ : F*T using helper.\n\nopen Helper\nlemma : ∀ {b i' is' os₁ os₂ as bs cs ds js} →\n Bit b →\n Fair os₁ →\n Fair os₂ →\n S b (i' ∷ is') os₁ os₂ as bs cs ds js →\n ∃[ js' ] js ≡ i' ∷ js'\nlemma Bb Fos₁ Fos₂ s with Fair-out Fos₁\n... | ft , os₁' , FTft , prf , Fos₁' = helper Bb Fos₂ s ft os₁' FTft Fos₁' prf\n", "meta": {"hexsha": "8018c0d654a9b038b3a93183ad2a3f0fc42a9cf7", "size": 6988, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "notes/FOT/FOTC/Program/ABP/StrongerInductionPrinciple/LemmaI.agda", "max_stars_repo_name": "asr/fotc", "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_issues_repo_path": "notes/FOT/FOTC/Program/ABP/StrongerInductionPrinciple/LemmaI.agda", "max_issues_repo_name": "asr/fotc", "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_forks_repo_path": "notes/FOT/FOTC/Program/ABP/StrongerInductionPrinciple/LemmaI.agda", "max_forks_repo_name": "asr/fotc", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "avg_line_length": 33.2761904762, "max_line_length": 79, "alphanum_fraction": 0.4242987979, "num_tokens": 2709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.3775406687981454, "lm_q1q2_score": 0.19024507263306137}} {"text": "module Issue452 where\n\ndata Bool : Set where\n true false : Bool\n\ndata ⊥ : Set where\n\nrecord ⊤ : Set where\n constructor tt\n\nabstract\n\n id : Bool → Bool\n id b = b\n\nIf_then_else_ : Bool → Set → Set → Set\nIf true then t else f = t\nIf false then t else f = f\n\ndata D : (b : Bool) → If b then ⊤ else ⊥ → Set where\n d : D (id true) _ -- this meta variable (type If (id true) ...) is unsolvable\n\nfoo : D true tt → ⊥\nfoo ()\n-- An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Rules/LHS/Unify.hs:402\n\n{- Trying to unify\n\n D true tt = D (id true) _\n\ntrue = id true is postponed, but then tt is handled of type \n\n If (id true)...\n\nwhich is not a data or record type, causing the panic\n\nSolution: do not postpone but fail, since in D : (b : Bool) -> X \n\n X depends on b\n\n-}\n", "meta": {"hexsha": "d18d83f9402acd97a2e18779ef14fdcc756e13b3", "size": 836, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/fail/Issue452.agda", "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_issues_repo_path": "test/fail/Issue452.agda", "max_issues_repo_name": "masondesu/agda", "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/fail/Issue452.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4418604651, "max_line_length": 80, "alphanum_fraction": 0.6507177033, "num_tokens": 258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.33807711748081287, "lm_q1q2_score": 0.18745377652206732}} {"text": "module Sessions.Semantics.Process where\n\nopen import Level\nopen import Size\nopen import Data.Nat\nopen import Data.Sum\nopen import Data.Product\nopen import Data.Unit\nopen import Data.Bool\nopen import Debug.Trace\n\nopen import Function\nopen import Relation.Unary hiding (Empty)\nopen import Relation.Unary.PredicateTransformer using (PT)\nopen import Relation.Binary.PropositionalEquality hiding ([_])\n\nopen import Sessions.Syntax.Types\nopen import Sessions.Syntax.Values\nopen import Sessions.Syntax.Expr\n\nopen import Sessions.Semantics.Commands\n\nopen import Relation.Ternary.Separation\nopen import Relation.Ternary.Separation.Allstar\nopen import Relation.Ternary.Separation.Construct.Market\nopen import Relation.Ternary.Separation.Construct.Product\nopen import Relation.Ternary.Separation.Morphisms\nopen import Relation.Ternary.Separation.Monad\nopen import Relation.Ternary.Separation.Bigstar\nopen import Relation.Ternary.Separation.Monad.Free Cmd δ as Free hiding (step)\nopen import Relation.Ternary.Separation.Monad.State\nopen import Relation.Ternary.Separation.Monad.Error\n\nopen Monads using (Monad; str; typed-str)\nopen Monad {{...}}\n\ndata Exc : Set where\n outOfFuel : Exc\n delay : Exc\n\nopen import Sessions.Semantics.Runtime delay\nopen import Sessions.Semantics.Communication delay\n\ndata Thread : Pred RCtx 0ℓ where\n forked : ∀[ Comp unit ⇒ Thread ]\n main : ∀ {a} → ∀[ Comp a ⇒ Thread ] \n\nPool : Pred RCtx 0ℓ\nPool = Bigstar Thread\n\nSt = Π₂ Pool ✴ Channels\n\nopen ExceptMonad {A = RCtx} Exc\nopen StateWithErr {C = RCtx} Exc\n\nonPool : ∀ {P} → ∀[ (Pool ─✴ Except Exc (P ✴ Pool)) ⇒ State? St P ]\napp (onPool f) (lift (snd pool ×⟨ σ , σ₁ ⟩ chs) k) (offerᵣ σ₂) with resplit σ₂ σ₁ k\n... | _ , _ , τ₁ , τ₂ , τ₃ =\n case app f pool τ₁ of λ where\n (error e) → partial (inj₁ e)\n (✓ (p ×⟨ σ₃ ⟩ p')) →\n let _ , _ , τ₄ , τ₅ , τ₆ = resplit σ₃ τ₂ τ₃\n in return (inj p ×⟨ offerᵣ τ₄ ⟩ lift (snd p' ×⟨ σ , τ₅ ⟩ chs) τ₆)\n\nonChannels : ∀ {P} → ∀[ State? Channels P ⇒ State? St P ]\napp (onChannels f) μ (offerᵣ σ₃) with ○≺●ᵣ μ\n... | inj pool ×⟨ offerᵣ σ₄ ⟩ chs with ⊎-assoc σ₃ (⊎-comm σ₄)\n... | _ , τ₁ , τ₂ = do\n px ×⟨ σ₄ ⟩ ●chs ×⟨ σ₅ ⟩ inj pool ←\n mapM (app f chs (offerᵣ τ₁) &⟨ J Pool ∥ offerₗ τ₂ ⟩ inj pool) ✴-assocᵣ\n return (px ×⟨ σ₄ ⟩ app (○≺●ₗ pool) ●chs (⊎-comm σ₅))\n\nenqueue : ∀[ Thread ⇒ State? St Emp ]\nenqueue thr =\n onPool (wand λ pool σ → return (empty ×⟨ ⊎-idˡ ⟩ (app (append thr) pool σ)))\n\n-- Smart reschedule of a thread:\n-- Escalates out-of-fuel erros in threads, and discards terminated workers.\nreschedule : ∀[ Thread ⇒ State? St Emp ]\n\nreschedule (forked (partial (pure (inj₁ _)))) = raise outOfFuel\nreschedule (forked (partial (pure (inj₂ tt)))) = return empty\nreschedule thr@(forked (partial (impure _))) = enqueue thr\n\nreschedule (main (partial (pure (inj₁ _)))) = raise outOfFuel\nreschedule thr@(main (partial (pure (inj₂ _)))) = enqueue thr\nreschedule thr@(main (partial (impure _))) = enqueue thr\n\n{- Select the next thread that is not done -}\ndequeue : ε[ State? St (Emp ∪ Thread) ]\ndequeue = \n onPool (wandit (λ pool →\n case (find isImpure pool) of λ where\n (error e) → return (inj₁ empty ×⟨ ⊎-idˡ ⟩ pool) \n (✓ (thr ×⟨ σ ⟩ pool')) → return (inj₂ thr ×⟨ σ ⟩ pool')))\n where\n isImpure : ∀ {Φ} → Thread Φ → Bool\n isImpure (main (partial (pure _))) = false\n isImpure (main (partial (impure _))) = true\n isImpure (forked (partial (pure _))) = false\n isImpure (forked (partial (impure _))) = true\n\nmodule _ where\n\n handle : ∀ {Φ} → (c : Cmd Φ) → State? St (δ c) Φ\n handle (fork thr) = trace \"handle:fork\" $ enqueue (forked thr)\n handle (mkchan α) = trace \"handle:mkchan\" $ onChannels newChan\n handle (send (ch ×⟨ σ ⟩ v)) = trace \"handle:send\" $ onChannels (app (send! ch) v σ)\n handle (receive ch) = trace \"handle:recv\" $ onChannels (receive? ch)\n handle (close ch) = trace \"handle:close\" $ onChannels (closeChan ch)\n\n step : ∀[ Thread ⇒ State? St Thread ]\n step thr@(main (partial c)) = do\n c' ← Free.step handle c\n return (main (partial c'))\n step (forked (partial c)) = do\n c' ← Free.step handle c\n return (forked (partial c'))\n\n -- try the first computation; if it fails with a 'delay' exception,\n -- then queue t\n _orDelay_ : ∀[ State? St Emp ⇒ Thread ⇒ State? St Emp ]\n c orDelay t = do\n c orElse λ where\n delay → enqueue t\n outOfFuel → raise outOfFuel\n\n -- Run a pool of threads in round-robing fashion\n -- until all have terminated, or fuel runs out\n run : ℕ → ε[ State? St Emp ] \n run zero = raise outOfFuel\n run (suc n) = do\n inj₂ thr ← dequeue\n -- if we cannot dequeue a thunked thread, we're done\n where (inj₁ e) → return e\n\n -- otherwise we take a step\n empty ← trace \"run:step\" (do thr' ← step thr; enqueue thr') orDelay thr\n\n -- rinse and repeat\n run n\n\n start : ℕ → Thread ε → ∃ λ Φ → Except Exc (● St) Φ\n start n thr = -, do\n let μ = lift (snd [ thr ] ×⟨ ⊎-idʳ ⟩ nil) ⊎-idʳ\n inj empty ×⟨ σ ⟩ μ ← app (run n) μ (offerᵣ ⊎-idˡ)\n case ⊎-id⁻ˡ σ of λ where\n refl → return μ\n\n where open ExceptMonad {A = Market RCtx} Exc\n", "meta": {"hexsha": "ef2fadc1fe2fb343cd904db23825f83412f2a1f0", "size": 5177, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Sessions/Semantics/Process.agda", "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_issues_repo_path": "src/Sessions/Semantics/Process.agda", "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Sessions/Semantics/Process.agda", "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "avg_line_length": 34.2847682119, "max_line_length": 87, "alphanum_fraction": 0.6486382075, "num_tokens": 1738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.34510528442897664, "lm_q1q2_score": 0.1873449877452955}} {"text": "------------------------------------------------------------------------\n-- INCREMENTAL λ-CALCULUS\n--\n-- Caching evaluation\n------------------------------------------------------------------------\n\nimport Parametric.Syntax.Type as Type\nimport Parametric.Syntax.Term as Term\n\nimport Parametric.Syntax.MType as MType\nimport Parametric.Syntax.MTerm as MTerm\n\nimport Parametric.Denotation.Value as Value\nimport Parametric.Denotation.Evaluation as Evaluation\nimport Parametric.Denotation.MValue as MValue\nimport Parametric.Denotation.CachingMValue as CachingMValue\nimport Parametric.Denotation.MEvaluation as MEvaluation\n\nmodule Parametric.Denotation.CachingMEvaluation\n {Base : Type.Structure}\n (Const : Term.Structure Base)\n (⟦_⟧Base : Value.Structure Base)\n (⟦_⟧Const : Evaluation.Structure Const ⟦_⟧Base)\n (ValConst : MTerm.ValConstStructure Const)\n (CompConst : MTerm.CompConstStructure Const)\n (cbnToCompConst : MTerm.CbnToCompConstStructure Const CompConst)\n (cbvToCompConst : MTerm.CbvToCompConstStructure Const CompConst)\n -- I should really switch to records - can it get sillier than this? More\n -- precisely, this is the kind of thing ML functors are designed to replace.\n -- They have also subtyping --- not sure whether that's good or bad.\n (⟦_⟧ValBase : MEvaluation.ValStructure Const ⟦_⟧Base ValConst CompConst cbnToCompConst cbvToCompConst)\n (⟦_⟧CompBase : MEvaluation.CompStructure Const ⟦_⟧Base ValConst CompConst cbnToCompConst cbvToCompConst)\n (ΔBase : CachingMValue.Structure Base ⟦_⟧Base)\n where\n\nopen Type.Structure Base\nopen Term.Structure Base Const\n\nopen MType.Structure Base\nopen MTerm.Structure Const ValConst CompConst cbnToCompConst cbvToCompConst\n\nopen Value.Structure Base ⟦_⟧Base\nopen Evaluation.Structure Const ⟦_⟧Base ⟦_⟧Const\nopen MValue.Structure Base ⟦_⟧Base\nopen CachingMValue.Structure Base ⟦_⟧Base ΔBase\nopen MEvaluation.Structure Const ⟦_⟧Base ValConst CompConst cbnToCompConst cbvToCompConst ⟦_⟧ValBase ⟦_⟧CompBase\n\nopen import Base.Denotation.Notation\n\n-- Extension Point: Evaluation of constants.\nValStructure : Set\nValStructure = ∀ {τ} → ValConst τ → ⟦ τ ⟧ValTypeHidCache\n\nCompStructure : Set\nCompStructure = ∀ {τ} → CompConst τ → ⟦ τ ⟧CompTypeHidCache\n\nmodule Structure\n (⟦_⟧ValBaseTermCache : ValStructure)\n (⟦_⟧CompBaseTermCache : CompStructure)\n where\n\n {-\n -- Prototype here the type-correctness of a simple non-standard semantics.\n -- This describes a simplified version of the transformation by Liu and\n -- Tanenbaum, PEPM 1995 - but for now, instead of producing object language\n -- terms, we produce host language terms to take advantage of the richer type\n -- system of the host language (in particular, here we need the unit type,\n -- product types and *existentials*).\n --\n -- As usual, we'll later switch to a real term transformation.\n -}\n open import Data.Product hiding (map)\n open import Data.Unit\n\n -- Defining a caching semantics for Term proves to be hard, requiring to\n -- insert and remove caches where we apply constants.\n\n -- Indeed, our plugin interface is not satisfactory for adding caching. CBPV can help us.\n\n -- The solution is to distinguish among different kinds of constants. Some are\n -- value constructors (and thus do not return caches), while others are\n -- computation constructors (and thus should return caches). For products, I\n -- believe we will only use positive/value products (i.e. pattern-match products),\n -- not negative/computation products (i.e. projection products).\n ⟦_⟧CompTermCache : ∀ {τ Γ} → Comp Γ τ → ⟦ Γ ⟧ValCtxHidCache → ⟦ τ ⟧CompTypeHidCache\n ⟦_⟧ValTermCache : ∀ {τ Γ} → Val Γ τ → ⟦ Γ ⟧ValCtxHidCache → ⟦ τ ⟧ValTypeHidCache\n ⟦_⟧ValsTermCache : ∀ {Γ Σ} → Vals Γ Σ → ⟦ Γ ⟧ValCtxHidCache → ⟦ Σ ⟧ValCtxHidCache\n\n open import Base.Denotation.Environment ValType ⟦_⟧ValTypeHidCache public\n using ()\n renaming (⟦_⟧Var to ⟦_⟧ValVarHidCache)\n\n -- This says that the environment does not contain caches... sounds wrong!\n -- Either we add extra variables for the caches, or we store computations in\n -- the environment (but that does not make sense), or we store caches in\n -- values, by acting not on F but on something else (U?).\n\n -- Copy of ⟦_⟧Vals\n ⟦ ∅ ⟧ValsTermCache ρ = ∅\n ⟦ vt • valtms ⟧ValsTermCache ρ = ⟦ vt ⟧ValTermCache ρ • ⟦ valtms ⟧ValsTermCache ρ\n\n -- I suspect the plan was to use extra variables; that's annoying to model in\n -- Agda but easier in implementations.\n\n ⟦ vVar x ⟧ValTermCache ρ = ⟦ x ⟧ValVarHidCache ρ\n ⟦ vThunk x ⟧ValTermCache ρ = ⟦ x ⟧CompTermCache ρ\n -- No caching, because the arguments are values, so evaluating them does not\n -- produce intermediate results.\n ⟦ vConst c ⟧ValTermCache ρ = ⟦ c ⟧ValBaseTermCache\n\n -- The only caching is done by the interpretation of the constant (because the\n -- arguments are values so need no caching).\n ⟦_⟧CompTermCache (cConst c) ρ = ⟦ c ⟧CompBaseTermCache\n\n -- Also, where are introduction forms for pairs and sums among values? With\n -- them, we should see that we can interpret them without adding a cache.\n\n -- Thunks keep seeming noops.\n ⟦_⟧CompTermCache (cForce x) ρ = ⟦ x ⟧ValTermCache ρ\n\n -- The effect of F is a writer monad of cached values, where the monoid is\n -- (isomorphic to) the free monoid over (∃ τ . τ), but we push the\n -- existentials up when pairing things!\n\n -- That's what we're interpreting computations in. In fact, one could use\n -- monads directly, but that does not deal with arity satisfactorily.\n ⟦_⟧CompTermCache (cReturn v) ρ = vUnit , (⟦ v ⟧ValTermCache ρ , tt)\n\n -- A function can invoke, in tail position, either a `cReturn` directly, or\n -- invoke another function. In the latter case, we need to ensure that the\n -- return value of the other function is not forwarded directly, but that\n -- further intermediate results from the current function are also recorded.\n --\n -- At one time, `f1 into cReturn` did this correctly, but `f1` didn't, while\n -- instead, they should be equivalent. In other words, we want `_into_` to\n -- satisfy the monadic laws for bind.\n\n {-\n -- Here we'd have a problem with the original `_into_` constructor from CBPV, because it does\n -- not require converting expressions to the \"CBPV A-normal form\".\n --\n -- If we tried supporting it, we could try to write something like:\n\n ⟦_⟧CompTermCache (v₁ into v₂) ρ =\n -- Sequence commands and combine their caches.\n {-\n let (_ , (r₁ , c₁)) = ⟦ v₁ ⟧CompTermCache ρ\n (_ , (r₂ , c₂)) = ⟦ v₂ ⟧CompTermCache (r₁ • ρ)\n in , (r₂ , (c₁ ,′ c₂))\n -}\n\n -- However, the code above does not work, because we only guarantee that v₂ is\n -- a computation, not that it's an F-computation - v₂ could also be function\n -- type or a computation product.\n\n -- Instead, we use a restricted CBPV, where these two possibilities are forbidden.\n -- If you want to save something between different lambdas, you need to add an\n -- F U to reflect that. (Double-check the papers which show how to encode\n -- arity using CBPV, it seems that they should find the same problem ---\n -- XXX they don't).\n -}\n\n -- But if we alter _into_ as described above, composing the caches works!\n -- However, we should not forget we also need to save the new intermediate\n -- result, that is the one produced by the first part of the let.\n ⟦_⟧CompTermCache (_into_ {σ} {τ} v₁ v₂) ρ =\n let (τ₁ , (r₁ , c₁)) = ⟦ v₁ ⟧CompTermCache ρ\n (τ₂ , (r₂ , c₂)) = ⟦ v₂ ⟧CompTermCache (r₁ • ρ)\n in (τ₁ v× τ₂ v× σ) , (r₂ ,′ (c₁ ,′ c₂ ,′ r₁))\n\n -- Note the compositionality and luck: we don't need to do anything at the\n -- cReturn time, we just need the nested into to do their job, because as I\n -- said intermediate results are a writer monad.\n --\n -- Q: But then, do we still need to do all the other stuff? IOW, do we still\n -- need to forbid (λ x . y <- f args; g args') and replace it with (λ x . y <-\n -- f args; z <- g args'; z)?\n --\n -- A: One thing we still need is using the monadic version of into for the\n -- same reasons - which makes sense, since it has the type of monadic bind.\n --\n -- Maybe not: if we use a monad, which respects left and right identity, the\n -- two above forms are equivalent. But what about associativity? We don't have\n -- associativity with nested tuples in the middle. That's why the monad uses\n -- lists! We can also use nested tuple, as long as in the into case we don't\n -- do (a, b) but append a b (ahem, where?), which decomposes the first list\n -- and prepends it to the second. To this end, we need to know the type of the\n -- first element, or to ensure it's always a pair. XXX: We should just reuse\n -- HList.\n\n -- In abstractions, we should start collecting all variables...\n\n -- Here, unlike in ⟦_⟧TermCache, we don't need to invent an empty cache,\n -- that's moved into the handling of cReturn. This makes *the* difference for\n -- nested lambdas, where we don't need to create caches multiple times!\n\n ⟦_⟧CompTermCache (cAbs v) ρ = λ x → ⟦ v ⟧CompTermCache (x • ρ)\n\n -- Here we see that we are in a sort of A-normal form, because the argument is\n -- a value (not quite ANF though, since values can be thunks - that is,\n -- computations which haven't been run yet, I guess. Do we have an use for\n -- that? That allows passing lambdas as arguments directly - which is fine,\n -- because producing a closure indeed does not have intermediate results!).\n ⟦_⟧CompTermCache (cApp t v) ρ = ⟦ t ⟧CompTermCache ρ (⟦ v ⟧ValTermCache ρ)\n\n ⟦_⟧TermCacheCBV : ∀ {τ Γ} → Term Γ τ → ⟦ fromCBVCtx Γ ⟧ValCtxHidCache → ⟦ cbvToCompType τ ⟧CompTypeHidCache\n ⟦ t ⟧TermCacheCBV = ⟦ fromCBV t ⟧CompTermCache\n\n module _ (ι : Base) where\n Γ : ValContext\n Γ = ∅\n σ = B ι\n τ = B ι\n f : Comp Γ (σ ⇛ F τ)\n f = cAbs (cReturn (vVar vThis))\n\n bar : ⟦ σ ⇛ F τ ⟧CompTypeHidCache\n bar = ⟦ f ⟧CompTermCache ∅\n\n open import Relation.Binary.PropositionalEquality\n bar≡ : bar ≡ (λ x → vUnit , x , tt)\n bar≡ = refl\n\n dbar : ⟦ σ ⇛ F τ ⟧ΔCompType\n dbar = λ dx → vUnit , λ c₀ → (dx , c₀)\n\n barbaz : ⟦ base ι ⟧Type → ⟦ ΔBase ι ⟧Type → ⟦ base ι ⟧Type × ⟦ ΔBase ι ⟧Type\n barbaz x dx =\n let\n (τ₁ , y , c₁) = bar x\n (τ₂ , dbar′) = dbar dx\n (dy , c₂) = dbar′ c₁\n in y , dy\n module _ (f : ⟦ σ ⇛ F τ ⟧CompTypeHidCache) (df : ⟦ σ ⇛ F τ ⟧ΔCompType)\n (proof : ∀ x dx → proj₁ (f x) ≡ proj₁ (df dx)) where\n\n -- fdf₁ : ⟦ base ι ⟧Type → ⟦ ΔBase ι ⟧Type → ⟦ base ι ⟧Type × ⟦ ΔBase ι ⟧Type\n -- fdf₁ x dx =\n -- let\n -- (τ₁ , y , c₁) = f x\n -- (τ₂ , dbar′) = df dx\n -- --(dy , c₂) = dbar′ c₁ -- fails, as it should be expected!\n -- in y , dy\n\n fdf : ⟦ base ι ⟧Type → ⟦ ΔBase ι ⟧Type → ⟦ base ι ⟧Type × ⟦ ΔBase ι ⟧Type\n fdf x dx with proof x dx\n ... | p =\n let\n (τ₁ , y , c₁) = f x\n (τ₂ , dbar′) = df dx\n (dy , c₂) = dbar′ (subst ⟦_⟧ValTypeHidCache p c₁) --\n in y , dy\n", "meta": {"hexsha": "aac35bab33c012bff6d87062a64506be1e0a99c2", "size": 10977, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Parametric/Denotation/CachingMEvaluation.agda", "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_issues_repo_path": "Parametric/Denotation/CachingMEvaluation.agda", "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_forks_repo_path": "Parametric/Denotation/CachingMEvaluation.agda", "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "avg_line_length": 43.3873517787, "max_line_length": 112, "alphanum_fraction": 0.6730436367, "num_tokens": 3383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.3522017956470284, "lm_q1q2_score": 0.18709289516676972}} {"text": "\nmodule Tactic.Reflection.Equality where\n\nopen import Prelude\nopen import Builtin.Reflection\nopen import Builtin.Float\n\ninstance\n EqVisibility : Eq Visibility\n _==_ {{EqVisibility}} visible visible = yes refl\n _==_ {{EqVisibility}} visible hidden = no (λ ())\n _==_ {{EqVisibility}} visible instance′ = no (λ ())\n _==_ {{EqVisibility}} hidden visible = no (λ ())\n _==_ {{EqVisibility}} hidden hidden = yes refl\n _==_ {{EqVisibility}} hidden instance′ = no (λ ())\n _==_ {{EqVisibility}} instance′ visible = no (λ ())\n _==_ {{EqVisibility}} instance′ hidden = no (λ ())\n _==_ {{EqVisibility}} instance′ instance′ = yes refl\n\n EqRelevance : Eq Relevance\n _==_ {{EqRelevance}} relevant relevant = yes refl\n _==_ {{EqRelevance}} relevant irrelevant = no (λ ())\n _==_ {{EqRelevance}} irrelevant relevant = no (λ ())\n _==_ {{EqRelevance}} irrelevant irrelevant = yes refl\n\n EqArgInfo : Eq ArgInfo\n _==_ {{EqArgInfo}} (arg-info v r) (arg-info v₁ r₁) =\n decEq₂ arg-info-inj₁ arg-info-inj₂ (v == v₁) (r == r₁)\n\n EqArg : ∀ {A} {{EqA : Eq A}} → Eq (Arg A)\n _==_ {{EqArg}} (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (x == x₁)\n\n EqLiteral : Eq Literal\n _==_ {{EqLiteral}} = eqLit\n where\n eqLit : (x y : Literal) → Dec (x ≡ y)\n eqLit (nat x) (nat y) = decEq₁ nat-inj (x == y)\n eqLit (word64 x) (word64 y) = decEq₁ word64-inj (x == y)\n eqLit (float x) (float y) = decEq₁ float-inj (x == y)\n eqLit (char x) (char y) = decEq₁ char-inj (x == y)\n eqLit (string x) (string y) = decEq₁ string-inj (x == y)\n eqLit (name x) (name y) = decEq₁ name-inj (x == y)\n eqLit (meta x) (meta y) = decEq₁ meta-inj (x == y)\n\n eqLit (nat _) (float _) = no λ()\n eqLit (nat _) (word64 _) = no λ()\n eqLit (nat _) (char _) = no λ()\n eqLit (nat _) (string _) = no λ()\n eqLit (nat _) (name _) = no λ()\n eqLit (nat _) (meta _) = no λ()\n eqLit (word64 _) (nat _) = no λ()\n eqLit (word64 _) (float _) = no λ()\n eqLit (word64 _) (char _) = no λ()\n eqLit (word64 _) (string _) = no λ()\n eqLit (word64 _) (name _) = no λ()\n eqLit (word64 _) (meta _) = no λ()\n eqLit (float _) (nat _) = no λ()\n eqLit (float _) (word64 _) = no λ()\n eqLit (float _) (char _) = no λ()\n eqLit (float _) (string _) = no λ()\n eqLit (float _) (name _) = no λ()\n eqLit (float _) (meta _) = no λ()\n eqLit (char _) (nat _) = no λ()\n eqLit (char _) (word64 _) = no λ()\n eqLit (char _) (float _) = no λ()\n eqLit (char _) (string _) = no λ()\n eqLit (char _) (name _) = no λ()\n eqLit (char _) (meta _) = no λ()\n eqLit (string _) (nat _) = no λ()\n eqLit (string _) (word64 _) = no λ()\n eqLit (string _) (float _) = no λ()\n eqLit (string _) (char _) = no λ()\n eqLit (string _) (name _) = no λ()\n eqLit (string _) (meta _) = no λ()\n eqLit (name _) (nat _) = no λ()\n eqLit (name _) (word64 _) = no λ()\n eqLit (name _) (float _) = no λ()\n eqLit (name _) (char _) = no λ()\n eqLit (name _) (string _) = no λ()\n eqLit (name _) (meta _) = no λ()\n eqLit (meta _) (nat _) = no λ()\n eqLit (meta _) (word64 _) = no λ()\n eqLit (meta _) (float _) = no λ()\n eqLit (meta _) (char _) = no λ()\n eqLit (meta _) (string _) = no λ()\n eqLit (meta _) (name _) = no λ()\n\nprivate\n eqSort : (x y : Sort) → Dec (x ≡ y)\n eqTerm : (x y : Term) → Dec (x ≡ y)\n eqPat : (x y : Pattern) → Dec (x ≡ y)\n eqClause : (x y : Clause) → Dec (x ≡ y)\n\n eqArgTerm : (x y : Arg Term) → Dec (x ≡ y)\n eqArgTerm (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqTerm x x₁)\n\n eqArgPat : (x y : Arg Pattern) → Dec (x ≡ y)\n eqArgPat (arg i x) (arg i₁ x₁) = decEq₂ arg-inj₁ arg-inj₂ (i == i₁) (eqPat x x₁)\n\n eqAbsTerm : (x y : Abs Term) → Dec (x ≡ y)\n eqAbsTerm (abs s x) (abs s₁ x₁) = decEq₂ abs-inj₁ abs-inj₂ (s == s₁) (eqTerm x x₁)\n\n eqPats : (x y : List (Arg Pattern)) → Dec (x ≡ y)\n eqPats [] [] = yes refl\n eqPats [] (x ∷ xs) = no λ ()\n eqPats (x ∷ xs) [] = no λ ()\n eqPats (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgPat x y) (eqPats xs ys)\n\n eqArgs : (x y : List (Arg Term)) → Dec (x ≡ y)\n eqArgs [] [] = yes refl\n eqArgs [] (x ∷ xs) = no λ ()\n eqArgs (x ∷ xs) [] = no λ ()\n eqArgs (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqArgTerm x y) (eqArgs xs ys)\n\n eqClauses : (x y : List Clause) → Dec (x ≡ y)\n eqClauses [] [] = yes refl\n eqClauses [] (x ∷ xs) = no λ ()\n eqClauses (x ∷ xs) [] = no λ ()\n eqClauses (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj-head cons-inj-tail (eqClause x y) (eqClauses xs ys)\n\n eqTerm (var x args) (var x₁ args₁) = decEq₂ var-inj₁ var-inj₂ (x == x₁) (eqArgs args args₁)\n eqTerm (con c args) (con c₁ args₁) = decEq₂ con-inj₁ con-inj₂ (c == c₁) (eqArgs args args₁)\n eqTerm (def f args) (def f₁ args₁) = decEq₂ def-inj₁ def-inj₂ (f == f₁) (eqArgs args args₁)\n eqTerm (meta x args) (meta x₁ args₁) = decEq₂ meta-inj₁ meta-inj₂ (x == x₁) (eqArgs args args₁)\n eqTerm (lam v x) (lam v₁ y) = decEq₂ lam-inj₁ lam-inj₂ (v == v₁) (eqAbsTerm x y)\n eqTerm (pi t₁ t₂) (pi t₃ t₄) = decEq₂ pi-inj₁ pi-inj₂ (eqArgTerm t₁ t₃) (eqAbsTerm t₂ t₄)\n eqTerm (agda-sort x) (agda-sort x₁) = decEq₁ sort-inj (eqSort x x₁)\n eqTerm (lit l) (lit l₁) = decEq₁ lit-inj (l == l₁)\n eqTerm (pat-lam c args) (pat-lam c₁ args₁) = decEq₂ pat-lam-inj₁ pat-lam-inj₂ (eqClauses c c₁) (eqArgs args args₁)\n eqTerm unknown unknown = yes refl\n\n eqTerm (var x args) (con c args₁) = no λ ()\n eqTerm (var x args) (def f args₁) = no λ ()\n eqTerm (var x args) (lam v y) = no λ ()\n eqTerm (var x args) (pi t₁ t₂) = no λ ()\n eqTerm (var x args) (agda-sort x₁) = no λ ()\n eqTerm (var x args) (lit x₁) = no λ ()\n eqTerm (var x args) unknown = no λ ()\n eqTerm (con c args) (var x args₁) = no λ ()\n eqTerm (con c args) (def f args₁) = no λ ()\n eqTerm (con c args) (lam v y) = no λ ()\n eqTerm (con c args) (pi t₁ t₂) = no λ ()\n eqTerm (con c args) (agda-sort x) = no λ ()\n eqTerm (con c args) (lit x) = no λ ()\n eqTerm (con c args) unknown = no λ ()\n eqTerm (def f args) (var x args₁) = no λ ()\n eqTerm (def f args) (con c args₁) = no λ ()\n eqTerm (def f args) (lam v y) = no λ ()\n eqTerm (def f args) (pi t₁ t₂) = no λ ()\n eqTerm (def f args) (agda-sort x) = no λ ()\n eqTerm (def f args) (lit x) = no λ ()\n eqTerm (def f args) unknown = no λ ()\n eqTerm (lam v x) (var x₁ args) = no λ ()\n eqTerm (lam v x) (con c args) = no λ ()\n eqTerm (lam v x) (def f args) = no λ ()\n eqTerm (lam v x) (pi t₁ t₂) = no λ ()\n eqTerm (lam v x) (agda-sort x₁) = no λ ()\n eqTerm (lam v x) (lit x₁) = no λ ()\n eqTerm (lam v x) unknown = no λ ()\n eqTerm (pi t₁ t₂) (var x args) = no λ ()\n eqTerm (pi t₁ t₂) (con c args) = no λ ()\n eqTerm (pi t₁ t₂) (def f args) = no λ ()\n eqTerm (pi t₁ t₂) (lam v y) = no λ ()\n eqTerm (pi t₁ t₂) (agda-sort x) = no λ ()\n eqTerm (pi t₁ t₂) (lit x) = no λ ()\n eqTerm (pi t₁ t₂) unknown = no λ ()\n eqTerm (agda-sort x) (var x₁ args) = no λ ()\n eqTerm (agda-sort x) (con c args) = no λ ()\n eqTerm (agda-sort x) (def f args) = no λ ()\n eqTerm (agda-sort x) (lam v y) = no λ ()\n eqTerm (agda-sort x) (pi t₁ t₂) = no λ ()\n eqTerm (agda-sort x) (lit x₁) = no λ ()\n eqTerm (agda-sort x) unknown = no λ ()\n eqTerm (lit x) (var x₁ args) = no λ ()\n eqTerm (lit x) (con c args) = no λ ()\n eqTerm (lit x) (def f args) = no λ ()\n eqTerm (lit x) (lam v y) = no λ ()\n eqTerm (lit x) (pi t₁ t₂) = no λ ()\n eqTerm (lit x) (agda-sort x₁) = no λ ()\n eqTerm (lit x) unknown = no λ ()\n eqTerm unknown (var x args) = no λ ()\n eqTerm unknown (con c args) = no λ ()\n eqTerm unknown (def f args) = no λ ()\n eqTerm unknown (lam v y) = no λ ()\n eqTerm unknown (pi t₁ t₂) = no λ ()\n eqTerm unknown (agda-sort x) = no λ ()\n eqTerm unknown (lit x) = no λ ()\n\n eqTerm (var _ _) (meta _ _) = no λ ()\n eqTerm (con _ _) (meta _ _) = no λ ()\n eqTerm (def _ _) (meta _ _) = no λ ()\n eqTerm (lam _ _) (meta _ _) = no λ ()\n eqTerm (pi _ _) (meta _ _) = no λ ()\n eqTerm (agda-sort _) (meta _ _) = no λ ()\n eqTerm (lit _) (meta _ _) = no λ ()\n eqTerm unknown (meta _ _) = no λ ()\n eqTerm (meta _ _) (var _ _) = no λ ()\n eqTerm (meta _ _) (con _ _) = no λ ()\n eqTerm (meta _ _) (def _ _) = no λ ()\n eqTerm (meta _ _) (lam _ _) = no λ ()\n eqTerm (meta _ _) (pi _ _) = no λ ()\n eqTerm (meta _ _) (agda-sort _) = no λ ()\n eqTerm (meta _ _) (lit _) = no λ ()\n eqTerm (meta _ _) unknown = no λ ()\n\n eqTerm (var _ _) (pat-lam _ _) = no λ ()\n eqTerm (con _ _) (pat-lam _ _) = no λ ()\n eqTerm (def _ _) (pat-lam _ _) = no λ ()\n eqTerm (lam _ _) (pat-lam _ _) = no λ ()\n eqTerm (pi _ _) (pat-lam _ _) = no λ ()\n eqTerm (meta _ _) (pat-lam _ _) = no λ ()\n eqTerm (agda-sort _) (pat-lam _ _) = no λ ()\n eqTerm (lit _) (pat-lam _ _) = no λ ()\n eqTerm unknown (pat-lam _ _) = no λ ()\n eqTerm (pat-lam _ _) (var _ _) = no λ ()\n eqTerm (pat-lam _ _) (con _ _) = no λ ()\n eqTerm (pat-lam _ _) (def _ _) = no λ ()\n eqTerm (pat-lam _ _) (lam _ _) = no λ ()\n eqTerm (pat-lam _ _) (pi _ _) = no λ ()\n eqTerm (pat-lam _ _) (meta _ _) = no λ ()\n eqTerm (pat-lam _ _) (agda-sort _) = no λ ()\n eqTerm (pat-lam _ _) (lit _) = no λ ()\n eqTerm (pat-lam _ _) unknown = no λ ()\n\n eqSort (set t) (set t₁) = decEq₁ set-inj (eqTerm t t₁)\n eqSort (lit n) (lit n₁) = decEq₁ slit-inj (n == n₁)\n eqSort unknown unknown = yes refl\n eqSort (set t) (lit n) = no λ ()\n eqSort (set t) unknown = no λ ()\n eqSort (lit n) (set t) = no λ ()\n eqSort (lit n) unknown = no λ ()\n eqSort unknown (set t) = no λ ()\n eqSort unknown (lit n) = no λ ()\n\n eqPat (con c ps) (con c₁ ps₁) = decEq₂ pcon-inj₁ pcon-inj₂ (c == c₁) (eqPats ps ps₁)\n eqPat dot dot = yes refl\n eqPat (var s) (var s₁) = decEq₁ pvar-inj (s == s₁)\n eqPat (lit l) (lit l₁) = decEq₁ plit-inj (l == l₁)\n eqPat (proj f) (proj f₁) = decEq₁ proj-inj (f == f₁)\n eqPat absurd absurd = yes refl\n\n eqPat (con _ _) dot = no λ ()\n eqPat (con _ _) (var _) = no λ ()\n eqPat (con _ _) (lit _) = no λ ()\n eqPat (con _ _) (proj _) = no λ ()\n eqPat (con _ _) absurd = no λ ()\n\n eqPat dot (con _ _) = no λ ()\n eqPat dot (var _) = no λ ()\n eqPat dot (lit _) = no λ ()\n eqPat dot (proj _) = no λ ()\n eqPat dot absurd = no λ ()\n\n eqPat (var _) (con _ _) = no λ ()\n eqPat (var _) dot = no λ ()\n eqPat (var _) (lit _) = no λ ()\n eqPat (var _) (proj _) = no λ ()\n eqPat (var _) absurd = no λ ()\n\n eqPat (lit _) (con _ _) = no λ ()\n eqPat (lit _) dot = no λ ()\n eqPat (lit _) (var _) = no λ ()\n eqPat (lit _) (proj _) = no λ ()\n eqPat (lit _) absurd = no λ ()\n\n eqPat (proj _) (con _ _) = no λ ()\n eqPat (proj _) dot = no λ ()\n eqPat (proj _) (var _) = no λ ()\n eqPat (proj _) (lit _) = no λ ()\n eqPat (proj _) absurd = no λ ()\n\n eqPat absurd (con _ _) = no λ ()\n eqPat absurd dot = no λ ()\n eqPat absurd (var _) = no λ ()\n eqPat absurd (lit _) = no λ ()\n eqPat absurd (proj _) = no λ ()\n\n eqClause (clause ps t) (clause ps₁ t₁) = decEq₂ clause-inj₁ clause-inj₂ (eqPats ps ps₁) (eqTerm t t₁)\n eqClause (absurd-clause ps) (absurd-clause ps₁) = decEq₁ absurd-clause-inj (eqPats ps ps₁)\n eqClause (clause _ _) (absurd-clause _) = no λ ()\n eqClause (absurd-clause _) (clause _ _) = no λ ()\n\ninstance\n EqTerm : Eq Term\n _==_ {{EqTerm}} = eqTerm\n\n EqSort : Eq Sort\n _==_ {{EqSort}} = eqSort\n\n EqClause : Eq Clause\n _==_ {{EqClause}} = eqClause\n\n EqPattern : Eq Pattern\n _==_ {{EqPattern}} = eqPat\n", "meta": {"hexsha": "1c98ffbd2fed23ade13879e2f3951fd1fb6ba635", "size": 11716, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Tactic/Reflection/Equality.agda", "max_stars_repo_name": "lclem/agda-prelude", "max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Tactic/Reflection/Equality.agda", "max_issues_repo_name": "lclem/agda-prelude", "max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Tactic/Reflection/Equality.agda", "max_forks_repo_name": "lclem/agda-prelude", "max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7152542373, "max_line_length": 116, "alphanum_fraction": 0.5402867873, "num_tokens": 4490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.3702253925955866, "lm_q1q2_score": 0.18655885981546744}} {"text": "import cedille-options\nopen import general-util\n\nmodule untyped-spans (options : cedille-options.options) {F : Set → Set} ⦃ monadF : monad F ⦄ where\n\nopen import ctxt\nopen import cedille-types\nopen import constants\nopen import conversion\nopen import free-vars\nopen import rename\nopen import spans options {F} ⦃ monadF ⦄\nopen import subst\nopen import syntax-util\nopen import to-string options\nopen import type-util\nopen import elab-util options\n\n{-# TERMINATING #-}\nuntyped-term : ctxt → ex-tm → spanM term\nuntyped-type : ctxt → ex-tp → spanM type\nuntyped-kind : ctxt → ex-kd → spanM kind\nuntyped-tpkd : ctxt → ex-tk → spanM tpkd\nuntyped-arg : ctxt → ex-arg → spanM arg\nuntyped-args : ctxt → ex-args → spanM args\nuntyped-let : ctxt → ex-def → erased? → posinfo → posinfo → spanM (ctxt × var × tagged-val × (∀ {ed : exprd} → ⟦ ed ⟧ → ⟦ ed ⟧) × (term → term))\nuntyped-cases : ctxt → ex-cases → renamectxt → spanM cases\nuntyped-case : ctxt → ex-case → (siblings : ℕ) → (ℕ → err-m) → renamectxt → spanM (case × (ℕ → err-m) × maybe ℕ)\n\nuntyped-let Γ (ExDefTerm pi x Tₑ? t) e? fm to =\n maybe-map (untyped-type Γ) Tₑ? >>=? λ Tₑ?~ →\n untyped-term Γ t >>= λ t~ →\n elim-pair (compileFail-in Γ t~) λ tvs e →\n let Tₑ~ = maybe-else' Tₑ?~ (TpHole pi) id in\n [- Var-span (Γ , pi - x :` Tkt Tₑ~) pi x untyped tvs e -]\n return\n (ctxt-term-def pi localScope opacity-open x (just t~) Tₑ~ Γ ,\n pi % x ,\n binder-data Γ pi x (Tkt Tₑ~) e? (just t~) fm to ,\n (λ {ed} T' → [ Γ - t~ / (pi % x) ] T') ,\n (λ t' → LetTm e? x nothing t~ ([ Γ - Var x / (pi % x) ] t')))\n\nuntyped-let Γ (ExDefType pi x k T) e? fm to =\n untyped-kind Γ k >>= λ k~ →\n untyped-type Γ T >>= λ T~ →\n [- TpVar-span (Γ , pi - x :` Tkk k~) pi x untyped [] nothing -]\n return\n (ctxt-type-def pi localScope opacity-open x (just T~) k~ Γ ,\n pi % x ,\n binder-data Γ pi x (Tkk k~) e? (just T~) fm to ,\n (λ {ed} T' → [ Γ - T~ / (pi % x) ] T') ,\n (λ t' → LetTp x k~ T~ ([ Γ - TpVar x / (pi % x) ] t')))\n\n\nuntyped-term Γ (ExApp t e t') =\n [- App-span tt (term-start-pos t) (term-end-pos t') untyped [] nothing -]\n untyped-term Γ t >>= λ t~ →\n untyped-term Γ t' >>= λ t'~ →\n return (if e then t~ else App t~ t'~)\n\nuntyped-term Γ (ExAppTp t T) =\n [- AppTp-span tt (term-start-pos t) (type-end-pos T) untyped [] nothing -]\n untyped-type Γ T >>= λ T~ →\n untyped-term Γ t\n\nuntyped-term Γ (ExBeta pi t? t?') =\n maybe-map (λ {(PosTm t pi) → untyped-term Γ t}) t? >>=? λ t?~ →\n maybe-map (λ {(PosTm t pi) → untyped-term Γ t}) t?' >>=? λ t?'~ →\n [- Beta-span pi (term-end-pos (ExBeta pi t? t?')) untyped [] nothing -]\n return (maybe-else' t?'~ id-term id)\n\nuntyped-term Γ (ExChi pi T? t) =\n maybe-map (untyped-type Γ) T? >>=? λ T?~ →\n [- Chi-span Γ pi T?~ t untyped [] nothing -]\n untyped-term Γ t\n\nuntyped-term Γ (ExDelta pi T? t) =\n [- Delta-span pi t untyped [] nothing -]\n maybe-map (untyped-type Γ) T? >>=? λ T?~ →\n untyped-term Γ t >>= λ t~ →\n return id-term\n\nuntyped-term Γ (ExEpsilon pi lr -? t) =\n [- Epsilon-span pi lr -? t untyped [] nothing -]\n untyped-term Γ t\n\nuntyped-term Γ (ExHole pi) =\n [- hole-span Γ pi nothing untyped [] -]\n return (Hole pi)\n\nuntyped-term Γ (ExIotaPair pi t₁ t₂ Tₘ? pi') =\n let tv-f = λ {(ExGuide pi'' x Tₘ) →\n [ binder-data Γ pi'' x (Tkt (TpHole pi'')) ff nothing\n (type-start-pos Tₘ) (type-end-pos Tₘ) ]} in\n [- IotaPair-span pi pi' untyped (maybe-else' Tₘ? [] tv-f) nothing -]\n untyped-term Γ t₁ >>= λ t₁~ →\n untyped-term Γ t₂ >>= λ t₂~ →\n maybe-map (λ {(ExGuide pi'' x Tₘ) →\n untyped-type (ctxt-term-decl pi'' x (TpHole pi'') Γ) Tₘ}) Tₘ? >>=? λ Tₘ?~ →\n return t₁~\n\nuntyped-term Γ (ExIotaProj t n pi) =\n [- IotaProj-span t pi untyped [] nothing -]\n untyped-term Γ t\n\nuntyped-term Γ (ExLam pi e pi' x tk? t) =\n (return tk? on-fail return (Tkt (TpHole pi')) >>=m untyped-tpkd Γ) >>= λ tk~ →\n untyped-term (Γ , pi' - x :` tk~) t >>= λ t~ →\n let eₖ? = tk? >>= λ _ → ifMaybej (tk-is-type tk~ && ~ e)\n \"λ-terms must bind a term, not a type (use Λ instead)\"\n eₑ? = ifMaybej (e && is-free-in (pi' % x) (erase t~))\n \"The Λ-bound variable occurs free in the erasure of the body\" in\n [- var-span e (Γ , pi' - x :` tk~) pi' x untyped tk~ eₑ? -]\n [- Lam-span Γ untyped pi pi' e x tk~ t [] eₖ? -]\n return (if e then t~ else Lam ff x nothing ([ Γ - Var x / (pi' % x) ] t~))\n\nuntyped-term Γ (ExLet pi e? d t) =\n untyped-let Γ d e? (term-start-pos t) (term-end-pos t) >>= λ where\n (Γ' , x , tv , σ , f) →\n untyped-term Γ' t >>= λ t~ →\n [- punctuation-span \"Parens (let)\" pi (term-end-pos t) -]\n [- Let-span e? pi (term-end-pos t) untyped []\n (ifMaybej (e? && is-free-in x t~)\n (unqual-local x ^ \"occurs free in the body of the term\")) -]\n return (if is-free-in x t~ then f t~ else t~)\n\nuntyped-term Γ (ExOpen pi o pi' x t) =\n [- Var-span Γ pi' x untyped [ not-for-navigation ] nothing -]\n [- Open-span o pi x t untyped [] nothing -]\n untyped-term Γ t\n\nuntyped-term Γ (ExParens pi t pi') =\n [- punctuation-span \"Parens (term)\" pi pi' -]\n untyped-term Γ t\n\nuntyped-term Γ (ExPhi pi t₌ t₁ t₂ pi') =\n [- Phi-span pi pi' untyped [] nothing -]\n untyped-term Γ t₌ >>\n untyped-term Γ t₁ >>\n untyped-term Γ t₂\n\nuntyped-term Γ (ExRho pi ρ+? ρ? t₌ Tₘ? t) =\n [- Rho-span pi t₌ t untyped ρ+?\n (maybe-else' Tₘ? (inj₁ 1) λ {(ExGuide pi' x Tₘ) → inj₂ x}) [] nothing -]\n untyped-term Γ t₌ >>\n maybe-map (λ {(ExGuide pi' x Tₘ) →\n untyped-type (ctxt-var-decl-loc pi' x Γ) Tₘ}) Tₘ? >>=? λ Tₘ?~ →\n untyped-term Γ t\n\nuntyped-term Γ (ExVarSigma pi t) =\n [- VarSigma-span pi t untyped [] nothing -]\n untyped-term Γ t\n\nuntyped-term Γ (ExTheta pi θ t ts) =\n [- Theta-span Γ pi θ t ts untyped [] nothing -]\n untyped-term Γ t >>= λ t~ →\n untyped-args Γ (map (λ {(Lterm e t) → ExTmArg e t}) ts) >>= λ as~ →\n return (recompose-apps (map Arg (erase-args as~)) t~)\n\nuntyped-term Γ (ExMu pi pi''' x t Tₘ? pi' ms pi'') =\n untyped-term Γ t >>= λ t~ →\n maybe-map (untyped-type Γ) Tₘ? >>=? λ Tₘ~? →\n [- Var-span Γ pi''' x untyped [] nothing -]\n let Γ' = ctxt-term-decl pi''' x (TpHole pi''') Γ \n ρ = renamectxt-single (pi''' % x) x\n tvs = [ binder-data Γ' pi''' x (Tkt (TpHole pi''')) ff nothing pi' pi'' ] in\n untyped-cases Γ' ms ρ >>= λ ms~ →\n -- Make sure we aren't matching upon a \"False\" datatype (e.g., one\n -- with no constructors) before any datatypes have been declared\n maybe-else' (head2 (trie-mappings (ctxt.μ Γ)))\n ([- Mu-span Γ pi pi'' Tₘ~? untyped tvs\n (just \"No datatypes have been declared yet\") -]\n return (Hole pi))\n λ where\n (Dₓ , ps , kᵢ , k , cs , eds , ecs) →\n [- Mu-span Γ pi pi'' Tₘ~? untyped tvs nothing -]\n return (Mu x t~ nothing (mk-data-info Dₓ Dₓ (params-to-args ps) [] ps kᵢ k cs cs eds ecs) ms~)\nuntyped-term Γ (ExSigma pi t? t Tₘ? pi' ms pi'') =\n untyped-term Γ t >>= λ t~ →\n maybe-map (untyped-type Γ) Tₘ? >>=? λ Tₘ~? →\n maybe-map (untyped-term Γ) t? >>=? λ t~? →\n let ρ = empty-renamectxt\n μ~ = t~?\n tvs = [] in\n untyped-cases Γ ms ρ >>= λ ms~ →\n -- Make sure we aren't matching upon a \"False\" datatype (e.g., one\n -- with no constructors) before any datatypes have been declared\n maybe-else' (head2 (trie-mappings (ctxt.μ Γ)))\n ([- Mu-span Γ pi pi'' Tₘ~? untyped tvs\n (just \"No datatypes have been declared yet\") -]\n return (Hole pi))\n λ where\n (Dₓ , ps , kᵢ , k , cs , eds , ecs) →\n [- Mu-span Γ pi pi'' Tₘ~? untyped tvs nothing -]\n return (Sigma μ~ t~ nothing (mk-data-info Dₓ Dₓ (params-to-args ps) [] ps kᵢ k cs cs eds ecs) ms~)\n\n-- x\nuntyped-term Γ (ExVar pi x) =\n maybe-else' (ctxt-binds-term-var Γ x)\n ([- Var-span Γ pi x untyped [] (just \"Not a term variable\") -]\n return (Var x))\n λ {(qx , as) →\n [- Var-span Γ pi x untyped [] nothing -]\n return (recompose-apps (map Arg (erase-args as)) (Var qx))}\n\n\n-- ∀/Π x : tk. T\nuntyped-type Γ (ExTpAbs pi e pi' x tk T) =\n untyped-tpkd Γ tk >>= λ tk~ →\n untyped-type (Γ , pi' - x :` tk~) T >>= λ T~ →\n let T~ = rename-var Γ (pi' % x) x T~ in\n [- punctuation-span \"Forall\" pi (posinfo-plus pi 1) -]\n [- var-span e (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -]\n [- TpQuant-span Γ e pi pi' x tk~ T untyped [] nothing -]\n return (TpAbs e x tk~ T~)\n\n-- ι x : T₁. T₂\nuntyped-type Γ (ExTpIota pi pi' x T₁ T₂) =\n untyped-type Γ T₁ >>= λ T₁~ →\n untyped-type (Γ , pi' - x :` Tkt T₁~) T₂ >>= λ T₂~ →\n let T₂~ = rename-var Γ (pi' % x) x T₂~ in\n [- punctuation-span \"Forall\" pi (posinfo-plus pi 1) -]\n [- var-span ff (Γ , pi' - x :` Tkt T₁~) pi' x untyped (Tkt T₁~) nothing -]\n [- Iota-span Γ pi pi' x T₂~ T₂ untyped [] nothing -]\n return (TpIota x T₁~ T₂~)\n\n-- {^ T ^} (generated by theta)\nuntyped-type Γ (ExTpNoSpans T pi) = untyped-type Γ T >>=spand return\n\n-- [d] - T\nuntyped-type Γ (ExTpLet pi d T) =\n untyped-let Γ d ff (type-start-pos T) (type-end-pos T) >>= λ where\n (Γ' , x , tv , σ , f) →\n untyped-type Γ' T >>= λ T~ →\n [- punctuation-span \"Parens (let)\" pi (type-end-pos T) -]\n [- TpLet-span pi (type-end-pos T) untyped [ tv ] -]\n return (σ T~)\n\n-- T · T'\nuntyped-type Γ (ExTpApp T T') =\n untyped-type Γ T >>= λ T~ →\n untyped-type Γ T' >>= λ T'~ →\n [- TpApp-span (type-start-pos T) (type-end-pos T) untyped [] nothing -]\n return (TpAppTp T~ T'~)\n\n-- T t\nuntyped-type Γ (ExTpAppt T t) =\n untyped-type Γ T >>= λ T~ →\n untyped-term Γ t >>= λ t~ →\n [- TpAppt-span (type-start-pos T) (term-end-pos t) untyped [] nothing -]\n return (TpAppTm T~ t~)\n\n-- T ➔/➾ T'\nuntyped-type Γ (ExTpArrow T e T') =\n untyped-type Γ T >>= λ T~ →\n untyped-type Γ T' >>= λ T'~ →\n [- TpArrow-span T T' untyped [] nothing -]\n return (TpAbs e ignored-var (Tkt T~) T'~)\n\n-- { t₁ ≃ t₂ }\nuntyped-type Γ (ExTpEq pi t₁ t₂ pi') =\n untyped-term Γ t₁ >>= λ t₁~ →\n untyped-term Γ t₂ >>= λ t₂~ →\n [- punctuation-span \"Parens (equation)\" pi pi' -]\n [- TpEq-span pi pi' untyped [] nothing -]\n return (TpEq t₁~ t₂~)\n\n-- ●\nuntyped-type Γ (ExTpHole pi) =\n [- tp-hole-span Γ pi nothing untyped [] -]\n return (TpHole pi)\n\n-- λ x : tk. T\nuntyped-type Γ (ExTpLam pi pi' x tk T) =\n untyped-tpkd Γ tk >>= λ tk~ →\n untyped-type (Γ , pi' - x :` tk~) T >>= λ T~ →\n [- punctuation-span \"Lambda (type)\" pi (posinfo-plus pi 1) -]\n [- var-span ff (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -]\n [- TpLambda-span Γ pi pi' x tk~ T untyped [] nothing -]\n return (TpLam x tk~ (rename-var Γ (pi' % x) x T~))\n\n-- (T)\nuntyped-type Γ (ExTpParens pi T pi') =\n [- punctuation-span \"Parens (type)\" pi pi' -]\n untyped-type Γ T\n\n-- x\nuntyped-type Γ (ExTpVar pi x) =\n maybe-else' (ctxt-binds-type-var Γ x)\n ([- TpVar-span Γ pi x untyped [] (just \"Undefined type variable\") -]\n return (TpVar x))\n λ {(qx , as) →\n [- TpVar-span Γ pi x untyped [] nothing -]\n return (apps-type (TpVar qx) (erase-args-keep as))}\n\n\n-- Π x : tk. k\nuntyped-kind Γ (ExKdAbs pi pi' x tk k) =\n untyped-tpkd Γ tk >>= λ tk~ →\n untyped-kind (Γ , pi' - x :` tk~) k >>= λ k~ →\n [- KdAbs-span Γ pi pi' x tk~ k untyped nothing -]\n [- var-span ff (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -]\n [- punctuation-span \"Pi (kind)\" pi (posinfo-plus pi 1) -]\n return (KdAbs x tk~ (rename-var Γ (pi' % x) x k~))\n\n-- tk ➔ k\nuntyped-kind Γ (ExKdArrow tk k) =\n untyped-tpkd Γ tk >>= λ tk~ →\n untyped-kind Γ k >>= λ k~ →\n [- KdArrow-span tk k untyped nothing -]\n return (KdAbs ignored-var tk~ k~)\n\n-- ●\nuntyped-kind Γ (ExKdHole pi) =\n [- kd-hole-span pi untyped -]\n return (KdHole pi)\n\n-- (k)\nuntyped-kind Γ (ExKdParens pi k pi') =\n [- punctuation-span \"Parens (kind)\" pi pi' -]\n untyped-kind Γ k\n\n-- ★\nuntyped-kind Γ (ExKdStar pi) =\n [- Star-span pi untyped nothing -]\n return KdStar\n\n-- κ as...\nuntyped-kind Γ (ExKdVar pi κ as) =\n case ctxt-lookup-kind-var-def Γ κ of λ where\n nothing →\n [- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as) [] untyped []\n (just \"Undefined kind variable\") -]\n return (KdHole pi)\n (just (ps , k)) →\n untyped-args Γ as >>= λ as~ →\n [- KdVar-span Γ (pi , κ)\n (args-end-pos (posinfo-plus-str pi κ) as)\n ps untyped (params-data Γ ps)\n (unless (length as =ℕ length ps)\n (\"Expected \" ^ ℕ-to-string (length ps) ^\n \" argument\" ^ (if length ps =ℕ 1 then \"\" else \"s\") ^\n \", but got \" ^ ℕ-to-string (length as))) -]\n return (fst (subst-params-args' Γ ps as~ k))\n\nuntyped-arg Γ (ExTmArg ff t) = inj₁ <$> untyped-term Γ t\nuntyped-arg Γ (ExTmArg tt t) = (inj₂ ∘ inj₁) <$> untyped-term Γ t\nuntyped-arg Γ (ExTpArg T) = (inj₂ ∘ inj₂) <$> untyped-type Γ T\n\nuntyped-args Γ = sequenceA ∘ map (untyped-arg Γ)\n\nuntyped-tpkd Γ (ExTkt T) = Tkt <$> untyped-type Γ T\nuntyped-tpkd Γ (ExTkk k) = Tkk <$> untyped-kind Γ k\n\nuntyped-cases Γ ms ρ =\n let msₗ = length ms in\n foldl (λ m rec ms f → untyped-case Γ m msₗ f ρ >>= uncurry₂ λ m asₗ n? → rec (maybe-else' n? ms (λ n → set-nth n (just m) ms)) asₗ)\n (const ∘ return) ms (repeat (length ms) nothing) (λ _ → nothing) >>=r drop-nothing\n\nuntyped-case-args : ctxt → posinfo → ex-case-args → ex-tm → renamectxt → spanM (case-args × term)\nuntyped-case-args Γ pi cas t ρ =\n foldr {B = ctxt → renamectxt → 𝕃 tagged-val → (term → spanM ⊤) → spanM (case-args × term)}\n (λ {(ExCaseArg me pi x) rec Γ' ρ tvs sm →\n let tk = case me of λ {ExCaseArgTp → Tkk (KdHole pi-gen);\n ExCaseArgTm → Tkt (TpHole pi-gen);\n ExCaseArgEr → Tkt (TpHole pi-gen)} in\n rec\n (ctxt-tk-decl pi x tk Γ')\n (renamectxt-insert ρ (pi % x) x)\n (binder-data Γ' pi x tk (ex-case-arg-erased me) nothing\n (term-start-pos t) (term-end-pos t) :: tvs)\n (λ t →\n [- var-span (ex-case-arg-erased me) Γ' pi x untyped tk\n (when (ex-case-arg-erased me && is-free-in (pi % x) (erase t))\n \"The bound variable occurs free in the erasure of the body (not allowed)\") -]\n sm t) >>=c λ cas →\n return2 (case me of λ {ExCaseArgTm → CaseArg ff x nothing :: cas; _ → cas})})\n (λ Γ' ρ tvs sm →\n [- pattern-clause-span pi t (reverse tvs) -]\n untyped-term Γ' t >>= λ t~ →\n sm t~ >>\n return2 [] (subst-renamectxt Γ' ρ t~))\n cas Γ ρ [] λ _ → spanMok\n\nuntyped-case Γ (ExCase pi x cas t) csₗ asₗ ρ =\n untyped-case-args Γ pi cas t ρ >>=c λ cas~ t~ →\n case (qual-lookup Γ x) of λ where\n (just (qx , as , ctr-def ps T Cₗ cᵢ cₐ , loc)) →\n let c~ = Case qx cas~ t~ []\n eᵢ = \"This constructor overlaps with \" ^ x\n eₐ = unless (length cas~ =ℕ cₐ)\n (\"Expected \" ^ ℕ-to-string cₐ ^\n \" arguments after erasure, but got \" ^ ℕ-to-string (length cas~))\n eₗ = unless (Cₗ =ℕ csₗ)\n (\"Constructor's datatype has \" ^ ℕ-to-string Cₗ ^\n (if Cₗ =ℕ 1 then \" constructor\" else \" constructors\") ^\n \", but expected \" ^ ℕ-to-string csₗ) in\n [- Var-span Γ pi x untyped [] (asₗ cᵢ ||-maybe (eₐ ||-maybe eₗ)) -]\n return2 c~ ((λ cᵢ' → when (cᵢ =ℕ cᵢ') eᵢ) , (maybe-not (asₗ cᵢ) >> just cᵢ))\n _ →\n [- Var-span Γ pi x untyped [] (just $ \"This is not a valid constructor name\") -]\n return2 (Case x cas~ t~ []) (asₗ , nothing)\n", "meta": {"hexsha": "f9cc265d7a4e4b1795445b443bf12d5001e6f8bb", "size": 15424, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/untyped-spans.agda", "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/untyped-spans.agda", "max_issues_repo_name": "ice1k/cedille", "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/untyped-spans.agda", "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2729528536, "max_line_length": 144, "alphanum_fraction": 0.5608791494, "num_tokens": 5699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.32766828768970435, "lm_q1q2_score": 0.18420740661750457}} {"text": "import cedille-options\nopen import general-util\nmodule meta-vars (options : cedille-options.options) {mF : Set → Set} ⦃ _ : monad mF ⦄ where\n\nopen import cedille-types\nopen import constants\nopen import conversion\nopen import ctxt\nopen import free-vars\nopen import rename\nopen import spans options {mF}\nopen import subst\nopen import syntax-util\nopen import to-string options\n\n-- misc\n----------------------------------------------------------------------\n\n\n-- Meta-variables, prototypes, decorated types\n-- ==================================================\n\nrecord meta-var-sol (A : Set) : Set where\n constructor mk-meta-var-sol\n field\n sol : A\n src : checking-mode\n\ndata meta-var-sort : Set where\n meta-var-tp : (k : kind) → (mtp : maybe $ meta-var-sol type) → meta-var-sort\n meta-var-tm : (tp : type) → (mtm : maybe $ meta-var-sol term) → meta-var-sort\n\nrecord meta-var : Set where\n constructor meta-var-mk\n field\n name : string\n sort : meta-var-sort\n loc : span-location\nopen meta-var\n\npattern meta-var-mk-tp x k mtp l = meta-var-mk x (meta-var-tp k mtp) l\n\nrecord meta-vars : Set where\n constructor meta-vars-mk\n field\n order : 𝕃 var\n varset : trie meta-var\nopen meta-vars\n\ndata prototype : Set where\n proto-maybe : maybe type → prototype\n proto-arrow : erased? → prototype → prototype\n\ndata decortype : Set where\n decor-type : type → decortype\n decor-arrow : erased? → type → decortype → decortype\n decor-decor : erased? → var → tpkd → meta-var-sort → decortype → decortype\n decor-stuck : type → prototype → decortype\n decor-error : type → prototype → decortype\n\n\n-- Simple definitions and accessors\n-- --------------------------------------------------\n\nmeta-var-name : meta-var → var\nmeta-var-name X = meta-var.name X\n\nmeta-vars-get-varlist : meta-vars → 𝕃 var\nmeta-vars-get-varlist Xs = map (name ∘ snd) (trie-mappings (varset Xs))\n\nmeta-var-solved? : meta-var → 𝔹\nmeta-var-solved? (meta-var-mk n (meta-var-tp k nothing) _) = ff\nmeta-var-solved? (meta-var-mk n (meta-var-tp k (just _)) _) = tt\nmeta-var-solved? (meta-var-mk n (meta-var-tm tp nothing) _) = ff\nmeta-var-solved? (meta-var-mk n (meta-var-tm tp (just _)) _) = tt\n\nmeta-vars-empty : meta-vars\nmeta-vars-empty = meta-vars-mk [] empty-trie\n\nmeta-vars-empty? : meta-vars → 𝔹\nmeta-vars-empty? Xs = ~ (trie-nonempty (varset Xs ))\n\nmeta-vars-solved? : meta-vars → 𝔹\nmeta-vars-solved? Xs = trie-all meta-var-solved? (varset Xs)\n\nmeta-vars-filter : (meta-var → 𝔹) → meta-vars → meta-vars\nmeta-vars-filter f Xs =\n meta-vars-mk or vs\n where\n vs = trie-filter f (varset Xs)\n or = filter (trie-contains vs) (order Xs)\n\nmeta-var-sort-eq? : ctxt → (=S =T : meta-var-sort) → 𝔹\nmeta-var-sort-eq? Γ (meta-var-tp k₁ mtp₁) (meta-var-tp k₂ mtp₂)\n with conv-kind Γ k₁ k₂\n... | ff = ff\n... | tt =\n maybe-equal? sol-eq mtp₁ mtp₂\n where\n sol-eq : (sol₁ sol₂ : meta-var-sol type) → 𝔹\n sol-eq (mk-meta-var-sol sol₁ src) (mk-meta-var-sol sol₂ src₁) =\n conv-type Γ sol₁ sol₂\n\nmeta-var-sort-eq? _ _ _ = ff\n-- TODO terms not supported\n-- meta-var-sol-eq? (meta-var-tm tp mtm) (meta-var-tm tp₁ mtm₁) = {!!}\n\nmeta-var-equal? : ctxt → (X Y : meta-var) → 𝔹\nmeta-var-equal? Γ (meta-var-mk name₁ sol₁ _) (meta-var-mk name₂ sol₂ _) =\n name₁ =string name₂ && meta-var-sort-eq? Γ sol₁ sol₂\n\nmeta-vars-equal? : ctxt → (Xs Ys : meta-vars) → 𝔹\nmeta-vars-equal? Γ Xs Ys =\n trie-equal? (meta-var-equal? Γ) (meta-vars.varset Xs) (meta-vars.varset Ys)\n\nmeta-vars-lookup : meta-vars → var → maybe meta-var\nmeta-vars-lookup Xs x = trie-lookup (varset Xs) x\n\nmeta-vars-lookup-with-kind : meta-vars → var → maybe (meta-var × kind)\nmeta-vars-lookup-with-kind Xs x\n with meta-vars-lookup Xs x\n... | nothing = nothing\n... | (just X@(meta-var-mk-tp _ k _ _)) = just $ X , k\n... | (just X) = nothing\n\nmeta-var-set-src : meta-var → checking-mode → meta-var\nmeta-var-set-src (meta-var-mk-tp name₁ k (just sol) loc₁) m =\n meta-var-mk-tp name₁ k (just (record sol { src = m })) loc₁\nmeta-var-set-src (meta-var-mk-tp name₁ k nothing loc₁) m =\n meta-var-mk-tp name₁ k nothing loc₁\nmeta-var-set-src (meta-var-mk name₁ (meta-var-tm tp (just sol)) loc₁) m =\n meta-var-mk name₁ (meta-var-tm tp (just (record sol { src = m }))) loc₁\nmeta-var-set-src (meta-var-mk name₁ (meta-var-tm tp nothing) loc₁) m\n = meta-var-mk name₁ (meta-var-tm tp nothing) loc₁\n\nmeta-vars-lookup-kind : meta-vars → var → maybe kind\nmeta-vars-lookup-kind Xs x with meta-vars-lookup Xs x\n... | nothing = nothing\n... | (just (meta-var-mk-tp _ k _ _)) = just k\n... | (just X) = nothing\n\n-- conversion to types, terms, tks\n-- --------------------------------------------------\n\nmeta-var-sort-to-tk : meta-var-sort → tpkd\nmeta-var-sort-to-tk (meta-var-tp k mtp) = Tkk k\nmeta-var-sort-to-tk (meta-var-tm tp mtm) = Tkt tp\n\nmeta-var-to-type : meta-var → maybe type\nmeta-var-to-type (meta-var-mk-tp x k (just tp) _) = just (meta-var-sol.sol tp)\nmeta-var-to-type (meta-var-mk-tp x k nothing _) = just (TpVar x)\nmeta-var-to-type (meta-var-mk x (meta-var-tm tp mtm) _) = nothing\n\nmeta-var-to-term : meta-var → maybe term\nmeta-var-to-term (meta-var-mk-tp x k mtp _) = nothing\nmeta-var-to-term (meta-var-mk x (meta-var-tm tp (just tm)) _) = just (meta-var-sol.sol tm)\nmeta-var-to-term (meta-var-mk x (meta-var-tm tp nothing) _) = just (Var x)\n\nmeta-var-to-type-unsafe : meta-var → type\nmeta-var-to-type-unsafe X\n with meta-var-to-type X\n... | just tp = tp\n... | nothing = TpVar (meta-var-name X)\n\nmeta-var-to-term-unsafe : meta-var → term\nmeta-var-to-term-unsafe X\n with meta-var-to-term X\n... | just tm = tm\n... | nothing = Var (meta-var-name X)\n\n-- if all meta-vars are solved, return their solutions as args\nmeta-vars-to-args : meta-vars → maybe args\nmeta-vars-to-args (meta-vars-mk or vs) =\n flip 𝕃maybe-map or λ x → trie-lookup vs x ≫=maybe λ where\n (meta-var-mk name (meta-var-tm tp tm?) loc) →\n tm? >>= just ∘' ArgEr ∘' meta-var-sol.sol\n (meta-var-mk name (meta-var-tp kd tp?) loc) →\n tp? >>= just ∘' ArgTp ∘' meta-var-sol.sol\n\nprototype-to-maybe : prototype → maybe type\nprototype-to-maybe (proto-maybe mtp) = mtp\nprototype-to-maybe (proto-arrow _ _) = nothing\n\nprototype-to-checking : prototype → checking-mode\nprototype-to-checking = maybe-to-checking ∘ prototype-to-maybe\n\ndecortype-to-type : decortype → type\ndecortype-to-type (decor-type tp) = tp\ndecortype-to-type (decor-arrow at tp dt) =\n TpArrow tp at (decortype-to-type dt)\ndecortype-to-type (decor-decor b x tk sol dt) =\n TpAbs b x tk (decortype-to-type dt)\ndecortype-to-type (decor-stuck tp pt) = tp\ndecortype-to-type (decor-error tp pt) = tp\n\n-- hnf for decortype\n-- --------------------------------------------------\n\nhnf-decortype : ctxt → unfolding → decortype → (is-head : 𝔹) → decortype\nhnf-decortype Γ uf (decor-type tp) ish =\n decor-type (hnf Γ (record uf {unfold-defs = ish}) tp)\nhnf-decortype Γ uf (decor-arrow e? tp dt) ish =\n decor-arrow e? (hnf Γ (record uf {unfold-defs = ff}) tp) (hnf-decortype Γ uf dt ff)\nhnf-decortype Γ uf (decor-decor e? x tk sol dt) ish =\n decor-decor e? x tk sol (hnf-decortype Γ uf dt ff)\nhnf-decortype Γ uf dt@(decor-stuck _ _) ish = dt\nhnf-decortype Γ uf (decor-error tp pt) ish =\n decor-error (hnf Γ (record uf {unfold-defs = ff}) tp) pt\n\n-- substitutions\n-- --------------------------------------------------\n\nsubsth-meta-var-sort : substh-ret-t meta-var-sort\nsubsth-meta-var-sort Γ ρ σ (meta-var-tp k mtp) =\n meta-var-tp (substh Γ ρ σ k) ((flip maybe-map) mtp λ sol →\n record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) })\nsubsth-meta-var-sort Γ ρ σ (meta-var-tm tp mtm) =\n meta-var-tm (substh Γ ρ σ tp) (flip maybe-map mtm λ sol →\n record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) })\n\nsubst-meta-var-sort : subst-ret-t meta-var-sort\nsubst-meta-var-sort Γ t x (meta-var-tp k mtp) =\n meta-var-tp (subst Γ t x k) $ (flip maybe-map) mtp λ sol →\n record sol { sol = subst Γ t x $ meta-var-sol.sol sol }\n\nsubst-meta-var-sort Γ t x (meta-var-tm tp mtm) =\n meta-var-tm (subst Γ t x tp) $ (flip maybe-map) mtm λ where\n (mk-meta-var-sol sol src) → mk-meta-var-sol (subst Γ t x sol) src\n\nmeta-vars-get-sub : meta-vars → trie (Σi exprd ⟦_⟧)\nmeta-vars-get-sub Xs =\n trie-catMaybe (trie-map (maybe-map ,_ ∘ meta-var-to-type) (varset Xs))\n\nmeta-vars-subst-type' : (unfold : 𝔹) → ctxt → meta-vars → type → type\nmeta-vars-subst-type' u Γ Xs tp =\n let tp' = substs Γ (meta-vars-get-sub Xs) tp in\n if u then hnf Γ unfold-head-elab tp' else tp'\n\nmeta-vars-subst-type : ctxt → meta-vars → type → type\nmeta-vars-subst-type = meta-vars-subst-type' tt\n\nmeta-vars-subst-kind : ctxt → meta-vars → kind → kind\nmeta-vars-subst-kind Γ Xs k\n = hnf Γ unfold-head-elab (substh Γ empty-renamectxt (meta-vars-get-sub Xs) k)\n\n-- string and span helpers\n-- --------------------------------------------------\n\nmeta-var-to-string : meta-var → strM\nmeta-var-to-string (meta-var-mk-tp name k nothing sl)\n = strMetaVar name sl\n >>str strAdd \" : \" >>str to-stringe k\nmeta-var-to-string (meta-var-mk-tp name k (just tp) sl)\n = strMetaVar name sl\n >>str strAdd \" : \" >>str to-stringe k\n >>str strAdd \" = \" >>str to-stringe (meta-var-sol.sol tp) -- tp\nmeta-var-to-string (meta-var-mk name (meta-var-tm tp nothing) sl)\n = strMetaVar name sl\n >>str strAdd \" : \" >>str to-stringe tp\nmeta-var-to-string (meta-var-mk name (meta-var-tm tp (just tm)) sl)\n = strMetaVar name sl\n >>str strAdd \" : \" >>str to-stringe tp\n >>str strAdd \" = \" >>str to-stringe (meta-var-sol.sol tm) -- tm\n\nmeta-vars-to-stringe : 𝕃 meta-var → strM\nmeta-vars-to-stringe []\n = strEmpty\nmeta-vars-to-stringe (v :: [])\n = meta-var-to-string v\nmeta-vars-to-stringe (v :: vs)\n = meta-var-to-string v >>str strAdd \", \" >>str meta-vars-to-stringe vs\n\nmeta-vars-to-string : meta-vars → strM\nmeta-vars-to-string Xs =\n meta-vars-to-stringe\n ((flip map) (order Xs) λ x →\n case trie-lookup (varset Xs) x of λ where\n nothing →\n meta-var-mk\n (x ^ \"-missing!\") (meta-var-tp KdStar nothing)\n missing-span-location\n (just X) → X)\n\nprototype-to-string : prototype → strM\nprototype-to-string (proto-maybe nothing) = strAdd \"⁇\"\nprototype-to-string (proto-maybe (just tp)) = to-stringe tp\nprototype-to-string (proto-arrow e? pt) =\n strAdd \"⁇\" >>str strAdd (arrowtype-to-string e?)\n >>str prototype-to-string pt\n\ndecortype-to-string : decortype → strM\ndecortype-to-string (decor-type tp) =\n strAdd \"[\" >>str to-stringe tp >>str strAdd \"]\"\ndecortype-to-string (decor-arrow e? tp dt) =\n to-stringe tp\n >>str strAdd (arrowtype-to-string e?)\n >>str decortype-to-string dt\ndecortype-to-string (decor-decor e? x tk sol dt) =\n strAdd (binder e? sol) >>str meta-var-to-string (meta-var-mk x sol missing-span-location)\n >>str strAdd \"<\" >>str tpkd-to-stringe tk >>str strAdd \">\" >>str strAdd \" . \" >>str decortype-to-string dt\n where\n binder : erased? → meta-var-sort → string\n binder Erased sol = \"∀ \"\n binder Pi (meta-var-tm tp mtm) = \"Π \"\n -- vv clause below \"shouldn't\" happen\n binder Pi (meta-var-tp k mtp) = \"∀ \"\n\ndecortype-to-string (decor-stuck tp pt) =\n strAdd \"(\" >>str to-stringe tp >>str strAdd \" , \" >>str prototype-to-string pt >>str strAdd \")\"\ndecortype-to-string (decor-error tp pt) =\n strAdd \"([\" >>str (to-stringe tp) >>str strAdd \"] ‼ \" >>str prototype-to-string pt >>str strAdd \")\"\n\nmeta-vars-data-h : ctxt → string → kind ∨ (meta-var-sol type) → tagged-val\nmeta-vars-data-h Γ X (inj₁ k) =\n strRunTag \"meta-vars-intro\" Γ\n (strAdd (unqual-local X ^ \" \") >>str to-stringe k)\nmeta-vars-data-h Γ X (inj₂ sol) =\n strRunTag \"meta-vars-sol\" Γ $\n strAdd (unqual-local X ^ \" \") >>str\n strAdd (checking-to-string (meta-var-sol.src sol) ^ \" \") >>str\n (to-stringe ∘ meta-var-sol.sol $ sol)\n\nmeta-vars-data-all : ctxt → meta-vars → 𝕃 tagged-val\nmeta-vars-data-all Γ = foldr\n (uncurry λ where\n _ (meta-var-mk X (meta-var-tp kd nothing) loc) xs →\n meta-vars-data-h Γ X (inj₁ kd) :: xs\n _ (meta-var-mk X (meta-var-tp kd (just tp)) loc) xs →\n meta-vars-data-h Γ X (inj₁ kd)\n :: meta-vars-data-h Γ X (inj₂ tp) :: xs\n _ _ xs → xs)\n [] ∘ (trie-mappings ∘ meta-vars.varset)\n\nmeta-vars-intro-data : ctxt → meta-vars → 𝕃 tagged-val\nmeta-vars-intro-data Γ = map (h ∘ snd) ∘ (trie-mappings ∘ meta-vars.varset)\n where\n h : meta-var → tagged-val\n h (meta-var-mk X (meta-var-tp kd mtp) loc) = meta-vars-data-h Γ X (inj₁ kd)\n h (meta-var-mk X (meta-var-tm tp mtm) loc) =\n meta-vars-data-h Γ X\n (inj₂ (mk-meta-var-sol (TpVar \"unimplemented\") untyped))\n\nmeta-vars-sol-data : ctxt → meta-vars → meta-vars → 𝕃 tagged-val\nmeta-vars-sol-data Γ Xsₒ Xsₙ = foldr (λ X xs → maybe-else xs (_:: xs) (h (snd X)))\n [] (trie-mappings (meta-vars.varset Xsₙ))\n where\n h : meta-var → maybe tagged-val\n h (meta-var-mk X (meta-var-tp kd (just tp)) loc) with trie-lookup (meta-vars.varset Xsₒ) X\n ...| just (meta-var-mk _ (meta-var-tp _ (just _)) _) = nothing\n ...| _ = just (meta-vars-data-h Γ X (inj₂ tp)\n )\n h (meta-var-mk X (meta-var-tp kd nothing) loc) = nothing\n h (meta-var-mk X (meta-var-tm tp mtm) loc) =\n just (meta-vars-data-h Γ X\n (inj₂ (mk-meta-var-sol (TpVar \"unimplemented\") untyped)))\n\n\nmeta-vars-check-type-mismatch : ctxt → string → type → meta-vars → type\n → 𝕃 tagged-val × err-m\nmeta-vars-check-type-mismatch Γ s tp Xs tp'\n = (expected-type Γ tp :: [ type-data Γ tp'' ]) ,\n (if conv-type Γ tp tp''\n then nothing\n else just (\"The expected type does not match the \"\n ^ s ^ \" type.\"))\n where tp'' = meta-vars-subst-type' ff Γ Xs tp'\n\nmeta-vars-check-type-mismatch-if : maybe type → ctxt → string → meta-vars\n → type → 𝕃 tagged-val × err-m\nmeta-vars-check-type-mismatch-if (just tp) Γ s Xs tp'\n = meta-vars-check-type-mismatch Γ s tp Xs tp'\nmeta-vars-check-type-mismatch-if nothing Γ s Xs tp'\n = [ type-data Γ tp″ ] , nothing\n where\n tp″ = meta-vars-subst-type' ff Γ Xs tp'\n\ndecortype-data : ctxt → decortype → tagged-val\ndecortype-data Γ dt = strRunTag \"head decoration\" Γ (decortype-to-string dt)\n\nprototype-data : ctxt → prototype → tagged-val\nprototype-data Γ pt = strRunTag \"head prototype\" Γ (prototype-to-string pt)\n\n\n-- collecting, merging, matching\n-- --------------------------------------------------\n\nmeta-var-fresh-t : (S : Set) → Set\nmeta-var-fresh-t S = meta-vars → var → span-location → S → meta-var\n\nmeta-var-fresh : meta-var-fresh-t meta-var-sort\nmeta-var-fresh Xs x sl sol\n with fresh-h (trie-contains (varset Xs)) (meta-var-pfx-str ^ x)\n... | x' = meta-var-mk x' sol sl\n\nmeta-var-fresh-tp : meta-var-fresh-t (kind × maybe (meta-var-sol type))\nmeta-var-fresh-tp Xs x sl (k , msol) =\n meta-var-fresh Xs x sl (meta-var-tp k msol)\n\nmeta-var-fresh-tm : meta-var-fresh-t (type × maybe (meta-var-sol term))\nmeta-var-fresh-tm Xs x sl (tp , mtm) = meta-var-fresh Xs x sl (meta-var-tm tp mtm)\n\nprivate\n meta-vars-set : meta-vars → meta-var → meta-vars\n meta-vars-set Xs X = record Xs { varset = trie-insert (varset Xs) (name X) X }\n\n-- add a meta-var\nmeta-vars-add : meta-vars → meta-var → meta-vars\nmeta-vars-add Xs X\n = record (meta-vars-set Xs X) { order = (order Xs) ++ [ name X ] }\n\nmeta-vars-add* : meta-vars → 𝕃 meta-var → meta-vars\nmeta-vars-add* Xs [] = Xs\nmeta-vars-add* Xs (Y :: Ys) = meta-vars-add* (meta-vars-add Xs Y) Ys\n\nmeta-vars-from-list : 𝕃 meta-var → meta-vars\nmeta-vars-from-list Xs = meta-vars-add* meta-vars-empty Xs\n\nmeta-vars-remove : meta-vars → meta-var → meta-vars\nmeta-vars-remove (meta-vars-mk or vs) X =\n let x = meta-var-name X\n in meta-vars-mk (remove _=string_ x or) (trie-remove vs x)\n\nmeta-vars-in-type : meta-vars → type → meta-vars\nmeta-vars-in-type Xs tp =\n let xs = free-vars tp in\n meta-vars-filter (stringset-contains xs ∘ name) Xs\n\nmeta-vars-unsolved : meta-vars → meta-vars\nmeta-vars-unsolved = meta-vars-filter λ where\n (meta-var-mk x (meta-var-tp k mtp) _) → ~ isJust mtp\n (meta-var-mk x (meta-var-tm tp mtm) _) → ~ isJust mtm\n\nmeta-vars-are-free-in-type : meta-vars → type → 𝔹\nmeta-vars-are-free-in-type Xs tp =\n let xs = free-vars tp in\n list-any (stringset-contains xs) (order Xs)\n\n\n-- Unfolding a type with meta-vars\n-- ==================================================\n\n-- ... in order to reveal a term or type application\n\n-- \"View\" data structures\n-- --------------------------------------------------\n\n-- The decorated type is really an arrow\nrecord is-tmabsd : Set where\n constructor mk-tmabsd\n field\n is-tmabsd-dt : decortype\n is-tmabsd-e? : erased?\n is-tmabsd-var : var\n is-tmabsd-dom : type\n is-tmabsd-var-in-body : 𝔹\n is-tmabsd-cod : decortype\nopen is-tmabsd public\n\nis-tmabsd? = decortype ∨ is-tmabsd\n\npattern yes-tmabsd dt e? x dom occ cod = inj₂ (mk-tmabsd dt e? x dom occ cod)\npattern not-tmabsd tp = inj₁ tp\n\nrecord is-tpabsd : Set where\n constructor mk-tpabsd\n field\n is-tpabsd-dt : decortype\n is-tpabsd-e? : erased?\n is-tpabsd-var : var\n is-tpabsd-kind : kind\n is-tpabsd-sol : maybe type\n is-tpabsd-body : decortype\nopen is-tpabsd public\n\nis-tpabsd? = decortype ∨ is-tpabsd\n\npattern yes-tpabsd dt e? x k mtp dt' = inj₂ (mk-tpabsd dt e? x k mtp dt')\npattern not-tpabsd dt = inj₁ dt\n\n{-# TERMINATING #-}\nnum-arrows-in-type : ctxt → type → ℕ\nnum-arrows-in-type Γ tp = nait Γ (hnf' Γ tp) 0 tt\n where\n hnf' : ctxt → type → type\n hnf' Γ tp = hnf Γ unfold-head-elab tp\n\n nait : ctxt → type → (acc : ℕ) → 𝔹 → ℕ\n -- definitely another arrow\n nait Γ (TpAbs _ _ (Tkk _) tp) acc uf = nait Γ tp acc ff\n nait Γ (TpAbs _ _ (Tkt _) tp) acc uf = nait Γ tp (1 + acc) ff\n -- definitely not another arrow\n nait Γ (TpIota _ _ _) acc uf = acc\n nait Γ (TpEq _ _) acc uf = acc\n nait Γ (TpHole _) acc uf = acc\n nait Γ (TpLam _ _ _) acc uf = acc\n nait Γ (TpVar x) acc tt = acc\n nait Γ (TpApp tp₁ tp₂) acc tt = acc\n nait Γ tp acc ff = nait Γ (hnf' Γ tp) acc tt\n\n-- Utilities for match-types in classify.agda\n-- ==================================================\n--\n-- Match a type with meta-variables in it to one without\n\n-- errors\n-- --------------------------------------------------\n\nmatch-error-data = string × 𝕃 tagged-val\n\nmatch-error-t : ∀ {a} → Set a → Set a\nmatch-error-t A = match-error-data ∨ A\n\npattern match-error e = inj₁ e\npattern match-ok a = inj₂ a\n\nmodule meta-vars-match-errors where\n -- boilerplate\n match-error-msg = \"Matching failed\"\n\n -- tagged values for error messages\n match-lhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val\n match-lhs = to-string-tag \"expected lhs\"\n\n match-rhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val\n match-rhs = to-string-tag \"computed rhs\"\n\n the-meta-var : var → tagged-val\n the-meta-var = strRunTag \"the meta-var\" empty-ctxt ∘ strAdd\n\n the-solution : ctxt → type → tagged-val\n the-solution = to-string-tag \"the solution\"\n\n fst-snd-sol : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val\n fst-snd-sol Γ t₁ t₂ =\n to-string-tag \"first solution\" Γ t₁ :: [ to-string-tag \"second solution\" Γ t₂ ]\n\n lhs-rhs : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val\n lhs-rhs Γ t₁ t₂ = match-lhs Γ t₁ :: [ match-rhs Γ t₂ ]\n\n -- error-data\n e-solution-ineq : ctxt → (tp₁ tp₂ : type) → var → match-error-data\n e-solution-ineq Γ tp₁ tp₂ X =\n match-error-msg ^ \" because it produced two incovertible solutions for a meta-variable\"\n , the-meta-var X :: fst-snd-sol Γ tp₁ tp₂\n\n e-match-failure : match-error-data\n e-match-failure =\n \"The expected argument type is not a (first-order) match of the computed type\"\n , []\n\n e-matchk-failure : match-error-data\n e-matchk-failure =\n \"The expected argument kind is not a (first-order) match of the computed kind\"\n , []\n\n e-meta-scope : ctxt → (X tp : type) → match-error-data\n-- e-meta-scope : ctxt → (x : var) → (tp₁ tp₂ : type) → match-error-data\n e-meta-scope Γ X tp =\n match-error-msg ^ \" because the solution contains a bound variable of the computed argument type\"\n , to-string-tag \"the meta var\" Γ X :: [ to-string-tag \"the solution\" Γ tp ]\n\n e-bad-sol-kind : ctxt → (X : var) → (sol : type) → match-error-data\n e-bad-sol-kind Γ X sol =\n \"The meta-variable was matched to a type whose kind does not match its own\"\n , the-meta-var X :: [ the-solution Γ sol ]\n\nopen meta-vars-match-errors\n\n-- meta-vars-match auxiliaries\n-- --------------------------------------------------\n\nlocal-vars = stringset\n\nmeta-vars-solve-tp : ctxt → meta-vars → var → type → checking-mode → match-error-t meta-vars\nmeta-vars-solve-tp Γ Xs x tp m with trie-lookup (varset Xs) x\n... | nothing\n = match-error $ x ^ \" is not a meta-var!\" , []\n... | just (meta-var-mk _ (meta-var-tm tp' mtm) _)\n = match-error $ x ^ \" is a term meta-var!\" , []\n... | just (meta-var-mk-tp _ k nothing sl)\n = match-ok (meta-vars-set Xs (meta-var-mk-tp x k (just (mk-meta-var-sol tp m)) sl))\n... | just (meta-var-mk-tp _ k (just sol) _) =\n let mk-meta-var-sol tp' src = sol in\n err⊎-guard (~ conv-type Γ tp tp') (e-solution-ineq Γ tp tp x)\n >> match-ok Xs\n\n-- update the kinds of HO meta-vars with\n-- solutions\nmeta-vars-update-kinds : ctxt → (Xs Xsₖ : meta-vars) → meta-vars\nmeta-vars-update-kinds Γ Xs Xsₖ =\n record Xs { varset = (flip trie-map) (varset Xs) λ where\n (meta-var-mk-tp x k mtp sl) → meta-var-mk-tp x (meta-vars-subst-kind Γ Xsₖ k) mtp sl\n sol → sol\n }\n\nhnf-elab-if : {ed : exprd} → 𝔹 → ctxt → ⟦ ed ⟧ → 𝔹 → ⟦ ed ⟧\nhnf-elab-if b Γ t b' = if b then hnf Γ (record unfold-head-elab {unfold-defs = b'}) t else t\n\nmeta-vars-add-from-tpabs : ctxt → span-location → meta-vars → erased? → var → kind → type → meta-var × meta-vars\nmeta-vars-add-from-tpabs Γ sl Xs e? x k tp =\n let Y = meta-var-fresh-tp Xs x sl (k , nothing)\n Xs' = meta-vars-add Xs Y\n-- tp' = subst Γ (meta-var-to-type-unsafe Y) x tp\n in Y , Xs'\n\n{-\n-- Legacy for elaboration.agda\n-- ==================================================\n\n-- TODO: remove dependency and delete code\n\n\n{-# TERMINATING #-} -- subst of a meta-var does not increase distance to arrow\nmeta-vars-peel : ctxt → span-location → meta-vars → type → (𝕃 meta-var) × type\nmeta-vars-peel Γ sl Xs (Abs pi e? pi' x tk@(Tkk k) tp)\n with meta-vars-add-from-tpabs Γ sl Xs (mk-tpabs e? x k tp)\n... | (Y , Xs')\n with subst Γ (meta-var-to-type-unsafe Y) x tp\n... | tp' =\n let ret = meta-vars-peel Γ sl Xs' tp' ; Ys = fst ret ; rtp = snd ret\n in (Y :: Ys , rtp)\nmeta-vars-peel Γ sl Xs (NoSpans tp _) =\n meta-vars-peel Γ sl Xs tp\nmeta-vars-peel Γ sl Xs (TpParens _ tp _) =\n meta-vars-peel Γ sl Xs tp\nmeta-vars-peel Γ sl Xs tp = [] , tp\n\nmeta-vars-unfold-tpapp : ctxt → meta-vars → type → is-tpabs?\nmeta-vars-unfold-tpapp Γ Xs tp\n with meta-vars-subst-type Γ Xs tp\n... | Abs _ b _ x (Tkk k) tp' = yes-tpabs b x k tp'\n... | tp' = not-tpabs tp'\n\nmeta-vars-unfold-tmapp : ctxt → span-location → meta-vars → type → 𝕃 meta-var × is-tmabs?\nmeta-vars-unfold-tmapp Γ sl Xs tp\n with meta-vars-peel Γ sl Xs (meta-vars-subst-type Γ Xs tp)\n... | Ys , Abs _ b _ x (Tkt dom) cod =\n Ys , yes-tmabs b x dom (is-free-in check-erased x cod) cod\n... | Ys , TpArrow dom e? cod =\n Ys , yes-tmabs e? \"_\" dom ff cod\n... | Ys , tp' = Ys , not-tmabs tp'\n\n-}\n", "meta": {"hexsha": "e5cacb49ad597f785bc1d707ed5715b2bfdfa80c", "size": 23095, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/meta-vars.agda", "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/meta-vars.agda", "max_issues_repo_name": "ice1k/cedille", "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/meta-vars.agda", "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8618012422, "max_line_length": 112, "alphanum_fraction": 0.6287075124, "num_tokens": 7505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.3557749071749626, "lm_q1q2_score": 0.18344462765391792}} {"text": "{-# OPTIONS --without-K #-}\n\n--open import HoTT\nopen import homotopy.3x3.PushoutPushout\nopen import homotopy.3x3.Transpose\nimport homotopy.3x3.To as To\nimport homotopy.3x3.From as From\nopen import homotopy.3x3.Common\n\nmodule homotopy.3x3.FromTo2 {i} (d : Span^2 {i}) where\n\nopen Span^2 d\nopen M d hiding (Pushout^2)\nopen M (transpose d) using () renaming (module F₁∙ to F∙₁; f₁∙ to f∙₁;\n module F₃∙ to F∙₃; f₃∙ to f∙₃;\n v-h-span to h-v-span)\nopen M using (Pushout^2)\n\nopen To d\nopen From d\n\nopen import homotopy.3x3.FromToInit d\n\nmodule M2 (c : A₂₂) where\n\n coh : ∀ {i} {A : Type i} {a b c d : A}\n {p q : a == b} (α : p == q)\n {v w : b == d} {β β' : w == v} (eqβ : β == β')\n {t u : a == c} {ε ε' : u == t} (eqε : ε == ε')\n {r s : c == d} (ζ : r == s)\n (γ : (q , v =□ t , s))\n (δ : (p , w =□ u , r))\n (eq : γ == δ ∙□-i/ ! β' / ε' / ∙□-o/ ! α / ζ /)\n → (α , β , γ =□□ δ , ε , ζ)\n coh idp {β = idp} idp {ε = idp} idp idp _ _ x = x\n\n end-lemma1 : ap (right ∘ f₃∙) (glue c) == ap (from ∘ i₄∙ ∘ f₃∙) (glue c) :> E∙₂Red.T-lhs c\n end-lemma1 =\n ap (right ∘ f₃∙) (glue c)\n =⟨ ap-∘ right f₃∙ (glue c) ⟩\n ap right (ap f₃∙ (glue c))\n =⟨ ap (ap right) (F₃∙.glue-β c) ⟩\n ap right (ap left (H₃₁ c) ∙ glue (f₃₂ c) ∙ ap right (H₃₃ c))\n =⟨ ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c) ⟩\n ap (right ∘ left) (H₃₁ c) ∙ ap right (glue (f₃₂ c)) ∙ ap (right ∘ right) (H₃₃ c)\n =⟨ ! (from-to-r-g (f₃₂ c)) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c)) ⟩\n ap (right ∘ left) (H₃₁ c) ∙ (ap (from ∘ i₄∙) (glue (f₃₂ c))) ∙ ap (right ∘ right) (H₃₃ c)\n =⟨ ! (ap-∙∙`∘`∘ (from ∘ i₄∙) left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) ⟩\n ap (from ∘ i₄∙) (ap left (H₃₁ c) ∙ glue (f₃₂ c) ∙ ap right (H₃₃ c))\n =⟨ ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ⟩\n ap (from ∘ i₄∙) (ap f₃∙ (glue c))\n =⟨ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) ⟩\n ap (from ∘ i₄∙ ∘ f₃∙) (glue c) ∎\n\n lemma1 : ↓-='-out (apd (from-to-r ∘ f₃∙) (glue c)) == end-lemma1\n lemma1 = \n ↓-='-out (apd (from-to-r ∘ f₃∙) (glue c))\n\n =⟨ apd-∘'' from-to-r f₃∙ (glue c) (F₃∙.glue-β c) |in-ctx ↓-='-out ⟩\n\n ↓-='-out (↓-ap-out= (λ b → from (to (right b)) == right b) f₃∙ (glue c) (F₃∙.glue-β c) (apd from-to-r (ap left (H₃₁ c) ∙ glue (f₃₂ c) ∙ ap right (H₃₃ c))))\n\n =⟨ apd-∙∙`∘`∘ from-to-r left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c) |in-ctx (λ u → ↓-='-out (↓-ap-out= (λ b → from (to (right b)) == right b) f₃∙ (glue c) (F₃∙.glue-β c) u)) ⟩\n\n ↓-='-out (↓-ap-out= (λ b → from (to (right b)) == right b) f₃∙ (glue c) (F₃∙.glue-β c) (↓-ap-in _ _ (apd (λ _ → idp) (H₃₁ c)) ∙ᵈ apd from-to-r (glue (f₃₂ c)) ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₃₃ c))))\n\n =⟨ FromToR.glue-β (f₃₂ c) |in-ctx (λ u → ↓-='-out (↓-ap-out= (λ b → from (to (right b)) == right b) f₃∙ (glue c) (F₃∙.glue-β c)\n (↓-ap-in _ _ (apd (λ _ → idp) (H₃₁ c)) ∙ᵈ u ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₃₃ c))))) ⟩\n\n ↓-='-out (↓-ap-out= (λ b → from (to (right b)) == right b) f₃∙ (glue c) (F₃∙.glue-β c)\n (↓-ap-in _ _ (apd (λ _ → idp) (H₃₁ c)) ∙ᵈ ↓-='-in (! (from-to-r-g (f₃₂ c))) ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₃₃ c))))\n\n =⟨ lemma-a _ f₃∙ (glue c) (F₃∙.glue-β c) _ ⟩\n\n ↓-='-out (↓-ap-in _ _ (apd (λ x → idp {a = right (left x)}) (H₃₁ c)) ∙ᵈ ↓-='-in (! (from-to-r-g (f₃₂ c))) ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₃₃ c)))\n ∙□-i/ ap-∘ right f₃∙ (glue c) ∙ ap (ap right) (F₃∙.glue-β c)\n / ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ∙ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) /\n\n =⟨ lemma-b (glue (f₃₂ c)) (apd (λ _ → idp) (H₃₁ c)) (! (from-to-r-g (f₃₂ c))) (apd (λ _ → idp) (H₃₃ c)) |in-ctx (λ u → u ∙□-i/ ap-∘ right f₃∙ (glue c) ∙ ap (ap right) (F₃∙.glue-β c)\n / ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ∙ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) /) ⟩\n\n (↓-='-out (apd (λ x → idp {a = right (left x)}) (H₃₁ c))\n ∙□h ((! (from-to-r-g (f₃₂ c)))\n ∙□h (↓-='-out (apd (λ _ → idp) (H₃₃ c)))))\n ∙□-i/ ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)\n / ! (ap-∙∙`∘`∘ (from ∘ i₄∙) left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) /\n ∙□-i/ ap-∘ right f₃∙ (glue c) ∙ ap (ap right) (F₃∙.glue-β c)\n / ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ∙ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) /\n\n =⟨ coh3 |in-ctx (λ u → u\n ∙□-i/ ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)\n / ! (ap-∙∙`∘`∘ (from ∘ i₄∙) left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) /\n ∙□-i/ ap-∘ right f₃∙ (glue c) ∙ ap (ap right) (F₃∙.glue-β c)\n / ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ∙ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) /) ⟩\n\n ((! (from-to-r-g (f₃₂ c))) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c)))\n ∙□-i/ ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)\n / ! (ap-∙∙`∘`∘ (from ∘ i₄∙) left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) /\n ∙□-i/ ap-∘ right f₃∙ (glue c) ∙ ap (ap right) (F₃∙.glue-β c)\n / ! (ap (ap (from ∘ i₄∙)) (F₃∙.glue-β c)) ∙ ∘-ap (from ∘ i₄∙) f₃∙ (glue c) /\n\n =⟨ coh' ⟩\n end-lemma1 ∎ where\n\n coh' : ∀ {i} {A : Type i} {x y : A} {a b c d e f g h : x == y} {p : a == b} {q : b == c}\n {r : c == d} {s : d == e} {t : e == f} {u : f == g} {v : g == h}\n → (s ∙□-i/ r / t / ∙□-i/ p ∙ q / u ∙ v /) == (a =⟨ p ⟩ b =⟨ q ⟩ c =⟨ r ⟩ d =⟨ s ⟩ e =⟨ t ⟩ f =⟨ u ⟩ g =⟨ v ⟩ h ∎)\n coh' {p = idp} {idp} {idp} {idp} {idp} {idp} {idp} = idp\n\n coh2 : ∀ {i j} {A : Type i} {B : Type j} {f : A → B} {x y : A} {p : x == y}\n → ↓-='-out (apd (λ x → idp {a = f x}) p) == idp {a = ap f p}\n coh2 {p = idp} = idp\n\n coh3 : (↓-='-out (apd (λ x → idp {a = right (left x)}) (H₃₁ c))\n ∙□h ((! (from-to-r-g (f₃₂ c)))\n ∙□h (↓-='-out (apd (λ _ → idp) (H₃₃ c))))) == ((! (from-to-r-g (f₃₂ c))) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c)))\n coh3 = \n ↓-='-out (apd (λ x → idp {a = right (left x)}) (H₃₁ c))\n ∙□h ((! (from-to-r-g (f₃₂ c)))\n ∙□h (↓-='-out (apd (λ _ → idp) (H₃₃ c))))\n\n =⟨ coh2 {f = right ∘ left} {p = H₃₁ c} |in-ctx (λ u → u ∙□h ((! (from-to-r-g (f₃₂ c))) ∙□h (↓-='-out (apd (λ _ → idp) (H₃₃ c))))) ⟩\n\n idp {a = ap (right ∘ left) (H₃₁ c)} ∙□h ((! (from-to-r-g (f₃₂ c)))\n ∙□h (↓-='-out (apd (λ _ → idp) (H₃₃ c))))\n\n =⟨ coh2 {f = right ∘ right} {p = H₃₃ c} |in-ctx (λ u → idp {a = ap (right ∘ left) (H₃₁ c)} ∙□h ((! (from-to-r-g (f₃₂ c))) ∙□h u)) ⟩\n\n idp {a = ap (right ∘ left) (H₃₁ c)} ∙□h ((! (from-to-r-g (f₃₂ c))) ∙□h idp {a = ap (right ∘ right) (H₃₃ c)})\n\n =⟨ coh4 (ap (right ∘ left) (H₃₁ c)) (ap (right ∘ right) (H₃₃ c)) (! (from-to-r-g (f₃₂ c))) ⟩\n\n ((! (from-to-r-g (f₃₂ c))) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c))) ∎ where\n\n coh4 : ∀ {i} {A : Type i} {x y z t : A} (p : x == y) (q : z == t) {s t : y == z} (r : s == t)\n → (idp {a = p} ∙□h (r ∙□h idp {a = q})) == (r |in-ctx (λ u → p ∙ u ∙ q))\n coh4 idp idp idp = idp\n\n end-lemma3 : ap (left ∘ f₁∙) (glue c) == ap (from ∘ i₀∙ ∘ f₁∙) (glue c)\n end-lemma3 =\n ap (left ∘ f₁∙) (glue c)\n =⟨ ap-∘ left f₁∙ (glue c) ⟩\n ap left (ap f₁∙ (glue c))\n =⟨ ap (ap left) (F₁∙.glue-β c) ⟩\n ap left (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))\n =⟨ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) ⟩\n ap (left ∘ left) (H₁₁ c) ∙ ap left (glue (f₁₂ c)) ∙ ap (left ∘ right) (H₁₃ c)\n =⟨ ! (from-to-l-g (f₁₂ c)) |in-ctx (λ u → ap (left ∘ left) (H₁₁ c) ∙ u ∙ ap (left ∘ right) (H₁₃ c)) ⟩\n ap (left ∘ left) (H₁₁ c) ∙ (ap (from ∘ i₀∙) (glue (f₁₂ c))) ∙ ap (left ∘ right) (H₁₃ c)\n =⟨ ! (ap-∙∙`∘`∘ (from ∘ i₀∙) left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c)) ⟩\n ap (from ∘ i₀∙) (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))\n =⟨ ! (ap (ap (from ∘ i₀∙)) (F₁∙.glue-β c)) ⟩\n ap (from ∘ i₀∙) (ap f₁∙ (glue c))\n =⟨ ∘-ap (from ∘ i₀∙) f₁∙ (glue c) ⟩\n ap (from ∘ i₀∙ ∘ f₁∙) (glue c) ∎\n\n lemma3 : ↓-='-out (apd (from-to-l ∘ f₁∙) (glue c)) == end-lemma3\n lemma3 =\n ↓-='-out (apd (from-to-l ∘ f₁∙) (glue c))\n\n =⟨ apd-∘'' from-to-l f₁∙ (glue c) (F₁∙.glue-β c) |in-ctx ↓-='-out ⟩\n\n ↓-='-out (↓-ap-out= (λ b → from (to (left b)) == left b) f₁∙ (glue c) (F₁∙.glue-β c) (apd from-to-l (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))))\n\n =⟨ lemma-a _ f₁∙ (glue c) (F₁∙.glue-β c) (apd from-to-l (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))) ⟩\n\n ↓-='-out (apd from-to-l (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c)))\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /\n\n =⟨ apd-∙∙`∘`∘ from-to-l left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) |in-ctx\n (λ u → ↓-='-out u ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /) ⟩\n\n ↓-='-out (↓-ap-in _ _ (apd (λ _ → idp) (H₁₁ c)) ∙ᵈ apd from-to-l (glue (f₁₂ c)) ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₁₃ c)))\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /\n\n =⟨ FromToL.glue-β (f₁₂ c) |in-ctx (λ u → ↓-='-out (↓-ap-in _ _ (apd (λ _ → idp) (H₁₁ c)) ∙ᵈ u ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₁₃ c)))\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /) ⟩\n\n ↓-='-out (↓-ap-in _ _ (apd (λ _ → idp) (H₁₁ c)) ∙ᵈ ↓-='-in (! (from-to-l-g (f₁₂ c))) ∙ᵈ ↓-ap-in _ _ (apd (λ _ → idp) (H₁₃ c)))\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /\n\n =⟨ lemma-b (glue (f₁₂ c)) (apd (λ _ → idp) (H₁₁ c)) (! (from-to-l-g (f₁₂ c))) (apd (λ _ → idp) (H₁₃ c))\n |in-ctx (λ u → u ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /) ⟩\n\n (↓-='-out (apd (λ _ → idp) (H₁₁ c)) ∙□h ((! (from-to-l-g (f₁₂ c))) ∙□h ↓-='-out (apd (λ _ → idp) (H₁₃ c))))\n ∙□-i/ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) / ! (ap-∙∙`∘`∘ (from ∘ i₀∙) left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c)) /\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /\n\n =⟨ coh2 (left ∘ left) (left ∘ right) (H₁₁ c) (! (from-to-l-g (f₁₂ c))) (H₁₃ c) |in-ctx (λ u →\n u ∙□-i/ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) / ! (ap-∙∙`∘`∘ (from ∘ i₀∙) left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c)) /\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /) ⟩\n\n ((! (from-to-l-g (f₁₂ c))) |in-ctx (λ u → ap (left ∘ left) (H₁₁ c) ∙ u ∙ ap (left ∘ right) (H₁₃ c)))\n ∙□-i/ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) / ! (ap-∙∙`∘`∘ (from ∘ i₀∙) left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c)) /\n ∙□-i/ ap-∘ left f₁∙ (glue c) ∙ ap (ap left) (F₁∙.glue-β c) / ! (ap (ap (from ∘ to ∘ left)) (F₁∙.glue-β c)) ∙ ∘-ap (from ∘ to ∘ left) f₁∙ (glue c) /\n\n =⟨ coh3 ⟩\n\n end-lemma3 ∎ where\n\n coh2 : ∀ {i i' j} {A : Type i} {A' : Type i'} {B : Type j} (f : A → B) (f' : A' → B)\n {a b : A} {a' b' : A'} (p : a == b) {s s' : f b == f' a'} (q : s == s') (r : a' == b')\n → (↓-='-out (apd (λ x → idp) p) ∙□h (q ∙□h (↓-='-out (apd (λ _ → idp) r))))\n == (q |in-ctx (λ u → ap f p ∙ u ∙ ap f' r))\n coh2 f f' idp idp idp = idp\n\n coh3 : ∀ {i} {A : Type i} {x y : A} {a b c d e f g h : x == y} {p : a == b} {q : b == c}\n {r : c == d} {s : d == e} {t : e == f} {u : f == g} {v : g == h}\n → (s ∙□-i/ r / t / ∙□-i/ p ∙ q / u ∙ v /) == (a =⟨ p ⟩ b =⟨ q ⟩ c =⟨ r ⟩ d =⟨ s ⟩ e =⟨ t ⟩ f =⟨ u ⟩ g =⟨ v ⟩ h ∎)\n coh3 {p = idp} {idp} {idp} {idp} {idp} {idp} {idp} = idp\n\n{- Lemma 2 -}\n\n lemma2-7 =\n ↓-='-out (ap↓ (ap from) (apd (glue {d = h-v-span}) (glue c)))\n\n =⟨ from-glue-glue-β c |in-ctx ↓-='-out ⟩\n\n ↓-='-out (↓-='-in (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /)\n ◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /)\n\n =⟨ thing _ (From.glue-β (left (f₁₂ c))) _ ⟩\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) / ∎\n\n\n lemma2-6 =\n ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c)))\n\n =⟨ ap□-↓-='-out-β _ _ from (apd (glue {d = h-v-span}) (glue c)) ⟩\n\n ↓-='-out (ap↓ (ap from) (apd (glue {d = h-v-span}) (glue c)))\n ∙□-i/ ∘-ap from (right ∘ f∙₃) (glue c) / ap-∘ from (left ∘ f∙₁) (glue c) /\n\n =⟨ lemma2-7 |in-ctx (λ u → (u ∙□-i/ ∘-ap from (right ∘ f∙₃) (glue c) / ap-∘ from (left ∘ f∙₁) (glue c) /)) ⟩\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ ∘-ap from (right ∘ f∙₃) (glue c) / ap-∘ from (left ∘ f∙₁) (glue c) / ∎\n\n lemma2-5 =\n ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c))\n ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /)\n\n =⟨ ap□-∙□-i/ from _ (E₂∙Red.lhs-i c) _ ⟩\n\n ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c)))\n ∙□-i/ ap (ap from) (E₂∙Red.lhs-i c) / ap (ap from) (E₂∙Red.rhs-i c) /\n\n =⟨ lemma2-6 |in-ctx (λ u → u ∙□-i/ ap (ap from) (E₂∙Red.lhs-i c) / ap (ap from) (E₂∙Red.rhs-i c) /) ⟩\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ ∘-ap from (right ∘ f∙₃) (glue c) / ap-∘ from (left ∘ f∙₁) (glue c) /\n ∙□-i/ ap (ap from) (E₂∙Red.lhs-i c) / ap (ap from) (E₂∙Red.rhs-i c) / ∎\n\n lemma2'-1 =\n E₂∙Red.ap-ap-coh-lhs-i c from ∙ ap (ap from) (E₂∙Red.lhs-i c) ∙ ∘-ap from (right ∘ f∙₃) (glue c) ∙ E∙₂Red.lhs-o c\n\n =⟨ eq1 {f = ap from}\n {q = ! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))}\n { ! (F∙₃.glue-β c) |in-ctx (ap right)}\n {∘-ap right f∙₃ (glue c)}\n {p = E₂∙Red.ap-ap-coh-lhs-i c from}\n {∘-ap from (right ∘ f∙₃) (glue c)}\n {ap-∘ i∙₄ f∙₃ (glue c)}\n {F∙₃.glue-β c |in-ctx (ap i∙₄)}\n {ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)}\n {I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))}\n ⟩\n\n (! (ap-∙∙!'`∘`∘ from (right ∘ left) (right ∘ right) (H₁₃ c) (ap right (glue (f₂₃ c))) (H₃₃ c))\n ∙ ap (ap from) (! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))\n ∙ (ap (ap from) (! (F∙₃.glue-β c) |in-ctx (ap right))\n ∙ (ap (ap from) (∘-ap right f∙₃ (glue c))\n ∙ ∘-ap from (right ∘ f∙₃) (glue c)\n ∙ ap-∘ i∙₄ f∙₃ (glue c))\n ∙ (F∙₃.glue-β c |in-ctx (ap i∙₄)))\n ∙ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))\n\n =⟨ ap-∘^3-coh from right f∙₃ (glue c) |in-ctx (λ u →\n (! (ap-∙∙!'`∘`∘ from (right ∘ left) (right ∘ right) (H₁₃ c) (ap right (glue (f₂₃ c))) (H₃₃ c))\n ∙ ap (ap from) (! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))\n ∙ (ap (ap from) (! (F∙₃.glue-β c) |in-ctx (ap right))\n ∙ u\n ∙ (F∙₃.glue-β c |in-ctx (ap i∙₄)))\n ∙ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))))\n ⟩\n\n (! (ap-∙∙!'`∘`∘ from (right ∘ left) (right ∘ right) (H₁₃ c) (ap right (glue (f₂₃ c))) (H₃₃ c))\n ∙ ap (ap from) (! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))\n ∙ (ap (ap from) (! (F∙₃.glue-β c) |in-ctx (ap right))\n ∙ ∘-ap from right (ap f∙₃ (glue c))\n ∙ (F∙₃.glue-β c |in-ctx (ap i∙₄)))\n ∙ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))\n\n =⟨ ap-∘-ap-coh from right (F∙₃.glue-β c) |in-ctx (λ u →\n (! (ap-∙∙!'`∘`∘ from (right ∘ left) (right ∘ right) (H₁₃ c) (ap right (glue (f₂₃ c))) (H₃₃ c))\n ∙ ap (ap from) (! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))\n ∙ u\n ∙ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))) ⟩\n\n (! (ap-∙∙!'`∘`∘ from (right ∘ left) (right ∘ right) (H₁₃ c) (ap right (glue (f₂₃ c))) (H₃₃ c))\n ∙ ap (ap from) (! (ap-∙∙!`∘`∘ right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c)))\n ∙ ∘-ap from right (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c)))\n ∙ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))\n\n =⟨ ap-∘-ap-∙∙!`∘`∘-coh from right left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c) |in-ctx (λ u →\n u ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))) ⟩\n\n (∘-ap from right (glue (f₂₃ c)) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))\n ∙ (I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))))\n\n =⟨ ∙-|in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))) (∘-ap from right (glue (f₂₃ c))) (I∙₄.glue-β (f₂₃ c)) ⟩\n\n ((∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))) ∎\n\n where\n\n eq1 : ∀ {i j} {A : Type i} {B : Type j} {f : A → B} {a b c d : A}\n {q : a == b} {r : b == c} {s : c == d}\n {g h k l m n : B} {p : g == f a} {t : f d == h} {u : h == k}\n {v : k == l} {w : l == m} {x : m == n}\n → p ∙ ap f (_ =⟨ q ⟩ _ =⟨ r ⟩ _ =⟨ s ⟩ _ ∎) ∙ t\n ∙ (_ =⟨ u ⟩ _ =⟨ v ⟩ _ =⟨ w ⟩ _ =⟨ x ⟩ _ ∎)\n == (p ∙ ap f q ∙ (ap f r ∙ (ap f s ∙ t ∙ u) ∙ v) ∙ w) ∙ x\n eq1 {q = idp} {idp} {idp} {p = p} {idp} {idp} {idp} {idp} {idp} = ! (∙-unit-r (p ∙ idp))\n\n lemma2'-2 :\n E∙₂Red.rhs-o c\n ∙ ap-∘ from (left ∘ f∙₁) (glue c)\n ∙ ap (ap from) (E₂∙Red.rhs-i c)\n ∙ E₂∙Red.ap-ap-coh-rhs-i c from\n == (! (∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))\n lemma2'-2 =\n E∙₂Red.rhs-o c ∙ ap-∘ from (left ∘ f∙₁) (glue c) ∙ ap (ap from) (E₂∙Red.rhs-i c) ∙ E₂∙Red.ap-ap-coh-rhs-i c from\n\n =⟨ eq1 {f = ap from}\n {p = ! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))}\n { ! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))}\n { ! (F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u)}\n {∘-ap i∙₀ f∙₁ (glue c)}\n {ap-∘ from (left ∘ f∙₁) (glue c)}\n {ap-∘ left f∙₁ (glue c)}\n {F∙₁.glue-β c |in-ctx (ap left)}\n {ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)}\n {ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c)}\n ⟩\n\n (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ ((! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))\n ∙ ((! (F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u))\n ∙ (∘-ap i∙₀ f∙₁ (glue c)\n ∙ ap-∘ from (left ∘ f∙₁) (glue c)\n ∙ ap (ap from) (ap-∘ left f∙₁ (glue c)))\n ∙ ap (ap from) (F∙₁.glue-β c |in-ctx (ap left)))\n ∙ ap (ap from) (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))\n ∙ ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c))\n\n =⟨ ap-∘^3-coh' from left f∙₁ (glue c)\n |in-ctx (λ u → (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ ((! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))\n ∙ ((! (F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u))\n ∙ u\n ∙ ap (ap from) (F∙₁.glue-β c |in-ctx (ap left)))\n ∙ ap (ap from) (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))\n ∙ ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c))) ⟩\n\n (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ ((! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))\n ∙ ((! (F∙₁.glue-β c) |in-ctx (ap i∙₀))\n ∙ ap-∘ from left (ap f∙₁ (glue c))\n ∙ ap (ap from) (F∙₁.glue-β c |in-ctx (ap left)))\n ∙ ap (ap from) (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))\n ∙ ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c))\n\n =⟨ ap-∘-ap-coh' from left (F∙₁.glue-β c)\n |in-ctx (λ u → (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ ((! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))\n ∙ u\n ∙ ap (ap from) (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))\n ∙ ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c))) ⟩\n\n (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ ((! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)))\n ∙ ap-∘ from left (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c))\n ∙ ap (ap from) (ap-!∙∙`∘`∘ left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c))\n ∙ ap-!'∙∙`∘`∘ from (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₂₁ c))) (H₃₁ c))\n\n =⟨ ap-∘-ap-!∙∙`∘`∘-coh from left left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)\n |in-ctx (λ u → (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))) ∙ u) ⟩\n\n (! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))))\n ∙ (ap-∘ from left (glue (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)))\n\n =⟨ coh2 (glue (f₂₁ c)) (I∙₀.glue-β (f₂₁ c)) ⟩\n\n (! (∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))) ∎\n\n where\n\n eq1 : ∀ {i j} {A : Type i} {B : Type j} {f : A → B} {a b c d e : B} {k l m n : A} {o : B}\n {p : a == b} {q : b == c} {r : c == d} {s : d == e} {t : e == f k} {u : k == l}\n {v : l == m} {w : m == n} {x : f n == o}\n → (_ =⟨ p ⟩ _ =⟨ q ⟩ _ =⟨ r ⟩ _ =⟨ s ⟩ _ ∎) ∙ t ∙ ap f (_ =⟨ u ⟩ _ =⟨ v ⟩ _ =⟨ w ⟩ _ ∎) ∙ x\n == (p ∙ (q ∙ ((r ∙ (s ∙ t ∙ ap f u) ∙ ap f v) ∙ ap f w ∙ x)))\n eq1 {p = idp} {idp} {idp} {idp} {t = t} {idp} {idp} {idp} {idp} = ! (∙-unit-r (t ∙ idp)) ∙ ! (∙-unit-r ((t ∙ idp) ∙ idp))\n\n coh2 : ∀ {i j k l} {A : Type i} {B : Type j} {C : Type k} {D : Type l}\n {a a' : A} (q : a == a') {h : A → B} {g : B → C} {f : (g (h a) == g (h a')) → D} {r : g (h a) == g (h a')} (p : ap (g ∘ h) q == r)\n → ((! p) |in-ctx f) ∙ (ap-∘ g h q |in-ctx f) == (! (∘-ap g h q ∙ p) |in-ctx f)\n coh2 idp p = ∙-unit-r _\n\n lemma2-4' =\n ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c))\n ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /)\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from / E₂∙Red.ap-ap-coh-rhs-i c from /\n\n =⟨ lemma2-5 |in-ctx (λ u → u ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from / E₂∙Red.ap-ap-coh-rhs-i c from /) ⟩\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-i/ E∙₂Red.lhs-o c / E∙₂Red.rhs-o c /\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ ∘-ap from (right ∘ f∙₃) (glue c) / ap-∘ from (left ∘ f∙₁) (glue c) /\n ∙□-i/ ap (ap from) (E₂∙Red.lhs-i c) / ap (ap from) (E₂∙Red.rhs-i c) /\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from / E₂∙Red.ap-ap-coh-rhs-i c from /\n\n =⟨ assoc (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /))\n (E∙₂Red.lhs-o c) (∘-ap from (right ∘ f∙₃) (glue c)) (ap (ap from) (E₂∙Red.lhs-i c))\n (E₂∙Red.ap-ap-coh-lhs-i c from) _ _ _ _ (From.glue-β (left (f₁₂ c))) _ ⟩\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from ∙ ap (ap from) (E₂∙Red.lhs-i c) ∙ ∘-ap from (right ∘ f∙₃) (glue c) ∙ E∙₂Red.lhs-o c\n / E∙₂Red.rhs-o c ∙ ap-∘ from (left ∘ f∙₁) (glue c) ∙ ap (ap from) (E₂∙Red.rhs-i c) ∙ E₂∙Red.ap-ap-coh-rhs-i c from /\n\n =⟨ ∙□-i/-rewrite (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /) lemma2'-1 lemma2'-2 ⟩ -- rewrite\n\n E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ (∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))\n / (! (∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c)) / ∎ where\n\n assoc : ∀ {i} {A : Type i} {a b b' c : A} {u u' : a == b} {v v1 v2 v3 v4 : b == c}\n {w w1 w2 w3 w4 : a == b'} {x x' : b' == c} (α : (u , v =□ w , x))\n (p1 : v1 == v) (p2 : v2 == v1) (p3 : v3 == v2) (p4 : v4 == v3)\n (q1 : w == w1) (q2 : w1 == w2) (q3 : w2 == w3) (q4 : w3 == w4)\n (r : u' == u) (s : x == x')\n → α ∙□-i/ p1 / q1 / ∙□-o/ r / s / ∙□-i/ p2 / q2 / ∙□-i/ p3 / q3 / ∙□-i/ p4 / q4 /\n == α ∙□-o/ r / s / ∙□-i/ p4 ∙ p3 ∙ p2 ∙ p1 / q1 ∙ q2 ∙ q3 ∙ q4 /\n assoc α idp idp idp idp idp idp idp idp idp idp = idp\n\n lemma2-4'' =\n E₂∙Red.ap-ap-coh c from (ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c))\n ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /)\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from / E₂∙Red.ap-ap-coh-rhs-i c from /)\n\n =⟨ lemma2-4' |in-ctx (E₂∙Red.ap-ap-coh c from) ⟩\n\n E₂∙Red.ap-ap-coh c from (E∙₂Red.coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /)\n ∙□-o/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /\n ∙□-i/ (∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c)) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c)))\n / (! (∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c))) |in-ctx (λ u → ! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))/)\n\n =⟨ lemma (∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c)) (From.glue-β (right (f₃₂ c))) (From.glue-β (left (f₁₂ c))) (∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c))\n (↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /) ⟩\n\n ↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /\n ∙□-o/ ∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c) / ! (∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c)) /\n ∙□-i/ (From.glue-β (right (f₃₂ c))) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c))\n / (! (From.glue-β (left (f₁₂ c)))) |in-ctx (λ u → ap (left ∘ left) (H₁₁ c) ∙ u ∙ ap (left ∘ right) (H₁₃ c)) / ∎\n\n lemma2-4 =\n ap□ from (E₂∙Red.coh c (↓-='-out (apd (glue {d = h-v-span}) (glue c))\n ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /))\n\n =⟨ E₂∙Red.ap-ap-coh-β c from (↓-='-out (apd (glue {d = h-v-span}) (glue c)) ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /) ⟩\n\n E₂∙Red.ap-ap-coh c from (ap□ from (↓-='-out (apd (glue {d = h-v-span}) (glue c))\n ∙□-i/ E₂∙Red.lhs-i c / E₂∙Red.rhs-i c /)\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-i c from / E₂∙Red.ap-ap-coh-rhs-i c from /)\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-o c from / E₂∙Red.ap-ap-coh-rhs-o c from /\n\n =⟨ lemma2-4'' |in-ctx (λ u → u ∙□-i/ E₂∙Red.ap-ap-coh-lhs-o c from / E₂∙Red.ap-ap-coh-rhs-o c from /) ⟩\n\n ↓-='-out (apd (glue {d = v-h-span}) (glue c))\n ∙□-i/ E∙₂Red.lhs-i c / E∙₂Red.rhs-i c /\n ∙□-o/ ∘-ap from left (glue (f₂₁ c)) ∙ I∙₀.glue-β (f₂₁ c) / ! (∘-ap from right (glue (f₂₃ c)) ∙ I∙₄.glue-β (f₂₃ c)) /\n ∙□-i/ (From.glue-β (right (f₃₂ c))) |in-ctx (λ u → ap (right ∘ left) (H₃₁ c) ∙ u ∙ ap (right ∘ right) (H₃₃ c))\n / (! (From.glue-β (left (f₁₂ c)))) |in-ctx (λ u → ap (left ∘ left) (H₁₁ c) ∙ u ∙ ap (left ∘ right) (H₁₃ c)) /\n ∙□-i/ E₂∙Red.ap-ap-coh-lhs-o c from / E₂∙Red.ap-ap-coh-rhs-o c from / ∎\n", "meta": {"hexsha": "73d104e36ca166560ef4f48a243627a3120b501e", "size": 30205, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "homotopy/3x3/FromTo2.agda", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_issues_repo_path": "homotopy/3x3/FromTo2.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "homotopy/3x3/FromTo2.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.6504854369, "max_line_length": 205, "alphanum_fraction": 0.4286045357, "num_tokens": 16462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.359364152021239, "lm_q1q2_score": 0.18108581367045287}} {"text": "{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.\n\n Copyright (c) 2021, Oracle and/or its affiliates.\n Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl\n-}\n\nopen import LibraBFT.Base.Types\nopen import LibraBFT.Concrete.Records\nopen import LibraBFT.Concrete.System\nopen import LibraBFT.Concrete.System.Parameters\nopen import LibraBFT.Impl.Consensus.EpochManager\nimport LibraBFT.Impl.Consensus.BlockStorage.BlockStore as BlockStore\nimport LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockStore as BlockStoreProps\nimport LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock as ExecutedBlock\nimport LibraBFT.Impl.Consensus.Liveness.RoundState as RoundState\nimport LibraBFT.Impl.Consensus.Liveness.ProposerElection as ProposerElection\nimport LibraBFT.Impl.Consensus.PersistentLivenessStorage as PersistentLivenessStorage\nimport LibraBFT.Impl.Consensus.PersistentLivenessStorage.Properties as PersistentLivenessStorageProps\nopen import LibraBFT.Impl.Consensus.RoundManager\nimport LibraBFT.Impl.Consensus.SafetyRules.SafetyRules as SafetyRules\nimport LibraBFT.Impl.Consensus.SafetyRules.Properties.SafetyRules as SafetyRulesProps\nopen import LibraBFT.Impl.OBM.Logging.Logging\nopen import LibraBFT.Impl.Properties.Util\nopen import LibraBFT.ImplShared.Base.Types\nopen import LibraBFT.ImplShared.Consensus.Types\nopen import LibraBFT.ImplShared.Consensus.Types.EpochDep\nopen import LibraBFT.ImplShared.Interface.Output\nopen import LibraBFT.ImplShared.Util.Dijkstra.All\nopen import Optics.All\nopen import Util.ByteString\nopen import Util.Hash\nopen import Util.Lemmas\nopen import Util.Prelude\nopen import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms\n\nopen OutputProps\nopen Invariants\nopen RoundManagerTransProps\n\n-- This module contains properties that are only about the behavior of the handlers, nothing to do\n-- with system state\n\nmodule LibraBFT.Impl.Consensus.RoundManager.Properties where\n\nmodule executeAndVoteMSpec (vb : ValidBlock) where\n b = vbBlock vb\n\n open executeAndVoteM b\n open SafetyRulesProps\n open import LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockStore\n\n isbQc = (_≡ b ^∙ bQuorumCert)\n\n VoteResultCorrect : (pre post : RoundManager) (lvr≡? : Bool) (r : Either ErrLog Vote) → Set\n VoteResultCorrect pre post lvr≡? (Left _) =\n VoteNotGenerated pre post lvr≡? ⊎ Voting.VoteGeneratedUnsavedCorrect pre post b\n VoteResultCorrect pre post lvr≡? (Right vote) =\n Voting.VoteGeneratedCorrect pre post vote b\n\n module _ (pre : RoundManager) where\n\n open QCProps\n open Invariants.Reqs b (pre ^∙ lBlockTree)\n\n record Contract (r : Either ErrLog Vote) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General properties / invariants\n rmInv : Preserves RoundManagerInv pre post\n noEpochChange : NoEpochChange pre post\n noMsgOuts : OutputProps.NoMsgs outs\n -- Voting\n lvr≡? : Bool\n voteResultCorrect : NoHC1 → VoteResultCorrect pre post lvr≡? r\n -- QCs\n qcPost : ∈Post⇒∈PreOr isbQc pre post\n\n contract' :\n LBFT-weakestPre (executeAndVoteM b) Contract pre\n contract' =\n executeAndInsertBlockMSpec.contract vb pre Post₀\n (λ where e ._ refl → contractBail [] refl)\n contract₁\n where\n Post₀ : LBFT-Post (Either ErrLog ExecutedBlock)\n Post₀ = RWS-weakestPre-∙^∙Post unit (withErrCtx (\"\" ∷ []))\n (RWS-weakestPre-ebindPost unit step₁ Contract)\n\n contractBail : ∀ {e} outs → OutputProps.NoMsgs outs → Contract (Left e) pre outs\n contractBail{e} outs noMsgOuts =\n mkContract\n reflPreservesRoundManagerInv (reflNoEpochChange{pre})\n noMsgOuts true (const vrc)\n qcPost\n where\n vrc : VoteResultCorrect pre pre true (Left e)\n vrc = inj₁ reflVoteNotGenerated\n\n qcPost : ∈Post⇒∈PreOr isbQc pre pre\n qcPost qc = Left\n\n module EAIBM = executeAndInsertBlockMSpec vb\n module EAIBE = executeAndInsertBlockESpec (EAIBM.bs pre) vb\n module _ (isOk : EAIBE.Ok) (con : EAIBE.ContractOk (proj₁ isOk) (proj₁ (proj₂ isOk))) where\n\n module EAIBECon = EAIBE.ContractOk con\n\n bs' = proj₁ isOk\n eb = proj₁ (proj₂ isOk)\n\n pre₁ = pre & rmBlockStore ∙~ bs'\n\n -- State invariants\n module _ where\n bsP : Preserves BlockStoreInv (rm→BlockStore-EC pre) (rm→BlockStore-EC pre₁)\n bsP bsi = EAIBECon.bsInv bsi\n\n srP : Preserves SafetyRulesInv (pre ^∙ lSafetyRules) (pre₁ ^∙ lSafetyRules)\n srP = mkPreservesSafetyRulesInv id\n\n invP₁ : Preserves RoundManagerInv pre pre₁\n invP₁ = mkPreservesRoundManagerInv id id bsP srP\n\n qcPost-BT : _\n qcPost-BT = ∈Post⇒∈PreOrBT-QCs≡ isbQc\n (cong (_^∙ bsInner ∙ btHighestCommitCert) EAIBECon.bs≡x)\n (cong (_^∙ bsInner ∙ btHighestQuorumCert) EAIBECon.bs≡x)\n\n qcPost₁ : ∈Post⇒∈PreOr isbQc pre pre₁\n qcPost₁ = ∈Post⇒∈PreOr-∙-BT-RM isbQc pre pre₁ qcPost-BT\n\n -- For the case any of the checks in `step₁` fails\n contractBail₁ : ∀ {e} outs → OutputProps.NoMsgs outs → Contract (Left e) pre₁ outs\n contractBail₁ outs noMsgOuts =\n mkContract invP₁ refl\n noMsgOuts true (const $ inj₁ (mkVoteNotGenerated refl refl))\n qcPost₁\n\n contract₁ : Post₀ (Right eb) pre₁ []\n proj₁ (contract₁ ._ refl ._ refl ._ refl ._ refl ._ refl) _ = contractBail₁ [] refl\n proj₁ (proj₂ (contract₁ ._ refl ._ refl ._ refl ._ refl ._ refl) _) _ = contractBail₁ [] refl\n proj₂ (proj₂ (contract₁ ._ refl ._ refl ._ refl ._ refl ._ refl) _) _ = contract₂\n where\n maybeSignedVoteProposal' = ExecutedBlock.maybeSignedVoteProposal eb\n\n module CASV = constructAndSignVoteMSpec\n\n proposedBlock = CASV.proposedBlock maybeSignedVoteProposal'\n\n Post₂ : LBFT-Post (Either ErrLog Vote)\n Post₂ = RWS-weakestPre-ebindPost unit step₃ Contract\n\n contract₂ : RWS-weakestPre (step₂ eb) Contract unit pre₁\n\n contract₂⇒ : RWS-Post-⇒ (CASV.Contract pre₁ proposedBlock) Post₂\n contract₂⇒ r pre₃ outs con = contract₂⇒-help r CASVCon.voteResCorrect\n where\n module CASVCon = CASV.Contract con\n CASVouts = outs\n\n invP₂ = transPreservesRoundManagerInv invP₁ CASVCon.rmInv\n\n qcPost₂ : QCProps.∈Post⇒∈PreOr (_≡ b ^∙ bQuorumCert) pre pre₃\n qcPost₂ = obm-dangerous-magic' \"TODO: waiting on `constructAndSignVoteM` contract\"\n\n contract₂⇒-help :\n (r : Either ErrLog Vote) (vrc : CASV.VoteResultCorrect pre₁ pre₃ proposedBlock CASVCon.lvr≡? r)\n → RWS-weakestPre-ebindPost unit step₃ Contract r pre₃ outs\n contract₂⇒-help (Left _) vrc =\n mkContract invP₂ CASVCon.noEpochChange CASVCon.noMsgOuts\n CASVCon.lvr≡? (const ∘ Left $ (transVoteNotGenerated (mkVoteNotGenerated refl refl) vrc))\n qcPost₂\n contract₂⇒-help (Right vote) vrc ._ refl = contract₃\n where\n\n open RoundManagerInv\n open BlockStoreInv\n open BlockTreeInv\n\n contract₃ : RWS-weakestPre (step₃ vote) (RWS-Post++ Contract CASVouts) unit pre₃\n contract₃ =\n PersistentLivenessStorageProps.saveVoteMSpec.contract vote\n Post₃ pre₃\n contractBail₃ contractOk₃\n where\n Post₃ : LBFT-Post (Either ErrLog Unit)\n Post₃ = RWS-weakestPre-ebindPost unit (const $ ok vote) (RWS-Post++ Contract CASVouts)\n\n vgc₃ : NoHC1 → Voting.VoteGeneratedCorrect pre pre₃ vote b {- proposedBlock -}\n vgc₃ nohc =\n Voting.glue-VoteNotGenerated-VoteGeneratedCorrect\n (mkVoteNotGenerated refl refl)\n (Voting.substVoteGeneratedCorrect proposedBlock b\n (EAIBECon.ebBlock≈ nohc)\n vrc)\n\n noMsgOutsBail₃ : ∀ outs → NoMsgs outs → NoMsgs (CASVouts ++ outs)\n noMsgOutsBail₃ outs noMsgs = ++-NoMsgs CASVouts outs CASVCon.noMsgOuts noMsgs\n\n noMsgOutsOk₃ : ∀ outs → NoMsgs outs → NoMsgs (CASVouts ++ outs ++ [])\n noMsgOutsOk₃ outs noMsgs rewrite ++-identityʳ outs = noMsgOutsBail₃ outs noMsgs\n\n contractBail₃ : ∀ outs → NoMsgs outs → NoErrors outs → Post₃ (Left fakeErr) pre₃ outs\n contractBail₃ outs noMsgOuts noErrOuts =\n mkContract invP₂ CASVCon.noEpochChange (noMsgOutsBail₃ outs noMsgOuts)\n CASVCon.lvr≡? ((Right ∘ Voting.mkVoteGeneratedUnsavedCorrect vote) ∘ vgc₃)\n qcPost₂\n\n contractOk₃ : ∀ outs → NoMsgs outs → NoErrors outs → Post₃ (Right unit) pre₃ outs\n contractOk₃ outs noMsgs noErrs unit refl =\n mkContract invP₂ CASVCon.noEpochChange (noMsgOutsOk₃ outs noMsgs)\n CASVCon.lvr≡? vgc₃ qcPost₂\n\n contract₂ = constructAndSignVoteMSpec.contract maybeSignedVoteProposal' pre₁ Post₂ contract₂⇒\n\n contract\n : ∀ Post\n → RWS-Post-⇒ Contract Post\n → LBFT-weakestPre (executeAndVoteM b) Post pre\n contract Post pf =\n RWS-⇒ (executeAndVoteM b) unit pre contract' pf\n\nmodule processProposalMSpec (vproposal : ValidBlock) where\n proposal = vbBlock vproposal\n\n open import LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockStore\n open import LibraBFT.Impl.Consensus.Liveness.Properties.ProposerElection\n open LibraBFT.Impl.Consensus.RoundManager.processProposalM proposal\n\n module _ (pre : RoundManager) where\n\n open Invariants.Reqs (vbBlock vproposal) (pre ^∙ lBlockTree)\n\n record Contract (u : Unit) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General properties / invariants\n rmInv : Preserves RoundManagerInv pre post\n noEpochChange : NoEpochChange pre post\n noProposals : OutputProps.NoProposals outs\n -- Voting\n voteAttemptCorrect : NoHC1 → Voting.VoteAttemptCorrect pre post outs proposal\n -- QCs\n outQcs∈RM : QCProps.OutputQc∈RoundManager outs post\n qcPost : QCProps.∈Post⇒∈PreOr (_≡ proposal ^∙ bQuorumCert) pre post\n\n contract' : LBFT-weakestPre (processProposalM proposal) Contract pre\n contract' ._ refl =\n isValidProposalMSpec.contract proposal pre\n (RWS-weakestPre-bindPost unit (step₁ (pre ^∙ lBlockStore)) Contract)\n (λ where\n mAuthor≡nothing ._ refl → (λ _ → contractBail refl) , (λ where ()))\n (λ where\n notValid ._ refl → (λ _ → contractBail refl) , (λ where ()))\n λ where\n vp ._ refl →\n (λ where ())\n , (λ _ →\n (λ _ → contractBail refl)\n , (λ _ →\n (λ _ → contractBail refl)\n , (λ _ → contract-step₂)))\n where\n contractBail : ∀ {outs} → OutputProps.NoMsgs outs → Contract unit pre outs\n contractBail{outs} nmo =\n mkContract reflPreservesRoundManagerInv (reflNoEpochChange{pre})\n noProposals vac outQcs qcPost\n where\n noProposals : NoProposals outs\n noProposals = OutputProps.NoMsgs⇒NoProposals outs nmo\n\n vac : NoHC1 → Voting.VoteAttemptCorrect pre pre outs proposal\n vac _ = Voting.voteAttemptBailed outs (OutputProps.NoMsgs⇒NoVotes outs nmo)\n\n outQcs : QCProps.OutputQc∈RoundManager outs pre\n outQcs = QCProps.NoMsgs⇒OutputQc∈RoundManager outs pre nmo\n\n qcPost : QCProps.∈Post⇒∈PreOr _ pre pre\n qcPost qc = Left\n\n contract-step₂ : RWS-weakestPre (executeAndVoteM proposal >>= step₂) Contract unit pre\n contract-step₂ =\n executeAndVoteMSpec.contract vproposal pre\n (RWS-weakestPre-bindPost unit step₂ Contract) pf-step₂\n where\n module EAV = executeAndVoteMSpec vproposal\n\n pf-step₂ : RWS-Post-⇒ (EAV.Contract pre) (RWS-weakestPre-bindPost unit step₂ Contract)\n pf-step₂ r st outs con = pf r EAVSpec.voteResultCorrect\n where\n module EAVSpec = executeAndVoteMSpec.Contract con\n rmInv₂ = transPreservesRoundManagerInv reflPreservesRoundManagerInv EAVSpec.rmInv\n\n pf : (r : Either ErrLog Vote) (vrc : NoHC1 → EAV.VoteResultCorrect pre st EAVSpec.lvr≡? r)\n → RWS-weakestPre-bindPost unit step₂ Contract r st outs\n pf (Left _) vrc ._ refl =\n mkContract rmInv₂ EAVSpec.noEpochChange\n noProposals\n vac\n qcOuts EAVSpec.qcPost\n where\n noMsgs : NoMsgs (outs ++ LogErr _ ∷ [])\n noMsgs = ++-NoMsgs outs (LogErr _ ∷ []) EAVSpec.noMsgOuts refl\n\n noProposals : NoProposals (outs ++ LogErr _ ∷ [])\n noProposals = NoMsgs⇒NoProposals (outs ++ LogErr _ ∷ []) noMsgs\n\n vac : NoHC1 → Voting.VoteAttemptCorrect pre st (outs ++ LogErr _ ∷ []) proposal\n vac nohc =\n inj₁ (EAVSpec.lvr≡?\n , Voting.mkVoteUnsentCorrect\n (NoMsgs⇒NoVotes (outs ++ LogErr _ ∷ []) noMsgs) (vrc nohc))\n\n qcOuts : QCProps.OutputQc∈RoundManager (outs ++ LogErr _ ∷ []) st\n qcOuts = QCProps.NoMsgs⇒OutputQc∈RoundManager (outs ++ LogErr _ ∷ []) st noMsgs\n\n pf (Right vote) vrc ._ refl ._ refl ._ refl =\n syncInfoMSpec.contract (st & rsVoteSent-rm ?~ vote)\n (RWS-weakestPre-bindPost unit (step₃ vote) (RWS-Post++ Contract outs))\n contract-step₃\n where\n stUpdateRS = st & rsVoteSent-rm ?~ vote\n\n module _\n (si : SyncInfo)\n (si≡ : si ≡ SyncInfo∙new\n (st ^∙ lBlockStore ∙ bsHighestQuorumCert)\n (st ^∙ lBlockStore ∙ bsHighestCommitCert)\n (st ^∙ lBlockStore ∙ bsHighestTimeoutCert))\n where\n contract-step₃ : RWS-weakestPre (step₃ vote si) (RWS-Post++ Contract outs) unit stUpdateRS\n contract-step₃ ._ refl ._ refl ._ refl ._ refl recipient@._ refl =\n mkContract rmInv₃\n (transNoEpochChange{i = pre}{j = st}{k = stUpdateRS} EAVSpec.noEpochChange refl)\n (OutputProps.++-NoProposals outs _ (OutputProps.NoMsgs⇒NoProposals outs EAVSpec.noMsgOuts) refl)\n vac\n outQcs qcPost\n where\n vm = VoteMsg∙new vote si\n\n vac : NoHC1 → Voting.VoteAttemptCorrect pre stUpdateRS (outs ++ SendVote vm _ ∷ []) proposal\n vac nohc =\n inj₂ (Voting.mkVoteSentCorrect vm recipient\n (OutputProps.++-NoVotes-OneVote outs _ (OutputProps.NoMsgs⇒NoVotes outs EAVSpec.noMsgOuts) refl)\n (Voting.glue-VoteGeneratedCorrect-VoteNotGenerated{s₂ = st}\n (vrc nohc) (mkVoteNotGenerated refl refl)))\n\n outQcs : QCProps.OutputQc∈RoundManager (outs ++ SendVote vm _ ∷ []) stUpdateRS\n outQcs =\n QCProps.++-OutputQc∈RoundManager{stUpdateRS}{outs}\n (QCProps.NoMsgs⇒OutputQc∈RoundManager outs stUpdateRS EAVSpec.noMsgOuts)\n (outQcSendVote ∷ [])\n where\n outQcSendVote : ∀ qc nm → qc QC∈NM nm → nm Msg∈Out (SendVote vm _) → qc QCProps.∈RoundManager stUpdateRS\n outQcSendVote qc .(V (VoteMsg∙new vote si)) (inSI inV (withVoteSIHighQC qc≡)) inSV rewrite si≡ =\n QCProps.inHQC (sym qc≡)\n outQcSendVote qc .(V (VoteMsg∙new vote si)) (inSI inV (withVoteSIHighCC qc≡)) inSV =\n QCProps.inHCC (just-injective $\n begin\n just qc ≡⟨ lem₁ ⟩\n sixxx ≡⟨ lem₂ (cong is-just (sym lem₁)) ⟩\n just (stUpdateRS ^∙ lBlockStore ∙ bsInner ∙ btHighestCommitCert) ∎)\n where\n open ≡-Reasoning\n sixxx = if (st ^∙ lBlockStore ∙ bsHighestQuorumCert) QCBoolEq (st ^∙ lBlockStore ∙ bsHighestCommitCert)\n then nothing\n else (just $ (st ^∙ lBlockStore ∙ bsHighestCommitCert))\n\n lem₁ : just qc ≡ sixxx\n lem₁ = begin\n just qc ≡⟨ sym qc≡ ⟩\n vm ^∙ vmSyncInfo ∙ sixxxHighestCommitCert ≡⟨ cong (_^∙ sixxxHighestCommitCert) si≡ ⟩\n sixxx ∎\n\n lem₂ : is-just sixxx ≡ true\n → sixxx ≡ just (stUpdateRS ^∙ lBlockStore ∙ bsInner ∙ btHighestCommitCert)\n lem₂ isj\n with (st ^∙ lBlockStore ∙ bsHighestQuorumCert) QCBoolEq (st ^∙ lBlockStore ∙ bsHighestCommitCert)\n ... | false = refl\n ... | true = absurd false ≡ true case isj of λ ()\n\n qcPost : QCProps.∈Post⇒∈PreOr (_≡ proposal ^∙ bQuorumCert) pre stUpdateRS\n qcPost qc qc∈stUpdateRS = EAVSpec.qcPost qc (qc∈st qc∈stUpdateRS)\n where\n qc∈st : qc QCProps.∈RoundManager stUpdateRS → qc QCProps.∈RoundManager st\n qc∈st (QCProps.inHQC qc≡) = QCProps.inHQC qc≡\n qc∈st (QCProps.inHCC qc≡) = QCProps.inHCC qc≡\n\n -- state invariants\n module _ where\n bsP : Preserves BlockStoreInv (rm→BlockStore-EC st) (rm→BlockStore-EC stUpdateRS)\n bsP = id\n\n srP : Preserves SafetyRulesInv (st ^∙ lSafetyRules) (stUpdateRS ^∙ lSafetyRules)\n srP = mkPreservesSafetyRulesInv id\n\n rmInv₃ : Preserves RoundManagerInv pre stUpdateRS\n rmInv₃ = transPreservesRoundManagerInv rmInv₂\n (mkPreservesRoundManagerInv id id bsP srP)\n\n contract : ∀ Post → RWS-Post-⇒ Contract Post → LBFT-weakestPre (processProposalM proposal) Post pre\n contract Post pf = LBFT-⇒ (processProposalM proposal) pre contract' pf\n\nmodule syncUpMSpec\n (now : Instant) (syncInfo : SyncInfo) (author : Author) (_helpRemote : Bool) where\n\n open syncUpM now syncInfo author _helpRemote\n open import LibraBFT.Impl.Consensus.ConsensusTypes.Properties.SyncInfo\n open import LibraBFT.Impl.Consensus.BlockStorage.Properties.SyncManager\n\n module _ (pre : RoundManager) where\n\n record Contract (r : Either ErrLog Unit) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General invariants / properties\n rmInv : Preserves RoundManagerInv pre post\n dnmBtIdToBlk : post ≡L pre at (lBlockTree ∙ btIdToBlock)\n noEpochChange : NoEpochChange pre post\n noVoteOuts : OutputProps.NoVotes outs\n -- Voting\n noVote : VoteNotGenerated pre post true\n -- QCs\n noOutQcs : QCProps.¬OutputQc outs\n qcPost : QCProps.∈Post⇒∈PreOr (_QC∈SyncInfo syncInfo) pre post\n\n contract' : LBFT-weakestPre (syncUpM now syncInfo author _helpRemote) Contract pre\n contract' =\n BlockStoreProps.syncInfoMSpec.contract pre\n (RWS-weakestPre-bindPost unit step₁ Contract)\n contract₁\n where\n localSyncInfo = BlockStoreProps.syncInfoMSpec.syncInfo pre\n\n contract₁ : RWS-weakestPre-bindPost unit step₁ Contract (BlockStoreProps.syncInfoMSpec.syncInfo pre) pre []\n proj₂ (contract₁ localSyncInfo lsi≡) hnc≡false =\n mkContract reflPreservesRoundManagerInv refl (reflNoEpochChange{pre}) refl\n (reflVoteNotGenerated{pre})\n [] qcPost\n where\n outQcs : QCProps.OutputQc∈RoundManager [] pre\n outQcs = QCProps.NoMsgs⇒OutputQc∈RoundManager [] pre refl\n\n qcPost : QCProps.∈Post⇒∈PreOr _ pre pre\n qcPost qc = Left\n proj₁ (contract₁ localSyncInfo lsi≡) hcn≡true vv@._ refl =\n verifyMSpec.contract syncInfo vv pre Post₁\n contract₃\n where\n Post₁ : LBFT-Post (Either ErrLog Unit)\n Post₁ = (RWS-weakestPre-∙^∙Post unit (withErrCtx (here' []))\n (RWS-weakestPre-ebindPost unit (λ _ → step₃ localSyncInfo vv) Contract))\n\n contract₃ : RWS-Post-⇒ (verifyMSpec.Contract syncInfo vv pre) Post₁\n contract₃ r st outs con ._ refl\n with VSpec.noStateChange\n where module VSpec = verifyMSpec.Contract con\n contract₃ (Left x) st outs con ._ refl\n | refl\n = mkContract VSpec.rmInv (cong (_^∙ lBlockTree ∙ btIdToBlock) VSpec.noStateChange) (reflNoEpochChange{st})\n (++-NoVotes outs [] (NoMsgs⇒NoVotes outs VSpec.noMsgOuts) refl)\n (reflVoteNotGenerated{st})\n noOutQcs qcPost\n where\n module VSpec = verifyMSpec.Contract con\n noOutQcs : QCProps.¬OutputQc (outs ++ [])\n noOutQcs = QCProps.++-¬OutputQc (QCProps.NoMsgs⇒¬OutputQc outs VSpec.noMsgOuts) []\n\n qcPost : QCProps.∈Post⇒∈PreOr _ st st\n qcPost qc = Left\n contract₃ (Right y) st₃ outs₃ con₃ ._ refl\n | refl = λ where\n unit refl →\n addCertsMSpec.contract syncInfo retriever st₃\n Post₃ contract₄\n where\n Post₃ : LBFT-Post (Either ErrLog Unit)\n Post₃ = (RWS-weakestPre-∙^∙Post unit (withErrCtx (here' []))\n (RWS-weakestPre-ebindPost unit (λ _ → step₄ localSyncInfo vv)\n (RWS-Post++ Contract (outs₃ ++ []))))\n\n retriever = BlockRetriever∙new now author\n\n contract₄ : RWS-Post-⇒ (addCertsMSpec.Contract syncInfo retriever st₃) Post₃\n contract₄ (Left _) st₄ outs₄ con₄ ._ refl =\n mkContract AC.rmInv AC.dnmBtIdToBlk AC.noEpochChange noVotes₄ AC.noVote noOutQcs AC.qcPost\n where\n module AC = addCertsMSpec.Contract con₄\n module VSpec = verifyMSpec.Contract con₃\n\n noVotes₄ : NoVotes $ (outs₃ ++ []) ++ outs₄ ++ []\n noVotes₄ =\n ++-NoVotes (outs₃ ++ []) (outs₄ ++ [])\n (++-NoVotes outs₃ [] (NoMsgs⇒NoVotes outs₃ VSpec.noMsgOuts) refl)\n (++-NoVotes outs₄ [] AC.noVoteOuts refl)\n\n noOutQcs : QCProps.¬OutputQc ((outs₃ ++ []) ++ outs₄ ++ [])\n noOutQcs =\n QCProps.++-¬OutputQc\n (QCProps.++-¬OutputQc\n (QCProps.NoMsgs⇒¬OutputQc outs₃ VSpec.noMsgOuts)\n (QCProps.NoMsgs⇒¬OutputQc [] refl))\n (QCProps.++-¬OutputQc\n AC.noOutQc (QCProps.NoMsgs⇒¬OutputQc [] refl))\n\n contract₄ (Right _) st₄ outs₄ con₄ ._ refl =\n obm-dangerous-magic' \"TODO: waiting on contract for `processCertificatesM`\"\n\n contract\n : ∀ Post → RWS-Post-⇒ Contract Post\n → LBFT-weakestPre (syncUpM now syncInfo author _helpRemote) Post pre\n contract Post pf =\n LBFT-⇒ (syncUpM now syncInfo author _helpRemote) pre\n contract' pf\n\nmodule ensureRoundAndSyncUpMSpec\n (now : Instant) (messageRound : Round) (syncInfo : SyncInfo)\n (author : Author) (helpRemote : Bool) where\n\n open ensureRoundAndSyncUpM now messageRound syncInfo author helpRemote\n\n module _ (pre : RoundManager) where\n\n record Contract (r : Either ErrLog Bool) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General invariants / properties\n rmInv : Preserves RoundManagerInv pre post\n dnmBtIdToBlk : post ≡L pre at (lBlockTree ∙ btIdToBlock)\n noEpochChange : NoEpochChange pre post\n noVoteOuts : OutputProps.NoVotes outs\n -- Voting\n noVote : VoteNotGenerated pre post true\n -- Signatures\n noOutQcs : QCProps.¬OutputQc outs\n qcPost : QCProps.∈Post⇒∈PreOr (_QC∈SyncInfo syncInfo) pre post\n\n contract'\n : LBFT-weakestPre (ensureRoundAndSyncUpM now messageRound syncInfo author helpRemote) Contract pre\n proj₁ (contract' ._ refl) _ =\n mkContract id refl refl refl vng outqcs qcPost\n where\n vng : VoteNotGenerated pre pre true\n vng = mkVoteNotGenerated refl refl\n\n outqcs : QCProps.¬OutputQc []\n outqcs = []\n\n qcPost : QCProps.∈Post⇒∈PreOr _ pre pre\n qcPost qc = Left\n\n proj₂ (contract' ._ refl) mrnd≥crnd = contract-step₁\n where\n contract-step₁ : LBFT-weakestPre step₁ Contract pre\n contract-step₁ = syncUpMSpec.contract now syncInfo author helpRemote pre Post contract-step₁'\n where\n Post = RWS-weakestPre-ebindPost unit (const step₂) Contract\n\n contract-step₁' : _\n contract-step₁' (Left _ ) st outs con =\n mkContract SU.rmInv SU.dnmBtIdToBlk SU.noEpochChange SU.noVoteOuts SU.noVote SU.noOutQcs SU.qcPost\n where\n module SU = syncUpMSpec.Contract con\n contract-step₁' (Right unit) st outs con = contract-step₂\n where\n module SU = syncUpMSpec.Contract con\n\n noVoteOuts' : NoVotes (outs ++ [])\n noVoteOuts' = ++-NoVotes outs [] SU.noVoteOuts refl\n\n noOutQcs : QCProps.¬OutputQc (outs ++ [])\n noOutQcs =\n QCProps.++-¬OutputQc SU.noOutQcs []\n\n contract-step₂ : Post (Right unit) st outs\n proj₁ (contract-step₂ ._ refl ._ refl) _ =\n mkContract SU.rmInv SU.dnmBtIdToBlk SU.noEpochChange noVoteOuts' SU.noVote\n noOutQcs SU.qcPost\n proj₂ (contract-step₂ ._ refl ._ refl) _ =\n mkContract SU.rmInv SU.dnmBtIdToBlk SU.noEpochChange noVoteOuts' SU.noVote\n noOutQcs SU.qcPost\n\n contract : ∀ Post → RWS-Post-⇒ Contract Post → LBFT-weakestPre (ensureRoundAndSyncUpM now messageRound syncInfo author helpRemote) Post pre\n contract Post pf =\n LBFT-⇒ (ensureRoundAndSyncUpM now messageRound syncInfo author helpRemote) pre contract' pf\n\nmodule processProposalMsgMSpec\n (now : Instant) (pm : ProposalMsg) (vproposal : BlockId-correct (pm ^∙ pmProposal)) where\n\n proposal = pm ^∙ pmProposal\n open processProposalMsgM now pm\n\n module _ (pre : RoundManager) where\n\n open Invariants.Reqs proposal (pre ^∙ lBlockTree)\n\n record Contract (_ : Unit) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General invariants / properties\n rmInv : Preserves RoundManagerInv pre post\n noEpochChange : NoEpochChange pre post\n -- Voting\n voteAttemptCorrect : NoHC1 → Voting.VoteAttemptCorrect pre post outs proposal\n -- QCs\n outQcs∈RM : QCProps.OutputQc∈RoundManager outs post\n qcPost : QCProps.∈Post⇒∈PreOr (_QC∈NM (P pm)) pre post\n\n contract' : LBFT-weakestPre (processProposalMsgM now pm) Contract pre\n contract' rewrite processProposalMsgM≡ = contract\n where\n contractBail : ∀ outs → OutputProps.NoMsgs outs → Contract unit pre outs\n contractBail outs nmo =\n mkContract reflPreservesRoundManagerInv (reflNoEpochChange{pre}) vac outqcs qcPost\n where\n vac : NoHC1 → Voting.VoteAttemptCorrect pre pre outs proposal\n vac _ = Voting.voteAttemptBailed outs (OutputProps.NoMsgs⇒NoVotes outs nmo)\n\n outqcs : QCProps.OutputQc∈RoundManager outs pre\n outqcs = QCProps.NoMsgs⇒OutputQc∈RoundManager outs pre nmo\n\n qcPost : QCProps.∈Post⇒∈PreOr _ pre pre\n qcPost qc = Left\n\n contract : LBFT-weakestPre step₀ Contract pre\n proj₁ contract ≡nothing = contractBail _ refl\n proj₂ contract = contract-step₁\n where\n -- These arguments come from the second proof obligation of RWS-weakestPre for RWS-maybe\n module _ (pAuthor : Author) (pAuthor≡ : pm ^∙ pmProposer ≡ just pAuthor) where\n pf-step₂ : RWS-Post-⇒ _ (RWS-weakestPre-bindPost unit step₂ Contract)\n\n contract-step₁ : LBFT-weakestPre (step₁ pAuthor) Contract pre\n contract-step₁ =\n ensureRoundAndSyncUpMSpec.contract now (pm ^∙ pmProposal ∙ bRound) (pm ^∙ pmSyncInfo) pAuthor true pre\n (RWS-weakestPre-bindPost unit step₂ Contract)\n pf-step₂\n\n pf-step₂ r st outs con = pf-step₂' r\n where\n module ERASU = ensureRoundAndSyncUpMSpec.Contract con\n contractBailAfterSync : ∀ outs' → OutputProps.NoMsgs outs' → RWS-Post++ Contract outs unit st outs'\n contractBailAfterSync outs' noMsgs' =\n mkContract ERASU.rmInv ERASU.noEpochChange vac outqcs qcPost\n where\n vac : NoHC1 → Voting.VoteAttemptCorrect pre st (outs ++ outs') proposal\n vac _ = Left (true , (Voting.mkVoteUnsentCorrect\n (OutputProps.++-NoVotes outs _ ERASU.noVoteOuts (OutputProps.NoMsgs⇒NoVotes outs' noMsgs'))\n (Left ERASU.noVote)))\n\n outqcs : QCProps.OutputQc∈RoundManager (outs ++ outs') st\n outqcs =\n QCProps.¬OutputQc⇒OutputQc∈RoundManager (outs ++ outs') st\n (QCProps.++-¬OutputQc ERASU.noOutQcs\n (QCProps.NoMsgs⇒¬OutputQc outs' noMsgs'))\n\n qcPost : QCProps.∈Post⇒∈PreOr (_QC∈NM (P pm)) pre st\n qcPost qc qc∈st\n with ERASU.qcPost qc qc∈st\n ... | Left qc∈pre = Left qc∈pre\n ... | Right qc∈si = Right (inSI inP qc∈si)\n\n pf-step₂' : (r : Either ErrLog Bool) → RWS-weakestPre-bindPost unit step₂ Contract r st outs\n pf-step₂' (Left e) ._ refl =\n contractBailAfterSync _ refl\n pf-step₂' (Right false) ._ refl ._ refl =\n contractBailAfterSync _ refl\n pf-step₂' (Right true) ._ refl =\n processProposalMSpec.contract (proposal , vproposal)\n st\n (RWS-Post++ Contract outs)\n pf-step₃\n where\n\n pf-step₃ : RWS-Post-⇒\n (processProposalMSpec.Contract (proposal , vproposal) _)\n (RWS-Post++ Contract outs)\n pf-step₃ unit st' outs' con =\n mkContract\n (transPreservesRoundManagerInv ERASU.rmInv (PP.rmInv con))\n (transNoEpochChange{i = pre}{j = st}{k = st'} ERASU.noEpochChange (PP.noEpochChange con))\n vac outqcs qcPost\n where\n module PP = processProposalMSpec.Contract\n vac : NoHC1 → Voting.VoteAttemptCorrect pre st' (outs ++ outs') proposal\n vac nohc rewrite sym ERASU.dnmBtIdToBlk =\n Voting.glue-VoteNotGenerated-VoteAttemptCorrect{outs₁ = outs}\n ERASU.noVote ERASU.noVoteOuts (PP.voteAttemptCorrect con nohc)\n\n outqcs : QCProps.OutputQc∈RoundManager (outs ++ outs') st'\n outqcs =\n QCProps.++-OutputQc∈RoundManager {rm = st'}\n (QCProps.¬OutputQc⇒OutputQc∈RoundManager outs st' ERASU.noOutQcs)\n (PP.outQcs∈RM con)\n\n qcPost : QCProps.∈Post⇒∈PreOr (_QC∈NM (P pm)) pre st'\n qcPost qc qc∈st'\n with PP.qcPost con qc qc∈st'\n ...| Right refl = Right inP\n ...| Left qc∈st\n with ERASU.qcPost qc qc∈st\n ... | Right qc∈si = Right (inSI inP qc∈si)\n ... | Left qc∈pre = Left qc∈pre\n\n contract : ∀ Post → RWS-Post-⇒ Contract Post → LBFT-weakestPre (processProposalMsgM now pm) Post pre\n contract Post pf =\n LBFT-⇒ (processProposalMsgM now pm) pre contract' pf\n\n\nmodule startSpec\n (now : Instant)\n (lastVoteSent : Maybe Vote)\n where\n\n module _ (pre : RoundManager)\n (rmi : RoundManagerInv pre) -- preconditions needed to prove contract\n where\n\n open InitProofDefs\n\n open start now lastVoteSent\n\n Contract : LBFT-Post Unit\n Contract _ post outs = ∃[ e ] (find' logErrMB outs ≡ just e)\n ⊎ find' logErrMB outs ≡ nothing × InitContractOk lastVoteSent post outs\n\n syncInfo = SyncInfo∙new (pre ^∙ (lBlockStore ∙ bsHighestQuorumCert))\n (pre ^∙ (lBlockStore ∙ bsHighestCommitCert))\n (pre ^∙ (lBlockStore ∙ bsHighestTimeoutCert))\n\n postulate\n contract-step₁ : LBFT-weakestPre (step₁-abs syncInfo) Contract pre\n\n contract' : LBFT-weakestPre (start-abs now lastVoteSent) Contract pre\n -- These are due to the various binds arising from syncInfoM, which is not abstract\n -- because it's more trouble than it's worth\n contract' rewrite start-abs-≡ =\n λ where ._ refl ._ refl ._ refl ._ refl ._ refl ._ refl si refl → contract-step₁\n", "meta": {"hexsha": "f0b5914464169077d1f1ace7171de7057a7b34a5", "size": 33249, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager/Properties.agda", "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": ["UPL-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager/Properties.agda", "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_licenses": ["UPL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager/Properties.agda", "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": ["UPL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.9918809202, "max_line_length": 143, "alphanum_fraction": 0.6143041896, "num_tokens": 9300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.577495350642608, "lm_q2_score": 0.3106943895971202, "lm_q1q2_score": 0.17942456546308}} {"text": "open import Data.Product using ( _×_ ; _,_ )\nopen import Data.Sum using ( inj₁ ; inj₂ )\nopen import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )\nopen import Relation.Unary using ( _∈_ ; _⊆_ )\nopen import Web.Semantic.DL.ABox using\n ( ABox ; Assertions ; ⟨ABox⟩ ; ε ; _,_ ; _∼_ ; _∈₁_ ; _∈₂_ )\nopen import Web.Semantic.DL.ABox.Interp using ( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ )\nopen import Web.Semantic.DL.ABox.Interp.Morphism using\n ( _≲_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ; ≡³-impl-≲ )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox.Interp using\n ( Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans ; con ; rol ; con-≈ ; rol-≈ )\nopen import Web.Semantic.DL.TBox.Interp.Morphism using\n ( ≲-image ; ≲-resp-≈ ; ≲-resp-con ; ≲-resp-rol ; ≲-refl )\nopen import Web.Semantic.Util using\n ( True ; tt ; id ; _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; →-dist-⊕ )\n\nmodule Web.Semantic.DL.ABox.Model {Σ : Signature} where\n\ninfix 2 _⊨a_ _⊨b_\ninfixr 5 _,_\n\n_⟦_⟧₀ : ∀ {X} (I : Interp Σ X) → X → (Δ ⌊ I ⌋)\nI ⟦ x ⟧₀ = ind I x\n\n_⊨a_ : ∀ {X} → Interp Σ X → ABox Σ X → Set\nI ⊨a ε = True\nI ⊨a (A , B) = (I ⊨a A) × (I ⊨a B)\nI ⊨a x ∼ y = ⌊ I ⌋ ⊨ ind I x ≈ ind I y\nI ⊨a x ∈₁ c = ind I x ∈ con ⌊ I ⌋ c\nI ⊨a (x , y) ∈₂ r = (ind I x , ind I y) ∈ rol ⌊ I ⌋ r\n\nAssertions✓ : ∀ {X} (I : Interp Σ X) A {a} → \n (a ∈ Assertions A) → (I ⊨a A) → (I ⊨a a)\nAssertions✓ I ε () I⊨A\nAssertions✓ I (A , B) (inj₁ a∈A) (I⊨A , I⊨B) = Assertions✓ I A a∈A I⊨A\nAssertions✓ I (A , B) (inj₂ a∈B) (I⊨A , I⊨B) = Assertions✓ I B a∈B I⊨B\nAssertions✓ I (i ∼ j) refl I⊨A = I⊨A\nAssertions✓ I (i ∈₁ c) refl I⊨A = I⊨A\nAssertions✓ I (ij ∈₂ r) refl I⊨A = I⊨A\n\n⊨a-resp-⊇ : ∀ {X} (I : Interp Σ X) A B → \n (Assertions A ⊆ Assertions B) → (I ⊨a B) → (I ⊨a A)\n⊨a-resp-⊇ I ε B A⊆B I⊨B = tt\n⊨a-resp-⊇ I (A₁ , A₂) B A⊆B I⊨B = \n ( ⊨a-resp-⊇ I A₁ B (A⊆B ∘ inj₁) I⊨B\n , ⊨a-resp-⊇ I A₂ B (A⊆B ∘ inj₂) I⊨B )\n⊨a-resp-⊇ I (x ∼ y) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B\n⊨a-resp-⊇ I (x ∈₁ c) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B\n⊨a-resp-⊇ I (xy ∈₂ r) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B\n\n⊨a-resp-≲ : ∀ {X} {I J : Interp Σ X} → (I ≲ J) → ∀ A → (I ⊨a A) → (J ⊨a A)\n⊨a-resp-≲ {X} {I} {J} I≲J ε I⊨A = \n tt\n⊨a-resp-≲ {X} {I} {J} I≲J (A , B) (I⊨A , I⊨B) = \n (⊨a-resp-≲ I≲J A I⊨A , ⊨a-resp-≲ I≲J B I⊨B)\n⊨a-resp-≲ {X} {I} {J} I≲J (x ∼ y) I⊨x∼y = \n ≈-trans ⌊ J ⌋ (≈-sym ⌊ J ⌋ (≲-resp-ind I≲J x)) \n (≈-trans ⌊ J ⌋ (≲-resp-≈ ≲⌊ I≲J ⌋ I⊨x∼y) \n (≲-resp-ind I≲J y))\n⊨a-resp-≲ {X} {I} {J} I≲J (x ∈₁ c) I⊨x∈c = \n con-≈ ⌊ J ⌋ c (≲-resp-con ≲⌊ I≲J ⌋ I⊨x∈c) (≲-resp-ind I≲J x)\n⊨a-resp-≲ {X} {I} {J} I≲J ((x , y) ∈₂ r) I⊨xy∈r = \n rol-≈ ⌊ J ⌋ r (≈-sym ⌊ J ⌋ (≲-resp-ind I≲J x)) \n (≲-resp-rol ≲⌊ I≲J ⌋ I⊨xy∈r) (≲-resp-ind I≲J y)\n\n⊨a-resp-≡ : ∀ {X : Set} (I : Interp Σ X) j →\n (ind I ≡ j) → ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a A)\n⊨a-resp-≡ (I , i) .i refl A I⊨A = I⊨A\n\n⊨a-resp-≡³ : ∀ {V X Y : Set} (I : Interp Σ (X ⊕ V ⊕ Y)) j →\n (→-dist-⊕ (ind I) ≡ →-dist-⊕ j) → ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a A)\n⊨a-resp-≡³ I j i≡j = ⊨a-resp-≲ (≡³-impl-≲ I j i≡j) \n\n⟨ABox⟩-Assertions : ∀ {X Y a} (f : X → Y) (A : ABox Σ X) → \n (a ∈ Assertions A) → (⟨ABox⟩ f a ∈ Assertions (⟨ABox⟩ f A))\n⟨ABox⟩-Assertions f ε ()\n⟨ABox⟩-Assertions f (A , B) (inj₁ a∈A) = inj₁ (⟨ABox⟩-Assertions f A a∈A)\n⟨ABox⟩-Assertions f (A , B) (inj₂ a∈B) = inj₂ (⟨ABox⟩-Assertions f B a∈B)\n⟨ABox⟩-Assertions f (x ∼ y) refl = refl\n⟨ABox⟩-Assertions f (x ∈₁ c) refl = refl\n⟨ABox⟩-Assertions f ((x , y) ∈₂ r) refl = refl\n\n⟨ABox⟩-resp-⊨ : ∀ {X Y} {I : Interp Σ X} {j : Y → Δ ⌊ I ⌋} \n (f : X → Y) → (∀ x → ⌊ I ⌋ ⊨ ind I x ≈ j (f x)) →\n ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a ⟨ABox⟩ f A)\n⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f ε I⊨ε = \n tt\n⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (A , B) (I⊨A , I⊨B) = \n (⟨ABox⟩-resp-⊨ f i≈j∘f A I⊨A , ⟨ABox⟩-resp-⊨ f i≈j∘f B I⊨B)\n⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (x ∼ y) x≈y = \n ≈-trans ⌊ I ⌋ (≈-sym ⌊ I ⌋ (i≈j∘f x)) (≈-trans ⌊ I ⌋ x≈y (i≈j∘f y))\n⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (x ∈₁ c) x∈⟦c⟧ =\n con-≈ ⌊ I ⌋ c x∈⟦c⟧ (i≈j∘f x)\n⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f ((x , y) ∈₂ r) xy∈⟦r⟧ =\n rol-≈ ⌊ I ⌋ r (≈-sym ⌊ I ⌋ (i≈j∘f x)) xy∈⟦r⟧ (i≈j∘f y)\n\n*-resp-⟨ABox⟩ : ∀ {X Y} (f : Y → X) I A →\n (I ⊨a ⟨ABox⟩ f A) → (f * I ⊨a A)\n*-resp-⟨ABox⟩ f (I , i) ε I⊨ε = \n tt\n*-resp-⟨ABox⟩ f (I , i) (A , B) (I⊨A , I⊨B) = \n (*-resp-⟨ABox⟩ f (I , i) A I⊨A , *-resp-⟨ABox⟩ f (I , i) B I⊨B )\n*-resp-⟨ABox⟩ f (I , i) (x ∼ y) x≈y = \n x≈y\n*-resp-⟨ABox⟩ f (I , i) (x ∈₁ c) x∈⟦c⟧ = \n x∈⟦c⟧\n*-resp-⟨ABox⟩ f (I , i) ((x , y) ∈₂ r) xy∈⟦c⟧ = \n xy∈⟦c⟧\n\n-- bnodes I f is the same as I, except that f is used as the interpretation\n-- for bnodes.\n\non-bnode : ∀ {V W X Y Z : Set} → (W → Z) → ((X ⊕ V ⊕ Y) → Z) → \n ((X ⊕ W ⊕ Y) → Z)\non-bnode f g (inode x) = g (inode x)\non-bnode f g (bnode w) = f w\non-bnode f g (enode y) = g (enode y)\n\nbnodes : ∀ {V W X Y} → (I : Interp Σ (X ⊕ V ⊕ Y)) → (W → Δ ⌊ I ⌋) → \n Interp Σ (X ⊕ W ⊕ Y)\nbnodes I f = (⌊ I ⌋ , on-bnode f (ind I))\n\nbnodes-resp-≲ : ∀ {V W X Y} (I J : Interp Σ (X ⊕ V ⊕ Y)) →\n (I≲J : I ≲ J) → (f : W → Δ ⌊ I ⌋) → \n (bnodes I f ≲ bnodes J (≲-image ≲⌊ I≲J ⌋ ∘ f))\nbnodes-resp-≲ (I , i) (J , j) (I≲J , i≲j) f = (I≲J , lemma) where\n\n lemma : ∀ x → \n J ⊨ ≲-image I≲J (on-bnode f i x) ≈ on-bnode (≲-image I≲J ∘ f) j x\n lemma (inode x) = i≲j (inode x)\n lemma (bnode v) = ≈-refl J\n lemma (enode y) = i≲j (enode y)\n\n-- I ⊨b A whenever there exists an f such that bnodes I f ⊨a A\n\ndata _⊨b_ {V W X Y} (I : Interp Σ (X ⊕ V ⊕ Y)) \n (A : ABox Σ (X ⊕ W ⊕ Y)) : Set where\n _,_ : ∀ f → (bnodes I f ⊨a A) → (I ⊨b A)\n\ninb : ∀ {V W X Y} {I : Interp Σ (X ⊕ V ⊕ Y)} {A : ABox Σ (X ⊕ W ⊕ Y)} → \n (I ⊨b A) → W → Δ ⌊ I ⌋\ninb (f , I⊨A) = f\n\n⊨b-impl-⊨a : ∀ {V W X Y} {I : Interp Σ (X ⊕ V ⊕ Y)} {A : ABox Σ (X ⊕ W ⊕ Y)} → \n (I⊨A : I ⊨b A) → (bnodes I (inb I⊨A) ⊨a A)\n⊨b-impl-⊨a (f , I⊨A) = I⊨A\n\n⊨a-impl-⊨b : ∀ {V X Y} (I : Interp Σ (X ⊕ V ⊕ Y)) A → (I ⊨a A) → (I ⊨b A)\n⊨a-impl-⊨b I A I⊨A = \n (ind I ∘ bnode , ⊨a-resp-≲ (≲-refl ⌊ I ⌋ , lemma) A I⊨A) where\n\n lemma : ∀ x → ⌊ I ⌋ ⊨ ind I x ≈ on-bnode (ind I ∘ bnode) (ind I) x\n lemma (inode x) = ≈-refl ⌊ I ⌋\n lemma (bnode v) = ≈-refl ⌊ I ⌋\n lemma (enode y) = ≈-refl ⌊ I ⌋\n\n⊨b-resp-≲ : ∀ {V W X Y} {I J : Interp Σ (X ⊕ V ⊕ Y)} → (I ≲ J) \n → ∀ (A : ABox Σ (X ⊕ W ⊕ Y)) → (I ⊨b A) → (J ⊨b A)\n⊨b-resp-≲ I≲J A (f , I⊨A) = \n ((≲-image ≲⌊ I≲J ⌋ ∘ f) , ⊨a-resp-≲ (bnodes-resp-≲ _ _ I≲J f) A I⊨A)\n\n", "meta": {"hexsha": "aebec4544a56bd10a78e08023d1c8a2f88e7d759", "size": 6400, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/ABox/Model.agda", "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_issues_repo_path": "src/Web/Semantic/DL/ABox/Model.agda", "max_issues_repo_name": "agda/agda-web-semantic", "max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_forks_repo_path": "src/Web/Semantic/DL/ABox/Model.agda", "max_forks_repo_name": "agda/agda-web-semantic", "max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "avg_line_length": 39.263803681, "max_line_length": 80, "alphanum_fraction": 0.46203125, "num_tokens": 3954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.35220178204788966, "lm_q1q2_score": 0.17747665124526993}} {"text": "------------------------------------------------------------------------\n-- Compiler correctness\n------------------------------------------------------------------------\n\n{-# OPTIONS --cubical --safe #-}\n\nmodule Lambda.Simplified.Partiality-monad.Inductive.Compiler-correctness\n where\n\nopen import Equality.Propositional.Cubical\nopen import Prelude hiding (⊥)\n\nopen import Monad equality-with-J\nopen import Vec.Function equality-with-J\n\nopen import Partiality-monad.Inductive\nopen import Partiality-monad.Inductive.Fixpoints hiding (comp; app)\nopen import Partiality-monad.Inductive.Monad\n\nopen import Lambda.Simplified.Compiler\nopen import Lambda.Simplified.Partiality-monad.Inductive.Interpreter\nopen import Lambda.Simplified.Partiality-monad.Inductive.Virtual-machine\nopen import Lambda.Simplified.Syntax\nopen import Lambda.Simplified.Virtual-machine\n\nprivate\n module C = Closure Code\n module T = Closure Tm\n\nopen Partial\nopen Trans-⊑\n\n-- Some abbreviations.\n\nevalⁿ : ∀ {n} → Tm n → T.Env n → ℕ → T.Value ⊥\nevalⁿ t ρ n = app→ eval n (_ , t , ρ)\n\n_∙ⁿ_ : T.Value → T.Value → ℕ → T.Value ⊥\n(v₁ ∙ⁿ v₂) n = function (v₁ ∙ v₂) (app→ eval n)\n\nexecⁿ : State → ℕ → Maybe C.Value ⊥\nexecⁿ s n = app→ (transformer execP) n s\n\n-- Compiler correctness.\n\nmutual\n\n ⟦⟧-correct :\n ∀ {n} t {ρ : T.Env n} {c s}\n {k : ℕ → T.Value → Maybe C.Value ⊥} {n} →\n (∀ v → execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳[ n ]\n λ n → k n v) →\n execⁿ ⟨ comp t c , s , comp-env ρ ⟩ ≳[ n ]\n λ n → evalⁿ t ρ (suc n) >>= k n\n ⟦⟧-correct (var x) {ρ} {c} {s} {k} hyp =\n execⁿ ⟨ var x ∷ c , s , comp-env ρ ⟩ ≳⟨ step⇓ ⟩\n execⁿ ⟨ c , val (comp-val (ρ x)) ∷ s , comp-env ρ ⟩ ≳⟨ hyp (ρ x) ⟩\n (λ n → k n (ρ x)) ≡⟨ sym now->>= ⟩≳\n (λ n → evalⁿ (var x) ρ (suc n) >>= k n) ∎≳\n\n ⟦⟧-correct (ƛ t) {ρ} {c} {s} {k} hyp =\n execⁿ ⟨ clo (comp t (ret ∷ [])) ∷ c , s , comp-env ρ ⟩ ≳⟨ step⇓ ⟩\n execⁿ ⟨ c , val (comp-val (T.ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≳⟨ hyp (T.ƛ t ρ) ⟩\n (λ n → k n (T.ƛ t ρ)) ≡⟨ sym now->>= ⟩≳\n (λ n → evalⁿ (ƛ t) ρ (suc n) >>= k n) ∎≳\n\n ⟦⟧-correct (t₁ · t₂) {ρ} {c} {s} {k} {n} hyp =\n execⁿ ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t₁ {n = n} λ v₁ → ⟦⟧-correct t₂ λ v₂ → ∙-correct v₁ v₂ hyp) ⟩\n\n (λ n → evalⁿ t₁ ρ (suc n) >>=′ λ v₁ →\n evalⁿ t₂ ρ (suc n) >>=′ λ v₂ →\n (v₁ ∙ⁿ v₂) n >>=\n k n) ≡⟨ cong (evalⁿ t₁ ρ (suc n) >>=′_)\n (⟨ext⟩ λ _ → associativity (evalⁿ t₂ ρ (suc n)) _ _) ⟩≳\n (λ n → evalⁿ t₁ ρ (suc n) >>=′ λ v₁ →\n (evalⁿ t₂ ρ (suc n) >>=′ λ v₂ → (v₁ ∙ⁿ v₂) n) >>=\n k n) ≡⟨ associativity (evalⁿ t₁ ρ (suc n)) _ _ ⟩≳\n\n (λ n → evalⁿ (t₁ · t₂) ρ (suc n) >>= k n) ∎≳\n\n ∙-correct :\n ∀ {n} v₁ v₂ {ρ : T.Env n} {c s}\n {k : ℕ → T.Value → Maybe C.Value ⊥} {n} →\n (∀ v → execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳[ n ]\n λ n → k n v) →\n execⁿ ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s\n , comp-env ρ\n ⟩ ≳[ n ]\n λ n → (v₁ ∙ⁿ v₂) n >>= k n\n\n ∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} {zero} hyp =\n execⁿ ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s\n , comp-env ρ\n ⟩ ≡⟨ refl ⟩≳\n\n const never ≡⟨ sym never->>= ⟩≳\n\n (λ n → (T.ƛ t₁ ρ₁ ∙ⁿ v₂) n >>= k n) ∎≳\n\n ∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} {suc n} hyp = later (\n execⁿ ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s\n , comp-env ρ\n ⟩ ∘ suc ≳⟨⟩\n\n execⁿ ⟨ comp t₁ (ret ∷ [])\n , ret c (comp-env ρ) ∷ s\n , cons (comp-val v₂) (comp-env ρ₁)\n ⟩ ∀≡⟨ (λ n → cong (λ ρ′ → execⁿ ⟨ comp t₁ (ret ∷ []) , ret c (comp-env ρ) ∷ s , ρ′ ⟩ n)\n (sym comp-cons)) ⟩≳\n execⁿ ⟨ comp t₁ (ret ∷ [])\n , ret c (comp-env ρ) ∷ s\n , comp-env (cons v₂ ρ₁)\n ⟩ ≳⟨ (⟦⟧-correct t₁ {n = n} λ v →\n\n execⁿ ⟨ ret ∷ []\n , val (comp-val v) ∷ ret c (comp-env ρ) ∷ s\n , comp-env (cons v₂ ρ₁)\n ⟩ ≳⟨ step⇓ ⟩\n\n execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳⟨ hyp v ⟩\n\n (λ n → k n v) ≳⟨ step⇓ ⟩\n\n (λ n → k (suc n) v) ∎≳) ⟩\n\n (λ n → evalⁿ t₁ (cons v₂ ρ₁) (suc n) >>= k (suc n)) ≳⟨⟩\n\n (λ n → (T.ƛ t₁ ρ₁ ∙ⁿ v₂) (suc n) >>= k (suc n)) ∎≳)\n\n-- Note that the equality that is used here is syntactic.\n\ncorrect :\n ∀ t →\n exec ⟨ comp t [] , [] , nil ⟩ ≡\n (⟦ t ⟧ nil >>= λ v → return (just (comp-val v)))\ncorrect t =\n exec ⟨ comp t [] , [] , nil ⟩ ≡⟨ cong (λ ρ → exec ⟨ comp t [] , [] , ρ ⟩) $ sym comp-nil ⟩\n\n exec ⟨ comp t [] , [] , comp-env nil ⟩ ≡⟨⟩\n\n ⨆ ( execⁿ ⟨ comp t [] , [] , comp-env nil ⟩\n , _\n ) ≡⟨ ≳→⨆≡⨆ 1 (⟦⟧-correct t $ λ v →\n\n execⁿ ⟨ [] , val (comp-val v) ∷ [] , comp-env nil ⟩ ≳⟨ step⇓ ⟩\n const (return (just (comp-val v))) ∎≳) ⟩\n\n ⨆ ( (λ n → evalⁿ t nil n >>= λ v →\n return (just (comp-val v)))\n , _\n ) ≡⟨ sym ⨆->>= ⟩\n\n (⟦ t ⟧ nil >>= λ v → return (just (comp-val v))) ∎\n", "meta": {"hexsha": "7affb5f368bcccd14158a9d109c1cf8f92472165", "size": 5964, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_issues_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_issues_repo_name": "nad/partiality-monad", "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9872611465, "max_line_length": 149, "alphanum_fraction": 0.3895036888, "num_tokens": 2198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.3522017684487511, "lm_q1q2_score": 0.1774766443925801}} {"text": "module Properties.Step where\n\nopen import Agda.Builtin.Equality using (_≡_; refl)\nopen import Agda.Builtin.Float using (primFloatPlus; primFloatMinus; primFloatTimes; primFloatDiv)\nopen import FFI.Data.Maybe using (just; nothing)\nopen import Luau.Heap using (Heap; _[_]; alloc; ok; function_is_end)\nopen import Luau.Syntax using (Block; Expr; nil; var; addr; function_is_end; block_is_end; _$_; local_←_; return; done; _∙_; name; fun; arg; number; binexp; +)\nopen import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; app₁ ; app₂ ; beta; function; block; return; done; local; subst; binOpEval; evalBinOp; binOp₁; binOp₂)\nopen import Luau.RuntimeError using (RuntimeErrorᴱ; RuntimeErrorᴮ; TypeMismatch; UnboundVariable; SEGV; app₁; app₂; block; local; return; bin₁; bin₂)\nopen import Luau.RuntimeType using (function; number)\nopen import Luau.Substitution using (_[_/_]ᴮ)\nopen import Luau.Value using (nil; addr; val; number)\nopen import Properties.Remember using (remember; _,_)\n\ndata StepResultᴮ {a} (H : Heap a) (B : Block a) : Set\ndata StepResultᴱ {a} (H : Heap a) (M : Expr a) : Set\n\ndata StepResultᴮ H B where\n step : ∀ H′ B′ → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → StepResultᴮ H B\n return : ∀ V {B′} → (B ≡ (return (val V) ∙ B′)) → StepResultᴮ H B\n done : (B ≡ done) → StepResultᴮ H B\n error : (RuntimeErrorᴮ H B) → StepResultᴮ H B\n\ndata StepResultᴱ H M where\n step : ∀ H′ M′ → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → StepResultᴱ H M\n value : ∀ V → (M ≡ val V) → StepResultᴱ H M\n error : (RuntimeErrorᴱ H M) → StepResultᴱ H M\n\nstepᴱ : ∀ {a} H M → StepResultᴱ {a} H M\nstepᴮ : ∀ {a} H B → StepResultᴮ {a} H B\n\nstepᴱ H nil = value nil refl\nstepᴱ H (var x) = error (UnboundVariable x)\nstepᴱ H (addr a) = value (addr a) refl\nstepᴱ H (number x) = value (number x) refl\nstepᴱ H (M $ N) with stepᴱ H M\nstepᴱ H (M $ N) | step H′ M′ D = step H′ (M′ $ N) (app₁ D)\nstepᴱ H (_ $ N) | value V refl with stepᴱ H N\nstepᴱ H (_ $ N) | value V refl | step H′ N′ s = step H′ (val V $ N′) (app₂ s)\nstepᴱ H (_ $ _) | value nil refl | value W refl = error (app₁ (TypeMismatch function nil λ()))\nstepᴱ H (_ $ _) | value (number n) refl | value W refl = error (app₁ (TypeMismatch function (number n) λ()))\nstepᴱ H (_ $ _) | value (addr a) refl | value W refl with remember (H [ a ])\nstepᴱ H (_ $ _) | value (addr a) refl | value W refl | (nothing , p) = error (app₁ (SEGV a p))\nstepᴱ H (_ $ _) | value (addr a) refl | value W refl | (just(function F is B end) , p) = step H (block fun F is B [ W / name (arg F) ]ᴮ end) (beta p)\nstepᴱ H (M $ N) | value V p | error E = error (app₂ E)\nstepᴱ H (M $ N) | error E = error (app₁ E)\nstepᴱ H (block b is B end) with stepᴮ H B\nstepᴱ H (block b is B end) | step H′ B′ D = step H′ (block b is B′ end) (block D)\nstepᴱ H (block b is (return _ ∙ B′) end) | return V refl = step H (val V) return\nstepᴱ H (block b is done end) | done refl = step H nil done\nstepᴱ H (block b is B end) | error E = error (block b E)\nstepᴱ H (function F is C end) with alloc H (function F is C end)\nstepᴱ H function F is C end | ok a H′ p = step H′ (addr a) (function p)\nstepᴱ H (binexp x op y) with stepᴱ H x\nstepᴱ H (binexp x op y) | value x′ refl with stepᴱ H y\nstepᴱ H (binexp x op y) | value (number x′) refl | value (number y′) refl = step H (number (evalBinOp x′ op y′)) binOpEval\nstepᴱ H (binexp x op y) | value (number x′) refl | step H′ y′ s = step H′ (binexp (number x′) op y′) (binOp₂ s)\nstepᴱ H (binexp x op y) | value (number x′) refl | error E = error (bin₂ E)\nstepᴱ H (binexp x op y) | value nil refl | _ = error (bin₁ (TypeMismatch number nil λ()))\nstepᴱ H (binexp x op y) | _ | value nil refl = error (bin₂ (TypeMismatch number nil λ()))\nstepᴱ H (binexp x op y) | value (addr a) refl | _ = error (bin₁ (TypeMismatch number (addr a) λ()))\nstepᴱ H (binexp x op y) | _ | value (addr a) refl = error (bin₂ (TypeMismatch number (addr a) λ()))\nstepᴱ H (binexp x op y) | step H′ x′ s = step H′ (binexp x′ op y) (binOp₁ s)\nstepᴱ H (binexp x op y) | error E = error (bin₁ E)\n\nstepᴮ H (function F is C end ∙ B) with alloc H (function F is C end)\nstepᴮ H (function F is C end ∙ B) | ok a H′ p = step H′ (B [ addr a / fun F ]ᴮ) (function p)\nstepᴮ H (local x ← M ∙ B) with stepᴱ H M\nstepᴮ H (local x ← M ∙ B) | step H′ M′ D = step H′ (local x ← M′ ∙ B) (local D)\nstepᴮ H (local x ← _ ∙ B) | value V refl = step H (B [ V / name x ]ᴮ) subst\nstepᴮ H (local x ← M ∙ B) | error E = error (local x E)\nstepᴮ H (return M ∙ B) with stepᴱ H M\nstepᴮ H (return M ∙ B) | step H′ M′ D = step H′ (return M′ ∙ B) (return D)\nstepᴮ H (return _ ∙ B) | value V refl = return V refl\nstepᴮ H (return M ∙ B) | error E = error (return E)\nstepᴮ H done = done refl\n", "meta": {"hexsha": "2a0978ff63c5f366c67679a81da55e5241504d16", "size": 4603, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "prototyping/Properties/Step.agda", "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "prototyping/Properties/Step.agda", "max_issues_repo_name": "Tr4shh/Roblox-Luau", "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prototyping/Properties/Step.agda", "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.7792207792, "max_line_length": 159, "alphanum_fraction": 0.6419726265, "num_tokens": 1838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.30074557894124154, "lm_q1q2_score": 0.17138066556075218}} {"text": "{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.\n\n Copyright (c) 2021, Oracle and/or its affiliates.\n Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl\n-}\n\nopen import LibraBFT.Base.Types\nopen import LibraBFT.Concrete.System\nopen import LibraBFT.Concrete.System.Parameters\nimport LibraBFT.Impl.Consensus.ConsensusTypes.Properties.QuorumCert as QC\nimport LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert\nopen import LibraBFT.Impl.Consensus.ConsensusTypes.SyncInfo as SI\nopen import LibraBFT.Impl.Properties.Util\nopen import LibraBFT.Impl.Types.BlockInfo as BI\nopen import LibraBFT.ImplShared.Consensus.Types\nopen import LibraBFT.ImplShared.Consensus.Types.EpochDep\nopen import LibraBFT.ImplShared.Interface.Output\nopen import LibraBFT.ImplShared.Util.Dijkstra.All\nopen import Optics.All\nopen import Util.Prelude\nopen import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms\n\nopen Invariants\nopen RoundManagerTransProps\n\nmodule LibraBFT.Impl.Consensus.ConsensusTypes.Properties.SyncInfo where\n\nmodule verifyMSpec (self : SyncInfo) (validator : ValidatorVerifier) where\n\n epoch = self ^∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biEpoch\n\n record SIVerifyProps (pre : RoundManager) : Set where\n field\n sivpEp≡ : epoch ≡ self ^∙ siHighestCommitCert ∙ qcCertifiedBlock ∙ biEpoch\n sivpTcEp≡ : maybeS (self ^∙ siHighestTimeoutCert) Unit $ λ tc -> epoch ≡ tc ^∙ tcEpoch\n sivpHqc≥Hcc : (self ^∙ siHighestQuorumCert) [ _≥_ ]L self ^∙ siHighestCommitCert at qcCertifiedBlock ∙ biRound\n sivpHqc≢empty : self ^∙ siHighestCommitCert ∙ qcCommitInfo ≢ BI.empty\n sivpHqcVer : QC.Contract (self ^∙ siHighestQuorumCert) validator\n sivpHccVer : maybeS (self ^∙ sixxxHighestCommitCert) Unit $ λ qc → QC.Contract qc validator\n -- Waiting on TimeoutCertificate Contract : sivpHtcVer : maybeS (self ^∙ siHighestTimeoutCert ) Unit $ λ tc → {!!}\n\n module _ (pre : RoundManager) where\n\n record Contract (r : Either ErrLog Unit) (post : RoundManager) (outs : List Output) : Set where\n constructor mkContract\n field\n -- General properties / invariants\n rmInv : Preserves RoundManagerInv pre post\n noStateChange : pre ≡ post\n -- Output\n noMsgOuts : OutputProps.NoMsgs outs\n -- Syncing\n syncResCorr : r ≡ Right unit → SIVerifyProps pre\n -- NOTE: Since the output contains no messages and the state does not\n -- change, nothing needs to be said about the quorum certificats in the\n -- output and post state\n\n verifyCorrect : SI.verify self validator ≡ Right unit → SIVerifyProps pre\n verifyCorrect verify≡\n with epoch ≟ self ^∙ siHighestCommitCert ∙ qcCertifiedBlock ∙ biEpoch\n ...| no ep≢ = absurd (Left _ ≡ Right _) case verify≡ of λ ()\n ...| yes sivpEp≡\n with sivpTcEp≡ verify≡\n where\n sivpTcEp≡ : SI.verify.step₁ self validator ≡ Right unit\n → maybeS (self ^∙ siHighestTimeoutCert) Unit (\\tc -> epoch ≡ tc ^∙ tcEpoch)\n × SI.verify.step₂ self validator ≡ Right unit\n sivpTcEp≡ verify≡₁\n with self ^∙ siHighestTimeoutCert\n ...| nothing = unit , verify≡₁\n ...| just tc\n with epoch ≟ tc ^∙ tcEpoch\n ...| yes tce≡ = tce≡ , verify≡₁\n ...| no tce≢ = absurd (Left _ ≡ Right _) case verify≡₁ of λ ()\n ...| sivpTcEp≡ , verify≡₂\n with sivpHqc≥Hcc verify≡₂\n where\n sivpHqc≥Hcc : (SI.verify.step₂ self validator ≡ Right unit)\n → (self ^∙ siHighestQuorumCert) [ _≥_ ]L self ^∙ siHighestCommitCert at qcCertifiedBlock ∙ biRound\n × SI.verify.step₃ self validator ≡ Right unit\n sivpHqc≥Hcc verify≡₂\n with self ^∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound\n ≥? self ^∙ siHighestCommitCert ∙ qcCertifiedBlock ∙ biRound\n ...| yes hqc≥hcc = hqc≥hcc , verify≡₂\n ...| no hqc> _)} (deseq eq1) dehole ()\nRE-split {.(trap _)} (detrap eq1) dehole ()\nRE-split {.(_ ∥ _)} (depar₂ eq1) dehole ()\nRE-split {.(suspend _ _)} (desuspend eq1) dehole ()\nRE-split {(pin ∥ qin)}{θ}{p'}{((epar₁ _) ∷ E)}{(epar₂ _) ∷ E'} (depar₁ eq1) (depar₂ eq2) par2\n = (t ∥ qin) , (epar₂ t) ∷ E' , (depar₁ (plug refl) , depar₂ eq2 , parl (~ref E') , par) where t = (E ⟦ p' ⟧e)\nRE-split {(pin ∥ qin)}{θ}{p'}{((epar₂ _) ∷ E)}{(epar₁ _) ∷ E'} (depar₂ eq1) (depar₁ eq2) par\n = (pin ∥ t) , ((epar₁ t) ∷ E' , (depar₂ (plug refl) , depar₁ eq2 , parr (~ref E') , par2)) where t = (E ⟦ p' ⟧e)\nRE-split {(pin ∥ qin)} (depar₁ eq1) (depar₁ eq2) (parr neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = d ∥ qin , (epar₁ qin) ∷ Eout , (depar₁ eqd , depar₁ eqo , parr ~ , parr a~)\nRE-split {(pin ∥ qin)} (depar₂ eq1) (depar₂ eq2) (parl neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = pin ∥ d , (epar₂ pin) ∷ Eout , (depar₂ eqd , depar₂ eqo , parl ~ , parl a~)\nRE-split {(loopˢ _ q)} (deloopˢ eq1) (deloopˢ eq2) (loopˢ neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = (loopˢ d q) , (eloopˢ q) ∷ Eout , (deloopˢ eqd , deloopˢ eqo , loopˢ ~ , loopˢ a~)\nRE-split {(._ >> q)} (deseq eq1) (deseq eq2) (seq neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = (d >> q) , (eseq q) ∷ Eout , (deseq eqd , deseq eqo , seq ~ , seq a~)\nRE-split {(suspend ._ S)} (desuspend eq1) (desuspend eq2) (susp neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = (suspend d S) , ((esuspend S) ∷ Eout) , (desuspend eqd , desuspend eqo , susp ~ , susp a~)\nRE-split {.(trap _)} (detrap eq1) (detrap eq2) (trp neg) with RE-split eq1 eq2 neg\n... | (d , Eout , (eqd , eqo , ~ , a~)) = (trap d) , (etrap ∷ Eout) , (detrap eqd , detrap eqo , trp ~ , trp a~)\n\n\nready-maint : ∀{θ e} → (S : Signal) → (S∈ : (Env.isSig∈ S θ)) → (stat : Signal.Status) → all-ready e θ\n → all-ready e (Env.set-sig{S} θ S∈ stat)\nready-maint {θ} {.(plus [])} S S∈ stat (aplus []) = aplus []\nready-maint {θ} {.(plus (num _ ∷ _))} S S∈ stat (aplus (brnum ∷ x₁)) with ready-maint S S∈ stat (aplus x₁)\n... | (aplus r) = aplus (brnum ∷ r)\nready-maint {θ} {.(plus (seq-ref _ ∷ _))} S S∈ stat (aplus (brseq x₁ ∷ x₂)) with ready-maint S S∈ stat (aplus x₂)\n... | (aplus r) = aplus (brseq x₁ ∷ r)\nready-maint {θ} {.(plus (shr-ref _ ∷ _))} S S∈ stat (aplus (brshr s∈ x ∷ x₁)) with ready-maint S S∈ stat (aplus x₁)\n... | (aplus r) = aplus (brshr s∈ x ∷ r)\n\nready-irr : ∀{θ e} → (S : Signal) → (S∈ : (Env.isSig∈ S θ)) → (stat : Signal.Status)\n → (e' : all-ready e θ)\n → (e'' : all-ready e (Env.set-sig{S} θ S∈ stat))\n → δ e' ≡ δ e''\n\nready-irr {θ} {.(plus [])} S S∈ stat (aplus []) (aplus []) = refl\nready-irr {θ} {.(plus (num _ ∷ _))} S S∈ stat (aplus (brnum ∷ x₁)) (aplus (brnum ∷ x₂))\n rewrite ready-irr S S∈ stat (aplus x₁) (aplus x₂) = refl\nready-irr {θ@(Θ Ss ss xs)} {.(plus (seq-ref _ ∷ _))} S S∈ stat (aplus (brseq{_}{x} x₁ ∷ x₂)) (aplus (brseq x₃ ∷ x₄))\n rewrite ready-irr S S∈ stat (aplus x₂) (aplus x₄) | seq∈-eq'{x}{xs} x₁ x₃ = refl\nready-irr {θ@(Θ Ss ss xs)} {.(plus (shr-ref _ ∷ _))} S S∈ stat (aplus (brshr{_}{s} s∈ x ∷ x₁)) (aplus (brshr s∈₁ x₂ ∷ x₃))\n rewrite ready-irr S S∈ stat (aplus x₁) (aplus x₃) | shr∈-eq'{s}{ss} s∈ s∈₁ = refl\n\nready-maint/irr : ∀{θ e} → (S : Signal) → (S∈ : (Env.isSig∈ S θ)) → (stat : Signal.Status)\n → (e' : all-ready e θ)\n → Σ[ e'' ∈ all-ready e (Env.set-sig{S} θ S∈ stat) ] δ e' ≡ δ e''\nready-maint/irr {θ}{e} S S∈ stat e' with ready-maint{θ}{e} S S∈ stat e'\n... | e'' = e'' , (ready-irr{θ}{e} S S∈ stat e' e'')\n\nready-maint/x : ∀{θ e} → (x : SeqVar) → (x∈ : (Env.isVar∈ x θ)) → (n : ℕ) → all-ready e θ\n → all-ready e (Env.set-var{x} θ x∈ n)\nready-maint/x {θ} {.(plus [])} x x∈ n (aplus []) = aplus []\nready-maint/x {θ} {.(plus (num _ ∷ _))} x₁ x∈ n (aplus (brnum ∷ x₂)) with ready-maint/x x₁ x∈ n (aplus x₂)\n... | (aplus r) = aplus (brnum ∷ r)\nready-maint/x {θ} {.(plus (seq-ref _ ∷ _))} x₁ x∈ n (aplus (brseq{x = x2} x₂ ∷ x₃)) with ready-maint/x x₁ x∈ n (aplus x₃)\n... | (aplus r) = aplus ((brseq (seq-set-mono'{x2}{x₁}{θ}{n}{x∈} x₂)) ∷ r)\nready-maint/x {θ} {.(plus (shr-ref _ ∷ _))} x₁ x∈ n (aplus (brshr s∈ x ∷ x₂)) with ready-maint/x x₁ x∈ n (aplus x₂)\n... | (aplus r) = aplus (brshr s∈ x ∷ r)\n\nready-maint-s : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.new n)\nready-maint-s {e = .(plus [])} s n s∈ ¬≡ (aplus []) = aplus []\nready-maint-s {e = .(plus (num _ ∷ _))} s n₁ s∈ ¬≡ (aplus (brnum ∷ x₁)) with ready-maint-s s n₁ s∈ ¬≡ (aplus x₁)\n... | aplus rec = aplus (brnum ∷ rec)\nready-maint-s {e = .(plus (seq-ref _ ∷ _))} s n s∈ ¬≡ (aplus (brseq x₁ ∷ x₂)) with ready-maint-s s n s∈ ¬≡ (aplus x₂)\n... | aplus rec = aplus (brseq x₁ ∷ rec)\nready-maint-s{θ} {e = (plus (shr-ref s ∷ ._))} s₁ n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) with ready-maint-s s₁ n s∈ ¬≡ (aplus x₁) | s SharedVar.≟ s₁\n... | aplus rec | yes refl with shr-stats-∈-irr{s}{θ} s∈ s∈₁\n... | eq rewrite eq = ⊥-elim (¬≡ x)\nready-maint-s{θ = θ} {e = (plus (shr-ref s ∷ ._))} s₁ n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) | aplus rec | no ¬s≡s₁\n with shr-putputget{θ = θ}{v2l = SharedVar.new}{n} ¬s≡s₁ s∈₁ s∈ (shr-set-mono'{s}{s₁}{θ}{n = n}{s∈} s∈₁) x refl\n... | (eq1 , eq2) = aplus (brshr ((shr-set-mono'{s}{s₁}{θ}{n = n}{s∈} s∈₁)) eq1 ∷ rec)\n\nready-irr-on-irr-s-helper : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → (e'' : all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.new n)) → δ e' ≡ δ e''\nready-irr-on-irr-s-helper {θ} {.(plus [])} s n s∈ ¬≡ (aplus []) (aplus []) = refl\nready-irr-on-irr-s-helper {θ} {.(plus (num _ ∷ _))} s n s∈ ¬≡ (aplus (brnum ∷ x₁)) (aplus (brnum ∷ x'))\n rewrite ready-irr-on-irr-s-helper s n s∈ ¬≡ (aplus x₁) (aplus x') = refl\nready-irr-on-irr-s-helper {θ@(Θ Ss ss xs)} {(plus (seq-ref x ∷ _))} s n s∈ ¬≡ (aplus (brseq x₁ ∷ x₂)) (aplus (brseq x₃ ∷ x'))\n rewrite ready-irr-on-irr-s-helper s n s∈ ¬≡ (aplus x₂) (aplus x') | seq∈-eq'{x}{xs} x₁ x₃ = refl\nready-irr-on-irr-s-helper {θ@(Θ Ss ss xs)} {(plus (shr-ref sₑ ∷ _))} s n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) (aplus (brshr s∈₂ x₂ ∷ x'))\n with sₑ SharedVar.≟ s\n... | yes sₑ≡s rewrite sₑ≡s | shr∈-eq'{s}{ss} s∈ s∈₁ = ⊥-elim (¬≡ x)\n... | no ¬sₑ≡s with shr-putputget{θ = θ}{v2l = SharedVar.new}{n} ¬sₑ≡s s∈₁ s∈ s∈₂ x refl\n... | (eq1 , eq2) rewrite ready-irr-on-irr-s-helper s n s∈ ¬≡ (aplus x₁) (aplus x') | eq2 = refl\n\nready-irr-on-irr-s : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → Σ[ e'' ∈ all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.new n) ] δ e' ≡ δ e''\nready-irr-on-irr-s s n s∈ ¬≡ e' = e'' , (ready-irr-on-irr-s-helper s n s∈ ¬≡ e' e'')\n where e'' = ready-maint-s s n s∈ ¬≡ e'\n\n-- copied and pasted form above\n-- TODO: maybe someday abstract over SharedVar.new/SharedVar.ready to sharedvar-status\nready-maint-s/ready : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.ready n)\nready-maint-s/ready {e = .(plus [])} s n s∈ ¬≡ (aplus []) = aplus []\nready-maint-s/ready {e = .(plus (num _ ∷ _))} s n₁ s∈ ¬≡ (aplus (brnum ∷ x₁)) with ready-maint-s/ready s n₁ s∈ ¬≡ (aplus x₁)\n... | aplus rec = aplus (brnum ∷ rec)\nready-maint-s/ready {e = .(plus (seq-ref _ ∷ _))} s n s∈ ¬≡ (aplus (brseq x₁ ∷ x₂)) with ready-maint-s/ready s n s∈ ¬≡ (aplus x₂)\n... | aplus rec = aplus (brseq x₁ ∷ rec)\nready-maint-s/ready{θ} {e = (plus (shr-ref s ∷ ._))} s₁ n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) with ready-maint-s/ready s₁ n s∈ ¬≡ (aplus x₁) | s SharedVar.≟ s₁\n... | aplus rec | yes refl with shr-stats-∈-irr{s}{θ} s∈ s∈₁\n... | eq rewrite eq = ⊥-elim (¬≡ x)\nready-maint-s/ready{θ = θ} {e = (plus (shr-ref s ∷ ._))} s₁ n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) | aplus rec | no ¬s≡s₁\n with shr-putputget{θ = θ}{v2l = SharedVar.ready}{n} ¬s≡s₁ s∈₁ s∈ (shr-set-mono'{s}{s₁}{θ}{n = n}{s∈} s∈₁) x refl\n... | (eq1 , eq2) = aplus (brshr ((shr-set-mono'{s}{s₁}{θ}{n = n}{s∈} s∈₁)) eq1 ∷ rec)\n\nready-irr-on-irr-s-helper/ready : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → (e'' : all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.ready n)) → δ e' ≡ δ e''\nready-irr-on-irr-s-helper/ready {θ} {.(plus [])} s n s∈ ¬≡ (aplus []) (aplus []) = refl\nready-irr-on-irr-s-helper/ready {θ} {.(plus (num _ ∷ _))} s n s∈ ¬≡ (aplus (brnum ∷ x₁)) (aplus (brnum ∷ x'))\n rewrite ready-irr-on-irr-s-helper/ready s n s∈ ¬≡ (aplus x₁) (aplus x') = refl\nready-irr-on-irr-s-helper/ready {θ@(Θ Ss ss xs)} {(plus (seq-ref x ∷ _))} s n s∈ ¬≡ (aplus (brseq x₁ ∷ x₂)) (aplus (brseq x₃ ∷ x'))\n rewrite ready-irr-on-irr-s-helper/ready s n s∈ ¬≡ (aplus x₂) (aplus x') | seq∈-eq'{x}{xs} x₁ x₃ = refl\nready-irr-on-irr-s-helper/ready {θ@(Θ Ss ss xs)} {(plus (shr-ref sₑ ∷ _))} s n s∈ ¬≡ (aplus (brshr s∈₁ x ∷ x₁)) (aplus (brshr s∈₂ x₂ ∷ x'))\n with sₑ SharedVar.≟ s\n... | yes sₑ≡s rewrite sₑ≡s | shr∈-eq'{s}{ss} s∈ s∈₁ = ⊥-elim (¬≡ x)\n... | no ¬sₑ≡s with shr-putputget{θ = θ}{v2l = SharedVar.ready}{n} ¬sₑ≡s s∈₁ s∈ s∈₂ x refl\n... | (eq1 , eq2) rewrite ready-irr-on-irr-s-helper/ready s n s∈ ¬≡ (aplus x₁) (aplus x') | eq2 = refl\n\nready-irr-on-irr-s/ready : ∀{θ e} → (s : SharedVar) → (n : ℕ) → (s∈ : Env.isShr∈ s θ) → ¬ (Env.shr-stats {s} θ s∈ ≡ SharedVar.ready) → (e' : all-ready e θ)\n → Σ[ e'' ∈ all-ready e (Env.set-shr{s = s} θ s∈ SharedVar.ready n) ] δ e' ≡ δ e''\nready-irr-on-irr-s/ready s n s∈ ¬≡ e' = e'' , (ready-irr-on-irr-s-helper/ready s n s∈ ¬≡ e' e'')\n where e'' = ready-maint-s/ready s n s∈ ¬≡ e'\n\nready-irr-on-irr-x-help : ∀{θ e} x n → (x∈ : Env.isVar∈ x θ) → (e' : all-ready e θ) → (SeqVar.unwrap x) ∉ (Xs (FVₑ e))\n → (e'' : all-ready e (Env.set-var{x = x} θ x∈ n))\n → δ e' ≡ δ e''\nready-irr-on-irr-x-help x n x∈ (aplus []) x∉FV (aplus []) = refl\nready-irr-on-irr-x-help x₁ n x∈ (aplus (brnum ∷ a)) x∉FV (aplus (brnum ∷ b)) rewrite ready-irr-on-irr-x-help x₁ n x∈ (aplus a) x∉FV (aplus b) = refl\nready-irr-on-irr-x-help{θ}{e} x₁ n x∈ (aplus (brseq{x = x} x₂ ∷ a)) x∉FV (aplus (brseq x₃ ∷ b))\n with x SeqVar.≟ x₁\n... | yes refl = ⊥-elim (x∉FV (here refl))\n... | no ¬x≡x₁ rewrite seq-putputget{θ = θ} ¬x≡x₁ x₂ x∈ x₃ refl\n | ready-irr-on-irr-x-help x₁ n x∈ (aplus a) (λ x → x∉FV (there x)) (aplus b) = refl\nready-irr-on-irr-x-help{θ} x₁ n x∈ (aplus (brshr{s = s} s∈ x ∷ a)) x∉FV (aplus (brshr s∈₁ x₂ ∷ b))\n rewrite ready-irr-on-irr-x-help x₁ n x∈ (aplus a) x∉FV (aplus b)\n | shr∈-eq'{s = s}{θ = (shr θ)} s∈ s∈₁\n = refl\n\nready-maint-x : ∀{θ e} x n → (x∈ : Env.isVar∈ x θ) → (e' : all-ready e θ) → (SeqVar.unwrap x) ∉ (Xs (FVₑ e))\n → all-ready e (Env.set-var{x = x} θ x∈ n)\nready-maint-x x n x∈ (aplus []) x∉FV = aplus []\nready-maint-x x₁ n₁ x∈ (aplus (brnum ∷ a)) x∉FV with ready-maint-x x₁ n₁ x∈ (aplus a) x∉FV\n... | (aplus r) = aplus (brnum ∷ r)\nready-maint-x{θ} x₁ n x∈ (aplus (brseq{x = x} x₂ ∷ a)) x∉FV with ready-maint-x x₁ n x∈ (aplus a) (λ x₃ → x∉FV (there x₃))\n... | (aplus r) = aplus ((brseq ((seq-set-mono'{x}{x₁}{θ}{n}{x∈} x₂))) ∷ r)\nready-maint-x x₁ n x∈ (aplus (brshr s∈ x ∷ a)) x∉FV with ready-maint-x x₁ n x∈ (aplus a) x∉FV\n... | (aplus r) = aplus ((brshr s∈ x) ∷ r)\n\nready-irr-on-irr-x : ∀{θ e} x n → (x∈ : Env.isVar∈ x θ) → (e' : all-ready e θ) → (SeqVar.unwrap x) ∉ (Xs (FVₑ e))\n → Σ[ e'' ∈ all-ready e (Env.set-var{x = x} θ x∈ n) ] δ e' ≡ δ e''\nready-irr-on-irr-x x n x∈ e' x∉FV = _ , ready-irr-on-irr-x-help x n x∈ e' x∉FV (ready-maint-x x n x∈ e' x∉FV)\n\nready-maint-θˡ : ∀{θ e} θ' → (e' : all-ready e θ) → (distinct (Dom θ') (FVₑ e)) → (all-ready e (θ ← θ'))\nready-maint-θˡ θ' (aplus []) Domθ'≠FVe = aplus []\nready-maint-θˡ θ' (aplus (brnum ∷ x₁)) Domθ'≠FVe with ready-maint-θˡ θ' (aplus x₁) Domθ'≠FVe\n... | (aplus f) = (aplus (brnum ∷ f))\nready-maint-θˡ{θ} θ' (aplus (brseq{x = x} x₁ ∷ x₂)) Domθ'≠FVe with ready-maint-θˡ θ' (aplus x₂) ((proj₁ Domθ'≠FVe) , (proj₁ (proj₂ Domθ'≠FVe)) , dist':: (proj₂ (proj₂ Domθ'≠FVe)))\n... | (aplus f) = aplus (brseq (Env.seq-←-monoˡ x θ θ' x₁) ∷ f)\nready-maint-θˡ{θ} θ' (aplus (brshr{s = s} s∈ s≡ ∷ x₁)) Domθ'≠FVe with ready-maint-θˡ θ' (aplus x₁) (((proj₁ Domθ'≠FVe) , dist':: (proj₁ (proj₂ Domθ'≠FVe)) , (proj₂ (proj₂ Domθ'≠FVe))))\n | shr-←-irr-get{θ}{θ'}{s} s∈ (λ x → (proj₁ (proj₂ Domθ'≠FVe)) _ x (here refl))\n... | (aplus f) | (s∈2 , eq) rewrite eq = aplus ((brshr s∈2 s≡) ∷ f)\nready-irr-on-irr-θˡ-help : ∀{θ e} θ' → (e' : all-ready e θ) → (distinct (Dom θ') (FVₑ e))\n → (e'' : (all-ready e (θ ← θ'))) → δ e' ≡ δ e''\nready-irr-on-irr-θˡ-help θ' (aplus []) Domθ'≠FVe (aplus []) = refl\nready-irr-on-irr-θˡ-help θ' (aplus (brnum ∷ x₁)) Domθ'≠FVe (aplus (brnum ∷ x₂))\n rewrite ready-irr-on-irr-θˡ-help θ' (aplus x₁) Domθ'≠FVe (aplus x₂)\n = refl\nready-irr-on-irr-θˡ-help{θ} θ' (aplus (brseq{x = x} x₁ ∷ x₂)) Domθ'≠FVe (aplus (brseq x₃ ∷ x₄))\n rewrite ready-irr-on-irr-θˡ-help θ' (aplus x₂) ((proj₁ Domθ'≠FVe) , (proj₁ (proj₂ Domθ'≠FVe)) , dist':: (proj₂ (proj₂ Domθ'≠FVe))) (aplus x₄)\n | seq-←-irr-get'{θ}{θ'}{x} x₁ (λ x → (proj₂ (proj₂ Domθ'≠FVe)) _ x (here refl)) x₃\n = refl\nready-irr-on-irr-θˡ-help{θ} θ' (aplus (brshr{s = s} s∈ x ∷ x₁)) Domθ'≠FVe (aplus (brshr s∈₁ x₂ ∷ x₃))\n rewrite ready-irr-on-irr-θˡ-help θ' (aplus x₁) ((proj₁ Domθ'≠FVe) , dist':: (proj₁ (proj₂ Domθ'≠FVe)) , (proj₂ (proj₂ Domθ'≠FVe))) (aplus x₃)\n | shr-←-irr-get/vals'{θ}{θ'}{s} s∈ (λ x → (proj₁ (proj₂ Domθ'≠FVe)) _ x (here refl)) s∈₁\n = refl\n\nready-irr-on-irr-θˡ : ∀{θ e} θ' → (e' : all-ready e θ) → (distinct (Dom θ') (FVₑ e))\n → Σ[ e'' ∈ (all-ready e (θ ← θ')) ] δ e' ≡ δ e''\nready-irr-on-irr-θˡ θ' e' Domθ'≠FVe = _ , ready-irr-on-irr-θˡ-help θ' e' Domθ'≠FVe (ready-maint-θˡ θ' e' Domθ'≠FVe)\n\nready-maint-θʳ : ∀ {θ' e} θ → (e' : all-ready e θ') → all-ready e (θ ← θ')\nready-maint-θʳ θ (aplus []) = aplus []\nready-maint-θʳ θ (aplus (brnum ∷ bound-readys))\n with ready-maint-θʳ θ (aplus bound-readys)\n... | aplus bound-readys' = aplus (brnum ∷ bound-readys')\nready-maint-θʳ {θ'} θ (aplus (brseq {x = x} x∈Domθ' ∷ bound-readys))\n with ready-maint-θʳ θ (aplus bound-readys)\n... | aplus bound-readys' = aplus (brseq (seq-←-monoʳ x θ' θ x∈Domθ') ∷ bound-readys')\nready-maint-θʳ {θ'} θ (aplus (brshr {s = s} s∈Domθ' θ's≡ready ∷ bound-readys))\n with ready-maint-θʳ θ (aplus bound-readys)\n... | aplus bound-readys' =\n aplus (brshr (shr-←-monoʳ s θ' θ s∈Domθ')\n (trans\n (shr-stats-←-right-irr' s θ θ' s∈Domθ'\n (shr-←-monoʳ s θ' θ s∈Domθ'))\n θ's≡ready) ∷\n bound-readys')\n\nready-irr-on-irr-θʳ-help : ∀ {θ' e} θ →\n (e' : all-ready e θ') →\n (e'' : all-ready e (θ ← θ')) →\n δ e' ≡ δ e''\nready-irr-on-irr-θʳ-help {θ'} θ (aplus []) (aplus []) = refl\nready-irr-on-irr-θʳ-help {θ'} θ (aplus (brnum ∷ bound-readys')) (aplus (brnum ∷ bound-readys''))\n with ready-irr-on-irr-θʳ-help θ (aplus bound-readys') (aplus bound-readys'')\n... | δe'≡δe'' rewrite δe'≡δe'' = refl\nready-irr-on-irr-θʳ-help {θ'} θ\n (aplus (brseq {x = x} x∈Domθ' ∷ bound-readys'))\n (aplus (brseq {x = .x} x∈Domθ←θ' ∷ bound-readys''))\n with ready-irr-on-irr-θʳ-help θ (aplus bound-readys') (aplus bound-readys'')\n... | δe'≡δe'' rewrite δe'≡δe'' | var-vals-←-right-irr' x θ θ' x∈Domθ' x∈Domθ←θ' = refl\nready-irr-on-irr-θʳ-help {θ'} θ\n (aplus (brshr {s = s} s∈Domθ' θ's≡ready ∷ bound-readys'))\n (aplus (brshr {s = .s} s∈Domθ←θ' ⟨θ←θ'⟩s≡ready ∷ bound-readys''))\n with ready-irr-on-irr-θʳ-help θ (aplus bound-readys') (aplus bound-readys'')\n... | δe'≡δe'' rewrite δe'≡δe'' | shr-vals-←-right-irr' s θ θ' s∈Domθ' s∈Domθ←θ' = refl\n\nready-irr-on-irr-θʳ : ∀ {θ' e} θ →\n (e' : all-ready e θ') →\n Σ[ e'' ∈ all-ready e (θ ← θ') ] δ e' ≡ δ e''\nready-irr-on-irr-θʳ θ e' = _ , ready-irr-on-irr-θʳ-help θ e' (ready-maint-θʳ θ e')\n\nCBE⟦p⟧=>CBp : ∀{BV FV E p} → CorrectBinding (E ⟦ p ⟧e) BV FV → ∃ (λ BV → ∃ (λ FV → (CorrectBinding p BV FV)))\nCBE⟦p⟧=>CBp{BV}{FV} {E = []} CB = BV , FV , CB\nCBE⟦p⟧=>CBp {E = epar₁ q ∷ E} (CBpar CB CB₁ x x₁ x₂ x₃) = CBE⟦p⟧=>CBp{E = E} CB\nCBE⟦p⟧=>CBp {E = epar₂ p ∷ E} (CBpar CB CB₁ x x₁ x₂ x₃) = CBE⟦p⟧=>CBp{E = E} CB₁\nCBE⟦p⟧=>CBp {E = eloopˢ q ∷ E} (CBloopˢ CB CB₁ x _) = CBE⟦p⟧=>CBp{E = E} CB\nCBE⟦p⟧=>CBp {E = eseq q ∷ E} (CBseq CB CB₁ x) = CBE⟦p⟧=>CBp{E = E} CB\nCBE⟦p⟧=>CBp {E = esuspend S ∷ E} (CBsusp CB x) = CBE⟦p⟧=>CBp{E = E} CB\nCBE⟦p⟧=>CBp {E = etrap ∷ E} (CBtrap CB) = CBE⟦p⟧=>CBp{E = E} CB\n\nCBE⟦p⟧=>CBp' : ∀{BV FV E p p'} → p ≐ E ⟦ p' ⟧e → CorrectBinding (p) BV FV → ∃ (λ BV → ∃ (λ FV → (CorrectBinding p' BV FV)))\nCBE⟦p⟧=>CBp'{E = E}{p' = p'} peq cb = CBE⟦p⟧=>CBp{E = E}{p = p'} (subst (λ x → CorrectBinding x _ _) (sym (unplug peq)) cb)\n-- , (BV⊆S , BV⊆s , BV⊆x)\n\nCBp⊆CBE⟦p⟧ : ∀{BVp FVp BVE FVE} → (E : EvaluationContext ) → (p : Term) → CorrectBinding p BVp FVp → CorrectBinding (E ⟦ p ⟧e) BVE FVE → (FVp ⊆ FVE × BVp ⊆ BVE)\n\nCBp⊆CBE⟦p⟧ [] p CBp CBE with binding-is-function CBp CBE\n... | (e1 , e2) rewrite e1 | e2 = (((λ x z → z) , (λ x z → z) , (λ x z → z))) , (((λ x z → z) , (λ x z → z) , (λ x z → z)))\nCBp⊆CBE⟦p⟧ (epar₁ q ∷ E) p CBp (CBpar CBE CBE₁ x x₁ x₂ x₃) with CBp⊆CBE⟦p⟧ E p CBp CBE\n... | (FV⊆S , FV⊆s , FV⊆x) , (BV⊆S , BV⊆s , BV⊆x) = ((λ x y → ++ˡ (FV⊆S x y)) , ((λ x y → ++ˡ (FV⊆s x y))) , ((λ x y → ++ˡ (FV⊆x x y)))) , (((λ x y → ++ˡ (BV⊆S x y))) , ((λ x y → ++ˡ (BV⊆s x y))) , ((λ x y → ++ˡ (BV⊆x x y))))\n\nCBp⊆CBE⟦p⟧ (epar₂ p ∷ E) p₁ CBp (CBpar{BVp = BVp}{FVp = FVp} CBE CBE₁ x x₁ x₂ x₃) with CBp⊆CBE⟦p⟧ E p₁ CBp CBE₁\n... | (FV⊆S , FV⊆s , FV⊆x) , (BV⊆S , BV⊆s , BV⊆x)\n = ((λ x z → ++ʳ (proj₁ FVp) (FV⊆S x z)) , (λ x → (++ʳ (proj₁ (proj₂ FVp))) ∘ (FV⊆s x)) , ((λ x → (++ʳ (proj₂ (proj₂ FVp))) ∘ (FV⊆x x))))\n , ((λ x z → ++ʳ (proj₁ BVp) (BV⊆S x z)) , (λ x → (++ʳ (proj₁ (proj₂ BVp))) ∘ (BV⊆s x)) , ((λ x → (++ʳ (proj₂ (proj₂ BVp))) ∘ (BV⊆x x))))\nCBp⊆CBE⟦p⟧ (eloopˢ q ∷ E) p CBp (CBloopˢ CBE CBE₁ x _) with CBp⊆CBE⟦p⟧ E p CBp CBE\n... | (FV⊆S , FV⊆s , FV⊆x) , (BV⊆S , BV⊆s , BV⊆x) = ((λ x y → ++ˡ (FV⊆S x y)) , ((λ x → ++ˡ ∘ (FV⊆s x)) ) , get FV⊆x) , (get BV⊆S , get BV⊆s , get BV⊆x)\n where\n get : ∀{a b c} → a ⊆¹ b → a ⊆¹ (b ++ c)\n get f = λ x y → ++ˡ (f x y)\nCBp⊆CBE⟦p⟧ (eseq q ∷ E) p CBp (CBseq CBE CBE₁ x) with CBp⊆CBE⟦p⟧ E p CBp CBE\n... | (FV⊆S , FV⊆s , FV⊆x) , (BV⊆S , BV⊆s , BV⊆x) = ((λ x y → ++ˡ (FV⊆S x y)) , ((λ x → ++ˡ ∘ (FV⊆s x)) ) , get FV⊆x) , (get BV⊆S , get BV⊆s , get BV⊆x)\n where\n get : ∀{a b c} → a ⊆¹ b → a ⊆¹ (b ++ c)\n get f = λ x y → ++ˡ (f x y)\n --(λ x₁ x₂ → {!there x₂!})\nCBp⊆CBE⟦p⟧ (esuspend S ∷ E) p CBp (CBsusp CBE x) with CBp⊆CBE⟦p⟧ E p CBp CBE\n... | (FV⊆S , FV⊆s , FV⊆x) , BV⊆ = (((λ x y → there (FV⊆S x y)) , FV⊆s , FV⊆x)) , BV⊆\nCBp⊆CBE⟦p⟧ (etrap ∷ E) p CBp (CBtrap CBE) = CBp⊆CBE⟦p⟧ E p CBp CBE\n\n\nCBp⊆CBE⟦p⟧' : ∀{BVp FVp BVE FVE} E p p' → p ≐ E ⟦ p' ⟧e → CorrectBinding p' BVp FVp → CorrectBinding p BVE FVE → (FVp ⊆ FVE × BVp ⊆ BVE)\nCBp⊆CBE⟦p⟧' E p p' peq cbp' cbp = CBp⊆CBE⟦p⟧ E p' cbp' (subst (λ x → CorrectBinding x _ _) (sym (unplug peq)) cbp)\n\ninspecting-cb-distinct-double-unplug : ∀{p q Ep Eq p' q' BV FV} → CorrectBinding (p ∥ q) BV FV\n → p ≐ Ep ⟦ p' ⟧e → q ≐ Eq ⟦ q' ⟧e\n →\n Σ (Term × VarList × VarList)\n λ {(o , BVo , FVo)\n → CorrectBinding o BVo FVo\n × o ≡ (p' ∥ q')}\ninspecting-cb-distinct-double-unplug{p' = p'}{q'} (CBpar CBp CBq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) p=Ep⟦p'⟧ q=Eq⟦q'⟧\n with CBE⟦p⟧=>CBp' p=Ep⟦p'⟧ CBp | CBE⟦p⟧=>CBp' q=Eq⟦q'⟧ CBq\n... | (BVp' , FVp' , CBp') | (BVq' , FVq' , CBq')\n with CBp⊆CBE⟦p⟧' _ _ _ p=Ep⟦p'⟧ CBp' CBp | CBp⊆CBE⟦p⟧' _ _ _ q=Eq⟦q'⟧ CBq' CBq\n... | (FVp'⊆FVp , BVp'⊆BVp) | (FVq'⊆FVq , BVq'⊆BVq)\n = (_ , _ , _) , CBpar CBp' CBq' (⊆-rep-dist-both BVp'⊆BVp BVq'⊆BVq BVp≠BVq) (⊆-rep-dist-both FVp'⊆FVp BVq'⊆BVq FVp≠BVq) (⊆-rep-dist-both BVp'⊆BVp FVq'⊆FVq BVp≠FVq) (⊆¹-rep-dist-both (proj₂ (proj₂ FVp'⊆FVp)) (proj₂ (proj₂ FVq'⊆FVq)) Xp≠Xq) , refl\n where\n ⊆¹-rep-dist-both : ∀{a b c d} → a ⊆¹ b → c ⊆¹ d → distinct' b d → distinct' a c\n ⊆¹-rep-dist-both sub1 sub2 dist = λ z z₁ z₂ → dist z (sub1 z z₁) (sub2 z z₂)\n ⊆-rep-dist-both : ∀{a b c d} → a ⊆ b → c ⊆ d → distinct b d → distinct a c\n ⊆-rep-dist-both a b c = (⊆¹-rep-dist-both , ⊆¹-rep-dist-both , ⊆¹-rep-dist-both) # a # b # c\n", "meta": {"hexsha": "b849eb6bfa42f10d960860bf5a445b8c8771cf52", "size": 23787, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/sn-calculus-confluence/helper.agda", "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_issues_repo_path": "agda/sn-calculus-confluence/helper.agda", "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "agda/sn-calculus-confluence/helper.agda", "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "avg_line_length": 67.3852691218, "max_line_length": 247, "alphanum_fraction": 0.5440786984, "num_tokens": 11629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795672, "lm_q2_score": 0.30735800417608683, "lm_q1q2_score": 0.1620749541950166}} {"text": "{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.\n\n Copyright (c) 2021, Oracle and/or its affiliates.\n Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl\n-}\n\nopen import LibraBFT.Concrete.Records\nopen import LibraBFT.Concrete.System\nopen import LibraBFT.Concrete.System.Parameters\nimport LibraBFT.Concrete.Properties.Common as Common\nimport LibraBFT.Concrete.Properties.VotesOnce as VO\nopen import LibraBFT.Impl.Consensus.Network as Network\nopen import LibraBFT.Impl.Consensus.Network.Properties as NetworkProps\nopen import LibraBFT.Impl.Consensus.RoundManager\nimport LibraBFT.Impl.Handle as Handle\nopen import LibraBFT.Impl.Handle.Properties\nopen import LibraBFT.Impl.IO.OBM.InputOutputHandlers\nopen import LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers\nopen import LibraBFT.Impl.Properties.Common\nopen import LibraBFT.ImplShared.Consensus.Types\nopen import LibraBFT.ImplShared.Consensus.Types.EpochDep\nopen import LibraBFT.ImplShared.Interface.Output\nopen import LibraBFT.ImplShared.Util.Crypto\nopen import LibraBFT.ImplShared.Util.Dijkstra.All\nopen ReachableSystemStateProps\nopen import LibraBFT.Impl.Properties.Util\nopen import Optics.All\nopen import Util.Lemmas\nopen import Util.PKCS\nopen import Util.Prelude\n\nopen Invariants\nopen RoundManagerTransProps\n\nopen import LibraBFT.Abstract.Types.EpochConfig UID NodeId\n\nopen ParamsWithInitAndHandlers Handle.InitHandler.initAndHandlers\nopen import LibraBFT.ImplShared.Util.HashCollisions Handle.InitHandler.initAndHandlers\n\nopen import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms\n Handle.InitHandler.initAndHandlers\n PeerCanSignForPK PeerCanSignForPK-stable\nopen Structural impl-sps-avp\nopen import LibraBFT.Impl.Handle.InitProperties\nopen initHandlerSpec\n\n-- This module proves the two \"VotesOnce\" proof obligations for our handler.\n\nmodule LibraBFT.Impl.Properties.VotesOnce (𝓔 : EpochConfig) where\n\n------------------------------------------------------------------------------\n\nnewVote⇒lv≡\n : ∀ {pre : SystemState}{pid s' acts v m pk}\n → ReachableSystemState pre\n → StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , acts)\n → v ⊂Msg m\n → send m ∈ acts\n → (sig : WithVerSig pk v)\n → Meta-Honest-PK pk\n → ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))\n → ¬ MsgWithSig∈ pk (ver-signature sig) (msgPool pre)\n → LastVoteIs s' v\n\nnewVote⇒lv≡ {pid = pid} preach (step-init rm×acts uni) v⊂m send∈acts sig hpk ¬bootstrap ¬mws∈pool\n with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts\n...| init-contract\n with initHandlerSpec.ContractOk.isInitPM init-contract send∈acts\n...| (_ , refl , noSigs)\n with v⊂m\n...| vote∈qc vs∈qc v≈rbld qc∈pm = ⊥-elim (noSigs vs∈qc qc∈pm)\n\nnewVote⇒lv≡{pre}{pid}{s'}{v = v}{m}{pk} preach sps@(step-msg{sndr , nm} m∈pool ini) (vote∈qc{vs}{qc} vs∈qc v≈rbld qc∈m) m∈acts sig hpk ¬bootstrap ¬msb4\n with cong _vSignature v≈rbld\n...| refl = ⊥-elim ∘′ ¬msb4 $ qcVoteSigsSentB4-handle pid preach sps m∈acts qc∈m sig vs∈qc v≈rbld ¬bootstrap\n\nnewVote⇒lv≡{pre}{pid}{v = v} preach (step-msg{sndr , P pm} m∈pool ini) vote∈vm m∈acts sig hpk ¬bootstrap ¬msb4\n with handleProposalSpec.contract! 0 pm (msgPool pre) (peerStates pre pid)\n...| handleProposalSpec.mkContract _ invalidProposal _ vac _ _\n -- TODO-2: DRY fail. This pattern arises several times in this file, where we need to know that\n -- the proposal being processed is valid, and to use handleProposalSpec to derive a contradiction\n -- if is not. Some are identical, some are not.\n with BlockId-correct? (pm ^∙ pmProposal)\n...| no ¬validProposal = ⊥-elim (sendVote∉actions {outs = handleOuts} {st = handlePre}\n (sym (proj₂ $ invalidProposal ¬validProposal)) m∈acts)\n where\n handlePre = peerStates pre pid\n handleOuts = LBFT-outs (handle pid (P pm) 0) (peerStates pre pid)\n\n...| yes refl\n with vac refl (nohc preach m∈pool pid ini (invariantsCorrect pid pre ini preach) refl refl)\n...| Voting.mkVoteAttemptCorrectWithEpochReq (inj₁ (_ , voteUnsent)) sdEpoch≡? =\n ⊥-elim (¬voteUnsent voteUnsent)\n where\n handleOuts = LBFT-outs (handle pid (P pm) 0) (peerStates pre pid)\n\n ¬voteUnsent : ¬ Voting.VoteUnsentCorrect (peerStates pre pid) _ _ _ _\n ¬voteUnsent (Voting.mkVoteUnsentCorrect noVoteMsgOuts _) =\n sendVote∉actions{outs = handleOuts}{st = peerStates pre pid}\n (sym noVoteMsgOuts) m∈acts\n...| Voting.mkVoteAttemptCorrectWithEpochReq (inj₂ (Voting.mkVoteSentCorrect (VoteMsg∙new v' _) rcvr voteMsgOuts vgCorrect)) sdEpoch≡? =\n sentVoteIsPostLV\n where\n handlePost = LBFT-post (handle pid (P pm) 0) (peerStates pre pid)\n handleOuts = LBFT-outs (handle pid (P pm) 0) (peerStates pre pid)\n\n sentVoteIsPostLV : LastVoteIs handlePost v\n sentVoteIsPostLV\n with Voting.VoteGeneratedCorrect.state vgCorrect\n ...| RoundManagerTransProps.mkVoteGenerated lv≡v _\n rewrite sym lv≡v\n = cong (just ∘ _^∙ vmVote) (sendVote∈actions{outs = handleOuts}{st = peerStates pre pid} (sym voteMsgOuts) m∈acts)\n\nnewVote⇒lv≡{pre}{pid}{s' = s'}{v = v} preach (step-msg{sndr , V vm} m∈pool ini) vote∈vm m∈outs sig hpk ¬bootstrap ¬msb4 =\n ⊥-elim (sendVote∉actions{outs = hvOut}{st = hvPre} (sym noVotes) m∈outs)\n where\n hvPre = peerStates pre pid\n hvOut = LBFT-outs (handleVote 0 vm) hvPre\n open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)\n\n------------------------------------------------------------------------------\n\noldVoteRound≤lvr\n : ∀ {pid pk v}{pre : SystemState}\n → (r : ReachableSystemState pre)\n → Meta-Honest-PK pk\n → (sig : WithVerSig pk v)\n → ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))\n → MsgWithSig∈ pk (ver-signature sig) (msgPool pre)\n → PeerCanSignForPK pre v pid pk\n → (peerStates pre pid) ^∙ rmEpoch ≡ (v ^∙ vEpoch)\n → v ^∙ vRound ≤ Meta.getLastVoteRound ((peerStates pre pid) ^∙ pssSafetyData-rm)\n\noldVoteRound≤lvr{pid} (step-s preach step@(step-peer{pid'} sp@(step-cheat cmc))) hpk sig ¬bootstrap mws∈pool pcsfpk epoch≡\n -- `pid`'s state is untouched by this step\n rewrite cheatStepDNMPeerStates₁{pid = pid'}{pid' = pid} sp unit\n = oldVoteRound≤lvr preach hpk sig ¬bootstrap mws∈prePool pcsfpkPre epoch≡\n where\n -- The cheat step could not have been where the signed message was introduced,\n -- so there must be a signed message in the pool prior to this\n mws∈prePool = ¬cheatForgeNew sp refl unit hpk mws∈pool (¬subst ¬bootstrap (msgSameSig mws∈pool))\n -- `pid` can sign for the message in the previous system state\n pcsfpkPre = PeerCanSignForPKProps.msb4 preach step pcsfpk hpk sig mws∈prePool\n\noldVoteRound≤lvr{pid}{v = v} step*@(step-s{pre = pre}{post = post@._} preach step@(step-peer{pid'} sp@(step-honest{st = ppost}{outs} sps))) hpk sig ¬bootstrap mws∈pool pcsfpk epoch≡\n with msgSameSig mws∈pool\n...| refl\n with newMsg⊎msgSentB4 preach sps hpk (msgSigned mws∈pool) ¬bootstrap (msg⊆ mws∈pool) (msg∈pool mws∈pool)\n...| Right msb4 = helpSentB4\n where\n pcsfpkPre : PeerCanSignForPK pre v pid _\n pcsfpkPre = PeerCanSignForPKProps.msb4 preach step pcsfpk hpk sig msb4\n\n ovrHyp : peerStates pre pid ^∙ rmEpoch ≡ v ^∙ vEpoch → v ^∙ vRound ≤ Meta.getLastVoteRound ((peerStates pre pid) ^∙ pssSafetyData-rm)\n ovrHyp ep≡ = oldVoteRound≤lvr{pre = pre} preach hpk sig ¬bootstrap msb4 pcsfpkPre ep≡\n\n helpSentB4 : v ^∙ vRound ≤ Meta.getLastVoteRound ((peerStates post pid) ^∙ pssSafetyData-rm)\n helpSentB4\n with pid ≟ pid'\n -- A step by `pid'` step cannot affect `pid`'s state\n ...| no pid≢\n rewrite sym (pids≢StepDNMPeerStates{pre = pre} sps pid≢)\n = ovrHyp epoch≡\n ...| yes refl = ≤-trans (ovrHyp epochPre≡) lvr≤\n where\n -- If a vote signed by a peer exists in the past, and that vote has an\n -- epoch id associated to it that is the same as the peer's post-state\n -- epoch, then the peer has that same epoch id in its immediately preceding\n -- pre-state.\n epochPre≡ : peerStates pre pid ^∙ rmEpoch ≡ v ^∙ vEpoch\n epochPre≡ =\n ReachableSystemStateProps.mws∈pool⇒epoch≡{v = v}{ppost}{outs} preach sps\n pcsfpkPre hpk sig ¬bootstrap msb4 epoch≡'\n where\n open ≡-Reasoning\n epoch≡' : ppost ^∙ rmEpoch ≡ v ^∙ vEpoch\n epoch≡' = begin\n ppost ^∙ rmEpoch ≡⟨ cong (_^∙ rmEpoch) (StepPeer-post-lemma sp) ⟩\n peerStates (StepPeer-post{pre = pre} sp) pid' ^∙ rmEpoch ≡⟨ epoch≡ ⟩\n v ^∙ vEpoch ∎\n\n ini : initialised pre pid' ≡ initd\n ini = ReachableSystemStateProps.mws∈pool⇒initd preach pcsfpkPre hpk sig ¬bootstrap msb4\n\n lvr≤ : Meta.getLastVoteRound ((peerStates pre pid) ^∙ pssSafetyData-rm) ≤ Meta.getLastVoteRound ((peerStates post pid) ^∙ pssSafetyData-rm)\n lvr≤\n rewrite sym (StepPeer-post-lemma{pre = pre} sp)\n = lastVotedRound-mono pid' pre preach ini sps\n (trans epochPre≡ (sym epoch≡))\n-- The vote was newly sent this round\n...| Left (m∈outs , pcsfpkPost , ¬msb4)\n-- ... and it really is the same vote, because there has not been a hash collision\n with sameSig⇒sameVoteData (msgSigned mws∈pool) sig (msgSameSig mws∈pool)\n...| Left nonInjSHA256 = ⊥-elim (PerReachableState.meta-no-collision step* nonInjSHA256)\n...| Right refl\n with PeerCanSignForPKProps.pidInjective pcsfpk pcsfpkPost refl\n...| refl = ≡⇒≤ vr≡lvrPost\n where\n vr≡lvrPost : v ^∙ vRound ≡ Meta.getLastVoteRound ((peerStates (StepPeer-post sp) pid) ^∙ pssSafetyData-rm)\n vr≡lvrPost\n rewrite sym (StepPeer-post-lemma sp)\n with newVote⇒lv≡{pre = pre}{pid = pid} preach sps (msg⊆ mws∈pool) m∈outs (msgSigned mws∈pool) hpk ¬bootstrap ¬msb4\n ...| lastVoteIsJust\n with ppost ^∙ pssSafetyData-rm ∙ sdLastVote\n ...| nothing = absurd (just _ ≡ nothing) case lastVoteIsJust of λ ()\n ...| just _ rewrite just-injective (sym lastVoteIsJust) = refl\n\n------------------------------------------------------------------------------\n\nsameERasLV⇒sameId-lem₁ :\n ∀ {pid pid' pk s acts}{pre : SystemState}\n → ReachableSystemState pre\n → (sp : StepPeer pre pid' s acts)\n → ∀ {v v'} → Meta-Honest-PK pk\n → PeerCanSignForPK (StepPeer-post sp) v pid pk\n → (sig' : WithVerSig pk v') → ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig'))\n → (mws : MsgWithSig∈ pk (ver-signature sig') (msgPool pre))\n → v ≡L v' at vEpoch → v ≡L v' at vRound\n → Σ[ mws ∈ MsgWithSig∈ pk (ver-signature sig') (msgPool pre) ]\n (¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature ∘ msgSigned $ mws)\n × PeerCanSignForPK pre v pid pk\n × v ≡L msgPart mws at vEpoch\n × v ≡L msgPart mws at vRound\n × msgPart mws ≡L v' at vProposedId)\n\nsameERasLV⇒sameId-lem₁{pid}{pid'}{pk}{pre = pre} rss sp {v}{v'} hpk pcsfpk sig' ¬bootstrap mws ≡epoch ≡round =\n mws , ¬bootstrap' , pcsfpkPre\n , trans ≡epoch (cong (_^∙ vdProposed ∙ biEpoch) (sym ≡voteData))\n , trans ≡round (cong (_^∙ vdProposed ∙ biRound) (sym ≡voteData))\n , cong (_^∙ vdProposed ∙ biId) ( ≡voteData)\n where\n -- That message has the same signature as `v'`, so it has the same vote data\n -- (unless there was a collision, which we currently assume does not occur).\n ≡voteData : msgPart mws ≡L v' at vVoteData\n ≡voteData = ⊎-elimˡ (PerReachableState.meta-no-collision rss) (sameSig⇒sameVoteData sig' (msgSigned mws) (sym ∘ msgSameSig $ mws))\n\n ¬bootstrap' : ¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature ∘ msgSigned $ mws)\n ¬bootstrap' rewrite msgSameSig mws = ¬bootstrap\n\n -- The peer can sign for `v` now, so it can sign for `v` in the preceeding\n -- step, because there is an honestly signed message part for the peer's pubkey in the\n -- current epoch already in the pool.\n pcsfpkPre : PeerCanSignForPK pre v pid pk\n pcsfpkPre = PeerCanSignForPKProps.msb4-eid≡ rss (step-peer sp) hpk pcsfpk ≡epoch sig' mws\n\nsameERasLV⇒sameId\n : ∀ {pid pid' pk}{st : SystemState}\n → ReachableSystemState st\n → ∀{v v' m'} → Meta-Honest-PK pk\n → just v ≡ peerStates st pid ^∙ pssSafetyData-rm ∙ sdLastVote\n → PeerCanSignForPK st v pid pk\n → v' ⊂Msg m' → (pid' , m') ∈ (msgPool st)\n → (sig' : WithVerSig pk v') → ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig'))\n → v ≡L v' at vEpoch → v ≡L v' at vRound\n → v ≡L v' at vProposedId\n-- Cheat steps cannot be where an honestly signed message originated.\nsameERasLV⇒sameId{pid}{pid'}{pk} (step-s{pre = pre} rss (step-peer sp@(step-cheat cmc))) {v}{v'}{m'} hpk ≡pidLV pcsfpk v'⊂m' m'∈pool sig' ¬bootstrap ≡epoch ≡round\n with sameERasLV⇒sameId-lem₁ rss sp hpk pcsfpk sig' ¬bootstrap mws ≡epoch ≡round\n where\n -- Track down the honestly signed message which existed before.\n mws : MsgWithSig∈ pk (ver-signature sig') (msgPool pre)\n mws = ¬cheatForgeNew sp refl unit hpk (mkMsgWithSig∈ m' v' v'⊂m' pid' m'∈pool sig' refl) ¬bootstrap\n...| mws , ¬bootstrap' , pcsfpkPre , ≡epoch' , ≡round' , v'id≡ =\n trans (sameERasLV⇒sameId rss hpk ≡pidLVPre pcsfpkPre (msg⊆ mws) (msg∈pool mws) (msgSigned mws) ¬bootstrap' ≡epoch' ≡round') v'id≡\n where\n -- The state of `pid` is unchanged\n ≡pidLVPre : just v ≡ peerStates pre pid ^∙ pssSafetyData-rm ∙ sdLastVote\n ≡pidLVPre = trans ≡pidLV (cong (_^∙ pssSafetyData-rm ∙ sdLastVote) (cheatStepDNMPeerStates₁ sp unit))\n\n-- Initialization steps cannot be where an honestly signed message originated\nsameERasLV⇒sameId {pid} {pid'} {pk}\n (step-s rss step@(step-peer{pre = pre} sp@(step-honest{pid“} sps@(step-init {rm} rm×acts uni))))\n {v} {v'} {m'} hpk ≡pidLV pcsfpk v'⊂m' m'∈pool sig' ¬bootstrap ≡epoch ≡round\n with pid ≟ pid“\n -- If this isn't `pid`, the step does not affect `pid`'s state\n...| no pid≢\n rewrite sym $ pids≢StepDNMPeerStates{pre = pre} sps pid≢\n = sameERasLV⇒sameId rss hpk ≡pidLV pcsfpkPre v'⊂m' (m'∈poolb4 v'⊂m') sig' ¬bootstrap ≡epoch ≡round\n where\n\n m'∈poolb4 : v' ⊂Msg m' → (pid' , m') ∈ (msgPool pre)\n m'∈poolb4 v'⊂m'\n with Any-++⁻ _ m'∈pool\n ...| inj₂ x = x\n ...| inj₁ x\n with initHandlerSpec.contract pid“ fakeBootstrapInfo rm×acts\n ...| init-contract\n with initHandlerSpec.ContractOk.isInitPM init-contract (proj₁ (senderMsgPair∈⇒send∈ _ x))\n ...| (pm , refl , noSigs)\n with v'⊂m'\n ...| vote∈qc vs∈qc v≈rbld qc∈nm\n = ⊥-elim (noSigs vs∈qc qc∈nm)\n\n mws : MsgWithSig∈ pk (ver-signature sig') (msgPool pre)\n mws = mkMsgWithSig∈ _ _ v'⊂m' _ (m'∈poolb4 v'⊂m') sig' refl\n\n pcsfpkPre : PeerCanSignForPK pre v pid pk\n pcsfpkPre = PeerCanSignForPKProps.msb4-eid≡ rss step hpk pcsfpk ≡epoch sig' mws\n -- If this is `pid`, the last vote cannot be a `just`!\n...| yes refl\n rewrite sym (StepPeer-post-lemma sp)\n with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts\n...| init-contract\n with initHandlerSpec.ContractOk.sdLVnothing init-contract\n...| lv≡nothing\n = absurd just v ≡ nothing case trans ≡pidLV lv≡nothing of λ ()\n\nsameERasLV⇒sameId{pid}{pid'}{pk} (step-s rss (step-peer{pre = pre} sp@(step-honest{pid“} sps@(step-msg{sndr , m} m∈pool ini)))) {v}{v'} hpk ≡pidLV pcsfpk v'⊂m' m'∈pool sig' ¬bootstrap ≡epoch ≡round\n with newMsg⊎msgSentB4 rss sps hpk sig' ¬bootstrap v'⊂m' m'∈pool\n-- The message has been sent before\n...| Right mws'\n with sameERasLV⇒sameId-lem₁ rss sp hpk pcsfpk sig' ¬bootstrap mws' ≡epoch ≡round\n...| mws , ¬bootstrap' , pcsfpkPre , ≡epoch' , ≡round' , v'id≡\n with pid ≟ pid“\n -- If this isn't `pid`, the step does not affect `pid`'s state\n...| no pid≢\n rewrite sym $ pids≢StepDNMPeerStates{pre = pre} sps pid≢\n = trans (sameERasLV⇒sameId rss hpk ≡pidLV pcsfpkPre (msg⊆ mws) (msg∈pool mws) (msgSigned mws) ¬bootstrap' ≡epoch' ≡round') v'id≡\n -- This is `pid`, so we need to know what message it was processing\n...| yes refl\n rewrite sym $ StepPeer-post-lemma{pre = pre} sp\n = trans (sameERasLV⇒sameId rss hpk (≡pidLVPre m m∈pool ≡pidLV) pcsfpkPre (msg⊆ mws) (msg∈pool mws) (msgSigned mws) ¬bootstrap' ≡epoch' ≡round') v'id≡\n where\n ≡pidLVPre : (m : NetworkMsg) → (sndr , m) ∈ msgPool pre → just v ≡ LBFT-post (handle pid m 0) (peerStates pre pid) ^∙ pssSafetyData-rm ∙ sdLastVote → just v ≡ peerStates pre pid ^∙ pssSafetyData-rm ∙ sdLastVote\n -- Last vote doesn't change when processing a vote message\n ≡pidLVPre (V vm) m∈pool ≡pidLV = begin\n just v ≡⟨ ≡pidLV ⟩\n hvPos ^∙ pssSafetyData-rm ∙ sdLastVote ≡⟨ cong (_^∙ sdLastVote) (sym noSDChange) ⟩\n hvPre ^∙ pssSafetyData-rm ∙ sdLastVote ∎\n where\n open ≡-Reasoning\n\n hvPre = peerStates pre pid\n hvPos = LBFT-post (handleVote 0 vm) hvPre\n hvOut = LBFT-outs (handleVote 0 vm) hvPre\n\n open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)\n\n -- Commit messages are only for reasoning about correctness\n ≡pidLVPre (C cm) m∈pool ≡pidLV = ≡pidLV\n\n ≡pidLVPre (P pm) m∈pool ≡pidLV = analyzeVoteAttempt\n where\n hpPre = peerStates pre pid“\n hpPos = LBFT-post (handleProposal 0 pm) hpPre\n\n open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm (msgPool pre) hpPre)\n renaming (rmInv to rmInvP)\n open Invariants.RoundManagerInv (invariantsCorrect pid“ pre ini rss)\n\n -- when the last vote is the same in pre and post states\n module OldVote (lv≡ : hpPre ≡L hpPos at pssSafetyData-rm ∙ sdLastVote) where\n open ≡-Reasoning\n ≡pidLVPre₁ : just v ≡ hpPre ^∙ pssSafetyData-rm ∙ sdLastVote\n ≡pidLVPre₁ = begin\n just v ≡⟨ ≡pidLV ⟩\n hpPos ^∙ pssSafetyData-rm ∙ sdLastVote ≡⟨ sym lv≡ ⟩\n hpPre ^∙ pssSafetyData-rm ∙ sdLastVote ∎\n\n -- When a new vote is generated, its round is strictly greater than that of the previous vote we attempted to send.\n module NewVote\n (vote : Vote) (lv≡v : just vote ≡ hpPos ^∙ pssSafetyData-rm ∙ sdLastVote)\n (lvr< : hpPre [ _<_ ]L hpPos at pssSafetyData-rm ∙ sdLastVotedRound)\n (lvr≡ : vote ^∙ vRound ≡ hpPos ^∙ pssSafetyData-rm ∙ sdLastVotedRound)\n (sdEpoch≡ : hpPre ^∙ pssSafetyData-rm ∙ sdEpoch ≡ pm ^∙ pmProposal ∙ bEpoch)\n (blockTriggered : Voting.VoteMadeFromBlock vote (pm ^∙ pmProposal))\n where\n\n -- `vote` comes from the peer handler contract\n v≡vote : v ≡ vote\n v≡vote = just-injective $ begin\n just v ≡⟨ ≡pidLV ⟩\n hpPos ^∙ pssSafetyData-rm ∙ sdLastVote ≡⟨ sym lv≡v ⟩\n just vote ∎\n where open ≡-Reasoning\n\n -- The round of `v'` must be less than the round of the vote stored in `sdLastVote`\n rv'≤lvrPre : v' ^∙ vRound ≤ Meta.getLastVoteRound (hpPre ^∙ pssSafetyData-rm)\n rv'≤lvrPre = oldVoteRound≤lvr rss hpk sig' ¬bootstrap mws pcsfpkPre'\n (ReachableSystemStateProps.mws∈pool⇒epoch≡ rss (step-msg m∈pool ini)\n pcsfpkPre' hpk sig' ¬bootstrap mws ≡epoch“)\n where\n pcsfpkPre' = peerCanSignEp≡ pcsfpkPre ≡epoch\n\n open ≡-Reasoning\n ≡epoch“ : hpPos ^∙ rmEpoch ≡ v' ^∙ vEpoch\n ≡epoch“ = begin\n hpPos ^∙ rmEpoch ≡⟨ sym noEpochChange ⟩\n hpPre ^∙ rmEpoch ≡⟨ rmEpochsMatch ⟩\n hpPre ^∙ pssSafetyData-rm ∙ sdEpoch ≡⟨ sdEpoch≡ ⟩\n pm ^∙ pmProposal ∙ bEpoch ≡⟨ sym $ Voting.VoteMadeFromBlock.epoch≡ blockTriggered ⟩\n vote ^∙ vEpoch ≡⟨ cong (_^∙ vEpoch) (sym v≡vote) ⟩\n v ^∙ vEpoch ≡⟨ ≡epoch ⟩\n v' ^∙ vEpoch ∎\n\n rv' _ _ rv'>rv = ⊥-elim (≤⇒≯ rv'≤rv rv'>rv)\n\nvotesOnce₁{pid = pid}{pid'}{pk = pk}{pre = pre} preach sps@(step-msg{sndr , V vm} m∈pool ini){v}{m}{v'}{m'} hpk v⊂m m∈acts sig ¬bootstrap ¬msb vspk v'⊂m' m'∈pool sig' ¬bootstrap' eid≡\n with v⊂m\n...| vote∈qc vs∈qc v≈rbld qc∈m rewrite cong _vSignature v≈rbld =\n ⊥-elim ∘′ ¬msb $ qcVoteSigsSentB4-handle pid preach sps m∈acts qc∈m sig vs∈qc v≈rbld ¬bootstrap\n...| vote∈vm =\n ⊥-elim (sendVote∉actions{outs = hvOut}{st = hvPre} (sym noVotes) m∈acts)\n where\n hvPre = peerStates pre pid\n hvOut = LBFT-outs (handleVote 0 vm) hvPre\n open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)\n\n------------------------------------------------------------------------------\n\nvotesOnce₂ : VO.ImplObligation₂ Handle.InitHandler.initAndHandlers 𝓔\n\nvotesOnce₂ {pid} {pk = pk} {pre} rss\n (step-init {rm} rm×acts uni)\n hpk v⊂m m∈acts sig ¬bootstrap ¬msb4 pcsfpk v'⊂m' m'∈acts sig' ¬bootstrap' ¬msb4' pcsfpk' ≡epoch ≡round\n with initHandlerSpec.contract pid fakeBootstrapInfo rm×acts\n...| init-contract\n with initHandlerSpec.ContractOk.isInitPM init-contract m∈acts\n...| (_ , refl , noSigs)\n with v⊂m\n...| vote∈qc vs∈qc v≈rbld qc∈pm = ⊥-elim (noSigs vs∈qc qc∈pm)\n\nvotesOnce₂{pid}{pk = pk}{pre} rss (step-msg{sndr , m“} m“∈pool ini){v}{v' = v'} hpk v⊂m m∈acts sig ¬bootstrap ¬msb4 pcsfpk v'⊂m' m'∈acts sig' ¬bootstrap' ¬msb4' pcsfpk' ≡epoch ≡round\n with v⊂m\n...| vote∈qc vs∈qc v≈rbld qc∈m rewrite cong _vSignature v≈rbld =\n ⊥-elim ∘′ ¬msb4 $ qcVoteSigsSentB4-handle pid rss (step-msg m“∈pool ini) m∈acts qc∈m sig vs∈qc v≈rbld ¬bootstrap\n...| vote∈vm\n with v'⊂m'\n...| vote∈qc vs∈qc' v≈rbld' qc∈m' rewrite cong _vSignature v≈rbld' =\n ⊥-elim ∘′ ¬msb4' $ qcVoteSigsSentB4-handle pid rss (step-msg m“∈pool ini) m'∈acts qc∈m' sig' vs∈qc' v≈rbld' ¬bootstrap'\n...| vote∈vm\n with m“\n...| P pm = cong (_^∙ vProposedId) v≡v'\n where\n hpPool = msgPool pre\n hpPre = peerStates pre pid\n hpOut = LBFT-outs (handleProposal 0 pm) hpPre\n open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hpPool hpPre)\n\n v≡v' : v ≡ v'\n v≡v'\n with BlockId-correct? (pm ^∙ pmProposal)\n ...| no ¬validProposal = ⊥-elim (sendVote∉actions {outs = hpOut} {st = hpPre} (sym (proj₂ $ invalidProposal ¬validProposal)) m∈acts)\n ...| yes refl\n with voteAttemptCorrect refl (nohc rss m“∈pool pid ini (invariantsCorrect pid pre ini rss) refl refl )\n ...| Voting.mkVoteAttemptCorrectWithEpochReq (Left (_ , Voting.mkVoteUnsentCorrect noVoteMsgOuts _)) _ =\n ⊥-elim (sendVote∉actions{outs = hpOut}{st = hpPre} (sym noVoteMsgOuts) m∈acts)\n ...| Voting.mkVoteAttemptCorrectWithEpochReq (Right (Voting.mkVoteSentCorrect vm pid voteMsgOuts _)) _ = begin\n v ≡⟨ cong (_^∙ vmVote) (sendVote∈actions{outs = hpOut}{st = hpPre} (sym voteMsgOuts) m∈acts) ⟩\n vm ^∙ vmVote ≡⟨ (sym $ cong (_^∙ vmVote) (sendVote∈actions{outs = hpOut}{st = hpPre} (sym voteMsgOuts) m'∈acts)) ⟩\n v' ∎\n where\n open ≡-Reasoning\n...| V vm = ⊥-elim (sendVote∉actions{outs = hvOut}{st = hvPre} (sym noVotes) m∈acts)\n where\n hvPre = peerStates pre pid\n hvOut = LBFT-outs (handle pid (V vm) 0) hvPre\n open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool pre) hvPre)\n", "meta": {"hexsha": "8e071ba4b8532447d7491e3c8f57d7223e714738", "size": 33911, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/LibraBFT/Impl/Properties/VotesOnce.agda", "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": ["UPL-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/LibraBFT/Impl/Properties/VotesOnce.agda", "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_licenses": ["UPL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/LibraBFT/Impl/Properties/VotesOnce.agda", "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": ["UPL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.3803030303, "max_line_length": 228, "alphanum_fraction": 0.6522072484, "num_tokens": 11909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.32082130731838393, "lm_q1q2_score": 0.1616638363949401}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Conversion.Transitivity where\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.RedSteps\nopen import Definition.Conversion\nopen import Definition.Conversion.Soundness\nopen import Definition.Conversion.Stability\nopen import Definition.Conversion.Whnf\nopen import Definition.Conversion.Conversion\nopen import Definition.Conversion.Reduction\nopen import Definition.Conversion.Lift\nopen import Definition.Typed.Consequences.Syntactic\nopen import Definition.Typed.Consequences.Injectivity\nimport Definition.Typed.Consequences.Inequality as WF\nopen import Definition.Typed.Consequences.Syntactic\nopen import Definition.Typed.Consequences.Substitution\nopen import Definition.Typed.Consequences.NeTypeEq\nopen import Definition.Typed.Consequences.SucCong\nopen import Definition.Typed.Consequences.Inversion\nopen import Definition.Typed.Consequences.Reduction\n\nopen import Tools.Nat\nopen import Tools.Product\nopen import Tools.Empty\nimport Tools.PropositionalEquality as PE\n\n\nmutual\n -- Transitivity of algorithmic equality of neutrals.\n trans~↑ : ∀ {t u v A B Γ}\n → Γ ⊢ t ~ u ↑ A\n → Γ ⊢ u ~ v ↑ B\n → Γ ⊢ t ~ v ↑ A\n × Γ ⊢ A ≡ B\n trans~↑ (var-refl x₁ x≡y) (var-refl x₂ x≡y₁) =\n var-refl x₁ (PE.trans x≡y x≡y₁)\n , neTypeEq (var _) x₁\n (PE.subst (λ x → _ ⊢ var x ∷ _) (PE.sym x≡y)\n x₂)\n trans~↑ (app-cong t~u a<>b) (app-cong u~v b<>c) =\n let t~v , ΠFG≡ΠF′G′ = trans~↓ t~u u~v\n F≡F₁ , G≡G₁ = injectivity ΠFG≡ΠF′G′\n a<>c = transConv↑Term F≡F₁ a<>b b<>c\n in app-cong t~v a<>c , substTypeEq G≡G₁ (soundnessConv↑Term a<>b)\n trans~↑ (fst-cong t~u) (fst-cong u~v) =\n let t~v , ΣFG≡ΣF′G′ = trans~↓ t~u u~v\n F≡F′ , _ = Σ-injectivity ΣFG≡ΣF′G′\n in fst-cong t~v , F≡F′\n trans~↑ (snd-cong t~u) (snd-cong u~v) =\n let t~v , ΣFG≡ΣF′G′ = trans~↓ t~u u~v\n F≡F′ , G≡G′ = Σ-injectivity ΣFG≡ΣF′G′\n in snd-cong t~v , substTypeEq G≡G′ (soundness~↑ (fst-cong t~u))\n trans~↑ (natrec-cong A<>B a₀<>b₀ aₛ<>bₛ t~u) (natrec-cong B<>C b₀<>c₀ bₛ<>cₛ u~v) =\n let ⊢Γ = wf (proj₁ (syntacticEqTerm (soundness~↓ t~u)))\n A≡B = soundnessConv↑ A<>B\n F[0]≡F₁[0] = substTypeEq A≡B (refl (zeroⱼ ⊢Γ))\n ΠℕFs≡ΠℕF₁s = sucCong A≡B\n A<>C = transConv↑ A<>B B<>C\n a₀<>c₀ = transConv↑Term F[0]≡F₁[0] a₀<>b₀ b₀<>c₀\n aₛ<>cₛ = transConv↑Term ΠℕFs≡ΠℕF₁s aₛ<>bₛ bₛ<>cₛ\n t~v , _ = trans~↓ t~u u~v\n in natrec-cong A<>C a₀<>c₀ aₛ<>cₛ t~v\n , substTypeEq A≡B (soundness~↓ t~u)\n trans~↑ (Emptyrec-cong A<>B t~u) (Emptyrec-cong B<>C u~v) =\n let A≡B = soundnessConv↑ A<>B\n A<>C = transConv↑ A<>B B<>C\n t~v , _ = trans~↓ t~u u~v\n in Emptyrec-cong A<>C t~v , A≡B\n\n -- Transitivity of algorithmic equality of neutrals with types in WHNF.\n trans~↓ : ∀ {t u v A B Γ}\n → Γ ⊢ t ~ u ↓ A\n → Γ ⊢ u ~ v ↓ B\n → Γ ⊢ t ~ v ↓ A\n × Γ ⊢ A ≡ B\n trans~↓ ([~] A₁ D whnfA k~l) ([~] A₂ D₁ whnfA₁ k~l₁) =\n let t~v , A≡B = trans~↑ k~l k~l₁\n in [~] A₁ D whnfA t~v\n , trans (sym (subset* D))\n (trans A≡B\n (subset* D₁))\n\n -- Transitivity of algorithmic equality of types.\n transConv↑ : ∀ {A B C Γ}\n → Γ ⊢ A [conv↑] B\n → Γ ⊢ B [conv↑] C\n → Γ ⊢ A [conv↑] C\n transConv↑ ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′)\n ([↑] A″ B″ D₁ D″ whnfA″ whnfB″ A′<>B″) =\n [↑] A′ B″ D D″ whnfA′ whnfB″\n (transConv↓ A′<>B′\n (PE.subst (λ x → _ ⊢ x [conv↓] B″)\n (whrDet* (D₁ , whnfA″)\n (D′ , whnfB′))\n A′<>B″))\n transConv↑′ : ∀ {A B C Γ Δ}\n → ⊢ Γ ≡ Δ\n → Γ ⊢ A [conv↑] B\n → Δ ⊢ B [conv↑] C\n → Γ ⊢ A [conv↑] C\n transConv↑′ Γ≡Δ aConvB bConvC =\n transConv↑ aConvB (stabilityConv↑ (symConEq Γ≡Δ) bConvC)\n\n -- Transitivity of algorithmic equality of types in WHNF.\n transConv↓ : ∀ {A B C Γ}\n → Γ ⊢ A [conv↓] B\n → Γ ⊢ B [conv↓] C\n → Γ ⊢ A [conv↓] C\n transConv↓ (U-refl x) (U-refl x₁) = U-refl x\n transConv↓ (ℕ-refl x) (ℕ-refl x₁) = ℕ-refl x\n transConv↓ (Empty-refl x) (Empty-refl x₁) = Empty-refl x\n transConv↓ (Unit-refl x) (Unit-refl x₁) = Unit-refl x\n transConv↓ (ne x) (ne x₁) =\n let A~C , U≡U = trans~↓ x x₁\n in ne A~C\n transConv↓ (Π-cong x x₁ x₂) (Π-cong x₃ x₄ x₅) =\n Π-cong x (transConv↑ x₁ x₄) (transConv↑′ (reflConEq (wf x) ∙ soundnessConv↑ x₁) x₂ x₅)\n transConv↓ (Σ-cong x x₁ x₂) (Σ-cong x₃ x₄ x₅) =\n Σ-cong x (transConv↑ x₁ x₄) (transConv↑′ (reflConEq (wf x) ∙ soundnessConv↑ x₁) x₂ x₅)\n -- Refutable cases\n transConv↓ (U-refl x) (ne ([~] A D whnfB ()))\n transConv↓ (ℕ-refl x) (ne ([~] A D whnfB ()))\n transConv↓ (Empty-refl x) (ne ([~] A D whnfB ()))\n transConv↓ (Π-cong x x₁ x₂) (ne ([~] A D whnfB ()))\n transConv↓ (Σ-cong x x₁ x₂) (ne ([~] A D whnfB ()))\n transConv↓ (ne ([~] A₁ D whnfB ())) (U-refl x₁)\n transConv↓ (ne ([~] A₁ D whnfB ())) (ℕ-refl x₁)\n transConv↓ (ne ([~] A₁ D whnfB ())) (Empty-refl x₁)\n transConv↓ (ne ([~] A₁ D whnfB ())) (Π-cong x₁ x₂ x₃)\n transConv↓ (ne ([~] A₁ D whnfB ())) (Σ-cong x₁ x₂ x₃)\n\n -- Transitivity of algorithmic equality of terms.\n transConv↑Term : ∀ {t u v A B Γ}\n → Γ ⊢ A ≡ B\n → Γ ⊢ t [conv↑] u ∷ A\n → Γ ⊢ u [conv↑] v ∷ B\n → Γ ⊢ t [conv↑] v ∷ A\n transConv↑Term A≡B ([↑]ₜ B₁ t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u)\n ([↑]ₜ B₂ t″ u″ D₁ d₁ d″ whnfB₁ whnft″ whnfu″ t<>u₁) =\n let B₁≡B₂ = trans (sym (subset* D))\n (trans A≡B\n (subset* D₁))\n d₁″ = conv* d″ (sym B₁≡B₂)\n d₁′ = conv* d′ B₁≡B₂\n in [↑]ₜ B₁ t′ u″ D d d₁″ whnfB whnft′ whnfu″\n (transConv↓Term B₁≡B₂ t<>u\n (PE.subst (λ x → _ ⊢ x [conv↓] u″ ∷ B₂)\n (whrDet*Term (d₁ , whnft″)\n (d₁′ , whnfu′))\n t<>u₁))\n\n transConv↑Term′ : ∀ {t u v A B Γ Δ}\n → ⊢ Γ ≡ Δ\n → Γ ⊢ A ≡ B\n → Γ ⊢ t [conv↑] u ∷ A\n → Δ ⊢ u [conv↑] v ∷ B\n → Γ ⊢ t [conv↑] v ∷ A\n transConv↑Term′ Γ≡Δ A≡B tConvU uConvV =\n transConv↑Term A≡B tConvU (stabilityConv↑Term (symConEq Γ≡Δ) uConvV)\n\n -- Transitivity of algorithmic equality of terms in WHNF.\n transConv↓Term : ∀ {t u v A B Γ}\n → Γ ⊢ A ≡ B\n → Γ ⊢ t [conv↓] u ∷ A\n → Γ ⊢ u [conv↓] v ∷ B\n → Γ ⊢ t [conv↓] v ∷ A\n transConv↓Term A≡B (ℕ-ins x) (ℕ-ins x₁) =\n ℕ-ins (proj₁ (trans~↓ x x₁))\n transConv↓Term A≡B (Empty-ins x) (Empty-ins x₁) =\n Empty-ins (proj₁ (trans~↓ x x₁))\n transConv↓Term A≡B (Unit-ins t~u) uConvV =\n let _ , [t] , _ = syntacticEqTerm (soundness~↓ t~u)\n _ , tNe , _ = ne~↓ t~u\n _ , _ , [v] = syntacticEqTerm (soundnessConv↓Term uConvV)\n [v] = conv [v] (sym A≡B)\n _ , _ , vWhnf = whnfConv↓Term uConvV\n in η-unit [t] [v] (ne tNe) vWhnf\n transConv↓Term A≡B (ne-ins t u x x₁) (ne-ins t′ u′ x₂ x₃) =\n ne-ins t (conv u′ (sym A≡B)) x\n (proj₁ (trans~↓ x₁ x₃))\n transConv↓Term A≡B (univ x x₁ x₂) (univ x₃ x₄ x₅) =\n univ x x₄ (transConv↓ x₂ x₅)\n transConv↓Term A≡B (zero-refl x) conv↓ =\n convConv↓Term (reflConEq x) (sym A≡B) ℕₙ conv↓\n transConv↓Term A≡B conv↓ (zero-refl _) = conv↓\n transConv↓Term A≡B (suc-cong x) (suc-cong x₁) =\n suc-cong (transConv↑Term A≡B x x₁)\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (η-eq x₅ x₆ y₂ y₃ x₇) =\n let F₁≡F , G₁≡G = injectivity A≡B\n in η-eq x₁ (conv x₆ (sym A≡B))\n y y₃ (transConv↑Term′ (reflConEq (wfEq F₁≡F) ∙ F₁≡F) G₁≡G x₃ x₇)\n transConv↓Term A≡B (Σ-η ⊢p ⊢r pProd rProd fstConv sndConv)\n (Σ-η ⊢r′ ⊢q _ qProd fstConv′ sndConv′) =\n let F≡ , G≡ = Σ-injectivity A≡B\n Gfst≡ = substTypeEq G≡ (soundnessConv↑Term fstConv)\n in Σ-η ⊢p (conv ⊢q (sym A≡B)) pProd qProd\n (transConv↑Term F≡ fstConv fstConv′)\n (transConv↑Term Gfst≡ sndConv sndConv′)\n transConv↓Term A≡B (η-unit [t] [u] tUnit uUnit) uConvV =\n let _ , _ , [v] = syntacticEqTerm (soundnessConv↓Term uConvV)\n [v] = conv [v] (sym A≡B)\n _ , _ , vWhnf = whnfConv↓Term uConvV\n in η-unit [t] [v] tUnit vWhnf\n\n -- Refutable cases\n transConv↓Term A≡B (ℕ-ins x) (ne-ins t u x₂ x₃) = ⊥-elim (WF.ℕ≢ne x₂ A≡B)\n transConv↓Term A≡B (ℕ-ins x) (univ x₂ x₃ x₄) = ⊥-elim (WF.U≢ℕ (sym A≡B))\n transConv↓Term A≡B (ℕ-ins x) (Empty-ins x₁) = ⊥-elim (WF.ℕ≢Emptyⱼ A≡B)\n transConv↓Term A≡B (ℕ-ins x) (Unit-ins x₁) = ⊥-elim (WF.ℕ≢Unitⱼ A≡B)\n transConv↓Term A≡B (ℕ-ins ([~] A D whnfB ())) (suc-cong x₂)\n transConv↓Term A≡B (ℕ-ins x) (η-eq x₃ x₄ y y₁ x₅) = ⊥-elim (WF.ℕ≢Π A≡B)\n transConv↓Term A≡B (ℕ-ins x₁) (Σ-η x₂ x₃ x₄ x₅ x₆ x₇) = ⊥-elim (WF.ℕ≢Σ A≡B)\n transConv↓Term A≡B (ℕ-ins x) (η-unit _ _ _ _) = ⊥-elim (WF.ℕ≢Unitⱼ A≡B)\n transConv↓Term A≡B (Empty-ins x) (ne-ins t u x₂ x₃) = ⊥-elim (WF.Empty≢neⱼ x₂ A≡B)\n transConv↓Term A≡B (Empty-ins x) (univ x₂ x₃ x₄) = ⊥-elim (WF.U≢Emptyⱼ (sym A≡B))\n transConv↓Term A≡B (Empty-ins x₁) (ℕ-ins x) = ⊥-elim (WF.ℕ≢Emptyⱼ (sym A≡B))\n transConv↓Term A≡B (Empty-ins x₁) (Unit-ins x) = ⊥-elim (WF.Empty≢Unitⱼ A≡B)\n transConv↓Term A≡B (Empty-ins ([~] A D whnfB ())) (suc-cong x₂)\n transConv↓Term A≡B (Empty-ins x) (η-eq x₃ x₄ y y₁ x₅) = ⊥-elim (WF.Empty≢Πⱼ A≡B)\n transConv↓Term A≡B (Empty-ins x₁) (Σ-η x₂ x₃ x₄ x₅ x₆ x₇) = ⊥-elim (WF.Empty≢Σⱼ A≡B)\n transConv↓Term A≡B (Empty-ins x₁) (η-unit _ _ _ _) = ⊥-elim (WF.Empty≢Unitⱼ A≡B)\n transConv↓Term A≡B (ne-ins t u x x₁) (ℕ-ins x₂) = ⊥-elim (WF.ℕ≢ne x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x x₁) (Empty-ins x₂) = ⊥-elim (WF.Empty≢neⱼ x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x x₁) (Unit-ins x₂) = ⊥-elim (WF.Unit≢neⱼ x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x x₁) (univ x₃ x₄ x₅) = ⊥-elim (WF.U≢ne x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x ([~] A D whnfB ())) (suc-cong x₃)\n transConv↓Term A≡B (ne-ins t u x x₁) (η-eq x₄ x₅ y y₁ x₆) = ⊥-elim (WF.Π≢ne x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x x₁) (Σ-η x₅ x₆ x₇ x₈ x₉ x₁₀) = ⊥-elim (WF.Σ≢ne x (sym A≡B))\n transConv↓Term A≡B (ne-ins t u x x₁) (η-unit _ _ _ _) = ⊥-elim (WF.Unit≢neⱼ x (sym A≡B))\n transConv↓Term A≡B (univ x x₁ x₂) (ℕ-ins x₃) = ⊥-elim (WF.U≢ℕ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (Empty-ins x₃) = ⊥-elim (WF.U≢Emptyⱼ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (Unit-ins x₃) = ⊥-elim (WF.U≢Unitⱼ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (ne-ins t u x₃ x₄) = ⊥-elim (WF.U≢ne x₃ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (suc-cong x₃) = ⊥-elim (WF.U≢ℕ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (η-eq x₄ x₅ y y₁ x₆) = ⊥-elim (WF.U≢Π A≡B)\n transConv↓Term A≡B (univ x₁ x₂ x₃) (Σ-η x₄ x₅ x₆ x₇ x₈ x₉) = ⊥-elim (WF.U≢Σ A≡B)\n transConv↓Term A≡B (univ x x₁ x₂) (η-unit _ _ _ _) = ⊥-elim (WF.U≢Unitⱼ A≡B)\n transConv↓Term A≡B (suc-cong x) (ℕ-ins ([~] A D whnfB ()))\n transConv↓Term A≡B (suc-cong x) (Empty-ins ([~] A D whnfB ()))\n transConv↓Term A≡B (suc-cong x) (ne-ins t u x₁ ([~] A D whnfB ()))\n transConv↓Term A≡B (suc-cong x) (univ x₁ x₂ x₃) = ⊥-elim (WF.U≢ℕ (sym A≡B))\n transConv↓Term A≡B (suc-cong x) (η-eq x₂ x₃ y y₁ x₄) = ⊥-elim (WF.ℕ≢Π A≡B)\n transConv↓Term A≡B (suc-cong x₁) (Σ-η x₂ x₃ x₄ x₅ x₆ x₇) = ⊥-elim (WF.ℕ≢Σ A≡B)\n transConv↓Term A≡B (suc-cong x) (η-unit _ _ _ _) = ⊥-elim (WF.ℕ≢Unitⱼ A≡B)\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (ℕ-ins x₄) = ⊥-elim (WF.ℕ≢Π (sym A≡B))\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (Empty-ins x₄) = ⊥-elim (WF.Empty≢Πⱼ (sym A≡B))\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (Unit-ins _) = ⊥-elim (WF.Unit≢Πⱼ (sym A≡B))\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (ne-ins t u x₄ x₅) = ⊥-elim (WF.Π≢ne x₄ A≡B)\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (univ x₄ x₅ x₆) = ⊥-elim (WF.U≢Π (sym A≡B))\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (suc-cong x₄) = ⊥-elim (WF.ℕ≢Π (sym A≡B))\n transConv↓Term A≡B (η-eq x₂ x₃ x₄ x₅ x₆) (Σ-η x₇ x₈ x₉ x₁₀ x₁₁ x₁₂) = ⊥-elim (WF.Π≢Σ A≡B)\n transConv↓Term A≡B (η-eq x₁ x₂ y y₁ x₃) (η-unit _ _ _ _) = ⊥-elim (WF.Unit≢Πⱼ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (ℕ-ins x₇) = ⊥-elim (WF.ℕ≢Σ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (Empty-ins x₇) = ⊥-elim (WF.Empty≢Σⱼ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (Unit-ins x₇) = ⊥-elim (WF.Unit≢Σⱼ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (ne-ins x₇ x₈ x₉ x₁₀) = ⊥-elim (WF.Σ≢ne x₉ A≡B)\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (univ x₇ x₈ x₉) = ⊥-elim (WF.U≢Σ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (suc-cong x₇) = ⊥-elim (WF.ℕ≢Σ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (η-eq x₈ x₉ x₁₀ x₁₁ x₁₂) = ⊥-elim (WF.Π≢Σ (sym A≡B))\n transConv↓Term A≡B (Σ-η x₁ x₂ x₃ x₄ x₅ x₆) (η-unit x₇ x₈ x₉ x₁₀) = ⊥-elim (WF.Unit≢Σⱼ (sym A≡B))\n\n-- Transitivity of algorithmic equality of types of the same context.\ntransConv : ∀ {A B C Γ}\n → Γ ⊢ A [conv↑] B\n → Γ ⊢ B [conv↑] C\n → Γ ⊢ A [conv↑] C\ntransConv A<>B B<>C = transConv↑ A<>B B<>C\n\n-- Transitivity of algorithmic equality of terms of the same context.\ntransConvTerm : ∀ {t u v A Γ}\n → Γ ⊢ t [conv↑] u ∷ A\n → Γ ⊢ u [conv↑] v ∷ A\n → Γ ⊢ t [conv↑] v ∷ A\ntransConvTerm t<>u u<>v =\n let t≡u = soundnessConv↑Term t<>u\n ⊢A , _ , _ = syntacticEqTerm t≡u\n in transConv↑Term (refl ⊢A) t<>u u<>v\n", "meta": {"hexsha": "5eb743dd3978e5db3cebb86a56369d94a0316c86", "size": 13610, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion/Transitivity.agda", "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Definition/Conversion/Transitivity.agda", "max_issues_repo_name": "Vtec234/logrel-mltt", "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Definition/Conversion/Transitivity.agda", "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.2624113475, "max_line_length": 98, "alphanum_fraction": 0.5510653931, "num_tokens": 6493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.31405055141190724, "lm_q1q2_score": 0.1607048818739721}} {"text": "open import cedille-types\nimport spans\nopen import ctxt\nimport cedille-options\nopen import general-util\n\nmodule type-inf\n (options : cedille-options.options)\n {mF : Set → Set}\n ⦃ _ : monad mF ⦄\n (check-term : ctxt → ex-tm → (T? : maybe type) →\n spans.spanM options {mF} (spans.check-ret options {mF} T? term))\n (check-type : ctxt → ex-tp → (k? : maybe kind) →\n spans.spanM options {mF} (spans.check-ret options {mF} k? type))\n where\n\nopen import spans options {mF}\nopen import rename\nopen import syntax-util\nopen import type-util\nopen import meta-vars options {mF}\nopen import resugar\nopen import subst\nopen import conversion\nopen import free-vars\nopen import constants\n\nrecord spine-data : Set where\n constructor mk-spine-data\n field\n spine-mvars : meta-vars\n spine-type : decortype\n spine-locale : ℕ\n spine-elab : meta-vars → term\n\ncheck-term-spine-elim : ctxt → spine-data → term × type\ncheck-term-spine-elim Γ (mk-spine-data Xs dt locl f~) =\n f~ Xs , meta-vars-subst-type' ff Γ Xs (decortype-to-type dt)\n-- elim-pair (maybe-else' (meta-vars-to-args Xs) ([] , Hole pi-gen) f~) recompose-apps ,\n-- meta-vars-subst-type' ff Γ Xs (decortype-to-type dt)\n\ncheck-term-spine : ctxt → ex-tm → (m : prototype) → 𝔹 → spanM (maybe spine-data)\n\ncheck-term-spine-return : meta-vars → decortype → ℕ → (meta-vars → term) → spanM (maybe spine-data)\ncheck-term-spine-return Xs dt locl f~ = return (just (mk-spine-data Xs dt locl f~))\n\n-- a flag indicating how aggresively we should be unfolding during matching.\n-- \"both\" is the backtracking flag. We will attempt \"both\" matches, which means\n-- first matching without unfolding, then if that fails unfolding the type once\n-- and continue matching the subexpresions with \"both\"\ndata match-unfolding-state : Set where\n match-unfolding-both match-unfolding-approx match-unfolding-hnf : match-unfolding-state\n\n-- main matching definitions\n-- --------------------------------------------------\n\n-- NOTE: these functions don't actually ever emit spans\nmatch-types : ctxt → meta-vars → local-vars → match-unfolding-state → (tpₓ tp : type) → spanM $ match-error-t meta-vars\nmatch-kinds : ctxt → meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars\nmatch-tpkds : ctxt → meta-vars → local-vars → match-unfolding-state → (tkₓ tk : tpkd) → spanM $ match-error-t meta-vars\n\nrecord match-prototype-data : Set where\n constructor mk-match-prototype-data\n field\n match-proto-mvars : meta-vars\n match-proto-dectp : decortype\n match-proto-error : 𝔹\nopen match-prototype-data\nmatch-prototype : ctxt → (Xs : meta-vars) (is-hnf : 𝔹) (tp : type) (pt : prototype) → spanM match-prototype-data\n\n-- substitutions used during matching\n-- --------------------------------------------------\n\n-- These have to be in the spanM monad because substitution can unlock a `stuck`\n-- decoration, causing another round of prototype matching (which invokes type matching)\n\nsubsth-decortype : ctxt → renamectxt → trie (Σi exprd ⟦_⟧) → decortype → spanM decortype\nsubsth-decortype Γ ρ σ (decor-type tp) = return $ decor-type (substh Γ ρ σ tp)\nsubsth-decortype Γ ρ σ (decor-arrow e? dom cod) =\n substh-decortype Γ ρ σ cod\n >>= λ cod → return $ decor-arrow e? (substh Γ ρ σ dom) cod\nsubsth-decortype Γ ρ σ (decor-decor e? x tk sol dt) =\n let x' = subst-rename-var-if Γ ρ x σ (decortype-to-type dt)\n Γ' = ctxt-var-decl x' Γ\n ρ' = renamectxt-insert ρ x x'\n in substh-decortype Γ' ρ' σ dt\n >>= λ dt' → return $ decor-decor e? x' (substh Γ ρ σ -tk tk) (substh-meta-var-sort Γ ρ σ sol) dt'\nsubsth-decortype Γ ρ σ (decor-stuck tp pt) =\n match-prototype Γ meta-vars-empty ff (substh Γ ρ σ tp) pt\n -- NOTE: its an invariant that if you start with no meta-variables,\n -- prototype matching produces no meta-variables as output\n >>= λ ret → return (match-proto-dectp ret)\n\nsubsth-decortype Γ ρ σ (decor-error tp pt) =\n return $ decor-error (substh Γ ρ σ tp) pt\n\nsubst-decortype : {ed : exprd} → ctxt → ⟦ ed ⟧ → var → decortype → spanM decortype\nsubst-decortype Γ s x dt = substh-decortype Γ empty-renamectxt (trie-single x (, s)) dt\n\nmeta-vars-subst-decortype' : (unfold : 𝔹) → ctxt → meta-vars → decortype → spanM decortype\nmeta-vars-subst-decortype' uf Γ Xs dt =\n substh-decortype Γ empty-renamectxt (meta-vars-get-sub Xs) dt\n >>= λ dt' → return $\n if uf then hnf-decortype Γ unfold-head-elab dt' tt else dt'\n\nmeta-vars-subst-decortype : ctxt → meta-vars → decortype → spanM decortype\nmeta-vars-subst-decortype = meta-vars-subst-decortype' tt\n\n\n-- unfolding a decorated type to reveal a term / type abstraction\n-- --------------------------------------------------\n\n{-# TERMINATING #-}\nmeta-vars-peel' : ctxt → span-location → meta-vars → decortype → spanM (𝕃 meta-var × decortype)\nmeta-vars-peel' Γ sl Xs (decor-decor e? x _ (meta-var-tp k mtp) dt) =\n let Y = meta-var-fresh-tp Xs x sl (k , mtp)\n Xs' = meta-vars-add Xs Y\n in subst-decortype Γ (meta-var-to-type-unsafe Y) x dt\n >>= λ dt' → meta-vars-peel' Γ sl Xs' dt'\n >>= λ ret → let Ys = fst ret ; rdt = snd ret\n in return $ Y :: Ys , rdt\nmeta-vars-peel' Γ sl Xs dt@(decor-decor e? x _ (meta-var-tm _ _) _) = return $ [] , dt\nmeta-vars-peel' Γ sl Xs dt@(decor-arrow _ _ _) = return $ [] , dt\n-- NOTE: vv The clause below will later generate a type error vv\nmeta-vars-peel' Γ sl Xs dt@(decor-stuck _ _) = return $ [] , dt\n-- NOTE: vv The clause below is an internal error, if reached vv\nmeta-vars-peel' Γ sl Xs dt@(decor-type _) = return $ [] , dt\nmeta-vars-peel' Γ sl Xs dt@(decor-error _ _) = return $ [] , dt\n\nmeta-vars-unfold-tmapp' : ctxt → span-location → meta-vars → decortype → spanM (𝕃 meta-var × is-tmabsd?)\nmeta-vars-unfold-tmapp' Γ sl Xs dt =\n meta-vars-subst-decortype Γ Xs dt\n >>= λ dt' → meta-vars-peel' Γ sl Xs dt'\n >>= λ where\n (Ys , dt'@(decor-arrow e? dom cod)) →\n return $ Ys , yes-tmabsd dt' e? ignored-var dom ff cod\n (Ys , dt'@(decor-decor e? x _ (meta-var-tm dom _) cod)) →\n return $ Ys , yes-tmabsd dt' e? x dom (is-free-in x (decortype-to-type cod)) cod\n (Ys , dt@(decor-decor _ _ _ (meta-var-tp _ _) _)) →\n return $ Ys , not-tmabsd dt\n-- NOTE: vv this is a type error vv\n (Ys , dt@(decor-stuck _ _)) →\n return $ Ys , not-tmabsd dt\n-- NOTE: vv this is an internal error, if reached vv\n (Ys , dt@(decor-type _)) →\n return $ Ys , not-tmabsd dt\n (Ys , dt@(decor-error _ _)) →\n return $ Ys , not-tmabsd dt\n\nmeta-vars-unfold-tpapp' : ctxt → meta-vars → decortype → spanM is-tpabsd?\nmeta-vars-unfold-tpapp' Γ Xs dt =\n meta-vars-subst-decortype Γ Xs dt\n >>= λ where\n (dt″@(decor-decor e? x _ (meta-var-tp k mtp) dt')) →\n return $ yes-tpabsd dt″ e? x k (flip maybe-map mtp meta-var-sol.sol) dt'\n (dt″@(decor-decor _ _ _ (meta-var-tm _ _) _)) →\n return $ not-tpabsd dt″\n (dt″@(decor-arrow _ _ _)) → return $ not-tpabsd dt″\n (dt″@(decor-stuck _ _)) → return $ not-tpabsd dt″\n (dt″@(decor-type _)) → return $ not-tpabsd dt″\n (dt″@(decor-error _ _)) → return $ not-tpabsd dt″\n\n\n\n-- errors\n-- --------------------------------------------------\n\n-- general type errors for applications\nmodule check-term-app-tm-errors\n {A : Set} (t₁ t₂ : ex-tm) (htp : type) (Xs : meta-vars) (is-locale : 𝔹) (m : checking-mode) (Γ : ctxt)\n where\n\n inapplicable : erased? → decortype → prototype → spanM (maybe A)\n inapplicable e? dt pt =\n spanM-add\n (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m\n (head-type Γ (meta-vars-subst-type Γ Xs htp)\n -- :: decortype-data Γ dt\n -- :: prototype-data Γ pt\n :: meta-vars-data-all Γ Xs)\n (just $ \"The type of the head does not allow the head to be applied to \"\n ^ h e? ^ \" argument\"))\n >> return nothing\n where h : erased? → string\n h Erased = \"an erased term\"\n h NotErased = \"a term\"\n\n bad-erasure : erased? → spanM (maybe A)\n bad-erasure e? =\n spanM-add\n (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m\n (head-type Γ (meta-vars-subst-type Γ Xs htp) :: meta-vars-data-all Γ Xs)\n (just (msg e?)))\n >> return nothing\n where\n msg : erased? → string\n msg Erased =\n \"The type computed for the head requires an explicit (non-erased) argument,\"\n ^ \" but the application is marked as erased\"\n msg NotErased =\n \"The type computed for the head requires an implicit (erased) argument,\"\n ^ \" but the application is marked as not erased\"\n\n unmatchable : (tpₓ tp : type) (msg : string) → 𝕃 tagged-val → spanM (maybe A)\n unmatchable tpₓ tp msg tvs =\n spanM-add\n (App-span is-locale (term-start-pos t₁) (term-end-pos t₂) m\n (arg-exp-type Γ tpₓ :: arg-type Γ tp :: tvs ++ meta-vars-data-all Γ Xs)\n (just msg))\n >> return nothing\n\n unsolved-meta-vars : type → 𝕃 tagged-val → spanM (maybe A)\n unsolved-meta-vars tp tvs =\n spanM-add\n (App-span tt (term-start-pos t₁) (term-end-pos t₂) m\n (type-data Γ tp :: meta-vars-data-all Γ Xs ++ tvs)\n (just \"There are unsolved meta-variables in this maximal application\"))\n >> return nothing\n\nmodule check-term-app-tp-errors\n {A : Set} (t : ex-tm) (tp : ex-tp) (htp : type) (Xs : meta-vars) (m : checking-mode) (Γ : ctxt)\n where\n\n inapplicable : decortype → spanM (maybe A)\n inapplicable dt =\n spanM-add\n (AppTp-span tt (term-start-pos t) (type-end-pos tp) synthesizing\n (head-type Γ (meta-vars-subst-type Γ Xs htp)\n -- :: decortype-data Γ dt\n :: meta-vars-data-all Γ Xs)\n (just \"The type of the head does not allow the head to be applied to a type argument\"))\n >> return nothing\n\n ctai-disagree : (ctai-sol : type) → spanM (maybe A)\n ctai-disagree ctai-sol =\n spanM-add (AppTp-span tt (term-start-pos t) (type-end-pos tp) m\n (head-type Γ (meta-vars-subst-type Γ Xs htp)\n :: contextual-type-argument Γ ctai-sol\n :: meta-vars-data-all Γ Xs)\n (just \"The given and contextually inferred type argument differ\"))\n >> return nothing\n\n-- meta-variable locality\n-- --------------------------------------------------\n\n-- for debugging -- prepend to the tvs returned by check-spine-locality if you're having trouble\nprivate\n locale-tag : ℕ → tagged-val\n locale-tag n = \"locale n\" , [[ ℕ-to-string n ]] , []\n\nprivate\n is-locale : (max : 𝔹) → (locl : maybe ℕ) → 𝔹\n is-locale max locl = max || maybe-else' locl ff iszero\n\ncheck-spine-locality : ctxt → meta-vars → type → (max : 𝔹) → (locl : ℕ)\n → spanM (maybe (meta-vars × ℕ × 𝔹))\ncheck-spine-locality Γ Xs tp max locl =\n let new-locl = if iszero locl then num-arrows-in-type Γ tp else locl\n new-Xs = if iszero locl then meta-vars-empty else Xs\n left-locl = is-locale max (just locl)\n in if left-locl && (~ meta-vars-solved? Xs)\n then return nothing\n else return (just (new-Xs , new-locl , left-locl))\n\n\n-- main definition\n--------------------------------------------------\n\ndata check-term-app-ret : Set where\n check-term-app-return : (t~ : term) (Xs : meta-vars) (cod : decortype) (arg-mode : checking-mode) → (tvs : 𝕃 tagged-val) → check-term-app-ret\n\ncheck-term-app : ctxt → (Xs : meta-vars) (Ys : 𝕃 meta-var) → (t₁ t₂ : ex-tm) → is-tmabsd → 𝔹 → spanM (maybe check-term-app-ret)\n\ncheck-term-spine Γ t'@(ExApp t₁ e? t₂) pt max =\n -- 1) type the applicand, extending the prototype\n let pt' = proto-arrow e? pt in\n check-term-spine Γ t₁ pt' ff\n on-fail handleApplicandTypeError\n -- 2) make sure the applicand type reveals an arrow (term abstraction)\n >>=m λ ret → let mk-spine-data Xs dt locl fₕ~ = ret in\n -- the meta-vars need to know the span they were introduced in\n let sloc = span-loc $ ctxt.fn Γ in\n -- see if the decorated type of the head `dt` reveals an arrow\n meta-vars-unfold-tmapp' Γ sloc Xs dt\n >>=c λ Ys tm-arrow? →\n return tm-arrow? on-fail (λ _ → genInapplicableError Xs dt pt' locl)\n -- if so, get the (plain, undecorated) type of the head `htp`\n >>=s λ arr → let htp = decortype-to-type ∘ is-tmabsd-dt $ arr in\n -- 3) make sure erasures of the applicand type + syntax of application match\n checkErasuresMatch e? (is-tmabsd-e? arr) htp Xs locl\n -- 4) type the application, filling in missing type arguments with meta-variables\n >>=m λ _ → check-term-app Γ Xs Ys t₁ t₂ arr (islocl locl)\n -- 5) check no unsolved mvars, if the application is maximal (or a locality)\n >>=m λ {(check-term-app-return t₂~ Xs' rtp' arg-mode tvs) →\n let rtp = decortype-to-type rtp' in\n checkLocality Γ Xs' htp rtp max (pred locl) tvs\n >>=m uncurry₂ λ Xs'' locl' is-loc →\n -- 6) generate span\n genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs\n >> check-term-spine-return Xs'' rtp' locl'\n -- 7) fill in solutions to meta-vars introduced here and return the rest\n λ sols →\n let sols = if max then Xs' else sols\n-- num-sols-here = length Ys\n-- sols-here = take num-sols-here sols\n-- sols-rest = drop num-sols-here sols\n-- as = maybe-else' (meta-vars-to-args (meta-vars-from-list sols-here)) [] id\n-- tₕ~ = recompose-apps as tₕₓ~\n tₕ~ = foldl (λ X t → maybe-else' (meta-vars-lookup sols (meta-var.name X)) t\n λ {(meta-var-mk X' (meta-var-tp k T?) _) →\n maybe-else' T? t (AppTp t ∘ meta-var-sol.sol);\n (meta-var-mk X' (meta-var-tm T t?) _) →\n maybe-else' t? t (AppEr t ∘ meta-var-sol.sol)})\n (fₕ~ sols) Ys\n app = if e? then AppEr else App in\n app tₕ~ t₂~\n }\n\n where\n mode = prototype-to-checking pt\n\n expected-type-if-pt : ctxt → prototype → 𝕃 tagged-val\n expected-type-if-pt Γ pt = case pt of λ where\n (proto-maybe mt) → maybe-else [] (λ tp → [ expected-type Γ tp ]) mt\n (proto-arrow _ _) → []\n\n span-loc : (fn : string) → span-location\n span-loc fn = fn , term-start-pos t₁ , term-end-pos t₂\n\n islocl : ℕ → 𝔹\n islocl locl = is-locale max (just $ pred locl)\n\n handleApplicandTypeError : spanM (maybe _)\n handleApplicandTypeError =\n spanM-add (App-span max (term-start-pos t₁) (term-end-pos t₂) mode (expected-type-if-pt Γ pt) nothing)\n >> check-term Γ t₂ nothing\n >>= (const $ return nothing)\n\n genInapplicableError : meta-vars → decortype → prototype → (locl : ℕ) → spanM (maybe _)\n genInapplicableError Xs dt pt locl =\n check-term-app-tm-errors.inapplicable\n t₁ t₂ (decortype-to-type dt) Xs (islocl locl) mode Γ e? dt (proto-arrow e? pt)\n\n checkErasuresMatch : (e?₁ e?₂ : erased?) → type → meta-vars → (locl : ℕ) → spanM (maybe ⊤)\n checkErasuresMatch e?₁ e?₂ htp Xs locl =\n if e?₁ xor e?₂\n then check-term-app-tm-errors.bad-erasure t₁ t₂ htp Xs (islocl locl) mode Γ e?₁\n else (return ∘ just $ triv)\n\n checkLocality : ctxt → meta-vars → (htp rtp : type) → (max : 𝔹) (locl : ℕ) → 𝕃 tagged-val → spanM ∘ maybe $ _\n checkLocality Γ Xs htp rtp max locl tvs =\n check-spine-locality Γ Xs rtp max locl\n on-fail check-term-app-tm-errors.unsolved-meta-vars\n t₁ t₂ htp Xs (islocl locl) mode Γ rtp tvs\n >>=m (return ∘ just)\n\n genAppSpan : ctxt → (Xs Xs' : meta-vars) → (Ys : 𝕃 meta-var) → prototype → type → (is-locl : 𝔹) → 𝕃 tagged-val → spanM ⊤\n genAppSpan Γ Xs Xs' Ys pt rtp is-loc tvs =\n spanM-add $ elim-pair\n (meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ \"synthesized\" meta-vars-empty rtp)\n λ tvs' → App-span is-loc (term-start-pos t₁) (term-end-pos t₂) mode\n (tvs' ++ meta-vars-intro-data Γ (meta-vars-from-list Ys)\n ++ meta-vars-sol-data Γ Xs Xs' ++ tvs)\n\ncheck-term-spine Γ t'@(ExAppTp t tp) pt max =\n -- 1) type the applicand `t`\n check-term-spine Γ t pt max\n on-fail handleApplicandTypeError\n -- 1a) Xs: spine meta-variables; dt: decorated type of t ; htp: plain type of `t`\n >>=m λ ret → let mk-spine-data Xs dt locl fₕ~ = ret ; htp = decortype-to-type dt in\n -- 2) make sure it reveals a type abstraction\n meta-vars-unfold-tpapp' Γ Xs dt\n on-fail (λ _ → genInapplicableError Xs htp dt)\n -- 3) ensure the type argument has the expected kind,\n -- but don't compare with the contextually infered type argument (for now)\n >>=s λ ret → let mk-tpabsd dt' e? x k sol rdt = ret in\n check-type Γ tp (just (meta-vars-subst-kind Γ Xs k))\n -- 4) produce the result type of the application\n >>= λ tp~ → subst-decortype-if Γ tp~ Xs x k sol rdt\n >>= λ ret → let Xs = fst ret ; rdt = snd ret ; rtp = decortype-to-type rdt in\n -- 5) generate span data\n genAppTpSpan Γ Xs pt rtp htp\n >> check-term-spine-return Xs rdt locl\n -- 7) fill in solutions to meta-vars introduced here and return the rest\n λ sols → AppTp (fₕ~ sols) tp~\n --(map-snd (λ tₕ~ → AppE tₕ~ (Ttp tp~)) ∘ fₕ~)\n\n where\n mode = prototype-to-checking pt\n\n span-loc : ctxt → span-location\n span-loc Γ = (ctxt.fn Γ) , term-start-pos t , type-end-pos tp\n\n handleApplicandTypeError : spanM ∘ maybe $ spine-data\n handleApplicandTypeError =\n [- AppTp-span tt (term-start-pos t) (type-end-pos tp) synthesizing [] nothing -]\n check-type Γ tp nothing >>= λ _ → return nothing\n\n genInapplicableError : meta-vars → type → decortype → spanM ∘ maybe $ spine-data\n genInapplicableError Xs htp dt =\n check-term-app-tp-errors.inapplicable t tp htp Xs mode Γ dt\n\n subst-decortype-if : ctxt → type → meta-vars → var → kind → maybe type → decortype → spanM (meta-vars × decortype)\n subst-decortype-if Γ tp Xs x k sol rdt =\n if ~ is-hole tp\n then subst-decortype Γ tp x rdt >>= (λ res → return (Xs , res))\n else let sol = maybe-map (λ t → mk-meta-var-sol t checking) sol\n Y = meta-var-fresh-tp Xs x (span-loc Γ) (k , sol)\n Xs' = meta-vars-add Xs Y\n in subst-decortype Γ (meta-var-to-type-unsafe Y) x rdt >>= λ rdt' → return (Xs' , rdt')\n\n genAppTpSpan : ctxt → meta-vars → prototype → (ret-tp head-tp : type) → spanM ⊤\n genAppTpSpan Γ Xs pt ret-tp head-tp = spanM-add ∘ elim-pair\n -- check for a type mismatch, if there even is an expected type\n (meta-vars-check-type-mismatch-if (prototype-to-maybe pt) Γ \"synthesizing\" Xs ret-tp) $\n -- then take the generated 𝕃 tagged-val and add to the span\n λ tvs → AppTp-span ff (term-start-pos t) (type-end-pos tp) mode $\n tvs {- ++ [ head-type Γ head-tp ] -}\n ++ meta-vars-data-all Γ Xs\n {- ++ (prototype-data Γ tp :: [ decortype-data Γ dt ]) -}\n\ncheck-term-spine Γ (ExParens _ t _) pt max =\n check-term-spine Γ t pt max\n\ncheck-term-spine Γ t pt max =\n check-term Γ t nothing >>=c λ t~ htp →\n let locl = num-arrows-in-type Γ htp\n in match-prototype Γ meta-vars-empty ff htp pt\n -- NOTE: it is an invariant that the variables solved in the\n -- solution set of the fst of this are a subset of the variables given\n -- to match-* -- that is, for (σ , W) = match-prototype ...\n -- we have dom(σ) = ∅\n >>= λ ret → let dt = match-proto-dectp ret in\n check-term-spine-return meta-vars-empty dt locl λ _ → t~\n\n-- check-term-app\n-- --------------------------------------------------\n--\n-- If `dom` has unsolved meta-vars in it, synthesize argument t₂ and try to solve for them.\n-- Otherwise, check t₂ against a fully known expected type\ncheck-term-app Γ Xs Zs t₁ t₂ (mk-tmabsd dt e? x dom occurs cod) is-locl =\n let Xs' = meta-vars-add* Xs Zs ; tp = decortype-to-type dt in\n -- 1) either synth or check arg type, depending on available info\n -- checking \"exits early\", as well as failure\n checkArgWithMetas Xs' tp (genAppRetType Γ)\n on-fail return\n -- 2) match *synthesized* type with expected (partial) type\n >>=s uncurry₂ λ rdt t₂~ atp → match-types Γ Xs' empty-trie match-unfolding-both dom atp\n >>= (handleMatchResult Xs' t₂~ atp tp rdt)\n\n where\n mode = synthesizing\n\n genAppRetType : ctxt → term → spanM decortype\n genAppRetType Γ t₂~ = if occurs then subst-decortype Γ t₂~ x cod else return cod\n\n genAppRetTypeHole : ctxt → spanM decortype\n genAppRetTypeHole Γ = if occurs then subst-decortype Γ (Hole posinfo-gen) x cod else return cod\n\n checkArgWithMetas : meta-vars → type → (term → spanM decortype) → spanM (maybe check-term-app-ret ∨ (decortype × term × type))\n checkArgWithMetas Xs' tp rdt-f =\n -- check arg against fully known type\n if ~ meta-vars-are-free-in-type Xs' dom\n then (check-term Γ t₂ (just dom) >>= λ t₂~ →\n rdt-f t₂~ >>= λ rdt →\n return (inj₁ (just $ check-term-app-return t₂~ Xs' rdt mode [])))\n -- synthesize type for the argument\n else (check-term Γ t₂ nothing >>=c λ t tp →\n rdt-f t >>= λ rdt →\n return (inj₂ $ rdt , t , tp))\n\n handleMatchResult : meta-vars → (t₂~ : term) → (atp tp : type) → decortype → match-error-t meta-vars → spanM ∘ maybe $ check-term-app-ret\n handleMatchResult Xs' t₂~ atp tp rdt (match-error (msg , tvs)) =\n check-term-app-tm-errors.unmatchable\n t₁ t₂ tp Xs' is-locl mode Γ dom atp msg tvs\n handleMatchResult Xs' t₂~ atp tp rdt (match-ok Xs) =\n meta-vars-subst-decortype' ff Γ Xs rdt\n >>= λ rdt → return ∘ just $ check-term-app-return t₂~ Xs rdt mode []\n\nmatch-unfolding-next : match-unfolding-state → match-unfolding-state\nmatch-unfolding-next match-unfolding-both = match-unfolding-both\nmatch-unfolding-next match-unfolding-approx = match-unfolding-approx\nmatch-unfolding-next match-unfolding-hnf = match-unfolding-both\n\nmodule m-err = meta-vars-match-errors\n\ncheck-type-for-match : ctxt → type → spanM $ match-error-t kind\ncheck-type-for-match Γ tp =\n (with-clear-error $\n check-type (qualified-ctxt Γ) (resugar tp) nothing >>=c λ _ k → return (match-ok $ k)) >>=spand return\n\n-- match-types\n-- --------------------------------------------------\n\nmatch-types-ok : meta-vars → spanM $ match-error-t meta-vars\nmatch-types-ok = return ∘ match-ok\n\nmatch-types-error : match-error-data → spanM $ match-error-t meta-vars\nmatch-types-error = return ∘ match-error\n\nmatch-types Γ Xs Ls match-unfolding-both tpₓ tp =\n match-types Γ Xs Ls match-unfolding-approx tpₓ tp\n >>= λ where\n (match-ok Xs) → match-types-ok Xs\n (match-error msg) →\n match-types Γ Xs Ls match-unfolding-hnf\n (hnf Γ unfold-head-elab tpₓ)\n (hnf Γ unfold-head-elab tp)\n\nmatch-types Γ Xs Ls unf tpₓ@(TpVar x) tp =\n -- check that x is a meta-var\n maybe-else' (meta-vars-lookup-with-kind Xs x)\n -- if not, make sure the two variables are the same\n -- TODO: above assumes no term meta-variables\n (return (err⊎-guard (~ conv-type Γ tpₓ tp) m-err.e-match-failure\n >> match-ok Xs))\n -- scope check the solution\n λ ret → let X = fst ret ; kₓ = snd ret in\n if are-free-in Ls tp then\n match-types-error $ m-err.e-meta-scope Γ tpₓ tp\n else (check-type-for-match Γ tp\n >>=s λ k → match-kinds Γ Xs empty-trie match-unfolding-both kₓ k\n on-fail (λ _ → return ∘ match-error $ m-err.e-bad-sol-kind Γ x tp)\n >>=s λ Xs → return (meta-vars-solve-tp Γ Xs x tp synthesizing)\n >>=s λ Xs → match-types-ok $ meta-vars-update-kinds Γ Xs Xs)\n\nmatch-types Γ Xs Ls unf (TpApp tpₓ₁ (Ttp tpₓ₂)) (TpApp tp₁ (Ttp tp₂)) =\n match-types Γ Xs Ls unf tpₓ₁ tp₁\n >>=s λ Xs' → match-types Γ Xs' Ls (match-unfolding-next unf) tpₓ₂ tp₂\n\nmatch-types Γ Xs Ls unf (TpApp tpₓ (Ttm tmₓ)) (TpApp tp (Ttm tm)) =\n match-types Γ Xs Ls unf tpₓ tp\n >>=s λ Xs' →\n return $ if ~ conv-term Γ tmₓ tm\n then (match-error m-err.e-match-failure) else\n match-ok Xs'\n\nmatch-types Γ Xs Ls unf tpₓ'@(TpAbs bₓ xₓ tkₓ tpₓ) tp'@(TpAbs b x tk tp) =\n if bₓ xor b\n then (match-types-error m-err.e-match-failure)\n else (match-tpkds Γ Xs Ls (match-unfolding-next unf) tkₓ tk >>=s λ Xs' → \n match-types (Γ→Γ' Γ) Xs' Ls' (match-unfolding-next unf) tpₓ tp)\n where\n Γ→Γ' : ctxt → ctxt\n Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)\n Ls' = stringset-insert Ls x\n\nmatch-types Γ Xs Ls unf (TpIota xₓ mₓ tpₓ) (TpIota x m tp) =\n match-types Γ Xs Ls (match-unfolding-next unf) mₓ m\n >>=s λ Xs →\n match-types (Γ→Γ' Γ) Xs Ls' (match-unfolding-next unf) tpₓ tp\n where\n Γ→Γ' : ctxt → ctxt\n Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)\n Ls' = stringset-insert Ls x\n\nmatch-types Γ Xs Ls unf (TpEq t₁ₓ t₂ₓ) (TpEq t₁ t₂) =\n if ~ conv-term Γ t₁ₓ t₁\n then match-types-error $ m-err.e-match-failure else\n if ~ conv-term Γ t₂ₓ t₂\n then match-types-error $ m-err.e-match-failure else\n match-types-ok Xs\n\nmatch-types Γ Xs Ls unf (TpLam xₓ atkₓ tpₓ) (TpLam x atk tp) =\n match-tpkds Γ Xs Ls (match-unfolding-next unf) atkₓ atk >>=s λ Xs →\n match-types (Γ→Γ' Γ) Xs Ls' (match-unfolding-next unf) tpₓ tp\n where\n Γ→Γ' : ctxt → ctxt\n Γ→Γ' Γ = ctxt-rename xₓ x (ctxt-var-decl-if x Γ)\n Ls' = stringset-insert Ls x\n\nmatch-types Γ Xs Ls unf tpₓ tp =\n match-types-error m-err.e-match-failure\n\n-- match-kinds\n-- --------------------------------------------------\n\n-- match-kinds-norm: match already normalized kinds\nmatch-kinds-norm : ctxt → meta-vars → local-vars → match-unfolding-state → (kₓ k : kind) → spanM $ match-error-t meta-vars\n\n-- kind pi\nmatch-kinds-norm Γ Xs Ls uf (KdAbs xₓ tkₓ kₓ) (KdAbs x tk k) =\n match-tpkds Γ Xs Ls uf tkₓ tk >>=s λ Xs →\n match-kinds (Γ→Γ' Γ) Xs Ls' uf kₓ k\n where\n Γ→Γ' = ctxt-rename xₓ x ∘ ctxt-var-decl-if x\n Ls' = stringset-insert Ls x\n\nmatch-kinds-norm Γ Xs Ls uf KdStar KdStar =\n match-types-ok $ Xs\nmatch-kinds-norm Γ Xs Ls uf kₓ k =\n match-types-error $ m-err.e-matchk-failure -- m-err.e-kind-ineq Γ kₓ k\n\nmatch-kinds Γ Xs Ls uf kₓ k =\n match-kinds-norm Γ Xs Ls uf\n (hnf Γ unfold-head-elab kₓ)\n (hnf Γ unfold-head-elab k)\n\n-- match-tk\n-- --------------------------------------------------\nmatch-tpkds Γ Xs Ls uf (Tkk kₓ) (Tkk k) = match-kinds Γ Xs Ls uf kₓ k\nmatch-tpkds Γ Xs Ls uf (Tkt tpₓ) (Tkt tp) = match-types Γ Xs Ls uf tpₓ tp\nmatch-tpkds Γ Xs Ls uf tkₓ tk =\n match-types-error m-err.e-matchk-failure -- m-err.e-tk-ineq Γ tkₓ tk\n\n\n-- match-prototype\n-- --------------------------------------------------\n\nmatch-prototype-err : type → prototype → spanM match-prototype-data\nmatch-prototype-err tp pt = return $ mk-match-prototype-data meta-vars-empty (decor-error tp pt) tt\n\n{-\n --------------------\n Xs ⊢? T ≔ ⁇ ⇒ (∅ , T)\n-}\nmatch-prototype Γ Xs uf tp (proto-maybe nothing) =\n return $ mk-match-prototype-data Xs (decor-type tp) ff\n\n{-\n Xs ⊢= T ≔ S ⇒ σ\n --------------------\n Xs ⊢? T ≔ S ⇒ (σ , T)\n-}\nmatch-prototype Γ Xs uf tp pt@(proto-maybe (just tp')) =\n match-types Γ Xs empty-trie match-unfolding-both tp tp'\n on-fail (λ _ → return $ mk-match-prototype-data Xs (decor-error tp pt) tt)\n >>=s λ Xs' → return $ mk-match-prototype-data Xs' (decor-type tp) ff\n\n{-\n Xs,X ⊢? T ≔ ⁇ → P ⇒ (σ , W)\n -----------------------------------------------\n Xs ⊢? ∀ X . T ≔ ⁇ → P ⇒ (σ - X , ∀ X = σ(X) . W)\n-}\nmatch-prototype Γ Xs uf (TpAbs bₓ x (Tkk k) tp) pt'@(proto-arrow e? pt) =\n -- 1) generate a fresh meta-var Y, add it to the meta-vars, and rename\n -- occurences of x in tp to Y\n let ret = meta-vars-add-from-tpabs Γ missing-span-location Xs Erased x k tp\n Y = fst ret ; Xs' = snd ret ; tp' = subst Γ (meta-var-to-type-unsafe Y) x tp\n -- 2) match the body against the original prototype to generate a decorated type\n -- and find some solutions\n in match-prototype Γ Xs' ff tp' pt'\n >>= λ ret →\n let mk-match-prototype-data Xs' dt err = ret\n Y' = maybe-else' (meta-vars-lookup Xs' (meta-var-name Y)) Y λ Y → Y\n x' = subst-rename-var-if{TYPE} Γ empty-renamectxt x empty-trie tp'\n -- 3) replace the meta-vars with the bound type variable\n in subst-decortype (ctxt-var-decl x' Γ) (TpVar x') (meta-var-name Y) dt\n -- 4) leave behind the solution for Y as a decoration and drop Y from Xs\n >>= λ dt' →\n let sort' = meta-var.sort (meta-var-set-src Y' checking)\n dt″ = decor-decor Erased x (Tkk k) sort' dt' in\n return $ mk-match-prototype-data (meta-vars-remove Xs' Y) dt″ err\n\n{-\n Xs ⊢? T ≔ P ⇒ (σ , P)\n -----------------------------\n Xs ⊢? S → T ≔ ⁇ → P ⇒ (σ , P)\n-}\nmatch-prototype Γ Xs uf (TpAbs b x (Tkt dom) cod) (proto-arrow e? pt) =\n match-prototype Γ Xs ff cod pt\n >>= λ ret →\n let mk-match-prototype-data Xs dt err = ret\n dt' = decor-decor b x (Tkt dom) (meta-var-tm dom nothing) dt\n in return $ if b xor e?\n then mk-match-prototype-data meta-vars-empty dt' tt\n else mk-match-prototype-data Xs dt' err\n\n{-\n X ∈ Xs\n -----------------------------------\n Xs ⊢? X ≔ ⁇ → P ⇒ (σ , (X , ⁇ → P))\n-}\nmatch-prototype Γ Xs tt tp@(TpVar x) pt@(proto-arrow _ _) =\n return $ mk-match-prototype-data Xs (decor-stuck tp pt) ff\n\n-- everything else...\n-- Types for which we should keep digging\nmatch-prototype Γ Xs ff tp@(TpVar x) pt@(proto-arrow _ _) =\n match-prototype Γ Xs tt (hnf Γ unfold-head-elab tp) pt\nmatch-prototype Γ Xs ff tp@(TpApp _ _) pt@(proto-arrow _ _) =\n match-prototype Γ Xs tt (hnf Γ unfold-head-elab tp) pt\n-- types for which we should suspend disbelief\nmatch-prototype Γ Xs tt tp@(TpApp _ _) pt@(proto-arrow _ _) =\n return $ mk-match-prototype-data Xs (decor-stuck tp pt) ff\n-- types which clearly do not match the prototype\nmatch-prototype Γ Xs uf tp@(TpEq _ _) pt@(proto-arrow _ _) =\n match-prototype-err tp pt\nmatch-prototype Γ Xs uf tp@(TpHole _) pt@(proto-arrow _ _) =\n match-prototype-err tp pt\nmatch-prototype Γ Xs uf tp@(TpLam _ _ _) pt@(proto-arrow _ _) =\n match-prototype-err tp pt\nmatch-prototype Γ Xs uf tp@(TpIota _ _ _) pt@(proto-arrow _ _) =\n match-prototype-err tp pt\n", "meta": {"hexsha": "67117f87cb0bc3917d5606c9b0c448ed58673c58", "size": 29384, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/type-inf.agda", "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/type-inf.agda", "max_issues_repo_name": "ice1k/cedille", "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/type-inf.agda", "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2791366906, "max_line_length": 143, "alphanum_fraction": 0.6303430438, "num_tokens": 9683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.3007455726738824, "lm_q1q2_score": 0.15507040683617732}} {"text": "-- {-# OPTIONS -v reify:100 -v syntax.reify:100 #-}\nmodule Issue857b where\n\ndata ⊥ : Set where\n\n⊥-elim : {A : Set} → ⊥ → A\n⊥-elim ()\n\ndata _≡_ {A : Set} (x : A) : A → Set where\n refl : x ≡ x\n\n_∋_ : (A : Set) → A → A\n_ ∋ x = x\n\nfoo : {A B : Set} {x : ⊥} {y : B} →\n ((⊥ → A) ∋ λ()) x ≡ ((⊥ → B → A) ∋ λ()) x y\nfoo = refl\n\n-- WAS: An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:514\n\nbar : {A B C : Set} {x : ⊥} {y : B} {z : C} →\n ((⊥ → B → A) ∋ λ()) x y ≡ ((⊥ → C → A) ∋ λ()) x z\nbar = refl\n\n-- WAS:\n-- .y != .z of type .B\n-- when checking that the expression refl has type\n-- ((⊥ → .B → .A) ∋ .Test.absurdLambda) .x .y ≡\n-- ((⊥ → .C → .A) ∋ .Test.absurdLambda) .x .z\n\n-- Note that z has type C, not B.\n\nbaz : {A : Set} → _≡_ {A = ⊥ → A} ⊥-elim (λ())\nbaz = refl\n\n-- WAS: An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:51\n\n-- ERROR: ⊥-elim x != (λ ()) x of type .A\n-- when checking that the expression refl has type ⊥-elim ≡ (λ ())\n", "meta": {"hexsha": "24766bf50d2b8401b65062f191c532f8821d3ddf", "size": 1102, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue857b.agda", "max_stars_repo_name": "cruhland/agda", "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1989, "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_issues_repo_path": "test/Fail/Issue857b.agda", "max_issues_repo_name": "cruhland/agda", "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4066, "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_forks_repo_path": "test/Fail/Issue857b.agda", "max_forks_repo_name": "cruhland/agda", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 371, "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "avg_line_length": 26.2380952381, "max_line_length": 70, "alphanum_fraction": 0.5299455535, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984434543458, "lm_q2_score": 0.28457601028405616, "lm_q1q2_score": 0.15227618014744634}}